diff --git a/pom.xml b/pom.xml index 2a133ea..35964d1 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ steamwar Spigot - 1.12 + 1.15 provided diff --git a/src/config.yml b/src/config.yml index 0ffc846..752b4b7 100644 --- a/src/config.yml +++ b/src/config.yml @@ -2,6 +2,8 @@ Spawn: X: Y: Z: + Yaw: + Pitch: Border: MinX: 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 a8a54af..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); - player.sendMessage("§7Dein Schild ist jetzt " + (newShieldState ? "§aan" : "§caus") + "§7."); - LobbyInventory.givePlayerLobbyItems(player); - return false; - } -} diff --git a/src/de/steamwar/lobby/inventorys/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java similarity index 72% rename from src/de/steamwar/lobby/inventorys/LobbyInventory.java rename to src/de/steamwar/lobby/inventories/LobbyInventory.java index e771050..2a67538 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,15 +9,16 @@ 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 ENDERPEARL_USED = Material.FIREWORK_CHARGE; + public static Material PARTICLE = Material.NAME_TAG; + public static Material ENDERPEARL_USED = Material.FIREWORK_STAR; 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()); - if(lobbyPlayer == null) return; player.getInventory().setItem(2, new ItemBuilder(PLAYER_HIDER) .setDisplayName(lobbyPlayer.getHiderState().getName()) @@ -31,21 +32,23 @@ public class LobbyInventory { .removeAllAtributs() .build()); - /*player.getInventory().setItem(6, new ItemBuilder(PARTIKEL) + player.getInventory().setItem(6, new ItemBuilder(PARTICLE) .setDisplayName("§6Partikel") .setUnbreakable(true) .removeAllAtributs() - .build());*/ + .build()); 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 74% rename from src/de/steamwar/lobby/inventorys/ParticleInventory.java rename to src/de/steamwar/lobby/inventories/ParticleInventory.java index c3d0c40..0ff37f0 100644 --- a/src/de/steamwar/lobby/inventorys/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -1,10 +1,11 @@ -package de.steamwar.lobby.inventorys; +package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Effect; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -12,37 +13,38 @@ 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"); List lore = new ArrayList<>(); lore.add("§aKlicken zum Auswählen"); - SWItem smoke = new SWItem(Material.WEB, "§7Smoke", lore, false, clickType -> { - lobbyPlayer.setParticle(Effect.SMOKE); + SWItem smoke = new SWItem(Material.COBWEB, "§7Smoke", lore, false, clickType -> { + lobbyPlayer.setParticle(Particle.SMOKE_NORMAL); player.closeInventory(); }); SWItem fire = new SWItem(Material.LAVA_BUCKET, "§cFeuer", lore, false, clickType -> { - lobbyPlayer.setParticle(Effect.LAVA_POP); + lobbyPlayer.setParticle(Particle.DRIP_LAVA); player.closeInventory(); }); - SWItem heart = new SWItem(Material.INK_SACK, (byte) 1, "§cHerzen", lore, false, clickType -> { - lobbyPlayer.setParticle(Effect.HEART); + SWItem heart = new SWItem(Material.RED_DYE, "§cHerzen", lore, false, clickType -> { + lobbyPlayer.setParticle(Particle.HEART); player.closeInventory(); }); SWItem water = new SWItem(Material.WATER_BUCKET, "§bWasser", lore, false, clickType -> { - lobbyPlayer.setParticle(Effect.WATERDRIP); + lobbyPlayer.setParticle(Particle.DRIP_WATER); player.closeInventory(); }); SWItem note = new SWItem(Material.NOTE_BLOCK, "§eNoten", lore, false, clickType -> { - lobbyPlayer.setParticle(Effect.NOTE); + lobbyPlayer.setParticle(Particle.NOTE); player.closeInventory(); }); diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index 224ae4d..3ecf583 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -38,7 +38,7 @@ public class DoubleJumpListener implements Listener { direction.setZ(direction.getZ() * multiplyer); player.setVelocity(direction.add(new Vector(0, 1.2, 0))); - //player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_LAUNCH, 1.0F, 1.0F); + player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_ROCKET_LAUNCH, 1.0F, 1.0F); } @EventHandler 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/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java new file mode 100644 index 0000000..2ff3aa6 --- /dev/null +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -0,0 +1,47 @@ +package de.steamwar.lobby.listener; + +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.utils.Config; +import de.steamwar.lobby.utils.LobbyPlayer; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerConnectionListener implements Listener { + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); + Player player = event.getPlayer(); + + 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, Config.Yaw, Config.Pitch)); + player.getInventory().clear(); + LobbyInventory.givePlayerLobbyItems(player); + player.setGameMode(GameMode.ADVENTURE); + player.setHealth(20); + player.setFoodLevel(20); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + } + + @EventHandler + public void handlePlayerKick(PlayerKickEvent event) { + if(event.getReason().equals("Flying is not enabled on this server") && event.getPlayer().getVehicle() instanceof EnderPearl) + event.setCancelled(true); + } + + +} 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/PlayerJoinListener.java b/src/de/steamwar/lobby/listener/PlayerJoinListener.java deleted file mode 100644 index 77b1468..0000000 --- a/src/de/steamwar/lobby/listener/PlayerJoinListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.steamwar.lobby.listener; - -import de.steamwar.lobby.inventorys.LobbyInventory; -import de.steamwar.lobby.utils.Config; -import de.steamwar.lobby.utils.LobbyPlayer; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerJoinListener implements Listener { - - @EventHandler - public void handlePlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - - if(LobbyPlayer.getLobbyPlayer(player.getUniqueId()) == null) - new LobbyPlayer(player.getUniqueId()); - - player.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ)); - LobbyInventory.givePlayerLobbyItems(player); - player.setGameMode(GameMode.ADVENTURE); - player.setHealth(20); - player.setFoodLevel(20); - } - - -} diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index 5145f38..d7beaa3 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -21,7 +21,9 @@ public class PlayerMoveListener implements Listener { Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, - Config.SpawnZ)); + Config.SpawnZ, + Config.Yaw, + Config.Pitch)); } private boolean isInRegion(Vector minPoint, Vector maxPoint, Vector location) { 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..366e186 100644 --- a/src/de/steamwar/lobby/utils/Config.java +++ b/src/de/steamwar/lobby/utils/Config.java @@ -15,9 +15,11 @@ public class Config { //Cache //Spawn - public static final int SpawnX; - public static final int SpawnY; - public static final int SpawnZ; + public static final double SpawnX; + public static final double SpawnY; + public static final double SpawnZ; + public static final float Yaw; + public static final float Pitch; //World Border public static final int BorderMinX; @@ -31,13 +33,15 @@ 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(); SpawnX = config.getInt("Spawn.X"); SpawnY = config.getInt("Spawn.Y"); SpawnZ = config.getInt("Spawn.Z"); + Yaw = (float) config.getDouble("Spawn.Yaw"); + Pitch = (float) config.getDouble("Spawn.Pitch"); BorderMinX = config.getInt("Border.MinX"); BorderMinY = config.getInt("Border.MinY"); diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index f782347..f7fc43c 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -1,30 +1,22 @@ package de.steamwar.lobby.utils; -import org.bukkit.Effect; +import org.bukkit.Particle; -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 Particle 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() { @@ -35,11 +27,11 @@ public class LobbyPlayer { this.hiderState = hiderState; } - public Effect getParticle() { + public Particle getParticle() { return particle; } - public void setParticle(Effect particle) { + public void setParticle(Particle particle) { this.particle = particle; } @@ -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