diff --git a/pom.xml b/pom.xml index 38d7737..e018c36 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.Shin_Ideal LobbyFlyPlugin - 1.0-SNAPSHOT + 2.0.0 8 diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/Fly.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyCommandExecutor.java similarity index 50% rename from src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/Fly.java rename to src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyCommandExecutor.java index be4a48a..eb2f2fa 100644 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/Fly.java +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyCommandExecutor.java @@ -1,19 +1,28 @@ package com.github.Shin_Ideal.LobbyFlyPlugin.CommandExecutors; +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class Fly implements CommandExecutor { +public class FlyCommandExecutor implements CommandExecutor { + + private final LobbyFlyPlugin Instance; + + public FlyCommandExecutor() { + Instance = LobbyFlyPlugin.getInstance(); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { + if (!(sender instanceof Player)) { return false; } Player player = (Player) sender; player.setAllowFlight(!player.getAllowFlight()); + player.sendMessage(Instance.getPluginMessagePrefix() + "Fly is " + (player.getAllowFlight() ? ChatColor.GREEN + "enable" : ChatColor.RED + "disable")); return true; } - } diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManage.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManageCommandExecutor.java similarity index 56% rename from src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManage.java rename to src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManageCommandExecutor.java index 8f44e64..a528776 100644 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManage.java +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/CommandExecutors/FlyManageCommandExecutor.java @@ -1,27 +1,31 @@ package com.github.Shin_Ideal.LobbyFlyPlugin.CommandExecutors; -import com.github.Shin_Ideal.LobbyFlyPlugin.ConfigManager; -import com.github.Shin_Ideal.LobbyFlyPlugin.ListenerManager; +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -public class FlyManage implements CommandExecutor { +public class FlyManageCommandExecutor implements CommandExecutor { + + private final LobbyFlyPlugin Instance; + + public FlyManageCommandExecutor() { + Instance = LobbyFlyPlugin.getInstance(); + } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(args.length==0){ + if (args.length == 0) { sendHelp(sender); return true; - }else { - switch (args[0]){ + } else { + switch (args[0]) { case "help": sendHelp(sender); break; case "reload": - reload(); - sender.sendMessage("reloaded!"); + reload(sender); break; default: @@ -32,14 +36,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - private void sendHelp(CommandSender sender){ + private void sendHelp(CommandSender sender) { sender.sendMessage("/flymanage "); sender.sendMessage("/flymanage "); } - private void reload() { - ConfigManager.reload(); - ListenerManager.reload(); + private void reload(CommandSender sender) { + Instance.reloadConfig(); + sender.sendMessage(Instance.getPluginMessagePrefix() + "Config Reloaded!"); } - } diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ConfigManager.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ConfigManager.java deleted file mode 100644 index ea957f7..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ConfigManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin; - -import org.bukkit.configuration.Configuration; - -public class ConfigManager { - - private static Configuration config; - - public static void Init(){ - LobbyFlyPlugin plugin = LobbyFlyPlugin.getPlugin(); - plugin.saveDefaultConfig(); - config=plugin.getConfig(); - } - - public static Configuration getConfig(){ - return config; - } - - public static void reload() { - LobbyFlyPlugin plugin = LobbyFlyPlugin.getPlugin(); - plugin.reloadConfig(); - config=plugin.getConfig(); - } - -} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ListenerManager.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ListenerManager.java deleted file mode 100644 index 6a00088..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/ListenerManager.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin; - -import com.github.Shin_Ideal.LobbyFlyPlugin.Listeners.*; -import org.bukkit.configuration.Configuration; -import org.bukkit.event.HandlerList; - -public class ListenerManager { - - public static void Init(){ - UpdateListener(); - } - - public static void Fina(){ - HandlerList.unregisterAll(); - } - - private static void UpdateListener(){ - LobbyFlyPlugin plugin = LobbyFlyPlugin.getPlugin(); - Configuration config = ConfigManager.getConfig(); - - HandlerList.unregisterAll(); - - if(config.getBoolean("join-fly.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Join_Fly_Listener(),plugin); - Join_Fly_Listener.setAdd_y_location(config.getDouble("join-fly.add-y-location")); - } - - if(config.getBoolean("disable-fall-damage.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Disable_Fall_Damage_Listener(),plugin); - } - - if(config.getBoolean("disable-all-damage.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Disable_All_Damage_Listener(),plugin); - } - - if(config.getBoolean("join-tp-spawn.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Join_Tp_Spawn_Listener(),plugin); - Join_Tp_Spawn_Listener.setXYZ( - config.getDouble("join-tp-spawn.add-x"), - config.getDouble("join-tp-spawn.add-y"), - config.getDouble("join-tp-spawn.add-z") - ); - } - - if(config.getBoolean("horizon-limit.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Horizon_Limit_Listener(),plugin); - Horizon_Limit_Listener.setDistance( - config.getDouble("horizon-limit.x-min-distance"), - config.getDouble("horizon-limit.x-max-distance"), - config.getDouble("horizon-limit.z-min-distance"), - config.getDouble("horizon-limit.z-max-distance") - ); - } - - if(config.getBoolean("back-from-void.enable")){ - plugin.getServer().getPluginManager().registerEvents(new Back_From_Void_Listener(),plugin); - Back_From_Void_Listener.setXYZ( - config.getDouble("join-tp-spawn.add-x"), - config.getDouble("join-tp-spawn.add-y"), - config.getDouble("join-tp-spawn.add-z") - ); - } - } - - public static void reload() { - UpdateListener(); - } - -} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/BackFromVoidListener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/BackFromVoidListener.java new file mode 100644 index 0000000..bdf3dff --- /dev/null +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/BackFromVoidListener.java @@ -0,0 +1,40 @@ +package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; + +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; + +public class BackFromVoidListener implements Listener { + + private final LobbyFlyPlugin Instance; + private final Configuration config; + + public BackFromVoidListener() { + Instance = LobbyFlyPlugin.getInstance(); + config = Instance.getConfig(); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (!config.getBoolean("back-from-void.enable")) { + return; + } + + if (!(event.getEntity() instanceof Player)) { + return; + } + if (!event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) { + return; + } + Player player = (Player) event.getEntity(); + player.teleport(player.getWorld().getSpawnLocation().add( + config.getDouble("join-tp-spawn.add-x") + , config.getDouble("join-tp-spawn.add-y") + , config.getDouble("join-tp-spawn.add-z") + )); + event.setCancelled(true); + } +} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Back_From_Void_Listener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Back_From_Void_Listener.java deleted file mode 100644 index 5a6c902..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Back_From_Void_Listener.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; - -public class Back_From_Void_Listener implements Listener { - - private static double x,y,z; - - public static void setXYZ(double addx,double addy,double addz) { - x = addx; - y = addy; - z = addz; - } - - @EventHandler - public void onDamage(EntityDamageEvent event){ - if(!(event.getEntity() instanceof Player)){ - return; - } - if(!event.getCause().equals(EntityDamageEvent.DamageCause.VOID)){ - return; - } - Player player = ((Player) event.getEntity()).getPlayer(); - - player.teleport(player.getWorld().getSpawnLocation().add(x,y,z)); - event.setCancelled(true); - } - -} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableAllDamageListener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableAllDamageListener.java new file mode 100644 index 0000000..1aa575a --- /dev/null +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableAllDamageListener.java @@ -0,0 +1,32 @@ +package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; + +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; + +public class DisableAllDamageListener implements Listener { + + private final LobbyFlyPlugin Instance; + private final Configuration config; + + public DisableAllDamageListener() { + Instance = LobbyFlyPlugin.getInstance(); + config = Instance.getConfig(); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (!config.getBoolean("disable-all-damage.enable")) { + return; + } + + if (!(event.getEntity() instanceof Player)) { + return; + } + + event.setCancelled(true); + } +} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableFallDamageListener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableFallDamageListener.java new file mode 100644 index 0000000..763dc6b --- /dev/null +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/DisableFallDamageListener.java @@ -0,0 +1,35 @@ +package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; + +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; + +public class DisableFallDamageListener implements Listener { + + private final LobbyFlyPlugin Instance; + private final Configuration config; + + public DisableFallDamageListener() { + Instance = LobbyFlyPlugin.getInstance(); + config = Instance.getConfig(); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (!config.getBoolean("disable-fall-damage.enable")) { + return; + } + + if (!(event.getEntity() instanceof Player)) { + return; + } + if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) { + return; + } + + event.setCancelled(true); + } +} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_All_Damage_Listener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_All_Damage_Listener.java deleted file mode 100644 index 70c7567..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_All_Damage_Listener.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; - -public class Disable_All_Damage_Listener implements Listener { - - @EventHandler - public void onDamage(EntityDamageEvent event){ - if(!(event.getEntity() instanceof Player)){ - return; - } - event.setCancelled(true); - } - -} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_Fall_Damage_Listener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_Fall_Damage_Listener.java deleted file mode 100644 index 4450100..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Disable_Fall_Damage_Listener.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; - -public class Disable_Fall_Damage_Listener implements Listener { - - @EventHandler - public void onDamage(EntityDamageEvent event){ - if(!(event.getEntity() instanceof Player)){ - return; - } - if(!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)){ - return; - } - event.setCancelled(true); - } - -} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/HorizonLimitListener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/HorizonLimitListener.java new file mode 100644 index 0000000..079ef03 --- /dev/null +++ b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/HorizonLimitListener.java @@ -0,0 +1,50 @@ +package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; + +import com.github.Shin_Ideal.LobbyFlyPlugin.LobbyFlyPlugin; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.util.Vector; + +public class HorizonLimitListener implements Listener { + + private final LobbyFlyPlugin Instance; + private final Configuration config; + + public HorizonLimitListener() { + Instance = LobbyFlyPlugin.getInstance(); + config = Instance.getConfig(); + } + + @EventHandler + public void onMove(PlayerMoveEvent event) { + if (!config.getBoolean("horizon-limit.enable")) { + return; + } + + Player player = event.getPlayer(); + Vector player_vector = player.getVelocity(); + double x = player.getLocation().getX(); + double z = player.getLocation().getZ(); + + double x_min_distance = config.getDouble("horizon-limit.x-min-distance"); + double x_max_distance = config.getDouble("horizon-limit.x-max-distance"); + double z_min_distance = config.getDouble("horizon-limit.z-min-distance"); + double z_max_distance = config.getDouble("horizon-limit.z-max-distance"); + + if (x < x_min_distance) { + player.setVelocity(player_vector.add(new Vector(1, 0, 0))); + } + if (x_max_distance < x) { + player.setVelocity(player_vector.add(new Vector(-1, 0, 0))); + } + if (z < z_min_distance) { + player.setVelocity(player_vector.add(new Vector(0, 0, 1))); + } + if (z_max_distance < z) { + player.setVelocity(player_vector.add(new Vector(0, 0, -1))); + } + } +} diff --git a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Horizon_Limit_Listener.java b/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Horizon_Limit_Listener.java deleted file mode 100644 index e03a68f..0000000 --- a/src/main/java/com/github/Shin_Ideal/LobbyFlyPlugin/Listeners/Horizon_Limit_Listener.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.Shin_Ideal.LobbyFlyPlugin.Listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.util.Vector; - -public class Horizon_Limit_Listener implements Listener { - - private static double x_min_distance; - private static double x_max_distance; - private static double z_min_distance; - private static double z_max_distance; - - public static void setDistance(double xmin,double xman,double zmin,double zmax){ - Horizon_Limit_Listener.x_min_distance = xmin; - Horizon_Limit_Listener.x_max_distance = xman; - Horizon_Limit_Listener.z_min_distance = zmin; - Horizon_Limit_Listener.z_max_distance = zmax; - } - - @EventHandler - public void onMove(PlayerMoveEvent event){ - Player player = event.getPlayer(); - - Vector player_vector = player.getVelocity(); - double x = player.getLocation().getX(); - double z = player.getLocation().getZ(); - - if(x