From 6384a562c8a756ec1f1a14a9884ec4d5f5946e50 Mon Sep 17 00:00:00 2001 From: ementalo Date: Sat, 16 Jul 2011 23:53:53 +0100 Subject: [PATCH 1/8] essentials.mute.exempt prevents muting, send messages when a player is muted to the muted --- .../essentials/EssentialsPlayerListener.java | 1 + .../essentials/commands/Commandmute.java | 19 +++++++++++++++---- Essentials/src/messages.properties | 4 ++++ Essentials/src/messages_da.properties | 4 ++++ Essentials/src/messages_de.properties | 4 ++++ Essentials/src/messages_en.properties | 3 +++ Essentials/src/messages_fr.properties | 4 ++++ Essentials/src/messages_nl.properties | 4 ++++ 8 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 64905a4bc..f727681f1 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -60,6 +60,7 @@ public class EssentialsPlayerListener extends PlayerListener if (user.isMuted()) { event.setCancelled(true); + user.sendMessage(Util.i18n("playeMuted")); LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); } final Iterator it = event.getRecipients().iterator(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index aca821aac..14bc41b3c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -21,7 +21,12 @@ public class Commandmute extends EssentialsCommand throw new NotEnoughArgumentsException(); } - User p = getPlayer(server, args, 0); + User p = getPlayer(server, args, 0, true); + if (p.isAuthorized("essentials.mute.exempt")) + { + sender.sendMessage(commandLabel); + return; + } long muteTimestamp = 0; if (args.length > 1) { @@ -30,13 +35,19 @@ public class Commandmute extends EssentialsCommand } p.setMuteTimeout(muteTimestamp); charge(sender); - - + boolean muted = p.toggleMuted(); sender.sendMessage( - p.toggleMuted() + muted ? (muteTimestamp > 0 ? Util.format("mutedPlayerFor", p.getDisplayName(), Util.formatDateDiff(muteTimestamp)) : Util.format("mutedPlayer", p.getDisplayName())) : Util.format("unmutedPlayer", p.getDisplayName())); + p.sendMessage( + muted + ? (muteTimestamp > 0 + ? Util.format("playerMutedFor", Util.formatDateDiff(muteTimestamp)) + : Util.i18n("playerMuted")) + : Util.i18n("playerUnmuted")); + } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index cd7607c24..6cd465575 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -182,6 +182,7 @@ nickSet = \u00a77Your nickname is now \u00a7c{0} noAccessCommand = \u00a7cYou do not have access to that command. noAccessPermission = \u00a7cYou do not have permission to access that {0}. noDestroyPermission = \u00a7cYou do not have permission to destroy that {0}. +noHelpFound = \u00a7cNo matching commands. noHomeSet = You have not set a home. noHomeSetPlayer = Player has not set a home. noKitPermission = \u00a7cYou need the \u00a7c{0}\u00a7c permission to use that kit. @@ -213,8 +214,11 @@ playerInJail = \u00a7cPlayer is already in jail {0}. playerJailed = \u00a77Player {0} jailed. playerJailedFor = \u00a77Player {0} jailed for {1}. playerKicked = \u00a7cPlayer {0} kicked: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cPlayer {0} was never on this server. playerNotFound = \u00a7cPlayer not found. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77Possible worlds are the numbers 0 through {0}. powerToolAir = Command can''t be attached to air. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index bd0352289..84b851a0c 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -184,6 +184,7 @@ nickSet = \u00a77Dit kaldenavn er nu \u00a7c{0} noAccessCommand = \u00a7cDu har ikke adgang til den kommando. noAccessPermission = \u00a7cDu har ikke tilladelse til at f\u00e5 adgang til det {0}. noDestroyPermission = \u00a7cDu har ikke tilladelse til at \u00f8del\u00e6gge det {0}. +noHelpFound = \u00a7cNo matching commands. noHomeSet = Du har sat et nyt hjem. noHomeSetPlayer = Spiller har ikke sat et hjem. noKitPermission = \u00a7cDu har brug for \u00a7c{0}\u00a7c tilladelsen for at bruge den pakke. @@ -215,8 +216,11 @@ playerInJail = \u00a7cSpiller er allerede i f\u00e6ngsel {0}. playerJailed = \u00a77Spiller {0} f\u00e6ngslet. playerJailedFor = \u00a77Spiller {0} f\u00e6ngslet for {1}. playerKicked = \u00a7cPlayer {0} kicked: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cSpiller {0} var aldrig p\u00e5 denne server. playerNotFound = \u00a7cSpiller ikke fundet. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77Mulige verdener er numrene 0 igennem {0}. powerToolAir = Kommando kan ikke blive tildelt luft. diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index cfc7f41e4..e2a0e8401 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -182,6 +182,7 @@ nickSet = \u00a77Dein Nickname ist nun \u00a7c{0} noAccessCommand = \u00a7cDu hast keinen Zugriff auf diesen Befehl. noAccessPermission = \u00a7cDu hast keine Rechte, den Block {0} zu \u00f6ffnen. noDestroyPermission = \u00a7cDu hast keine Rechte, den Block {0} zu zerst\u00f6ren. +noHelpFound = \u00a7cNo matching commands. noHomeSet = Du hast kein Zuhause gesetzt. noHomeSetPlayer = Spieler hat kein Zuhause gesetzt. noKitPermission = \u00a7cDu brauchst die Berechtigung \u00a7c{0}\u00a7c um diese Ausr\u00fcstung anzufordern. @@ -213,8 +214,11 @@ playerInJail = \u00a7cSpieler ist bereits in Gef\u00e4ngnis {0}. playerJailed = \u00a77Spieler {0} eingesperrt. playerJailedFor = \u00a77Spieler {0} eingesperrt f\u00fcr {1}. playerKicked = \u00a7cSpieler {0} rausgeworfen: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cSpieler {0} war niemals auf diesem Server. playerNotFound = \u00a7cSpieler nicht gefunden. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77M\u00f6gliche Welten sind nummeriet von 0 bis {0}. powerToolAir = Befehl kann nicht mit Luft verbunden werden. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index d65e6fd7f..d5c088eef 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -214,8 +214,11 @@ playerInJail = \u00a7cPlayer is already in jail {0}. playerJailed = \u00a77Player {0} jailed. playerJailedFor = \u00a77Player {0} jailed for {1}. playerKicked = \u00a7cPlayer {0} kicked: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cPlayer {0} was never on this server. playerNotFound = \u00a7cPlayer not found. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77Possible worlds are the numbers 0 through {0}. powerToolAir = Command can''t be attached to air. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index e5591cb96..ed5890c2e 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -182,6 +182,7 @@ nickSet = \u00a77Votre pseudo est maintenant \u00a7c{0} noAccessCommand = \u00a7cVous n''avez pas acc\u00e8s \u00e0 cette commande. noAccessPermission = \u00a7cVous n''avez pas la permissions d''acc\u00e9der \u00e0 cette {0} noDestroyPermission = \u00a7cVous n''avez pas la permission de d\u00e9truire ce {0}. +noHelpFound = \u00a7cNo matching commands. noHomeSet = Vous n''avez pas d\u00e9fini de home. noHomeSetPlayer = Le joueur n''a pas d\u00e9fini son home. noKitPermission = \u00a7cVous avez besoin de la permission \u00a7c{0}\u00a7c pour utiliser ce kit. @@ -213,8 +214,11 @@ playerInJail = \u00a7cLe joueur est d\u00e9j\u00e0 dans la prison {0}. playerJailed = \u00a77Le joueur {0} a \u00e9t\u00e9 emprisonn\u00e9. playerJailedFor = \u00a77{0} a \u00e9t\u00e9 emprisonn\u00e9 pour {1}. playerKicked = \u00a7cPlayer {0} kicked: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cLe joueur {0} n''a jamais \u00e9t\u00e9 sur le serveur. playerNotFound = \u00a7cLe joueur est introuvable. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77Les mondes possibles sont les nombres 0 par {0}. powerToolAir = La commande ne peut pas \u00eatre attach\u00e9e \u00e0 l''air. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 5091b6d42..0658d5cbf 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -183,6 +183,7 @@ nickSet = \u00a77Je nickname is nu \u00a7c{0} noAccessCommand = \u00a7cJe hebt geen toegang tot die opdracht. noAccessPermission = \u00a7cJe hebt hier geen toegang voor {0}. noDestroyPermission = \u00a7cJe hebt geen toegang om dat te vernietigen {0}. +noHelpFound = \u00a7cNo matching commands. noHomeSet = Je hebt geen home gemaakt. noHomeSetPlayer = Speler heeft geen home. noKitPermission = \u00a7cJe hebt de \u00a7c{0}\u00a7c toestemming nodig om die kit te gebruiken. @@ -214,8 +215,11 @@ playerInJail = \u00a7cSpeler zit al in de gevangenis {0}. playerJailed = \u00a77Speler {0} is in de gevangenis gezet. playerJailedFor = \u00a77Speler {0} is in de gevangenis gezet voor {1}. playerKicked = \u00a7cPlayer {0} kicked: {1} +playerMuted = "$7You have been muted" +playerMutedFor = "$7You have been muted for {0}" playerNeverOnServer = \u00a7cSpeler {0} is nooit op deze server geweest. playerNotFound = \u00a7cSpeler niet gevonden. +playerUnmuted = "$7You have been unmuted" pong = Pong! possibleWorlds = \u00a77Mogelijk zijn de werelden de nummer 0 tot en met {0}. powerToolAir = Command kan niet worden bevestigd aan de lucht. From 51e0b61fbb9de571a5fb4567c817bc7efeec0f13 Mon Sep 17 00:00:00 2001 From: ementalo Date: Sun, 17 Jul 2011 00:13:57 +0100 Subject: [PATCH 2/8] Test #706. essentials.mute.exempt - messages for mute players --- .../src/com/earth2me/essentials/EssentialsPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index f727681f1..f539227f0 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -60,7 +60,7 @@ public class EssentialsPlayerListener extends PlayerListener if (user.isMuted()) { event.setCancelled(true); - user.sendMessage(Util.i18n("playeMuted")); + user.sendMessage(Util.i18n("playerMuted")); LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); } final Iterator it = event.getRecipients().iterator(); From ef4433c9fd580b7c90d94850a6c28ceb7c3c99ae Mon Sep 17 00:00:00 2001 From: ementalo Date: Sun, 17 Jul 2011 22:31:12 +0100 Subject: [PATCH 3/8] CB #1000 Bukkit #700 --- .../com/earth2me/essentials/Essentials.java | 2 +- .../com/earth2me/essentials/FakeWorld.java | 30 ++++++++- .../earth2me/essentials/OfflinePlayer.java | 65 +++++++++++++++++++ .../earth2me/essentials/PlayerWrapper.java | 64 ++++++++++++++++++ .../com/earth2me/essentials/FakeServer.java | 6 ++ 5 files changed, 165 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index a7252b1c5..de51196a6 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -46,7 +46,7 @@ import org.bukkit.plugin.java.*; public class Essentials extends JavaPlugin implements IEssentials { - public static final int BUKKIT_VERSION = 974; + public static final int BUKKIT_VERSION = 1000; private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); diff --git a/Essentials/src/com/earth2me/essentials/FakeWorld.java b/Essentials/src/com/earth2me/essentials/FakeWorld.java index 976566704..7f5acae03 100644 --- a/Essentials/src/com/earth2me/essentials/FakeWorld.java +++ b/Essentials/src/com/earth2me/essentials/FakeWorld.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import java.util.List; +import java.util.UUID; import org.bukkit.BlockChangeDelegate; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; @@ -8,6 +9,7 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.TreeType; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.entity.Arrow; import org.bukkit.entity.Boat; @@ -392,7 +394,33 @@ public class FakeWorld implements World throw new UnsupportedOperationException("Not supported yet."); } - public long getUID() + public UUID getUID() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Block getHighestBlockAt(int i, int i1) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Block getHighestBlockAt(Location lctn) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + + public Biome getBiome(int i, int i1) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public double getTemperature(int i, int i1) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public double getHumidity(int i, int i1) { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index ff0b73fbd..1e15c30a0 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -3,6 +3,7 @@ package com.earth2me.essentials; import java.net.InetSocketAddress; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.UUID; import org.bukkit.Achievement; import org.bukkit.Effect; @@ -23,6 +24,10 @@ import org.bukkit.entity.Vehicle; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; @@ -513,4 +518,64 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } + + public boolean isPermissionSet(String string) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isPermissionSet(Permission prmsn) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean hasPermission(String string) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean hasPermission(Permission prmsn) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PermissionAttachment addAttachment(Plugin plugin) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PermissionAttachment addAttachment(Plugin plugin, int i) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void removeAttachment(PermissionAttachment pa) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void recalculatePermissions() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Set getEffectivePermissions() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void setOp(boolean bln) + { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java index 99ade90ce..8acd7fed6 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java +++ b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java @@ -7,6 +7,10 @@ import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.*; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; public class PlayerWrapper implements Player @@ -560,4 +564,64 @@ public class PlayerWrapper implements Player { base.resetPlayerTime(); } + + public boolean isPermissionSet(String string) + { + return base.isPermissionSet(string); + } + + public boolean isPermissionSet(Permission prmsn) + { + return base.isPermissionSet(prmsn); + } + + public boolean hasPermission(String string) + { + return base.hasPermission(string); + } + + public boolean hasPermission(Permission prmsn) + { + return base.hasPermission(prmsn); + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) + { + return base.addAttachment(plugin, string, bln); + } + + public PermissionAttachment addAttachment(Plugin plugin) + { + return base.addAttachment(plugin); + } + + public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) + { + return base.addAttachment(plugin, string, bln, i); + } + + public PermissionAttachment addAttachment(Plugin plugin, int i) + { + return base.addAttachment(plugin, i); + } + + public void removeAttachment(PermissionAttachment pa) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void recalculatePermissions() + { + base.recalculatePermissions(); + } + + public Set getEffectivePermissions() + { + return base.getEffectivePermissions(); + } + + public void setOp(boolean bln) + { + base.setOp(bln); + } } diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index 1d2ddd9c1..a8e8dd89b 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -4,6 +4,7 @@ import com.avaje.ebean.config.ServerConfig; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Server; @@ -244,4 +245,9 @@ public class FakeServer implements Server { throw new UnsupportedOperationException("Not supported yet."); } + + public World getWorld(UUID uuid) + { + throw new UnsupportedOperationException("Not supported yet."); + } } From 15c088e6dee3b470b7de80c95f7ec639613593e8 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 00:30:39 +0200 Subject: [PATCH 4/8] Bukkit Permission system New config setting: use-bukkit-permissions --- .../essentials/BukkitPermissionsHandler.java | 39 +++++++++++++++++++ .../com/earth2me/essentials/Essentials.java | 11 +++++- .../com/earth2me/essentials/ISettings.java | 2 + .../earth2me/essentials/OfflinePlayer.java | 10 ++--- .../src/com/earth2me/essentials/Settings.java | 6 ++- Essentials/src/config.yml | 6 +++ 6 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java diff --git a/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java new file mode 100644 index 000000000..a352bcb5a --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java @@ -0,0 +1,39 @@ +package com.earth2me.essentials; + +import org.bukkit.entity.Player; + + +public class BukkitPermissionsHandler implements IPermissionsHandler +{ + + public String getGroup(Player base) + { + return "default"; + } + + public boolean canBuild(Player base, String group) + { + return true; + } + + public boolean inGroup(Player base, String group) + { + return false; + } + + public boolean hasPermission(Player base, String node) + { + return base.hasPermission(node); + } + + public String getPrefix(Player base) + { + return ""; + } + + public String getSuffix(Player base) + { + return ""; + } + +} diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index de51196a6..9bd0998f8 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -158,7 +158,14 @@ public class Essentials extends JavaPlugin implements IEssentials } else { - this.permissionsHandler = new ConfigPermissionsHandler(this); + if (this.getSettings().useBukkitPermissions()) + { + this.permissionsHandler = new BukkitPermissionsHandler(); + } + else + { + this.permissionsHandler = new ConfigPermissionsHandler(this); + } } final ServerListener serverListener = new EssentialsPluginListener(paymentMethod); @@ -642,7 +649,7 @@ public class Essentials extends JavaPlugin implements IEssentials { return bans; } - + public ItemDb getItemDb() { return itemDb; diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 638f0593a..c53992461 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -128,4 +128,6 @@ public interface ISettings extends IConf boolean changeDisplayName(); boolean isPlayerCommand(String string); + + public boolean useBukkitPermissions(); } diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index 1e15c30a0..895e2c4d5 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -521,22 +521,22 @@ public class OfflinePlayer implements Player public boolean isPermissionSet(String string) { - throw new UnsupportedOperationException("Not supported yet."); + return false; } public boolean isPermissionSet(Permission prmsn) { - throw new UnsupportedOperationException("Not supported yet."); + return false; } public boolean hasPermission(String string) { - throw new UnsupportedOperationException("Not supported yet."); + return false; } public boolean hasPermission(Permission prmsn) { - throw new UnsupportedOperationException("Not supported yet."); + return false; } public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) @@ -566,7 +566,6 @@ public class OfflinePlayer implements Player public void recalculatePermissions() { - throw new UnsupportedOperationException("Not supported yet."); } public Set getEffectivePermissions() @@ -576,6 +575,5 @@ public class OfflinePlayer implements Player public void setOp(boolean bln) { - throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index d63bc7194..9f4bde9e0 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -463,5 +463,9 @@ public class Settings implements ISettings { return config.getBoolean("change-displayname", true); } - + + public boolean useBukkitPermissions() + { + return config.getBoolean("use-bukkit-permissions", false); + } } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index d50144956..90f8372cb 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -182,10 +182,16 @@ debug: false # Set the locale for all messages # If you don't set this, the default locale of the server will be used. +# Don't forget to remove the # infront of the line #locale: de_DE #turn off god mode when people exit remove-god-on-disconnect: false + +# Use the permission system of bukkit +# This only works if no other permission plugins are installed +use-bukkit-permissions: false + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | # From 424781c4a7ce41f5d432ebe3f557eb10d80d05a6 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 00:50:03 +0200 Subject: [PATCH 5/8] Protection of signs against pistons --- .../com/earth2me/essentials/Essentials.java | 2 + .../essentials/signs/EssentialsSign.java | 12 ++- .../essentials/signs/SignBlockListener.java | 78 ++++++++++++++++--- .../essentials/signs/SignProtection.java | 76 ++++++++++-------- 4 files changed, 118 insertions(+), 50 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 9bd0998f8..45a2aff60 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -197,6 +197,8 @@ public class Essentials extends JavaPlugin implements IEssentials pm.registerEvent(Type.BLOCK_BREAK, signBlockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_IGNITE, signBlockListener, Priority.Low, this); pm.registerEvent(Type.BLOCK_BURN, signBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_PISTON_EXTEND, signBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_PISTON_RETRACT, signBlockListener, Priority.Low, this); final SignPlayerListener signPlayerListener = new SignPlayerListener(this); pm.registerEvent(Type.PLAYER_INTERACT, signPlayerListener, Priority.Low, this); diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index c4853c31e..4884ce6f0 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -189,6 +189,11 @@ public class EssentialsSign return true; } + public boolean onBlockPush(Block block, IEssentials ess) + { + return true; + } + public static boolean checkIfBlockBreaksSigns(final Block block) { if (block.getFace(BlockFace.UP).getType() == Material.SIGN_POST) @@ -333,7 +338,7 @@ public class EssentialsSign protected final Double getDoublePositive(final String line) throws SignException { final double quantity = getDouble(line); - if (Math.round(quantity*100.0) < 1.0) + if (Math.round(quantity * 100.0) < 1.0) { throw new SignException(Util.i18n("moreThanZero")); } @@ -425,7 +430,6 @@ public class EssentialsSign { return; } - } @@ -454,7 +458,7 @@ public class EssentialsSign { return block; } - + public final void updateSign() { sign.update(); @@ -469,7 +473,7 @@ public class EssentialsSign void setLine(final int index, final String text); public Block getBlock(); - + void updateSign(); } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index c452e1b63..7574b7691 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -13,6 +13,8 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; @@ -21,12 +23,12 @@ public class SignBlockListener extends BlockListener { private final transient IEssentials ess; private final static Logger LOGGER = Logger.getLogger("Minecraft"); - + public SignBlockListener(IEssentials ess) { this.ess = ess; } - + @Override public void onBlockBreak(final BlockBreakEvent event) { @@ -34,13 +36,13 @@ public class SignBlockListener extends BlockListener { return; } - + if (protectSignsAndBlocks(event.getBlock(), event.getPlayer())) { event.setCancelled(true); } } - + public boolean protectSignsAndBlocks(final Block block, final Player player) { final int mat = block.getTypeId(); @@ -78,7 +80,7 @@ public class SignBlockListener extends BlockListener } return false; } - + @Override public void onSignChange(final SignChangeEvent event) { @@ -104,12 +106,13 @@ public class SignBlockListener extends BlockListener User user = ess.getUser(event.getPlayer()); if (user.isAuthorized("essentials.signs.color")) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) + { event.setLine(i, event.getLine(i).replaceAll("&([0-9a-f])", "§$1")); } } } - + @Override public void onBlockPlace(final BlockPlaceEvent event) { @@ -117,7 +120,7 @@ public class SignBlockListener extends BlockListener { return; } - + final Block against = event.getBlockAgainst(); if (against.getType() == Material.WALL_SIGN || against.getType() == Material.SIGN_POST) @@ -142,7 +145,7 @@ public class SignBlockListener extends BlockListener } } } - + @Override public void onBlockBurn(final BlockBurnEvent event) { @@ -150,7 +153,7 @@ public class SignBlockListener extends BlockListener { return; } - + final Block block = event.getBlock(); if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST @@ -170,7 +173,7 @@ public class SignBlockListener extends BlockListener } } } - + @Override public void onBlockIgnite(final BlockIgniteEvent event) { @@ -178,10 +181,61 @@ public class SignBlockListener extends BlockListener { return; } - + if (protectSignsAndBlocks(event.getBlock(), event.getPlayer())) { event.setCancelled(true); } } + + @Override + public void onBlockPistonExtend(BlockPistonExtendEvent event) + { + for (Block block : event.getBlocks()) + { + if ((block.getType() == Material.WALL_SIGN + || block.getType() == Material.SIGN_POST + || EssentialsSign.checkIfBlockBreaksSigns(block))) + { + event.setCancelled(true); + return; + } + for (Signs signs : Signs.values()) + { + final EssentialsSign sign = signs.getSign(); + if (sign.getBlocks().contains(block.getType()) + && !sign.onBlockPush(block, ess)) + { + event.setCancelled(true); + return; + } + } + } + } + + @Override + public void onBlockPistonRetract(BlockPistonRetractEvent event) + { + if (event.isSticky()) + { + final Block block = event.getBlock(); + if ((block.getType() == Material.WALL_SIGN + || block.getType() == Material.SIGN_POST + || EssentialsSign.checkIfBlockBreaksSigns(block))) + { + event.setCancelled(true); + return; + } + for (Signs signs : Signs.values()) + { + final EssentialsSign sign = signs.getSign(); + if (sign.getBlocks().contains(block.getType()) + && !sign.onBlockPush(block, ess)) + { + event.setCancelled(true); + return; + } + } + } + } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index 555bb0114..1e2813b5b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -21,7 +21,7 @@ import org.bukkit.inventory.ItemStack; public class SignProtection extends EssentialsSign { private final transient Set protectedBlocks = EnumSet.noneOf(Material.class); - + public SignProtection() { super("Protection"); @@ -30,7 +30,7 @@ public class SignProtection extends EssentialsSign protectedBlocks.add(Material.FURNACE); protectedBlocks.add(Material.DISPENSER); } - + @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { @@ -43,14 +43,14 @@ public class SignProtection extends EssentialsSign player.sendMessage("§4You are not allowed to create sign here."); return false; } - + @Override protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = checkProtectionSign(sign, player, username); return state == SignProtectionState.OWNER; } - + public boolean hasAdjacentBlock(final Block block, final Block... ignoredBlocks) { final Block[] faces = getAdjacentBlocks(block); @@ -70,7 +70,7 @@ public class SignProtection extends EssentialsSign } return false; } - + private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess) { final Map signs = getConnectedSigns(block, player, username, false); @@ -88,14 +88,14 @@ public class SignProtection extends EssentialsSign } } } - + private Map getConnectedSigns(final Block block, final User user, final String username, boolean secure) { final Map signs = new HashMap(); getConnectedSigns(block, signs, user, username, secure ? 4 : 2); return signs; } - + private void getConnectedSigns(final Block block, final Map signs, final User user, final String username, final int depth) { final Block[] faces = getAdjacentBlocks(block); @@ -108,20 +108,20 @@ public class SignProtection extends EssentialsSign } final SignProtectionState check = checkProtectionSign(b, user, username); signs.put(loc, check); - + if (protectedBlocks.contains(b.getType()) && depth > 0) { getConnectedSigns(b, signs, user, username, depth - 1); } } } - - + + public enum SignProtectionState { NOT_ALLOWED, ALLOWED, NOSIGN, OWNER } - + private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) { if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) @@ -134,7 +134,7 @@ public class SignProtection extends EssentialsSign } return SignProtectionState.NOSIGN; } - + private SignProtectionState checkProtectionSign(final ISign sign, final User user, final String username) { if (user == null || username == null) @@ -163,7 +163,7 @@ public class SignProtection extends EssentialsSign } return SignProtectionState.NOT_ALLOWED; } - + private Block[] getAdjacentBlocks(final Block block) { return new Block[] @@ -176,7 +176,7 @@ public class SignProtection extends EssentialsSign block.getFace(BlockFace.UP) }; } - + public SignProtectionState isBlockProtected(final Block block, final User user, final String username, boolean secure) { final Map signs = getConnectedSigns(block, user, username, secure); @@ -194,7 +194,7 @@ public class SignProtection extends EssentialsSign } return retstate; } - + public boolean isBlockProtected(final Block block) { final Block[] faces = getAdjacentBlocks(block); @@ -211,7 +211,7 @@ public class SignProtection extends EssentialsSign if (protectedBlocks.contains(b.getType())) { final Block[] faceChest = getAdjacentBlocks(b); - + for (Block a : faceChest) { if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN) @@ -227,20 +227,20 @@ public class SignProtection extends EssentialsSign } return false; } - + @Override public Set getBlocks() { return protectedBlocks; } - + @Override protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException { for (Block adjBlock : getAdjacentBlocks(block)) { final SignProtectionState state = isBlockProtected(adjBlock, player, username, true); - + if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED) && !player.isAuthorized("essentials.signs.protection.override")) { @@ -249,66 +249,74 @@ public class SignProtection extends EssentialsSign } } return true; - + } - + @Override protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = isBlockProtected(block, player, username, false); - + if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN || state == SignProtectionState.ALLOWED) { return true; } - + if (state == SignProtectionState.NOT_ALLOWED && player.isAuthorized("essentials.signs.protection.override")) { return true; } - - + + player.sendMessage(Util.format("noAccessPermission", block.getType().toString().toLowerCase())); return false; } - + @Override protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = isBlockProtected(block, player, username, false); - + if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN) { checkIfSignsAreBroken(block, player, username, ess); return true; } - + if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED) && player.isAuthorized("essentials.signs.protection.override")) { checkIfSignsAreBroken(block, player, username, ess); return true; } - - + + player.sendMessage(Util.format("noDestroyPermission", block.getType().toString().toLowerCase())); return false; } - + @Override public boolean onBlockExplode(final Block block, final IEssentials ess) { final SignProtectionState state = isBlockProtected(block, null, null, false); - + return state == SignProtectionState.NOSIGN; } - + @Override public boolean onBlockBurn(final Block block, final IEssentials ess) { final SignProtectionState state = isBlockProtected(block, null, null, false); - + + return state == SignProtectionState.NOSIGN; + } + + @Override + public boolean onBlockPush(final Block block, final IEssentials ess) + { + final SignProtectionState state = isBlockProtected(block, null, null, false); + return state == SignProtectionState.NOSIGN; } } From 6733d177df8e332cb806129db6c1f59adfbcd810 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 01:05:42 +0200 Subject: [PATCH 6/8] Piston push blacklist --- Essentials/src/config.yml | 6 ++-- .../essentials/protect/EssentialsProtect.java | 2 ++ .../EssentialsProtectBlockListener.java | 33 +++++++++++++++++++ .../essentials/protect/ProtectConfig.java | 3 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 90f8372cb..1d6e7ef81 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -305,7 +305,7 @@ protect: on-placement: 10,11,46 on-use: # 46: TNT - on-break: 46 + on-break: # Users cannot PLACE these types of blocks/items. # < 255 designates a BLOCK @@ -317,7 +317,9 @@ protect: #prevent people from breaking blocks #break: 20,50 break: - + + # Which blocks should not be pushed by pistons + piston: # General physics/behavior modifications prevent: diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 18acd9be3..53843843f 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -45,6 +45,8 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this); + pm.registerEvent(Type.BLOCK_PISTON_EXTEND, blockListener, Priority.Highest, this); + pm.registerEvent(Type.BLOCK_PISTON_RETRACT, blockListener, Priority.Highest, this); final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this); pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this); diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index 1b9736a5a..5d0a62d72 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -14,6 +14,8 @@ import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; @@ -319,4 +321,35 @@ public class EssentialsProtectBlockListener extends BlockListener } } } + + @Override + public void onBlockPistonExtend(BlockPistonExtendEvent event) + { + if (event.isCancelled()) + { + return; + } + for (Block block : event.getBlocks()) + { + if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId())) + { + event.setCancelled(true); + return; + } + } + } + + @Override + public void onBlockPistonRetract(BlockPistonRetractEvent event) + { + if (event.isCancelled() || !event.isSticky()) + { + return; + } + if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, event.getRetractLocation().getBlock().getTypeId())) + { + event.setCancelled(true); + return; + } + } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 75824c368..950da0ebf 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -45,7 +45,8 @@ public enum ProtectConfig alert_on_break("protect.alert.on-break"), blacklist_placement("protect.blacklist.placement"), blacklist_usage("protect.blacklist.usage"), - blacklist_break("protect.blacklist.break"); + blacklist_break("protect.blacklist.break"), + blacklist_piston("protect.blacklist.piston"); private final String configName; private final String defValueString; private final boolean defValueBoolean; From d2e1b2435f39a62efec58aa4f4a829d042c1bc4f Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 01:17:24 +0200 Subject: [PATCH 7/8] Cleaned deprecated functions --- .../com/earth2me/essentials/FakeWorld.java | 20 ------------------- .../src/com/earth2me/essentials/Util.java | 1 - .../essentials/signs/EssentialsSign.java | 4 ++-- .../essentials/signs/SignProtection.java | 12 +++++------ .../EssentialsProtectBlockListener.java | 18 ++++++++--------- .../EssentialsProtectEntityListener.java | 12 +++++------ 6 files changed, 23 insertions(+), 44 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/FakeWorld.java b/Essentials/src/com/earth2me/essentials/FakeWorld.java index 7f5acae03..d39df60e4 100644 --- a/Essentials/src/com/earth2me/essentials/FakeWorld.java +++ b/Essentials/src/com/earth2me/essentials/FakeWorld.java @@ -174,26 +174,6 @@ public class FakeWorld implements World throw new UnsupportedOperationException("Not supported yet."); } - public Minecart spawnMinecart(Location lctn) - { - throw new UnsupportedOperationException("Not supported yet."); - } - - public StorageMinecart spawnStorageMinecart(Location lctn) - { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PoweredMinecart spawnPoweredMinecart(Location lctn) - { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Boat spawnBoat(Location lctn) - { - throw new UnsupportedOperationException("Not supported yet."); - } - public LivingEntity spawnCreature(Location lctn, CreatureType ct) { throw new UnsupportedOperationException("Not supported yet."); diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 515ef83a5..2ba7f0eb7 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -375,7 +375,6 @@ public class Util } catch (IOException ex) { - return cl.getResourceAsStream(string); } } } diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 4884ce6f0..52b16404e 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -196,7 +196,7 @@ public class EssentialsSign public static boolean checkIfBlockBreaksSigns(final Block block) { - if (block.getFace(BlockFace.UP).getType() == Material.SIGN_POST) + if (block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST) { return true; } @@ -209,7 +209,7 @@ public class EssentialsSign }; for (BlockFace blockFace : directions) { - final Block signblock = block.getFace(blockFace); + final Block signblock = block.getRelative(blockFace); if (signblock.getType() == Material.WALL_SIGN) { final org.bukkit.material.Sign sign = (org.bukkit.material.Sign)signblock.getState().getData(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index 1e2813b5b..4922b3dbb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -168,12 +168,12 @@ public class SignProtection extends EssentialsSign { return new Block[] { - block.getFace(BlockFace.NORTH), - block.getFace(BlockFace.SOUTH), - block.getFace(BlockFace.EAST), - block.getFace(BlockFace.WEST), - block.getFace(BlockFace.DOWN), - block.getFace(BlockFace.UP) + block.getRelative(BlockFace.NORTH), + block.getRelative(BlockFace.SOUTH), + block.getRelative(BlockFace.EAST), + block.getRelative(BlockFace.WEST), + block.getRelative(BlockFace.DOWN), + block.getRelative(BlockFace.UP) }; } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index 5d0a62d72..de6791305 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -60,7 +60,7 @@ public class EssentialsProtectBlockListener extends BlockListener prot.alert(user, blockPlaced.getType().toString(), Util.i18n("alertPlaced")); } - final Block below = blockPlaced.getFace(BlockFace.DOWN); + final Block below = blockPlaced.getRelative(BlockFace.DOWN); if (below.getType() == Material.RAILS && prot.getSettingBool(ProtectConfig.prevent_block_on_rail) && prot.getStorage().isProtected(below, user.getName())) @@ -77,7 +77,7 @@ public class EssentialsProtectBlockListener extends BlockListener protect.add(blockPlaced); if (prot.getSettingBool(ProtectConfig.protect_below_rails)) { - protect.add(blockPlaced.getFace(BlockFace.DOWN)); + protect.add(blockPlaced.getRelative(BlockFace.DOWN)); } } if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) @@ -117,7 +117,7 @@ public class EssentialsProtectBlockListener extends BlockListener return; } if (event.getBlock().getType() == Material.OBSIDIAN - || event.getBlock().getFace(BlockFace.DOWN).getType() == Material.OBSIDIAN) + || event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN) { event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_portal_creation)); return; @@ -262,14 +262,14 @@ public class EssentialsProtectBlockListener extends BlockListener storage.unprotectBlock(block); if (type == Material.RAILS || type == Material.SIGN_POST) { - final Block below = block.getFace(BlockFace.DOWN); + final Block below = block.getRelative(BlockFace.DOWN); storage.unprotectBlock(below); } else { for (BlockFace blockFace : faces) { - final Block against = block.getFace(blockFace); + final Block against = block.getRelative(blockFace); storage.unprotectBlock(against); } } @@ -278,7 +278,7 @@ public class EssentialsProtectBlockListener extends BlockListener { for (BlockFace blockFace : faces) { - final Block against = block.getFace(blockFace); + final Block against = block.getRelative(blockFace); storage.unprotectBlock(against); } } @@ -298,14 +298,14 @@ public class EssentialsProtectBlockListener extends BlockListener storage.unprotectBlock(block); if (type == Material.RAILS || type == Material.SIGN_POST) { - final Block below = block.getFace(BlockFace.DOWN); + final Block below = block.getRelative(BlockFace.DOWN); storage.unprotectBlock(below); } else { for (BlockFace blockFace : faces) { - final Block against = block.getFace(blockFace); + final Block against = block.getRelative(blockFace); storage.unprotectBlock(against); } } @@ -314,7 +314,7 @@ public class EssentialsProtectBlockListener extends BlockListener { for (BlockFace blockFace : faces) { - final Block against = block.getFace(blockFace); + final Block against = block.getRelative(blockFace); storage.unprotectBlock(against); } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index defbde243..ceb72bd8d 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -240,19 +240,19 @@ public class EssentialsProtectEntityListener extends EntityListener for (Block block : event.blockList()) { - if ((block.getType() == Material.RAILS || block.getFace(BlockFace.UP).getType() == Material.RAILS) + if ((block.getType() == Material.RAILS || block.getRelative(BlockFace.UP).getType() == Material.RAILS) && prot.getSettingBool(ProtectConfig.protect_rails)) { event.setCancelled(true); return; } if ((block.getType() == Material.WALL_SIGN - || block.getFace(BlockFace.NORTH).getType() == Material.WALL_SIGN - || block.getFace(BlockFace.EAST).getType() == Material.WALL_SIGN - || block.getFace(BlockFace.SOUTH).getType() == Material.WALL_SIGN - || block.getFace(BlockFace.WEST).getType() == Material.WALL_SIGN + || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN + || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN + || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN + || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST - || block.getFace(BlockFace.UP).getType() == Material.SIGN_POST) + || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST) && prot.getSettingBool(ProtectConfig.protect_signs)) { event.setCancelled(true); From f5f04b032a48e3bfc9e4d377443d7759367742f7 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 01:39:41 +0200 Subject: [PATCH 8/8] Protect Rails and other signs from pistons --- .../EssentialsProtectBlockListener.java | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index de6791305..7b5f93d0e 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -336,6 +336,38 @@ public class EssentialsProtectBlockListener extends BlockListener event.setCancelled(true); return; } + if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS + || block.getType() == Material.RAILS) + && prot.getSettingBool(ProtectConfig.protect_rails)) + { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.protect_signs)) + { + for (BlockFace blockFace : faces) + { + if (blockFace == BlockFace.DOWN) + { + continue; + } + final Block sign = block.getRelative(blockFace); + if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF) + && sign.getType() == Material.SIGN_POST) + { + event.setCancelled(true); + return; + } + if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST + || blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST + || blockFace == BlockFace.SELF) + && sign.getType() == Material.WALL_SIGN) + { + event.setCancelled(true); + return; + } + } + } } } @@ -346,10 +378,43 @@ public class EssentialsProtectBlockListener extends BlockListener { return; } - if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, event.getRetractLocation().getBlock().getTypeId())) + final Block block = event.getRetractLocation().getBlock(); + if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId())) { event.setCancelled(true); return; } + if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS + || block.getType() == Material.RAILS) + && prot.getSettingBool(ProtectConfig.protect_rails)) + { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.protect_signs)) + { + for (BlockFace blockFace : faces) + { + if (blockFace == BlockFace.DOWN) + { + continue; + } + final Block sign = block.getRelative(blockFace); + if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF) + && sign.getType() == Material.SIGN_POST) + { + event.setCancelled(true); + return; + } + if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST + || blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST + || blockFace == BlockFace.SELF) + && sign.getType() == Material.WALL_SIGN) + { + event.setCancelled(true); + return; + } + } + } } }