diff --git a/bin/cz/boosik/boosCooldown/BoosConfigManager.class b/bin/cz/boosik/boosCooldown/BoosConfigManager.class index eb9403f..4082b96 100644 Binary files a/bin/cz/boosik/boosCooldown/BoosConfigManager.class and b/bin/cz/boosik/boosCooldown/BoosConfigManager.class differ diff --git a/bin/cz/boosik/boosCooldown/BoosCoolDown.class b/bin/cz/boosik/boosCooldown/BoosCoolDown.class index c6271ea..1e9f3aa 100644 Binary files a/bin/cz/boosik/boosCooldown/BoosCoolDown.class and b/bin/cz/boosik/boosCooldown/BoosCoolDown.class differ diff --git a/bin/cz/boosik/boosCooldown/BoosCoolDownListener.class b/bin/cz/boosik/boosCooldown/BoosCoolDownListener.class index 25b97ab..730fd07 100644 Binary files a/bin/cz/boosik/boosCooldown/BoosCoolDownListener.class and b/bin/cz/boosik/boosCooldown/BoosCoolDownListener.class differ diff --git a/bin/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.class b/bin/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.class new file mode 100644 index 0000000..bda9d16 Binary files /dev/null and b/bin/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.class differ diff --git a/bin/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.class b/bin/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.class new file mode 100644 index 0000000..0481e3c Binary files /dev/null and b/bin/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.class differ diff --git a/bin/plugin.yml b/bin/plugin.yml index 51ffa77..b9a1dc9 100644 --- a/bin/plugin.yml +++ b/bin/plugin.yml @@ -1,6 +1,6 @@ name: boosCooldowns main: cz.boosik.boosCooldown.BoosCoolDown -version: 3.6.4 +version: 3.6.5 authors: [LordBoos (ingame name boosik)] softdepend: [Vault] description: > diff --git a/src/cz/boosik/boosCooldown/BoosConfigManager.java b/src/cz/boosik/boosCooldown/BoosConfigManager.java index 0867345..41d01dc 100644 --- a/src/cz/boosik/boosCooldown/BoosConfigManager.java +++ b/src/cz/boosik/boosCooldown/BoosConfigManager.java @@ -581,10 +581,13 @@ public class BoosConfigManager { conf.load(confFile); } catch (FileNotFoundException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file not found!"); } catch (IOException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Could not read configuration file!"); } catch (InvalidConfigurationException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file is invalid!"); } } @@ -596,10 +599,13 @@ public class BoosConfigManager { confusers.load(confusersFile); } catch (FileNotFoundException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Storage file not found!"); } catch (IOException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Could not read storage file!"); } catch (InvalidConfigurationException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Storage file is invalid!"); } } @@ -620,6 +626,7 @@ public class BoosConfigManager { confusers.save(confusersFile); } catch (IOException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!"); } } @@ -645,6 +652,8 @@ public class BoosConfigManager { conf.save(confFile); } catch (IOException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Could not save configuration file!"); + } reload(); } @@ -670,6 +679,7 @@ public class BoosConfigManager { conf.addDefault("options.options.cooldowns_enabled", true); conf.addDefault("options.options.prices_enabled", true); conf.addDefault("options.options.limits_enabled", true); + conf.addDefault("options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS", false); conf.addDefault("options.options.save_interval_in_minutes", 15); conf.addDefault("options.options.cancel_warmup_on_damage", false); conf.addDefault("options.options.cancel_warmup_on_move", false); @@ -725,15 +735,7 @@ public class BoosConfigManager { "&6You are not allowed to use this sign!&f"); } if (confFile.exists()) { - try { - conf.load(confFile); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } + load(); } try { conf.addDefault("commands.groups.default.*", "1,1,0.0,-1"); @@ -772,7 +774,12 @@ public class BoosConfigManager { confusersFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); + BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!"); } } } + + static boolean getAutoSave() { + return conf.getBoolean("options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS", false); + } } diff --git a/src/cz/boosik/boosCooldown/BoosCoolDown.java b/src/cz/boosik/boosCooldown/BoosCoolDown.java index 832e5b7..00f620b 100644 --- a/src/cz/boosik/boosCooldown/BoosCoolDown.java +++ b/src/cz/boosik/boosCooldown/BoosCoolDown.java @@ -27,6 +27,8 @@ import cz.boosik.boosCooldown.Listeners.BoosPlayerInteractListener; import cz.boosik.boosCooldown.Listeners.BoosPlayerMoveListener; import cz.boosik.boosCooldown.Listeners.BoosPlayerToggleSneakListener; import cz.boosik.boosCooldown.Listeners.BoosPlayerToggleSprintListener; +import cz.boosik.boosCooldown.Listeners.BoosSignChangeListener; +import cz.boosik.boosCooldown.Listeners.BoosSignInteractListener; /** * Hlavní třída pluginu. Třída je potomkem JavaPlugin a implementuje Runnable. @@ -306,9 +308,11 @@ public class BoosCoolDown extends JavaPlugin implements Runnable { registerListeners(); initializeVault(); BukkitScheduler scheduler = this.getServer().getScheduler(); + if (BoosConfigManager.getAutoSave()){ scheduler.scheduleSyncRepeatingTask(this, this, BoosConfigManager.getSaveInterval() * 1200, BoosConfigManager.getSaveInterval() * 1200); + } if (BoosConfigManager.getClearOnRestart()) { BoosConfigManager.clear(); } @@ -352,6 +356,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable { if (BoosConfigManager.getCancelWarmupOnSprint()) { pm.registerEvents(new BoosPlayerToggleSprintListener(), this); } + if (BoosConfigManager.getSignCommands()) { + pm.registerEvents(new BoosSignChangeListener(), this); + pm.registerEvents(new BoosSignInteractListener(this), this); + } } /** diff --git a/src/cz/boosik/boosCooldown/BoosCoolDownListener.java b/src/cz/boosik/boosCooldown/BoosCoolDownListener.java index 61b72e1..40eba60 100644 --- a/src/cz/boosik/boosCooldown/BoosCoolDownListener.java +++ b/src/cz/boosik/boosCooldown/BoosCoolDownListener.java @@ -105,8 +105,8 @@ public class BoosCoolDownListener implements Listener { return; } Player player = event.getPlayer(); - String originalCommand = event.getMessage().trim() - .replaceAll(" +", " ").toLowerCase(); + String originalCommand = event.getMessage().replace("\\", "\\\\"); + originalCommand.trim().replaceAll(" +", " ").toLowerCase(); String regexCommad = ""; Set aliases = BoosConfigManager.getAliases(); Set commands = BoosConfigManager.getCommands(player); diff --git a/src/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.java b/src/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.java new file mode 100644 index 0000000..a1fc750 --- /dev/null +++ b/src/cz/boosik/boosCooldown/Listeners/BoosSignChangeListener.java @@ -0,0 +1,49 @@ +package cz.boosik.boosCooldown.Listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.SignChangeEvent; + +import util.boosChat; +import cz.boosik.boosCooldown.BoosConfigManager; + +/** + * @author Jakub Kolář + * + */ +public class BoosSignChangeListener implements Listener { + /** + * @param event + */ + @EventHandler(priority = EventPriority.NORMAL) + private void onSignChange(SignChangeEvent event) { + if (event.isCancelled()) + return; + + Player player = event.getPlayer(); + String line1 = event.getLine(0); + String line2 = event.getLine(1); + if (line1.equals("[boosCooldowns]")) { + if (line2.equals("player") + && !player + .hasPermission("booscooldowns.signs.player.place")) { + boosChat.sendMessageToPlayer(player, + BoosConfigManager.getCannotCreateSignMessage()); + event.getBlock().breakNaturally(); + event.setCancelled(true); + return; + } + if (line2.equals("server") + && !player + .hasPermission("booscooldowns.signs.server.place")) { + boosChat.sendMessageToPlayer(player, + BoosConfigManager.getCannotCreateSignMessage()); + event.getBlock().breakNaturally(); + event.setCancelled(true); + return; + } + } + } +} diff --git a/src/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.java b/src/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.java new file mode 100644 index 0000000..4a34f1d --- /dev/null +++ b/src/cz/boosik/boosCooldown/Listeners/BoosSignInteractListener.java @@ -0,0 +1,76 @@ +package cz.boosik.boosCooldown.Listeners; + +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import util.boosChat; +import cz.boosik.boosCooldown.BoosConfigManager; +import cz.boosik.boosCooldown.BoosCoolDown; + +/** + * @author Jakub + * + */ +public class BoosSignInteractListener implements Listener { + private final BoosCoolDown plugin; + + /** + * @param instance + */ + public BoosSignInteractListener(BoosCoolDown instance) { + plugin = instance; + } + + /** + * @param event + */ + @EventHandler(priority = EventPriority.NORMAL) + private void onSignInteract(PlayerInteractEvent event) { + String msg; + if (event.isCancelled()) + return; + + if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.SIGN_POST + || event.getClickedBlock().getType() == Material.WALL_SIGN) { + Sign s = (Sign) event.getClickedBlock().getState(); + String line1 = s.getLine(0); + String line2 = s.getLine(1); + String line3 = s.getLine(2); + String line4 = s.getLine(3); + Player player = event.getPlayer(); + if (line1.equals("[boosCooldowns]")) { + if (line2.equals("player") + && player + .hasPermission("booscooldowns.signs.player.use")) { + msg = line3; + if (line3.endsWith("+") || !line4.isEmpty()) { + msg = line3.substring(0, line3.length() - 1) + " " + + line4; + } + event.getPlayer().chat(msg); + } else if (line2.equals("server") + && player + .hasPermission("booscooldowns.signs.server.use")) { + msg = line3; + if (line3.endsWith("+") || !line4.isEmpty()) { + msg = line3.substring(0, line3.length() - 1) + " " + + line4; + } + plugin.getServer().dispatchCommand( + plugin.getServer().getConsoleSender(), msg); + } else { + boosChat.sendMessageToPlayer(player, + BoosConfigManager.getCannotUseSignMessage()); + } + } + } + } + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 51ffa77..b9a1dc9 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: boosCooldowns main: cz.boosik.boosCooldown.BoosCoolDown -version: 3.6.4 +version: 3.6.5 authors: [LordBoos (ingame name boosik)] softdepend: [Vault] description: >