Managed to get rid of some commands. This needs to be rethought even more though.

This commit is contained in:
Olof Larsson 2011-10-22 17:03:49 +02:00
parent 45d6a6628a
commit a78a4dff98
15 changed files with 61 additions and 347 deletions

View File

@ -16,10 +16,9 @@ public class Conf
public static ChatColor colorNeutral = ChatColor.WHITE;
public static ChatColor colorEnemy = ChatColor.RED;
// TODO: We need to change the relation color system.
// I would like peaceful factions to have the relation color gold.
// For this to be possible some refactoring needs to be done.
public static ChatColor colorPeaceful = ChatColor.GOLD;
public static ChatColor colorWar = ChatColor.DARK_RED;
//public static ChatColor colorWilderness = ChatColor.DARK_GREEN;
// Power
public static double powerPlayerMax = 10.0;

View File

@ -14,6 +14,7 @@ import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil;
@ -69,17 +70,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
private transient boolean mapAutoUpdating;
// FIELD: autoClaimEnabled
private transient boolean autoClaimEnabled;
public boolean isAutoClaimEnabled()
private transient Faction autoClaimFor;
public Faction getAutoClaimFor()
{
if (this.factionId.equals("0")) return false;
return autoClaimEnabled;
return autoClaimFor;
}
public void setIsAutoClaimEnabled(boolean enabled)
public void setAutoClaimFor(Faction faction)
{
this.autoClaimEnabled = enabled;
if (enabled)
this.autoClaimFor = faction;
if (this.autoClaimFor != null)
{
// TODO: merge these into same autoclaim
this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
}
@ -93,7 +94,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
this.autoSafeZoneEnabled = enabled;
if (enabled)
{
this.autoClaimEnabled = false;
this.autoClaimFor = null;
this.autoWarZoneEnabled = false;
}
}
@ -106,7 +107,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
this.autoWarZoneEnabled = enabled;
if (enabled)
{
this.autoClaimEnabled = false;
this.autoClaimFor = null;
this.autoSafeZoneEnabled = false;
}
}
@ -152,7 +153,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
this.lastPowerUpdateTime = System.currentTimeMillis();
this.lastLoginTime = System.currentTimeMillis();
this.mapAutoUpdating = false;
this.autoClaimEnabled = false;
this.autoClaimFor = null;
this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
@ -180,7 +181,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
this.chatMode = ChatMode.PUBLIC;
this.role = Role.NORMAL;
this.title = "";
this.autoClaimEnabled = false;
this.autoClaimFor = null;
if (doSpotUpdate)
{
@ -647,6 +648,14 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
{
return true;
}
else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer()))
{
return true;
}
else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))
{
return true;
}
else if (myFaction != forFaction)
{
error = P.p.txt.parse("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(this));
@ -734,7 +743,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false;
// if economy is enabled and they're not on the bypass list, make 'em pay
if (Econ.shouldBeUsed() && ! this.isAdminBypassing())
if (Econ.shouldBeUsed() && ! this.isAdminBypassing() && ! forFaction.isSafeZone() && ! forFaction.isWarZone())
{
double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
//String costString = Econ.moneyString(cost);

View File

@ -55,7 +55,7 @@ public class Factions extends EntityCollection<Faction>
if ( ! this.exists("-1"))
{
Faction faction = this.create("-1");
faction.setTag(ChatColor.GOLD+"Safe Zone");
faction.setTag("SafeZone");
faction.setDescription("Free from PVP and monsters");
}
@ -63,7 +63,7 @@ public class Factions extends EntityCollection<Faction>
if ( ! this.exists("-2"))
{
Faction faction = this.create("-2");
faction.setTag(ChatColor.DARK_RED+"War Zone");
faction.setTag("WarZone");
faction.setDescription("Not the safest place to be");
}
@ -153,7 +153,7 @@ public class Factions extends EntityCollection<Faction>
// TODO: Slow index building
for (Faction faction : this.get())
{
tag2faction.put(faction.getTag(), faction);
tag2faction.put(ChatColor.stripColor(faction.getTag()), faction);
}
String tag = TextUtil.getWhereLongestCommonStartCI(tag2faction.keySet(), pattern);

View File

@ -1,7 +1,6 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoClaim extends FCommand
@ -12,48 +11,32 @@ public class CmdAutoClaim extends FCommand
this.aliases.add("autoclaim");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.optionalArgs.put("faction", "your");
this.permission = Permission.AUTOCLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoClaimEnabled());
fme.setIsAutoClaimEnabled(enabled);
if ( ! enabled)
Faction forFaction = this.argAsFaction(0, myFaction);
if (forFaction == null || (forFaction == myFaction && fme.getAutoClaimFor() == myFaction))
{
fme.setAutoClaimFor(null);
msg("<i>Auto-claiming of land disabled.");
return;
}
FLocation flocation = new FLocation(fme);
if (Conf.worldsNoClaiming.contains(flocation.getWorldName()))
{
msg("<b>Sorry, this world has land claiming disabled.");
fme.setIsAutoClaimEnabled(false);
return;
}
if (myFaction.getLandRounded() >= myFaction.getPowerRounded())
{
msg("<b>You can't claim more land! You need more power!");
fme.setIsAutoClaimEnabled(false);
return;
}
msg("<i>Auto-claiming of land enabled.");
fme.attemptClaim(myFaction, me.getLocation(), false);
fme.setAutoClaimFor(forFaction);
msg("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(fme));
fme.attemptClaim(forFaction, me.getLocation(), true);
}
}
}

