diff --git a/build.gradle b/build.gradle index a0b1109..a93cea1 100644 --- a/build.gradle +++ b/build.gradle @@ -45,3 +45,9 @@ processResources { expand props } } + +compileJava.options.encoding = 'UTF-8' + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} diff --git a/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class b/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class deleted file mode 100644 index ec52b28..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/ExplosionsControl.class and /dev/null 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 deleted file mode 100644 index 4736ca2..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/commands/Commands.class and /dev/null differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/commands/Tabs.class b/build/classes/java/main/me/improper/explosionscontrol/commands/Tabs.class deleted file mode 100644 index 6a09783..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/commands/Tabs.class and /dev/null 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 deleted file mode 100644 index 25fe29b..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/Config.class and /dev/null differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfigFile.class b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfigFile.class deleted file mode 100644 index ede6764..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfigFile.class and /dev/null differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfiguration.class b/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfiguration.class deleted file mode 100644 index 13d37bc..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionConfiguration.class and /dev/null 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 deleted file mode 100644 index 663b18a..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionMode.class and /dev/null 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 deleted file mode 100644 index 6f63cc2..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/data/ExplosionToggle.class and /dev/null 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 deleted file mode 100644 index 47f479e..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode$1.class and /dev/null 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 deleted file mode 100644 index b0b1fc5..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnExplode.class and /dev/null 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 deleted file mode 100644 index 50ed7c9..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory$1.class and /dev/null 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 deleted file mode 100644 index f1f9a1b..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/events/OnInventory.class and /dev/null differ diff --git a/build/classes/java/main/me/improper/explosionscontrol/other/Item.class b/build/classes/java/main/me/improper/explosionscontrol/other/Item.class deleted file mode 100644 index 29ef88d..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/Item.class and /dev/null 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 deleted file mode 100644 index f5ca352..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$1.class and /dev/null 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 deleted file mode 100644 index d250d2f..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$2.class and /dev/null 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 deleted file mode 100644 index e2794a1..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$3.class and /dev/null 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 deleted file mode 100644 index b7b2e60..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$4.class and /dev/null 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 deleted file mode 100644 index 204e7fb..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$5.class and /dev/null 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 deleted file mode 100644 index 6aec798..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound$6.class and /dev/null 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 deleted file mode 100644 index 42c8fcd..0000000 Binary files a/build/classes/java/main/me/improper/explosionscontrol/other/ServerSound.class and /dev/null differ diff --git a/build/libs/ExplosionsControl-3.0.jar b/build/libs/ExplosionsControl-3.0.jar index d3e97b6..17a5d64 100644 Binary files a/build/libs/ExplosionsControl-3.0.jar and b/build/libs/ExplosionsControl-3.0.jar differ diff --git a/build/resources/main/config.yml b/build/resources/main/config.yml deleted file mode 100644 index 57fcb63..0000000 --- a/build/resources/main/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -# -# -# This is ExplosionsControl by ImproperIssues -# -# Please note that all the explosions configurations have been moved to -# "plugins/ExplosionsControl/worldconfigurations" and are no longer -# configured through this config! -# -# -# -# If you do enjoy this plugin, please star it on github! -# Visit and star https://github.com/ItziSpyder/ExplosionsControl -# -# - -config: - plugin: - prefix: '§7[§eExplosions§6Control§7] §' \ No newline at end of file diff --git a/build/resources/main/plugin.yml b/build/resources/main/plugin.yml index 927657c..fc7d685 100644 --- a/build/resources/main/plugin.yml +++ b/build/resources/main/plugin.yml @@ -1,16 +1,7 @@ name: ExplosionsControl version: '3.0' -main: me.improper.explosionscontrol.ExplosionsControl +main: io.github.itzispyder.explosionscontrol.ExplosionsControl api-version: 1.17 authors: [ ImproperIssues ] description: Manager server explosions with just a few simple clicks! website: github.com/ItziSpyder -commands: - explosions: - description: Opens up the explosions toggle menu - usage: /explosions - permission: explosionscontrol.commands.explosions - loadworlds: - description: Loads in all the configuration files in case they didn't load - usage: /loadworlds - permission: explosionscontrol.commands.loadworlds \ No newline at end of file diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 84448c4..0a50b4b 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/io/github/itzispyder/explosionscontrol/ExplosionsControl.java b/src/main/java/io/github/itzispyder/explosionscontrol/ExplosionsControl.java new file mode 100644 index 0000000..9f604fc --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/ExplosionsControl.java @@ -0,0 +1,26 @@ +package io.github.itzispyder.explosionscontrol; + +import io.github.itzispyder.explosionscontrol.data.ExplosionConfig; +import io.github.itzispyder.explosionscontrol.utils.Text; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.logging.Logger; + +public final class ExplosionsControl extends JavaPlugin { + + public static final Logger logger = Bukkit.getLogger(); + public static final String starter = Text.color("&7[&6Ex&eC&7] &r"); + public static ExplosionsControl instance; + + @Override + public void onEnable() { + instance = this; + ExplosionConfig.updateAllWorlds(); + } + + @Override + public void onDisable() { + ExplosionConfig.updateAllWorlds(); + } +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/commands/CmdExHandler.java b/src/main/java/io/github/itzispyder/explosionscontrol/commands/CmdExHandler.java new file mode 100644 index 0000000..07cb41c --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/commands/CmdExHandler.java @@ -0,0 +1,14 @@ +package io.github.itzispyder.explosionscontrol.commands; + +import org.bukkit.command.Command; + +public record CmdExHandler(Exception ex, Command cmd) { + + public String getHelp() { + String help = "§cError: §7"; + if (ex instanceof IndexOutOfBoundsException) help += "Unknown or incomplete command."; + else if (ex instanceof NullPointerException) help += "Command contains a null value."; + else help += ex.getMessage(); + return help + "\n§cCaused by: §7" + ex.getClass().getSimpleName() + "\n" + "§cUsage: §7" + cmd.getUsage(); + } +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/commands/TabComplBuilder.java b/src/main/java/io/github/itzispyder/explosionscontrol/commands/TabComplBuilder.java new file mode 100644 index 0000000..710923b --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/commands/TabComplBuilder.java @@ -0,0 +1,60 @@ +package io.github.itzispyder.explosionscontrol.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.*; + +public class TabComplBuilder { + + private Map> entries = new HashMap<>(); + private final CommandSender sender; + private final Command command; + private final String alias; + private final String[] args; + + public TabComplBuilder(CommandSender sender, Command command, String alias, String[] args) { + this.sender = sender; + this.command = command; + this.alias = alias; + this.args = args; + } + + /** + * Adds to the tab completion + * @param atIndex should be a number above or equal to 1 + * @param entry string array + * @param condition condition + */ + public TabComplBuilder add(int atIndex, String[] entry, boolean condition) { + if (condition) add(atIndex,entry); + return this; + } + + /** + * Adds to the tab completion + * @param atIndex should be a number above or equal to 1 + * @param entry string array + */ + public TabComplBuilder add(int atIndex, String[] entry) { + atIndex = Math.max(1,atIndex); + entries.put(atIndex,Arrays.stream(entry).toList()); + return this; + } + + public TabComplBuilder add(int atIndex, List entry, boolean condition) { + if (condition) add(atIndex,entry); + return this; + } + + public TabComplBuilder add(int atIndex, List entry) { + entries.put(atIndex,entry); + return this; + } + + public List build() { + List list = new ArrayList<>(entries.get(args.length) != null ? entries.get(args.length) : new ArrayList<>()); + list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase())); + return list; + } +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/data/ExplosionConfig.java b/src/main/java/io/github/itzispyder/explosionscontrol/data/ExplosionConfig.java new file mode 100644 index 0000000..d53f2b4 --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/data/ExplosionConfig.java @@ -0,0 +1,164 @@ +package io.github.itzispyder.explosionscontrol.data; + +import com.google.gson.Gson; +import io.github.itzispyder.explosionscontrol.utils.FileValidationUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.io.*; + +import static io.github.itzispyder.explosionscontrol.ExplosionsControl.instance; +import static io.github.itzispyder.explosionscontrol.ExplosionsControl.logger; + +public class ExplosionConfig { + + private final String world; + private Mode minecartMode; + private Mode witherMode; + private Mode tntMode; + private Mode fireballMode; + private Mode creeperMode; + private Mode blockMode; + private Mode crystalMode; + + public ExplosionConfig(World world) { + this.world = world.getName(); + this.minecartMode = Mode.ENABLED; + this.witherMode = Mode.ENABLED; + this.tntMode = Mode.ENABLED; + this.fireballMode = Mode.ENABLED; + this.creeperMode = Mode.ENABLED; + this.crystalMode = Mode.ENABLED; + this.blockMode = Mode.ENABLED; + } + + public World getWorld() { + return Bukkit.getWorld(world); + } + + public Mode getMinecartMode() { + return minecartMode; + } + + public void setMinecartMode(Mode minecartMode) { + this.minecartMode = minecartMode; + } + + public Mode getWitherMode() { + return witherMode; + } + + public void setWitherMode(Mode witherMode) { + this.witherMode = witherMode; + } + + public Mode getTntMode() { + return tntMode; + } + + public void setTntMode(Mode tntMode) { + this.tntMode = tntMode; + } + + public Mode getFireballMode() { + return fireballMode; + } + + public void setFireballMode(Mode fireballMode) { + this.fireballMode = fireballMode; + } + + public Mode getCreeperMode() { + return creeperMode; + } + + public void setCreeperMode(Mode creeperMode) { + this.creeperMode = creeperMode; + } + + public Mode getBlockMode() { + return blockMode; + } + + public void setBlockMode(Mode blockMode) { + this.blockMode = blockMode; + } + + public Mode getCrystalMode() { + return crystalMode; + } + + public void setCrystalMode(Mode crystalMode) { + this.crystalMode = crystalMode; + } + + public File getFile() { + return getFileOf(getWorld()); + } + + public void save() { + save(this); + } + + public static File getFileOf(World world) { + return new File(instance.getDataFolder(), "worlds/" + world.getName() + ".json"); + } + + public static void updateAllWorlds() { + for (World world : Bukkit.getWorlds()) { + load(world).save(); + } + } + + private static T getOrDef(T val, T def) { + return val != null ? val : def; + } + + public static void save(ExplosionConfig config) { + File file = config.getFile(); + if (FileValidationUtils.validate(file)) { + try { + Gson gson = new Gson(); + String json = gson.toJson(config); + FileWriter fw = new FileWriter(file); + BufferedWriter bw = new BufferedWriter(fw); + + bw.write(json); + bw.close(); + } + catch (Exception ex) { + logger.warning("An error occurred while saving config for \"" + config.world + "\""); + ex.printStackTrace(); + } + } + } + + public static ExplosionConfig load(World world) { + return load(getFileOf(world)); + } + + public static ExplosionConfig load(File file) { + ExplosionConfig defaultConfig = new ExplosionConfig(Bukkit.getWorlds().get(0)); + + if (FileValidationUtils.validate(file)) { + try { + FileReader fr = new FileReader(file); + BufferedReader br = new BufferedReader(fr); + Gson gson = new Gson(); + String json = br.readLine(); + + ExplosionConfig config = json == null ? defaultConfig : gson.fromJson(json, ExplosionConfig.class); + + br.close(); + config.save(); + return config; + } + catch (Exception ex) { + logger.warning("An error occurred while loading config for \"" + file.getPath() + "\""); + ex.printStackTrace(); + } + } + + return defaultConfig; + } +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/data/Mode.java b/src/main/java/io/github/itzispyder/explosionscontrol/data/Mode.java new file mode 100644 index 0000000..d518482 --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/data/Mode.java @@ -0,0 +1,10 @@ +package io.github.itzispyder.explosionscontrol.data; + +public enum Mode { + + ENABLED, + DISABLED, + NONE, + DYNAMIC + +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/utils/FileValidationUtils.java b/src/main/java/io/github/itzispyder/explosionscontrol/utils/FileValidationUtils.java new file mode 100644 index 0000000..410ee8f --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/utils/FileValidationUtils.java @@ -0,0 +1,21 @@ +package io.github.itzispyder.explosionscontrol.utils; + +import java.io.File; + +public final class FileValidationUtils { + + public static boolean validate(File file) { + try { + if (!file.getParentFile().exists()) + if (!file.getParentFile().mkdirs()) + return false; + if (!file.exists()) + if (!file.createNewFile()) + return false; + return true; + } + catch (Exception ex) { + return false; + } + } +} diff --git a/src/main/java/me/improper/explosionscontrol/other/ServerSound.java b/src/main/java/io/github/itzispyder/explosionscontrol/utils/SoundPlayer.java similarity index 86% rename from src/main/java/me/improper/explosionscontrol/other/ServerSound.java rename to src/main/java/io/github/itzispyder/explosionscontrol/utils/SoundPlayer.java index bc7f2a3..a461eb7 100644 --- a/src/main/java/me/improper/explosionscontrol/other/ServerSound.java +++ b/src/main/java/io/github/itzispyder/explosionscontrol/utils/SoundPlayer.java @@ -1,255 +1,256 @@ -package me.improper.explosionscontrol.other; - -import me.improper.explosionscontrol.ExplosionsControl; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -public class ServerSound { - - private Location location; - private Sound sound; - 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; - this.pitch = pitch; - this.volume = volume; - } - - - /** - * 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) { - p.playSound(this.location,this.sound,this.volume,this.pitch); - } - } - } - - /** - * 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) { - p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); - } - } - } - - - /** - * 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; - @Override - public void run() { - if (i < times) { - play(player); - i ++; - } else { - this.cancel(); - } - } - }.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; - @Override - public void run() { - if (i < times) { - playAt(player); - i ++; - } else { - this.cancel(); - } - } - }.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; - @Override - public void run() { - if (i < times) { - playAll(); - i ++; - } else { - this.cancel(); - } - } - }.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; - @Override - public void run() { - if (i < times) { - playAllAt(); - i ++; - } else { - this.cancel(); - } - } - }.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; - @Override - public void run() { - if (i < times) { - playWithin(radius); - i ++; - } else { - this.cancel(); - } - } - }.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; - @Override - public void run() { - if (i < times) { - playWithinAt(distance); - i ++; - } else { - this.cancel(); - } - } - }.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay); - } - - public Sound getSound() { - return sound; - } - - public float getPitch() { - return pitch; - } - - public float getVolume() { - return volume; - } - - public Location getLocation() { - return location; - } - - public void setPitch(float pitch) { - this.pitch = pitch; - } - - public void setVolume(float volume) { - this.volume = volume; - } - - public void setSound(Sound sound) { - this.sound = sound; - } - - public void setLocation(Location location) { - this.location = location; - } -} +package io.github.itzispyder.explosionscontrol.utils; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import static io.github.itzispyder.explosionscontrol.ExplosionsControl.instance; + +public class SoundPlayer { + + private Location location; + private Sound sound; + 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 SoundPlayer(Location location, Sound sound, float volume, float pitch) { + this.location = location; + this.sound = sound; + this.pitch = pitch; + this.volume = volume; + } + + + /** + * 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().distance(this.location) < distance) { + p.playSound(this.location,this.sound,this.volume,this.pitch); + } + } + } + + /** + * 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().distance(this.location) < distance) { + p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); + } + } + } + + + /** + * 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; + @Override + public void run() { + if (i < times) { + play(player); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,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; + @Override + public void run() { + if (i < times) { + playAt(player); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,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; + @Override + public void run() { + if (i < times) { + playAll(); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,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; + @Override + public void run() { + if (i < times) { + playAllAt(); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,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; + @Override + public void run() { + if (i < times) { + playWithin(radius); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,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; + @Override + public void run() { + if (i < times) { + playWithinAt(distance); + i ++; + } else { + this.cancel(); + } + } + }.runTaskTimer(instance,0,tickDelay); + } + + public Sound getSound() { + return sound; + } + + public float getPitch() { + return pitch; + } + + public float getVolume() { + return volume; + } + + public Location getLocation() { + return location; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + public void setVolume(float volume) { + this.volume = volume; + } + + public void setSound(Sound sound) { + this.sound = sound; + } + + public void setLocation(Location location) { + this.location = location; + } +} diff --git a/src/main/java/io/github/itzispyder/explosionscontrol/utils/Text.java b/src/main/java/io/github/itzispyder/explosionscontrol/utils/Text.java new file mode 100644 index 0000000..9144b0e --- /dev/null +++ b/src/main/java/io/github/itzispyder/explosionscontrol/utils/Text.java @@ -0,0 +1,96 @@ +package io.github.itzispyder.explosionscontrol.utils; + +import io.github.itzispyder.explosionscontrol.ExplosionsControl; + +public class Text { + + public static String of(String s) { + return s; + } + + public static String ofAll(String s) { + return builder(s).prefix().color().build(); + } + + /** + * Replaces all & with § to color the text + * @param s string + * @return result + */ + public static String color(String s) { + return s.replaceAll("&","§"); + } + + public static String asPath(String s) { + return s.toLowerCase() + .replaceAll(" ","_") + .replaceAll("[^.a-b0-9_-]","") + .trim(); + } + + public static String asDirectory(String s) { + return s.toLowerCase() + .replaceAll(" ","_") + .replaceAll("[^./a-b0-9_-]","") + .trim(); + } + + public static String prefixed(String s) { + return ExplosionsControl.starter + s; + } + + public static TextBuilder builder(String s) { + return new TextBuilder(s); + } + + public static TextBuilder builder() { + return builder(""); + } + + public static String removeColors(String msg) { + String s = msg; + while (s.length() >= 2 && s.contains("§")) { + int index = s.indexOf("§"); + s = s.replaceAll(s.substring(index, index + 2), ""); + } + return s; + } + + public static class TextBuilder { + + private String s; + + public TextBuilder(String s) { + this.s = s; + } + + public TextBuilder message(String s) { + this.s = s; + return this; + } + + public TextBuilder color() { + s = Text.color(s); + return this; + } + + public TextBuilder prefix() { + s = Text.prefixed(s); + return this; + } + + public TextBuilder asPath() { + s = Text.asPath(s); + return this; + } + + public TextBuilder asDirectory() { + s = Text.asDirectory(s); + return this; + } + + public String build() { + return s; + } + } +} diff --git a/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java b/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java deleted file mode 100644 index 43f95d2..0000000 --- a/src/main/java/me/improper/explosionscontrol/ExplosionsControl.java +++ /dev/null @@ -1,51 +0,0 @@ -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; - - @Override - public void onEnable() { - // Plugin startup logic - STARTER = Config.getPluginPrefix(); - Bukkit.broadcastMessage(STARTER + "aExplosionsControls has loaded!"); - ExplosionConfigFile.setup(); - ExplosionToggle.setup(); - - // Files - getConfig().options().copyDefaults(); - saveDefaultConfig(); - - // Events - Bukkit.getPluginManager().registerEvents(new OnExplode(),this); - Bukkit.getPluginManager().registerEvents(new OnInventory(),this); - - // Commands - getCommand("explosions").setExecutor(new Commands()); - getCommand("explosions").setTabCompleter(new Tabs()); - getCommand("loadworlds").setExecutor(new Commands()); - getCommand("loadworlds").setTabCompleter(new Tabs()); - } - - @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() { - return Bukkit.getPluginManager().getPlugin("ExplosionsControl"); - } -} diff --git a/src/main/java/me/improper/explosionscontrol/commands/Commands.java b/src/main/java/me/improper/explosionscontrol/commands/Commands.java deleted file mode 100644 index 4e1b400..0000000 --- a/src/main/java/me/improper/explosionscontrol/commands/Commands.java +++ /dev/null @@ -1,43 +0,0 @@ -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; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - String commandName = command.getName().toLowerCase().trim(); - - try { - switch (commandName) { - case "explosions" -> { - ((Player) sender).openInventory(ExplosionToggle.EXPLOSIONMENU); - return true; - } - 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 = 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(); - sender.sendMessage(message); - return true; - } - - return false; - } -} diff --git a/src/main/java/me/improper/explosionscontrol/commands/Tabs.java b/src/main/java/me/improper/explosionscontrol/commands/Tabs.java deleted file mode 100644 index c468bc8..0000000 --- a/src/main/java/me/improper/explosionscontrol/commands/Tabs.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.improper.explosionscontrol.commands; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; - -import java.util.ArrayList; -import java.util.List; - -public class Tabs implements TabCompleter { - @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - List list = new ArrayList<>(); - String commandName = command.getName().toLowerCase().trim(); - - switch (commandName) { - case "explosions","loadworlds" -> { - break; - } - } - - list.removeIf(i -> !i.toLowerCase().contains(args[args.length - 1].toLowerCase())); - return list; - } -} diff --git a/src/main/java/me/improper/explosionscontrol/data/Config.java b/src/main/java/me/improper/explosionscontrol/data/Config.java deleted file mode 100644 index 2824678..0000000 --- a/src/main/java/me/improper/explosionscontrol/data/Config.java +++ /dev/null @@ -1,19 +0,0 @@ -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/ExplosionConfigFile.java b/src/main/java/me/improper/explosionscontrol/data/ExplosionConfigFile.java deleted file mode 100644 index e875163..0000000 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionConfigFile.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.improper.explosionscontrol.data; - -import org.bukkit.Bukkit; -import org.bukkit.World; - -public class ExplosionConfigFile { - - /** - * Creates a configuration for each existing world. - * These are saved to "plugins/ExplosionsControl/worldconfigurations". - */ - public static void setup() { - for (World world : Bukkit.getWorlds()) { - ExplosionConfiguration configuration = new ExplosionConfiguration(world); - configuration.save(); - } - } -} diff --git a/src/main/java/me/improper/explosionscontrol/data/ExplosionConfiguration.java b/src/main/java/me/improper/explosionscontrol/data/ExplosionConfiguration.java deleted file mode 100644 index 69d6996..0000000 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionConfiguration.java +++ /dev/null @@ -1,139 +0,0 @@ -package me.improper.explosionscontrol.data; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.Serializable; - -public class ExplosionConfiguration implements Serializable { - - private String world; - private ExplosionMode allowTnt, allowCrystal, allowFireball, allowCreeper, allowMinecart, allowWither, allowBlock; - - /** - * Constructs a world configuration for explosions. - * Note that if the data file is null or does not exist it will create - * a new instance of this class instead of loading the data. - * - * @param world World - */ - public ExplosionConfiguration(World world) { - try { - File file = new File("plugins/ExplosionsControl/worldconfigurations/" + world.getName() + ".yml"); - if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); - if (!file.exists()) { - file.createNewFile(); - this.world = world.getName(); - this.allowTnt = ExplosionMode.ENABLED; - this.allowCrystal = ExplosionMode.ENABLED; - this.allowFireball = ExplosionMode.ENABLED; - this.allowCreeper = ExplosionMode.ENABLED; - this.allowMinecart = ExplosionMode.ENABLED; - this.allowWither = ExplosionMode.ENABLED; - this.allowBlock = ExplosionMode.ENABLED; - return; - } - FileConfiguration data = YamlConfiguration.loadConfiguration(file); - this.world = data.getString("worldconfig.world"); - this.allowTnt = ExplosionMode.valueOf(data.getString("worldconfig.allowTnt").toUpperCase()); - this.allowCrystal = ExplosionMode.valueOf(data.getString("worldconfig.allowCrystal").toUpperCase()); - this.allowFireball = ExplosionMode.valueOf(data.getString("worldconfig.allowFireball").toUpperCase()); - this.allowCreeper = ExplosionMode.valueOf(data.getString("worldconfig.allowCreeper").toUpperCase()); - this.allowMinecart = ExplosionMode.valueOf(data.getString("worldconfig.allowMinecart").toUpperCase()); - this.allowWither = ExplosionMode.valueOf(data.getString("worldconfig.allowWither").toUpperCase()); - this.allowBlock = ExplosionMode.valueOf(data.getString("worldconfig.allowBlock").toUpperCase()); - } catch (Exception exception) { - Bukkit.getLogger().warning(exception.toString()); - } - } - - /** - * Save the current configuration to a file config. - */ - public void save() { - try { - File file = new File("plugins/ExplosionsControl/worldconfigurations/" + world + ".yml"); - if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); - if (!file.exists()) file.createNewFile(); - FileConfiguration data = YamlConfiguration.loadConfiguration(file); - data.set("worldconfig.world",world); - data.set("worldconfig.allowBlock",allowBlock.name()); - data.set("worldconfig.allowCreeper",allowCreeper.name()); - data.set("worldconfig.allowCrystal",allowCrystal.name()); - data.set("worldconfig.allowFireball",allowFireball.name()); - data.set("worldconfig.allowMinecart",allowMinecart.name()); - data.set("worldconfig.allowTnt",allowTnt.name()); - data.set("worldconfig.allowWither",allowWither.name()); - data.save(file); - } catch (Exception exception) { - Bukkit.getLogger().warning(exception.toString()); - } - } - - public void setWorld(String world) { - this.world = world; - } - - public void setAllowBlock(ExplosionMode allowBlock) { - this.allowBlock = allowBlock; - } - - public void setAllowCreeper(ExplosionMode allowCreeper) { - this.allowCreeper = allowCreeper; - } - - public void setAllowCrystal(ExplosionMode allowCrystal) { - this.allowCrystal = allowCrystal; - } - - public void setAllowFireball(ExplosionMode allowFireball) { - this.allowFireball = allowFireball; - } - - public void setAllowMinecart(ExplosionMode allowMinecart) { - this.allowMinecart = allowMinecart; - } - - public void setAllowTnt(ExplosionMode allowTnt) { - this.allowTnt = allowTnt; - } - - public void setAllowWither(ExplosionMode allowWither) { - this.allowWither = allowWither; - } - - public String getWorld() { - return world; - } - - public ExplosionMode getAllowBlock() { - return allowBlock; - } - - public ExplosionMode getAllowCreeper() { - return allowCreeper; - } - - public ExplosionMode getAllowCrystal() { - return allowCrystal; - } - - public ExplosionMode getAllowFireball() { - return allowFireball; - } - - public ExplosionMode getAllowMinecart() { - return allowMinecart; - } - - public ExplosionMode getAllowTnt() { - return allowTnt; - } - - public ExplosionMode getAllowWither() { - return allowWither; - } -} diff --git a/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java b/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java deleted file mode 100644 index 7513226..0000000 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionMode.java +++ /dev/null @@ -1,44 +0,0 @@ -package me.improper.explosionscontrol.data; - -import java.io.Serializable; - -public enum ExplosionMode implements Serializable { - - ENABLED(0), - DISABLED(1), - 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 deleted file mode 100644 index 10db6e7..0000000 --- a/src/main/java/me/improper/explosionscontrol/data/ExplosionToggle.java +++ /dev/null @@ -1,110 +0,0 @@ -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; - - /** - * This will prepare the ExplosionsControl main toggle menu. - * Server staff members will be able to edit explosion configurations - * through this menu! - */ - public static void setup() { - 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 - }); - - 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; - } - - /** - * Open the toggle configuration menu for a player! - * - * @param player Player - * @param world World - */ - 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 deleted file mode 100644 index 8b756b6..0000000 --- a/src/main/java/me/improper/explosionscontrol/events/OnExplode.java +++ /dev/null @@ -1,216 +0,0 @@ -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.*; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.FallingBlock; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.util.Vector; - -public class OnExplode implements Listener { - - @EventHandler - public static void EntityExplodeEvent(EntityExplodeEvent e) { - Entity entity = e.getEntity(); - Location loc = e.getLocation(); - World world = loc.getWorld(); - ExplosionConfiguration configuration = new ExplosionConfiguration(world); - - switch (entity.getType()) { - case PRIMED_TNT -> { - switch (configuration.getAllowTnt()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - case FIREBALL,DRAGON_FIREBALL,SMALL_FIREBALL -> { - switch (configuration.getAllowFireball()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - case CREEPER -> { - switch (configuration.getAllowCreeper()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - case ENDER_CRYSTAL -> { - switch (configuration.getAllowCrystal()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - case MINECART_TNT -> { - switch (configuration.getAllowMinecart()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - case WITHER_SKULL -> { - switch (configuration.getAllowWither()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block block : e.blockList()) launchBlock(block, loc); - } - } - } - } - } - - @EventHandler - public static void BlockExplodeEvent(BlockExplodeEvent e) { - Block block = e.getBlock(); - Location loc = block.getLocation(); - World world = loc.getWorld(); - ExplosionConfiguration configuration = new ExplosionConfiguration(world); - - switch (configuration.getAllowBlock()) { - case DISABLED -> { - e.setCancelled(true); - fakeExplode(loc); - } - case NONE -> { - e.setCancelled(true); - } - case DYNAMIC -> { - for (Block b : e.blockList()) launchBlock(b, loc); - } - } - } - - @EventHandler - public static void EntityDamageByEntityEvent(EntityDamageByEntityEvent e) { - try { - Entity damager = e.getDamager(); - Location loc = e.getDamager().getLocation(); - World world = loc.getWorld(); - ExplosionConfiguration configuration = new ExplosionConfiguration(world); - - switch (damager.getType()) { - case PRIMED_TNT -> { - if (configuration.getAllowTnt().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - case FIREBALL,DRAGON_FIREBALL,SMALL_FIREBALL -> { - if (configuration.getAllowFireball().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - case CREEPER -> { - if (configuration.getAllowCreeper().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - case ENDER_CRYSTAL -> { - if (configuration.getAllowCrystal().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - case MINECART_TNT -> { - if (configuration.getAllowMinecart().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - case WITHER_SKULL -> { - if (configuration.getAllowWither().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - } - } catch (Exception exception) {} - } - - @EventHandler - public static void EntityDamageEvent(EntityDamageEvent e) { - try { - Entity entity = e.getEntity(); - Location loc = entity.getLocation(); - World world = loc.getWorld(); - ExplosionConfiguration configuration = new ExplosionConfiguration(world); - EntityDamageEvent.DamageCause cause = e.getCause(); - - switch (cause) { - case BLOCK_EXPLOSION -> { - if (configuration.getAllowBlock().equals(ExplosionMode.NONE)) e.setCancelled(true); - } - } - } catch (Exception exception) {} - } - - /** - * Attempts to launch a block as a falling block according to its original location - * This feature is in beta, expect many bugs! - * - * @param block Block - * @param origin Location - */ - public static void launchBlock(Block block, Location origin) { - Location loc = block.getLocation(); - Vector vector = origin - .toVector() - .subtract(loc.toVector()) - .normalize() - .add(new Vector(0,1,0)) - .multiply(new Vector(-0.7,0.7,-0.7)); - FallingBlock fb = origin.getWorld().spawnFallingBlock(block.getLocation(),block.getBlockData()); - 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 deleted file mode 100644 index 8d5aafd..0000000 --- a/src/main/java/me/improper/explosionscontrol/events/OnInventory.java +++ /dev/null @@ -1,118 +0,0 @@ -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/Item.java b/src/main/java/me/improper/explosionscontrol/other/Item.java deleted file mode 100644 index 79f7998..0000000 --- a/src/main/java/me/improper/explosionscontrol/other/Item.java +++ /dev/null @@ -1,110 +0,0 @@ -package me.improper.explosionscontrol.other; - -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.List; -import java.util.Set; - -public class Item extends ItemStack { - - private ItemMeta meta = super.getItemMeta(); - - /** - * This creates in instance of this class, which is an extension - * or the ItemStack class, aiming to simplify the process of - * modifying an item's item meta. - * - * @param itemStack ItemStack - */ - public Item(ItemStack itemStack) { - super(itemStack); - } - - /** - * Set the display name of an item. - * - * @param displayName String - */ - public void setDisplayName(String displayName) { - meta.setDisplayName(displayName); - super.setItemMeta(meta); - } - - /** - * Set the lore of an item. - * - * @param lore List - */ - public void setLore(List lore) { - meta.setLore(lore); - super.setItemMeta(meta); - } - - /** - * Adds item flags to an item. - * - * @param flag ItemFlag... - */ - public void addItemFlags(ItemFlag... flag) { - meta.addItemFlags(flag); - super.setItemMeta(meta); - } - - /** - * Sets the unbreakable state of an item. - * - * @param unbreakable boolean - */ - public void setUnbreakable(boolean unbreakable) { - meta.setUnbreakable(unbreakable); - super.setItemMeta(meta); - } - - /** - * Sets the custom model data of an item. - * - * @param customModelData String - */ - public void setCustomModelData(int customModelData) { - meta.setCustomModelData(customModelData); - super.setItemMeta(meta); - } - - /** - * Returns the display name of the item. - * - * @return A string as the display name. - */ - public String getDisplayName() { - return meta.getDisplayName(); - } - - /** - * Returns the lore of the item. - * - * @return A string array as the lore. - */ - public List getLore() { - return meta.getLore(); - } - - /** - * Returns an array of the items flags of the item. - * - * @return An array of the item flags. - */ - public Set getItemFlags() { - return meta.getItemFlags(); - } - - /** - * Returns the custom model data of the item. - * - * @return The custom model data of the item. - */ - public int getCustomModelData() { - return meta.getCustomModelData(); - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index 57fcb63..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -# -# -# This is ExplosionsControl by ImproperIssues -# -# Please note that all the explosions configurations have been moved to -# "plugins/ExplosionsControl/worldconfigurations" and are no longer -# configured through this config! -# -# -# -# If you do enjoy this plugin, please star it on github! -# Visit and star https://github.com/ItziSpyder/ExplosionsControl -# -# - -config: - plugin: - prefix: '§7[§eExplosions§6Control§7] §' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 020b4d6..cef9f88 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,16 +1,7 @@ name: ExplosionsControl version: '${version}' -main: me.improper.explosionscontrol.ExplosionsControl +main: io.github.itzispyder.explosionscontrol.ExplosionsControl api-version: 1.17 authors: [ ImproperIssues ] description: Manager server explosions with just a few simple clicks! website: github.com/ItziSpyder -commands: - explosions: - description: Opens up the explosions toggle menu - usage: /explosions - permission: explosionscontrol.commands.explosions - loadworlds: - description: Loads in all the configuration files in case they didn't load - usage: /loadworlds - permission: explosionscontrol.commands.loadworlds \ No newline at end of file