diff --git a/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class b/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class index ab41486..a72f946 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class and b/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/commands/Commands.class b/build/classes/java/main/me/improper/explosionscontrol/commands/Commands.class index 95f5719..4736ca2 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/commands/Commands.class and b/build/classes/java/main/me/improper/explosionscontrol/commands/Commands.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/data/Config.class b/build/classes/java/main/me/improper/explosionscontrol/data/Config.class new file mode 100644 index 0000000..25fe29b Binary files /dev/null and b/build/classes/java/main/me/improper/explosionscontrol/data/Config.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionMode.class b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionMode.class index 332760d..663b18a 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionMode.class and b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionMode.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionToggle.class b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionToggle.class index 3f8a832..2471667 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionToggle.class and b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionToggle.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode$1.class b/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode$1.class index db166f3..47f479e 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode$1.class and b/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode$1.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode.class b/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode.class index e5af5a3..b0b1fc5 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode.class and b/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory$1.class b/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory$1.class new file mode 100644 index 0000000..50ed7c9 Binary files /dev/null and b/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory$1.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory.class b/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory.class new file mode 100644 index 0000000..f1f9a1b Binary files /dev/null and b/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$1.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$1.class index 5aff274..f5ca352 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$1.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$1.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$2.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$2.class index adf7140..d250d2f 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$2.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$2.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$3.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$3.class index 9ca7de6..e2794a1 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$3.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$3.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$4.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$4.class index 727cedf..b7b2e60 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$4.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$4.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$5.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$5.class index 3e6adfd..204e7fb 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$5.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$5.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$6.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$6.class index dbcd3d4..6aec798 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$6.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$6.class differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound.class b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound.class index be4ed06..42c8fcd 100644 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound.class and b/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound.class differ diff --git a/build/libs/ExplosionsControl-3.0.jar b/build/libs/ExplosionsControl-3.0.jar index 14b1e0d..6b7a120 100644 Binary files a/build/libs/ExplosionsControl-3.0.jar and b/build/libs/ExplosionsControl-3.0.jar differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 8866c02..ce7fb69 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java b/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java index 512fab1..25d83b5 100644 --- a/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java +++ b/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java @@ -2,19 +2,23 @@ package me.improper.explosionscontrol; import me.improper.explosionscontrol.commands.Commands; import me.improper.explosionscontrol.commands.Tabs; +import me.improper.explosionscontrol.data.Config; import me.improper.explosionscontrol.data.ExplosionConfigFile; import me.improper.explosionscontrol.data.ExplosionToggle; import me.improper.explosionscontrol.events.OnExplode; +import me.improper.explosionscontrol.events.OnInventory; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; public final class ExplosionsControl extends JavaPlugin { + public static String STARTER = Config.getPluginPrefix(); + @Override public void onEnable() { // Plugin startup logic - Bukkit.broadcastMessage(""); + Bukkit.broadcastMessage(STARTER + "aExplosionsControls has loaded!"); ExplosionConfigFile.setup(); ExplosionToggle.setup(); @@ -24,6 +28,7 @@ public final class ExplosionsControl extends JavaPlugin { // Events Bukkit.getPluginManager().registerEvents(new OnExplode(),this); + Bukkit.getPluginManager().registerEvents(new OnInventory(),this); // Commands getCommand("explosions").setExecutor(new Commands()); @@ -35,6 +40,8 @@ public final class ExplosionsControl extends JavaPlugin { @Override public void onDisable() { // Plugin shutdown logic + Bukkit.broadcastMessage(STARTER + "cExplosionsControls has disabled! If this isn't a reload please consider restarting" + + " as your server is no longer being protected from explosions!"); } public static Plugin getInstance() { diff --git a/src/main/java/me/improper/explosionscontrol/commands/Commands.java b/src/main/java/me/improper/explosionscontrol/commands/Commands.java index 56c431e..4e1b400 100644 --- a/src/main/java/me/improper/explosionscontrol/commands/Commands.java +++ b/src/main/java/me/improper/explosionscontrol/commands/Commands.java @@ -1,8 +1,11 @@ package me.improper.explosionscontrol.commands; +import me.improper.explosionscontrol.ExplosionsControl; import me.improper.explosionscontrol.data.ExplosionConfigFile; import me.improper.explosionscontrol.data.ExplosionToggle; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -21,11 +24,13 @@ public class Commands implements CommandExecutor { } case "loadworlds" -> { ExplosionConfigFile.setup(); + sender.sendMessage(ExplosionsControl.STARTER + "6Reloaded all world explosions configurations!"); + for (World world : Bukkit.getWorlds()) sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.YELLOW + world.getName()); return true; } } } catch (Exception exception) { - String message = ChatColor.DARK_RED + "Command error: " + ChatColor.RED; + String message = ExplosionsControl.STARTER + ChatColor.DARK_RED + "Command error: " + ChatColor.RED; if (exception instanceof NullPointerException) message += "Command contains a null value!"; else if (exception instanceof IndexOutOfBoundsException) message += "Incomplete command! Not enough information was provided!"; else message += exception.getMessage(); diff --git a/src/main/java/me/improper/explosionscontrol/data/Config.java b/src/main/java/me/improper/explosionscontrol/data/Config.java new file mode 100644 index 0000000..2824678 --- /dev/null +++ b/src/main/java/me/improper/explosionscontrol/data/Config.java @@ -0,0 +1,19 @@ +package me.improper.explosionscontrol.data; + +import me.improper.explosionscontrol.ExplosionsControl; +import org.bukkit.configuration.file.FileConfiguration; + +public class Config { + + private static FileConfiguration CONFIG = ExplosionsControl.getInstance().getConfig(); + + /** + * This will return the current plugin prefix set + * in the plugin's configuration file. + * + * @return The plugin prefix + */ + public static String getPluginPrefix() { + return CONFIG.getString("config.plugin.prefix"); + } +} diff --git a/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java b/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java index 2c7cdff..7513226 100644 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java +++ b/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java @@ -9,9 +9,36 @@ public enum ExplosionMode implements Serializable { DYNAMIC(2), NONE(3); + /** + * Attempts to get an explosion mode from the index value provided. + * + * @param index int + * @return An explosion mode from the index value. + */ + public static ExplosionMode fromIndex(int index) { + for (ExplosionMode mode : ExplosionMode.values()) if (index == mode.getIndex()) return mode; + return fromIndex(0); + } + private final int index; + /** + * Constructs an explosion mode from the index provided. + * + * @param index int + */ ExplosionMode(int index) { this.index = index; } + + /** + * Returns the index of the current explosion mode value. + * A number out of bounds will be read as 0! + * + * @return The index of the current value + */ + public int getIndex() { + if (index >= ExplosionMode.values().length || index < 0) return 0; + return index; + } } diff --git a/src/main/java/me/improper/explosionscontrol/data/ExplosionToggle.java b/src/main/java/me/improper/explosionscontrol/data/ExplosionToggle.java index 38a8be8..a0cb334 100644 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionToggle.java +++ b/src/main/java/me/improper/explosionscontrol/data/ExplosionToggle.java @@ -1,12 +1,17 @@ package me.improper.explosionscontrol.data; +import me.improper.explosionscontrol.ExplosionsControl; import me.improper.explosionscontrol.other.Item; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import java.util.List; + public class ExplosionToggle { public static Inventory EXPLOSIONMENU; @@ -17,19 +22,83 @@ public class ExplosionToggle { * through this menu! */ public static void setup() { - Inventory menu = Bukkit.createInventory(null,54,"Explosions"); + Inventory menu = Bukkit.createInventory(null,54, ExplosionsControl.STARTER + "eConfigurations"); Item reload = new Item(new ItemStack(Material.COMPASS)); reload.setDisplayName(ChatColor.AQUA + "Load Worlds"); - - + Item blank = new Item(new ItemStack(Material.DARK_OAK_SIGN)); + blank.setDisplayName(ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "Blank World"); + Item b = new Item(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)); + b.setDisplayName(" "); + Item o = new Item(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE)); + o.setDisplayName(" "); + Item y = new Item(new ItemStack(Material.YELLOW_STAINED_GLASS_PANE)); + y.setDisplayName(" "); + Item a = new Item(new ItemStack(Material.AIR)); menu.setContents(new ItemStack[]{ - + y,y,y,y,y,y,y,y,reload, + b,b,b,b,b,b,b,b,b, + o,a,a,a,a,a,a,a,o, + o,a,a,a,a,a,a,a,o, + o,a,a,a,a,a,a,a,o, + o,o,o,o,o,o,o,o,o }); - menu.addItem(reload); + for (World world : Bukkit.getWorlds()) { + Item worldIcon = new Item(new ItemStack(Material.OAK_SIGN)); + worldIcon.setDisplayName(ChatColor.GRAY + world.getName()); + worldIcon.setLore(List.of(ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "(Click to config)")); + menu.setItem(menu.firstEmpty(),worldIcon); + } + + while (menu.firstEmpty() != -1) menu.setItem(menu.firstEmpty(),blank); EXPLOSIONMENU = menu; } + + public static void openToggleMenu(Player player, World world) { + Inventory menu = Bukkit.createInventory(null,54, ExplosionsControl.STARTER + "eEditing " + world.getName()); + ExplosionConfiguration configuration = new ExplosionConfiguration(world); + + Item b = new Item(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)); + b.setDisplayName(" "); + Item o = new Item(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE)); + o.setDisplayName(" "); + Item y = new Item(new ItemStack(Material.YELLOW_STAINED_GLASS_PANE)); + y.setDisplayName(" "); + Item blank = new Item(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE)); + blank.setDisplayName(" "); + Item a = new Item(new ItemStack(Material.AIR)); + Item back = new Item(new ItemStack(Material.ARROW)); + back.setDisplayName("<< Back to world menu"); + // toggles + Item creeper = new Item(new ItemStack(Material.CREEPER_HEAD)); + creeper.setDisplayName(configuration.getAllowCreeper().name()); + Item crystal = new Item(new ItemStack(Material.END_CRYSTAL)); + crystal.setDisplayName(configuration.getAllowCrystal().name()); + Item tnt = new Item(new ItemStack(Material.TNT)); + tnt.setDisplayName(configuration.getAllowTnt().name()); + Item minecart = new Item(new ItemStack(Material.TNT_MINECART)); + minecart.setDisplayName(configuration.getAllowMinecart().name()); + Item anchor = new Item(new ItemStack(Material.RESPAWN_ANCHOR)); + anchor.setDisplayName(configuration.getAllowBlock().name()); + Item fireball = new Item(new ItemStack(Material.FIRE_CHARGE)); + fireball.setDisplayName(configuration.getAllowFireball().name()); + Item wither = new Item(new ItemStack(Material.WITHER_SKELETON_SKULL)); + wither.setDisplayName(configuration.getAllowWither().name()); + + menu.setContents(new ItemStack[]{ + back,y,y,y,y,y,y,y,y, + b,b,b,b,b,b,b,b,b, + o,a,a,a,a,a,a,a,o, + o,creeper,crystal,tnt,minecart,anchor,fireball,wither,o, + o,a,a,a,a,a,a,a,o, + o,o,o,o,o,o,o,o,o + }); + + while (menu.firstEmpty() != -1) menu.setItem(menu.firstEmpty(),blank); + + player.openInventory(menu); + } } diff --git a/src/main/java/me/improper/explosionscontrol/events/OnExplode.java b/src/main/java/me/improper/explosionscontrol/events/OnExplode.java index 2da7ac7..8b756b6 100644 --- a/src/main/java/me/improper/explosionscontrol/events/OnExplode.java +++ b/src/main/java/me/improper/explosionscontrol/events/OnExplode.java @@ -3,10 +3,7 @@ package me.improper.explosionscontrol.events; import me.improper.explosionscontrol.data.ExplosionConfiguration; import me.improper.explosionscontrol.data.ExplosionMode; import me.improper.explosionscontrol.other.ServerSound; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; @@ -26,14 +23,13 @@ public class OnExplode implements Listener { Location loc = e.getLocation(); World world = loc.getWorld(); ExplosionConfiguration configuration = new ExplosionConfiguration(world); - ServerSound explosion = new ServerSound(e.getLocation(),Sound.ENTITY_GENERIC_EXPLODE,10,0.7F); switch (entity.getType()) { case PRIMED_TNT -> { switch (configuration.getAllowTnt()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -47,7 +43,7 @@ public class OnExplode implements Listener { switch (configuration.getAllowFireball()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -61,7 +57,7 @@ public class OnExplode implements Listener { switch (configuration.getAllowCreeper()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -75,7 +71,7 @@ public class OnExplode implements Listener { switch (configuration.getAllowCrystal()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -89,7 +85,7 @@ public class OnExplode implements Listener { switch (configuration.getAllowMinecart()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -103,7 +99,7 @@ public class OnExplode implements Listener { switch (configuration.getAllowWither()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -122,12 +118,11 @@ public class OnExplode implements Listener { Location loc = block.getLocation(); World world = loc.getWorld(); ExplosionConfiguration configuration = new ExplosionConfiguration(world); - ServerSound explosion = new ServerSound(block.getLocation(),Sound.ENTITY_GENERIC_EXPLODE,10,0.7F); switch (configuration.getAllowBlock()) { case DISABLED -> { e.setCancelled(true); - explosion.playWithin(5000); + fakeExplode(loc); } case NONE -> { e.setCancelled(true); @@ -205,4 +200,17 @@ public class OnExplode implements Listener { fb.setVelocity(vector); block.setType(Material.AIR); } + + /** + * Plays a sound and displays the explosion particles at the provided world location. + * + * @param location Location + */ + public static void fakeExplode(Location location) { + ServerSound explosion = new ServerSound(location,Sound.ENTITY_GENERIC_EXPLODE,10,0.7F); + explosion.playWithin(5000); + location.getWorld().spawnParticle(Particle.EXPLOSION_LARGE,location,1,1,1,1,0); + location.getWorld().spawnParticle(Particle.EXPLOSION_HUGE,location,1,1,1,1,0); + location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL,location,5,1,1,1,0); + } } diff --git a/src/main/java/me/improper/explosionscontrol/events/OnInventory.java b/src/main/java/me/improper/explosionscontrol/events/OnInventory.java new file mode 100644 index 0000000..8d5aafd --- /dev/null +++ b/src/main/java/me/improper/explosionscontrol/events/OnInventory.java @@ -0,0 +1,118 @@ +package me.improper.explosionscontrol.events; + +import me.improper.explosionscontrol.ExplosionsControl; +import me.improper.explosionscontrol.data.ExplosionConfigFile; +import me.improper.explosionscontrol.data.ExplosionConfiguration; +import me.improper.explosionscontrol.data.ExplosionMode; +import me.improper.explosionscontrol.data.ExplosionToggle; +import me.improper.explosionscontrol.other.Item; +import me.improper.explosionscontrol.other.ServerSound; +import org.bukkit.*; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; + +public class OnInventory implements Listener { + + @EventHandler + public static void InventoryClickEvent(InventoryClickEvent e) { + Player p = (Player) e.getWhoClicked(); + Inventory inv = e.getClickedInventory(); + String title = e.getView().getTitle(); + + try { + Item item = new Item(e.getCurrentItem()); + ServerSound reload = new ServerSound(p.getLocation(),Sound.BLOCK_ENCHANTMENT_TABLE_USE,10,10); + ServerSound click = new ServerSound(p.getLocation(),Sound.UI_BUTTON_CLICK,10,1); + ServerSound edit = new ServerSound(p.getLocation(),Sound.ITEM_DYE_USE,10,10); + + if (title.contains(ExplosionsControl.STARTER + "eConfigurations")) { + if (inv.getType().equals(InventoryType.PLAYER)) return; + e.setCancelled(true); + if (item.getDisplayName().equals(" ")) return; + if (item.getDisplayName().equals(ChatColor.AQUA + "Load Worlds")) { + p.closeInventory(); + ExplosionConfigFile.setup(); + ExplosionToggle.setup(); + p.openInventory(ExplosionToggle.EXPLOSIONMENU); + reload.play(p); + return; + } + if (item.getType().equals(Material.DARK_OAK_SIGN)) return; + if (item.getType().equals(Material.OAK_SIGN)) { + World world = Bukkit.getWorld(item.getDisplayName().replaceAll(ChatColor.GRAY + "","")); + ExplosionToggle.openToggleMenu(p,world); + click.play(p); + } + } + if (title.contains(ExplosionsControl.STARTER + "eEditing ")) { + if (inv.getType().equals(InventoryType.PLAYER)) return; + e.setCancelled(true); + if (item.getDisplayName().equals(" ")) return; + if (item.getType().equals(Material.DARK_OAK_SIGN)) return; + if (item.getDisplayName().equals("<< Back to world menu")) { + p.openInventory(ExplosionToggle.EXPLOSIONMENU); + click.play(p); + return; + } + World world = Bukkit.getWorld(title.substring((ExplosionsControl.STARTER + "eEditing ").length())); + ExplosionConfiguration configuration = new ExplosionConfiguration(world); + + switch (item.getType()) { + case FIRE_CHARGE -> { + configuration.setAllowFireball(ExplosionMode.fromIndex(configuration.getAllowFireball().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case CREEPER_HEAD -> { + configuration.setAllowCreeper(ExplosionMode.fromIndex(configuration.getAllowCreeper().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case TNT -> { + configuration.setAllowTnt(ExplosionMode.fromIndex(configuration.getAllowTnt().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case TNT_MINECART -> { + configuration.setAllowMinecart(ExplosionMode.fromIndex(configuration.getAllowMinecart().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case WITHER_SKELETON_SKULL -> { + configuration.setAllowWither(ExplosionMode.fromIndex(configuration.getAllowWither().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case END_CRYSTAL -> { + configuration.setAllowCrystal(ExplosionMode.fromIndex(configuration.getAllowCrystal().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + case RESPAWN_ANCHOR -> { + configuration.setAllowBlock(ExplosionMode.fromIndex(configuration.getAllowBlock().getIndex() + 1)); + configuration.save(); + ExplosionToggle.setup(); + ExplosionToggle.openToggleMenu(p,world); + edit.play(p); + } + } + } + } catch (Exception exception) {} + } +} diff --git a/src/main/java/me/improper/explosionscontrol/other/ServerSound.java b/src/main/java/me/improper/explosionscontrol/other/ServerSound.java index 41c51b0..bc7f2a3 100644 --- a/src/main/java/me/improper/explosionscontrol/other/ServerSound.java +++ b/src/main/java/me/improper/explosionscontrol/other/ServerSound.java @@ -14,6 +14,16 @@ public class ServerSound { private float volume; private float pitch; + /** + * Constructs a new sound, this aims to add more methods to + * the Bukkit APIs Sound class, as they don't have many + * methods to use. + * + * @param location Location + * @param sound Sound + * @param volume float + * @param pitch float + */ public ServerSound(Location location, Sound sound, float volume, float pitch) { this.location = location; this.sound = sound; @@ -22,14 +32,29 @@ public class ServerSound { } + /** + * Plays a sound to a player but at the store location + * + * @param player Player + */ public void play(Player player) { player.playSound(this.location,this.sound,this.volume,this.pitch); } + /** + * Plays a sound to a player but at the player's location + * + * @param player Player + */ public void playAt(Player player) { player.playSound(player.getLocation(),this.sound,this.volume,this.pitch); } + /** + * Plays the sound to all players within a distance, but at the stored location. + * + * @param distance double + */ public void playWithin(double distance) { for (Player p : Bukkit.getOnlinePlayers()) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { @@ -38,6 +63,11 @@ public class ServerSound { } } + /** + * Plays the sound to all players within a distance, but at the players' location. + * + * @param distance double + */ public void playWithinAt(double distance) { for (Player p : Bukkit.getOnlinePlayers()) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { @@ -46,14 +76,28 @@ public class ServerSound { } } + + /** + * Plays the sound to all players on the server, but at the stored location. + */ public void playAll() { for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch); } + /** + * Plays the sound to all players on the server, but at the players' location. + */ public void playAllAt() { for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); } + /** + * Repeats a sound to a player, but at the stored location. + * + * @param player Player + * @param times int + * @param tickDelay int + */ public void repeat(Player player, int times, int tickDelay) { new BukkitRunnable() { int i = 0; @@ -69,6 +113,13 @@ public class ServerSound { }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); } + /** + * Repeats a sound to a player, but at the player's location. + * + * @param player Player + * @param times int + * @param tickDelay int + */ public void repeatAt(Player player, int times, int tickDelay) { new BukkitRunnable() { int i = 0; @@ -84,6 +135,12 @@ public class ServerSound { }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); } + /** + * Repeats a sound to all players on the server, but at the stored location. + * + * @param times int + * @param tickDelay int + */ public void repeatAll(int times, int tickDelay) { new BukkitRunnable() { int i = 0; @@ -99,6 +156,12 @@ public class ServerSound { }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); } + /** + * Repeats a sound to all players on the server, but at the players' location. + * + * @param times int + * @param tickDelay int + */ public void repeatAllAt(int times, int tickDelay) { new BukkitRunnable() { int i = 0; @@ -114,6 +177,13 @@ public class ServerSound { }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); } + /** + * Repeats a sound to all players within a radius, but at the stored location. + * + * @param radius double + * @param times int + * @param tickDelay int + */ public void repeatAll(double radius,int times, int tickDelay) { new BukkitRunnable() { int i = 0; @@ -129,6 +199,13 @@ public class ServerSound { }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); } + /** + * Repeats a sound to all players within a radius, but at the players' location. + * + * @param distance double + * @param times int + * @param tickDelay int + */ public void repeatAllAt(double distance, int times, int tickDelay) { new BukkitRunnable() { int i = 0;