From f42fb8e8bf9205c9d19ae4021b8e224a66ac916d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 21 Oct 2011 18:14:04 +0200 Subject: [PATCH] Removing some old code and try to read colors in the listeners. --- src/com/massivecraft/factions/FPlayer.java | 113 ------------------ .../listeners/FactionsBlockListener.java | 14 +-- .../listeners/FactionsChatEarlyListener.java | 14 --- .../listeners/FactionsEntityListener.java | 53 ++++---- .../listeners/FactionsPlayerListener.java | 30 ++--- 5 files changed, 50 insertions(+), 174 deletions(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 3da00e0b..cc5b0fa0 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -784,24 +784,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator Board.setFactionAt(myFaction, flocation); return true; } - - // -------------------------------------------- // - // Get and search - // -------------------------------------------- // - - /*private static FPlayer get(String playerName) - { - if (instances.containsKey(playerName)) - { - return instances.get(playerName); - } - - FPlayer vplayer = new FPlayer(); - vplayer.playerName = playerName; - - instances.put(playerName, vplayer); - return vplayer; - }*/ // -------------------------------------------- // // Persistance @@ -813,101 +795,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator return ! this.deleteMe; } - /* - public static boolean save() - { - //Factions.log("Saving players to disk"); - - // We only wan't to save the players with non default values - Map playersToSave = new HashMap(); - for (Entry entry : instances.entrySet()) { - if (entry.getValue().shouldBeSaved()) { - playersToSave.put(entry.getKey(), entry.getValue()); - } - } - - try { - DiscUtil.write(file, P.p.gson.toJson(playersToSave)); - } catch (Exception e) { - e.printStackTrace(); - P.log("Failed to save the players to disk."); - return false; - } - return true; - } - - public static boolean load() { - P.log("Loading players from disk"); - if ( ! file.exists()) { - if ( ! loadOld()) - P.log("No players to load from disk. Creating new file."); - save(); - return true; - } - - try { - Type type = new TypeToken>(){}.getType(); - Map instancesFromFile = P.p.gson.fromJson(DiscUtil.read(file), type); - instances.clear(); - instances.putAll(instancesFromFile); - } catch (Exception e) { - e.printStackTrace(); - P.log("Failed to load the players from disk."); - return false; - } - - fillPlayernames(); - - return true; - } - - public static void fillPlayernames() { - for(Entry entry : instances.entrySet()) { - entry.getValue().playerName = entry.getKey(); - } - } - */ - - - /*private static boolean loadOld() - { - File folderFollower = new File(P.p.getDataFolder(), "follower"); - - if ( ! folderFollower.isDirectory()) return false; - - p.log("Players file doesn't exist, attempting to load old pre-1.1 data."); - - String ext = ".json"; - - class jsonFileFilter implements FileFilter - { - @Override - public boolean accept(File file) - { - return (file.getName().toLowerCase().endsWith(".json") && file.isFile()); - } - } - - File[] jsonFiles = folderFollower.listFiles(new jsonFileFilter()); - - for (File jsonFile : jsonFiles) { - // Extract the name from the filename. The name is filename minus ".json" - String name = jsonFile.getName(); - name = name.substring(0, name.length() - ext.length()); - try { - FPlayer follower = P.p.gson.fromJson(DiscUtil.read(jsonFile), FPlayer.class); - follower.playerName = name; - follower.lastLoginTime = System.currentTimeMillis(); - instances.put(follower.playerName, follower); - P.log("loaded pre-1.1 follower "+name); - } catch (Exception e) { - e.printStackTrace(); - P.log(Level.WARNING, "failed to load follower "+name); - } - } - return true; - }*/ - public void msg(String str, Object... args) { this.sendMessage(P.p.txt.parse(str, args)); diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 4ab7d693..6d3285b2 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -175,7 +175,7 @@ public class FactionsBlockListener extends BlockListener return true; // This is not faction territory. Use whatever you like here. if (!justCheck) - me.sendMessage("You can't "+action+" in the wilderness."); + me.msg("You can't "+action+" in the wilderness."); return false; } @@ -185,7 +185,7 @@ public class FactionsBlockListener extends BlockListener return true; if (!justCheck) - me.sendMessage("You can't "+action+" in a safe zone."); + me.msg("You can't "+action+" in a safe zone."); return false; } @@ -195,7 +195,7 @@ public class FactionsBlockListener extends BlockListener return true; if (!justCheck) - me.sendMessage("You can't "+action+" in a war zone."); + me.msg("You can't "+action+" in a war zone."); return false; } @@ -212,14 +212,14 @@ public class FactionsBlockListener extends BlockListener player.damage(Conf.actionDeniedPainAmount); if (!deny) - me.sendMessage("It is painful to try to "+action+" in the territory of "+otherFaction.getTag(myFaction)); + me.msg("It is painful to try to "+action+" in the territory of "+otherFaction.getTag(myFaction)); } // cancel building/destroying in other territory? if (deny) { if (!justCheck) - me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction)); + me.msg("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction)); return false; } @@ -232,12 +232,12 @@ public class FactionsBlockListener extends BlockListener player.damage(Conf.actionDeniedPainAmount); if (!Conf.ownedAreaDenyBuild) - me.sendMessage("It is painful to try to "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); + me.msg("It is painful to try to "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); } if (Conf.ownedAreaDenyBuild) { if (!justCheck) - me.sendMessage("You can't "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); + me.msg("You can't "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); return false; } diff --git a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java index c2ce32ae..e8f9e533 100644 --- a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java @@ -28,20 +28,6 @@ public class FactionsChatEarlyListener extends PlayerListener @Override public void onPlayerChat(PlayerChatEvent event) { - // Is it a slashless Factions command? - /*if ((event.getMessage().startsWith(P.p.getBaseCommand()+" ") || event.getMessage().equals(P.p.getBaseCommand())) && Conf.allowNoSlashCommand) { - String msg = event.getMessage().trim(); - // make sure command isn't denied due to being in enemy/neutral territory - if (!FactionsPlayerListener.preventCommand("/" + msg.toLowerCase(), event.getPlayer())) { - List parameters = TextUtil.split(msg); - parameters.remove(0); - CommandSender sender = event.getPlayer(); - P.p.handleCommand(sender, parameters); - } - event.setCancelled(true); - return; - }*/ - if (event.isCancelled()) return; if (p.handleCommand(event.getPlayer(), event.getMessage())) diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 03e09526..2529d479 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -58,31 +58,31 @@ public class FactionsEntityListener extends EntityListener // war zones always override worldsNoPowerLoss either way, thus this layout if (! Conf.warZonePowerLoss) { - fplayer.sendMessage("You didn't lose any power since you were in a war zone."); + fplayer.msg("You didn't lose any power since you were in a war zone."); return; } if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { - fplayer.sendMessage("The world you are in has power loss normally disabled, but you still lost power since you were in a war zone."); + fplayer.msg("The world you are in has power loss normally disabled, but you still lost power since you were in a war zone."); } } else if (faction.isNone() && !Conf.wildernessPowerLoss && !Conf.worldsNoWildernessProtection.contains(player.getWorld().getName())) { - fplayer.sendMessage("You didn't lose any power since you were in the wilderness."); + fplayer.msg("You didn't lose any power since you were in the wilderness."); return; } else if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { - fplayer.sendMessage("You didn't lose any power due to the world you died in."); + fplayer.msg("You didn't lose any power due to the world you died in."); return; } else if (Conf.peacefulMembersDisablePowerLoss && fplayer.hasFaction() && fplayer.getFaction().isPeaceful()) { - fplayer.sendMessage("You didn't lose any power since you are in a peaceful faction."); + fplayer.msg("You didn't lose any power since you are in a peaceful faction."); return; } fplayer.onDeath(); - fplayer.sendMessage("Your power is now "+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded()); + fplayer.msg("Your power is now "+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded()); } /** @@ -92,17 +92,20 @@ public class FactionsEntityListener extends EntityListener * I can hurt neutrals as long as they are outside their own territory. */ @Override - public void onEntityDamage(EntityDamageEvent event) { - if ( event.isCancelled()) { - return; - } + public void onEntityDamage(EntityDamageEvent event) + { + if ( event.isCancelled()) return; - if (event instanceof EntityDamageByEntityEvent) { + if (event instanceof EntityDamageByEntityEvent) + { EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event; - if ( ! this.canDamagerHurtDamagee(sub)) { + if ( ! this.canDamagerHurtDamagee(sub)) + { event.setCancelled(true); } - } else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) { + } + else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) + { // Players can not take any damage in a Safe Zone event.setCancelled(true); } @@ -249,7 +252,7 @@ public class FactionsEntityListener extends EntityListener if (damager instanceof Player) { FPlayer attacker = FPlayers.i.get((Player)damager); - attacker.sendMessage("You can't hurt other players in "+(defLocFaction.isSafeZone() ? "a SafeZone." : "peaceful territory.")); + attacker.msg("You can't hurt other players in "+(defLocFaction.isSafeZone() ? "a SafeZone." : "peaceful territory.")); return false; } return !defLocFaction.noMonstersInTerritory(); @@ -269,7 +272,7 @@ public class FactionsEntityListener extends EntityListener if (attacker.hasLoginPvpDisabled()) { - attacker.sendMessage("You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in."); + attacker.msg("You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in."); return false; } @@ -278,7 +281,7 @@ public class FactionsEntityListener extends EntityListener // so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be? if (locFaction.noPvPInTerritory()) { - attacker.sendMessage("You can't hurt other players while you are in "+(locFaction.isSafeZone() ? "a SafeZone." : "peaceful territory.")); + attacker.msg("You can't hurt other players while you are in "+(locFaction.isSafeZone() ? "a SafeZone." : "peaceful territory.")); return false; } else if (locFaction.isWarZone() && Conf.warZoneFriendlyFire) @@ -291,7 +294,7 @@ public class FactionsEntityListener extends EntityListener if (attackFaction.isNone() && Conf.disablePVPForFactionlessPlayers) { - attacker.sendMessage("You can't hurt other players until you join a faction."); + attacker.msg("You can't hurt other players until you join a faction."); return false; } else if (defendFaction.isNone()) @@ -303,19 +306,19 @@ public class FactionsEntityListener extends EntityListener } else if (Conf.disablePVPForFactionlessPlayers) { - attacker.sendMessage("You can't hurt players who are not currently in a faction."); + attacker.msg("You can't hurt players who are not currently in a faction."); return false; } } if (defendFaction.isPeaceful()) { - attacker.sendMessage("You can't hurt players who are in a peaceful faction."); + attacker.msg("You can't hurt players who are in a peaceful faction."); return false; } else if (attackFaction.isPeaceful()) { - attacker.sendMessage("You can't hurt players while you are in a peaceful faction."); + attacker.msg("You can't hurt players while you are in a peaceful faction."); return false; } @@ -324,7 +327,7 @@ public class FactionsEntityListener extends EntityListener // You can not hurt neutral factions if (Conf.disablePVPBetweenNeutralFactions && relation.isNeutral()) { - attacker.sendMessage("You can't hurt neutral factions. Declare them as an enemy."); + attacker.msg("You can't hurt neutral factions. Declare them as an enemy."); return false; } @@ -337,7 +340,7 @@ public class FactionsEntityListener extends EntityListener // You can never hurt faction members or allies if (relation.isMember() || relation.isAlly()) { - attacker.sendMessage(p.txt.parse("You can't hurt "+defender.getNameAndRelevant(attacker))); + attacker.msg("You can't hurt "+defender.getNameAndRelevant(attacker)); return false; } @@ -346,8 +349,8 @@ public class FactionsEntityListener extends EntityListener // You can not hurt neutrals in their own territory. if (ownTerritory && relation.isNeutral()) { - attacker.sendMessage(p.txt.parse("You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory unless you declare them as an enemy.")); - defender.sendMessage(p.txt.parse(attacker.getNameAndRelevant(defender)+" tried to hurt you.")); + attacker.msg("You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory unless you declare them as an enemy."); + defender.msg(attacker.getNameAndRelevant(defender)+" tried to hurt you."); return false; } @@ -359,7 +362,7 @@ public class FactionsEntityListener extends EntityListener // Send message String perc = MessageFormat.format("{0,number,#%}", (Conf.territoryShieldFactor)); // TODO does this display correctly?? - defender.sendMessage(p.txt.parse("Enemy damage reduced by "+ChatColor.RED+perc+".")); + defender.msg("Enemy damage reduced by "+ChatColor.RED+perc+"."); } return true; diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 8be12cd9..a21c4f74 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -265,17 +265,17 @@ public class FactionsPlayerListener extends PlayerListener if (me.getRole().value < Role.MODERATOR.value) { - me.sendMessage("You must be "+Role.MODERATOR+" to claim land."); + me.msg("You must be %s to claim land.", Role.MODERATOR.toString()); me.setIsAutoClaimEnabled(false); } else if (Conf.worldsNoClaiming.contains(to.getWorldName())) { - me.sendMessage("Sorry, this world has land claiming disabled."); + me.msg("Sorry, this world has land claiming disabled."); me.setIsAutoClaimEnabled(false); } else if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { - me.sendMessage("You can't claim more land! You need more power!"); + me.msg("You can't claim more land! You need more power!"); me.setIsAutoClaimEnabled(false); } else @@ -294,7 +294,7 @@ public class FactionsPlayerListener extends PlayerListener if (!Board.getFactionAt(playerFlocation).isSafeZone()) { Board.setFactionAt(Factions.i.getSafeZone(), playerFlocation); - me.sendMessage("This land is now a safe zone."); + me.msg("This land is now a safe zone."); } } } @@ -311,7 +311,7 @@ public class FactionsPlayerListener extends PlayerListener if (!Board.getFactionAt(playerFlocation).isWarZone()) { Board.setFactionAt(Factions.i.getWarZone(), playerFlocation); - me.sendMessage("This land is now a war zone."); + me.msg("This land is now a war zone."); } } } @@ -374,7 +374,7 @@ public class FactionsPlayerListener extends PlayerListener return true; // This is not faction territory. Use whatever you like here. if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the wilderness."); + me.msg("You can't use %s in the wilderness.", TextUtil.getMaterialName(material)); return false; } @@ -384,7 +384,7 @@ public class FactionsPlayerListener extends PlayerListener return true; if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a safe zone."); + me.msg("You can't use %s in a safe zone.", TextUtil.getMaterialName(material)); return false; } @@ -394,7 +394,7 @@ public class FactionsPlayerListener extends PlayerListener return true; if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a war zone."); + me.msg("You can't use %s in a war zone.", TextUtil.getMaterialName(material)); return false; } @@ -406,7 +406,7 @@ public class FactionsPlayerListener extends PlayerListener if (rel.confDenyUseage()) { if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); + me.msg("You can't use %s in the territory of %s.", TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); return false; } @@ -415,7 +415,7 @@ public class FactionsPlayerListener extends PlayerListener if (Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc)) { if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); + me.msg("You can't use %s in this territory, it is owned by: %s.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); return false; } @@ -456,7 +456,7 @@ public class FactionsPlayerListener extends PlayerListener if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) { if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); + me.msg("You can't use %s in the territory of %s.", TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); return false; } @@ -465,8 +465,8 @@ public class FactionsPlayerListener extends PlayerListener if (Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc)) { if (!justCheck) - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); - + me.msg("You can't use %s in this territory, it is owned by: %s.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); + return false; } @@ -584,7 +584,7 @@ public class FactionsPlayerListener extends PlayerListener cmdCheck = cmdCheck.toLowerCase(); if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { - me.sendMessage("You can't use the command \""+fullCmd+"\" in neutral territory."); + me.msg("You can't use the command \""+fullCmd+"\" in neutral territory."); return true; } } @@ -612,7 +612,7 @@ public class FactionsPlayerListener extends PlayerListener cmdCheck = cmdCheck.toLowerCase(); if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { - me.sendMessage("You can't use the command \""+fullCmd+"\" in enemy territory."); + me.msg("You can't use the command \""+fullCmd+"\" in enemy territory."); return true; } }