2011-03-18 17:33:23 +01:00
|
|
|
package com.bukkit.mcteam.factions.commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import com.bukkit.mcteam.factions.Conf;
|
|
|
|
import com.bukkit.mcteam.factions.FPlayer;
|
|
|
|
import com.bukkit.mcteam.factions.Faction;
|
2011-03-19 13:00:03 +01:00
|
|
|
import com.bukkit.mcteam.factions.struct.Role;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
public class FCommandLeave extends FCommand {
|
|
|
|
|
|
|
|
public FCommandLeave() {
|
|
|
|
requiredParameters = new ArrayList<String>();
|
|
|
|
optionalParameters = new ArrayList<String>();
|
|
|
|
|
|
|
|
permissions = "";
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
|
|
|
|
helpNameAndParams = "leave";
|
|
|
|
helpDescription = "Leave your faction";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void perform() {
|
2011-03-19 13:00:03 +01:00
|
|
|
if ( ! me.hasFaction()) {
|
|
|
|
sendMessage("You are not member of any faction.");
|
|
|
|
return;
|
|
|
|
}
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
Faction faction = me.getFaction();
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
if (me.role == Role.ADMIN && faction.getFPlayers().size() > 1) {
|
|
|
|
sendMessage("You must give the admin role to someone else first.");
|
|
|
|
return;
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
faction.sendMessage(me.getNameAndRelevant(faction) + Conf.colorSystem + " left your faction.");
|
|
|
|
me.resetFactionData();
|
|
|
|
FPlayer.save();
|
|
|
|
|
|
|
|
if (faction.getFPlayers().size() == 0) {
|
2011-03-18 17:33:23 +01:00
|
|
|
// Remove this faction
|
2011-03-19 13:00:03 +01:00
|
|
|
for (FPlayer fplayer : FPlayer.getAllOnline()) {
|
|
|
|
fplayer.sendMessage("The faction "+faction.getTag(fplayer)+Conf.colorSystem+" was disbanded.");
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
Faction.delete(faction.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|