From ca6b185bd1ee4324bd115e1cbae5dc38aa6d94b1 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 9 May 2012 03:24:07 +0200 Subject: [PATCH] New cape system and refactored spout appearances. --- plugin.yml | 22 +- src/com/massivecraft/factions/Conf.java | 7 +- src/com/massivecraft/factions/FPlayer.java | 9 +- src/com/massivecraft/factions/Faction.java | 5 + src/com/massivecraft/factions/P.java | 2 +- .../factions/cmd/CapeCommand.java | 52 ++ .../massivecraft/factions/cmd/CmdCape.java | 36 ++ .../massivecraft/factions/cmd/CmdCapeGet.java | 25 + .../factions/cmd/CmdCapeRemove.java | 35 ++ .../massivecraft/factions/cmd/CmdCapeSet.java | 49 ++ .../massivecraft/factions/cmd/CmdConfig.java | 3 +- .../massivecraft/factions/cmd/CmdDisband.java | 3 +- .../massivecraft/factions/cmd/CmdInvite.java | 3 + .../massivecraft/factions/cmd/CmdKick.java | 2 +- src/com/massivecraft/factions/cmd/CmdTag.java | 2 +- .../massivecraft/factions/cmd/CmdTitle.java | 2 +- .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/cmd/FRelationCommand.java | 2 +- .../factions/integration/SpoutFeatures.java | 454 ++++++++---------- .../integration/SpoutMainListener.java | 3 +- .../listeners/FactionsHealthBarListener.java | 2 +- .../listeners/FactionsPlayerListener.java | 12 +- .../listeners/FactionsServerListener.java | 14 +- .../massivecraft/factions/struct/FPerm.java | 3 + .../factions/struct/Permission.java | 6 +- 25 files changed, 446 insertions(+), 309 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CapeCommand.java create mode 100644 src/com/massivecraft/factions/cmd/CmdCape.java create mode 100644 src/com/massivecraft/factions/cmd/CmdCapeGet.java create mode 100644 src/com/massivecraft/factions/cmd/CmdCapeRemove.java create mode 100644 src/com/massivecraft/factions/cmd/CmdCapeSet.java diff --git a/plugin.yml b/plugin.yml index 48542d55..64093aa3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -35,9 +35,7 @@ permissions: children: factions.kit.fullplayer: true factions.adminmode: true - factions.chatspy: true factions.kit.fullplayer: - default: true description: Can also create new factions. children: factions.kit.halfplayer: true @@ -46,7 +44,8 @@ permissions: description: Can do all but create factions. children: factions.autoclaim: true - factions.chat: true + factions.cape: true + factions.cape.*: true factions.claim: true factions.deinvite: true factions.description: true @@ -78,12 +77,21 @@ permissions: factions.version: true factions.adminmode: description: enable admin bypass mode - factions.chatspy: - description: enable admin chat spy mode factions.autoclaim: description: auto-claim land as you walk around - factions.chat: - description: change chat mode + factions.cape: + description: manage faction capes + factions.cape.*: + children: + factions.cape.get: true + factions.cape.set: true + factions.cape.remove: true + factions.cape.get: + description: get faction cape + factions.cape.set: + description: set faction cape + factions.cape.remove: + description: remove faction cape factions.claim: description: claim land where you are standing factions.config: diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 0e81a3c4..6514dc8d 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -177,8 +177,7 @@ public class Conf public static String spoutHealthBarColorTag = "{c}"; public static int spoutHealthBarWidth = 30; public static Map spoutHealthBarColorUnderQuota = new LinkedHashMap(); - public static boolean spoutFactionLeaderCapes = true; // Show capes on faction admins, colored based on the viewer's relation to the target player - public static boolean spoutFactionOfficerCapes = true; // same, but for faction moderators + public static boolean spoutCapes = true; // Show faction capes public static int spoutTerritoryDisplayPosition = 3; // permanent territory display, instead of by chat; 0 = disabled, 1 = top left, 2 = top center, 3+ = top right public static float spoutTerritoryDisplaySize = 1.0f; // text scale (size) for territory display public static boolean spoutTerritoryDisplayShowDescription = true; // whether to show the faction description, not just the faction tag @@ -188,11 +187,11 @@ public class Conf public static boolean spoutTerritoryNoticeShowDescription = false; // whether to show the faction description in the notice, not just the faction tag public static float spoutTerritoryNoticeSize = 1.5f; // text scale (size) for notice public static float spoutTerritoryNoticeLeaveAfterSeconds = 2.00f; // how many seconds before the notice goes away - public static String capeAlly = "https://github.com/MassiveCraft/Factions/raw/master/capes/ally.png"; + /*public static String capeAlly = "https://github.com/MassiveCraft/Factions/raw/master/capes/ally.png"; public static String capeEnemy = "https://github.com/MassiveCraft/Factions/raw/master/capes/enemy.png"; public static String capeMember = "https://github.com/MassiveCraft/Factions/raw/master/capes/member.png"; public static String capeNeutral = "https://github.com/MassiveCraft/Factions/raw/master/capes/neutral.png"; - public static String capePeaceful = "https://github.com/MassiveCraft/Factions/raw/master/capes/peaceful.png"; + public static String capePeaceful = "https://github.com/MassiveCraft/Factions/raw/master/capes/peaceful.png";*/ // Economy settings public static boolean econEnabled = false; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 4f713da6..c4ffcedc 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -53,13 +53,14 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator if (oldFaction != null) oldFaction.removeFPlayer(this); faction.addFPlayer(this); this.factionId = faction.getId(); - SpoutFeatures.updateAppearances(this.getPlayer()); + SpoutFeatures.updateTitle(this, null); + SpoutFeatures.updateTitle(null, this); } // FIELD: role private Rel role; public Rel getRole() { return this.role; } - public void setRole(Rel role) { this.role = role; SpoutFeatures.updateAppearances(this.getPlayer()); } + public void setRole(Rel role) { this.role = role; SpoutFeatures.updateTitle(this, null); } // FIELD: title private String title; @@ -141,7 +142,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator if (doSpoutUpdate) { - SpoutFeatures.updateAppearances(this.getPlayer()); + SpoutFeatures.updateTitle(this, null); + SpoutFeatures.updateTitle(null, this); + SpoutFeatures.updateCape(this.getPlayer(), null); } } diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 2ade2b94..1902f4c9 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -95,6 +95,11 @@ public class Faction extends Entity implements EconomyParticipator return aid; } + + // FIELD: cape + private String cape; + public String getCape() { return cape; } + public void setCape(String val) { this.cape = val; } // FIELD: powerBoost // special increase/decrease to default and max power for this faction diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index c390c8e0..d488a373 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -97,8 +97,8 @@ public class P extends MPlugin Board.load(); // Add Base Commands - this.cmdBase = new FCmdRoot(); this.cmdAutoHelp = new CmdAutoHelp(); + this.cmdBase = new FCmdRoot(); this.getBaseCommands().add(cmdBase); EssentialsFeatures.setup(); diff --git a/src/com/massivecraft/factions/cmd/CapeCommand.java b/src/com/massivecraft/factions/cmd/CapeCommand.java new file mode 100644 index 00000000..b43e071d --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CapeCommand.java @@ -0,0 +1,52 @@ +package com.massivecraft.factions.cmd; + +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.FPerm; + +public abstract class CapeCommand extends FCommand +{ + public Faction capeFaction; + public String currentCape; + + public CapeCommand() + { + this.optionalArgs.put("faction", "your"); + + this.disableOnLock = true; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public boolean validCall(CommandSender sender, List args) + { + if ( ! super.validCall(sender, args)) return false; + + + this.capeFaction = null; + this.currentCape = null; + + if (this.myFaction == null && ! this.argIsSet(this.requiredArgs.size())) + { + msg("You must specify a faction from console."); + return false; + } + + this.capeFaction = this.argAsFaction(this.requiredArgs.size(), this.myFaction); + if (this.capeFaction == null) return false; + + // Do we have permission to manage the cape of that faction? + if (fme != null && ! FPerm.CAPE.has(fme, capeFaction)) return false; + + this.currentCape = this.capeFaction.getCape(); + + return true; + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdCape.java b/src/com/massivecraft/factions/cmd/CmdCape.java new file mode 100644 index 00000000..2b8f7f10 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdCape.java @@ -0,0 +1,36 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.Permission; + +public class CmdCape extends FCommand +{ + public CmdCapeGet cmdCapeGet = new CmdCapeGet(); + public CmdCapeSet cmdCapeSet = new CmdCapeSet(); + public CmdCapeRemove cmdCapeRemove = new CmdCapeRemove(); + + public CmdCape() + { + super(); + this.aliases.add("cape"); + + this.permission = Permission.CAPE.node; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + + this.addSubCommand(this.cmdCapeGet); + this.addSubCommand(this.cmdCapeSet); + this.addSubCommand(this.cmdCapeRemove); + } + + @Override + public void perform() + { + this.commandChain.add(this); + P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdCapeGet.java b/src/com/massivecraft/factions/cmd/CmdCapeGet.java new file mode 100644 index 00000000..35cd8653 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdCapeGet.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.struct.Permission; + +public class CmdCapeGet extends CapeCommand +{ + public CmdCapeGet() + { + this.aliases.add("get"); + this.permission = Permission.CAPE_GET.node; + } + + @Override + public void perform() + { + if (currentCape == null) + { + msg("%s has no cape set.", capeFaction.describeTo(fme, true)); + } + else + { + msg("The cape of %s is \"%s\".", capeFaction.describeTo(fme, true), currentCape); + } + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdCapeRemove.java b/src/com/massivecraft/factions/cmd/CmdCapeRemove.java new file mode 100644 index 00000000..71a65175 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdCapeRemove.java @@ -0,0 +1,35 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.util.RelationUtil; + +public class CmdCapeRemove extends CapeCommand +{ + + public CmdCapeRemove() + { + this.aliases.add("rm"); + this.aliases.add("rem"); + this.aliases.add("remove"); + this.aliases.add("del"); + this.aliases.add("delete"); + this.permission = Permission.CAPE_REMOVE.node; + } + + @Override + public void perform() + { + if (currentCape == null) + { + msg("%s has no cape set.", capeFaction.describeTo(fme, true)); + } + else + { + capeFaction.setCape(null); + SpoutFeatures.updateCape(capeFaction, null); + msg("%s removed the cape from %s.", RelationUtil.describeThatToMe(fme, fme, true), capeFaction.describeTo(fme)); + capeFaction.msg("%s removed the cape from %s.", RelationUtil.describeThatToMe(fme, capeFaction, true), capeFaction.describeTo(capeFaction)); + } + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdCapeSet.java b/src/com/massivecraft/factions/cmd/CmdCapeSet.java new file mode 100644 index 00000000..3999cc70 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdCapeSet.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions.cmd; + +import java.net.URL; + +import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.util.RelationUtil; + +public class CmdCapeSet extends CapeCommand +{ + + public CmdCapeSet() + { + this.aliases.add("set"); + this.requiredArgs.add("url"); + this.permission = Permission.CAPE_SET.node; + } + + @Override + public void perform() + { + String newCape = this.argAsString(0); + + if (isUrlValid(newCape)) + { + capeFaction.setCape(newCape); + SpoutFeatures.updateCape(capeFaction, null); + msg("%s set the cape of %s to \"%s\".", RelationUtil.describeThatToMe(fme, fme, true), capeFaction.describeTo(fme), newCape); + capeFaction.msg("%s set the cape of %s to \"%s\".", RelationUtil.describeThatToMe(fme, capeFaction, true), capeFaction.describeTo(capeFaction), newCape); + } + else + { + msg("\"%s\" is not a valid URL.", newCape); + } + } + + public static boolean isUrlValid(String urlString) + { + try + { + new URL(urlString); + return true; + } + catch (Exception e) + { + return false; + } + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdConfig.java b/src/com/massivecraft/factions/cmd/CmdConfig.java index 5d180bbf..e42341f8 100644 --- a/src/com/massivecraft/factions/cmd/CmdConfig.java +++ b/src/com/massivecraft/factions/cmd/CmdConfig.java @@ -393,7 +393,8 @@ public class CmdConfig extends FCommand Conf.save(); // in case some Spout related setting was changed - SpoutFeatures.updateAppearances(); + SpoutFeatures.updateTitle(null, null); + //SpoutFeatures.updateCape(null); } } diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index ea2e2f58..06f62de2 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -91,6 +91,7 @@ public class CmdDisband extends FCommand faction.detach(); - SpoutFeatures.updateAppearances(); + SpoutFeatures.updateTitle(null, null); + SpoutFeatures.updateCape(null, null); } } diff --git a/src/com/massivecraft/factions/cmd/CmdInvite.java b/src/com/massivecraft/factions/cmd/CmdInvite.java index 2760577f..a06dab3b 100644 --- a/src/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdInvite.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; public class CmdInvite extends FCommand @@ -37,6 +38,8 @@ public class CmdInvite extends FCommand return; } + if (fme != null && ! FPerm.INVITE.has(fme, myFaction)) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostInvite, "to invite someone", "for inviting someone")) return; diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index fae97e0c..8ad53a5d 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -27,7 +27,7 @@ public class CmdKick extends FCommand senderMustBePlayer = true; senderMustBeMember = false; - senderMustBeOfficer = true; + senderMustBeOfficer = false; senderMustBeLeader = false; } diff --git a/src/com/massivecraft/factions/cmd/CmdTag.java b/src/com/massivecraft/factions/cmd/CmdTag.java index 97e736f5..a5015b59 100644 --- a/src/com/massivecraft/factions/cmd/CmdTag.java +++ b/src/com/massivecraft/factions/cmd/CmdTag.java @@ -78,7 +78,7 @@ public class CmdTag extends FCommand if (Conf.spoutFactionTagsOverNames) { - SpoutFeatures.updateAppearances(myFaction); + SpoutFeatures.updateTitle(myFaction, null); } } diff --git a/src/com/massivecraft/factions/cmd/CmdTitle.java b/src/com/massivecraft/factions/cmd/CmdTitle.java index 4c98ba8e..ba014ad5 100644 --- a/src/com/massivecraft/factions/cmd/CmdTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdTitle.java @@ -45,7 +45,7 @@ public class CmdTitle extends FCommand if (Conf.spoutFactionTitlesOverNames) { - SpoutFeatures.updateAppearances(me); + SpoutFeatures.updateTitle(me, null); } } diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 28eac6b5..92c37f4d 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -9,6 +9,7 @@ public class FCmdRoot extends FCommand public CmdLeader cmdLeader = new CmdLeader(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdAdmin cmdBypass = new CmdAdmin(); + public CmdCape cmdCape = new CmdCape(); public CmdClaim cmdClaim = new CmdClaim(); public CmdConfig cmdConfig = new CmdConfig(); public CmdCreate cmdCreate = new CmdCreate(); @@ -71,6 +72,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdLeader); this.addSubCommand(this.cmdAutoClaim); this.addSubCommand(this.cmdBypass); + this.addSubCommand(this.cmdCape); this.addSubCommand(this.cmdClaim); this.addSubCommand(this.cmdConfig); this.addSubCommand(this.cmdCreate); diff --git a/src/com/massivecraft/factions/cmd/FRelationCommand.java b/src/com/massivecraft/factions/cmd/FRelationCommand.java index 6ed76a40..c1c75ce5 100644 --- a/src/com/massivecraft/factions/cmd/FRelationCommand.java +++ b/src/com/massivecraft/factions/cmd/FRelationCommand.java @@ -93,7 +93,7 @@ public abstract class FRelationCommand extends FCommand myFaction.msg("This will have no effect while your faction is peaceful."); } - SpoutFeatures.updateAppearances(myFaction, them); + SpoutFeatures.updateTitle(myFaction, them); SpoutFeatures.updateTerritoryDisplayLoc(null); } } diff --git a/src/com/massivecraft/factions/integration/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java index 4359dfe9..cb93db27 100644 --- a/src/com/massivecraft/factions/integration/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.integration; +import java.util.Arrays; +import java.util.HashSet; import java.util.Set; import com.massivecraft.factions.Conf; @@ -14,62 +16,216 @@ import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; import org.bukkit.entity.Player; -import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.HealthBarUtil; -import org.getspout.spoutapi.gui.Color; import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.SpoutManager; public class SpoutFeatures { - private transient static boolean spoutMe = false; - private transient static SpoutMainListener mainListener; - private transient static boolean listenersHooked; + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private static SpoutMainListener mainListener; + + private static boolean enabled = false; + public static boolean isEnabled() { return enabled; } - public static void setup() + // -------------------------------------------- // + // SETUP AND AVAILABILITY + // -------------------------------------------- // + + public static boolean setup() { - Plugin test = Bukkit.getServer().getPluginManager().getPlugin("Spout"); - if (test == null || !test.isEnabled()) return; - - setAvailable(true, test.getDescription().getFullName()); + Plugin plugin = Bukkit.getPluginManager().getPlugin("Spout"); + if (plugin == null || ! plugin.isEnabled()) + { + if (enabled == false) return false; + enabled = false; + return false; + } + + if (enabled == true) return true; + enabled = true; + + P.p.log("Found and will use features of "+plugin.getDescription().getFullName()); + mainListener = new SpoutMainListener(); + Bukkit.getPluginManager().registerEvents(mainListener, P.p); + + return true; } - // set integration availability - public static void setAvailable(boolean enable, String pluginName) + // -------------------------------------------- // + // CAPES + // -------------------------------------------- // + // Capes look the same to everyone. + + public static void updateCape(final Object ofrom, final Object oto) { - spoutMe = enable; - if (!spoutMe) return; - - P.p.log("Found and will use features of "+pluginName); - - if (!listenersHooked) + // Enabled and non-null? + if ( ! isEnabled()) return; + if ( ! Conf.spoutCapes) return; + + Set fromPlayers = getPlayersFromObject(ofrom); + Set toPlayers = getPlayersFromObject(oto); + + for (Player player : fromPlayers) { - listenersHooked = true; - mainListener = new SpoutMainListener(); - Bukkit.getServer().getPluginManager().registerEvents(mainListener, P.p); + FPlayer fplayer = FPlayers.i.get(player); + SpoutPlayer splayer = SpoutManager.getPlayer(player); + Faction faction = fplayer.getFaction(); + + String cape = faction.getCape(); + + for (Player playerTo : toPlayers) + { + SpoutPlayer splayerTo = SpoutManager.getPlayer(playerTo); + + // Set the cape + if (cape != null) + { + try + { + splayer.setCapeFor(splayerTo, cape); + } + catch (Exception e) + { + + } + } + else + { + splayer.resetCapeFor(splayerTo); + } + } } } - - // If we're successfully hooked into Spout - public static boolean enabled() + + public static void updateCapeShortly(final Object ofrom, final Object oto) { - return spoutMe; + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() + { + @Override + public void run() + { + updateCape(ofrom, oto); + } + }, 10); } - - // If Spout is available and the specified Player is running the Spoutcraft client - public static boolean availableFor(Player player) + + // -------------------------------------------- // + // TITLE + // -------------------------------------------- // + + public static void updateTitle(final Object ofrom, final Object oto) { - return spoutMe && SpoutManager.getPlayer(player).isSpoutCraftEnabled(); + // Enabled and non-null? + if ( ! isEnabled()) return; + if ( ! (Conf.spoutFactionTagsOverNames || Conf.spoutFactionTitlesOverNames || Conf.spoutHealthBarUnderNames)) return; + + Set fromPlayers = getPlayersFromObject(ofrom); + Set toPlayers = getPlayersFromObject(oto); + + for (Player player : fromPlayers) + { + FPlayer fplayer = FPlayers.i.get(player); + SpoutPlayer splayer = SpoutManager.getPlayer(player); + Faction faction = fplayer.getFaction(); + + for (Player playerTo : toPlayers) + { + FPlayer fplayerTo = FPlayers.i.get(playerTo); + SpoutPlayer splayerTo = SpoutManager.getPlayer(playerTo); + Faction factionTo = fplayerTo.getFaction(); + + ChatColor relationColor = faction.getRelationTo(factionTo).getColor(); + + String title = generateTitle(player, fplayer, faction, relationColor); + splayer.setTitleFor(splayerTo, title); + } + } } + + public static void updateTitleShortly(final Object ofrom, final Object oto) + { + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() + { + @Override + public void run() + { + updateTitle(ofrom, oto); + } + }, 10); + } + + public static String generateTitle(Player player, FPlayer fplayer, Faction faction, ChatColor relationColor) + { + String ret = null; + + ret = player.getDisplayName(); + + if (faction.isNormal()) + { + String addTag = ""; + if (Conf.spoutFactionTagsOverNames) + { + addTag += relationColor.toString() + "[" + fplayer.getRole().getPrefix() + faction.getTag() + "]"; + } + + if (Conf.spoutFactionTitlesOverNames && ! fplayer.getTitle().isEmpty()) + { + addTag += (addTag.isEmpty() ? "" : " ") + fplayer.getTitle(); + } + ret = addTag + "\n" + ret; + } + + if (Conf.spoutHealthBarUnderNames) + { + ret += "\n"; + ret += HealthBarUtil.getHealthbar(player.getHealth() / 20d); + } + + return ret; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static Set getPlayersFromObject(Object o) + { + Set ret = new HashSet(); + if (o instanceof Player) + { + ret.add((Player)o); + } + else if (o instanceof FPlayer) + { + ret.add(((FPlayer)o).getPlayer()); + } + else if (o instanceof Faction) + { + ret.addAll(((Faction)o).getOnlinePlayers()); + } + else + { + ret.addAll(Arrays.asList(Bukkit.getOnlinePlayers())); + } + + return ret; + } + + // -------------------------------------------- // + // TERRITORY DISPLAY + // -------------------------------------------- // // update displayed current territory for all players inside a specified chunk; if specified chunk is null, then simply update everyone online public static void updateTerritoryDisplayLoc(FLocation fLoc) { - if (!enabled()) - return; + if ( ! isEnabled()) return; Set players = FPlayers.i.getOnline(); @@ -85,245 +241,13 @@ public class SpoutFeatures // update displayed current territory for specified player; returns false if unsuccessful public static boolean updateTerritoryDisplay(FPlayer player) { - if (!enabled()) - return false; - + if ( ! isEnabled()) return false; return mainListener.updateTerritoryDisplay(player, true); } public static void playerDisconnect(FPlayer player) { - if (!enabled()) - return; - + if ( ! isEnabled()) return; mainListener.removeTerritoryLabels(player.getName()); } - - - // update all appearances between every player - public static void updateAppearances() - { - if (!enabled()) - return; - - Set players = FPlayers.i.getOnline(); - - for (FPlayer playerA : players) - { - for (FPlayer playerB : players) - { - updateSingle(playerB, playerA); - } - } - } - - // update all appearances related to a specific player - public static void updateAppearances(Player player) - { - if (!enabled() || player == null) - return; - - Set players = FPlayers.i.getOnline(); - FPlayer playerA = FPlayers.i.get(player); - - for (FPlayer playerB : players) - { - updateSingle(playerB, playerA); - updateSingle(playerA, playerB); - } - } - - // update how this player looks in the eyes of all other players - public static void updateMyAppearance(Player player) - { - if (!enabled() || player == null) return; - - Set players = FPlayers.i.getOnline(); - FPlayer playerA = FPlayers.i.get(player); - - for (FPlayer playerB : players) - { - updateSingle(playerB, playerA); - } - } - - // as above method, but with a delay added; useful for after-login update which doesn't always propagate if done immediately - public static void updateAppearancesShortly(final Player player) - { - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() - { - @Override - public void run() - { - updateAppearances(player); - } - }, 100); - } - - // update all appearances related to a single faction - public static void updateAppearances(Faction faction) - { - if (!enabled() || faction == null) - return; - - Set players = FPlayers.i.getOnline(); - Faction factionA; - - for (FPlayer playerA : players) - { - factionA = playerA.getFaction(); - - for (FPlayer playerB : players) - { - if (factionA != faction && playerB.getFaction() != faction) - continue; - - updateSingle(playerB, playerA); - } - } - } - - // update all appearances between two factions - public static void updateAppearances(Faction factionA, Faction factionB) - { - if (!enabled() || factionA == null || factionB == null) - return; - - for (FPlayer playerA : factionA.getFPlayersWhereOnline(true)) - { - for (FPlayer playerB : factionB.getFPlayersWhereOnline(true)) - { - updateSingle(playerB, playerA); - updateSingle(playerA, playerB); - } - } - } - - - // update a single appearance; internal use only by above public methods - private static void updateSingle(FPlayer viewer, FPlayer viewed) - { - if (viewer == null || viewed == null) - return; - - Faction viewedFaction = viewed.getFaction(); - if (viewedFaction == null) - return; - - // these still end up returning null on occasion at this point, mucking up the SpoutManager.getPlayer() method - if (viewer.getPlayer() == null || viewed.getPlayer() == null) - return; - - SpoutPlayer pViewer = SpoutManager.getPlayer(viewer.getPlayer()); - SpoutPlayer pViewed = SpoutManager.getPlayer(viewed.getPlayer()); - if (pViewed == null || pViewer == null) - return; - - String viewedTitle = viewed.getTitle(); - Rel viewedRole = viewed.getRole(); - - if ((Conf.spoutFactionTagsOverNames || Conf.spoutFactionTitlesOverNames || Conf.spoutHealthBarUnderNames) && viewer != viewed) - { - String title = pViewed.getDisplayName(); - - if (viewedFaction.isNormal()) - { - String addTag = ""; - if (Conf.spoutFactionTagsOverNames) - { - addTag += viewedFaction.getTag(viewed.getColorTo(viewer).toString() + "[") + "]"; - } - - String rolePrefix = viewedRole.getPrefix(); - if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty())) - { - addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle; - } - - title = addTag + "\n" + title; - } - - if (Conf.spoutHealthBarUnderNames) - { - title += "\n"; - title += HealthBarUtil.getHealthbar(pViewed.getHealth() / 20d); - } - - pViewed.setTitleFor(pViewer, title); - } - - if - ( - ( - Conf.spoutFactionLeaderCapes - && - viewedRole.equals(Rel.LEADER) - ) - || - ( - Conf.spoutFactionOfficerCapes - && - viewedRole.equals(Rel.OFFICER) - ) - ) - { - Rel relation = viewer.getRelationTo(viewed); - String cape = ""; - if (!viewedFaction.isNormal()) - { - // yeah, no cape if no faction - } - else if (relation == Rel.TRUCE) - cape = Conf.capePeaceful; - else if (relation == Rel.NEUTRAL) - cape = Conf.capeNeutral; - else if (relation == Rel.MEMBER) - cape = Conf.capeMember; - else if (relation == Rel.ENEMY) - cape = Conf.capeEnemy; - else if (relation == Rel.ALLY) - cape = Conf.capeAlly; - - if (cape.isEmpty()) - pViewed.resetCapeFor(pViewer); - else - pViewed.setCapeFor(pViewer, cape); - } - else if (Conf.spoutFactionLeaderCapes || Conf.spoutFactionOfficerCapes) - { - pViewed.resetCapeFor(pViewer); - } - } - - - // method to convert a Bukkit ChatColor to a Spout Color - protected static Color getSpoutColor(ChatColor inColor, int alpha) - { - if (inColor == null) - return SpoutFixedColor(191, 191, 191, alpha); - - switch (inColor.getChar()) - { - case 0x1: return SpoutFixedColor(0, 0, 191, alpha); - case 0x2: return SpoutFixedColor(0, 191, 0, alpha); - case 0x3: return SpoutFixedColor(0, 191, 191, alpha); - case 0x4: return SpoutFixedColor(191, 0, 0, alpha); - case 0x5: return SpoutFixedColor(191, 0, 191, alpha); - case 0x6: return SpoutFixedColor(191, 191, 0, alpha); - case 0x7: return SpoutFixedColor(191, 191, 191, alpha); - case 0x8: return SpoutFixedColor(64, 64, 64, alpha); - case 0x9: return SpoutFixedColor(64, 64, 255, alpha); - case 0xA: return SpoutFixedColor(64, 255, 64, alpha); - case 0xB: return SpoutFixedColor(64, 255, 255, alpha); - case 0xC: return SpoutFixedColor(255, 64, 64, alpha); - case 0xD: return SpoutFixedColor(255, 64, 255, alpha); - case 0xE: return SpoutFixedColor(255, 255, 64, alpha); - case 0xF: return SpoutFixedColor(255, 255, 255, alpha); - default: return SpoutFixedColor(0, 0, 0, alpha); - } - } - private static Color SpoutFixedColor(int r, int g, int b, int a) - { - return new Color(r/255.0f, g/255.0f, b/255.0f, a/255.0f); - } } diff --git a/src/com/massivecraft/factions/integration/SpoutMainListener.java b/src/com/massivecraft/factions/integration/SpoutMainListener.java index 9319dfd0..1f50a174 100644 --- a/src/com/massivecraft/factions/integration/SpoutMainListener.java +++ b/src/com/massivecraft/factions/integration/SpoutMainListener.java @@ -29,7 +29,8 @@ public class SpoutMainListener implements Listener { final FPlayer me = FPlayers.i.get(event.getPlayer()); - SpoutFeatures.updateAppearances(me.getPlayer()); + SpoutFeatures.updateTitle(me, null); + SpoutFeatures.updateTitle(null, me); updateTerritoryDisplay(me, true); } diff --git a/src/com/massivecraft/factions/listeners/FactionsHealthBarListener.java b/src/com/massivecraft/factions/listeners/FactionsHealthBarListener.java index 32eae52d..c52daf03 100644 --- a/src/com/massivecraft/factions/listeners/FactionsHealthBarListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsHealthBarListener.java @@ -33,7 +33,7 @@ public class FactionsHealthBarListener implements Listener if ( ! Conf.spoutHealthBarUnderNames) return; if ( ! (entity instanceof Player)) return; Player player = (Player)entity; - SpoutFeatures.updateMyAppearance(player); + SpoutFeatures.updateTitle(player, null); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 4b10c03a..9d27bd91 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -53,13 +53,11 @@ public class FactionsPlayerListener implements Listener // Update the lastLoginTime for this fplayer me.setLastLoginTime(System.currentTimeMillis()); -/* This is now done in a separate task which runs every few minutes - // Run the member auto kick routine. Twice to get to the admins... - FPlayers.i.autoLeaveOnInactivityRoutine(); - FPlayers.i.autoLeaveOnInactivityRoutine(); - */ - - SpoutFeatures.updateAppearancesShortly(event.getPlayer()); + //SpoutFeatures.updateAppearancesShortly(event.getPlayer()); + SpoutFeatures.updateTitleShortly(event.getPlayer(), null); + SpoutFeatures.updateTitleShortly(null, event.getPlayer()); + SpoutFeatures.updateCapeShortly(event.getPlayer(), null); + SpoutFeatures.updateCapeShortly(null, event.getPlayer()); } @EventHandler(priority = EventPriority.NORMAL) diff --git a/src/com/massivecraft/factions/listeners/FactionsServerListener.java b/src/com/massivecraft/factions/listeners/FactionsServerListener.java index 205a547e..40fd1422 100644 --- a/src/com/massivecraft/factions/listeners/FactionsServerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsServerListener.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.listeners; -import org.bukkit.plugin.Plugin; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -22,21 +21,12 @@ public class FactionsServerListener implements Listener @EventHandler(priority = EventPriority.MONITOR) public void onPluginDisable(PluginDisableEvent event) { - String name = event.getPlugin().getDescription().getName(); - if (name.equals("Spout")) - { - SpoutFeatures.setAvailable(false, ""); - } + SpoutFeatures.setup(); } @EventHandler(priority = EventPriority.MONITOR) public void onPluginEnable(PluginEnableEvent event) { - Plugin plug = event.getPlugin(); - String name = plug.getDescription().getName(); - if (name.equals("Spout")) - { - SpoutFeatures.setAvailable(true, plug.getDescription().getFullName()); - } + SpoutFeatures.setup(); } } \ No newline at end of file diff --git a/src/com/massivecraft/factions/struct/FPerm.java b/src/com/massivecraft/factions/struct/FPerm.java index d71b5991..095f2320 100644 --- a/src/com/massivecraft/factions/struct/FPerm.java +++ b/src/com/massivecraft/factions/struct/FPerm.java @@ -31,10 +31,12 @@ public enum FPerm BUTTON("button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), LEVER("lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER), + INVITE("invite", "invite players", Rel.LEADER, Rel.OFFICER), KICK("kick", "kick members", Rel.LEADER, Rel.OFFICER), SETHOME("sethome", "set the home", Rel.LEADER, Rel.OFFICER), WITHDRAW("withdraw", "withdraw money", Rel.LEADER, Rel.OFFICER), TERRITORY("territory", "claim or unclaim", Rel.LEADER, Rel.OFFICER), + CAPE("cape", "set the cape", Rel.LEADER, Rel.OFFICER), DISBAND("disband", "disband the faction", Rel.LEADER), PERMS("perms", "manage permissions", Rel.LEADER), ; @@ -77,6 +79,7 @@ public enum FPerm if (str.startsWith("but")) return BUTTON; if (str.startsWith("l")) return LEVER; if (str.startsWith("co")) return CONTAINER; + if (str.startsWith("i")) return INVITE; if (str.startsWith("k")) return KICK; if (str.startsWith("s")) return SETHOME; if (str.startsWith("w")) return WITHDRAW; diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index 1a3f0ccd..383782a7 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -7,8 +7,10 @@ public enum Permission { ADMIN("adminmode"), AUTOCLAIM("autoclaim"), - CHAT("chat"), - CHATSPY("chatspy"), + CAPE("cape"), + CAPE_GET("cape.get"), + CAPE_SET("cape.set"), + CAPE_REMOVE("cape.remove"), CLAIM("claim"), CONFIG("config"), CREATE("create"),