From 390ad76fa66de576f79a0c6a4374bc72f9d0aac6 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 22 Apr 2013 14:16:07 +0200 Subject: [PATCH] Patched away the errors with ugly meassures. --- src/com/massivecraft/factions/FPerm.java | 16 +------- .../factions/TerritoryAccess.java | 15 ++++---- .../factions/cmd/CmdFactionsAccess.java | 4 +- .../massivecraft/factions/entity/Board.java | 2 +- .../massivecraft/factions/entity/FPlayer.java | 6 +-- .../listeners/FactionsListenerMain.java | 12 +++--- .../listeners/TodoFactionsPlayerListener.java | 38 ++++++++++--------- 7 files changed, 39 insertions(+), 54 deletions(-) diff --git a/src/com/massivecraft/factions/FPerm.java b/src/com/massivecraft/factions/FPerm.java index 8091ca01..3a49de83 100644 --- a/src/com/massivecraft/factions/FPerm.java +++ b/src/com/massivecraft/factions/FPerm.java @@ -8,9 +8,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import org.bukkit.Location; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; @@ -171,8 +169,6 @@ public enum FPerm private static final String errorpattern = "%s does not allow you to %s."; public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot) { - if (testSubject instanceof ConsoleCommandSender) return true; - RelationParticipator rpSubject = null; if (testSubject instanceof CommandSender) @@ -232,16 +228,8 @@ public enum FPerm return false; } } - return this.has(testSubject, access.getHostFaction(), informIfNot); - } - public boolean has(Object testSubject, Location loc, boolean informIfNot) - { - PS ps = PS.valueOf(loc); - return this.has(testSubject, ps, informIfNot); - } - public boolean has(Object testSubject, Location loc) - { - return this.has(testSubject, loc, false); + + return this.has(testSubject, BoardColls.get().getFactionAt(ps), informIfNot); } public boolean has(Object testSubject, PS ps) { diff --git a/src/com/massivecraft/factions/TerritoryAccess.java b/src/com/massivecraft/factions/TerritoryAccess.java index 1435a7ce..ed7e75c7 100644 --- a/src/com/massivecraft/factions/TerritoryAccess.java +++ b/src/com/massivecraft/factions/TerritoryAccess.java @@ -7,9 +7,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.FactionColls; public class TerritoryAccess { @@ -19,7 +18,6 @@ public class TerritoryAccess private String hostFactionId; public String getHostFactionId() { return this.hostFactionId; } - public Faction getHostFaction() { return FactionColl.get().get(this.hostFactionId); } public void setHostFactionId(String hostFactionId) { this.hostFactionId = hostFactionId; } private boolean hostFactionAllowed = true; @@ -105,7 +103,7 @@ public class TerritoryAccess if (testSubject instanceof String) return hostFactionId.equals((String)testSubject); else if (testSubject instanceof CommandSender) - return hostFactionId.equals(FPlayerColl.get().get(testSubject).getFactionId()); + return hostFactionId.equals(FPlayer.get(testSubject).getFactionId()); else if (testSubject instanceof FPlayer) return hostFactionId.equals(((FPlayer)testSubject).getFactionId()); else if (testSubject instanceof Faction) @@ -131,14 +129,14 @@ public class TerritoryAccess this.fplayerIds.clear(); } - public String factionList() + public String factionList(Faction universeExtractable) { StringBuilder list = new StringBuilder(); for (String factionID : factionIds) { if (list.length() > 0) list.append(", "); - list.append(FactionColl.get().get(factionID).getTag()); + list.append(FactionColls.get().get(universeExtractable).get(factionID).getTag()); } return list.toString(); } @@ -160,7 +158,7 @@ public class TerritoryAccess public boolean subjectHasAccess(Object testSubject) { if (testSubject instanceof Player) - return fPlayerHasAccess(FPlayerColl.get().get(testSubject)); + return fPlayerHasAccess(FPlayer.get(testSubject)); else if (testSubject instanceof FPlayer) return fPlayerHasAccess((FPlayer)testSubject); else if (testSubject instanceof Faction) @@ -184,7 +182,8 @@ public class TerritoryAccess // this should normally only be checked after running subjectHasAccess() or fPlayerHasAccess() above to see if they have access explicitly granted public boolean subjectAccessIsRestricted(Object testSubject) { - return ( ! this.isHostFactionAllowed() && this.doesHostFactionMatch(testSubject) && ! FPerm.ACCESS.has(testSubject, this.getHostFaction())); + Faction hostFaction = FactionColls.get().get(testSubject).get(this.getHostFactionId()); + return ( ! this.isHostFactionAllowed() && this.doesHostFactionMatch(testSubject) && ! FPerm.ACCESS.has(testSubject, hostFaction)); } //----------------------------------------------// diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java index 7134218f..4624e2d4 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java @@ -37,7 +37,7 @@ public class CmdFactionsAccess extends FCommand PS chunk = PS.valueOf(me).getChunk(true); TerritoryAccess territory = BoardColls.get().getTerritoryAccessAt(chunk); - Faction locFaction = territory.getHostFaction(); + Faction locFaction = BoardColls.get().getFactionAt(chunk); boolean accessAny = Perm.ACCESS_ANY.has(sender, false); if (type.isEmpty() || type.equals("view")) @@ -96,7 +96,7 @@ public class CmdFactionsAccess extends FCommand msg("Host faction %s has %s in this territory.", locFaction.getTag(), Txt.parse(territory.isHostFactionAllowed() ? "normal access" : "restricted access")); String players = territory.fplayerList(); - String factions = territory.factionList(); + String factions = territory.factionList(locFaction); if (factions.isEmpty()) msg("No factions have been explicitly granted access."); diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index e31e3012..ea060201 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -98,7 +98,7 @@ public class Board extends Entity implements BoardInterface public Faction getFactionAt(PS ps) { if (ps == null) return null; - return this.getTerritoryAccessAt(ps).getHostFaction(); + return FactionColls.get().get(this).get(this.getTerritoryAccessAt(ps).getHostFactionId()); } // SET diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index 6d797579..8f9a0cb2 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -153,13 +153,9 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public FPlayer() { this.resetFactionData(false); + this.setFactionId(ConfServer.newPlayerStartingFactionID); this.power = ConfServer.powerStarting; this.lastPowerUpdateTime = System.currentTimeMillis(); - - if ( ! ConfServer.newPlayerStartingFactionID.equals(Const.FACTIONID_NONE) && FactionColl.get().containsId(ConfServer.newPlayerStartingFactionID)) - { - this.factionId = ConfServer.newPlayerStartingFactionID; - } } public final void resetFactionData(boolean doSpoutUpdate) diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 457dc377..97c3772c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -5,7 +5,6 @@ import java.util.Collection; import java.util.Iterator; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Enderman; import org.bukkit.entity.Entity; @@ -594,7 +593,7 @@ public class FactionsListenerMain implements Listener if (targetFaction == pistonFaction) return; // if potentially pushing into air/water/lava in another territory, we need to check it out - if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && ! FPerm.BUILD.has(pistonFaction, targetBlock.getLocation())) + if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && ! FPerm.BUILD.has(pistonFaction, PS.valueOf(targetBlock))) { event.setCancelled(true); } @@ -614,18 +613,19 @@ public class FactionsListenerMain implements Listener // if not a sticky piston, retraction should be fine if (!event.isSticky()) return; - Location targetLoc = event.getRetractLocation(); + Block retractBlock = event.getRetractLocation().getBlock(); + PS retractPs = PS.valueOf(retractBlock); // if potentially retracted block is just air/water/lava, no worries - if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return; + if (retractBlock.isEmpty() || retractBlock.isLiquid()) return; Faction pistonFaction = BoardColls.get().getFactionAt(PS.valueOf(event.getBlock())); // members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case - Faction targetFaction = BoardColls.get().getFactionAt(PS.valueOf(targetLoc)); + Faction targetFaction = BoardColls.get().getFactionAt(retractPs); if (targetFaction == pistonFaction) return; - if ( ! FPerm.BUILD.has(pistonFaction, targetLoc)) + if (!FPerm.BUILD.has(pistonFaction, retractPs)) { event.setCancelled(true); } diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index 2094c5ea..befb089c 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.listeners; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -82,7 +81,7 @@ public class TodoFactionsPlayerListener implements Listener TerritoryAccess access = BoardColls.get().getTerritoryAccessAt(chunkTo); // Did we change "host"(faction)? - boolean changedFaction = (BoardColls.get().getFactionAt(chunkFrom) != access.getHostFaction()); + boolean changedFaction = (BoardColls.get().getFactionAt(chunkFrom) != BoardColls.get().getFactionAt(chunkTo)); // let Spout handle most of this if it's available boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(fplayer); @@ -130,41 +129,44 @@ public class TodoFactionsPlayerListener implements Listener if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; // only interested on right-clicks for below - if ( ! playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) + if ( ! playerCanUseItemHere(player, PS.valueOf(block), event.getMaterial(), false)) { event.setCancelled(true); return; } } - // TODO: Refactor ! justCheck -> to informIfNot // TODO: Possibly incorporate pain build... - public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck) + public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean justCheck) { + if (!Const.MATERIALS_EDIT_TOOLS.contains(material)) return true; + String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; - FPlayer me = FPlayer.get(name); - if (me.isUsingAdminMode()) return true; - if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; - return true; + FPlayer fplayer = FPlayer.get(player); + if (fplayer.isUsingAdminMode()) return true; + + return FPerm.BUILD.has(fplayer, ps, !justCheck); } + public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) { String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; - FPlayer me = FPlayer.get(name); + FPlayer me = FPlayer.get(player); if (me.isUsingAdminMode()) return true; - Location loc = block.getLocation(); + + PS ps = PS.valueOf(block); Material material = block.getType(); - if (Const.MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; - if (Const.MATERIALS_CONTAINER.contains(material) && ! FPerm.CONTAINER.has(me, loc, ! justCheck)) return false; - if (Const.MATERIALS_DOOR.contains(material) && ! FPerm.DOOR.has(me, loc, ! justCheck)) return false; - if (material == Material.STONE_BUTTON && ! FPerm.BUTTON.has(me, loc, ! justCheck)) return false; - if (material == Material.LEVER && ! FPerm.LEVER.has(me, loc, ! justCheck)) return false; + if (Const.MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, ps, ! justCheck)) return false; + if (Const.MATERIALS_CONTAINER.contains(material) && ! FPerm.CONTAINER.has(me, ps, ! justCheck)) return false; + if (Const.MATERIALS_DOOR.contains(material) && ! FPerm.DOOR.has(me, ps, ! justCheck)) return false; + if (material == Material.STONE_BUTTON && ! FPerm.BUTTON.has(me, ps, ! justCheck)) return false; + if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false; return true; } @@ -176,7 +178,7 @@ public class TodoFactionsPlayerListener implements Listener Block block = event.getBlockClicked(); Player player = event.getPlayer(); - if ( ! playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) + if ( ! playerCanUseItemHere(player, PS.valueOf(block), event.getBucket(), false)) { event.setCancelled(true); return; @@ -188,7 +190,7 @@ public class TodoFactionsPlayerListener implements Listener Block block = event.getBlockClicked(); Player player = event.getPlayer(); - if ( ! playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) + if ( ! playerCanUseItemHere(player, PS.valueOf(block), event.getBucket(), false)) { event.setCancelled(true); return;