Factions/src/org/mcteam/factions/commands/FCommandJoin.java

66 lines
1.5 KiB
Java
Raw Normal View History

2011-04-08 15:51:07 +02:00
package org.mcteam.factions.commands;
2011-03-19 13:00:03 +01:00
2011-04-08 15:51:07 +02:00
import org.mcteam.factions.Conf;
import org.mcteam.factions.Faction;
2011-03-19 13:00:03 +01:00
public class FCommandJoin extends FBaseCommand {
2011-03-19 13:00:03 +01:00
public FCommandJoin() {
aliases.add("join");
2011-03-19 13:00:03 +01:00
requiredParameters.add("faction name");
helpDescription = "Join a faction";
}
@Override
2011-03-19 13:00:03 +01:00
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
2011-03-19 13:00:03 +01:00
String factionName = parameters.get(0);
Faction faction = findFaction(factionName);
if (faction == null) {
return;
}
2011-03-23 17:39:56 +01:00
if ( ! faction.isNormal()) {
sendMessage("You may only join normal factions. This is a system faction.");
return;
}
2011-03-22 17:20:21 +01:00
if (faction == me.getFaction()) {
2011-03-19 13:00:03 +01:00
sendMessage("You are already a member of "+faction.getTag(me));
return;
}
if (me.hasFaction()) {
sendMessage("You must leave your current faction first.");
return;
}
if (!Conf.CanLeaveWithNegativePower && me.getPower() < 0) {
sendMessage("You cannot join a faction until your power is positive.");
return;
}
2011-03-19 13:00:03 +01:00
if( ! faction.getOpen() && ! faction.isInvited(me)) {
sendMessage("This guild requires invitation.");
faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" tried to join your faction.");
return;
}
me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getTag(me));
faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction.");
me.resetFactionData();
2011-03-22 17:20:21 +01:00
me.setFaction(faction);
faction.deinvite(me);
2011-03-19 13:00:03 +01:00
}
}