diff --git a/src/de/steamwar/lobby/Config.java b/src/de/steamwar/lobby/Config.java index f3685e5..ab93d86 100644 --- a/src/de/steamwar/lobby/Config.java +++ b/src/de/steamwar/lobby/Config.java @@ -26,15 +26,23 @@ import org.bukkit.configuration.serialization.ConfigurationSerialization; public class Config { - public static double SpawnX = 0; - public static double SpawnY = 0; - public static double SpawnZ = 0; - public static float Pitch = 0; - public static float Yaw = 0; + public static final double SpawnX = 2; + public static final double SpawnY = 63; + public static final double SpawnZ = 2; + public static final float Pitch = 0; + public static final float Yaw = 0; static { ConfigurationSerialization.registerClass(Portal.class); ConfigurationSerialization.registerClass(Hologram.class); + + FileConfiguration yml = LobbySystem.getPlugin().getConfig(); + + /*SpawnX = yml.getDouble("SpawnX"); + SpawnY = yml.getDouble("SpawnY"); + SpawnZ = yml.getDouble("SpawnZ"); + Pitch = (float) yml.getDouble("Pitch"); + Yaw = (float) yml.getDouble("Yaw");*/ } private final FileConfiguration yml; @@ -44,12 +52,6 @@ public class Config { yml.getList("portals", Portal.getPortals()); yml.getList("holograms", Hologram.getHolograms()); - - SpawnX = yml.getDouble("SpawnX"); - SpawnY = yml.getDouble("SpawnY"); - SpawnZ = yml.getDouble("SpawnZ"); - Pitch = (float) yml.getDouble("Pitch"); - Yaw = (float) yml.getDouble("Yaw"); } public void save() { diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 9839c24..018a84d 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -25,7 +25,11 @@ import de.steamwar.lobby.command.PortalCommand; import de.steamwar.lobby.listener.Fightservers; import de.steamwar.lobby.listener.PlayerConnection; import de.steamwar.lobby.listener.Portals; +import de.steamwar.lobby.listener.features.*; import de.steamwar.message.Message; +import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; public class LobbySystem extends JavaPlugin { @@ -43,7 +47,6 @@ public class LobbySystem extends JavaPlugin { public void onEnable() { message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); - new PlayerConnection(); new Fightservers(); new Portals(); new PortalCommand(); @@ -51,6 +54,16 @@ public class LobbySystem extends JavaPlugin { new FlyCommand(); config = new Config(getConfig()); + new PlayerConnection(); + new DoubleJumpListener(); + new ElytraListener(); + new ParticleListener(); + new PlayerInventoryListener(); + new PlayerWorldInteractionListener(); + + World world = Bukkit.getWorlds().get(0); + world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false); + Bukkit.getOfflinePlayer("zOnlyKroks").setWhitelisted(true); } public static LobbySystem getPlugin() { diff --git a/src/de/steamwar/lobby/command/FlyCommand.java b/src/de/steamwar/lobby/command/FlyCommand.java index fc164ac..1ac3f76 100644 --- a/src/de/steamwar/lobby/command/FlyCommand.java +++ b/src/de/steamwar/lobby/command/FlyCommand.java @@ -4,7 +4,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.lobby.util.LobbyPlayer; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class FlyCommand extends SWCommand { @@ -13,11 +12,8 @@ public class FlyCommand extends SWCommand { super("fly"); } - @Register("fly") - public void flyCommand(CommandSender sender) { - if (!(sender instanceof Player)) return; - - Player player = (Player) sender; + @Register + public void genericCommand(Player player) { SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); diff --git a/src/de/steamwar/lobby/inventories/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java index 08dfb68..7d3d735 100644 --- a/src/de/steamwar/lobby/inventories/LobbyInventory.java +++ b/src/de/steamwar/lobby/inventories/LobbyInventory.java @@ -16,9 +16,6 @@ public class LobbyInventory { public static void givePlayerLobbyItems(Player player) { - player.getInventory().setChestplate(new ItemStack(Material.AIR)); - player.getInventory().setItem(8, new ItemStack(Material.AIR)); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); player.getInventory().setItem(3, new ItemBuilder(lobbyPlayer.isFlyingElytra() ? ELYTRA_USED : ELYTRA_READY) @@ -27,12 +24,16 @@ public class LobbyInventory { .removeAllAtributs() .build()); + if(lobbyPlayer.isFlyingElytra()) { + player.getInventory().setItem(4, + new ItemBuilder(Material.FIREWORK_ROCKET, 1).setDisplayName("§5Rakete").build()); + } + player.getInventory().setItem(5, new ItemBuilder(PARTICLE) .setDisplayName("§6Partikel") .setUnbreakable(true) .removeAllAtributs() .build()); - } } diff --git a/src/de/steamwar/lobby/listener/PlayerConnection.java b/src/de/steamwar/lobby/listener/PlayerConnection.java index 071bf98..0c629cd 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnection.java +++ b/src/de/steamwar/lobby/listener/PlayerConnection.java @@ -37,17 +37,16 @@ import org.bukkit.event.player.PlayerQuitEvent; public class PlayerConnection extends BasicListener { - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); - + e.setJoinMessage(null); player.setGameMode(GameMode.ADVENTURE); player.setWalkSpeed(0.5f); 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); diff --git a/src/de/steamwar/lobby/listener/features/ElytraListener.java b/src/de/steamwar/lobby/listener/features/ElytraListener.java index 63e56ef..5f13419 100644 --- a/src/de/steamwar/lobby/listener/features/ElytraListener.java +++ b/src/de/steamwar/lobby/listener/features/ElytraListener.java @@ -4,6 +4,8 @@ import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.listener.BasicListener; import de.steamwar.lobby.util.ItemBuilder; import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -11,49 +13,35 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; public class ElytraListener extends BasicListener { - @EventHandler(priority = EventPriority.NORMAL) + @EventHandler(priority = EventPriority.HIGHEST) public void handlePlayerInteract(PlayerInteractEvent event) { - if(event.getMaterial() != LobbyInventory.ELYTRA_READY) return; - Action action = event.getAction(); - if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; - - event.setCancelled(true); - Player player = event.getPlayer(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - player.getInventory().setChestplate(new ItemStack(Material.ELYTRA)); - - LobbyInventory.givePlayerLobbyItems(player); - - lobbyPlayer.setFlyingElytra(true); - - if(event.getItem().equals(new ItemStack(Material.FIREWORK_ROCKET))) { - event.getItem().setAmount(1); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerToggleGlide(EntityToggleGlideEvent event) { - if(!(event.getEntity() instanceof Player)) return; - Player player = (Player) event.getEntity(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - - if(!event.isGliding() && lobbyPlayer.isFlyingElytra()) { - lobbyPlayer.setFlyingElytra(false); + if(!lobbyPlayer.isFlyingElytra()) { + player.getInventory().setChestplate(new ItemStack(Material.ELYTRA)); + player.setGliding(true); + player.teleport(new Location(Bukkit.getWorlds().get(0),player.getLocation().getX(),player.getLocation().getY() + 4, player.getLocation().getZ(), player.getLocation().getYaw(), player.getLocation().getPitch())); + lobbyPlayer.setFlyingElytra(true); LobbyInventory.givePlayerLobbyItems(player); } } - public void givePlayerFirework(Player player) { - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + @EventHandler + public void onMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - if(!lobbyPlayer.isFlyingElytra()) return; - - player.getInventory().setItem(8, new ItemBuilder(Material.FIREWORK_ROCKET, 1).setDisplayName("§5Rakete").build()); + if(lobbyPlayer.isFlyingElytra() && player.isOnGround()) { + lobbyPlayer.setFlyingElytra(false); + player.getInventory().clear(); + LobbyInventory.givePlayerLobbyItems(player); + } } } diff --git a/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java deleted file mode 100644 index 421ebf1..0000000 --- a/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java +++ /dev/null @@ -1,113 +0,0 @@ -package de.steamwar.lobby.listener.features; - -import de.steamwar.lobby.listener.BasicListener; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.data.Bisected; -import org.bukkit.block.data.type.Stairs; -import org.bukkit.entity.AbstractArrow; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.spigotmc.event.entity.EntityDismountEvent; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class PlayerSeatListener extends BasicListener { - - private static class SeatLocation { - - private int x; - private int y; - private int z; - - public SeatLocation(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SeatLocation)) return false; - SeatLocation that = (SeatLocation) o; - return x == that.x && - y == that.y && - z == that.z; - } - - @Override - public int hashCode() { - return Objects.hash(x, y, z); - } - - } - - private Set seats = new HashSet<>(); - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) - return; - - if (!event.getClickedBlock().getType().name().toLowerCase().contains("stairs")) - return; - - if (event.getPlayer().getGameMode() != GameMode.ADVENTURE && event.getPlayer().getGameMode() != GameMode.SURVIVAL) - return; - - if (((Stairs) event.getClickedBlock().getBlockData()).getHalf() != Bisected.Half.BOTTOM) - return; - - if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT) - return; - - if (event.getPlayer().isInsideVehicle()) - event.getPlayer().getVehicle().remove(); - - if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) - return; - - Location location = event.getClickedBlock().getLocation(); - SeatLocation seatLocation = getSeatLocation(location); - if (seats.contains(seatLocation)) - return; - seats.add(seatLocation); - - Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW); - arrow.setGravity(false); - arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); - arrow.addPassenger(event.getPlayer()); - arrow.setPersistent(true); - } - - @EventHandler - public void onEntityDismount(EntityDismountEvent event) { - seats.remove(getSeatLocation(event.getDismounted().getLocation())); - - if (event.getEntityType() != EntityType.PLAYER) - return; - - event.getDismounted().remove(); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer().isInsideVehicle()) - event.getPlayer().getVehicle().remove(); - } - - public SeatLocation getSeatLocation(Location location) { - return new SeatLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - } - -} - diff --git a/src/de/steamwar/lobby/listener/features/PlayerWorldInteractionListener.java b/src/de/steamwar/lobby/listener/features/PlayerWorldInteractionListener.java index bd15fb2..5fdecde 100644 --- a/src/de/steamwar/lobby/listener/features/PlayerWorldInteractionListener.java +++ b/src/de/steamwar/lobby/listener/features/PlayerWorldInteractionListener.java @@ -1,11 +1,15 @@ package de.steamwar.lobby.listener.features; import de.steamwar.lobby.listener.BasicListener; +import org.bukkit.Material; +import org.bukkit.advancement.Advancement; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerTeleportEvent; @@ -13,6 +17,11 @@ public class PlayerWorldInteractionListener extends BasicListener { @EventHandler(priority = EventPriority.LOW) public void handlePlayerInteract(PlayerInteractEvent event) { + if(event.getItem() == null) return; + if (event.getItem().getType() == Material.FIREWORK_ROCKET) { + event.getItem().setAmount(2); + return; + } event.setCancelled(true); } @@ -36,5 +45,14 @@ public class PlayerWorldInteractionListener extends BasicListener { event.setCancelled(true); } + @EventHandler + public void playerAdvancementEvent(PlayerAdvancementDoneEvent event) { + Player p = event.getPlayer(); + Advancement advancement = event.getAdvancement(); + for(String c: advancement.getCriteria()) { + p.getAdvancementProgress(advancement).revokeCriteria(c); + } + } + }