diff --git a/LobbySystem.iml b/LobbySystem.iml new file mode 100644 index 0000000..97e2b2b --- /dev/null +++ b/LobbySystem.iml @@ -0,0 +1,50 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 56d4c27..9839c24 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -19,10 +19,11 @@ package de.steamwar.lobby; +import de.steamwar.lobby.command.FlyCommand; import de.steamwar.lobby.command.HologramCommand; import de.steamwar.lobby.command.PortalCommand; import de.steamwar.lobby.listener.Fightservers; -import de.steamwar.lobby.listener.Join; +import de.steamwar.lobby.listener.PlayerConnection; import de.steamwar.lobby.listener.Portals; import de.steamwar.message.Message; import org.bukkit.plugin.java.JavaPlugin; @@ -42,11 +43,12 @@ public class LobbySystem extends JavaPlugin { public void onEnable() { message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); - new Join(); + new PlayerConnection(); new Fightservers(); new Portals(); new PortalCommand(); new HologramCommand(); + new FlyCommand(); config = new Config(getConfig()); } diff --git a/src/de/steamwar/lobby/command/FlyCommand.java b/src/de/steamwar/lobby/command/FlyCommand.java new file mode 100644 index 0000000..fc164ac --- /dev/null +++ b/src/de/steamwar/lobby/command/FlyCommand.java @@ -0,0 +1,37 @@ +package de.steamwar.lobby.command; + +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 { + + public FlyCommand() { + super("fly"); + } + + @Register("fly") + public void flyCommand(CommandSender sender) { + if (!(sender instanceof Player)) return; + + Player player = (Player) sender; + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + if (userGroup == UserGroup.Member) { + player.sendMessage("§cUnbekannter Befehl."); + return; + } + + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); + boolean newFlightState = !lobbyPlayer.isFlying(); + + lobbyPlayer.setFly(newFlightState); + player.setAllowFlight(newFlightState); + player.setFlying(newFlightState); + player.sendMessage("§7Du kannst jetzt " + (newFlightState ? "§afliegen§7." : "§cnicht §7mehr fliegen.")); + } +} diff --git a/src/de/steamwar/lobby/inventories/EventParticle.java b/src/de/steamwar/lobby/inventories/EventParticle.java new file mode 100644 index 0000000..98fc1c7 --- /dev/null +++ b/src/de/steamwar/lobby/inventories/EventParticle.java @@ -0,0 +1,28 @@ +package de.steamwar.lobby.inventories; + +import de.steamwar.lobby.particle.*; +import org.bukkit.Material; +import org.bukkit.Particle; + +public enum EventParticle { + + WarGearSeason(22, new int[]{12, 285, 54}, new CloudCircleParticle(Material.ENCHANTING_TABLE, "§cVerzaubert", ParticleInventory.loreBuilder(new String[]{"Wolke", "Ring"}, "WarGearSeason Event 1., 2. oder 3. Platz"), Particle.ENCHANTMENT_TABLE, location -> location.add(0, 1.1, 0)), new SimpleParticle(Material.BOOK, "§5Verzaubert", ParticleInventory.loreBuilder(new String[0], "WarGearSeason Event"), Particle.ENCHANTMENT_TABLE)), + AirshipEvent(26, new int[]{205, 9, 54, 120, 292}, new CircleParticle(Material.SNOWBALL, "§fCloud", ParticleInventory.loreBuilder(new String[]{"Ring"}, "AirshipEvent Event 1., 2. oder 3. Platz"), Particle.CLOUD, null, location -> location.add(0, 2.2, 0)), new SimpleParticle(Material.SNOW_BLOCK, "§fCloud", ParticleInventory.loreBuilder(new String[0], "AirshipEvent Event"), Particle.CLOUD)), + HellsBellsWs(28, new int[]{205, 9, 11}, new CloudCircleParticle(Material.TNT_MINECART, "§7Smoke", ParticleInventory.loreBuilder(new String[]{"Wolke", "Ring"}, "HellsBells Event 1., 2. oder 3. Platz"), Particle.CAMPFIRE_COSY_SMOKE, location -> location.add(0, 2.2, 0)), new CircleParticle(Material.TNT, "§8Smoke", ParticleInventory.loreBuilder(new String[]{"Ring"}, "HellsBells Event"), Particle.CAMPFIRE_COSY_SMOKE, null, location -> location, 0, 0, 0, 0.01)), + Underwater(31, new int[]{9, 210, 520}, new CloudParticle(Material.PRISMARINE_CRYSTALS, "§bWasser", ParticleInventory.loreBuilder(new String[]{"Wolke"}, "Underwater Event 1., 2. oder 3. Platz"), Particle.DRIP_WATER), new SimpleParticle(Material.PRISMARINE_BRICKS, "§bWasser", ParticleInventory.loreBuilder(new String[0], "Underwater Event"), Particle.DRIP_WATER)); + + public static EventParticle[] eventParticles = values(); + + EventParticle(int event, int[] placementTeams, SpecialParticle placementParticle, SpecialParticle participationParticles) { + this.event = event; + this.placementTeams = placementTeams; + this.placementParticle = placementParticle; + this.participationParticles = participationParticles; + + } + + public final int event; + public final int[] placementTeams; + public final SpecialParticle placementParticle; + public final SpecialParticle participationParticles; +} diff --git a/src/de/steamwar/lobby/inventories/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java new file mode 100644 index 0000000..ea9141c --- /dev/null +++ b/src/de/steamwar/lobby/inventories/LobbyInventory.java @@ -0,0 +1,33 @@ +package de.steamwar.lobby.inventories; + +import de.steamwar.lobby.util.ItemBuilder; +import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class LobbyInventory { + + private LobbyInventory() {} + + 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 SHIELD = Material.SHIELD; + + public static void givePlayerLobbyItems(Player player) { + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + + player.getInventory().setItem(3, new ItemBuilder(lobbyPlayer.isEnderPearlUsed() ? ENDERPEARL_USED : ENDERPEARL_READY) + .setDisplayName("§5Enderperle") + .setUnbreakable(true) + .removeAllAtributs() + .build()); + + player.getInventory().setItem(5, new ItemBuilder(PARTICLE) + .setDisplayName("§6Partikel") + .setUnbreakable(true) + .removeAllAtributs() + .build()); + } + +} diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java new file mode 100644 index 0000000..37f1816 --- /dev/null +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -0,0 +1,181 @@ +package de.steamwar.lobby.inventories; + +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.lobby.particle.*; +import de.steamwar.lobby.util.LobbyPlayer; +import de.steamwar.sql.*; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.stream.Collectors; + +public class ParticleInventory { + + private ParticleInventory() { + } + + private static final List PLAYER_PARTICLES = new ArrayList<>(); + private static final List TEAM_PARTICLES = new ArrayList<>(); + private static final List SERVERTEAM_PARTICLES = new ArrayList<>(); + + private static final List> PLAYER_PARTICLES_ENTRIES = new ArrayList<>(); + private static final List> TEAM_PARTICLES_ENTRIES = new ArrayList<>(); + private static final List> SERVERTEAM_PARTICLES_ENTRIES = new ArrayList<>(); + + static { + List defaultLore = loreBuilder(null, null); + List teamLore = loreBuilder(null, "Team beitritt"); + List serverTeamLore = loreBuilder(null, "Serverteam"); + List serverTeamLore_C = loreBuilder(new String[]{"Wolke"}, "Serverteam"); + List serverTeamLore_R = loreBuilder(new String[]{"Ring"}, "Serverteam"); + List serverTeamLore_2R = loreBuilder(new String[]{"doppel Ring"}, "Serverteam"); + List serverTeamLore_CR = loreBuilder(new String[]{"Wolke", "Ring"}, "Serverteam"); + + PLAYER_PARTICLES.add(new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", defaultLore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.COBWEB, "§7Smoke", defaultLore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", defaultLore, Particle.DRIP_LAVA)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.WATER_BUCKET, "§bWasser", defaultLore, Particle.DRIP_WATER)); + PLAYER_PARTICLES.add(new FunctionalParticle(Material.RED_DYE, "§cHerzen", defaultLore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5))); + PLAYER_PARTICLES.add(new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", defaultLore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5))); + PLAYER_PARTICLES.add(new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", defaultLore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.SNOWBALL, "§fSnowball", defaultLore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new FunctionalParticle(Material.GLASS_BOTTLE, "§5Effekt", defaultLore, (world, player, time) -> { + world.spawnParticle(Particle.REDSTONE, player.getLocation().add(0.0, 0.2, 0.0), 5, 0F, 0.2F, 0F, 0.01, SpecialParticle.getParticleDust()); + })); + PLAYER_PARTICLES.add(new SimpleParticle(Material.CAMPFIRE, "§7Rauch", defaultLore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.CAULDRON, "§5Magie", defaultLore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", defaultLore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.SLIME_BALL, "§aSchleim", defaultLore, Particle.SLIME)); + PLAYER_PARTICLES.add(new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", defaultLore, Particle.SPELL_MOB)); + + TEAM_PARTICLES.addAll(PLAYER_PARTICLES); + TEAM_PARTICLES.add(new SimpleParticle(Material.INK_SAC, "§8Squid", teamLore, Particle.SQUID_INK, 0.2F, 0.2F, 0.2F, 0.01)); + TEAM_PARTICLES.add(new SimpleParticle(Material.TUBE_CORAL, "§aBubble", teamLore, Particle.BUBBLE_POP, 0.2F, 0.2F, 0.2F, 0.01)); + TEAM_PARTICLES.add(new SimpleParticle(Material.HONEY_BOTTLE, "§6Honey", teamLore, Particle.DRIPPING_HONEY, 0.2F, 0.2F, 0.2F, 1)); + TEAM_PARTICLES.add(new SimpleParticle(Material.HONEYCOMB, "§6Nectar", teamLore, Particle.FALLING_NECTAR, 0.2F, 0.2F, 0.2F, 1)); + TEAM_PARTICLES.add(new FunctionalParticle(Material.FIRE_CHARGE, "§7Firework", loreBuilder(new String[]{"in Luft"}, "Team beitritt"), (world, player, time) -> { + if (world.getBlockAt(player.getLocation().subtract(0, 1, 0)).getType() == Material.AIR) { + world.spawnParticle(Particle.FIREWORKS_SPARK, player.getLocation().subtract(0, -0.2, 0), 2, 0.1F, 0.1F, 0.1F, 0.2); + } + })); + TEAM_PARTICLES.add(new SimpleParticle(Material.DRAGON_BREATH, "§5Dragon Breath", teamLore, Particle.DRAGON_BREATH, 1F, 0.02F, 1F, 0.01)); + TEAM_PARTICLES.add(new SimpleParticle(Material.SPIDER_EYE, "§5Damage", teamLore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01)); + TEAM_PARTICLES.add(new SimpleParticle(Material.BLUE_DYE, "§dDolphin", teamLore, Particle.DOLPHIN, 0.2F, 0F, 0.2F, 0.01)); + TEAM_PARTICLES.add(new CircleParticle(Material.RED_CONCRETE, "§cHerzen", loreBuilder(new String[]{"Ring"}, "Team beitritt"), Particle.HEART, null, location -> location.add(0, 2.2, 0))); + + SERVERTEAM_PARTICLES.addAll(TEAM_PARTICLES); + SERVERTEAM_PARTICLES.add(new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", serverTeamLore, Particle.SPELL_WITCH)); + SERVERTEAM_PARTICLES.add(new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", serverTeamLore, Particle.ENCHANTMENT_TABLE)); + SERVERTEAM_PARTICLES.add(new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", serverTeamLore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01)); + SERVERTEAM_PARTICLES.add(new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", serverTeamLore, Particle.FLAME, 0F, 0.2F, 0F, 0.01)); + SERVERTEAM_PARTICLES.add(new SimpleParticle(Material.END_ROD, "§fEnd Rod", serverTeamLore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.WHITE_WOOL, "§fCloud", serverTeamLore_C, Particle.CLOUD)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.TOTEM_OF_UNDYING, "§aTotem", serverTeamLore_C, Particle.TOTEM)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.WHITE_DYE, "§eZauber", serverTeamLore_C, Particle.ENCHANTMENT_TABLE)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.FIRE_CORAL_BLOCK, "§cFlammen", serverTeamLore_C, Particle.FLAME)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.LIME_SHULKER_BOX, "§aSneeze", serverTeamLore_C, Particle.SNEEZE)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.GREEN_SHULKER_BOX, "§aSchleim", serverTeamLore_C, Particle.SLIME)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.DEAD_BRAIN_CORAL_BLOCK, "§8Smoke", serverTeamLore_C, Particle.CAMPFIRE_COSY_SMOKE)); + SERVERTEAM_PARTICLES.add(new CloudParticle(Material.FIREWORK_STAR, "§5Town", serverTeamLore_C, Particle.TOWN_AURA)); + SERVERTEAM_PARTICLES.add(new CircleParticle(Material.MAGMA_BLOCK, "§cFlammen", serverTeamLore_R, Particle.FLAME, null, location -> location.add(0, 1.1, 0), 0F, 0.0F, 0F, 0.01)); + SERVERTEAM_PARTICLES.add(new CircleParticle(Material.ENCHANTED_BOOK, "§fEnchanted", serverTeamLore_R, Particle.ENCHANTMENT_TABLE, null, location -> location.add(0, 1.1, 0), 0.0F, 0.0F, 0.0F, 0.01)); + SERVERTEAM_PARTICLES.add(new CircleParticle(Material.NOTE_BLOCK, "§eNoten", serverTeamLore_R, Particle.NOTE, null, location -> location.add(0, 2.2, 0), 0.0F, 0.0F, 0.0F, 0.01)); + SERVERTEAM_PARTICLES.add(new CircleParticle(Material.GUARDIAN_SPAWN_EGG, "§bWater§7/§cFire", serverTeamLore_2R, Particle.DRIP_WATER, Particle.DRIP_LAVA, location -> location.add(0, 1.1, 0), 0.0F, 0.0F, 0.0F, 0.01)); + SERVERTEAM_PARTICLES.add(new CircleParticle(Material.DIAMOND_SWORD, "§5Magic§7/§eZauber", serverTeamLore_2R, Particle.CRIT_MAGIC, Particle.ENCHANTMENT_TABLE, location -> location.add(0, 1.1, 0), 0.0F, 0.0F, 0.0F, 0.01)); + SERVERTEAM_PARTICLES.add(new CloudCircleParticle(Material.GLOWSTONE_DUST, "§5Magic", serverTeamLore_CR, Particle.CRIT_MAGIC, location -> location.add(0, 1.1, 0))); + SERVERTEAM_PARTICLES.add(new CloudCircleParticle(Material.FIRE_CORAL, "§cFlammen", serverTeamLore_CR, Particle.FLAME, location -> location.add(0, 1.1, 0))); + SERVERTEAM_PARTICLES.add(new CloudCircleParticle(Material.FIREWORK_ROCKET, "§7Firework", serverTeamLore_CR, Particle.FIREWORKS_SPARK, location -> location.add(0, 1.1, 0))); + SERVERTEAM_PARTICLES.add(new CloudCircleParticle(Material.CYAN_DYE, "§aWater", serverTeamLore_CR, Particle.WATER_WAKE, location -> location.add(0, 1.1, 0))); + + PLAYER_PARTICLES.forEach(specialParticle -> PLAYER_PARTICLES_ENTRIES.add(new SWListInv.SWListEntry<>(specialParticle.getItem(), specialParticle))); + TEAM_PARTICLES.forEach(specialParticle -> TEAM_PARTICLES_ENTRIES.add(new SWListInv.SWListEntry<>(specialParticle.getItem(), specialParticle))); + SERVERTEAM_PARTICLES.forEach(specialParticle -> SERVERTEAM_PARTICLES_ENTRIES.add(new SWListInv.SWListEntry<>(specialParticle.getItem(), specialParticle))); + } + + private static SWInventory createInventory(Player player) { + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + List> particleList; + if (userGroup == UserGroup.Member) { + if (steamwarUser.getTeam() != 0) { + particleList = new ArrayList<>(TEAM_PARTICLES_ENTRIES); + } else { + if (TEAM_PARTICLES.contains(lobbyPlayer.getParticle())) { + lobbyPlayer.setParticle(null); + } + particleList = new ArrayList<>(PLAYER_PARTICLES_ENTRIES); + } + } else { + particleList = new ArrayList<>(SERVERTEAM_PARTICLES_ENTRIES); + } + + Set events = steamwarUser.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(steamwarUser.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet()); + for (EventParticle eventParticle : EventParticle.eventParticles) { + boolean clickablePlacement = userGroup.isTeamGroup(); + clickablePlacement |= (steamwarUser.getTeam() != 0 && contains(eventParticle.placementTeams, steamwarUser.getTeam())); + if (clickablePlacement) { + particleList.add(new SWListInv.SWListEntry<>(eventParticle.placementParticle.getItem(), eventParticle.placementParticle)); + } else { + SWItem swItem = eventParticle.placementParticle.getItem(); + swItem.setName(swItem.getItemMeta().getDisplayName() + " §8- §c§lGesperrt"); + particleList.add(new SWListInv.SWListEntry<>(swItem, null)); + } + + if (eventParticle.placementTeams.length != 0 && (userGroup.isTeamGroup() || events.contains(eventParticle.event))) { + particleList.add(new SWListInv.SWListEntry<>(eventParticle.participationParticles.getItem(), eventParticle.participationParticles)); + } else { + SWItem swItem = eventParticle.participationParticles.getItem(); + swItem.setName(swItem.getItemMeta().getDisplayName() + " §8- §c§lGesperrt"); + particleList.add(new SWListInv.SWListEntry<>(swItem, null)); + } + } + + SWListInv particleSWListInv = new SWListInv<>(player, "§6Partikel", false, particleList, (clickType, particle) -> { + if (particle == null) return; + lobbyPlayer.setParticle(particle); + }); + particleSWListInv.setItem(49, Material.BARRIER, "§8Keine Partikel", new ArrayList<>(), false, clickType -> { + lobbyPlayer.setParticle(null); + }); + + return particleSWListInv; + } + + private static boolean contains(int[] ints, int element) { + for (int i : ints) { + if (i == element) return true; + } + return false; + } + + public static void openParticleInventory(Player player) { + createInventory(player).open(); + } + + public static List loreBuilder(String[] attribute, String unlocked) { + List lore = new ArrayList<>(); + lore.add(""); + if (attribute != null && attribute.length > 0) { + lore.add("§eAttribute§7:"); + for (String s : attribute) { + lore.add("§7- §f" + s); + } + lore.add(""); + } + if (unlocked != null) { + lore.add("§eFreigeschaltet durch"); + lore.add("§f" + unlocked); + lore.add(""); + } + lore.add("§eKlicken zum auswählen"); + return lore; + } + +} + diff --git a/src/de/steamwar/lobby/listener/Join.java b/src/de/steamwar/lobby/listener/PlayerConnection.java similarity index 54% rename from src/de/steamwar/lobby/listener/Join.java rename to src/de/steamwar/lobby/listener/PlayerConnection.java index 225f14b..1026d69 100644 --- a/src/de/steamwar/lobby/listener/Join.java +++ b/src/de/steamwar/lobby/listener/PlayerConnection.java @@ -21,13 +21,20 @@ package de.steamwar.lobby.listener; import de.steamwar.comms.packets.ImALobbyPacket; import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.util.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.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; -public class Join extends BasicListener { +public class PlayerConnection extends BasicListener { @EventHandler public void onJoin(PlayerJoinEvent e) { @@ -36,6 +43,28 @@ public class Join extends BasicListener { player.setGameMode(GameMode.ADVENTURE); player.setWalkSpeed(0.5f); + LobbyPlayer.getLobbyPlayer(player.getUniqueId()); //initialisiert einen neuen LP falls nicht vorhanden + + //TODO: Config + player.teleport(new Location(Bukkit.getWorlds().get(0), 0, 60, 0, 0, 0)); + + player.getInventory().clear(); + LobbyInventory.givePlayerLobbyItems(player); + player.setGameMode(GameMode.ADVENTURE); + player.setHealth(20); + player.setFoodLevel(20); + Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> new ImALobbyPacket().send(player), 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/features/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/features/DoubleJumpListener.java new file mode 100644 index 0000000..b929b22 --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/DoubleJumpListener.java @@ -0,0 +1,62 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.listener.BasicListener; +import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.util.Vector; + +public class DoubleJumpListener extends BasicListener { + + double multiplyer = 1.4; + + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + player.setAllowFlight(true); + player.setFlying(false); + } + + @EventHandler + public void handlePlayerToggleFlight(PlayerToggleFlightEvent event) { + Player player = event.getPlayer(); + if (player.getGameMode() != GameMode.ADVENTURE && player.getGameMode() != GameMode.SURVIVAL) { + return; + } + if (LobbyPlayer.getLobbyPlayer(player).isFlying()) { + return; + } + + event.setCancelled(true); + player.setAllowFlight(false); + player.setFlying(false); + + Vector direction = player.getLocation().getDirection(); + direction.setX(direction.getX() * multiplyer); + direction.setY(direction.getY() * (multiplyer / 2)); + direction.setZ(direction.getZ() * multiplyer); + + player.setVelocity(direction.add(new Vector(0, 1.2, 0))); + player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_ROCKET_LAUNCH, 1.0F, 1.0F); + } + + @EventHandler + public void handlePlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + + if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) return; + if (LobbyPlayer.getLobbyPlayer(player).isFlying()) return; + + player.setAllowFlight(true); + if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { + player.setFlying(false); + } + } + +} diff --git a/src/de/steamwar/lobby/listener/features/EnderpearlListener.java b/src/de/steamwar/lobby/listener/features/EnderpearlListener.java new file mode 100644 index 0000000..49f885d --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/EnderpearlListener.java @@ -0,0 +1,64 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.listener.BasicListener; +import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; + +public class EnderpearlListener extends BasicListener { + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerInteract(PlayerInteractEvent event) { + if(event.getMaterial() != LobbyInventory.ENDERPEARL_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.setEnderPearlUsed(true); + + EnderPearl enderPearl = player.launchProjectile(EnderPearl.class); + enderPearl.setPassenger(player); + + LobbyInventory.givePlayerLobbyItems(player); + + Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> { + lobbyPlayer.setEnderPearlUsed(false); + + if(player == null) //in case of player leave + return; + LobbyInventory.givePlayerLobbyItems(player); + }, 20 * 3); + } + + @EventHandler + public void handleVehicleExit(VehicleExitEvent event) { + if(!(event.getExited() instanceof Player)) + return; + Player player = (Player) event.getExited(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + + lobbyPlayer.setEnderPearlUsed(false); + LobbyInventory.givePlayerLobbyItems(player); + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 0.5F); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerTeleport(PlayerTeleportEvent event) { + if(event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; + if(event.getPlayer().isInsideVehicle()) return; + event.setCancelled(true); + } +} diff --git a/src/de/steamwar/lobby/listener/features/ParticleListener.java b/src/de/steamwar/lobby/listener/features/ParticleListener.java new file mode 100644 index 0000000..48a5bb3 --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/ParticleListener.java @@ -0,0 +1,46 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.inventories.ParticleInventory; +import de.steamwar.lobby.listener.BasicListener; +import de.steamwar.lobby.particle.SpecialParticle; +import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +public class ParticleListener extends BasicListener { + + private static double deg = 0; + + public ParticleListener() { + Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { + deg += 0.1; + if (deg > 360) deg = 0; + }, 0, 1); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getMaterial() != LobbyInventory.PARTICLE) return; + + ParticleInventory.openParticleInventory(player); + } + + @EventHandler + public void handlePlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + SpecialParticle particle = lobbyPlayer.getParticle(); + + if (particle == null) return; + particle.execute(player.getWorld(), player, deg); + } + + +} diff --git a/src/de/steamwar/lobby/listener/features/PlayerInventoryListener.java b/src/de/steamwar/lobby/listener/features/PlayerInventoryListener.java new file mode 100644 index 0000000..45e8c75 --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/PlayerInventoryListener.java @@ -0,0 +1,33 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.listener.BasicListener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; + +public class PlayerInventoryListener extends BasicListener { + + @EventHandler + public void handlePlayerDropItem(PlayerDropItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void handlePlayerPickupItem(PlayerPickupItemEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void handleInventoryClick(InventoryClickEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } + +} diff --git a/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java new file mode 100644 index 0000000..421ebf1 --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/PlayerSeatListener.java @@ -0,0 +1,113 @@ +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 new file mode 100644 index 0000000..bd15fb2 --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/PlayerWorldInteractionListener.java @@ -0,0 +1,40 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.listener.BasicListener; +import org.bukkit.entity.EntityType; +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.PlayerInteractEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class PlayerWorldInteractionListener extends BasicListener { + + @EventHandler(priority = EventPriority.LOW) + public void handlePlayerInteract(PlayerInteractEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void handleEntityDamage(EntityDamageEvent event) { + if(event.getEntityType() != EntityType.PLAYER) return; + event.setCancelled(true); + } + + @EventHandler + public void handleFoodLevelChange(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOW) + public void handlePlayerTeleport(PlayerTeleportEvent event) { + PlayerTeleportEvent.TeleportCause cause = event.getCause(); + if (cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY || + cause == PlayerTeleportEvent.TeleportCause.END_PORTAL || + cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) + event.setCancelled(true); + } + +} + diff --git a/src/de/steamwar/lobby/particle/CircleParticle.java b/src/de/steamwar/lobby/particle/CircleParticle.java new file mode 100644 index 0000000..1c76092 --- /dev/null +++ b/src/de/steamwar/lobby/particle/CircleParticle.java @@ -0,0 +1,87 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.function.Function; +import java.util.function.UnaryOperator; + +public class CircleParticle extends SpecialParticle { + + private Particle particle; + private Particle particle2; + private Function locationShift; + private boolean customVelocity = false; + private float vx; + private float vy; + private float vz; + private double time = 1; + + public CircleParticle(Material material, String name, List lore, Particle particle, Particle particle2, UnaryOperator locationShift) { + super(material, name, lore); + this.particle = particle; + this.particle2 = particle2; + this.locationShift = locationShift; + } + + public CircleParticle(Material material, String name, List lore, Particle particle, Particle particle2, UnaryOperator locationShift, float vx, float vy, float vz, double time) { + super(material, name, lore); + this.particle = particle; + this.particle2 = particle2; + this.locationShift = locationShift; + customVelocity = true; + this.vx = vx; + this.vy = vy; + this.vz = vz; + this.time = time; + } + + @Override + public void particle(World world, Player player, double deg) { + Vector vector = new Vector(1, 0, 0); + vector.rotateAroundY(deg); + if (customVelocity) { + world.spawnParticle(particle, locationShift.apply(player.getLocation().add(vector)), 1, vx, vy, vz, time); + } else { + world.spawnParticle(particle, locationShift.apply(player.getLocation().add(vector)), 1); + } + + if (particle2 == null) { + return; + } + + vector.setX(-vector.getX()); + vector.setZ(-vector.getZ()); + if (customVelocity) { + world.spawnParticle(particle2, locationShift.apply(player.getLocation().add(vector)), 1, vx, vy, vz, time); + } else { + world.spawnParticle(particle2, locationShift.apply(player.getLocation().add(vector)), 1); + } + } + +} diff --git a/src/de/steamwar/lobby/particle/CloudCircleParticle.java b/src/de/steamwar/lobby/particle/CloudCircleParticle.java new file mode 100644 index 0000000..80f9ed7 --- /dev/null +++ b/src/de/steamwar/lobby/particle/CloudCircleParticle.java @@ -0,0 +1,44 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.function.UnaryOperator; + +public class CloudCircleParticle extends CircleParticle { + + public CloudCircleParticle(Material material, String name, List lore, Particle particle, UnaryOperator locationShift) { + super(material, name, lore, particle, null, locationShift, 0.0F, 0.0F, 0.0F, 0.01); + asCloud = true; + } + + @Override + public void particle(World world, Player player, double deg) { + super.particle(world, player, deg); + } + +} diff --git a/src/de/steamwar/lobby/particle/CloudParticle.java b/src/de/steamwar/lobby/particle/CloudParticle.java new file mode 100644 index 0000000..706c071 --- /dev/null +++ b/src/de/steamwar/lobby/particle/CloudParticle.java @@ -0,0 +1,44 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.List; + +public class CloudParticle extends SpecialParticle { + + private Particle particle; + + public CloudParticle(Material material, String name, List lore, Particle particle) { + super(material, name, lore); + asCloud = true; + this.particle = particle; + } + + @Override + public void particle(World world, Player player, double deg) { + world.spawnParticle(particle, player.getLocation().subtract(0, -0.2, 0), 5, 0.5F, 0.02F, 0.5F, 0.01); + } +} diff --git a/src/de/steamwar/lobby/particle/FunctionalParticle.java b/src/de/steamwar/lobby/particle/FunctionalParticle.java new file mode 100644 index 0000000..2e11da0 --- /dev/null +++ b/src/de/steamwar/lobby/particle/FunctionalParticle.java @@ -0,0 +1,43 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.List; + +public class FunctionalParticle extends SpecialParticle { + + private ParticleFunction particleFunction; + + public FunctionalParticle(Material material, String name, List lore, ParticleFunction particleFunction) { + super(material, name, lore); + this.particleFunction = particleFunction; + } + + @Override + public void particle(World world, Player player, double deg) { + particleFunction.accept(world, player, deg); + } + +} diff --git a/src/de/steamwar/lobby/particle/ParticleFunction.java b/src/de/steamwar/lobby/particle/ParticleFunction.java new file mode 100644 index 0000000..ab210ec --- /dev/null +++ b/src/de/steamwar/lobby/particle/ParticleFunction.java @@ -0,0 +1,29 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface ParticleFunction { + void accept(World world, Player player, double time); +} diff --git a/src/de/steamwar/lobby/particle/SimpleParticle.java b/src/de/steamwar/lobby/particle/SimpleParticle.java new file mode 100644 index 0000000..52c0b1d --- /dev/null +++ b/src/de/steamwar/lobby/particle/SimpleParticle.java @@ -0,0 +1,62 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.*; +import org.bukkit.entity.Player; + +import java.util.List; + +public class SimpleParticle extends SpecialParticle { + + private Particle particle; + private boolean customVelocity = false; + private float vx; + private float vy; + private float vz; + private double time = 1; + + public SimpleParticle(Material material, String name, List lore, Particle particle) { + super(material, name, lore); + this.particle = particle; + } + + public SimpleParticle(Material material, String name, List lore, Particle particle, float vx, float vy, float vz, double time) { + super(material, name, lore); + this.particle = particle; + customVelocity = true; + this.vx = vx; + this.vy = vy; + this.vz = vz; + this.time = time; + } + + @Override + public void particle(World world, Player player, double deg) { + Location location = player.getLocation().add(0.0, 0.2, 0.0); + if (customVelocity) { + world.spawnParticle(particle, location, 5, vx, vy, vz, time); + } else { + world.spawnParticle(particle, location, 5); + } + } + +} diff --git a/src/de/steamwar/lobby/particle/SpecialParticle.java b/src/de/steamwar/lobby/particle/SpecialParticle.java new file mode 100644 index 0000000..6ba8e21 --- /dev/null +++ b/src/de/steamwar/lobby/particle/SpecialParticle.java @@ -0,0 +1,84 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.lobby.particle; + +import de.steamwar.inventory.SWItem; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public abstract class SpecialParticle { + + private static final List EMPTY_LORE = new ArrayList<>(); + private static Random random = new Random(); + + public static Color randomColor() { + return Color.fromRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256)); + } + + public static float randomSize() { + return random.nextFloat() / 2 + 1; + } + + public static Particle.DustOptions getParticleDust() { + return new Particle.DustOptions(randomColor(), randomSize()); + } + + private Material material; + private String name; + private List lore; + protected boolean asCloud = false; + + protected SpecialParticle(Material material, String name, List lore) { + if (lore == null) { + lore = EMPTY_LORE; + } + this.material = material; + this.name = name; + this.lore = lore; + } + + public final SWItem getItem() { + return new SWItem(material, name, lore, false, clickType -> {}); + } + + public final void execute(World world, Player player, double deg) { + if (asCloud) { + if (world.getBlockAt(player.getLocation().subtract(0, 1, 0)).getType() == Material.AIR) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 5, 2, false, false, false)); + } else { + player.removePotionEffect(PotionEffectType.SLOW_FALLING); + return; + } + } + particle(world, player, deg); + } + + public abstract void particle(World world, Player player, double deg); + +} diff --git a/src/de/steamwar/lobby/util/ItemBuilder.java b/src/de/steamwar/lobby/util/ItemBuilder.java new file mode 100644 index 0000000..859bcb5 --- /dev/null +++ b/src/de/steamwar/lobby/util/ItemBuilder.java @@ -0,0 +1,66 @@ +package de.steamwar.lobby.util; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; + +public class ItemBuilder { + + private ItemStack item; + private ItemMeta meta; + + public ItemBuilder(Material matrial) { + item = new ItemStack(matrial); + meta = item.getItemMeta(); + } + + + public ItemBuilder(Material matrial, int amount) { + item = new ItemStack(matrial, amount); + meta = item.getItemMeta(); + } + public ItemBuilder(Material matrial, short subid) { + item = new ItemStack(matrial, 1, subid); + meta = item.getItemMeta(); + } + + public ItemBuilder removeAllAtributs() { + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + meta.addItemFlags(ItemFlag.HIDE_DESTROYS); + meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); + meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + return this; + } + + public ItemBuilder setDisplayName(String name) { + meta.setDisplayName(name); + return this; + } + + public ItemBuilder addLore(ArrayList lore) { + meta.setLore(lore); + return this; + } + + public ItemBuilder addEnchantment(Enchantment enchantment, int level) { + meta.addEnchant(enchantment, level, true); + return this; + } + + public ItemStack build() { + item.setItemMeta(meta); + return item; + } + + public ItemBuilder setUnbreakable(boolean unbreakable) { + meta.setUnbreakable(unbreakable); + return this; + } + +} diff --git a/src/de/steamwar/lobby/util/LobbyPlayer.java b/src/de/steamwar/lobby/util/LobbyPlayer.java new file mode 100644 index 0000000..0c8c63a --- /dev/null +++ b/src/de/steamwar/lobby/util/LobbyPlayer.java @@ -0,0 +1,57 @@ +package de.steamwar.lobby.util; + +import de.steamwar.lobby.particle.SpecialParticle; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class LobbyPlayer { + + private static Map cache = new HashMap<>(); + + private SpecialParticle specialParticle; + + private boolean enderPearlUsed; + private boolean fly; + + private LobbyPlayer(UUID uuid) { + cache.put(uuid, this); + specialParticle = null; + } + + public boolean isFlying() { + return fly; + } + + public void setFly(boolean fly) { + this.fly = fly; + } + + public SpecialParticle getParticle() { + return specialParticle; + } + + public void setParticle(SpecialParticle specialParticle) { + this.specialParticle = specialParticle; + } + + public boolean isEnderPearlUsed() { + return enderPearlUsed; + } + + public void setEnderPearlUsed(boolean enderPearlUsed) { + this.enderPearlUsed = enderPearlUsed; + } + + public static LobbyPlayer getLobbyPlayer(UUID uuid) { + LobbyPlayer lobbyPlayer = cache.get(uuid); + return lobbyPlayer == null ? new LobbyPlayer(uuid) : lobbyPlayer; + } + + public static LobbyPlayer getLobbyPlayer(Player player) { + return getLobbyPlayer(player.getUniqueId()); + } + +}