Skip to content

Instantly share code, notes, and snippets.

@superckl
Last active January 2, 2016 22:08
Show Gist options
  • Save superckl/8367677 to your computer and use it in GitHub Desktop.
Save superckl/8367677 to your computer and use it in GitHub Desktop.
package me.superckl.addonmanager.commands;
import me.superckl.addonmanager.AddonManagerPlugin;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Permission;
/**
* 'Borrowed' from Factions and editted a bit
*/
public class FactionChat extends FCommand{
public FactionChat()
{
this.aliases.add("c");
this.aliases.add("chat");
this.optionalArgs.put("mode", "next");
this.permission = Permission.CHAT.node;
this.disableOnLock = false;
this.senderMustBePlayer = true;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.senderMustBeAdmin = false;
}
public void perform()
{
if (!Conf.factionOnlyChat)
{
msg("<b>The built in chat chat channels are disabled on this server.", new Object[0]);
return;
}
String modeString = argAsString(0);
ChatMode modeTarget = this.fme.getChatMode().getNext();
if (modeString != null)
{
modeString.toLowerCase();
if (modeString.startsWith("p"))
{
modeTarget = ChatMode.PUBLIC;
}
else if (modeString.startsWith("a"))
{
modeTarget = ChatMode.ALLIANCE;
}
else if (modeString.startsWith("f"))
{
modeTarget = ChatMode.FACTION;
}
else
{
msg("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'", new Object[0]);
return;
}
}
this.fme.setChatMode(modeTarget);
AddonManagerPlugin.getUser(this.me.getName()).setChatMode(modeTarget);
if (this.fme.getChatMode() == ChatMode.PUBLIC)
{
msg("<i>Public chat mode.", new Object[0]);
}
else if (this.fme.getChatMode() == ChatMode.ALLIANCE)
{
msg("<i>Alliance only chat mode.", new Object[0]);
}
else
{
msg("<i>Faction only chat mode.", new Object[0]);
}
}
}
try {
Field field = MPlugin.class.getDeclaredField("baseCommands");
field.setAccessible(true);
((List<MCommand<?>>)field.get(Bukkit.getPluginManager().getPlugin("Factions"))).get(0).subCommands.set(4, new FactionChat());
} catch (IllegalArgumentException | IllegalAccessException
| NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment