From 16b2c3dee38c1b82c9a781677e16932c177a19bb Mon Sep 17 00:00:00 2001 From: md678685 Date: Fri, 15 Jun 2018 19:09:27 +0100 Subject: [PATCH 1/4] Reset pending confirmations on login (#2033) On login, resets any pending confirmations for the user. Fixes #2021, closes #2023. --- .../src/com/earth2me/essentials/EssentialsPlayerListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index d67e8d9c6..b4f080e05 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -308,6 +308,9 @@ public class EssentialsPlayerListener implements Listener { user.setGodModeEnabled(false); ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName()); } + + user.setConfirmingClearCommand(null); + user.getConfirmingPayments().clear(); user.stopTransaction(); } From 27d9f3725af2a314614d27ea2174b96a16125f17 Mon Sep 17 00:00:00 2001 From: md678685 Date: Fri, 15 Jun 2018 19:18:55 +0100 Subject: [PATCH 2/4] Wrap constructScalar for SnakeYAML 1.21 (#2040) In theory, fixes #1974, fixes #1975 and fixes #1976, and also means that Spigot are free to upgrade SnakeYAML to 1.21 again when ready. --- .../essentials/storage/BukkitConstructor.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java index 54f780e52..2d82f134e 100644 --- a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java +++ b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java @@ -13,6 +13,8 @@ import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; import org.yaml.snakeyaml.introspector.PropertyUtils; import org.yaml.snakeyaml.nodes.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Locale; @@ -32,10 +34,30 @@ public class BukkitConstructor extends CustomClassLoaderConstructor { private class ConstructBukkitScalar extends ConstructScalar { + + private Method constructScalarMethod = null; + + protected String constructScalarRefl(ScalarNode scalarNode) { + try { + if (constructScalarMethod == null) { + constructScalarMethod = ConstructScalar.class.getMethod("constructScalar", ScalarNode.class); + } + return (String) constructScalarMethod.invoke(this, scalarNode); + } catch (NoSuchMethodException + | SecurityException + | IllegalAccessException + | IllegalArgumentException + | InvocationTargetException e) { + e.printStackTrace(); + } + + return null; + } + @Override public Object construct(final Node node) { if (node.getType().equals(Material.class)) { - final String val = (String) constructScalar((ScalarNode) node); + final String val = constructScalarRefl((ScalarNode) node); Material mat; if (NumberUtil.isInt(val)) { final int typeId = Integer.parseInt(val); @@ -46,7 +68,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor { return mat; } if (node.getType().equals(MaterialData.class)) { - final String val = (String) constructScalar((ScalarNode) node); + final String val = constructScalarRefl((ScalarNode) node); if (val.isEmpty()) { return null; } @@ -71,7 +93,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor { return new MaterialData(mat, data); } if (node.getType().equals(ItemStack.class)) { - final String val = (String) constructScalar((ScalarNode) node); + final String val = constructScalarRefl((ScalarNode) node); if (val.isEmpty()) { return null; } @@ -134,7 +156,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor { return stack; } if (node.getType().equals(EnchantmentLevel.class)) { - final String val = (String) constructScalar((ScalarNode) node); + final String val = constructScalarRefl((ScalarNode) node); if (val.isEmpty()) { return null; } From 4873beb100f999e6a839a36d8ccce4e65ecc4931 Mon Sep 17 00:00:00 2001 From: md678685 Date: Fri, 15 Jun 2018 19:20:06 +0100 Subject: [PATCH 3/4] Allow updating the compass target to be optional (#1937) If `compass-towards-home-perm` is enabled in the EssentialsX config, then the permission `essentials.home.compass` is checked before changing the player's compass target. Closes #1918. --- .../essentials/EssentialsPlayerListener.java | 3 +++ .../com/earth2me/essentials/ISettings.java | 2 ++ .../src/com/earth2me/essentials/Settings.java | 12 ++++++++++++ Essentials/src/config.yml | 19 +++++++++++++------ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index b4f080e05..57a5b620e 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -353,7 +353,10 @@ public class EssentialsPlayerListener implements Listener { } // Makes the compass item ingame always point to the first essentials home. #EasterEgg + // EssentialsX: This can now optionally require a permission to enable, if set in the config. private void updateCompass(final User user) { + if (ess.getSettings().isCompassTowardsHomePerm() && !user.isAuthorized("essentials.home.compass")) return; + Location loc = user.getHome(user.getLocation()); if (loc == null) { loc = user.getBase().getBedSpawnLocation(); diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 367b4dbae..77b800836 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -306,4 +306,6 @@ public interface ISettings extends IConf { List getDefaultEnabledConfirmCommands(); boolean isConfirmCommandEnabledByDefault(String commandName); + + boolean isCompassTowardsHomePerm(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 56b4e50d5..cb1dbe2f4 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -533,6 +533,7 @@ public class Settings implements net.ess3.api.ISettings { currencyFormat = _getCurrencyFormat(); unprotectedSigns = _getUnprotectedSign(); defaultEnabledConfirmCommands = _getDefaultEnabledConfirmCommands(); + isCompassTowardsHomePerm = _isCompassTowardsHomePerm(); } private List itemSpawnBl = new ArrayList(); @@ -1439,4 +1440,15 @@ public class Settings implements net.ess3.api.ISettings { public boolean isConfirmCommandEnabledByDefault(String commandName) { return getDefaultEnabledConfirmCommands().contains(commandName.toLowerCase()); } + + private boolean isCompassTowardsHomePerm; + + private boolean _isCompassTowardsHomePerm() { + return config.getBoolean("compass-towards-home-perm", false); + } + + @Override + public boolean isCompassTowardsHomePerm() { + return isCompassTowardsHomePerm; + } } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 28fcf6ca1..24b8af5e7 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -522,6 +522,13 @@ default-enabled-confirm-commands: #- pay #- clearinventory +# Set the timeout, in seconds for players to accept a tpa before the request is cancelled. +# Set to 0 for no timeout. +tpa-accept-cancellation: 120 + +# Allow players to set hats by clicking on their helmet slot. +allow-direct-hat: true + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | # @@ -551,12 +558,12 @@ sethome-multiple: # In this example someone with 'essentials.sethome.multiple' and 'essentials.sethome.multiple.vip' will have 5 homes. # Remember, they MUST have both permission nodes in order to be able to set multiple homes. -# Set the timeout, in seconds for players to accept a tpa before the request is cancelled. -# Set to 0 for no timeout. -tpa-accept-cancellation: 120 - -# Allow players to set hats by clicking on their helmet slot. -allow-direct-hat: true +# Controls whether players need the permission "essentials.home.compass" in order to point +# the player's compass at their first home. +# +# Leaving this as false will retain Essentials' original behaviour, which is to always +# change the compass' direction to point towards their first home. +compass-towards-home-perm: false ############################################################ # +------------------------------------------------------+ # From de57a8c6025c8581b8eec9342e5812d871589914 Mon Sep 17 00:00:00 2001 From: md678685 Date: Fri, 15 Jun 2018 19:21:18 +0100 Subject: [PATCH 4/4] Disable EssProtect emergency mode when Ess loads late (#1954) Related: EssentialsX/Essentials#1951. --- .../essentials/protect/EmergencyListener.java | 14 +++++++++ .../essentials/protect/EssentialsProtect.java | 30 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyListener.java index c48295aa1..7a9f2bba8 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyListener.java @@ -10,9 +10,16 @@ import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.server.PluginEnableEvent; public class EmergencyListener implements Listener { + EssentialsProtect plugin; + + EmergencyListener(final EssentialsProtect essProtPlugin) { + plugin = essProtPlugin; + } + @EventHandler(priority = EventPriority.LOW) public void onBlockBurn(final BlockBurnEvent event) { event.setCancelled(true); @@ -47,4 +54,11 @@ public class EmergencyListener implements Listener { public void onEntityDamage(final EntityDamageEvent event) { event.setCancelled(true); } + + @EventHandler + public void onPluginEnabled(final PluginEnableEvent event) { + if (event.getPlugin().getName().equals("Essentials")) { + plugin.disableEmergencyMode(); + } + } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index be3679365..49d12e521 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.protect; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -19,6 +20,8 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { private final Map> settingsList = new EnumMap>(ProtectConfig.class); private EssentialsConnect ess = null; + private final EmergencyListener emListener = new EmergencyListener(this); + @Override public void onEnable() { final PluginManager pm = this.getServer().getPluginManager(); @@ -27,6 +30,12 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { enableEmergencyMode(pm); return; } + + initialize(pm, essPlugin); + } + + private void initialize(final PluginManager pm, final Plugin essPlugin) { + LOGGER.log(Level.INFO, "Continuing to enable Protect."); ess = new EssentialsConnect(essPlugin, this); final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this); @@ -40,13 +49,30 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { } private void enableEmergencyMode(final PluginManager pm) { - final EmergencyListener emListener = new EmergencyListener(); pm.registerEvents(emListener, this); for (Player player : getServer().getOnlinePlayers()) { player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); } - LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now."); + LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now."); + } + + void disableEmergencyMode() { + final PluginManager pm = this.getServer().getPluginManager(); + final Plugin essPlugin = pm.getPlugin("Essentials"); + if (essPlugin == null || !essPlugin.isEnabled()) { + LOGGER.log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!"); + return; + } + + HandlerList.unregisterAll(emListener); + + for (Player player : getServer().getOnlinePlayers()) { + player.sendMessage("Essentials Protect is no longer in emergency mode."); + } + LOGGER.log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode."); + + initialize(pm, essPlugin); } @Override