From 8fd088e2914fc73c6d6ec2a12ecf0af247ee99c3 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 25 Apr 2013 12:04:01 +0200 Subject: [PATCH] A few minor bugfixes and tweaks. --- .../factions/cmd/CmdFactionsAutoClaim.java | 1 + .../factions/cmd/CmdFactionsClaim.java | 2 +- .../factions/cmd/CmdFactionsDescription.java | 4 +- .../factions/cmd/CmdFactionsMap.java | 9 +- .../factions/cmd/CmdFactionsUnclaimall.java | 2 +- .../massivecraft/factions/entity/UPlayer.java | 86 ++++++++++--------- .../listeners/FactionsListenerMain.java | 8 +- 7 files changed, 60 insertions(+), 52 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 966fcdf2..dad9fc98 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -31,6 +31,7 @@ public class CmdFactionsAutoClaim extends FCommand return; } + // FPerm if (forFaction.isNormal() && !FPerm.TERRITORY.has(usender, forFaction, true)) return; usender.setAutoClaimFaction(forFaction); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index 4a8ff5d0..3c393c9c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -37,7 +37,7 @@ public class CmdFactionsClaim extends FCommand if (forFaction == null) return; // FPerm - if (!FPerm.TERRITORY.has(sender, forFaction, true)) return; + if (forFaction.isNormal() && !FPerm.TERRITORY.has(sender, forFaction, true)) return; // Validate if (radius < 1) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 77a3dd49..93216820 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -24,7 +24,7 @@ public class CmdFactionsDescription extends FCommand public void perform() { // Args - String newDescription = this.argConcatFrom(1); + String newDescription = this.argConcatFrom(0); // Event FactionsEventDescriptionChange event = new FactionsEventDescriptionChange(sender, usenderFaction, newDescription); @@ -33,7 +33,7 @@ public class CmdFactionsDescription extends FCommand newDescription = event.getNewDescription(); // Apply - usenderFaction.setDescription(this.argConcatFrom(1)); + usenderFaction.setDescription(newDescription); // Inform usenderFaction.msg("%s set your faction description to:\n%s", Mixin.getDisplayName(sender), usenderFaction.getDescription()); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index eb72efa1..7862455e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -30,13 +30,12 @@ public class CmdFactionsMap extends FCommand if (this.arg(0, ARBoolean.get(), !msender.isMapAutoUpdating())) { - // Turn on - - msender.setMapAutoUpdating(true); - msg("Map auto update ENABLED."); - // And show the map once showMap(); + + // Turn on + msender.setMapAutoUpdating(true); + msg("Map auto update ENABLED."); } else { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 59930b9a..9490f168 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -58,7 +58,7 @@ public class CmdFactionsUnclaimall extends FCommand } // Inform - usenderFaction.msg("%s unclaimed 5 of your 200 faction land. You now have 23 land left.", usender.describeTo(usenderFaction, true), countSuccess, countTotal, countFail); + usenderFaction.msg("%s unclaimed %d of your %d faction land. You now have %d land claimed.", usender.describeTo(usenderFaction, true), countSuccess, countTotal, countFail); // Log if (MConf.get().logLandUnclaims) diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index ea99d7b7..f84593ac 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -18,10 +18,10 @@ import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipC import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.ps.PS; -import com.massivecraft.mcore.ps.PSFormatSlug; import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.SenderUtil; +import com.massivecraft.mcore.util.Txt; public class UPlayer extends SenderEntity implements EconomyParticipator @@ -212,10 +212,10 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // Update index Faction oldFaction = FactionColls.get().get(this).get(oldFactionId); - Faction faction = FactionColls.get().get(this).get(factionId); + Faction faction = this.getFaction(); - oldFaction.uplayers.remove(this); - faction.uplayers.add(this); + if (oldFaction != null) oldFaction.uplayers.remove(this); + if (faction != null) faction.uplayers.add(this); // Mark as changed this.changed(); @@ -611,24 +611,12 @@ public class UPlayer extends SenderEntity implements EconomyParticipato { int ownedLand = newFaction.getLandCount(); - if (!uconf.claimingFromOthersAllowed && oldFaction.isNormal()) - { - msg("You may not claim land from others."); - return false; - } - if (mconf.worldsNoClaiming.contains(ps.getWorld())) { msg("Sorry, this world has land claiming disabled."); return false; } - if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) - { - msg("You can't claim this land due to your relation with the current owner."); - return false; - } - if (newFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers) { msg("Factions must have at least %s members to claim land.", uconf.claimsRequireMinFactionMembers); @@ -647,35 +635,50 @@ public class UPlayer extends SenderEntity implements EconomyParticipato return false; } - if - ( - uconf.claimsMustBeConnected - && newFaction.getLandCountInWorld(ps.getWorld()) > 0 - && !BoardColls.get().isConnectedPs(ps, newFaction) - && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !oldFaction.isNormal()) - ) + if (oldFaction.isNormal()) { - if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) + if (!uconf.claimingFromOthersAllowed) { - msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); + msg("You may not claim land from others."); + return false; } - else + + if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) { - msg("You can only claim additional land which is connected to your first claim!"); + msg("You can't claim this land due to your relation with the current owner."); + return false; + } + + if + ( + uconf.claimsMustBeConnected + && newFaction.getLandCountInWorld(ps.getWorld()) > 0 + && !BoardColls.get().isConnectedPs(ps, newFaction) + && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !oldFaction.isNormal()) + ) + { + if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) + { + msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); + } + else + { + msg("You can only claim additional land which is connected to your first claim!"); + } + return false; + } + + if (!oldFaction.hasLandInflation()) + { + msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(this)); + return false; + } + + if ( ! BoardColls.get().isBorderPs(ps)) + { + msg("You must start claiming land at the border of the territory."); + return false; } - return false; - } - - if (!oldFaction.hasLandInflation()) - { - msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(this)); - return false; - } - - if ( ! BoardColls.get().isBorderPs(ps)) - { - msg("You must start claiming land at the border of the territory."); - return false; } } @@ -705,7 +708,8 @@ public class UPlayer extends SenderEntity implements EconomyParticipato for (UPlayer informee : informees) { - informee.msg("%s did %s %s for %s from %s.", this.describeTo(informee, true), event.getType().toString().toLowerCase(), chunk.toString(PSFormatSlug.get()), newFaction.describeTo(informee), oldFaction.describeTo(informee)); + String chunkString = Txt.parse("%s %d %d", Mixin.getWorldDisplayName(chunk.getWorld()), chunk.getChunkX(), chunk.getChunkZ()); + informee.msg("%s did %s %s for %s from %s.", this.describeTo(informee, true), event.getType().toString().toLowerCase(), chunkString, newFaction.describeTo(informee), oldFaction.describeTo(informee)); } return true; diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 4f19c4ae..dbd787cd 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -486,11 +486,15 @@ public class FactionsListenerMain implements Listener @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void blockMonsters(EntityTargetEvent event) { - // If a monster is targeting something ... + // If a monster ... if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; + // ... is targeting something ... + Entity target = event.getTarget(); + if (target == null) return; + // ... at a place where monsters are forbidden ... - PS ps = PS.valueOf(event.getTarget()); + PS ps = PS.valueOf(target); Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.MONSTERS)) return;