diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index f250e73..9effc35 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -1,9 +1,7 @@ package de.steamwar.lobby; import de.steamwar.lobby.commands.FlyCommand; -import de.steamwar.lobby.commands.ShieldCommand; import de.steamwar.lobby.listener.*; -import de.steamwar.lobby.utils.Config; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -16,19 +14,16 @@ public class LobbySystem extends JavaPlugin { public void onEnable() { instance = this; - if(Config.SpawnY == 0) - shutdown(null); - init(); getCommand("fly").setExecutor(new FlyCommand()); - getCommand("schild").setExecutor(new ShieldCommand()); } public void init() { PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerMoveListener(), instance); - pm.registerEvents(new PlayerJoinListener(), instance); + pm.registerEvents(new PlayerConnectionListener(), instance); pm.registerEvents(new PlayerInventoryListener(), instance); pm.registerEvents(new PlayerWorldInteractionListener(), instance); pm.registerEvents(new DoubleJumpListener(), instance); @@ -37,11 +32,6 @@ public class LobbySystem extends JavaPlugin { pm.registerEvents(new EnderPearlListener(), instance); pm.registerEvents(new ShieldListener(), instance); } - - public void shutdown(final String reason) { - Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(reason)); - Bukkit.shutdown(); - } public static LobbySystem getInstance() { diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index 4224a37..d9e8c39 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -20,10 +20,12 @@ public class FlyCommand implements CommandExecutor { SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); - if(userGroup != UserGroup.Developer && - userGroup != UserGroup.Moderator && - userGroup != UserGroup.Admin && - userGroup != UserGroup.Youtuber) { + if(userGroup != UserGroup.Admin && + userGroup != UserGroup.Moderator && + userGroup != UserGroup.Developer && + userGroup != UserGroup.Supporter && + userGroup != UserGroup.Builder && + userGroup != UserGroup.Youtuber) { player.sendMessage("§cDu verfügst nicht über die benötigten Rechte!"); return false; } diff --git a/src/de/steamwar/lobby/commands/ShieldCommand.java b/src/de/steamwar/lobby/commands/ShieldCommand.java deleted file mode 100644 index 4ebbfe2..0000000 --- a/src/de/steamwar/lobby/commands/ShieldCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.steamwar.lobby.commands; - -import de.steamwar.lobby.inventorys.LobbyInventory; -import de.steamwar.lobby.utils.LobbyPlayer; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserGroup; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class ShieldCommand implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - - Player player = (Player) sender; - SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); - UserGroup userGroup = steamwarUser.getUserGroup(); - - if(userGroup != UserGroup.Developer && - userGroup != UserGroup.Moderator && - userGroup != UserGroup.Admin && - userGroup != UserGroup.Youtuber) { - player.sendMessage("§cDu verfügst nicht über die benötigten Rechte!"); - return false; - } - - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - boolean newShieldState = !lobbyPlayer.isShield(); - - lobbyPlayer.setShield(newShieldState); - LobbyInventory.givePlayerLobbyItems(player); - player.sendMessage("§7Dein Schild ist jetzt " + (newShieldState ? "§aan" : "§caus") + "§7."); - return false; - } -} diff --git a/src/de/steamwar/lobby/inventorys/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java similarity index 77% rename from src/de/steamwar/lobby/inventorys/LobbyInventory.java rename to src/de/steamwar/lobby/inventories/LobbyInventory.java index 18f8a6b..ce86f9e 100644 --- a/src/de/steamwar/lobby/inventorys/LobbyInventory.java +++ b/src/de/steamwar/lobby/inventories/LobbyInventory.java @@ -1,4 +1,4 @@ -package de.steamwar.lobby.inventorys; +package de.steamwar.lobby.inventories; import de.steamwar.lobby.utils.ItemBuilder; import de.steamwar.lobby.utils.LobbyPlayer; @@ -9,11 +9,13 @@ import org.bukkit.entity.Player; public class LobbyInventory { + private LobbyInventory() {} + public static Material PLAYER_HIDER = Material.BLAZE_ROD; - public static Material PARTIKEL = Material.NAME_TAG; + public static Material PARTICLE = Material.NAME_TAG; public static Material ENDERPEARL_USED = Material.FIREWORK_CHARGE; public static Material ENDERPEARL_READY = Material.ENDER_PEARL; - public static Material SCHILD = Material.SHIELD; + public static Material SHIELD = Material.SHIELD; public static void givePlayerLobbyItems(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); @@ -31,7 +33,7 @@ public class LobbyInventory { .removeAllAtributs() .build()); - player.getInventory().setItem(6, new ItemBuilder(PARTIKEL) + player.getInventory().setItem(6, new ItemBuilder(PARTICLE) .setDisplayName("§6Partikel") .setUnbreakable(true) .removeAllAtributs() @@ -39,13 +41,15 @@ public class LobbyInventory { UserGroup userGroup = SteamwarUser.get(player.getUniqueId()).getUserGroup(); - if(userGroup != UserGroup.Developer && + if(userGroup != UserGroup.Admin && userGroup != UserGroup.Moderator && - userGroup != UserGroup.Admin && + userGroup != UserGroup.Developer && + userGroup != UserGroup.Supporter && + userGroup != UserGroup.Builder && userGroup != UserGroup.Youtuber) { return; } - player.getInventory().setItem(8, new ItemBuilder(SCHILD) + player.getInventory().setItem(8, new ItemBuilder(SHIELD) .setDisplayName("§bSchild §8| " + (lobbyPlayer.isShield() ? "§aan" : "§caus")) .setUnbreakable(true) .removeAllAtributs() diff --git a/src/de/steamwar/lobby/inventorys/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java similarity index 96% rename from src/de/steamwar/lobby/inventorys/ParticleInventory.java rename to src/de/steamwar/lobby/inventories/ParticleInventory.java index c3d0c40..40dba79 100644 --- a/src/de/steamwar/lobby/inventorys/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -1,4 +1,4 @@ -package de.steamwar.lobby.inventorys; +package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -12,9 +12,10 @@ import java.util.List; public class ParticleInventory { + private ParticleInventory() {} + public static void openParticleInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - if(lobbyPlayer == null) return; SWInventory swInventory = new SWInventory(player, 9 * 1, "§6Partikel"); diff --git a/src/de/steamwar/lobby/listener/EnderPearlListener.java b/src/de/steamwar/lobby/listener/EnderPearlListener.java index dab2164..d1be829 100644 --- a/src/de/steamwar/lobby/listener/EnderPearlListener.java +++ b/src/de/steamwar/lobby/listener/EnderPearlListener.java @@ -1,7 +1,7 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.LobbySystem; -import de.steamwar.lobby.inventorys.LobbyInventory; +import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Bukkit; import org.bukkit.Sound; @@ -10,11 +10,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleExitEvent; -import org.bukkit.util.Vector; public class EnderPearlListener implements Listener { diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index c1147a3..af2a98b 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -1,7 +1,7 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.inventorys.LobbyInventory; -import de.steamwar.lobby.inventorys.ParticleInventory; +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.inventories.ParticleInventory; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -15,7 +15,7 @@ public class ParticleListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if(event.getMaterial() != LobbyInventory.PARTIKEL) + if(event.getMaterial() != LobbyInventory.PARTICLE) return; ParticleInventory.openParticleInventory(player); @@ -25,7 +25,7 @@ public class ParticleListener implements Listener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - if(lobbyPlayer == null || lobbyPlayer.getParticle() == null) return; + if(lobbyPlayer.getParticle() == null) return; player.getWorld().playEffect(player.getLocation().add(0.0D, 0.2D, 0.0D), lobbyPlayer.getParticle(), 5); } diff --git a/src/de/steamwar/lobby/listener/PlayerJoinListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java similarity index 64% rename from src/de/steamwar/lobby/listener/PlayerJoinListener.java rename to src/de/steamwar/lobby/listener/PlayerConnectionListener.java index 77b1468..889e9f8 100644 --- a/src/de/steamwar/lobby/listener/PlayerJoinListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -1,6 +1,6 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.inventorys.LobbyInventory; +import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.utils.Config; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Bukkit; @@ -10,15 +10,16 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; -public class PlayerJoinListener implements Listener { +public class PlayerConnectionListener implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); Player player = event.getPlayer(); - if(LobbyPlayer.getLobbyPlayer(player.getUniqueId()) == null) - new LobbyPlayer(player.getUniqueId()); + LobbyPlayer.getLobbyPlayer(player.getUniqueId()); //initialisiert einen neuen LP falls nicht vorhanden player.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ)); LobbyInventory.givePlayerLobbyItems(player); @@ -27,5 +28,10 @@ public class PlayerJoinListener implements Listener { player.setFoodLevel(20); } + @EventHandler + public void handlePlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + } + } diff --git a/src/de/steamwar/lobby/listener/PlayerHiderListener.java b/src/de/steamwar/lobby/listener/PlayerHiderListener.java index 397161b..599dc0b 100644 --- a/src/de/steamwar/lobby/listener/PlayerHiderListener.java +++ b/src/de/steamwar/lobby/listener/PlayerHiderListener.java @@ -1,6 +1,6 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.inventorys.LobbyInventory; +import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.utils.LobbyPlayer; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; diff --git a/src/de/steamwar/lobby/listener/ShieldListener.java b/src/de/steamwar/lobby/listener/ShieldListener.java index 742769f..7952d5e 100644 --- a/src/de/steamwar/lobby/listener/ShieldListener.java +++ b/src/de/steamwar/lobby/listener/ShieldListener.java @@ -1,13 +1,10 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.LobbySystem; -import de.steamwar.lobby.inventorys.LobbyInventory; +import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.utils.LobbyPlayer; -import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.entity.EnderPearl; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -82,7 +79,7 @@ public class ShieldListener implements Listener { @EventHandler public void handlePlayerInteract(PlayerInteractEvent event) { - if(event.getMaterial() != LobbyInventory.SCHILD) return; + if(event.getMaterial() != LobbyInventory.SHIELD) return; Action action = event.getAction(); if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; diff --git a/src/de/steamwar/lobby/utils/Config.java b/src/de/steamwar/lobby/utils/Config.java index 9419b80..4c9b3c8 100644 --- a/src/de/steamwar/lobby/utils/Config.java +++ b/src/de/steamwar/lobby/utils/Config.java @@ -31,7 +31,7 @@ public class Config { if(!new File(instance.getDataFolder(), "config.yml").exists()) { instance.saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); - instance.shutdown(null); + throw new SecurityException(); } FileConfiguration config = instance.getConfig(); diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index f782347..8e517ae 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -2,29 +2,21 @@ package de.steamwar.lobby.utils; import org.bukkit.Effect; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class LobbyPlayer { - private static List cache = new ArrayList<>(); + private static Map cache = new HashMap(); - private UUID uuid; private PlayerHiderState hiderState; private Effect particle; private boolean fly; private boolean enderPearlUsed; private boolean shield; - public LobbyPlayer(UUID uuid) { - this.uuid = uuid; + private LobbyPlayer(UUID uuid) { this.hiderState = PlayerHiderState.SHOW_ALL; - cache.add(this); - } - - public UUID getUuid() { - return uuid; + cache.put(uuid, this); } public PlayerHiderState getHiderState() { @@ -95,10 +87,7 @@ public class LobbyPlayer { } public static LobbyPlayer getLobbyPlayer(UUID uuid) { - for(LobbyPlayer current : cache) { - if(current.getUuid().equals(uuid)) - return current; - } - return null; + LobbyPlayer lobbyPlayer = cache.get(uuid); + return lobbyPlayer == null ? new LobbyPlayer(uuid) : lobbyPlayer; } } diff --git a/src/plugin.yml b/src/plugin.yml index 2797cdd..b24d08a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -5,5 +5,4 @@ depend: [SpigotCore] main: de.steamwar.lobby.LobbySystem commands: - fly: - schild: \ No newline at end of file + fly: \ No newline at end of file