View File

@ -1,54 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoSafeclaim extends FCommand
{
public CmdAutoSafeclaim()
{
super();
this.aliases.add("autosafe");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.MANAGE_SAFE_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
this.setHelpShort("Auto-claim land for the safezone");
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoSafeClaimEnabled());
fme.setIsAutoSafeClaimEnabled(enabled);
if ( ! enabled)
{
msg("<i>Auto-claiming of safe zone disabled.");
return;
}
msg("<i>Auto-claiming of safe zone enabled.");
FLocation playerFlocation = new FLocation(fme);
if (!Board.getFactionAt(playerFlocation).isSafeZone())
{
Board.setFactionAt(Factions.i.getSafeZone(), playerFlocation);
msg("<i>This land is now a safe zone.");
}
}
}

View File

@ -1,55 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoWarclaim extends FCommand
{
public CmdAutoWarclaim()
{
super();
aliases.add("autowar");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.MANAGE_WAR_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
this.setHelpShort("Auto-claim land for the warzone");
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoWarClaimEnabled());
fme.setIsAutoWarClaimEnabled(enabled);
if ( ! enabled)
{
msg("<i>Auto-claiming of war zone disabled.");
return;
}
msg("<i>Auto-claiming of war zone enabled.");
FLocation playerFlocation = new FLocation(fme);
if (!Board.getFactionAt(playerFlocation).isWarZone())
{
Board.setFactionAt(Factions.i.getWarZone(), playerFlocation);
msg("<i>This land is now a war zone.");
}
}
}

View File

@ -18,7 +18,7 @@ public class CmdClaim extends FCommand
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;

View File

@ -160,11 +160,7 @@ public class CmdHelp extends FCommand
pageLines = new ArrayList<String>();
pageLines.add("Finally some commands for the server admins:");
pageLines.add( p.cmdBase.cmdBypass.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdSafeclaim.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdAutoSafeclaim.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdSafeunclaimall.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdWarclaim.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdAutoWarclaim.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdWarunclaimall.getUseageTemplate(true) );
pageLines.add(p.txt.parse("<i>Note: " + p.cmdBase.cmdUnclaim.getUseageTemplate(false) + P.p.txt.parse("<i>") + " works on safe/war zones as well."));
helpPages.add(pageLines);

View File

