From 80d132af70bc75abeed9c8608e1ca1e4c5ed66e3 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 10 Oct 2011 14:21:22 +0200 Subject: [PATCH] Added forgotten type adapters. --- src/com/massivecraft/factions/P.java | 129 ++---------------- .../factions/cmd/CmdDeinvite.java | 2 +- .../factions/cmd/CmdDescription.java | 1 + .../massivecraft/factions/cmd/CmdInvite.java | 2 +- .../massivecraft/factions/cmd/CmdKick.java | 2 +- .../massivecraft/factions/zcore/MCommand.java | 3 +- 6 files changed, 16 insertions(+), 123 deletions(-) diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 4a177491..76e1908a 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -1,7 +1,9 @@ package com.massivecraft.factions; import java.lang.reflect.Modifier; +import java.lang.reflect.Type; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.bukkit.block.Block; @@ -22,11 +24,14 @@ import com.massivecraft.factions.listeners.FactionsChatEarlyListener; import com.massivecraft.factions.listeners.FactionsEntityListener; import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.struct.ChatMode; +import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter; +import com.massivecraft.factions.util.MyLocationTypeAdapter; import com.massivecraft.factions.zcore.MPlugin; import com.nijiko.permissions.PermissionHandler; import com.earth2me.essentials.chat.EssentialsChat; import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.integration.EssentialsFeatures; public class P extends MPlugin @@ -121,10 +126,14 @@ public class P extends MPlugin @Override public GsonBuilder getGsonBuilder() { + Type mapFLocToStringSetType = new TypeToken>>(){}.getType(); + return new GsonBuilder() .setPrettyPrinting() .disableHtmlEscaping() - .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE); + .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) + .registerTypeAdapter(Location.class, new MyLocationTypeAdapter()) + .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()); } @Override @@ -330,122 +339,4 @@ public class P extends MPlugin { return FactionsPlayerListener.playerCanUseItemHere(player, location, material, true); } - - // -------------------------------------------- // - // Test rights - // -------------------------------------------- // - /* - public static boolean hasPermParticipate(CommandSender sender) { - return hasPerm(sender, "factions.participate"); - } - - public static boolean hasPermCreate(CommandSender sender) { - return hasPerm(sender, "factions.create"); - } - - public static boolean hasPermManageSafeZone(CommandSender sender) { - return hasPerm(sender, "factions.manageSafeZone"); - } - - public static boolean hasPermManageWarZone(CommandSender sender) { - return hasPerm(sender, "factions.manageWarZone"); - } - - public static boolean hasPermAdminBypass(CommandSender sender) { - return hasPerm(sender, "factions.adminBypass"); - } - - public static boolean hasPermReload(CommandSender sender) { - return hasPerm(sender, "factions.reload"); - } - - public static boolean hasPermSaveAll(CommandSender sender) { - return hasPerm(sender, "factions.saveall"); - } - - public static boolean hasPermLock(CommandSender sender) { - return hasPerm(sender, "factions.lock"); - } - - public static boolean hasPermConfigure(CommandSender sender) { - return hasPerm(sender, "factions.config"); - } - - public static boolean hasPermDisband(CommandSender sender) { - return hasPerm(sender, "factions.disband"); - } - - public static boolean hasPermViewAnyPower(CommandSender sender) { - return hasPerm(sender, "factions.viewAnyPower"); - } - - public static boolean hasPermOwnershipBypass(CommandSender sender) { - return hasPerm(sender, "factions.ownershipBypass"); - } - - public static boolean hasPermSetPeaceful(CommandSender sender) { - return hasPerm(sender, "factions.setPeaceful"); - } - - public static boolean hasPermSetPermanent(CommandSender sender) { - return hasPerm(sender, "factions.setPermanent"); - } - - public static boolean hasPermPeacefulExplosionToggle(CommandSender sender) { - return hasPerm(sender, "factions.peacefulExplosionToggle"); - } - - public static boolean hasPermViewAnyFactionBalance(CommandSender sender) { - return hasPerm(sender, "factions.viewAnyFactionBalance"); - } - - public static boolean isCommandDisabled(CommandSender sender, String command) { - return (hasPerm(sender, "factions.commandDisable."+command) && !hasPerm(sender, "factions.commandDisable.none")); - } - - private static boolean hasPerm(CommandSender sender, String permNode) { - if (P.Permissions == null || ! (sender instanceof Player)) { - return sender.isOp() || sender.hasPermission(permNode); - } - - Player player = (Player)sender; - return P.Permissions.has(player, permNode); - } - */ - // -------------------------------------------- // - // Commands - // -------------------------------------------- // - /* - @Override - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) - { - List parameters = new ArrayList(Arrays.asList(args)); - this.handleCommand(sender, parameters); - return true; - } - - public void handleCommand(CommandSender sender, List parameters) - { - if (parameters.size() == 0) - { - this.commands.get(0).execute(sender, parameters); - return; - } - - String commandName = parameters.get(0).toLowerCase(); - parameters.remove(0); - - for (FBaseCommand fcommand : this.commands) - { - if (fcommand.getAliases().contains(commandName)) - { - fcommand.execute(sender, parameters); - return; - } - } - - sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try "+Conf.colorCommand+"/"+this.getBaseCommand()+" help"); - } - */ - } diff --git a/src/com/massivecraft/factions/cmd/CmdDeinvite.java b/src/com/massivecraft/factions/cmd/CmdDeinvite.java index c004561d..c92ce4ca 100644 --- a/src/com/massivecraft/factions/cmd/CmdDeinvite.java +++ b/src/com/massivecraft/factions/cmd/CmdDeinvite.java @@ -33,7 +33,7 @@ public class CmdDeinvite extends FCommand if (you.getFaction() == myFaction) { msg("%s is already a member of %s", you.getName(), myFaction.getTag()); - msg("You might want to: %s", new CmdKick().getUseageTemplate(false)); + msg("You might want to: %s", p.cmdBase.cmdKick.getUseageTemplate(false)); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdDescription.java b/src/com/massivecraft/factions/cmd/CmdDescription.java index cd476bad..a1aee2be 100644 --- a/src/com/massivecraft/factions/cmd/CmdDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdDescription.java @@ -14,6 +14,7 @@ public class CmdDescription extends FCommand this.aliases.add("desc"); this.requiredArgs.add("desc"); + this.errorOnToManyArgs = false; //this.optionalArgs this.permission = Permission.DESCRIPTION.node; diff --git a/src/com/massivecraft/factions/cmd/CmdInvite.java b/src/com/massivecraft/factions/cmd/CmdInvite.java index c9db369a..a58f7e32 100644 --- a/src/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdInvite.java @@ -33,7 +33,7 @@ public class CmdInvite extends FCommand if (you.getFaction() == myFaction) { msg("%s is already a member of %s", you.getName(), myFaction.getTag()); - msg("You might want to: " + new CmdKick().getUseageTemplate(false)); + msg("You might want to: " + p.cmdBase.cmdKick.getUseageTemplate(false)); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index 78ef0824..e0609e87 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -35,7 +35,7 @@ public class CmdKick extends FCommand if (fme == you) { msg("You cannot kick yourself."); - msg("You might want to: %s", new CmdLeave().getUseageTemplate(false)); + msg("You might want to: %s", p.cmdBase.cmdLeave.getUseageTemplate(false)); return; } diff --git a/src/com/massivecraft/factions/zcore/MCommand.java b/src/com/massivecraft/factions/zcore/MCommand.java index 63180d96..c51bb476 100644 --- a/src/com/massivecraft/factions/zcore/MCommand.java +++ b/src/com/massivecraft/factions/zcore/MCommand.java @@ -32,6 +32,7 @@ public abstract class MCommand // Information on the args public List requiredArgs; public LinkedHashMap optionalArgs; + public boolean errorOnToManyArgs = true; // FIELD: Help Short // This field may be left blank and will in such case be loaded from the permissions node instead. @@ -198,7 +199,7 @@ public abstract class MCommand return false; } - if (args.size() > this.requiredArgs.size() + this.optionalArgs.size()) + if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs) { if (sender != null) {