Now it compiles. Time to fix runtime errors...

This commit is contained in:
Olof Larsson 2011-03-22 18:48:09 +01:00
parent 4e964ba194
commit 1c062c9c79
30 changed files with 312 additions and 275 deletions

View File

@ -1,3 +1,7 @@
name: Factions name: Factions
version: 1.0 beta8 version: 1.1
main: com.bukkit.mcteam.factions.Factions main: com.bukkit.mcteam.factions.Factions
commands:
f:
description: All of the Factions commands
usage: See documentation.

View File

@ -51,111 +51,13 @@ public class Conf {
public static List<Material> territoryProtectedMaterials = new ArrayList<Material>(); public static List<Material> territoryProtectedMaterials = new ArrayList<Material>();
// Command names / aliases public static boolean allowNoSlashCommand = true;
public static List<String> aliasBase = new ArrayList<String>();
public static List<String> aliasHelp = new ArrayList<String>();
public static List<String> aliasList = new ArrayList<String>();
public static List<String> aliasShow = new ArrayList<String>();
public static List<String> aliasMap = new ArrayList<String>();
public static List<String> aliasJoin = new ArrayList<String>();
public static List<String> aliasLeave = new ArrayList<String>();
public static List<String> aliasCreate = new ArrayList<String>();
public static List<String> aliasTag = new ArrayList<String>();
public static List<String> aliasDescription = new ArrayList<String>();
public static List<String> aliasChat = new ArrayList<String>();
public static List<String> aliasTitle = new ArrayList<String>();
public static List<String> aliasInvite = new ArrayList<String>();
public static List<String> aliasDeinvite = new ArrayList<String>();
public static List<String> aliasOpen = new ArrayList<String>();
public static List<String> aliasKick = new ArrayList<String>();
public static List<String> aliasModerator = new ArrayList<String>();
public static List<String> aliasAdmin = new ArrayList<String>();
public static List<String> aliasClaim = new ArrayList<String>();
public static List<String> aliasUnclaim = new ArrayList<String>();
public static List<String> aliasRelationAlly = new ArrayList<String>();
public static List<String> aliasRelationNeutral = new ArrayList<String>();
public static List<String> aliasRelationEnemy = new ArrayList<String>();
public static List<String> aliasVersion = new ArrayList<String>();
// Value aliases
public static List<String> aliasTrue = new ArrayList<String>();
static { static {
territoryProtectedMaterials.add(Material.WOODEN_DOOR); territoryProtectedMaterials.add(Material.WOODEN_DOOR);
territoryProtectedMaterials.add(Material.DISPENSER); territoryProtectedMaterials.add(Material.DISPENSER);
territoryProtectedMaterials.add(Material.CHEST); territoryProtectedMaterials.add(Material.CHEST);
territoryProtectedMaterials.add(Material.FURNACE); territoryProtectedMaterials.add(Material.FURNACE);
aliasBase.add("/f");
aliasBase.add("f");
aliasHelp.add("help");
aliasHelp.add("h");
aliasHelp.add("?");
aliasList.add("list");
aliasList.add("ls");
aliasShow.add("show");
aliasShow.add("who");
aliasMap.add("map");
aliasJoin.add("join");
aliasLeave.add("leave");
aliasCreate.add("create");
aliasCreate.add("new");
aliasTag.add("tag");
aliasDescription.add("desc");
aliasChat.add("chat");
aliasChat.add("c");
aliasTitle.add("title");
aliasInvite.add("invite");
aliasInvite.add("inv");
aliasDeinvite.add("deinvite");
aliasDeinvite.add("deinv");
aliasOpen.add("open");
aliasOpen.add("close");
aliasKick.add("kick");
aliasModerator.add("mod");
aliasAdmin.add("admin");
aliasClaim.add("claim");
aliasUnclaim.add("unclaim");
aliasUnclaim.add("declaim");
aliasRelationAlly.add("ally");
aliasRelationNeutral.add("neutral");
aliasRelationEnemy.add("enemy");
aliasVersion.add("version");
aliasTrue.add("true");
aliasTrue.add("yes");
aliasTrue.add("y");
aliasTrue.add("ok");
aliasTrue.add("on");
aliasTrue.add("+");
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -53,6 +53,44 @@ public class Faction {
return this.id; return this.id;
} }
public boolean getOpen() {
return open;
}
public void setOpen(boolean isOpen) {
open = isOpen;
save();
}
public String getTag() {
return this.getTag("");
}
public String getTag(String prefix) {
return prefix+this.tag;
}
public String getTag(Faction otherFaction) {
return this.getTag(otherFaction.getRelationColor(this).toString());
}
public String getTag(FPlayer otherFollower) {
return this.getTag(otherFollower.getRelationColor(this).toString());
}
public void setTag(String str) {
if (Conf.factionTagForceUpperCase) {
str = str.toUpperCase();
}
this.tag = str;
save();
}
public String getDescription() {
return this.description;
}
public void setDescription(String value) {
this.description = value;
save();
}
// ------------------------------- // -------------------------------
// Invites // Invites
// ------------------------------- // -------------------------------
@ -106,49 +144,6 @@ public class Faction {
return getRelation(follower.getFaction()); return getRelation(follower.getFaction());
} }
// -------------------------------
// Information
// -------------------------------
public String getTag() {
return this.getTag("");
}
public String getTag(String prefix) {
return prefix+this.tag;
}
public String getTag(Faction otherFaction) {
return this.getTag(otherFaction.getRelationColor(this).toString());
}
public String getTag(FPlayer otherFollower) {
return this.getTag(otherFollower.getRelationColor(this).toString());
}
public void setTag(String str) {
if (Conf.factionTagForceUpperCase) {
str = str.toUpperCase();
}
this.tag = str;
this.save();
}
public String getDescription() {
return this.description;
}
public void setDescription(String value) {
this.description = value;
this.save();
}
public boolean getOpen() {
return open;
}
public void setOpen(boolean isOpen) {
open = isOpen;
this.save();
}
//----------------------------------------------// //----------------------------------------------//
// Power // Power
//----------------------------------------------// //----------------------------------------------//
@ -336,11 +331,10 @@ public class Faction {
if ( ! file.exists()) { if ( ! file.exists()) {
Factions.log("No factions to load from disk. Creating new file."); Factions.log("No factions to load from disk. Creating new file.");
save(); save();
return true;
} }
try { try {
Type type = new TypeToken<Map<String, Faction>>(){}.getType(); Type type = new TypeToken<Map<Integer, Faction>>(){}.getType();
instances = Factions.gson.fromJson(DiscUtil.read(file), type); instances = Factions.gson.fromJson(DiscUtil.read(file), type);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -4,6 +4,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -17,6 +18,29 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.bukkit.mcteam.factions.commands.FBaseCommand; import com.bukkit.mcteam.factions.commands.FBaseCommand;
import com.bukkit.mcteam.factions.commands.FCommandAdmin;
import com.bukkit.mcteam.factions.commands.FCommandChat;
import com.bukkit.mcteam.factions.commands.FCommandClaim;
import com.bukkit.mcteam.factions.commands.FCommandCreate;
import com.bukkit.mcteam.factions.commands.FCommandDeinvite;
import com.bukkit.mcteam.factions.commands.FCommandDescription;
import com.bukkit.mcteam.factions.commands.FCommandHelp;
import com.bukkit.mcteam.factions.commands.FCommandInvite;
import com.bukkit.mcteam.factions.commands.FCommandJoin;
import com.bukkit.mcteam.factions.commands.FCommandKick;
import com.bukkit.mcteam.factions.commands.FCommandLeave;
import com.bukkit.mcteam.factions.commands.FCommandList;
import com.bukkit.mcteam.factions.commands.FCommandMap;
import com.bukkit.mcteam.factions.commands.FCommandMod;
import com.bukkit.mcteam.factions.commands.FCommandOpen;
import com.bukkit.mcteam.factions.commands.FCommandRelationAlly;
import com.bukkit.mcteam.factions.commands.FCommandRelationEnemy;
import com.bukkit.mcteam.factions.commands.FCommandRelationNeutral;
import com.bukkit.mcteam.factions.commands.FCommandShow;
import com.bukkit.mcteam.factions.commands.FCommandTag;
import com.bukkit.mcteam.factions.commands.FCommandTitle;
import com.bukkit.mcteam.factions.commands.FCommandUnclaim;
import com.bukkit.mcteam.factions.commands.FCommandVersion;
import com.bukkit.mcteam.factions.listeners.FactionsBlockListener; import com.bukkit.mcteam.factions.listeners.FactionsBlockListener;
import com.bukkit.mcteam.factions.listeners.FactionsEntityListener; import com.bukkit.mcteam.factions.listeners.FactionsEntityListener;
import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener; import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener;
@ -49,30 +73,49 @@ public class Factions extends JavaPlugin {
// Commands // Commands
public List<FBaseCommand> commands = new ArrayList<FBaseCommand>(); public List<FBaseCommand> commands = new ArrayList<FBaseCommand>();
private String baseCommand;
public Factions() { public Factions() {
Factions.instance = this; Factions.instance = this;
// Add the commands
commands.add(new FCommandHelp());
commands.add(new FCommandAdmin());
commands.add(new FCommandChat());
commands.add(new FCommandClaim());
commands.add(new FCommandCreate());
commands.add(new FCommandDeinvite());
commands.add(new FCommandDescription());
commands.add(new FCommandInvite());
commands.add(new FCommandJoin());
commands.add(new FCommandKick());
commands.add(new FCommandLeave());
commands.add(new FCommandList());
commands.add(new FCommandMap());
commands.add(new FCommandMod());
commands.add(new FCommandOpen());
commands.add(new FCommandRelationAlly());
commands.add(new FCommandRelationEnemy());
commands.add(new FCommandRelationNeutral());
commands.add(new FCommandShow());
commands.add(new FCommandTag());
commands.add(new FCommandTitle());
commands.add(new FCommandUnclaim());
commands.add(new FCommandVersion());
} }
@Override @Override
public void onEnable() { public void onEnable() {
// Add the commands
/*commands.add(new VCommandBlood());
commands.add(new VCommandInfect());
commands.add(new VCommandLoad());
commands.add(new VCommandSave());
commands.add(new VCommandTime());
commands.add(new VCommandTurn());
commands.add(new VCommandCure());
commands.add(new VCommandList());
commands.add(new VCommandVersion());*/
setupPermissions();
setupHelp();
log("=== INIT START ==="); log("=== INIT START ===");
long timeInitStart = System.currentTimeMillis(); long timeInitStart = System.currentTimeMillis();
setupHelp();
setupPermissions();
// Ensure basefolder exists!
this.getDataFolder().mkdirs();
FPlayer.load(); FPlayer.load();
Faction.load(); Faction.load();
Board.load(); Board.load();
@ -97,8 +140,10 @@ public class Factions extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
// TODO Auto-generated method stub FPlayer.save();
Faction.save();
Board.save();
log("Disabled");
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -130,9 +175,7 @@ public class Factions extends JavaPlugin {
if (test != null) { if (test != null) {
helpPlugin = ((Help) test); helpPlugin = ((Help) test);
Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName()); Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName());
helpPlugin.registerCommand(this.getBaseCommand()+" help *[page]", "Factions plugin help.", helpPlugin, true);
// TODO not hardcoded:
helpPlugin.registerCommand("f help *[page]", "Factions plugin help.", helpPlugin, true);
} }
} }
@ -141,6 +184,17 @@ public class Factions extends JavaPlugin {
// Commands // Commands
// -------------------------------------------- // // -------------------------------------------- //
@SuppressWarnings("unchecked")
public String getBaseCommand() {
if (this.baseCommand != null) {
return this.baseCommand;
}
Map<String, Object> Commands = (Map<String, Object>)this.getDescription().getCommands();
this.baseCommand = Commands.keySet().iterator().next();
return this.baseCommand;
}
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
List<String> parameters = new ArrayList<String>(Arrays.asList(args)); List<String> parameters = new ArrayList<String>(Arrays.asList(args));
@ -164,8 +218,7 @@ public class Factions extends JavaPlugin {
} }
} }
sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try /help faction"); // TODO test help messages exists.... sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try "+Conf.colorCommand+"/f help");
//TODO should we use internal help system instead?
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -14,6 +14,8 @@ import com.bukkit.mcteam.factions.struct.Role;
import com.bukkit.mcteam.factions.util.TextUtil; import com.bukkit.mcteam.factions.util.TextUtil;
public class FBaseCommand { public class FBaseCommand {
public List<String> aliases;
public List<String> requiredParameters; public List<String> requiredParameters;
public List<String> optionalParameters; public List<String> optionalParameters;
@ -42,17 +44,7 @@ public class FBaseCommand {
helpDescription = "no description"; helpDescription = "no description";
} }
public ArrayList<String> getAliases() { public List<String> getAliases() {
String name = this.getClass().getName().toLowerCase();
if (name.lastIndexOf('.') > 0) {
name = name.substring(name.lastIndexOf('.')+1);
}
name = name.substring(8);
ArrayList<String> aliases = new ArrayList<String>();
aliases.add(name);
return aliases; return aliases;
} }
@ -66,7 +58,6 @@ public class FBaseCommand {
this.parameters = parameters; this.parameters = parameters;
if ( ! validateCall()) { if ( ! validateCall()) {
sendMessage("try /help factions");
return; return;
} }
@ -137,7 +128,7 @@ public class FBaseCommand {
// -------------------------------------------- // // -------------------------------------------- //
// Help and usage description // Help and usage description
// -------------------------------------------- // // -------------------------------------------- //
public String getUseageTemplate(boolean withColor) { public String getUseageTemplate(boolean withColor, boolean withDescription) {
String ret = ""; String ret = "";
if (withColor) { if (withColor) {
@ -161,9 +152,17 @@ public class FBaseCommand {
} }
ret += TextUtil.implode(parts, " "); ret += TextUtil.implode(parts, " ");
if (withDescription) {
ret += " "+Conf.colorSystem + this.helpDescription;
}
return ret; return ret;
} }
public String getUseageTemplate(boolean withColor) {
return getUseageTemplate(withColor, false);
}
public String getUseageTemplate() { public String getUseageTemplate() {
return getUseageTemplate(true); return getUseageTemplate(true);
} }
@ -260,4 +259,16 @@ public class FBaseCommand {
return false; 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());
}
} }

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandAdmin extends FBaseCommand { public class FCommandAdmin extends FBaseCommand {
public FCommandAdmin() { public FCommandAdmin() {
aliases = new ArrayList<String>();
aliases.add("admin");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");

View File

@ -5,6 +5,10 @@ import java.util.ArrayList;
public class FCommandChat extends FBaseCommand { public class FCommandChat extends FBaseCommand {
public FCommandChat() { public FCommandChat() {
aliases = new ArrayList<String>();
aliases.add("chat");
aliases.add("c");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -12,6 +12,9 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandClaim extends FBaseCommand { public class FCommandClaim extends FBaseCommand {
public FCommandClaim() { public FCommandClaim() {
aliases = new ArrayList<String>();
aliases.add("claim");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandCreate extends FBaseCommand { public class FCommandCreate extends FBaseCommand {
public FCommandCreate() { public FCommandCreate() {
aliases = new ArrayList<String>();
aliases.add("create");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("faction tag"); requiredParameters.add("faction tag");
@ -51,8 +54,8 @@ public class FCommandCreate extends FBaseCommand {
follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower)); follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower));
} }
sendMessage("Now update your faction description. Use:"); sendMessage("You should now:");
sendMessage(Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasDescription.get(0)+" "+"[description]"); sendMessage( new FCommandDescription().getUseageTemplate() );
} }
} }

View File

@ -10,6 +10,10 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandDeinvite extends FBaseCommand { public class FCommandDeinvite extends FBaseCommand {
public FCommandDeinvite() { public FCommandDeinvite() {
aliases = new ArrayList<String>();
aliases.add("deinvite");
aliases.add("deinv");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");
@ -41,6 +45,7 @@ public class FCommandDeinvite extends FBaseCommand {
if (you.getFaction() == myFaction) { if (you.getFaction() == myFaction) {
sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); sendMessage(you.getName()+" is already a member of "+myFaction.getTag());
sendMessage(new FCommandKick().getUseageTemplate());
return; return;
} }

View File

@ -10,9 +10,12 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandDescription extends FBaseCommand { public class FCommandDescription extends FBaseCommand {
public FCommandDescription() { public FCommandDescription() {
aliases = new ArrayList<String>();
aliases.add("desc");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("description"); requiredParameters.add("desc");
permissions = ""; permissions = "";

View File

@ -8,6 +8,11 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandHelp extends FBaseCommand { public class FCommandHelp extends FBaseCommand {
public FCommandHelp() { public FCommandHelp() {
aliases = new ArrayList<String>();
aliases.add("help");
aliases.add("h");
aliases.add("?");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
optionalParameters.add("page"); optionalParameters.add("page");
@ -48,36 +53,36 @@ public class FCommandHelp extends FBaseCommand {
ArrayList<String> pageLines; ArrayList<String> pageLines;
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandHelp().getUseageTemplate() ); pageLines.add( new FCommandHelp().getUseageTemplate(true, true) );
pageLines.add( new FCommandList().getUseageTemplate() ); pageLines.add( new FCommandList().getUseageTemplate(true, true) );
pageLines.add( new FCommandShow().getUseageTemplate() ); pageLines.add( new FCommandShow().getUseageTemplate(true, true) );
pageLines.add( new FCommandMap().getUseageTemplate() ); pageLines.add( new FCommandMap().getUseageTemplate(true, true) );
pageLines.add( new FCommandJoin().getUseageTemplate() ); pageLines.add( new FCommandJoin().getUseageTemplate(true, true) );
pageLines.add( new FCommandLeave().getUseageTemplate() ); pageLines.add( new FCommandLeave().getUseageTemplate(true, true) );
pageLines.add( new FCommandChat().getUseageTemplate() ); pageLines.add( new FCommandChat().getUseageTemplate(true, true) );
pageLines.add( new FCommandCreate().getUseageTemplate() ); pageLines.add( new FCommandCreate().getUseageTemplate(true, true) );
pageLines.add( new FCommandTag().getUseageTemplate() ); pageLines.add( new FCommandTag().getUseageTemplate(true, true) );
pageLines.add( new FCommandDescription().getUseageTemplate() ); pageLines.add( new FCommandDescription().getUseageTemplate(true, true) );
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandOpen().getUseageTemplate() ); pageLines.add( new FCommandOpen().getUseageTemplate(true, true) );
pageLines.add( new FCommandTitle().getUseageTemplate() ); pageLines.add( new FCommandTitle().getUseageTemplate(true, true) );
pageLines.add( new FCommandInvite().getUseageTemplate() ); pageLines.add( new FCommandInvite().getUseageTemplate(true, true) );
pageLines.add( new FCommandDeinvite().getUseageTemplate() ); pageLines.add( new FCommandDeinvite().getUseageTemplate(true, true) );
pageLines.add( new FCommandClaim().getUseageTemplate() ); pageLines.add( new FCommandClaim().getUseageTemplate(true, true) );
pageLines.add( new FCommandUnclaim().getUseageTemplate() ); pageLines.add( new FCommandUnclaim().getUseageTemplate(true, true) );
pageLines.add( new FCommandKick().getUseageTemplate() ); pageLines.add( new FCommandKick().getUseageTemplate(true, true) );
pageLines.add( new FCommandMod().getUseageTemplate() ); pageLines.add( new FCommandMod().getUseageTemplate(true, true) );
pageLines.add( new FCommandAdmin().getUseageTemplate() ); pageLines.add( new FCommandAdmin().getUseageTemplate(true, true) );
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandRelationAlly().getUseageTemplate() ); pageLines.add( new FCommandRelationAlly().getUseageTemplate(true, true) );
pageLines.add( new FCommandRelationNeutral().getUseageTemplate() ); pageLines.add( new FCommandRelationNeutral().getUseageTemplate(true, true) );
pageLines.add( new FCommandRelationEnemy().getUseageTemplate() ); pageLines.add( new FCommandRelationEnemy().getUseageTemplate(true, true) );
pageLines.add(""); pageLines.add("");
pageLines.add(Conf.colorSystem+"Set the relation you WISH to have with another faction."); pageLines.add(Conf.colorSystem+"Set the relation you WISH to have with another faction.");
pageLines.add(Conf.colorSystem+"Your default relation with other factions will be neutral."); pageLines.add(Conf.colorSystem+"Your default relation with other factions will be neutral.");
@ -114,7 +119,7 @@ public class FCommandHelp extends FBaseCommand {
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandVersion().getUseageTemplate() ); pageLines.add( new FCommandVersion().getUseageTemplate(true, true) );
helpPages.add(pageLines); helpPages.add(pageLines);
} }

View File

@ -10,6 +10,10 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandInvite extends FBaseCommand { public class FCommandInvite extends FBaseCommand {
public FCommandInvite() { public FCommandInvite() {
aliases = new ArrayList<String>();
aliases.add("invite");
aliases.add("inv");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");
@ -41,7 +45,8 @@ public class FCommandInvite extends FBaseCommand {
if (you.getFaction() == myFaction) { if (you.getFaction() == myFaction) {
sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); sendMessage(you.getName()+" is already a member of "+myFaction.getTag());
sendMessage("You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasKick.get(0)+Conf.colorParameter+" "+you.getName()); sendMessage("You might want to :");
sendMessage(new FCommandKick().getUseageTemplate());
return; return;
} }

View File

@ -9,6 +9,9 @@ import com.bukkit.mcteam.factions.Faction;
public class FCommandJoin extends FBaseCommand { public class FCommandJoin extends FBaseCommand {
public FCommandJoin() { public FCommandJoin() {
aliases = new ArrayList<String>();
aliases.add("join");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("faction name"); requiredParameters.add("faction name");

View File

@ -9,6 +9,9 @@ import com.bukkit.mcteam.factions.Faction;
public class FCommandKick extends FBaseCommand { public class FCommandKick extends FBaseCommand {
public FCommandKick() { public FCommandKick() {
aliases = new ArrayList<String>();
aliases.add("kick");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");
@ -37,7 +40,8 @@ public class FCommandKick extends FBaseCommand {
if (me == you) { if (me == you) {
sendMessage("You cannot kick yourself."); sendMessage("You cannot kick yourself.");
sendMessage("You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasLeave.get(0)); sendMessage("You might want to:");
sendMessage(new FCommandLeave().getUseageTemplate());
return; return;
} }

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandLeave extends FBaseCommand { public class FCommandLeave extends FBaseCommand {
public FCommandLeave() { public FCommandLeave() {
aliases = new ArrayList<String>();
aliases.add("leave");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -11,6 +11,10 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandList extends FBaseCommand { public class FCommandList extends FBaseCommand {
public FCommandList() { public FCommandList() {
aliases = new ArrayList<String>();
aliases.add("list");
aliases.add("ls");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
optionalParameters.add("page"); optionalParameters.add("page");

View File

@ -3,12 +3,14 @@ package com.bukkit.mcteam.factions.commands;
import java.util.ArrayList; import java.util.ArrayList;
import com.bukkit.mcteam.factions.Board; import com.bukkit.mcteam.factions.Board;
import com.bukkit.mcteam.factions.Conf;
import com.bukkit.mcteam.factions.FLocation; import com.bukkit.mcteam.factions.FLocation;
public class FCommandMap extends FBaseCommand { public class FCommandMap extends FBaseCommand {
public FCommandMap() { public FCommandMap() {
aliases = new ArrayList<String>();
aliases.add("map");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
optionalParameters.add("on|off"); optionalParameters.add("on|off");
@ -23,7 +25,7 @@ public class FCommandMap extends FBaseCommand {
public void perform() { public void perform() {
if (parameters.size() > 0) { if (parameters.size() > 0) {
String mapAutoUpdating = parameters.get(0); String mapAutoUpdating = parameters.get(0);
if (Conf.aliasTrue.contains(mapAutoUpdating.toLowerCase())) { if (parseBool(mapAutoUpdating)) {
// Turn on // Turn on
me.setMapAutoUpdating(true); me.setMapAutoUpdating(true);
sendMessage("Map auto update ENABLED."); sendMessage("Map auto update ENABLED.");

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandMod extends FBaseCommand { public class FCommandMod extends FBaseCommand {
public FCommandMod() { public FCommandMod() {
aliases = new ArrayList<String>();
aliases.add("mod");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");

View File

@ -9,6 +9,10 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandOpen extends FBaseCommand { public class FCommandOpen extends FBaseCommand {
public FCommandOpen() { public FCommandOpen() {
aliases = new ArrayList<String>();
aliases.add("open");
aliases.add("close");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -1,9 +1,16 @@
package com.bukkit.mcteam.factions.commands; package com.bukkit.mcteam.factions.commands;
import java.util.ArrayList;
import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Relation;
public class FCommandRelationAlly extends FRelationCommand { public class FCommandRelationAlly extends FRelationCommand {
public FCommandRelationAlly() {
aliases = new ArrayList<String>();
aliases.add("ally");
}
public void perform() { public void perform() {
relation(Relation.ALLY, parameters.get(0)); relation(Relation.ALLY, parameters.get(0));
} }

View File

@ -1,9 +1,16 @@
package com.bukkit.mcteam.factions.commands; package com.bukkit.mcteam.factions.commands;
import java.util.ArrayList;
import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Relation;
public class FCommandRelationEnemy extends FRelationCommand { public class FCommandRelationEnemy extends FRelationCommand {
public FCommandRelationEnemy() {
aliases = new ArrayList<String>();
aliases.add("enemy");
}
public void perform() { public void perform() {
relation(Relation.ENEMY, parameters.get(0)); relation(Relation.ENEMY, parameters.get(0));
} }

View File

@ -1,9 +1,16 @@
package com.bukkit.mcteam.factions.commands; package com.bukkit.mcteam.factions.commands;
import java.util.ArrayList;
import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Relation;
public class FCommandRelationNeutral extends FRelationCommand { public class FCommandRelationNeutral extends FRelationCommand {
public FCommandRelationNeutral() {
aliases = new ArrayList<String>();
aliases.add("neutral");
}
public void perform() { public void perform() {
relation(Relation.NEUTRAL, parameters.get(0)); relation(Relation.NEUTRAL, parameters.get(0));
} }

View File

@ -13,6 +13,10 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandShow extends FBaseCommand { public class FCommandShow extends FBaseCommand {
public FCommandShow() { public FCommandShow() {
aliases = new ArrayList<String>();
aliases.add("show");
aliases.add("who");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
optionalParameters.add("faction tag"); optionalParameters.add("faction tag");

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandTag extends FBaseCommand { public class FCommandTag extends FBaseCommand {
public FCommandTag() { public FCommandTag() {
aliases = new ArrayList<String>();
aliases.add("tag");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("faction tag"); requiredParameters.add("faction tag");

View File

@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FCommandTitle extends FBaseCommand { public class FCommandTitle extends FBaseCommand {
public FCommandTitle() { public FCommandTitle() {
aliases = new ArrayList<String>();
aliases.add("title");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("player name"); requiredParameters.add("player name");

View File

@ -11,6 +11,10 @@ import com.bukkit.mcteam.factions.struct.Role;
public class FCommandUnclaim extends FBaseCommand { public class FCommandUnclaim extends FBaseCommand {
public FCommandUnclaim() { public FCommandUnclaim() {
aliases = new ArrayList<String>();
aliases.add("unclaim");
aliases.add("declaim");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -7,6 +7,9 @@ import com.bukkit.mcteam.factions.Factions;
public class FCommandVersion extends FBaseCommand { public class FCommandVersion extends FBaseCommand {
public FCommandVersion() { public FCommandVersion() {
aliases = new ArrayList<String>();
aliases.add("version");
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();

View File

@ -6,6 +6,7 @@ import org.bukkit.ChatColor;
import com.bukkit.mcteam.factions.Conf; import com.bukkit.mcteam.factions.Conf;
import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.Faction;
import com.bukkit.mcteam.factions.Factions;
import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Relation;
import com.bukkit.mcteam.factions.struct.Role; import com.bukkit.mcteam.factions.struct.Role;
@ -15,7 +16,7 @@ public class FRelationCommand extends FBaseCommand {
requiredParameters = new ArrayList<String>(); requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
requiredParameters.add("faction tag"); requiredParameters.add("faction tag");
helpDescription = "Declare your factions relation wish to another faction"; helpDescription = "Set relation wish to another faction";
permissions = ""; permissions = "";
senderMustBePlayer = true; senderMustBePlayer = true;
@ -54,7 +55,7 @@ public class FRelationCommand extends FBaseCommand {
myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag()); myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag());
} else { } else {
otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " wishes to be your "+whishedRelation.getColor()+whishedRelation.toString()); otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " wishes to be your "+whishedRelation.getColor()+whishedRelation.toString());
otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept."); 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); myFaction.sendMessage(currentRelationColor+otherFaction.getTag()+Conf.colorSystem+ " were informed that you wish to be "+whishedRelation.getColor()+whishedRelation);
} }
} }

View File

@ -1,10 +1,14 @@
package com.bukkit.mcteam.factions.listeners; package com.bukkit.mcteam.factions.listeners;
import java.util.*; import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerItemEvent;
@ -13,6 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import com.bukkit.mcteam.factions.Board; import com.bukkit.mcteam.factions.Board;
import com.bukkit.mcteam.factions.Conf; import com.bukkit.mcteam.factions.Conf;
import com.bukkit.mcteam.factions.FLocation;
import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.FPlayer;
import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.Faction;
import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.Factions;
@ -21,43 +26,31 @@ import com.bukkit.mcteam.factions.util.TextUtil;
public class FactionsPlayerListener extends PlayerListener{ public class FactionsPlayerListener extends PlayerListener{
/**
* If someone says something that starts with the factions base command
* we handle that command.
*/
@Override
public void onPlayerCommandPreprocess(PlayerChatEvent event) {
Player player = event.getPlayer();
String msg = event.getMessage();
if (handleCommandOrChat(player, msg)) {
event.setCancelled(true);
}
}
@Override @Override
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) {
List<String> parameters = TextUtil.split(event.getMessage().trim());
parameters.remove(0);
CommandSender sender = event.getPlayer();
Factions.instance.handleCommand(sender, parameters);
event.setCancelled(true);
return;
}
if (event.isCancelled()) { if (event.isCancelled()) {
return; // Some other plugin ate this... return;
} }
Player talkingPlayer = event.getPlayer(); Player talkingPlayer = event.getPlayer();
String msg = event.getMessage(); String msg = event.getMessage();
// Is this a faction command?...
if ( handleCommandOrChat(talkingPlayer, msg) ) {
// ... Yes it was! We should choke the chat message.
event.setCancelled(true);
return;
}
// ... it was not a command. This means that it is a chat message! // ... it was not a command. This means that it is a chat message!
FPlayer me = FPlayer.get(talkingPlayer); FPlayer me = FPlayer.get(talkingPlayer);
// Is it a faction chat message? // Is it a faction chat message?
if (me.isFactionChatting()) { if (me.isFactionChatting()) {
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg); String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
me.getFaction().sendMessage(message, false); me.getFaction().sendMessage(message);
Logger.getLogger("Minecraft").info("FactionChat "+me.getFaction().getTag()+": "+message); Logger.getLogger("Minecraft").info("FactionChat "+me.getFaction().getTag()+": "+message);
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -95,27 +88,16 @@ public class FactionsPlayerListener extends PlayerListener{
} }
} }
public boolean handleCommandOrChat(Player player, String msg) {
ArrayList<String> tokens = TextUtil.split(msg.trim());
if (Conf.aliasBase.contains(tokens.get(0))) {
tokens.remove(0);
FPlayer follower = FPlayer.get(player);
Commands.base(follower, tokens);
return true;
}
return false;
}
@Override @Override
public void onPlayerJoin(PlayerEvent event) { public void onPlayerJoin(PlayerEvent event) {
//Follower.get(event.getPlayer()).sendJoinInfo(); // Make sure that all online players do have a fplayer.
FPlayer.get(event.getPlayer());
} }
@Override @Override
public void onPlayerQuit(PlayerEvent event) { public void onPlayerQuit(PlayerEvent event) {
FPlayer follower = FPlayer.get(event.getPlayer()); // Save all players on player quit.
Log.debug("Saved follower on player quit: "+follower.getName()); FPlayer.save();
follower.save(); // We save the followers on logout in order to save their non autosaved state like power.
} }
@Override @Override
@ -123,22 +105,23 @@ public class FactionsPlayerListener extends PlayerListener{
FPlayer me = FPlayer.get(event.getPlayer()); FPlayer me = FPlayer.get(event.getPlayer());
// Did we change coord? // Did we change coord?
Coord coordFrom = me.lastStoodAt; FLocation from = me.getLastStoodAt();
Coord coordTo = Coord.from(event.getTo()); FLocation to = new FLocation(event.getTo());
if (coordFrom.equals(coordTo)) {
if (from.equals(to)) {
return; return;
} }
// Yes we did change coord (: // Yes we did change coord (:
me.lastStoodAt = coordTo;
Board board = Board.get(event.getPlayer().getWorld()); me.setLastStoodAt(to);
if (me.isMapAutoUpdating()) { if (me.isMapAutoUpdating()) {
me.sendMessage(board.getMap(me.getFaction(), Coord.from(me), me.getPlayer().getLocation().getYaw()), false); me.sendMessage(Board.getMap(me.getFaction(), to, me.getPlayer().getLocation().getYaw()));
} else { } else {
// Did we change "host"(faction)? // Did we change "host"(faction)?
Faction factionFrom = board.getFactionAt(coordFrom); Faction factionFrom = Board.getFactionAt(from);
Faction factionTo = board.getFactionAt(coordTo); Faction factionTo = Board.getFactionAt(to);
if ( factionFrom != factionTo) { if ( factionFrom != factionTo) {
me.sendFactionHereMessage(); me.sendFactionHereMessage();
} }
@ -147,17 +130,15 @@ public class FactionsPlayerListener extends PlayerListener{
@Override @Override
public void onPlayerItem(PlayerItemEvent event) { public void onPlayerItem(PlayerItemEvent event) {
// debug if (event.isCancelled()) {
//event.getPlayer().sendMessage("Item in hand: " + event.getItem().getTypeId() + " Block clicked: " + event.getBlockClicked().getTypeId() + "(" + event.getBlockClicked().getType().toString() + ")");
if (event.isCancelled())
return; return;
}
if (event.getBlockClicked() == null) if (event.getBlockClicked() == null) {
return; // right-clicked on air, not a block; no worries then return; // right-clicked on air, not a block; no worries then
}
if (!this.playerCanUseItemHere(event.getPlayer(), event.getBlockClicked(), event.getItem().getTypeId())) if ( ! this.playerCanUseItemHere(event.getPlayer(), event.getBlockClicked(), event.getItem().getTypeId())) {
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -175,10 +156,9 @@ public class FactionsPlayerListener extends PlayerListener{
return true; // Item isn't one we're preventing. return true; // Item isn't one we're preventing.
} }
Coord coord = Coord.parseCoord(block); Faction otherFaction = Board.getFactionAt(new FLocation(block));
Faction otherFaction = Board.get(player.getWorld()).getFactionAt(coord);
if (otherFaction == null || otherFaction.id == 0) { if (otherFaction == null || otherFaction.getId() == 0) {
return true; // This is not faction territory. Use whatever you like here. return true; // This is not faction territory. Use whatever you like here.
} }
@ -187,7 +167,7 @@ public class FactionsPlayerListener extends PlayerListener{
// Cancel if we are not in our own territory // Cancel if we are not in our own territory
if (myFaction != otherFaction) { if (myFaction != otherFaction) {
me.sendMessage(Conf.colorSystem+"You can't use that in the territory of "+otherFaction.getTag(myFaction)); me.sendMessage("You can't use that in the territory of "+otherFaction.getTag(myFaction));
return false; return false;
} }