@ -1,50 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdSafeclaim extends FCommand
{
public CmdSafeclaim()
{
this.aliases.add("safeclaim");
this.aliases.add("safe");
//this.requiredArgs.add("");
this.optionalArgs.put("radius", "0");
this.permission = Permission.MANAGE_SAFE_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("Claim land for the safezone");
}
@Override
public void perform()
{
// The current location of the player
FLocation playerFlocation = new FLocation(fme);
int radius = this.argAsInt(0, 0);
if (radius < 0) radius = 0;
FLocation from = playerFlocation.getRelative(radius, radius);
FLocation to = playerFlocation.getRelative(-radius, -radius);
for (FLocation locToClaim : FLocation.getArea(from, to))
{
Board.setFactionAt(Factions.i.getSafeZone(), locToClaim);
}
msg("<i>You claimed <h>%d chunks<i> for the <a>safe zone<i>.", (1+radius*2)*(1+radius*2));
}
}

View File

@ -36,56 +36,6 @@ public class CmdUnclaimall extends FCommand
{
if ( ! Econ.modifyMoney(fme , refund, "to unclaim all faction land", "for unclaiming all faction land")) return;
}
//String moneyBack = "<i>";
/*if (Econ.shouldBeUsed())
{
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
// a real refund
if (refund > 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" <i>received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
else
{
Econ.addMoney(fme.getName(), refund);
moneyBack = " They received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
}
// wait, you're charging people to unclaim land? outrageous
else if (refund < 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
if(!faction.removeMoney(-refund))
{
msg("<b>Unclaiming all faction land will cost <h>"+Econ.moneyString(-refund)+"<b>, which your faction can't currently afford.");
return;
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
}
else
{
if (!Econ.deductMoney(fme.getName(), -refund))
{
msg("<b>Unclaiming all faction land will cost <h>"+Econ.moneyString(-refund)+"<b>, which you can't currently afford.");
return;
}
moneyBack = "<i> It cost them <h>"+Econ.moneyString(refund)+"<i>.";
}
moneyBack = "<i> It cost them <h>"+Econ.moneyString(refund)+"<i>.";
}
// no refund
else
{
moneyBack = "";
}
}*/
Board.unclaimAll(myFaction.getId());
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));

View File

@ -1,48 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdWarclaim extends FCommand
{
public CmdWarclaim()
{
this.aliases.add("warclaim");
this.aliases.add("war");
//this.requiredArgs.add("");
this.optionalArgs.put("radius", "0");
this.permission = Permission.MANAGE_WAR_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("Claim land for the warzone");
}
public void perform()
{
// The current location of the player
FLocation playerFlocation = new FLocation(fme);
int radius = this.argAsInt(0, 0);
if (radius < 0) radius = 0;
FLocation from = playerFlocation.getRelative(radius, radius);
FLocation to = playerFlocation.getRelative(-radius, -radius);
for (FLocation locToClaim : FLocation.getArea(from, to))
{
Board.setFactionAt(Factions.i.getWarZone(), locToClaim);
}
msg("<i>You claimed <h>%d chunks<i> for the <a>war zone<i>.", (1+radius*2)*(1+radius*2));
}
}

View File

