Fixed the package structure
This commit is contained in:
262
src/org/mcteam/factions/commands/FBaseCommand.java
Normal file
262
src/org/mcteam/factions/commands/FBaseCommand.java
Normal file
@ -0,0 +1,262 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
|
||||
public class FBaseCommand {
|
||||
public List<String> aliases;
|
||||
public List<String> requiredParameters;
|
||||
public List<String> optionalParameters;
|
||||
|
||||
public String helpNameAndParams;
|
||||
public String helpDescription;
|
||||
|
||||
public CommandSender sender;
|
||||
public boolean senderMustBePlayer;
|
||||
public Player player;
|
||||
public FPlayer me;
|
||||
|
||||
public List<String> parameters;
|
||||
|
||||
|
||||
public FBaseCommand() {
|
||||
aliases = new ArrayList<String>();
|
||||
requiredParameters = new ArrayList<String>();
|
||||
optionalParameters = new ArrayList<String>();
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
helpNameAndParams = "fail!";
|
||||
helpDescription = "no description";
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, List<String> parameters) {
|
||||
this.sender = sender;
|
||||
this.parameters = parameters;
|
||||
|
||||
if ( ! validateCall()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.senderMustBePlayer) {
|
||||
this.player = (Player)sender;
|
||||
this.me = FPlayer.get(this.player);
|
||||
}
|
||||
|
||||
perform();
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(Conf.colorSystem+message);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> messages) {
|
||||
for(String message : messages) {
|
||||
this.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateCall() {
|
||||
if ( this.senderMustBePlayer && ! (sender instanceof Player)) {
|
||||
sendMessage("This command can only be used by ingame players.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! hasPermission(sender)) {
|
||||
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parameters.size() < requiredParameters.size()) {
|
||||
sendMessage("Usage: "+this.getUseageTemplate(true));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return Factions.hasPermParticipate(sender);
|
||||
}
|
||||
|
||||
/*public boolean testPermission(CommandSender sender) {
|
||||
// There are two cases where we default to op:
|
||||
// 1. Permissions is not installed
|
||||
// 2. The sender is not a player
|
||||
if ( Factions.Permissions == null || (! (sender instanceof Player))) {
|
||||
if (this.opOnly && sender.isOp()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// No permissions are needed to use this command.
|
||||
if (this.permissions.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
return Factions.Permissions.has(player, this.permissions);
|
||||
}*/
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Help and usage description
|
||||
// -------------------------------------------- //
|
||||
public String getUseageTemplate(boolean withColor, boolean withDescription) {
|
||||
String ret = "";
|
||||
|
||||
if (withColor) {
|
||||
ret += Conf.colorCommand;
|
||||
}
|
||||
|
||||
ret += Factions.instance.getBaseCommand()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
|
||||
|
||||
List<String> parts = new ArrayList<String>();
|
||||
|
||||
for (String requiredParameter : this.requiredParameters) {
|
||||
parts.add("["+requiredParameter+"]");
|
||||
}
|
||||
|
||||
for (String optionalParameter : this.optionalParameters) {
|
||||
parts.add("*["+optionalParameter+"]");
|
||||
}
|
||||
|
||||
if (withColor) {
|
||||
ret += Conf.colorParameter;
|
||||
}
|
||||
|
||||
ret += TextUtil.implode(parts, " ");
|
||||
|
||||
if (withDescription) {
|
||||
ret += " "+Conf.colorSystem + this.helpDescription;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getUseageTemplate(boolean withColor) {
|
||||
return getUseageTemplate(withColor, false);
|
||||
}
|
||||
|
||||
public String getUseageTemplate() {
|
||||
return getUseageTemplate(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Assertions
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean assertHasFaction() {
|
||||
if ( ! me.hasFaction()) {
|
||||
sendMessage("You are not member of any faction.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean assertMinRole(Role role) {
|
||||
if (me.getRole().value < role.value) {
|
||||
sendMessage("You must be "+role+" to "+this.helpDescription+".");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Commonly used logic
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FPlayer findFPlayer(String playerName, boolean defaultToMe) {
|
||||
FPlayer fp = FPlayer.find(playerName);
|
||||
|
||||
if (fp == null) {
|
||||
if (defaultToMe) {
|
||||
return me;
|
||||
}
|
||||
sendMessage("The player \""+playerName+"\" could not be found");
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
public FPlayer findFPlayer(String playerName) {
|
||||
return findFPlayer(playerName, false);
|
||||
}
|
||||
|
||||
|
||||
public Faction findFaction(String factionName, boolean defaultToMine) {
|
||||
// First we search player names
|
||||
FPlayer fp = FPlayer.find(factionName);
|
||||
if (fp != null) {
|
||||
return fp.getFaction();
|
||||
}
|
||||
|
||||
// Secondly we search faction names
|
||||
Faction faction = Faction.findByTag(factionName);
|
||||
if (faction != null) {
|
||||
return faction;
|
||||
}
|
||||
|
||||
if (defaultToMine) {
|
||||
return me.getFaction();
|
||||
}
|
||||
|
||||
me.sendMessage(Conf.colorSystem+"No faction or player \""+factionName+"\" was found");
|
||||
return null;
|
||||
}
|
||||
|
||||
public Faction findFaction(String factionName) {
|
||||
return findFaction(factionName, false);
|
||||
}
|
||||
|
||||
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
|
||||
if ( ! i.getFaction().equals(you.getFaction())) {
|
||||
i.sendMessage(you.getNameAndRelevant(i)+Conf.colorSystem+" is not in the same faction as you.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (you.getRole().equals(Role.ADMIN)) {
|
||||
i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
|
||||
} else if (i.getRole().equals(Role.MODERATOR)) {
|
||||
i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
|
||||
} else {
|
||||
i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean parseBool(String str) {
|
||||
List<String> aliasTrue = new ArrayList<String>();
|
||||
aliasTrue.add("true");
|
||||
aliasTrue.add("yes");
|
||||
aliasTrue.add("y");
|
||||
aliasTrue.add("ok");
|
||||
aliasTrue.add("on");
|
||||
aliasTrue.add("+");
|
||||
|
||||
return aliasTrue.contains(str.toLowerCase());
|
||||
}
|
||||
}
|
60
src/org/mcteam/factions/commands/FCommandAdmin.java
Normal file
60
src/org/mcteam/factions/commands/FCommandAdmin.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandAdmin extends FBaseCommand {
|
||||
|
||||
public FCommandAdmin() {
|
||||
aliases.add("admin");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
helpDescription = "Hand over your admin rights";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if (you.getFaction() != myFaction) {
|
||||
sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == me) {
|
||||
sendMessage("The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
me.setRole(Role.MODERATOR);
|
||||
you.setRole(Role.ADMIN);
|
||||
|
||||
// Inform all players
|
||||
for (FPlayer fplayer : FPlayer.getAllOnline()) {
|
||||
if (fplayer.getFaction() == me.getFaction()) {
|
||||
fplayer.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+you.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction.");
|
||||
} else {
|
||||
fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" gave "+you.getNameAndRelevant(fplayer)+Conf.colorSystem+" the leadership of "+myFaction.getTag(fplayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
src/org/mcteam/factions/commands/FCommandBypass.java
Normal file
33
src/org/mcteam/factions/commands/FCommandBypass.java
Normal file
@ -0,0 +1,33 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.bukkit.mcteam.factions.Conf;
|
||||
import com.bukkit.mcteam.factions.Faction;
|
||||
import com.bukkit.mcteam.factions.Factions;
|
||||
import com.bukkit.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandBypass extends FBaseCommand {
|
||||
|
||||
public FCommandBypass() {
|
||||
aliases.add("bypass");
|
||||
|
||||
helpDescription = "Enable admin bypass mode; build/destroy anywhere";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return Factions.hasPermAdminBypass(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if ( ! Conf.adminBypassPlayers.contains(player.getName())) {
|
||||
Conf.adminBypassPlayers.add(player.getName());
|
||||
me.sendMessage("You have enabled admin bypass mode. You will be able to build or destroy anywhere.");
|
||||
} else {
|
||||
Conf.adminBypassPlayers.remove(player.getName());
|
||||
me.sendMessage("You have disabled admin bypass mode.");
|
||||
}
|
||||
}
|
||||
}
|
28
src/org/mcteam/factions/commands/FCommandChat.java
Normal file
28
src/org/mcteam/factions/commands/FCommandChat.java
Normal file
@ -0,0 +1,28 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
public class FCommandChat extends FBaseCommand {
|
||||
|
||||
public FCommandChat() {
|
||||
aliases.add("chat");
|
||||
aliases.add("c");
|
||||
|
||||
helpDescription = "Switch faction only chat on and off";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! me.isFactionChatting()) {
|
||||
// Turn on
|
||||
me.setFactionChatting(true);
|
||||
sendMessage("Faction-only chat ENABLED.");
|
||||
} else {
|
||||
// Turn off
|
||||
me.setFactionChatting(false);
|
||||
sendMessage("Faction-only chat DISABLED.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
76
src/org/mcteam/factions/commands/FCommandClaim.java
Normal file
76
src/org/mcteam/factions/commands/FCommandClaim.java
Normal file
@ -0,0 +1,76 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Board;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FLocation;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandClaim extends FBaseCommand {
|
||||
|
||||
public FCommandClaim() {
|
||||
aliases.add("claim");
|
||||
|
||||
helpDescription = "Claim the land where you are standing";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
FLocation flocation = new FLocation(me);
|
||||
Faction otherFaction = Board.getFactionAt(flocation);
|
||||
|
||||
if (myFaction == otherFaction) {
|
||||
sendMessage("You already own this land.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) {
|
||||
sendMessage("You can't claim more land! You need more power!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherFaction.getRelation(me) == Relation.ALLY) {
|
||||
sendMessage("You can't claim the land of your allies.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherFaction.isSafeZone()) {
|
||||
sendMessage("You can not claim a SafeZone.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherFaction.isNone()) {
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D");
|
||||
} else { //if (otherFaction.isNormal()) {
|
||||
|
||||
if ( ! otherFaction.hasLandInflation()) {
|
||||
// TODO more messages WARN current faction most importantly
|
||||
sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! Board.isBorderLocation(flocation)) {
|
||||
sendMessage("You must start claiming land at the border of the territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// ASDF claimed some of your land 450 blocks NNW of you.
|
||||
// ASDf claimed some land from FACTION NAME
|
||||
otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O");
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction));
|
||||
}
|
||||
|
||||
Board.setFactionAt(myFaction, flocation);
|
||||
}
|
||||
|
||||
}
|
59
src/org/mcteam/factions/commands/FCommandCreate.java
Normal file
59
src/org/mcteam/factions/commands/FCommandCreate.java
Normal file
@ -0,0 +1,59 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
|
||||
public class FCommandCreate extends FBaseCommand {
|
||||
|
||||
public FCommandCreate() {
|
||||
aliases.add("create");
|
||||
|
||||
requiredParameters.add("faction tag");
|
||||
|
||||
helpDescription = "Create a new faction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return Factions.hasPermCreate(sender);
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
String tag = parameters.get(0);
|
||||
|
||||
if (me.hasFaction()) {
|
||||
sendMessage("You must leave your current faction first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Faction.isTagTaken(tag)) {
|
||||
sendMessage("That tag is already in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> tagValidationErrors = Faction.validateTag(tag);
|
||||
if (tagValidationErrors.size() > 0) {
|
||||
sendMessage(tagValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = Faction.create();
|
||||
faction.setTag(tag);
|
||||
me.setRole(Role.ADMIN);
|
||||
me.setFaction(faction);
|
||||
|
||||
for (FPlayer follower : FPlayer.getAllOnline()) {
|
||||
follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower));
|
||||
}
|
||||
|
||||
sendMessage("You should now: " + new FCommandDescription().getUseageTemplate(true, true));
|
||||
}
|
||||
|
||||
}
|
49
src/org/mcteam/factions/commands/FCommandDeinvite.java
Normal file
49
src/org/mcteam/factions/commands/FCommandDeinvite.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandDeinvite extends FBaseCommand {
|
||||
|
||||
public FCommandDeinvite() {
|
||||
aliases.add("deinvite");
|
||||
aliases.add("deinv");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
helpDescription = "Remove a pending invitation";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getFaction() == myFaction) {
|
||||
sendMessage(you.getName()+" is already a member of "+myFaction.getTag());
|
||||
sendMessage("You might want to: " + new FCommandKick().getUseageTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.deinvite(you);
|
||||
|
||||
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" revoked your invitation to "+myFaction.getTag(you));
|
||||
myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" revoked "+you.getNameAndRelevant(me)+"'s"+Conf.colorSystem+" invitation.");
|
||||
}
|
||||
|
||||
}
|
36
src/org/mcteam/factions/commands/FCommandDescription.java
Normal file
36
src/org/mcteam/factions/commands/FCommandDescription.java
Normal file
@ -0,0 +1,36 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
public class FCommandDescription extends FBaseCommand {
|
||||
|
||||
public FCommandDescription() {
|
||||
aliases.add("desc");
|
||||
|
||||
requiredParameters.add("desc");
|
||||
|
||||
helpDescription = "Change the faction description";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.getFaction().setDescription(TextUtil.implode(parameters));
|
||||
|
||||
// Broadcast the description to everyone
|
||||
for (FPlayer fplayer : FPlayer.getAllOnline()) {
|
||||
fplayer.sendMessage("The faction "+fplayer.getRelationColor(me)+me.getFaction().getTag()+Conf.colorSystem+" changed their description to:");
|
||||
fplayer.sendMessage(me.getFaction().getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
135
src/org/mcteam/factions/commands/FCommandHelp.java
Normal file
135
src/org/mcteam/factions/commands/FCommandHelp.java
Normal file
@ -0,0 +1,135 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
|
||||
public class FCommandHelp extends FBaseCommand {
|
||||
|
||||
public FCommandHelp() {
|
||||
aliases.add("help");
|
||||
aliases.add("h");
|
||||
aliases.add("?");
|
||||
|
||||
optionalParameters.add("page");
|
||||
|
||||
helpDescription = "Display a help page";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
int page = 1;
|
||||
if (parameters.size() > 0) {
|
||||
try {
|
||||
page = Integer.parseInt(parameters.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
// wasn't an integer
|
||||
}
|
||||
}
|
||||
sendMessage(TextUtil.titleize("Factions Help ("+page+"/"+helpPages.size()+")"));
|
||||
page -= 1;
|
||||
if (page < 0 || page >= helpPages.size()) {
|
||||
sendMessage("This page does not exist");
|
||||
return;
|
||||
}
|
||||
sendMessage(helpPages.get(page));
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Build the help pages
|
||||
//----------------------------------------------//
|
||||
|
||||
public static ArrayList<ArrayList<String>> helpPages;
|
||||
|
||||
static {
|
||||
helpPages = new ArrayList<ArrayList<String>>();
|
||||
ArrayList<String> pageLines;
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add( new FCommandHelp().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandList().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandShow().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandMap().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandJoin().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandLeave().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandChat().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandHome().getUseageTemplate(true, true) );
|
||||
pageLines.add( "Learn how to create a faction on the next page." );
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add( "Create a faction using these two commands:" );
|
||||
pageLines.add( new FCommandCreate().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandDescription().getUseageTemplate(true, true) );
|
||||
pageLines.add( "You might wan't to close it and use invitations:" );
|
||||
pageLines.add( new FCommandOpen().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandInvite().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandDeinvite().getUseageTemplate(true, true) );
|
||||
pageLines.add( "And don't forget to set your home:" );
|
||||
pageLines.add( new FCommandSethome().getUseageTemplate(true, true) );
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add( "Faction can claim land that will be protected." );
|
||||
pageLines.add( new FCommandClaim().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandUnclaim().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandTag().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandKick().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandMod().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandAdmin().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandTitle().getUseageTemplate(true, true) );
|
||||
pageLines.add( "Player titles are just for fun. No rules connected to them." );
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add( new FCommandRelationAlly().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandRelationNeutral().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandRelationEnemy().getUseageTemplate(true, true) );
|
||||
pageLines.add("");
|
||||
pageLines.add("Set the relation you WISH to have with another faction.");
|
||||
pageLines.add("Your default relation with other factions will be neutral.");
|
||||
pageLines.add("");
|
||||
pageLines.add("If BOTH factions choose \"ally\" you will be allies.");
|
||||
pageLines.add("If ONE faction chooses \"enemy\" you will be enemies.");
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add("You can never hurt members or allies.");
|
||||
pageLines.add("You can not hurt neutrals in their own territory.");
|
||||
pageLines.add("You can always hurt enemies and players without faction.");
|
||||
pageLines.add("");
|
||||
pageLines.add("Damage from enemies is reduced in your own territory.");
|
||||
pageLines.add("When you die you lose power. It is restored over time.");
|
||||
pageLines.add("The power of a faction is the sum of all member power.");
|
||||
pageLines.add("The power of a faction determines how much land it can hold.");
|
||||
pageLines.add("You can claim land from factions with too little power.");
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add("Only faction members can build and destroy in their own");
|
||||
pageLines.add("territory. Usage of the following items is also restricted:");
|
||||
pageLines.add("Door, Chest, Furnace and Dispenser.");
|
||||
pageLines.add("");
|
||||
pageLines.add("Make sure to put pressure plates in front of doors for your");
|
||||
pageLines.add("guest visitors. Otherwise they can't get through. You can");
|
||||
pageLines.add("also use this to create member only areas.");
|
||||
pageLines.add("As dispensers are protected, you can create traps without");
|
||||
pageLines.add("worrying about those arrows getting stolen.");
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add("Finally some commands for the server admins:");
|
||||
pageLines.add( new FCommandVersion().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandSafeclaim().getUseageTemplate(true, true) );
|
||||
pageLines.add( new FCommandBypass().getUseageTemplate(true, true) );
|
||||
helpPages.add(pageLines);
|
||||
}
|
||||
|
||||
}
|
||||
|
36
src/org/mcteam/factions/commands/FCommandHome.java
Normal file
36
src/org/mcteam/factions/commands/FCommandHome.java
Normal file
@ -0,0 +1,36 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandHome extends FBaseCommand {
|
||||
|
||||
public FCommandHome() {
|
||||
aliases.add("home");
|
||||
|
||||
helpDescription = "Teleport to the faction home";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! Conf.homesEnabled) {
|
||||
me.sendMessage("Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if ( ! myFaction.hasHome()) {
|
||||
me.sendMessage("You faction does not have a home. " + (me.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
|
||||
me.sendMessage(new FCommandSethome().getUseageTemplate(true, true));
|
||||
return;
|
||||
}
|
||||
|
||||
player.teleport(myFaction.getHome());
|
||||
}
|
||||
|
||||
}
|
49
src/org/mcteam/factions/commands/FCommandInvite.java
Normal file
49
src/org/mcteam/factions/commands/FCommandInvite.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandInvite extends FBaseCommand {
|
||||
|
||||
public FCommandInvite() {
|
||||
aliases.add("invite");
|
||||
aliases.add("inv");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
helpDescription = "Invite a player";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if (you.getFaction() == myFaction) {
|
||||
sendMessage(you.getName()+" is already a member of "+myFaction.getTag());
|
||||
sendMessage("You might want to: " + new FCommandKick().getUseageTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.invite(you);
|
||||
|
||||
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you));
|
||||
myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" invited "+you.getNameAndRelevant(me)+Conf.colorSystem+" to your faction.");
|
||||
}
|
||||
|
||||
}
|
53
src/org/mcteam/factions/commands/FCommandJoin.java
Normal file
53
src/org/mcteam/factions/commands/FCommandJoin.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
|
||||
public class FCommandJoin extends FBaseCommand {
|
||||
|
||||
public FCommandJoin() {
|
||||
aliases.add("join");
|
||||
|
||||
requiredParameters.add("faction name");
|
||||
|
||||
helpDescription = "Join a faction";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
String factionName = parameters.get(0);
|
||||
|
||||
Faction faction = findFaction(factionName);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! faction.isNormal()) {
|
||||
sendMessage("You may only join normal factions. This is a system faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (faction == me.getFaction()) {
|
||||
sendMessage("You are already a member of "+faction.getTag(me));
|
||||
return;
|
||||
}
|
||||
|
||||
if (me.hasFaction()) {
|
||||
sendMessage("You must leave your current faction first.");
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
me.setFaction(faction);
|
||||
faction.deinvite(me);
|
||||
}
|
||||
|
||||
}
|
50
src/org/mcteam/factions/commands/FCommandKick.java
Normal file
50
src/org/mcteam/factions/commands/FCommandKick.java
Normal file
@ -0,0 +1,50 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
|
||||
public class FCommandKick extends FBaseCommand {
|
||||
|
||||
public FCommandKick() {
|
||||
aliases.add("kick");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
helpDescription = "Kick a player from the faction";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if (you.getFaction() != myFaction) {
|
||||
sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member of "+myFaction.getTag(me));
|
||||
return;
|
||||
}
|
||||
|
||||
if (me == you) {
|
||||
sendMessage("You cannot kick yourself.");
|
||||
sendMessage("You might want to: " + new FCommandLeave().getUseageTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole().value >= me.getRole().value) { // TODO add more informative messages.
|
||||
sendMessage("Your rank is too low to kick this player.");
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.deinvite(you);
|
||||
you.resetFactionData();
|
||||
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(myFaction)+Conf.colorSystem+" from the faction! :O");
|
||||
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+myFaction.getTag(you)+Conf.colorSystem+"! :O");
|
||||
}
|
||||
|
||||
}
|
26
src/org/mcteam/factions/commands/FCommandLeave.java
Normal file
26
src/org/mcteam/factions/commands/FCommandLeave.java
Normal file
@ -0,0 +1,26 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class FCommandLeave extends FBaseCommand {
|
||||
|
||||
public FCommandLeave() {
|
||||
aliases.add("leave");
|
||||
|
||||
helpDescription = "Leave your faction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.leave();
|
||||
}
|
||||
|
||||
}
|
92
src/org/mcteam/factions/commands/FCommandList.java
Normal file
92
src/org/mcteam/factions/commands/FCommandList.java
Normal file
@ -0,0 +1,92 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
|
||||
public class FCommandList extends FBaseCommand {
|
||||
|
||||
public FCommandList() {
|
||||
aliases.add("list");
|
||||
aliases.add("ls");
|
||||
|
||||
optionalParameters.add("page");
|
||||
|
||||
helpDescription = "Show a list of the factions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll());
|
||||
FactionList.remove(Faction.getNone());
|
||||
FactionList.remove(Faction.getSafeZone());
|
||||
|
||||
int page = 1;
|
||||
if (parameters.size() > 0) {
|
||||
try {
|
||||
page = Integer.parseInt(parameters.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
// wasn't an integer
|
||||
}
|
||||
}
|
||||
page -= 1;
|
||||
|
||||
// Sort by total followers first
|
||||
Collections.sort(FactionList, new Comparator<Faction>(){
|
||||
@Override
|
||||
public int compare(Faction f1, Faction f2) {
|
||||
if (f1.getFPlayers().size() < f2.getFPlayers().size())
|
||||
return 1;
|
||||
else if (f1.getFPlayers().size() > f2.getFPlayers().size())
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Then sort by how many members are online now
|
||||
Collections.sort(FactionList, new Comparator<Faction>(){
|
||||
@Override
|
||||
public int compare(Faction f1, Faction f2) {
|
||||
if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size())
|
||||
return 1;
|
||||
else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size())
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
FactionList.add(0, Faction.getNone());
|
||||
|
||||
int maxPage = (int)Math.floor((double)FactionList.size() / 9D);
|
||||
if (page < 0 || page > maxPage) {
|
||||
sendMessage("The faction list is only " + (maxPage+1) + " page(s) long");
|
||||
return;
|
||||
}
|
||||
|
||||
String header = "Faction List";
|
||||
if (maxPage > 1) header += " (page " + (page+1) + " of " + (maxPage+1) + ")";
|
||||
sendMessage(TextUtil.titleize(header));
|
||||
|
||||
int maxPos = (page+1) * 9;
|
||||
if (maxPos > FactionList.size()) maxPos = FactionList.size();
|
||||
for (int pos = page * 9; pos < maxPos; pos++) {
|
||||
Faction faction = FactionList.get(pos);
|
||||
if (faction.getId() == 0) {
|
||||
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
|
||||
} else {
|
||||
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
47
src/org/mcteam/factions/commands/FCommandMap.java
Normal file
47
src/org/mcteam/factions/commands/FCommandMap.java
Normal file
@ -0,0 +1,47 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Board;
|
||||
import org.mcteam.factions.FLocation;
|
||||
|
||||
|
||||
public class FCommandMap extends FBaseCommand {
|
||||
|
||||
public FCommandMap() {
|
||||
aliases.add("map");
|
||||
|
||||
optionalParameters.add("on|off");
|
||||
|
||||
helpDescription = "Show territory map, set optional auto update";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if (parameters.size() > 0) {
|
||||
String mapAutoUpdating = parameters.get(0);
|
||||
if (parseBool(mapAutoUpdating)) {
|
||||
// Turn on
|
||||
me.setMapAutoUpdating(true);
|
||||
sendMessage("Map auto update ENABLED.");
|
||||
|
||||
// And show the map once
|
||||
showMap();
|
||||
} else {
|
||||
// Turn off
|
||||
me.setMapAutoUpdating(false);
|
||||
sendMessage("Map auto update DISABLED.");
|
||||
}
|
||||
} else {
|
||||
showMap();
|
||||
}
|
||||
}
|
||||
|
||||
public void showMap() {
|
||||
sendMessage(Board.getMap(me.getFaction(), new FLocation(me), me.getPlayer().getLocation().getYaw()));
|
||||
}
|
||||
|
||||
}
|
57
src/org/mcteam/factions/commands/FCommandMod.java
Normal file
57
src/org/mcteam/factions/commands/FCommandMod.java
Normal file
@ -0,0 +1,57 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandMod extends FBaseCommand {
|
||||
|
||||
public FCommandMod() {
|
||||
aliases.add("mod");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
helpDescription = "Give or revoke moderator rights";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
if (you.getFaction() != myFaction) {
|
||||
sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == me) {
|
||||
sendMessage("The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Role.MODERATOR) {
|
||||
// Revoke
|
||||
you.setRole(Role.NORMAL);
|
||||
myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" is no longer moderator in your faction.");
|
||||
} else {
|
||||
// Give
|
||||
you.setRole(Role.MODERATOR);
|
||||
myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" was promoted to moderator in your faction.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
src/org/mcteam/factions/commands/FCommandOpen.java
Normal file
40
src/org/mcteam/factions/commands/FCommandOpen.java
Normal file
@ -0,0 +1,40 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandOpen extends FBaseCommand {
|
||||
|
||||
public FCommandOpen() {
|
||||
aliases.add("open");
|
||||
aliases.add("close");
|
||||
|
||||
helpDescription = "Switch if invitation is required to join";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
myFaction.setOpen( ! me.getFaction().getOpen());
|
||||
|
||||
String open = myFaction.getOpen() ? "open" : "closed";
|
||||
|
||||
// Inform
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open);
|
||||
for (Faction faction : Faction.getAll()) {
|
||||
if (faction == me.getFaction()) {
|
||||
continue;
|
||||
}
|
||||
faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
15
src/org/mcteam/factions/commands/FCommandRelationAlly.java
Normal file
15
src/org/mcteam/factions/commands/FCommandRelationAlly.java
Normal file
@ -0,0 +1,15 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
|
||||
public class FCommandRelationAlly extends FRelationCommand {
|
||||
|
||||
public FCommandRelationAlly() {
|
||||
aliases.add("ally");
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
relation(Relation.ALLY, parameters.get(0));
|
||||
}
|
||||
|
||||
}
|
15
src/org/mcteam/factions/commands/FCommandRelationEnemy.java
Normal file
15
src/org/mcteam/factions/commands/FCommandRelationEnemy.java
Normal file
@ -0,0 +1,15 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
|
||||
public class FCommandRelationEnemy extends FRelationCommand {
|
||||
|
||||
public FCommandRelationEnemy() {
|
||||
aliases.add("enemy");
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
relation(Relation.ENEMY, parameters.get(0));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
|
||||
public class FCommandRelationNeutral extends FRelationCommand {
|
||||
|
||||
public FCommandRelationNeutral() {
|
||||
aliases.add("neutral");
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
relation(Relation.NEUTRAL, parameters.get(0));
|
||||
}
|
||||
|
||||
}
|
30
src/org/mcteam/factions/commands/FCommandSafeclaim.java
Normal file
30
src/org/mcteam/factions/commands/FCommandSafeclaim.java
Normal file
@ -0,0 +1,30 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Board;
|
||||
import org.mcteam.factions.FLocation;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
|
||||
|
||||
public class FCommandSafeclaim extends FBaseCommand {
|
||||
|
||||
public FCommandSafeclaim() {
|
||||
aliases.add("safeclaim");
|
||||
aliases.add("safe");
|
||||
|
||||
helpDescription = "Claim land for the safezone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return Factions.hasPermManageSafeZone(sender);
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
FLocation flocation = new FLocation(me);
|
||||
Board.setFactionAt(Faction.getSafeZone(), flocation);
|
||||
sendMessage("This land is now a safe zone");
|
||||
}
|
||||
|
||||
}
|
38
src/org/mcteam/factions/commands/FCommandSethome.java
Normal file
38
src/org/mcteam/factions/commands/FCommandSethome.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandSethome extends FBaseCommand {
|
||||
|
||||
public FCommandSethome() {
|
||||
aliases.add("sethome");
|
||||
|
||||
helpDescription = "Set the faction home";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! Conf.homesEnabled) {
|
||||
me.sendMessage("Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO may only be inside faction territory
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
myFaction.setHome(player.getLocation());
|
||||
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" set the home for your faction. You can now use:");
|
||||
myFaction.sendMessage(new FCommandHome().getUseageTemplate(true, true));
|
||||
}
|
||||
|
||||
}
|
120
src/org/mcteam/factions/commands/FCommandShow.java
Normal file
120
src/org/mcteam/factions/commands/FCommandShow.java
Normal file
@ -0,0 +1,120 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
|
||||
public class FCommandShow extends FBaseCommand {
|
||||
|
||||
public FCommandShow() {
|
||||
aliases.add("show");
|
||||
aliases.add("who");
|
||||
|
||||
optionalParameters.add("faction tag");
|
||||
|
||||
helpDescription = "Show faction information";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
Faction faction;
|
||||
if (parameters.size() > 0) {
|
||||
faction = findFaction(parameters.get(0), true);
|
||||
} else {
|
||||
faction = me.getFaction();
|
||||
}
|
||||
|
||||
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
|
||||
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
|
||||
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
|
||||
|
||||
sendMessage(TextUtil.titleize(faction.getTag(me)));
|
||||
sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription());
|
||||
if ( ! faction.isNormal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(faction.getOpen()) {
|
||||
sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"no invitation is needed");
|
||||
} else {
|
||||
sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"invitation is required");
|
||||
}
|
||||
sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded());
|
||||
|
||||
String listpart;
|
||||
|
||||
// List relation
|
||||
String allyList = Conf.colorChrome+"Allies: ";
|
||||
String enemyList = Conf.colorChrome+"Enemies: ";
|
||||
for (Faction otherFaction : Faction.getAll()) {
|
||||
if (otherFaction == faction) {
|
||||
continue;
|
||||
}
|
||||
listpart = otherFaction.getTag(me)+Conf.colorSystem+", ";
|
||||
if (otherFaction.getRelation(faction) == Relation.ALLY) {
|
||||
allyList += listpart;
|
||||
} else if (otherFaction.getRelation(faction) == Relation.ENEMY) {
|
||||
enemyList += listpart;
|
||||
}
|
||||
}
|
||||
if (allyList.endsWith(", ")) {
|
||||
allyList = allyList.substring(0, allyList.length()-2);
|
||||
}
|
||||
if (enemyList.endsWith(", ")) {
|
||||
enemyList = enemyList.substring(0, enemyList.length()-2);
|
||||
}
|
||||
|
||||
sendMessage(allyList);
|
||||
sendMessage(enemyList);
|
||||
|
||||
// List the members...
|
||||
String onlineList = Conf.colorChrome+"Members online: ";
|
||||
String offlineList = Conf.colorChrome+"Members offline: ";
|
||||
for (FPlayer follower : admins) {
|
||||
listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
|
||||
if (follower.isOnline()) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
}
|
||||
for (FPlayer follower : mods) {
|
||||
listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
|
||||
if (follower.isOnline()) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
}
|
||||
for (FPlayer follower : normals) {
|
||||
listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
|
||||
if (follower.isOnline()) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineList.endsWith(", ")) {
|
||||
onlineList = onlineList.substring(0, onlineList.length()-2);
|
||||
}
|
||||
if (offlineList.endsWith(", ")) {
|
||||
offlineList = offlineList.substring(0, offlineList.length()-2);
|
||||
}
|
||||
|
||||
sendMessage(onlineList);
|
||||
sendMessage(offlineList);
|
||||
}
|
||||
|
||||
}
|
60
src/org/mcteam/factions/commands/FCommandTag.java
Normal file
60
src/org/mcteam/factions/commands/FCommandTag.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
|
||||
public class FCommandTag extends FBaseCommand {
|
||||
|
||||
public FCommandTag() {
|
||||
aliases.add("tag");
|
||||
|
||||
requiredParameters.add("faction tag");
|
||||
|
||||
helpDescription = "Change the faction tag";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String tag = parameters.get(0);
|
||||
|
||||
// TODO does not first test cover selfcase?
|
||||
if (Faction.isTagTaken(tag) && ! TextUtil.getComparisonString(tag).equals(me.getFaction().getComparisonTag())) {
|
||||
sendMessage("That tag is already taken");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> errors = new ArrayList<String>();
|
||||
errors.addAll(Faction.validateTag(tag));
|
||||
if (errors.size() > 0) {
|
||||
sendMessage(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
String oldtag = myFaction.getTag();
|
||||
myFaction.setTag(tag);
|
||||
|
||||
// Inform
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+myFaction.getTag());
|
||||
for (Faction faction : Faction.getAll()) {
|
||||
if (faction == me.getFaction()) {
|
||||
continue;
|
||||
}
|
||||
faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldtag+Conf.colorSystem+" chainged their name to "+myFaction.getTag(faction));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
45
src/org/mcteam/factions/commands/FCommandTitle.java
Normal file
45
src/org/mcteam/factions/commands/FCommandTitle.java
Normal file
@ -0,0 +1,45 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FPlayer;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.util.TextUtil;
|
||||
|
||||
public class FCommandTitle extends FBaseCommand {
|
||||
|
||||
public FCommandTitle() {
|
||||
aliases.add("title");
|
||||
|
||||
requiredParameters.add("player name");
|
||||
|
||||
optionalParameters.add("title");
|
||||
|
||||
helpDescription = "Set or remove a players title";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
parameters.remove(0);
|
||||
String title = TextUtil.implode(parameters);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! canIAdministerYou(me, you)) {
|
||||
return;
|
||||
}
|
||||
|
||||
you.setTitle(title);
|
||||
|
||||
// Inform
|
||||
Faction myFaction = me.getFaction();
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed a title: "+you.getNameAndRelevant(myFaction));
|
||||
}
|
||||
|
||||
}
|
54
src/org/mcteam/factions/commands/FCommandUnclaim.java
Normal file
54
src/org/mcteam/factions/commands/FCommandUnclaim.java
Normal file
@ -0,0 +1,54 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.mcteam.factions.Board;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.FLocation;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandUnclaim extends FBaseCommand {
|
||||
|
||||
public FCommandUnclaim() {
|
||||
aliases.add("unclaim");
|
||||
aliases.add("declaim");
|
||||
|
||||
helpDescription = "Unclaim the land where you are standing";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
FLocation flocation = new FLocation(me);
|
||||
Faction otherFaction = Board.getFactionAt(flocation);
|
||||
|
||||
if (otherFaction.isSafeZone()) {
|
||||
if (Factions.hasPermManageSafeZone(sender)) {
|
||||
Board.removeAt(flocation);
|
||||
sendMessage("Safe zone was unclaimed.");
|
||||
} else {
|
||||
sendMessage("This is a safe zone. You lack permissions to unclaim.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
|
||||
if ( myFaction != otherFaction) {
|
||||
sendMessage("You don't own this land.");
|
||||
return;
|
||||
}
|
||||
|
||||
Board.removeAt(flocation);
|
||||
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed some land.");
|
||||
}
|
||||
|
||||
}
|
27
src/org/mcteam/factions/commands/FCommandVersion.java
Normal file
27
src/org/mcteam/factions/commands/FCommandVersion.java
Normal file
@ -0,0 +1,27 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.factions.Factions;
|
||||
|
||||
|
||||
public class FCommandVersion extends FBaseCommand {
|
||||
|
||||
public FCommandVersion() {
|
||||
aliases.add("version");
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
helpDescription = "Which version are you using?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void perform() {
|
||||
sendMessage("You are running "+Factions.instance.getDescription().getFullName());
|
||||
}
|
||||
|
||||
}
|
56
src/org/mcteam/factions/commands/FRelationCommand.java
Normal file
56
src/org/mcteam/factions/commands/FRelationCommand.java
Normal file
@ -0,0 +1,56 @@
|
||||
package org.mcteam.factions.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.mcteam.factions.Conf;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
import org.mcteam.factions.struct.Relation;
|
||||
import org.mcteam.factions.struct.Role;
|
||||
|
||||
|
||||
public class FRelationCommand extends FBaseCommand {
|
||||
|
||||
public FRelationCommand() {
|
||||
requiredParameters.add("faction tag");
|
||||
|
||||
helpDescription = "Set relation wish to another faction";
|
||||
}
|
||||
|
||||
public void relation(Relation whishedRelation, String otherFactionName) {
|
||||
if ( ! assertHasFaction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
Faction otherFaction = findFaction(otherFactionName, false);
|
||||
if (otherFaction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherFaction.getId() == 0) {
|
||||
sendMessage("Nope! You can't :) The default faction is not a real faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherFaction == myFaction) {
|
||||
sendMessage("Nope! You can't declare a relation to yourself :)");
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setRelationWish(otherFaction, whishedRelation);
|
||||
Relation currentRelation = myFaction.getRelation(otherFaction);
|
||||
ChatColor currentRelationColor = currentRelation.getColor();
|
||||
if (whishedRelation == currentRelation) {
|
||||
otherFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+myFaction.getTag());
|
||||
myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag());
|
||||
} else {
|
||||
otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " wishes to be your "+whishedRelation.getColor()+whishedRelation.toString());
|
||||
otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Factions.instance.getBaseCommand()+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept.");
|
||||
myFaction.sendMessage(currentRelationColor+otherFaction.getTag()+Conf.colorSystem+ " were informed that you wish to be "+whishedRelation.getColor()+whishedRelation);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user