diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/AntiCooldownApi.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/AntiCooldownApi.java index 27f743c..503da01 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/AntiCooldownApi.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/AntiCooldownApi.java @@ -1,6 +1,6 @@ package com.yourgamespace.anticooldown.api; -import com.yourgamespace.anticooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; import org.bukkit.entity.Player; public class AntiCooldownApi { diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/events/PlayerCooldownChangeEvent.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/events/PlayerCooldownChangeEvent.java index 838080c..d1ce586 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/events/PlayerCooldownChangeEvent.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/api/events/PlayerCooldownChangeEvent.java @@ -1,6 +1,6 @@ package com.yourgamespace.anticooldown.api.events; -import com.yourgamespace.anticooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/files/PluginConfig.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/files/PluginConfig.java index 835f265..7070474 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/files/PluginConfig.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/files/PluginConfig.java @@ -2,7 +2,6 @@ import com.yourgamespace.anticooldown.data.Data; import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.ItemDamageManager; import com.yourgamespace.anticooldown.utils.ItemRestrictionManager; import com.yourgamespace.anticooldown.utils.basics.AntiCooldownLogger; import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; @@ -29,6 +28,7 @@ public class PluginConfig { public PluginConfig() {} public void initConfigFile() { + if (!configFile.exists()) AntiCooldown.getInstance().saveResource(configFile.getName(), false); config = YamlConfiguration.loadConfiguration(configFile); // Pre-load config version for upgrade check @@ -36,7 +36,97 @@ public void initConfigFile() { } public void setupConfig() { - if (!configFile.exists()) AntiCooldown.getInstance().saveResource(configFile.getName(), false); + // START Messages + config.addDefault("Messages.Prefix", "§7[§3AntiCooldown§7] "); + config.addDefault("Messages.ActionBarPrefix", "§3AntiCooldown§7 »"); + config.addDefault("Messages.SwitchWorld.Bypassed", "§ePvP Cooldown is §c§lnot disabled §ein this world, but you have §2Bypass-Permissions§a! §aCooldown is disable for you."); + config.addDefault("Messages.SwitchWorld.Enabled", "§ePvP Cooldown is §a§ldisabled §ein this world!"); + config.addDefault("Messages.SwitchWorld.Disabled", "§ePvP Cooldown is §c§lnot disabled §ein this world!"); + config.addDefault("Messages.Login.Bypassed", "§aHey, welcome to the server! §ePvP Cooldown is §c§lnot disabled §ein this world, but you have §2Bypass-Permissions§a! §aCooldown is disable for you."); + config.addDefault("Messages.Login.Enabled", "§aHey, welcome to the server! §ePvP Cooldown is §a§ldisabled §ein this world!"); + config.addDefault("Messages.Login.Disabled", "§aHey, welcome to the server! §ePvP Cooldown is §c§lnot disabled §ein this world!"); + config.addDefault("Messages.CustomItemDamage.ActionBarMessage", "%actionbar_prefix% §aCustom-Damage applied: §7%finaldamage%§c❤ §7Damage"); + config.addDefault("Messages.ItemRestriction.ActionBarMessage.Enabled", "%actionbar_prefix% §aItem is no longer restricted! PvP Cooldown is §a§ldisabled §aagain"); + config.addDefault("Messages.ItemRestriction.ActionBarMessage.Disabled", "%actionbar_prefix% §cItem is restricted! PvP Cooldown is temporarily §c§lactivated"); + config.addDefault("Messages.Setting.AddDisabledWorld", "§aOK! In the world §e%world% §athe cooldown is now activated."); + config.addDefault("Messages.Setting.RemoveDisabledWorld", "§aOK! In the world §e%world% §athe cooldown is now deactivated."); + config.addDefault("Messages.Error.WorldAlreadyDisabled", "§cThis world is already §c§ldeactivated§c!"); + config.addDefault("Messages.Error.WorldAlreadyEnabled", "§cThis world is already §a§lactivated§c!"); + config.addDefault("Messages.Error.PlayerNotOnline", "§cThe player is not online!"); + config.addDefault("Messages.Error.NoPerms", "§cNo permissions!"); + // END Messages + + //Placeholder + config.addDefault("Placeholder.World.CooldownEnabled", "Enabled"); + config.addDefault("Placeholder.World.CooldownDisabled", "Disabled"); + config.addDefault("Placeholder.Player.CooldownEnabled", "Enabled"); + config.addDefault("Placeholder.Player.CooldownDisabled", "Disabled"); + + // Config List Options + //List: Restricted Items + List restrictedItems = config.getStringList("Settings.Values.RestrictedItems"); + restrictedItems.add("DIAMOND_AXE"); + restrictedItems.add("GOLDEN_AXE"); + restrictedItems.add("IRON_AXE"); + restrictedItems.add("STONE_AXE"); + restrictedItems.add("NETHERITE_AXE"); + restrictedItems.add("WOODEN_AXE"); + + //List: Disabled Worlds + List disabledWorlds = config.getStringList("Settings.Values.DisabledWorlds"); + disabledWorlds.add("YourWorldName"); + + //List: Item Damage Values + List customItemDamage = config.getStringList("Settings.Values.CustomItemDamage"); + customItemDamage.add("WOOD_AXE:3.0D"); + customItemDamage.add("WOODEN_AXE:3.0D"); + customItemDamage.add("GOLD_AXE:3.0D"); + customItemDamage.add("GOLDEN_AXE:3.0D"); + customItemDamage.add("STONE_AXE:4.0D"); + customItemDamage.add("IRON_AXE:5.0D"); + customItemDamage.add("DIAMOND_AXE:6.0D"); + customItemDamage.add("WOOD_PICKAXE:2.0D"); + customItemDamage.add("WOODEN_PICKAXE:2.0D"); + customItemDamage.add("GOLD_PICKAXE:2.0D"); + customItemDamage.add("GOLDEN_PICKAXE:2.0D"); + customItemDamage.add("STONE_PICKAXE:3.0D"); + customItemDamage.add("IRON_PICKAXE:4.0D"); + customItemDamage.add("DIAMOND_PICKAXE:5.0D"); + customItemDamage.add("WOODEN_SHOVEL:1.0D"); + customItemDamage.add("GOLDEN_SHOVEL:1.0D"); + customItemDamage.add("STONE_SHOVEL:2.0D"); + customItemDamage.add("IRON_SHOVEL:3.0D"); + customItemDamage.add("DIAMOND_SHOVEL:4.0D"); + + // START Settings + //Settings: Permissions + config.addDefault("Settings.Permissions.UsePermissions", false); + config.addDefault("Settings.Permissions.UseBypassPermission", false); + //Settings: Messages + config.addDefault("Settings.Messages.UseLoginMessage", true); + config.addDefault("Settings.Messages.UseSwitchWorldMessage", true); + //Settings: Values + config.addDefault("Settings.Values.AttackSpeed", 100); + config.addDefault("Settings.Values.DisabledWorlds", disabledWorlds); + config.addDefault("Settings.Values.RestrictedItems", restrictedItems); + config.addDefault("Settings.Values.CustomItemDamage", customItemDamage); + //Settings: Features + config.addDefault("Settings.Features.DisableSweepAttacks", true); + config.addDefault("Settings.Features.DisableNewCombatSounds", true); + config.addDefault("Settings.Features.DisablePlayerCollision", true); + config.addDefault("Settings.Features.DisableEnderpearlCooldown", true); + config.addDefault("Settings.Features.CustomItemDamage.EnableCustomItemDamage", true); + config.addDefault("Settings.Features.CustomItemDamage.SendActionBar", true); + config.addDefault("Settings.Features.ItemRestriction.EnableItemRestriction", false); + config.addDefault("Settings.Features.ItemRestriction.SendActionBar", true); + config.addDefault("Settings.Features.ItemRestriction.UseAsWhitelist", false); + //Settings: UpdateChecker + config.addDefault("Settings.Updates.UseUpdateChecker", true); + config.addDefault("Settings.Updates.ConsoleNotify", true); + config.addDefault("Settings.Updates.IngameNotify", true); + // END Settings + + config.addDefault("ConfigVersion", data.getCurrentConfigVersion()); } public void upgradeConfig() { @@ -68,6 +158,10 @@ private void saveConfig() { public void loadConfig() { antiCooldownLogger.info("§aLoad configurations from config file §e" + configFile.getName() + " §a..."); + config.set(AntiCooldown.getInstance().getDescription().getName() + "_COMMENT_" + 1, " " + "Test"); + config.set("Test", "Test123123"); + saveConfig(); + //Messages cacheContainer.add(String.class, "PREFIX", config.getString("Messages.Prefix")); cacheContainer.add(String.class, "ACTIONBAR_PREFIX", config.getString("Messages.ActionBarPrefix")); @@ -131,12 +225,12 @@ public void loadConfig() { antiCooldownLogger.info("§aWorld §e" + disabledWorld + " §adisabled!"); } - //Values: CustomItemDamage - for (String customItemDamage : config.getStringList("Settings.Values.CustomItemDamage")) { - String[] itemParams = customItemDamage.split(":"); - - ItemDamageManager.addCache(itemParams[0], itemParams[1]); - } + // //Values: CustomItemDamage + // for (String customItemDamage : config.getStringList("Settings.Values.CustomItemDamage")) { + // String[] itemParams = customItemDamage.split(":"); + // + // ItemDamageManager.addCache(itemParams[0], itemParams[1]); + // } antiCooldownLogger.info("§aConfigurations from config file §e" + configFile.getName() + " §asuccessfully loaded!"); } diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/main/AntiCooldown.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/main/AntiCooldown.java index b916179..c6b6465 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/main/AntiCooldown.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/main/AntiCooldown.java @@ -5,21 +5,19 @@ import com.yourgamespace.anticooldown.commands.CmdAntiCooldown; import com.yourgamespace.anticooldown.data.Data; import com.yourgamespace.anticooldown.files.PluginConfig; -import com.yourgamespace.anticooldown.modules.AttackCooldown; -import com.yourgamespace.anticooldown.modules.CombatSounds; -import com.yourgamespace.anticooldown.modules.CustomItemDamage; import com.yourgamespace.anticooldown.modules.EnderpearlCooldown; import com.yourgamespace.anticooldown.modules.ItemRestriction; import com.yourgamespace.anticooldown.modules.PlayerCollision; import com.yourgamespace.anticooldown.modules.SweepAttackDamage; import com.yourgamespace.anticooldown.modules.SweepAttackParticle; import com.yourgamespace.anticooldown.modules.UpdateNotifyOnJoin; -import com.yourgamespace.anticooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.modules.attackcooldown.main.AttackCooldown; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.utils.PlaceholderHandler; +import com.yourgamespace.anticooldown.utils.WorldManager; import com.yourgamespace.anticooldown.utils.basics.AntiCooldownLogger; import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; -import com.yourgamespace.anticooldown.utils.PlaceholderHandler; import com.yourgamespace.anticooldown.utils.basics.VersionHandler; -import com.yourgamespace.anticooldown.utils.WorldManager; import com.yourgamespace.anticooldown.utils.module.ModuleCommandHandler; import com.yourgamespace.anticooldown.utils.module.ModuleDescription; import com.yourgamespace.anticooldown.utils.module.ModuleHandler; @@ -136,9 +134,9 @@ private void initialisation() { private void manageConfigs() { antiCooldownLogger.info("§aLoading config files ..."); - pluginConfig.setupConfig(); pluginConfig.initConfigFile(); pluginConfig.upgradeConfig(); + pluginConfig.setupConfig(); pluginConfig.loadConfig(); antiCooldownLogger.info("§aConfig files was successfully loaded!"); @@ -151,10 +149,8 @@ private void registerModules() { moduleHandler.registerModule(new AttackCooldown(false, new ModuleDescription("AttackCooldown", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.registerModule(new SweepAttackDamage(false, new ModuleDescription("SweepAttackDamage", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.registerModule(new SweepAttackParticle(true, new ModuleDescription("SweepAttackParticle", "1.0", "Internal Module", "YourGameSpace"))); - moduleHandler.registerModule(new CombatSounds(true, new ModuleDescription("CombatSounds", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.registerModule(new EnderpearlCooldown(false, new ModuleDescription("EnderpearlCooldown", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.registerModule(new PlayerCollision(true, new ModuleDescription("PlayerCollision", "1.0", "Internal Module", "YourGameSpace"))); - moduleHandler.registerModule(new CustomItemDamage(false, new ModuleDescription("CustomItemDamage", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.registerModule(new ItemRestriction(false, new ModuleDescription("ItemRestriction", "1.0", "Internal Module", "YourGameSpace"))); moduleHandler.enableModules(); diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/AttackCooldown.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/AttackCooldown.java deleted file mode 100644 index 618639c..0000000 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/AttackCooldown.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.yourgamespace.anticooldown.modules; - -import com.yourgamespace.anticooldown.api.events.WorldDisableEvent; -import com.yourgamespace.anticooldown.api.events.WorldEnableEvent; -import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.CooldownHandler; -import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; -import com.yourgamespace.anticooldown.utils.WorldManager; -import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; -import com.yourgamespace.anticooldown.utils.module.ModuleDescription; -import de.tubeof.tubetils.api.cache.CacheContainer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent; - -@SuppressWarnings("ConstantConditions") -public class AttackCooldown extends AntiCooldownModule implements Listener { - - private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); - private final CooldownHandler cooldownHandler = new CooldownHandler(); - private final WorldManager worldManager = AntiCooldown.getWorldManager(); - - public AttackCooldown(boolean isProtocolLibRequired, ModuleDescription moduleDescription) { - super(isProtocolLibRequired, moduleDescription); - } - - //@Override - //public void onEnable() { - // registerListener(this); - // - // cooldownHandler.setOnlinePlayersCooldown(); - //} - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - String world = player.getLocation().getWorld().getName(); - - // Check Bypass and Permissions - boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - // If not permitted: Return; - if (!isPermitted) return; - - // Check if world is disabled - if (worldManager.isWorldDisabled(world)) { - // If disabled and is bypassed, disable cooldown; - // If disabled and is not bypassed, do nothing; - if (isBypassed) { - cooldownHandler.disableCooldown(player); - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_BYPASSED"))); - } - } else { - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_DISABLED"))); - } - } - } else { - cooldownHandler.disableCooldown(player); - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_ENABLED"))); - } - } - } - - @EventHandler - public void onWorldEnable(WorldEnableEvent event) { - World world = event.getWorld(); - - for (Player player : world.getPlayers()) { - // Check Permissions - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - // Check if player is permitted - if (!isPermitted) continue; - cooldownHandler.disableCooldown(player); - } - } - - @EventHandler - public void onWorldDisable(WorldDisableEvent event) { - World world = event.getWorld(); - - for (Player player : world.getPlayers()) { - // Check Bypass and Permissions - boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - if (!isPermitted) continue; - if (!isBypassed) cooldownHandler.enableCooldown(player); - } - } - - @EventHandler - public void onWorldTeleport(PlayerTeleportEvent event) { - // Check if world was changed; If not: Return - if (event.getFrom().getWorld() == event.getTo().getWorld()) return; - - Player player = event.getPlayer(); - String world = event.getTo().getWorld().getName(); - - // Check Bypass and Permissions - boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - // If not permitted: Return; - if (!isPermitted) return; - - // 2 Tick Delay to prevent bugs - Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCooldown.getInstance(), () -> { - // Check if world is disabled - if (worldManager.isWorldDisabled(world)) { - // If disabled and is bypassed, disable cooldown; - // If disabled and is not bypassed, do nothing; - if (isBypassed) { - cooldownHandler.disableCooldown(player); - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_BYPASSED"))); - } - } else { - cooldownHandler.enableCooldown(player); - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_DISABLED"))); - } - } - } else { - cooldownHandler.disableCooldown(player); - if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { - player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_ENABLED"))); - } - } - }, 2); - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - - if (cooldownHandler.isCooldownDisabled(player)) { - cooldownHandler.enableCooldown(player); - } - } -} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CombatSounds.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CombatSounds.java deleted file mode 100644 index 7d8713b..0000000 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CombatSounds.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.yourgamespace.anticooldown.modules; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketEvent; -import com.yourgamespace.anticooldown.api.events.WorldDisableEvent; -import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; -import com.yourgamespace.anticooldown.utils.WorldManager; -import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; -import com.yourgamespace.anticooldown.utils.module.ModuleDescription; -import de.tubeof.tubetils.api.cache.CacheContainer; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -public class CombatSounds extends AntiCooldownModule { - - private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); - private final WorldManager worldManager = AntiCooldown.getWorldManager(); - - public CombatSounds(boolean isProtocolLibRequired, ModuleDescription moduleDescription) { - super(isProtocolLibRequired, moduleDescription); - } - - //@Override - //public void registerPacketHandler() { - // new PacketHandler(); - //} - - public class PacketHandler { - - public PacketHandler() { - onNewAttackSounds(); - } - - private void onNewAttackSounds() { - if (!ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "DISABLE_NEW_COMBAT_SOUNDS"))) return; - - AntiCooldown.getProtocolManager().addPacketListener(new PacketAdapter(AntiCooldown.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_SOUND_EFFECT) { - @Override - public void onPacketSending(PacketEvent event) { - // Check if valid sound - boolean valid = false; - Sound sound = event.getPacket().getSoundEffects().read(0); - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_SWEEP)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_CRIT)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_KNOCKBACK)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_STRONG)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_NODAMAGE)) valid = true; - - // If not valid: Return; - if (!valid) return; - - // Check if player has permissions - Player player = event.getPlayer(); - String world = player.getWorld().getName(); - - // Check Bypass and Permissions - boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.combatsounds") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - // If not permitted: Return; - if (!isPermitted) return; - - // Check if world is disabled - if (worldManager.isWorldDisabled(world)) { - // If disabled and is bypassed: disable sounds; - if (isBypassed) event.setCancelled(true); - } else { - // If permitted and not bypassed: disable sounds; - event.setCancelled(true); - } - } - }); - } - } -} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/ItemRestriction.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/ItemRestriction.java index 9a3701e..892bf25 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/ItemRestriction.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/ItemRestriction.java @@ -1,7 +1,7 @@ package com.yourgamespace.anticooldown.modules; import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; import com.yourgamespace.anticooldown.utils.ItemRestrictionManager; import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; import com.yourgamespace.anticooldown.utils.WorldManager; diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/JoinQuit.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/JoinQuit.java new file mode 100644 index 0000000..46d3141 --- /dev/null +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/JoinQuit.java @@ -0,0 +1,64 @@ +package com.yourgamespace.anticooldown.modules.attackcooldown.listeners; + +import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.utils.WorldManager; +import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.utils.module.ModuleListener; +import de.tubeof.tubetils.api.cache.CacheContainer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.Objects; + +public class JoinQuit extends ModuleListener { + + private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); + private final CooldownHandler cooldownHandler = new CooldownHandler(); + private final WorldManager worldManager = AntiCooldown.getWorldManager(); + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + String world = Objects.requireNonNull(player.getLocation().getWorld()).getName(); + + // Check Bypass and Permissions + boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); + boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); + + // If not permitted: Return; + if (!isPermitted) return; + + // Check if world is disabled + if (worldManager.isWorldDisabled(world)) { + // If disabled and is bypassed, disable cooldown; + // If disabled and is not bypassed, do nothing; + if (isBypassed) { + cooldownHandler.disableCooldown(player); + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_BYPASSED"))); + } + } else { + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_DISABLED"))); + } + } + } else { + cooldownHandler.disableCooldown(player); + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_LOGIN_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "LOGIN_ENABLED"))); + } + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + + if (cooldownHandler.isCooldownDisabled(player)) { + cooldownHandler.enableCooldown(player); + } + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldChange.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldChange.java new file mode 100644 index 0000000..238c30f --- /dev/null +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldChange.java @@ -0,0 +1,62 @@ +package com.yourgamespace.anticooldown.modules.attackcooldown.listeners; + +import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.utils.WorldManager; +import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.utils.module.ModuleListener; +import de.tubeof.tubetils.api.cache.CacheContainer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerTeleportEvent; + +import java.util.Objects; + +public class WorldChange extends ModuleListener { + + private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); + private final CooldownHandler cooldownHandler = new CooldownHandler(); + private final WorldManager worldManager = AntiCooldown.getWorldManager(); + + @EventHandler + public void onWorldTeleport(PlayerTeleportEvent event) { + // Check if world was changed; If not: Return + if (event.getFrom().getWorld() == Objects.requireNonNull(event.getTo()).getWorld()) return; + + Player player = event.getPlayer(); + String world = Objects.requireNonNull(event.getTo().getWorld()).getName(); + + // Check Bypass and Permissions + boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); + boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); + + // If not permitted: Return; + if (!isPermitted) return; + + // 2 Tick Delay to prevent bugs + Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCooldown.getInstance(), () -> { + // Check if world is disabled + if (worldManager.isWorldDisabled(world)) { + // If disabled and is bypassed, disable cooldown; + // If disabled and is not bypassed, do nothing; + if (isBypassed) { + cooldownHandler.disableCooldown(player); + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_BYPASSED"))); + } + } else { + cooldownHandler.enableCooldown(player); + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_DISABLED"))); + } + } + } else { + cooldownHandler.disableCooldown(player); + if (ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_SWITCH_WORLD_MESSAGES"))) { + player.sendMessage(cacheContainer.get(String.class, "PREFIX") + ObjectTransformer.getString(cacheContainer.get(String.class, "SWITCH_WORLD_ENABLED"))); + } + } + }, 2); + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldStateChange.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldStateChange.java new file mode 100644 index 0000000..fc2c9e2 --- /dev/null +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/listeners/WorldStateChange.java @@ -0,0 +1,48 @@ +package com.yourgamespace.anticooldown.modules.attackcooldown.listeners; + +import com.yourgamespace.anticooldown.api.events.WorldDisableEvent; +import com.yourgamespace.anticooldown.api.events.WorldEnableEvent; +import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.utils.WorldManager; +import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.utils.module.ModuleListener; +import de.tubeof.tubetils.api.cache.CacheContainer; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +public class WorldStateChange extends ModuleListener { + + private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); + private final CooldownHandler cooldownHandler = new CooldownHandler(); + private final WorldManager worldManager = AntiCooldown.getWorldManager(); + + @EventHandler + public void onWorldEnable(WorldEnableEvent event) { + World world = event.getWorld(); + + for (Player player : world.getPlayers()) { + // Check Permissions + boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); + + // Check if player is permitted + if (!isPermitted) continue; + cooldownHandler.disableCooldown(player); + } + } + + @EventHandler + public void onWorldDisable(WorldDisableEvent event) { + World world = event.getWorld(); + + for (Player player : world.getPlayers()) { + // Check Bypass and Permissions + boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); + boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.cooldown") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); + + if (!isPermitted) continue; + if (!isBypassed) cooldownHandler.enableCooldown(player); + } + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/main/AttackCooldown.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/main/AttackCooldown.java new file mode 100644 index 0000000..0815807 --- /dev/null +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/main/AttackCooldown.java @@ -0,0 +1,28 @@ +package com.yourgamespace.anticooldown.modules.attackcooldown.main; + +import com.yourgamespace.anticooldown.modules.attackcooldown.listeners.JoinQuit; +import com.yourgamespace.anticooldown.modules.attackcooldown.listeners.WorldChange; +import com.yourgamespace.anticooldown.modules.attackcooldown.listeners.WorldStateChange; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; +import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; +import com.yourgamespace.anticooldown.utils.module.ModuleDescription; +import org.bukkit.event.Listener; + +public class AttackCooldown extends AntiCooldownModule implements Listener { + + public AttackCooldown(boolean isProtocolLibRequired, ModuleDescription moduleDescription) { + super(isProtocolLibRequired, moduleDescription); + } + + private final CooldownHandler cooldownHandler = new CooldownHandler(); + + @Override + public void onEnable() { + registerListener(new JoinQuit()); + registerListener(new WorldChange()); + registerListener(new WorldStateChange()); + + // Reload: Apply cooldown to all online players + cooldownHandler.setDefaultCooldown(); + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/CooldownHandler.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/utils/CooldownHandler.java similarity index 91% rename from anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/CooldownHandler.java rename to anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/utils/CooldownHandler.java index 9207766..bd17cee 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/CooldownHandler.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/attackcooldown/utils/CooldownHandler.java @@ -1,7 +1,8 @@ -package com.yourgamespace.anticooldown.utils; +package com.yourgamespace.anticooldown.modules.attackcooldown.utils; import com.yourgamespace.anticooldown.api.events.PlayerCooldownChangeEvent; import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.utils.WorldManager; import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; import de.tubeof.tubetils.api.cache.CacheContainer; import org.bukkit.Bukkit; @@ -14,8 +15,7 @@ public class CooldownHandler { private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); private final WorldManager worldManager = AntiCooldown.getWorldManager(); - public CooldownHandler() { - } + public CooldownHandler() {} public boolean isCooldownDisabled(Player player) { return player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getBaseValue() != 4; @@ -58,11 +58,10 @@ public void setOnlinePlayersCooldown() { // If disabled and is not bypassed, do nothing; if (isBypassed) { disableCooldown(player); - Bukkit.getPluginManager().callEvent(new PlayerCooldownChangeEvent(player)); } else { enableCooldown(player); - Bukkit.getPluginManager().callEvent(new PlayerCooldownChangeEvent(player)); } + Bukkit.getPluginManager().callEvent(new PlayerCooldownChangeEvent(player)); } else { disableCooldown(player); Bukkit.getPluginManager().callEvent(new PlayerCooldownChangeEvent(player)); diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/PlaceholderHandler.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/PlaceholderHandler.java index 7db20d7..57cb225 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/PlaceholderHandler.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/PlaceholderHandler.java @@ -1,6 +1,7 @@ package com.yourgamespace.anticooldown.utils; import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.modules.attackcooldown.utils.CooldownHandler; import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; import com.yourgamespace.anticooldown.utils.module.ModulePlaceholderHandler; import de.tubeof.tubetils.api.cache.CacheContainer; diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/basics/AntiCooldownLogger.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/basics/AntiCooldownLogger.java index 45fdfa2..f18466a 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/basics/AntiCooldownLogger.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/basics/AntiCooldownLogger.java @@ -15,7 +15,7 @@ public void warn(String message) { AntiCooldown.getInstance().getLogger().warning(message); } - public void debug(Class paramClass, String message) { + public void debug(Class paramClass, String message) { AntiCooldown.getInstance().getLogger().fine("[DEBUG] [" + paramClass.getName() + "]§r " + message); } } diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/AntiCooldownModule.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/AntiCooldownModule.java index d1419a2..1c58e13 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/AntiCooldownModule.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/AntiCooldownModule.java @@ -1,5 +1,6 @@ package com.yourgamespace.anticooldown.utils.module; +import com.yourgamespace.anticooldown.files.PluginConfig; import com.yourgamespace.anticooldown.main.AntiCooldown; import com.yourgamespace.anticooldown.utils.basics.AntiCooldownLogger; import org.bukkit.Bukkit; @@ -10,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; @SuppressWarnings("unused") @@ -18,8 +20,10 @@ public abstract class AntiCooldownModule { private final AntiCooldownLogger logger = AntiCooldown.getAntiCooldownLogger(); private final ModuleCommandHandler moduleCommandHandler = AntiCooldown.getModuleCommandHandler(); private final ModulePlaceholderHandler modulePlaceholderHandler = AntiCooldown.getModulePlaceholderHandler(); + private final PluginConfig pluginConfig = AntiCooldown.getPluginConfig(); private final PluginManager pluginManager = Bukkit.getPluginManager(); + private final HashMap configOptions = new HashMap<>(); private final ArrayList listeners = new ArrayList<>(); private final ArrayList packetHandlers = new ArrayList<>(); private final boolean isProtocolLibRequired; @@ -126,8 +130,7 @@ private void setEnabled(boolean enabled) { * If necessary, possibility to register packet handler. */ public void registerPacketHandler(ModulePacketHandler modulePacketHandler) { - AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.sendingAdapter()); - AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.receivingAdapter()); + AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.packetAdapter()); packetHandlers.add(modulePacketHandler); } @@ -148,8 +151,7 @@ public void enableModule() { listeners.forEach(ModuleListener::onLoad); packetHandlers.forEach(modulePacketHandler -> { modulePacketHandler.onLoad(); - AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.sendingAdapter()); - AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.receivingAdapter()); + AntiCooldown.getProtocolManager().addPacketListener(modulePacketHandler.packetAdapter()); }); setEnabled(true); @@ -169,8 +171,7 @@ public void disableModule() { }); packetHandlers.forEach(modulePacketHandler -> { modulePacketHandler.onUnload(); - AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.sendingAdapter()); - AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.receivingAdapter()); + AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.packetAdapter()); }); logger.info("§aModule §e" + getDescription().getName() + " §asuccessfully disabled!"); @@ -191,8 +192,7 @@ public void disableModule(String reason) { }); packetHandlers.forEach(modulePacketHandler -> { modulePacketHandler.onUnload(); - AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.sendingAdapter()); - AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.receivingAdapter()); + AntiCooldown.getProtocolManager().removePacketListener(modulePacketHandler.packetAdapter()); }); logger.info("§aModule §e" + getDescription().getName() + " §asuccessfully disabled! §eReason: " + reason); @@ -220,7 +220,7 @@ public boolean isProtocolLibRequired() { * Get AntiCooldownLogger instance * @return AntiCooldownLogger instance */ - private AntiCooldownLogger getLogger() { + public AntiCooldownLogger getLogger() { return logger; } @@ -228,7 +228,7 @@ private AntiCooldownLogger getLogger() { * Get ModuleCommandHandler * @return ModuleCommandHandler instance */ - private ModuleCommandHandler getModuleCommandHandler() { + public ModuleCommandHandler getModuleCommandHandler() { return moduleCommandHandler; } @@ -236,7 +236,7 @@ private ModuleCommandHandler getModuleCommandHandler() { * Get ModulePlaceholderHandler * @return ModulePlaceholderHandler instance */ - private ModulePlaceholderHandler getModulePlaceholderHandler() { + public ModulePlaceholderHandler getModulePlaceholderHandler() { return modulePlaceholderHandler; } diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleConfig.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleConfig.java new file mode 100644 index 0000000..14f1fa5 --- /dev/null +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleConfig.java @@ -0,0 +1,68 @@ +package com.yourgamespace.anticooldown.utils.module; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; + +@SuppressWarnings("ResultOfMethodCallIgnored") +public class ModuleConfig { + + private final AntiCooldownModule antiCooldownModule; + private String configSuffix; + private String configPrefix; + + public ModuleConfig(@NotNull AntiCooldownModule antiCooldownModule, @NotNull String configPrefix, @NotNull String configSuffix) { + this.antiCooldownModule = antiCooldownModule; + this.configPrefix = configPrefix; + this.configSuffix = configSuffix; + } + + public ModuleConfig(@NotNull AntiCooldownModule antiCooldownModule) { + this.antiCooldownModule = antiCooldownModule; + } + + private File configFile; + private FileConfiguration fileConfiguration; + + public final File getFile() { + // If null then assign + if (configFile == null) { + if (configPrefix == null || configSuffix == null) { + configFile = new File("plugins/AntiCooldown", "module-" + antiCooldownModule.getDescription().getName().toLowerCase() + ".yml"); + } else { + configFile = new File("plugins/AntiCooldown", "module-" + configPrefix + antiCooldownModule.getDescription().getName().toLowerCase() + configSuffix + ".yml"); + } + } + + // Create file if not exists + try { + configFile.createNewFile(); + } catch (IOException exception) { + antiCooldownModule.getLogger().warn("§cAn error occurred while trying to create new module config:"); + exception.printStackTrace(); + } + + return configFile; + } + + public final FileConfiguration getConfig() { + // If null then assign + if (fileConfiguration == null) { + fileConfiguration = YamlConfiguration.loadConfiguration(getFile()); + } + + return fileConfiguration; + } + + public final void saveConfig() { + try { + getConfig().save(getFile()); + } catch (IOException exception) { + antiCooldownModule.getLogger().warn("§cAn error occurred while trying to save module config changes:"); + exception.printStackTrace(); + } + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleHandler.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleHandler.java index 0e33c6e..ba7306b 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleHandler.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModuleHandler.java @@ -43,10 +43,7 @@ public ArrayList getEnabledModules() { } public AntiCooldownModule getModule(String name) { - for (AntiCooldownModule antiCooldownModule : enabledModules) { - if (antiCooldownModule.getDescription().getName().equalsIgnoreCase(name)) return antiCooldownModule; - } - return null; + return enabledModules.stream().filter(antiCooldownModule -> antiCooldownModule.getDescription().getName().equals(name)).findFirst().orElse(null); } public void registerModule(AntiCooldownModule antiCooldownModule) { @@ -71,7 +68,7 @@ public void unregisterModule(String moduleName) { AntiCooldownModule antiCooldownModule = antiCooldownModuleIterator.next(); if (!antiCooldownModule.getDescription().getName().equals(moduleName)) continue; - enabledModules.remove(antiCooldownModule); + antiCooldownModuleIterator.remove(); antiCooldownModule.disableModule(); } } @@ -81,7 +78,7 @@ public void unregisterModule(String moduleName, String reason) { AntiCooldownModule antiCooldownModule = antiCooldownModuleIterator.next(); if (!antiCooldownModule.getDescription().getName().equals(moduleName)) continue; - enabledModules.remove(antiCooldownModule); + antiCooldownModuleIterator.remove(); antiCooldownModule.disableModule(reason); } } @@ -100,7 +97,6 @@ public void enableModules() { for (File file : Objects.requireNonNull(folder.listFiles())) { try { - long millis = System.currentTimeMillis(); AntiCooldownModule antiCooldownModule = loadModule(file); if (antiCooldownModule != null) { registerModule(antiCooldownModule); @@ -115,7 +111,6 @@ public void enableModule(File file) { checkFolder(); try { - long millis = System.currentTimeMillis(); AntiCooldownModule antiCooldownModule = loadModule(file); if (antiCooldownModule != null) { registerModule(antiCooldownModule); diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModulePacketHandler.java b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModulePacketHandler.java index 2d1ac87..8d40752 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModulePacketHandler.java +++ b/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/module/ModulePacketHandler.java @@ -26,17 +26,13 @@ public void onSending(PacketEvent event) {} public void onReceiving(PacketEvent event) {} - public final PacketAdapter sendingAdapter() { + public final PacketAdapter packetAdapter() { return new PacketAdapter(AntiCooldown.getInstance(), listenerPriority, packetTypes) { @Override public void onPacketSending(PacketEvent event) { onSending(event); } - }; - } - public final PacketAdapter receivingAdapter() { - return new PacketAdapter(AntiCooldown.getInstance(), listenerPriority, packetTypes) { @Override public void onPacketReceiving(PacketEvent event) { onReceiving(event); diff --git a/anticooldown/src/main/resources/Config.yml b/anticooldown/src/main/resources/Config.yml index 14d7861..55b24c2 100644 --- a/anticooldown/src/main/resources/Config.yml +++ b/anticooldown/src/main/resources/Config.yml @@ -3,7 +3,7 @@ Messages: # Prefix for chat messages Prefix: '§7[§3AntiCooldown§7] ' # Prefix for actionbar messages - ActionBarPrefix: §3AntiCooldown§7 » + ActionBarPrefix: '§3AntiCooldown§7 » ' # Messages related to a world switch SwitchWorld: diff --git a/anticooldown/src/main/resources/Config_old.yml b/anticooldown/src/main/resources/Config_old.yml new file mode 100644 index 0000000..14d7861 --- /dev/null +++ b/anticooldown/src/main/resources/Config_old.yml @@ -0,0 +1,206 @@ +# All messages of AntiCooldown +Messages: + # Prefix for chat messages + Prefix: '§7[§3AntiCooldown§7] ' + # Prefix for actionbar messages + ActionBarPrefix: §3AntiCooldown§7 » + + # Messages related to a world switch + SwitchWorld: + # Message when the world is deactivated but the player has bypass permissions + # Bypass-Permission: anticooldown.bypass + Bypassed: §ePvP Cooldown is §c§lnot disabled §ein this world, but you have §2Bypass-Permissions§a! + §aCooldown is disable for you. + # Message when the cooldown is deactivated in the world + Enabled: §ePvP Cooldown is §a§ldisabled §ein this world! + # Message when the cooldown is activated in the world + Disabled: §ePvP Cooldown is §c§lnot disabled §ein this world! + + # Messages related to player login + Login: + # Message when the world is deactivated but the player has bypass permissions + # Bypass-Permission: anticooldown.bypass + Bypassed: §aHey, welcome to the server! §ePvP Cooldown is §c§lnot disabled §ein + this world, but you have §2Bypass-Permissions§a! §aCooldown is disable for you. + # # Message when the cooldown is deactivated in the world + Enabled: §aHey, welcome to the server! §ePvP Cooldown is §a§ldisabled §ein this + world! + # Message when the cooldown is activated in the world + Disabled: §aHey, welcome to the server! §ePvP Cooldown is §c§lnot disabled §ein + this world! + + # Messages related to the CustomItemDamage module + CustomItemDamage: + # Message that is displayed as an ActionBar and informs the player about the custom damage + ActionBarMessage: '%actionbar_prefix% §aCustom-Damage applied: §7%finaldamage%§c❤ + §7Damage' + + # Messages related to the ItemRestriction module + ItemRestriction: + # Message that is displayed as an ActionBar and informs the player about the custom damage + ActionBarMessage: + # Message as ActionBar, which is displayed when the item is deactivated + Enabled: '%actionbar_prefix% §aItem is no longer restricted! PvP Cooldown is + §a§ldisabled §aagain' + # Message as ActionBar, which is displayed when the item is activated + Disabled: '%actionbar_prefix% §cItem is restricted! PvP Cooldown is temporarily + §c§lactivated' + + # Messages related to ingame commands and/or settings + Setting: + # Message when a world will be disabled + AddDisabledWorld: §aOK! In the world §e%world% §athe cooldown is now activated. + # Message when a world will be enabled + RemoveDisabledWorld: §aOK! In the world §e%world% §athe cooldown is now deactivated. + + # Messages related to errors + Error: + # Message when a world is already disabled + WorldAlreadyDisabled: §cThis world is already §c§ldeactivated§c! + # Message when a world is already enabled + WorldAlreadyEnabled: §cThis world is already §a§lactivated§c! + # Message when the player is not online + # Mainly used for commands + PlayerNotOnline: §cThe player is not online! + # Message if a player try to use commands and has no permissions + NoPerms: §cNo permissions! + +# Content of placerholders +Placeholder: + # Placeholder related to world cooldown + # Placeholder: anticooldown_worldcooldown + World: + # The content which is returned with the above placeholder, + # if the cooldown is enabled in the world. + CooldownEnabled: Enabled + # The content which is returned with the above placeholder, + # if the cooldown is disabled in the world. + CooldownDisabled: Disabled + # Placeholder related to players cooldown + # Placeholder: anticooldown_playercooldown + Player: + # The content which is returned with the above placeholder, + # if the cooldown is enabled for the player. + CooldownEnabled: Enabled + # The content which is returned with the above placeholder, + # if the cooldown is disabled for the player. + CooldownDisabled: Disabled + +# Setting options of AntiCooldown +Settings: + # Settings related to permissions + Permissions: + # Determines whether permissions are to be used + # Available options: true, false + UsePermissions: false + # Sets whether to use the bypass permissions. + # Note: Bypass permissions are not dependent on the UsePermissions option + # Available options: true, false + UseBypassPermission: false + Messages: + # Determines whether the player should be sent a message + # about the current cooldown status when logging in. + # Available options: true, false + UseLoginMessage: true + # Determines whether the player should be sent a message + # about the current cooldown status when switching worlds. + # Available options: true, false + UseSwitchWorldMessage: true + + # All values which are used by AntiCooldown + Values: + # Sets the BaseAttackSpeed which is used for the cool down deactivation + # 16 is the minimum value for the cool-down to be deactivated + # Recommended: 100 - This makes the cooldown indicator invisible + AttackSpeed: 100 + # Worlds in which AntiCooldown is not active + DisabledWorlds: + - YourWorldName + # Item that the player can hold in their hand and temporarily reactivate the player's cooldown. + # This item list can also be used as a whitelist, so that the cooldown is only deactivated if + # the player is holding one of the items entered here. Requires the activation of UseAsWhitelist. + RestrictedItems: + - DIAMOND_AXE + - GOLDEN_AXE + - IRON_AXE + - STONE_AXE + - NETHERITE_AXE + - WOODEN_AXE + # The base damage value of an item can be overwritten here + # SYNTAX: ITEM:DAMAGE + # NOTE: The damage is of the data type "Double", it is therefore necessary to specify "D" after the value, + # as in the already existing entries! + # Material-List of the latest Spigot version: + # https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html + CustomItemDamage: + - WOOD_AXE:3.0D + - WOODEN_AXE:3.0D + - GOLD_AXE:3.0D + - GOLDEN_AXE:3.0D + - STONE_AXE:4.0D + - IRON_AXE:5.0D + - DIAMOND_AXE:6.0D + - WOOD_PICKAXE:2.0D + - WOODEN_PICKAXE:2.0D + - GOLD_PICKAXE:2.0D + - GOLDEN_PICKAXE:2.0D + - STONE_PICKAXE:3.0D + - IRON_PICKAXE:4.0D + - DIAMOND_PICKAXE:5.0D + - WOODEN_SHOVEL:1.0D + - GOLDEN_SHOVEL:1.0D + - STONE_SHOVEL:2.0D + - IRON_SHOVEL:3.0D + - DIAMOND_SHOVEL:4.0D + + # Settings related to features for AntiCooldown + Features: + # Should the SweepAttack be deactivated? + # This also automatically disables any particles of an sweep attack + # if ProtocolLib is installed. + # Available options: true, false + DisableSweepAttacks: true + # Should the new attack sounds be deactivated? + # Available options: true, false + DisableNewCombatSounds: true + # Should player collisions be disabled? + # Available options: true, false + DisablePlayerCollision: true + # Should the cooldown of ender pearls be deactivated? + # This will also disable the cooldown animation at the client. + # Available options: true, false + DisableEnderpearlCooldown: true + CustomItemDamage: + # Determines whether the EnableCustomItemDamage module should be activated. + # The damage of the defined items in "CustomItemDamage" is thereby applied. + # Available options: true, false + EnableCustomItemDamage: false + # Should a message in the form of an ActionBar be sent to the attacker? + # Available options: true, false + SendActionBar: true + ItemRestriction: + # Determines whether the item restrictions are to be used. + # Available options: true, false + EnableItemRestriction: false + # Should a message be sent to the player in the form of an ActionBar + # when their Cooldown status has changed due to a restricted item? + # Available options: true, false + SendActionBar: true + # Determines whether the defined items are to be used as a whitelist. + # The cooldown is only deactivated if this is the case. + # Available options: true, false + UseAsWhitelist: false + Updates: + # Should AntiCooldown check for updates? + # Available options: true, false + UseUpdateChecker: true + # If there is an update, should this be output in the console? + # Available options: true, false + ConsoleNotify: true + # If there is an update, should this be displayed to an admin when logging in? + # Available options: true, false + IngameNotify: true + +# Version of the current config +# DO NOT CHANGE! +ConfigVersion: 18 \ No newline at end of file diff --git a/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/main/CombatSounds.java b/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/main/CombatSounds.java new file mode 100644 index 0000000..371cb43 --- /dev/null +++ b/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/main/CombatSounds.java @@ -0,0 +1,18 @@ +package com.yourgamespace.anticooldown.module.combatsounds.main; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.ListenerPriority; +import com.yourgamespace.anticooldown.module.combatsounds.packethandler.DisableSounds; +import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; + +public class CombatSounds extends AntiCooldownModule { + + public CombatSounds(boolean isProtocolLibRequired) { + super(true); + } + + @Override + public void onEnable() { + registerPacketHandler(new DisableSounds(ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_SOUND_EFFECT)); + } +} diff --git a/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/packethandler/DisableSounds.java b/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/packethandler/DisableSounds.java new file mode 100644 index 0000000..e8c7045 --- /dev/null +++ b/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/combatsounds/packethandler/DisableSounds.java @@ -0,0 +1,57 @@ +package com.yourgamespace.anticooldown.module.combatsounds.packethandler; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.PacketEvent; +import com.yourgamespace.anticooldown.main.AntiCooldown; +import com.yourgamespace.anticooldown.utils.WorldManager; +import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.utils.module.ModulePacketHandler; +import de.tubeof.tubetils.api.cache.CacheContainer; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public class DisableSounds extends ModulePacketHandler { + + public DisableSounds(ListenerPriority listenerPriority, PacketType... packetTypes) { + super(listenerPriority, packetTypes); + } + + private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); + private final WorldManager worldManager = AntiCooldown.getWorldManager(); + + @Override + public void onSending(PacketEvent event) { + // Check if valid sound + boolean valid = false; + Sound sound = event.getPacket().getSoundEffects().read(0); + if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_SWEEP)) valid = true; + if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_CRIT)) valid = true; + if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_KNOCKBACK)) valid = true; + if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_STRONG)) valid = true; + if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_NODAMAGE)) valid = true; + + // If not valid: Return; + if (!valid) return; + + // Check if player has permissions + Player player = event.getPlayer(); + String world = player.getWorld().getName(); + + // Check Bypass and Permissions + boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); + boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.combatsounds") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); + + // If not permitted: Return; + if (!isPermitted) return; + + // Check if world is disabled + if (worldManager.isWorldDisabled(world)) { + // If disabled and is bypassed: disable sounds; + if (isBypassed) event.setCancelled(true); + } else { + // If permitted and not bypassed: disable sounds; + event.setCancelled(true); + } + } +} diff --git a/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/main/CombatSounds.java b/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/main/CombatSounds.java deleted file mode 100644 index dad3b58..0000000 --- a/module/combatsounds/src/main/java/com/yourgamespace/anticooldown/module/main/CombatSounds.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.yourgamespace.anticooldown.module.main; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketEvent; -import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.WorldManager; -import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; -import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; -import de.tubeof.tubetils.api.cache.CacheContainer; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -@SuppressWarnings("unused") -public class CombatSounds extends AntiCooldownModule { - - public CombatSounds(boolean isProtocolLibRequired) { - super(true); - } - - private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); - private final WorldManager worldManager = AntiCooldown.getWorldManager(); - - //@Override - //public void registerPacketHandler() { - // new PacketHandler(); - //} - - public class PacketHandler { - - public PacketHandler() { - onNewAttackSounds(); - } - - private void onNewAttackSounds() { - if (!ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "DISABLE_NEW_COMBAT_SOUNDS"))) return; - - AntiCooldown.getProtocolManager().addPacketListener(new PacketAdapter(AntiCooldown.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_SOUND_EFFECT) { - @Override - public void onPacketSending(PacketEvent event) { - // Check if valid sound - boolean valid = false; - Sound sound = event.getPacket().getSoundEffects().read(0); - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_SWEEP)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_CRIT)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_KNOCKBACK)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_STRONG)) valid = true; - if (sound.equals(Sound.ENTITY_PLAYER_ATTACK_NODAMAGE)) valid = true; - - // If not valid: Return; - if (!valid) return; - - // Check if player has permissions - Player player = event.getPlayer(); - String world = player.getWorld().getName(); - - // Check Bypass and Permissions - boolean isBypassed = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_BYPASS_PERMISSION")) && player.hasPermission("anticooldown.bypass"); - boolean isPermitted = ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")) && player.hasPermission("anticooldown.combatsounds") || !ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "USE_PERMISSIONS")); - - // If not permitted: Return; - if (!isPermitted) return; - - // Check if world is disabled - if (worldManager.isWorldDisabled(world)) { - // If disabled and is bypassed: disable sounds; - if (isBypassed) event.setCancelled(true); - } else { - // If permitted and not bypassed: disable sounds; - event.setCancelled(true); - } - } - }); - } - } -} diff --git a/module/combatsounds/src/main/resources/module.yml b/module/combatsounds/src/main/resources/module.yml index 773672b..ead8b7f 100644 --- a/module/combatsounds/src/main/resources/module.yml +++ b/module/combatsounds/src/main/resources/module.yml @@ -1,5 +1,5 @@ name: CombatSounds version: 1.0.0-DEV -main: com.yourgamespace.anticooldown.module.main.CombatSounds +main: com.yourgamespace.anticooldown.module.combatsounds.main.CombatSounds author: YourGameSpace description: Disable new combat sounds \ No newline at end of file diff --git a/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/files/Config.java b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/files/Config.java new file mode 100644 index 0000000..7039ad6 --- /dev/null +++ b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/files/Config.java @@ -0,0 +1,51 @@ +package com.yourgamespace.anticooldown.module.customitemdamage.files; + +import com.yourgamespace.anticooldown.module.customitemdamage.main.CustomItemDamage; +import com.yourgamespace.anticooldown.module.customitemdamage.utils.ItemDamageManager; +import com.yourgamespace.anticooldown.utils.module.ModuleConfig; + +import java.util.List; + +public class Config { + + private final ModuleConfig moduleConfig = new ModuleConfig(CustomItemDamage.getInstance()); + + public Config() {} + + public void setupConfig() { + moduleConfig.getConfig().options().copyDefaults(true); + + //List: Item Damage Values + List customItemDamage = moduleConfig.getConfig().getStringList("OverrideItemDamage"); + customItemDamage.add("WOOD_AXE:3.0D"); + customItemDamage.add("WOODEN_AXE:3.0D"); + customItemDamage.add("GOLD_AXE:3.0D"); + customItemDamage.add("GOLDEN_AXE:3.0D"); + customItemDamage.add("STONE_AXE:4.0D"); + customItemDamage.add("IRON_AXE:5.0D"); + customItemDamage.add("DIAMOND_AXE:6.0D"); + customItemDamage.add("WOOD_PICKAXE:2.0D"); + customItemDamage.add("WOODEN_PICKAXE:2.0D"); + customItemDamage.add("GOLD_PICKAXE:2.0D"); + customItemDamage.add("GOLDEN_PICKAXE:2.0D"); + customItemDamage.add("STONE_PICKAXE:3.0D"); + customItemDamage.add("IRON_PICKAXE:4.0D"); + customItemDamage.add("DIAMOND_PICKAXE:5.0D"); + customItemDamage.add("WOODEN_SHOVEL:1.0D"); + customItemDamage.add("GOLDEN_SHOVEL:1.0D"); + customItemDamage.add("STONE_SHOVEL:2.0D"); + customItemDamage.add("IRON_SHOVEL:3.0D"); + customItemDamage.add("DIAMOND_SHOVEL:4.0D"); + moduleConfig.getConfig().addDefault("OverrideItemDamage", customItemDamage); + + moduleConfig.saveConfig(); + } + + public void loadConfig() { + //Values: CustomItemDamage + for (String customItemDamage : moduleConfig.getConfig().getStringList("OverrideItemDamage")) { + String[] itemParams = customItemDamage.split(":"); + ItemDamageManager.addCache(itemParams[0], itemParams[1]); + } + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CustomItemDamage.java b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/listeners/ApplyDamage.java similarity index 79% rename from anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CustomItemDamage.java rename to module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/listeners/ApplyDamage.java index d04efae..56eb959 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/modules/CustomItemDamage.java +++ b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/listeners/ApplyDamage.java @@ -1,40 +1,32 @@ -package com.yourgamespace.anticooldown.modules; +package com.yourgamespace.anticooldown.module.customitemdamage.listeners; import com.yourgamespace.anticooldown.main.AntiCooldown; -import com.yourgamespace.anticooldown.utils.ItemDamageHandler; -import com.yourgamespace.anticooldown.utils.ItemDamageManager; -import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.module.customitemdamage.utils.ItemDamageHandler; +import com.yourgamespace.anticooldown.module.customitemdamage.utils.ItemDamageManager; import com.yourgamespace.anticooldown.utils.WorldManager; -import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; -import com.yourgamespace.anticooldown.utils.module.ModuleDescription; +import com.yourgamespace.anticooldown.utils.basics.ObjectTransformer; +import com.yourgamespace.anticooldown.utils.module.ModuleListener; import de.tubeof.tubetils.api.cache.CacheContainer; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; @SuppressWarnings("ConstantConditions") -public class CustomItemDamage extends AntiCooldownModule implements Listener { +public class ApplyDamage extends ModuleListener { private final CacheContainer cacheContainer = AntiCooldown.getCacheContainer(); private final WorldManager worldManager = AntiCooldown.getWorldManager(); - public CustomItemDamage(boolean isProtocolLibRequired, ModuleDescription moduleDescription) { - super(isProtocolLibRequired, moduleDescription); - } - - //@Override - //public void onEnable() { - // registerListener(this); - //} - @EventHandler public void onDamage(EntityDamageByEntityEvent event) { - if (!ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "ENABLE_CUSTOM_ITEM_DAMAGE"))) return; + // PERMA REMOVED: Removed since module system. (5.0.0) + // Unnecessary check: Module can be removed or disabled. + //if (!ObjectTransformer.getBoolean(cacheContainer.get(Boolean.class, "ENABLE_CUSTOM_ITEM_DAMAGE"))) return; + // END PERMA REMOVED if (!(event.getDamager() instanceof Player)) return; Player player = (Player) event.getDamager(); ItemStack itemStack = player.getInventory().getItemInMainHand(); diff --git a/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/main/CustomItemDamage.java b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/main/CustomItemDamage.java new file mode 100644 index 0000000..4b6959b --- /dev/null +++ b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/main/CustomItemDamage.java @@ -0,0 +1,35 @@ +package com.yourgamespace.anticooldown.module.customitemdamage.main; + +import com.yourgamespace.anticooldown.module.customitemdamage.files.Config; +import com.yourgamespace.anticooldown.module.customitemdamage.listeners.ApplyDamage; +import com.yourgamespace.anticooldown.utils.module.AntiCooldownModule; +import org.bukkit.event.Listener; + +public class CustomItemDamage extends AntiCooldownModule implements Listener { + + public CustomItemDamage(boolean isProtocolLibRequired) { + super(false); + } + + private static CustomItemDamage instance; + private static Config config; + + @Override + public void onEnable() { + instance = this; + config = new Config(); + + config.setupConfig(); + config.loadConfig(); + + registerListener(new ApplyDamage()); + } + + public static CustomItemDamage getInstance() { + return instance; + } + + public static Config getConfig() { + return config; + } +} diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageHandler.java b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageHandler.java similarity index 98% rename from anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageHandler.java rename to module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageHandler.java index 4379a45..4d33d59 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageHandler.java +++ b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageHandler.java @@ -1,4 +1,4 @@ -package com.yourgamespace.anticooldown.utils; +package com.yourgamespace.anticooldown.module.customitemdamage.utils; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; diff --git a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageManager.java b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageManager.java similarity index 95% rename from anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageManager.java rename to module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageManager.java index 66e13c8..91bb48f 100644 --- a/anticooldown/src/main/java/com/yourgamespace/anticooldown/utils/ItemDamageManager.java +++ b/module/customitemdamage/src/main/java/com/yourgamespace/anticooldown/module/customitemdamage/utils/ItemDamageManager.java @@ -1,4 +1,4 @@ -package com.yourgamespace.anticooldown.utils; +package com.yourgamespace.anticooldown.module.customitemdamage.utils; import com.yourgamespace.anticooldown.main.AntiCooldown; import com.yourgamespace.anticooldown.utils.basics.AntiCooldownLogger; @@ -11,7 +11,6 @@ public class ItemDamageManager { private static final AntiCooldownLogger antiCooldownLogger = AntiCooldown.getAntiCooldownLogger(); - private static final HashMap itemDamages = new HashMap<>(); public static void addCache(String paramMaterial, String paramDamage) { diff --git a/module/customitemdamage/src/main/resources/module.yml b/module/customitemdamage/src/main/resources/module.yml new file mode 100644 index 0000000..54dd044 --- /dev/null +++ b/module/customitemdamage/src/main/resources/module.yml @@ -0,0 +1,5 @@ +name: CustomItemDamage +version: 1.0.0-DEV +main: com.yourgamespace.anticooldown.module.customitemdamage.main.CustomItemDamage +author: YourGameSpace +description: Override base item damage \ No newline at end of file