@ -8,8 +8,6 @@ public class FCmdRoot extends FCommand
{
public CmdAdmin cmdAdmin = new CmdAdmin();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
public CmdAutoSafeclaim cmdAutoSafeclaim = new CmdAutoSafeclaim();
public CmdAutoWarclaim cmdAutoWarclaim = new CmdAutoWarclaim();
public CmdBoom cmdBoom = new CmdBoom();
public CmdBypass cmdBypass = new CmdBypass();
public CmdChat cmdChat = new CmdChat();
@ -40,7 +38,6 @@ public class FCmdRoot extends FCommand
public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy();
public CmdRelationNeutral cmdRelationNeutral = new CmdRelationNeutral();
public CmdReload cmdReload = new CmdReload();
public CmdSafeclaim cmdSafeclaim = new CmdSafeclaim();
public CmdSafeunclaimall cmdSafeunclaimall = new CmdSafeunclaimall();
public CmdSaveAll cmdSaveAll = new CmdSaveAll();
public CmdSethome cmdSethome = new CmdSethome();
@ -50,7 +47,6 @@ public class FCmdRoot extends FCommand
public CmdUnclaim cmdUnclaim = new CmdUnclaim();
public CmdUnclaimall cmdUnclaimall = new CmdUnclaimall();
public CmdVersion cmdVersion = new CmdVersion();
public CmdWarclaim cmdWarclaim = new CmdWarclaim();
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
public FCmdRoot()
@ -77,8 +73,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdAdmin);
this.addSubCommand(this.cmdAutoClaim);
this.addSubCommand(this.cmdAutoSafeclaim);
this.addSubCommand(this.cmdAutoWarclaim);
this.addSubCommand(this.cmdBoom);
this.addSubCommand(this.cmdBypass);
this.addSubCommand(this.cmdChat);
@ -109,7 +103,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdRelationEnemy);
this.addSubCommand(this.cmdRelationNeutral);
this.addSubCommand(this.cmdReload);
this.addSubCommand(this.cmdSafeclaim);
this.addSubCommand(this.cmdSafeunclaimall);
this.addSubCommand(this.cmdSaveAll);
this.addSubCommand(this.cmdSethome);
@ -119,7 +112,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdUnclaim);
this.addSubCommand(this.cmdUnclaimall);
this.addSubCommand(this.cmdVersion);
this.addSubCommand(this.cmdWarclaim);
this.addSubCommand(this.cmdWarunclaimall);
}

View File

@ -32,7 +32,6 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.zcore.util.TextUtil;
@ -252,34 +251,9 @@ public class FactionsPlayerListener extends PlayerListener
}
}
if (me.isAutoClaimEnabled())
if (me.getAutoClaimFor() != null)
{
Faction myFaction = me.getFaction();
// TODO: Why is this ("cost") here and unused??? Should it be used somewhere Brettflan? :)
// Olof just commented it out to avoid the error.
// So sayeth Brettflan, answered in a comment since you asked in a comment:
// NOTHING MORE TODO: it was used, but apparently not needed after some changes including this commit: https://github.com/MassiveCraft/Factions/commit/5eaf9c68358c6076bb856baf80fd6496e2ab02ce
//
//Faction otherFaction = Board.getFactionAt(to);
//double cost = Econ.calculateClaimCost(myFaction.getLandRounded(), otherFaction.isNormal());
if (me.getRole().value < Role.MODERATOR.value)
{
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.msg("<b>Sorry, this world has land claiming disabled.");
me.setIsAutoClaimEnabled(false);
}
else if (myFaction.getLandRounded() >= myFaction.getPowerRounded())
{
me.msg("<b>You can't claim more land! You need more power!");
me.setIsAutoClaimEnabled(false);
}
else
me.attemptClaim(myFaction, player.getLocation(), false);
me.attemptClaim(me.getAutoClaimFor(), player.getLocation(), true);
}
else if (me.isAutoSafeClaimEnabled())
{

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.util;
import java.util.Arrays;
import java.util.HashSet;
import org.bukkit.ChatColor;
import org.bukkit.entity.Creature;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
@ -51,6 +52,8 @@ public class MiscUtil
{
String ret = "";
str = ChatColor.stripColor(str);
for (char c : str.toCharArray())
{
if (substanceChars.contains(String.valueOf(c)))

View File

@ -116,10 +116,25 @@ public class RelationUtil
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
{
if (getFaction(that) != null && getFaction(that).isPeaceful() && getFaction(that) != getFaction(me))
Faction thatFaction = getFaction(that);
if (thatFaction != null)
{
return Conf.colorPeaceful;
if (thatFaction.isPeaceful() && thatFaction != getFaction(me))
{
return Conf.colorPeaceful;
}
if (thatFaction.isSafeZone() && thatFaction != getFaction(me))
{
return Conf.colorPeaceful;
}
if (thatFaction.isWarZone() && thatFaction != getFaction(me))
{
return Conf.colorWar;
}
}
return getRelationTo(that, me).getColor();
}
}