Removing some old code and try to read colors in the listeners.

This commit is contained in:
Olof Larsson 2011-10-21 18:14:04 +02:00
parent 38e128010c
commit f42fb8e8bf
5 changed files with 50 additions and 174 deletions

View File

@ -785,24 +785,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
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<String, FPlayer> playersToSave = new HashMap<String, FPlayer>();
for (Entry<String, FPlayer> 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<Map<String, FPlayer>>(){}.getType();
Map<String, FPlayer> 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<String, FPlayer> 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));

View File

@ -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("<b>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("<b>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("<b>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("<b>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("<b>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("<b>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("<b>You can't "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc));
return false;
}

View File

@ -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<String> 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()))

View File

@ -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("<i>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("<b>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("<i>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("<i>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("<i>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("<i>Your power is now <h>"+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("<i>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("<i>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("<i>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("<i>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("<i>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("<i>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("<i>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("<i>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("<i>You can't hurt "+defender.getNameAndRelevant(attacker)));
attacker.msg("<i>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("<i>You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+"<i> in their own territory unless you declare them as an enemy."));
defender.sendMessage(p.txt.parse(attacker.getNameAndRelevant(defender)+"<i> tried to hurt you."));
attacker.msg("<i>You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+"<i> in their own territory unless you declare them as an enemy.");
defender.msg(attacker.getNameAndRelevant(defender)+"<i> 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("<i>Enemy damage reduced by "+ChatColor.RED+perc+"<i>."));
defender.msg("<i>Enemy damage reduced by "+ChatColor.RED+perc+"<i>.");
}
return true;

View File

@ -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("<b>You must be <h>%s<b> 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("<b>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("<b>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("<i>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("<i>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("<b>You can't use <h>%s<b> 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("<b>You can't use <h>%s<b> 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("<b>You can't use <h>%s<b> 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("<b>You can't use <h>%s<b> in the territory of <h>%s<b>.", 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("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", 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("<b>You can't use <h>%s<b> in the territory of <h>%s<b>.", TextUtil.getMaterialName(material), otherFaction.getTag(myFaction));
return false;
}
@ -465,7 +465,7 @@ 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("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", 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("<b>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("<b>You can't use the command \""+fullCmd+"\" in enemy territory.");
return true;
}
}