From 53f1508a0159a9563d9a2f57e39fe4d52fcd9a78 Mon Sep 17 00:00:00 2001 From: flifloo Date: Mon, 7 Sep 2020 23:35:55 +0200 Subject: [PATCH] Fix a lot of warnings --- .../WrapperPlayServerSpawnEntityLiving.java | 1 - .../java/fr/leomelki/loupgarou/MainLg.java | 41 ++++----- .../loupgarou/classes/LGCustomItems.java | 6 +- .../fr/leomelki/loupgarou/classes/LGGame.java | 71 ++++++-------- .../leomelki/loupgarou/classes/LGPlayer.java | 45 ++++----- .../leomelki/loupgarou/classes/LGSound.java | 3 +- .../fr/leomelki/loupgarou/classes/LGVote.java | 79 +++++++--------- .../loupgarou/classes/chat/LGChat.java | 2 +- .../loupgarou/events/LGGameJoinEvent.java | 3 +- .../loupgarou/events/LGVampiredEvent.java | 2 - .../loupgarou/events/LGVoteLeaderChange.java | 8 +- .../loupgarou/listeners/CancelListener.java | 12 ++- .../loupgarou/listeners/ChatListener.java | 10 +- .../loupgarou/listeners/JoinListener.java | 19 ++-- .../loupgarou/listeners/VoteListener.java | 8 +- .../fr/leomelki/loupgarou/roles/RAnge.java | 4 +- .../leomelki/loupgarou/roles/RAssassin.java | 20 ++-- .../fr/leomelki/loupgarou/roles/RBouffon.java | 6 +- .../leomelki/loupgarou/roles/RChasseur.java | 7 +- .../loupgarou/roles/RChasseurDeVampire.java | 42 +++------ .../leomelki/loupgarou/roles/RChienLoup.java | 9 +- .../fr/leomelki/loupgarou/roles/RCorbeau.java | 35 +++---- .../fr/leomelki/loupgarou/roles/RCupidon.java | 60 ++++++------ .../leomelki/loupgarou/roles/RDetective.java | 77 +++++----------- .../leomelki/loupgarou/roles/RDictateur.java | 13 ++- .../loupgarou/roles/REnfantSauvage.java | 26 ++---- .../loupgarou/roles/REnfantSauvageLG.java | 11 +-- .../fr/leomelki/loupgarou/roles/RGarde.java | 44 ++++----- .../loupgarou/roles/RGrandMechantLoup.java | 31 ++----- .../leomelki/loupgarou/roles/RLoupGarou.java | 10 +- .../loupgarou/roles/RLoupGarouBlanc.java | 36 ++++---- .../loupgarou/roles/RLoupGarouNoir.java | 11 ++- .../loupgarou/roles/RMontreurDOurs.java | 3 - .../loupgarou/roles/RPetiteFille.java | 6 +- .../fr/leomelki/loupgarou/roles/RPirate.java | 42 ++++----- .../fr/leomelki/loupgarou/roles/RPretre.java | 76 ++++++++------- .../loupgarou/roles/RPronostiqueur.java | 22 ++--- .../leomelki/loupgarou/roles/RPyromane.java | 92 +++++++++---------- .../leomelki/loupgarou/roles/RSorciere.java | 13 ++- .../leomelki/loupgarou/roles/RSurvivant.java | 11 ++- .../fr/leomelki/loupgarou/roles/RVampire.java | 16 +--- .../fr/leomelki/loupgarou/roles/RVoyante.java | 20 ++-- .../fr/leomelki/loupgarou/roles/Role.java | 10 +- .../scoreboard/CustomScoreboardEntry.java | 6 +- .../loupgarou/utils/MultipleValueMap.java | 9 +- .../loupgarou/utils/VariableCache.java | 2 +- 46 files changed, 465 insertions(+), 615 deletions(-) diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java index 2dda2ff..10f2a40 100644 --- a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java @@ -29,7 +29,6 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.PacketConstructor; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket { public static final PacketType TYPE = diff --git a/src/main/java/fr/leomelki/loupgarou/MainLg.java b/src/main/java/fr/leomelki/loupgarou/MainLg.java index 7f02fb0..467380b 100644 --- a/src/main/java/fr/leomelki/loupgarou/MainLg.java +++ b/src/main/java/fr/leomelki/loupgarou/MainLg.java @@ -81,13 +81,12 @@ import fr.leomelki.loupgarou.roles.RVampire; import fr.leomelki.loupgarou.roles.RVillageois; import fr.leomelki.loupgarou.roles.RVoyante; import fr.leomelki.loupgarou.roles.Role; -import fr.leomelki.loupgarou.utils.VariousUtils; import lombok.Getter; import lombok.Setter; public class MainLg extends JavaPlugin{ private static MainLg instance; - @Getter private final HashMap> roles = new HashMap>(); + @Getter private final HashMap> roles = new HashMap<>(); @Getter private static final String prefix = ""/*"§7[§9Loup-Garou§7] "*/; @Getter @Setter private LGGame currentGame;//Because for now, only one game will be playable on one server (flemme) @@ -104,10 +103,10 @@ public class MainLg extends JavaPlugin{ saveConfig(); } loadConfig(); - Bukkit.getPluginManager().registerEvents(new JoinListener(), this); - Bukkit.getPluginManager().registerEvents(new CancelListener(), this); - Bukkit.getPluginManager().registerEvents(new VoteListener(), this); - Bukkit.getPluginManager().registerEvents(new ChatListener(), this); + Bukkit.getPluginManager().registerEvents(new JoinListener(this), this); + Bukkit.getPluginManager().registerEvents(new CancelListener(this), this); + Bukkit.getPluginManager().registerEvents(new VoteListener(this), this); + Bukkit.getPluginManager().registerEvents(new ChatListener(this), this); Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this); for(Player player : Bukkit.getOnlinePlayers()) @@ -118,7 +117,7 @@ public class MainLg extends JavaPlugin{ @Override public void onPacketSending(PacketEvent event) { WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket()); - LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer()); + LGPlayer lgp = LGPlayer.thePlayer(instance, event.getPlayer()); if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay()) event.setCancelled(true); } @@ -137,11 +136,11 @@ public class MainLg extends JavaPlugin{ protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { @Override public void onPacketSending(PacketEvent event) { - LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket()); - ArrayList datas = new ArrayList(); + ArrayList datas = new ArrayList<>(); for(PlayerInfoData data : info.getData()) { - LGPlayer lgp = LGPlayer.thePlayer(Bukkit.getPlayer(data.getProfile().getUUID())); + LGPlayer lgp = LGPlayer.thePlayer(instance, Bukkit.getPlayer(data.getProfile().getUUID())); if(player.getGame() != null && player.getGame() == lgp.getGame()) { LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); WrappedChatComponent displayName = data.getDisplayName(); @@ -169,7 +168,7 @@ public class MainLg extends JavaPlugin{ protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) { @Override public void onPacketSending(PacketEvent event) { - LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); if(player.getGame() != null && player.getGame().isStarted()) { WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket()); health.setFood(6); @@ -179,12 +178,12 @@ public class MainLg extends JavaPlugin{ protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) { @Override public void onPacketSending(PacketEvent event) { - LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket()); team.setColor(ChatColor.WHITE); Player other = Bukkit.getPlayer(team.getName()); if(other == null)return; - LGPlayer lgp = LGPlayer.thePlayer(other); + LGPlayer lgp = LGPlayer.thePlayer(instance, other); if(player.getGame() != null && player.getGame() == lgp.getGame()) { LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); Bukkit.getPluginManager().callEvent(evt2); @@ -198,7 +197,7 @@ public class MainLg extends JavaPlugin{ protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) { @Override public void onPacketSending(PacketEvent event) { - LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); if(player.getGame() != null) { WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket()); if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId()) @@ -237,7 +236,7 @@ public class MainLg extends JavaPlugin{ sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'est pas connecté."); return true; } - LGGame game = LGPlayer.thePlayer(selected).getGame(); + LGGame game = LGPlayer.thePlayer(instance, selected).getGame(); if(game == null) { sender.sendMessage("§4Erreur : §cLe joueur §4"+selected.getName()+"§c n'est pas dans une partie."); return true; @@ -256,7 +255,7 @@ public class MainLg extends JavaPlugin{ sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !"); return true; } - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(instance, player); if(lgp.getGame() == null) { sender.sendMessage("§4Erreur : §cLe joueur §4"+lgp.getName()+"§c n'est pas dans une partie."); return true; @@ -318,7 +317,7 @@ public class MainLg extends JavaPlugin{ String role = null; if(args[2].length() <= 2) try { - Integer i = Integer.valueOf(args[2]); + int i = Integer.parseInt(args[2]); Object[] array = getRoles().keySet().toArray(); if(array.length <= i) { sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas."); @@ -369,7 +368,7 @@ public class MainLg extends JavaPlugin{ @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { if(!sender.hasPermission("loupgarou.admin")) - return new ArrayList(0); + return new ArrayList<>(0); if(args.length > 1) { if(args[0].equalsIgnoreCase("roles")) @@ -381,11 +380,11 @@ public class MainLg extends JavaPlugin{ return Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); }else if(args.length == 1) return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks"); - return new ArrayList(0); + return new ArrayList<>(0); } private List getStartingList(String startsWith, String... list){ startsWith = startsWith.toLowerCase(); - ArrayList returnlist = new ArrayList(); + ArrayList returnlist = new ArrayList<>(); if(startsWith.length() == 0) return Arrays.asList(list); for(String s : list) @@ -397,7 +396,7 @@ public class MainLg extends JavaPlugin{ int players = 0; for(String role : roles.keySet()) players += getConfig().getInt("role."+role); - currentGame = new LGGame(players); + currentGame = new LGGame(this, players); } @Override public void onDisable() { diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java index 85c532c..3cb9564 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java @@ -17,13 +17,13 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; public class LGCustomItems { - static HashMap, HashMap> mappings = new HashMap, HashMap>(); + static final HashMap, HashMap> mappings = new HashMap<>(); static { JSONParser parser = new JSONParser(); try { JSONObject mappings = (JSONObject)parser.parse("{\"PetiteFille\":{\"\":\"WET_SPONGE\",\"infecte\":\"ORANGE_BED\",\"infecte_mort\":\"ACACIA_WOOD\",\"infecte_maire\":\"SPRUCE_TRAPDOOR\",\"vampire-infecte\":\"BLAST_FURNACE\",\"maire\":\"POPPY\",\"mort\":\"STONE_SLAB\",\"maire_mort\":\"OAK_PLANKS\",\"mort_vampire-infecte\":\"GREEN_SHULKER_BOX\",\"maire_vampire-infecte\":\"SPRUCE_WOOD\",\"infecte_maire_mort\":\"DARK_OAK_PRESSURE_PLATE\",\"maire_mort_vampire-infecte\":\"LIGHT_BLUE_CONCRETE\"},\"LoupGarou\":{\"\":\"DARK_OAK_TRAPDOOR\",\"infecte\":\"CORNFLOWER\",\"infecte_mort\":\"GREEN_WOOL\",\"infecte_maire\":\"RED_BANNER\",\"vampire-infecte\":\"ACACIA_DOOR\",\"maire\":\"PRISMARINE_WALL\",\"maire_mort\":\"BLACK_STAINED_GLASS\",\"mort\":\"DEAD_BRAIN_CORAL\",\"mort_vampire-infecte\":\"COMPARATOR\",\"maire_vampire-infecte\":\"STONE_BRICK_SLAB\",\"infecte_maire_mort\":\"MAGMA_BLOCK\",\"maire_mort_vampire-infecte\":\"JUNGLE_TRAPDOOR\"},\"Corbeau\":{\"infecte_mort\":\"PINK_CONCRETE_POWDER\",\"infecte\":\"TRIDENT\",\"\":\"GRAY_BED\",\"infecte_maire\":\"OAK_SIGN\",\"vampire-infecte\":\"STRIPPED_DARK_OAK_LOG\",\"maire\":\"YELLOW_GLAZED_TERRACOTTA\",\"maire_mort\":\"LECTERN\",\"mort\":\"MELON\",\"mort_vampire-infecte\":\"BARREL\",\"maire_vampire-infecte\":\"LIGHT_GRAY_DYE\",\"infecte_maire_mort\":\"REDSTONE_LAMP\",\"maire_mort_vampire-infecte\":\"BELL\"},\"MontreurDOurs\":{\"infecte_mort\":\"LIGHT_BLUE_TERRACOTTA\",\"\":\"BLUE_DYE\",\"infecte\":\"BLUE_STAINED_GLASS\",\"infecte_maire\":\"DARK_OAK_BUTTON\",\"vampire-infecte\":\"JUNGLE_PLANKS\",\"maire\":\"LEAD\",\"maire_mort\":\"CHISELED_RED_SANDSTONE\",\"mort\":\"RABBIT_FOOT\",\"mort_vampire-infecte\":\"SKULL_BANNER_PATTERN\",\"maire_vampire-infecte\":\"PETRIFIED_OAK_SLAB\",\"infecte_maire_mort\":\"BRAIN_CORAL_FAN\",\"maire_mort_vampire-infecte\":\"CHISELED_SANDSTONE\"},\"LoupGarouBlanc\":{\"infecte_mort\":\"LIME_STAINED_GLASS_PANE\",\"infecte\":\"TORCH\",\"\":\"ACACIA_FENCE_GATE\",\"infecte_maire\":\"SPRUCE_LOG\",\"vampire-infecte\":\"GREEN_CONCRETE_POWDER\",\"maire\":\"DEAD_BUBBLE_CORAL_BLOCK\",\"mort\":\"MUSHROOM_STEM\",\"maire_mort\":\"HORN_CORAL_FAN\",\"mort_vampire-infecte\":\"ORANGE_CARPET\",\"maire_vampire-infecte\":\"MAGENTA_BANNER\",\"infecte_maire_mort\":\"FLOWER_BANNER_PATTERN\",\"maire_mort_vampire-infecte\":\"GRASS_PATH\"},\"Assassin\":{\"infecte\":\"WITHER_ROSE\",\"\":\"ENCHANTED_BOOK\",\"infecte_mort\":\"DARK_OAK_SIGN\",\"infecte_maire\":\"DEAD_TUBE_CORAL_WALL_FAN\",\"vampire-infecte\":\"PURPUR_SLAB\",\"maire\":\"DEAD_TUBE_CORAL_BLOCK\",\"maire_mort\":\"BIRCH_FENCE_GATE\",\"mort\":\"REDSTONE_TORCH\",\"mort_vampire-infecte\":\"ACACIA_SLAB\",\"maire_vampire-infecte\":\"DEAD_BUSH\",\"infecte_maire_mort\":\"INFESTED_MOSSY_STONE_BRICKS\",\"maire_mort_vampire-infecte\":\"BLACK_SHULKER_BOX\"},\"Voyante\":{\"infecte_mort\":\"FLINT\",\"\":\"DRAGON_HEAD\",\"infecte\":\"FIRE_CORAL_BLOCK\",\"infecte_maire\":\"BRAIN_CORAL_WALL_FAN\",\"vampire-infecte\":\"LIGHT_BLUE_WOOL\",\"maire\":\"DARK_OAK_BOAT\",\"maire_mort\":\"NETHERRACK\",\"mort\":\"BLACK_STAINED_GLASS_PANE\",\"mort_vampire-infecte\":\"WHEAT_SEEDS\",\"maire_vampire-infecte\":\"GRAY_GLAZED_TERRACOTTA\",\"infecte_maire_mort\":\"LIGHT_BLUE_SHULKER_BOX\",\"maire_mort_vampire-infecte\":\"TURTLE_HELMET\"},\"Dictateur\":{\"\":\"STRIPPED_DARK_OAK_WOOD\",\"infecte_mort\":\"LAPIS_BLOCK\",\"infecte\":\"GREEN_CARPET\",\"infecte_maire\":\"OAK_DOOR\",\"vampire-infecte\":\"STONE_BRICK_WALL\",\"maire\":\"COCOA_BEANS\",\"maire_mort\":\"GRANITE_SLAB\",\"mort\":\"STICKY_PISTON\",\"mort_vampire-infecte\":\"GRAY_CARPET\",\"maire_vampire-infecte\":\"ACACIA_BOAT\",\"infecte_maire_mort\":\"JUNGLE_LEAVES\",\"maire_mort_vampire-infecte\":\"RED_MUSHROOM\"},\"LoupGarouNoir\":{\"infecte_mort\":\"WHITE_STAINED_GLASS_PANE\",\"\":\"YELLOW_BED\",\"infecte\":\"LIGHT_BLUE_BANNER\",\"infecte_maire\":\"SPRUCE_PLANKS\",\"vampire-infecte\":\"ORANGE_SHULKER_BOX\",\"maire\":\"STRIPPED_OAK_LOG\",\"maire_mort\":\"MOSSY_COBBLESTONE_SLAB\",\"mort\":\"DEAD_FIRE_CORAL_WALL_FAN\",\"mort_vampire-infecte\":\"BIRCH_SIGN\",\"maire_vampire-infecte\":\"BEETROOT_SEEDS\",\"infecte_maire_mort\":\"BEACON\",\"maire_mort_vampire-infecte\":\"CLAY\"},\"ChaperonRouge\":{\"\":\"YELLOW_CONCRETE_POWDER\",\"infecte\":\"LIME_BANNER\",\"infecte_mort\":\"DEAD_BUBBLE_CORAL\",\"infecte_maire\":\"GRAY_SHULKER_BOX\",\"vampire-infecte\":\"WITHER_SKELETON_SKULL\",\"maire\":\"PODZOL\",\"mort\":\"GRAY_BANNER\",\"maire_mort\":\"LIGHT_BLUE_DYE\",\"mort_vampire-infecte\":\"INK_SAC\",\"maire_vampire-infecte\":\"PURPLE_CARPET\",\"infecte_maire_mort\":\"WHITE_CONCRETE_POWDER\",\"maire_mort_vampire-infecte\":\"LAPIS_LAZULI\"},\"EnfantSauvage\":{\"infecte\":\"CARTOGRAPHY_TABLE\",\"\":\"LIGHT_GRAY_STAINED_GLASS_PANE\",\"infecte_mort\":\"YELLOW_WOOL\",\"infecte_maire\":\"POLISHED_DIORITE\",\"vampire-infecte\":\"IRON_HORSE_ARMOR\",\"maire\":\"TUBE_CORAL\",\"mort\":\"STRING\",\"maire_mort\":\"LEATHER_HORSE_ARMOR\",\"mort_vampire-infecte\":\"DARK_OAK_FENCE\",\"maire_vampire-infecte\":\"SPRUCE_DOOR\",\"infecte_maire_mort\":\"YELLOW_TERRACOTTA\",\"maire_mort_vampire-infecte\":\"BAMBOO\"},\"Faucheur\":{\"infecte_mort\":\"MAGENTA_CARPET\",\"infecte\":\"GRAY_STAINED_GLASS\",\"\":\"LIME_GLAZED_TERRACOTTA\",\"infecte_maire\":\"STRIPPED_OAK_WOOD\",\"vampire-infecte\":\"PINK_CONCRETE\",\"maire\":\"FERN\",\"maire_mort\":\"CHORUS_PLANT\",\"mort\":\"ORANGE_TULIP\",\"mort_vampire-infecte\":\"MAGENTA_GLAZED_TERRACOTTA\",\"maire_vampire-infecte\":\"NETHER_BRICK_WALL\",\"infecte_maire_mort\":\"DARK_OAK_FENCE_GATE\",\"maire_mort_vampire-infecte\":\"STRIPPED_BIRCH_LOG\"},\"Cupidon\":{\"\":\"SPRUCE_SLAB\",\"infecte_mort\":\"BONE_MEAL\",\"infecte\":\"MAGENTA_WOOL\",\"infecte_maire\":\"POPPED_CHORUS_FRUIT\",\"vampire-infecte\":\"LAVA_BUCKET\",\"maire\":\"GOLDEN_HELMET\",\"maire_mort\":\"GRASS\",\"mort\":\"STONE_PICKAXE\",\"mort_vampire-infecte\":\"LIGHT_GRAY_CARPET\",\"maire_vampire-infecte\":\"DAMAGED_ANVIL\",\"infecte_maire_mort\":\"COBBLESTONE\",\"maire_mort_vampire-infecte\":\"JUNGLE_FENCE_GATE\"},\"EnfantSauvageLG\":{\"\":\"SAND\",\"infecte_mort\":\"END_CRYSTAL\",\"infecte\":\"CYAN_WOOL\",\"infecte_maire\":\"WOODEN_AXE\",\"vampire-infecte\":\"GRAY_TERRACOTTA\",\"maire\":\"LANTERN\",\"maire_mort\":\"HEAVY_WEIGHTED_PRESSURE_PLATE\",\"mort\":\"WHITE_SHULKER_BOX\",\"mort_vampire-infecte\":\"BUBBLE_CORAL_FAN\",\"maire_vampire-infecte\":\"BIRCH_PRESSURE_PLATE\",\"infecte_maire_mort\":\"PINK_CARPET\",\"maire_mort_vampire-infecte\":\"BLAZE_POWDER\"},\"Chasseur\":{\"infecte_mort\":\"PINK_STAINED_GLASS\",\"infecte\":\"PRISMARINE_SLAB\",\"\":\"SEAGRASS\",\"infecte_maire\":\"WOODEN_SHOVEL\",\"vampire-infecte\":\"GRINDSTONE\",\"maire\":\"YELLOW_STAINED_GLASS_PANE\",\"maire_mort\":\"SUNFLOWER\",\"mort\":\"STICK\",\"mort_vampire-infecte\":\"YELLOW_BANNER\",\"maire_vampire-infecte\":\"SPONGE\",\"infecte_maire_mort\":\"HOPPER_MINECART\",\"maire_mort_vampire-infecte\":\"CYAN_CONCRETE\"},\"Bouffon\":{\"infecte\":\"BIRCH_PLANKS\",\"\":\"ACACIA_SAPLING\",\"infecte_mort\":\"COBBLESTONE_SLAB\",\"infecte_maire\":\"COBBLESTONE_WALL\",\"vampire-infecte\":\"RABBIT_HIDE\",\"maire\":\"SUGAR_CANE\",\"maire_mort\":\"NETHER_BRICK_FENCE\",\"mort\":\"DRIED_KELP_BLOCK\",\"mort_vampire-infecte\":\"END_STONE_BRICK_SLAB\",\"maire_vampire-infecte\":\"RED_CONCRETE_POWDER\",\"infecte_maire_mort\":\"BUBBLE_CORAL\",\"maire_mort_vampire-infecte\":\"IRON_ORE\"},\"Detective\":{\"\":\"CROSSBOW\",\"infecte_mort\":\"RED_STAINED_GLASS\",\"infecte\":\"CYAN_GLAZED_TERRACOTTA\",\"infecte_maire\":\"DIAMOND_AXE\",\"vampire-infecte\":\"SPRUCE_LEAVES\",\"maire\":\"BLACK_TERRACOTTA\",\"mort\":\"YELLOW_CARPET\",\"maire_mort\":\"DIORITE\",\"mort_vampire-infecte\":\"ZOMBIE_HEAD\",\"maire_vampire-infecte\":\"ENDER_EYE\",\"infecte_maire_mort\":\"PINK_SHULKER_BOX\",\"maire_mort_vampire-infecte\":\"DEAD_FIRE_CORAL_BLOCK\"},\"GrandMechantLoup\":{\"infecte_mort\":\"SEA_LANTERN\",\"\":\"OBSERVER\",\"infecte\":\"DRAGON_BREATH\",\"infecte_maire\":\"MAGENTA_TERRACOTTA\",\"vampire-infecte\":\"MOSSY_STONE_BRICK_WALL\",\"maire\":\"DROPPER\",\"maire_mort\":\"PRISMARINE_SHARD\",\"mort\":\"PINK_STAINED_GLASS_PANE\",\"mort_vampire-infecte\":\"SMOKER\",\"maire_vampire-infecte\":\"COAL_ORE\",\"infecte_maire_mort\":\"ORANGE_WOOL\",\"maire_mort_vampire-infecte\":\"FIRE_CORAL_FAN\"},\"Survivant\":{\"\":\"BROWN_DYE\",\"infecte_mort\":\"CYAN_SHULKER_BOX\",\"infecte\":\"END_STONE_BRICKS\",\"infecte_maire\":\"MILK_BUCKET\",\"vampire-infecte\":\"JUNGLE_LOG\",\"maire\":\"CAKE\",\"mort\":\"GLOBE_BANNER_PATTERN\",\"maire_mort\":\"RED_MUSHROOM_BLOCK\",\"mort_vampire-infecte\":\"FIRE_CORAL_WALL_FAN\",\"maire_vampire-infecte\":\"BLACK_CONCRETE\",\"infecte_maire_mort\":\"LILY_PAD\",\"maire_mort_vampire-infecte\":\"MINECART\"},\"ChienLoupLG\":{\"\":\"RED_NETHER_BRICK_SLAB\",\"infecte\":\"PURPLE_STAINED_GLASS\",\"infecte_mort\":\"LIME_CONCRETE\",\"infecte_maire\":\"PURPLE_WOOL\",\"vampire-infecte\":\"SOUL_SAND\",\"maire\":\"ACACIA_SIGN\",\"mort\":\"PURPLE_GLAZED_TERRACOTTA\",\"maire_mort\":\"GRAY_CONCRETE_POWDER\",\"mort_vampire-infecte\":\"IRON_DOOR\",\"maire_vampire-infecte\":\"JUNGLE_DOOR\",\"infecte_maire_mort\":\"DARK_OAK_DOOR\",\"maire_mort_vampire-infecte\":\"JUNGLE_BOAT\"},\"Garde\":{\"\":\"RED_SANDSTONE\",\"infecte\":\"LIGHT_GRAY_BED\",\"infecte_mort\":\"WOODEN_PICKAXE\",\"infecte_maire\":\"YELLOW_DYE\",\"vampire-infecte\":\"FARMLAND\",\"maire\":\"EXPERIENCE_BOTTLE\",\"maire_mort\":\"GLASS_PANE\",\"mort\":\"HORN_CORAL_BLOCK\",\"mort_vampire-infecte\":\"DEAD_HORN_CORAL_BLOCK\",\"maire_vampire-infecte\":\"LIME_DYE\",\"infecte_maire_mort\":\"VINE\",\"maire_mort_vampire-infecte\":\"TNT_MINECART\"},\"Villageois\":{\"\":\"SPRUCE_FENCE\",\"infecte_mort\":\"IRON_INGOT\",\"infecte\":\"DEAD_HORN_CORAL_FAN\",\"infecte_maire\":\"PURPLE_CONCRETE\",\"vampire-infecte\":\"DARK_OAK_PLANKS\",\"maire\":\"END_ROD\",\"maire_mort\":\"BLUE_ICE\",\"mort\":\"MAGENTA_STAINED_GLASS\",\"mort_vampire-infecte\":\"ENDER_PEARL\",\"maire_vampire-infecte\":\"COMMAND_BLOCK\",\"infecte_maire_mort\":\"TERRACOTTA\",\"maire_mort_vampire-infecte\":\"ACACIA_BUTTON\"},\"Ange\":{\"\":\"CAMPFIRE\",\"infecte\":\"BROWN_BED\",\"infecte_mort\":\"WHITE_TERRACOTTA\",\"infecte_maire\":\"GOLDEN_PICKAXE\",\"vampire-infecte\":\"PISTON\",\"maire\":\"BLUE_GLAZED_TERRACOTTA\",\"maire_mort\":\"GREEN_TERRACOTTA\",\"mort\":\"GOLDEN_BOOTS\",\"mort_vampire-infecte\":\"JUNGLE_FENCE\",\"maire_vampire-infecte\":\"SLIME_BALL\",\"infecte_maire_mort\":\"DEAD_BUBBLE_CORAL_FAN\",\"maire_mort_vampire-infecte\":\"LIME_TERRACOTTA\"},\"ChienLoup\":{\"\":\"RED_SANDSTONE_SLAB\",\"infecte_mort\":\"MAGENTA_DYE\",\"infecte\":\"BIRCH_BUTTON\",\"infecte_maire\":\"PINK_BANNER\",\"vampire-infecte\":\"LIGHT_BLUE_STAINED_GLASS_PANE\",\"maire\":\"GREEN_BED\",\"mort\":\"DIRT\",\"maire_mort\":\"POLISHED_GRANITE_SLAB\",\"mort_vampire-infecte\":\"LIGHT_GRAY_STAINED_GLASS\",\"maire_vampire-infecte\":\"STRIPPED_JUNGLE_LOG\",\"infecte_maire_mort\":\"PURPLE_STAINED_GLASS_PANE\",\"maire_mort_vampire-infecte\":\"LEATHER\"},\"Medium\":{\"infecte_mort\":\"BROWN_MUSHROOM_BLOCK\",\"infecte\":\"ORANGE_CONCRETE\",\"\":\"GREEN_STAINED_GLASS\",\"infecte_maire\":\"BROWN_STAINED_GLASS_PANE\",\"vampire-infecte\":\"COAL\",\"maire\":\"CHARCOAL\",\"maire_mort\":\"BRICK_SLAB\",\"mort\":\"ENCHANTING_TABLE\",\"mort_vampire-infecte\":\"CYAN_CARPET\",\"maire_vampire-infecte\":\"DARK_OAK_SAPLING\",\"infecte_maire_mort\":\"SALMON_BUCKET\",\"maire_mort_vampire-infecte\":\"NETHER_BRICKS\"},\"Pyromane\":{\"\":\"RED_WOOL\",\"infecte_mort\":\"CYAN_DYE\",\"infecte\":\"INFESTED_COBBLESTONE\",\"infecte_maire\":\"BIRCH_FENCE\",\"vampire-infecte\":\"RED_BED\",\"maire\":\"DEAD_HORN_CORAL_WALL_FAN\",\"mort\":\"GLASS_BOTTLE\",\"maire_mort\":\"OAK_TRAPDOOR\",\"mort_vampire-infecte\":\"COBWEB\",\"maire_vampire-infecte\":\"POLISHED_GRANITE\",\"infecte_maire_mort\":\"JUNGLE_SLAB\",\"maire_mort_vampire-infecte\":\"NETHER_STAR\"},\"ChasseurDeVampire\":{\"infecte\":\"PAINTING\",\"infecte_mort\":\"COMPOSTER\",\"\":\"ANDESITE_SLAB\",\"infecte_maire\":\"SPAWNER\",\"vampire-infecte\":\"CHORUS_FLOWER\",\"maire\":\"FEATHER\",\"mort\":\"SKELETON_SKULL\",\"maire_mort\":\"WHITE_BANNER\",\"mort_vampire-infecte\":\"BOOKSHELF\",\"maire_vampire-infecte\":\"DIAMOND_SHOVEL\",\"infecte_maire_mort\":\"BIRCH_WOOD\",\"maire_mort_vampire-infecte\":\"RED_CONCRETE\"},\"Pirate\":{\"infecte\":\"BEDROCK\",\"\":\"JUNGLE_SAPLING\",\"infecte_mort\":\"YELLOW_CONCRETE\",\"infecte_maire\":\"POLISHED_DIORITE_SLAB\",\"vampire-infecte\":\"RED_TULIP\",\"maire\":\"NETHER_BRICK_SLAB\",\"maire_mort\":\"ANDESITE\",\"mort\":\"BLUE_CONCRETE\",\"mort_vampire-infecte\":\"ORANGE_TERRACOTTA\",\"maire_vampire-infecte\":\"STRIPPED_ACACIA_LOG\",\"infecte_maire_mort\":\"GLASS\",\"maire_mort_vampire-infecte\":\"LIME_BED\"},\"Vampire\":{\"infecte\":\"SANDSTONE\",\"infecte_mort\":\"PURPLE_SHULKER_BOX\",\"\":\"IRON_SHOVEL\",\"infecte_maire\":\"BRICK_WALL\",\"vampire-infecte\":\"RED_STAINED_GLASS_PANE\",\"maire\":\"MOSSY_STONE_BRICK_SLAB\",\"mort\":\"REPEATER\",\"maire_mort\":\"SNOWBALL\",\"mort_vampire-infecte\":\"BLUE_CONCRETE_POWDER\",\"maire_vampire-infecte\":\"ITEM_FRAME\",\"infecte_maire_mort\":\"DANDELION\",\"maire_mort_vampire-infecte\":\"LEATHER_BOOTS\"},\"Pretre\":{\"\":\"DARK_OAK_SLAB\",\"infecte_mort\":\"DARK_OAK_LEAVES\",\"infecte\":\"CONDUIT\",\"infecte_maire\":\"OXEYE_DAISY\",\"vampire-infecte\":\"SPRUCE_SIGN\",\"maire\":\"HOPPER\",\"maire_mort\":\"SLIME_BLOCK\",\"mort\":\"MOSSY_COBBLESTONE\",\"mort_vampire-infecte\":\"RED_GLAZED_TERRACOTTA\",\"maire_vampire-infecte\":\"SANDSTONE_SLAB\",\"infecte_maire_mort\":\"LIGHT_BLUE_CARPET\",\"maire_mort_vampire-infecte\":\"CYAN_STAINED_GLASS_PANE\"},\"Sorciere\":{\"\":\"MAP\",\"infecte_mort\":\"MOJANG_BANNER_PATTERN\",\"infecte\":\"CYAN_BED\",\"infecte_maire\":\"IRON_HELMET\",\"vampire-infecte\":\"CYAN_TERRACOTTA\",\"maire\":\"PURPLE_TERRACOTTA\",\"mort\":\"PUFFERFISH_BUCKET\",\"maire_mort\":\"SCUTE\",\"mort_vampire-infecte\":\"STRIPPED_SPRUCE_LOG\",\"maire_vampire-infecte\":\"BLACK_BED\",\"infecte_maire_mort\":\"DIAMOND_HOE\",\"maire_mort_vampire-infecte\":\"BIRCH_SLAB\"}}"); for(Object key : mappings.keySet()) { - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); JSONObject array = (JSONObject) mappings.get(key); for(Object key2 : array.keySet()) map.put((String)key2, Material.valueOf((String)array.get(key2))); @@ -54,7 +54,7 @@ public class LGCustomItems { return mapps.get(sj.toString()); } public static Material getItem(LGPlayer player) { - return getItem(player, new ArrayList()); + return getItem(player, new ArrayList<>()); } public static void updateItem(LGPlayer lgp) { diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java index aa958e5..251ba6b 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java @@ -75,32 +75,30 @@ public class LGGame implements Listener{ @Getter private final SecureRandom random = new SecureRandom(); @Getter private final int maxPlayers; - @Getter private final ArrayList inGame = new ArrayList(); - @Getter private final ArrayList roles = new ArrayList(); - + @Getter private final ArrayList inGame = new ArrayList<>(); + @Getter private final ArrayList roles = new ArrayList<>(); + @Getter private final MainLg plugin; + @Getter private boolean started; @Getter private int night = 0; private BukkitTask startingTask; @Getter @Setter private int waitTicks; @Getter private boolean day; @Getter public long time = 0; - @Getter private final HashMap placements = new HashMap(); + @Getter private final HashMap placements = new HashMap<>(); - @Getter private final LGChat spectatorChat = new LGChat((sender, message) -> { - return "§7"+sender.getName()+" §6» §f"+message; - }); - @Getter private final LGChat dayChat = new LGChat((sender, message) -> { - return "§e"+sender.getName()+" §6» §f"+message; - }); + @Getter private final LGChat spectatorChat = new LGChat((sender, message) -> "§7"+sender.getName()+" §6» §f"+message); + @Getter private final LGChat dayChat = new LGChat((sender, message) -> "§e"+sender.getName()+" §6» §f"+message); - public LGGame(int maxPlayers) { + public LGGame(MainLg mainLg, int maxPlayers) { + this.plugin = mainLg; this.maxPlayers = maxPlayers; Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance()); } @Getter - private final MultipleValueMap deaths = new MultipleValueMap(); + private final MultipleValueMap deaths = new MultipleValueMap<>(); public void sendActionBarMessage(String msg) { WrapperPlayServerChat chat = new WrapperPlayServerChat(); @@ -236,11 +234,11 @@ public class LGGame implements Listener{ for(LGPlayer other : getInGame()) { other.updatePrefix(); if(lgp != other) { - player.hidePlayer(other.getPlayer()); - player.showPlayer(other.getPlayer()); + player.hidePlayer(plugin, other.getPlayer()); + player.showPlayer(plugin, other.getPlayer()); - other.getPlayer().hidePlayer(player); - other.getPlayer().showPlayer(player); + other.getPlayer().hidePlayer(plugin, player); + other.getPlayer().showPlayer(plugin, player); } } @@ -304,7 +302,7 @@ public class LGGame implements Listener{ //Registering roles List original = MainLg.getInstance().getConfig().getList("spawns"); - List list = new ArrayList(original); + List list = new ArrayList<>(original); for(LGPlayer lgp : getInGame()) { List location = (List) list.remove(random.nextInt(list.size())); Player p = lgp.getPlayer(); @@ -383,12 +381,7 @@ public class LGGame implements Listener{ updateRoleScoreboard(); //Classe les roles afin de les appeler dans le bon ordre - roles.sort(new Comparator() { - @Override - public int compare(Role role1, Role role2) { - return role1.getTurnOrder()-role2.getTurnOrder(); - } - }); + roles.sort(Comparator.comparingInt(Role::getTurnOrder)); //Start day one nextNight(10); @@ -400,7 +393,7 @@ public class LGGame implements Listener{ roles_.get(lgp.getRole()).increase(); else roles_.put(lgp.getRole(), new IndexedRole(lgp.getRole())); - ArrayList roles = new ArrayList(roles_.values()); + ArrayList roles = new ArrayList<>(roles_.values()); roles.sort((a, b)->{ //TODO fix dégueu juste ici pour le chien loup lg à changer (2x) return (b.getNumber()+(b.getRole().getType() != RoleType.LOUP_GAROU || b.getRole() instanceof RChienLoupLG || b.getRole() instanceof REnfantSauvageLG ? b.getRole().getType() == RoleType.NEUTRAL ? 0 : 999 : 200) - a.getNumber()-(a.getRole().getType() != RoleType.LOUP_GAROU || a.getRole() instanceof RChienLoupLG || a.getRole() instanceof REnfantSauvageLG ? a.getRole().getType() == RoleType.NEUTRAL ? 0 : 999 : 200)); @@ -419,7 +412,7 @@ public class LGGame implements Listener{ lgp.getScoreboard().getLine(i).delete(); } public List getAlive(){ - ArrayList alive = new ArrayList(); + ArrayList alive = new ArrayList<>(); for(LGPlayer lgp : getInGame()) if(!lgp.isDead()) alive.add(lgp); @@ -444,9 +437,7 @@ public class LGGame implements Listener{ setMayor(getAlive().get(random.nextInt(getAlive().size()))); broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); nextNight(); - }, (player, secondsLeft)->{ - return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)"; - }); + }, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)"); mayor.choose((choosen)->{ if(choosen != null) { mayor.stopChoosing(); @@ -474,9 +465,7 @@ public class LGGame implements Listener{ } } }.runTaskTimer(MainLg.getInstance(), 1, 1); - LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)->{ - return "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : ""); - }); + LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)-> "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")); } private void nextNight_() { if(ended)return; @@ -534,13 +523,13 @@ public class LGGame implements Listener{ for(LGPlayer lgp : getInGame()) if(lgp == killed) { WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); - ArrayList infos = new ArrayList(); + ArrayList infos = new ArrayList<>(); info.setAction(PlayerInfoAction.REMOVE_PLAYER); infos.add(new PlayerInfoData(new WrappedGameProfile(lgp.getPlayer().getUniqueId(), lgp.getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(lgp.getName()))); info.setData(infos); info.sendPacket(lgp.getPlayer()); }else - lgp.getPlayer().hidePlayer(killed.getPlayer()); + lgp.getPlayer().hidePlayer(plugin, killed.getPlayer()); if(vote != null) vote.remove(killed); @@ -594,7 +583,7 @@ public class LGGame implements Listener{ public void endGame(LGWinType winType) { if(ended)return; - ArrayList winners = new ArrayList(); + ArrayList winners = new ArrayList<>(); LGGameEndEvent event = new LGGameEndEvent(this, winType, winners); Bukkit.getPluginManager().callEvent(event); @@ -643,7 +632,7 @@ public class LGGame implements Listener{ team.setMode(1); team.setName("you_are"); team.sendPacket(lgp.getPlayer()); - LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); + LGPlayer.thePlayer(plugin, lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); } //A remettre pour activer le démarrage automatique /* wait(30, ()->{ @@ -747,9 +736,7 @@ public class LGGame implements Listener{ setMayor(getAlive().get(random.nextInt(getAlive().size()))); broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); startDay(); - }, (player, secondsLeft)->{ - return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)"; - }); + }, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)"); mayor.choose((choosen)->{ if(choosen != null) { mayor.stopChoosing(); @@ -816,9 +803,7 @@ public class LGGame implements Listener{ Bukkit.getPluginManager().callEvent(event); if(!event.isCancelled()) { broadcastMessage("§9Il est temps de voter pour élire un §5§lCapitaine§9."); - vote = new LGVote(180, 20, this, true, true, (player, secondsLeft)-> { - return player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"; - }); + vote = new LGVote(180, 20, this, true, true, (player, secondsLeft)-> player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); vote.start(getAlive(), getInGame(), ()->{ if(vote.getChoosen() == null) setMayor(getAlive().get(random.nextInt(getAlive().size()))); @@ -851,9 +836,7 @@ public class LGGame implements Listener{ if(!event.isCancelled()) { broadcastMessage("§9La phase des votes a commencé."); isPeopleVote = true; - vote = new LGVote(180, 20, this, false, false, (player, secondsLeft)-> { - return player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"; - }); + vote = new LGVote(180, 20, this, false, false, (player, secondsLeft)-> player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); vote.start(getAlive(), getInGame(), ()->{ isPeopleVote = false; if(vote.getChoosen() == null || (vote.isMayorVote() && getMayor() == null)) diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java b/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java index 9cf5bf8..55e53f8 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java @@ -1,9 +1,6 @@ package fr.leomelki.loupgarou.classes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import java.util.*; import org.bukkit.GameMode; import org.bukkit.Location; @@ -42,11 +39,13 @@ import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_15_R1.WorldType; public class LGPlayer { - private static final HashMap cachedPlayers = new HashMap(); - public static LGPlayer thePlayer(Player player) { + private static final HashMap cachedPlayers = new HashMap<>(); + private final MainLg plugin; + + public static LGPlayer thePlayer(MainLg plugin, Player player) { LGPlayer lgp = cachedPlayers.get(player); if(lgp == null) { - lgp = new LGPlayer(player); + lgp = new LGPlayer(plugin, player); cachedPlayers.put(player, lgp); } return lgp; @@ -64,10 +63,12 @@ public class LGPlayer { @Getter @Setter private LGGame game; @Getter @Setter private String latestObjective; @Getter private CustomScoreboard scoreboard; - public LGPlayer(Player player) { + public LGPlayer(MainLg mainLg, Player player) { + this.plugin = mainLg; this.player = player; } - public LGPlayer(String name) { + public LGPlayer(MainLg mainLg, String name) { + this.plugin = mainLg; this.name = name; } @@ -139,7 +140,7 @@ public class LGPlayer { return false; } public void choose(LGChooseCallback callback, LGPlayer... blacklisted) { - this.blacklistedChoice = blacklisted == null ? new ArrayList(0) : Arrays.asList(blacklisted); + this.blacklistedChoice = blacklisted == null ? new ArrayList<>(0) : Arrays.asList(blacklisted); this.chooseCallback = callback; //sendMessage("§7§oTIP: Regardez un joueur et tapez le afin de le sélectionner."); } @@ -157,17 +158,17 @@ public class LGPlayer { for(LGPlayer lgp : getGame().getAlive()) if(!lgp.isDead()) { if(lgp != this && lgp.getPlayer() != null) - getPlayer().showPlayer(lgp.getPlayer()); + getPlayer().showPlayer(plugin, lgp.getPlayer()); else{ WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); team.setMode(2); team.setName(lgp.getName()); team.setPrefix(WrappedChatComponent.fromText("")); - team.setPlayers(Arrays.asList(lgp.getName())); + team.setPlayers(Collections.singletonList(lgp.getName())); team.sendPacket(getPlayer()); WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); - ArrayList infos = new ArrayList(); + ArrayList infos = new ArrayList<>(); info.setAction(PlayerInfoAction.ADD_PLAYER); infos.add(new PlayerInfoData(new WrappedGameProfile(getPlayer().getUniqueId(), getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(getName()))); info.setData(infos); @@ -182,10 +183,10 @@ public class LGPlayer { //TODO Update prefix for only one guy public void updatePrefix() { if(getGame() != null && !isDead() && player != null) { - List meList = Arrays.asList(getName()); + List meList = Collections.singletonList(getName()); for(LGPlayer lgp : getGame().getInGame()) { WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); - ArrayList infos = new ArrayList(); + ArrayList infos = new ArrayList<>(); info.setAction(PlayerInfoAction.ADD_PLAYER); infos.add(new PlayerInfoData(new WrappedGameProfile(getPlayer().getUniqueId(), getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(getName()))); info.setData(infos); @@ -203,13 +204,13 @@ public class LGPlayer { public void hideView() { if(getGame() != null && player != null) { WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); - ArrayList infos = new ArrayList(); + ArrayList infos = new ArrayList<>(); info.setAction(PlayerInfoAction.ADD_PLAYER); for(LGPlayer lgp : getGame().getAlive()) if(lgp != this && lgp.getPlayer() != null) { if(!lgp.isDead()) infos.add(new PlayerInfoData(new WrappedGameProfile(lgp.getPlayer().getUniqueId(), lgp.getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(lgp.getName()))); - getPlayer().hidePlayer(lgp.getPlayer()); + getPlayer().hidePlayer(plugin, lgp.getPlayer()); } info.setData(infos); info.sendPacket(getPlayer()); @@ -224,14 +225,14 @@ public class LGPlayer { for(LGPlayer lgp : getGame().getInGame()) { if(lgp == this) { WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); - ArrayList infos = new ArrayList(); + ArrayList infos = new ArrayList<>(); info.setAction(PlayerInfoAction.ADD_PLAYER); infos.add(new PlayerInfoData(new WrappedGameProfile(getPlayer().getUniqueId(), getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(getName()))); info.setData(infos); info.sendPacket(getPlayer()); }else if(!isDead() && lgp.getPlayer() != null){ - lgp.getPlayer().hidePlayer(getPlayer()); - lgp.getPlayer().showPlayer(getPlayer()); + lgp.getPlayer().hidePlayer(plugin, getPlayer()); + lgp.getPlayer().showPlayer(plugin, getPlayer()); } } } @@ -242,7 +243,7 @@ public class LGPlayer { WrapperPlayServerPlayerInfo infos = new WrapperPlayServerPlayerInfo(); infos.setAction(PlayerInfoAction.ADD_PLAYER); WrappedGameProfile gameProfile = new WrappedGameProfile(getPlayer().getUniqueId(), getPlayer().getName()); - infos.setData(Arrays.asList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName())))); + infos.setData(Collections.singletonList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName())))); infos.sendPacket(getPlayer()); //Pour qu'il voit son skin changer (sa main et en f5), on lui dit qu'il respawn (alors qu'il n'est pas mort mais ça marche quand même mdr) PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(DimensionManager.OVERWORLD, 0, WorldType.NORMAL, EnumGamemode.ADVENTURE); @@ -304,7 +305,7 @@ public class LGPlayer { if(player != null) for(LGPlayer lgp : getGame().getInGame()) if(lgp != this && lgp.getPlayer() != null) - lgp.getPlayer().hidePlayer(getPlayer()); + lgp.getPlayer().hidePlayer(plugin, getPlayer()); muted = true; } public void resetMuted() { diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java b/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java index e5dee26..1bed5e2 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java @@ -11,7 +11,8 @@ public enum LGSound { AMBIANT_NIGHT(Sound.MUSIC_DISC_MALL), AMBIANT_DAY(Sound.MUSIC_DISC_MELLOHI); - @Getter Sound sound; + @Getter + final Sound sound; LGSound(Sound sound){ this.sound = sound; } diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java index 5497cb7..2e87c97 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java @@ -1,13 +1,8 @@ package fr.leomelki.loupgarou.classes; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.StringJoiner; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -36,7 +31,6 @@ import fr.leomelki.loupgarou.utils.VariousUtils; import lombok.Getter; import net.minecraft.server.v1_15_R1.DataWatcher; import net.minecraft.server.v1_15_R1.DataWatcherObject; -import net.minecraft.server.v1_15_R1.DataWatcherRegistry; import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.EntityArmorStand; import net.minecraft.server.v1_15_R1.IChatBaseComponent; @@ -51,11 +45,11 @@ public class LGVote { private final LGGame game; @Getter private List participants, viewers; private final TextGenerator generator; - @Getter private final HashMap> votes = new HashMap>(); + @Getter private final HashMap> votes = new HashMap<>(); private int votesSize = 0; private LGPlayer mayor; - private ArrayList latestTop = new ArrayList(), blacklisted = new ArrayList(); - private final boolean positiveVote, randomIfEqual; + private ArrayList latestTop = new ArrayList<>(), blacklisted = new ArrayList<>(); + private final boolean randomIfEqual; @Getter private boolean mayorVote; private boolean ended; public LGVote(int timeout, int littleTimeout, LGGame game, boolean positiveVote, boolean randomIfEqual, TextGenerator generator) { @@ -64,7 +58,6 @@ public class LGVote { this.timeout = timeout; this.game = game; this.generator = generator; - this.positiveVote = positiveVote; this.randomIfEqual = randomIfEqual; } public void start(List participants, List viewers, Runnable callback) { @@ -134,7 +127,7 @@ public class LGVote { if(equal) choosen = null; if(equal && mayor == null && randomIfEqual) { - ArrayList choosable = new ArrayList(); + ArrayList choosable = new ArrayList<>(); for(Entry> entry : votes.entrySet()) if(entry.getValue().size() == max) choosable.add(entry.getKey()); @@ -146,7 +139,7 @@ public class LGVote { player.sendMessage("§9Égalité, le §5§lCapitaine§9 va départager les votes."); mayor.sendMessage("§6Tu dois choisir qui va mourir."); - ArrayList choosable = new ArrayList(); + ArrayList choosable = new ArrayList<>(); for(Entry> entry : votes.entrySet()) if(entry.getValue().size() == max) choosable.add(entry.getKey()); @@ -160,7 +153,7 @@ public class LGVote { for(int i = 0;i blackListed = new ArrayList(); + ArrayList blackListed = new ArrayList<>(); for(LGPlayer player : participants) if(!choosable.contains(player)) blackListed.add(player); @@ -186,26 +179,22 @@ public class LGVote { timeout = secondsLeft; return mayor == player ? "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour délibérer" : "§6Le §5§lCapitaine§6 délibère (§e"+secondsLeft+" s§6)"; }); - mayor.choose(new LGChooseCallback() { - - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - if(blackListed.contains(choosen)) - mayor.sendMessage("§4§oCe joueur n'est pas concerné par le choix."); - else { - for(LGPlayer player : participants) - if(choosable.contains(player)) - VariousUtils.setWarning(player.getPlayer(), false); + mayor.choose(choosen -> { + if(choosen != null) { + if(blackListed.contains(choosen)) + mayor.sendMessage("§4§oCe joueur n'est pas concerné par le choix."); + else { + for(LGPlayer player : participants) + if(choosable.contains(player)) + VariousUtils.setWarning(player.getPlayer(), false); - for(int i = 0;i { + if(choosen != null) + vote(who, choosen); }; } public void vote(LGPlayer voter, LGPlayer voted) { @@ -264,7 +249,7 @@ public class LGVote { if(votes.containsKey(voted)) votes.get(voted).add(voter); else - votes.put(voted, new ArrayList(Arrays.asList(voter))); + votes.put(voted, new ArrayList<>(Collections.singletonList(voter))); voter.getCache().set("vote", voted); updateVotes(voted); } @@ -292,7 +277,7 @@ public class LGVote { } public List getVotes(LGPlayer voted){ - return votes.containsKey(voted) ? votes.get(voted) : new ArrayList(0); + return votes.containsKey(voted) ? votes.get(voted) : new ArrayList<>(0); } private void updateVotes(LGPlayer voted) { @@ -311,7 +296,7 @@ public class LGVote { if(entry.getValue().size() > max) max = entry.getValue().size(); ArrayList last = latestTop; - latestTop = new ArrayList(); + latestTop = new ArrayList<>(); for(Entry> entry : votes.entrySet()) if(entry.getValue().size() == max) latestTop.add(entry.getKey()); @@ -383,11 +368,11 @@ public class LGVote { // spawn.sendPacket(lgp.getPlayer()); } } - WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), - noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)), - customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class)), - customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class)), - item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class)); + final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); + final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); + WrappedDataWatcherObject customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class)); + WrappedDataWatcherObject customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class)); + WrappedDataWatcherObject item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class)); private void showVoting(LGPlayer to, LGPlayer ofWho) { int entityId = -to.getPlayer().getEntityId(); WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); diff --git a/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java index 93d2c65..cc24658 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java @@ -9,7 +9,7 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class LGChat { - @Getter private final HashMap viewers = new HashMap(); + @Getter private final HashMap viewers = new HashMap<>(); @Getter private final LGChatCallback defaultCallback; public interface LGChatCallback{ diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java index d4b0a03..aa9c525 100644 --- a/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java +++ b/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java @@ -10,5 +10,6 @@ public class LGGameJoinEvent extends LGEvent{ this.player = player; } - @Getter LGPlayer player; + @Getter + final LGPlayer player; } diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGVampiredEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGVampiredEvent.java index 682856c..749fffd 100644 --- a/src/main/java/fr/leomelki/loupgarou/events/LGVampiredEvent.java +++ b/src/main/java/fr/leomelki/loupgarou/events/LGVampiredEvent.java @@ -1,7 +1,5 @@ package fr.leomelki.loupgarou.events; -import org.bukkit.event.Cancellable; - import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; import lombok.Getter; diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java b/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java index 4a9864b..694eaf1 100644 --- a/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java +++ b/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java @@ -16,7 +16,11 @@ public class LGVoteLeaderChange extends LGEvent{ this.vote = vote; } - @Getter ArrayList latest, now; - @Getter LGVote vote; + @Getter + final ArrayList latest; + @Getter + final ArrayList now; + @Getter + final LGVote vote; } diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java index 9e97e1a..ed13288 100644 --- a/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java +++ b/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java @@ -1,5 +1,6 @@ package fr.leomelki.loupgarou.listeners; +import fr.leomelki.loupgarou.MainLg; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,13 +18,18 @@ import org.bukkit.event.weather.WeatherChangeEvent; import fr.leomelki.loupgarou.classes.LGPlayer; public class CancelListener implements Listener{ + private final MainLg plugin; + + public CancelListener (MainLg mainLg) { + this.plugin = mainLg; + } @EventHandler public void onPluie(WeatherChangeEvent e) { e.setCancelled(true); } @EventHandler public void onMove(PlayerMoveEvent e) { - LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer()); + LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer()); if(lgp.getGame() != null && lgp.getGame().isStarted() && e.getFrom().distanceSquared(e.getTo()) > 0.001) e.setTo(e.getFrom()); } @@ -58,12 +64,12 @@ public class CancelListener implements Listener{ } @EventHandler public void onClickInventory(InventoryClickEvent e) { - if(LGPlayer.thePlayer((Player)e.getWhoClicked()).getGame() != null) + if(LGPlayer.thePlayer(plugin, (Player)e.getWhoClicked()).getGame() != null) e.setCancelled(true); } @EventHandler public void onClickInventory(PlayerSwapHandItemsEvent e) { - if(LGPlayer.thePlayer(e.getPlayer()).getGame() != null) + if(LGPlayer.thePlayer(plugin, e.getPlayer()).getGame() != null) e.setCancelled(true); } } diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/ChatListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/ChatListener.java index 34d6021..4abf630 100644 --- a/src/main/java/fr/leomelki/loupgarou/listeners/ChatListener.java +++ b/src/main/java/fr/leomelki/loupgarou/listeners/ChatListener.java @@ -1,5 +1,6 @@ package fr.leomelki.loupgarou.listeners; +import fr.leomelki.loupgarou.MainLg; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -8,10 +9,17 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import fr.leomelki.loupgarou.classes.LGPlayer; public class ChatListener implements Listener{ + + private final MainLg plugin; + + public ChatListener(MainLg mainLg) { + this.plugin = mainLg; + } + @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent e) { if(!e.isCancelled()) { - LGPlayer player = LGPlayer.thePlayer(e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(plugin, e.getPlayer()); player.onChat(e.getMessage()); e.setCancelled(true); } diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java index 1ca3af9..1117d92 100644 --- a/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java +++ b/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java @@ -1,6 +1,6 @@ package fr.leomelki.loupgarou.listeners; -import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -21,6 +21,11 @@ import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class JoinListener implements Listener{ + private final MainLg plugin; + + public JoinListener(MainLg mainLg) { + this.plugin = mainLg; + } @EventHandler public void onJoin(PlayerJoinEvent e) { @@ -29,17 +34,17 @@ public class JoinListener implements Listener{ WrapperPlayServerScoreboardTeam myTeam = new WrapperPlayServerScoreboardTeam(); myTeam.setName(p.getName()); myTeam.setPrefix(WrappedChatComponent.fromText("")); - myTeam.setPlayers(Arrays.asList(p.getName())); + myTeam.setPlayers(Collections.singletonList(p.getName())); myTeam.setMode(0); boolean noSpec = p.getGameMode() != GameMode.SPECTATOR; for (Player player : Bukkit.getOnlinePlayers()) if (player != p) { if (player.getGameMode() != GameMode.SPECTATOR) - player.hidePlayer(p); + player.hidePlayer(plugin, p); WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); team.setName(player.getName()); team.setPrefix(WrappedChatComponent.fromText("")); - team.setPlayers(Arrays.asList(player.getName())); + team.setPlayers(Collections.singletonList(player.getName())); team.setMode(0); team.sendPacket(p); @@ -49,7 +54,7 @@ public class JoinListener implements Listener{ if (e.getJoinMessage() == null || !e.getJoinMessage().equals("joinall")) { //p.getPlayer().setResourcePack("http://leomelki.fr/mcgames/ressourcepacks/v32/loup_garou.zip"); } else { - LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer()); + LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer()); lgp.showView(); lgp.join(MainLg.getInstance().getCurrentGame()); } @@ -64,7 +69,7 @@ public class JoinListener implements Listener{ public void onResoucePack(PlayerResourcePackStatusEvent e) { if (e.getStatus() == Status.SUCCESSFULLY_LOADED) { Player p = e.getPlayer(); - LGPlayer lgp = LGPlayer.thePlayer(p); + LGPlayer lgp = LGPlayer.thePlayer(plugin, p); lgp.showView(); lgp.join(MainLg.getInstance().getCurrentGame()); } else if(e.getStatus() == Status.DECLINED || e.getStatus() == Status.FAILED_DOWNLOAD) @@ -73,7 +78,7 @@ public class JoinListener implements Listener{ @EventHandler public void onLeave(PlayerQuitEvent e) { Player p = e.getPlayer(); - LGPlayer lgp = LGPlayer.thePlayer(p); + LGPlayer lgp = LGPlayer.thePlayer(plugin, p); if(lgp.getGame() != null) { lgp.leaveChat(); if(lgp.getRole() != null && !lgp.isDead()) diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java index 47669c3..692cb68 100644 --- a/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java +++ b/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java @@ -1,5 +1,6 @@ package fr.leomelki.loupgarou.listeners; +import fr.leomelki.loupgarou.MainLg; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -9,10 +10,15 @@ import org.bukkit.event.player.PlayerAnimationType; import fr.leomelki.loupgarou.classes.LGPlayer; public class VoteListener implements Listener{ + private final MainLg plugin; + + public VoteListener(MainLg mainLg) { + this.plugin = mainLg; + } @EventHandler public void onClick(PlayerAnimationEvent e) { if(e.getAnimationType() == PlayerAnimationType.ARM_SWING) - LGPlayer.thePlayer(e.getPlayer()).chooseAction(); + LGPlayer.thePlayer(plugin, e.getPlayer()).chooseAction(); } @EventHandler public void onBreak(BlockBreakEvent e) { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java b/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java index 988d2ca..c1d61c0 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java @@ -10,8 +10,6 @@ import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; -import fr.leomelki.loupgarou.events.LGMayorVoteEvent; -import fr.leomelki.loupgarou.events.LGNightStart; import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent; import fr.leomelki.loupgarou.events.LGVoteEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; @@ -93,7 +91,7 @@ public class RAnge extends Role{ vote = false; } } - ArrayList winners = new ArrayList(); + final ArrayList winners = new ArrayList<>(); int night = 1; @EventHandler public void onDeath(LGPlayerGotKilledEvent e) { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java b/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java index d76cb38..b071969 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java @@ -5,7 +5,6 @@ import org.bukkit.event.EventPriority; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; @@ -61,17 +60,14 @@ public class RAssassin extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - getGame().kill(choosen, Reason.ASSASSIN); - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); - player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6."); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null && choosen != player) { + getGame().kill(choosen, Reason.ASSASSIN); + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); + player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6."); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java b/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java index 1bcbe5e..b823678 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java @@ -67,9 +67,7 @@ public class RBouffon extends Role{ return; } LGPlayer player = players.remove(0); - getGame().wait(getTimeout(), ()->{RBouffon.this.onNightTurnTimeout(player);this.run();}, (currentPlayer, secondsLeft)->{ - return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"; - }); + getGame().wait(getTimeout(), ()->{RBouffon.this.onNightTurnTimeout(player);this.run();}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); player.sendMessage("§6"+getTask()); // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); onNightTurn(player, this); @@ -121,7 +119,7 @@ public class RBouffon extends Role{ player.stopChoosing(); } - ArrayList needToPlay = new ArrayList(); + final ArrayList needToPlay = new ArrayList<>(); @EventHandler public void onPlayerKill(LGPlayerKilledEvent e) { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java b/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java index fbeaa82..aba8c62 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java @@ -8,7 +8,6 @@ import org.bukkit.event.EventHandler; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.events.LGDayStartEvent; -import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGNightStart; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; @@ -60,9 +59,7 @@ public class RChasseur extends Role{ getGame().wait(getTimeout(), ()->{ this.onNightTurnTimeout(player); callback.run(); - }, (currentPlayer, secondsLeft)->{ - return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e"+secondsLeft+" s§6)"; - }); + }, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e"+secondsLeft+" s§6)"); getGame().broadcastMessage("§9"+getBroadcastedTask()); player.sendMessage("§6"+getTask()); //player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 60); @@ -88,7 +85,7 @@ public class RChasseur extends Role{ player.stopChoosing(); } - ArrayList needToPlay = new ArrayList(); + final ArrayList needToPlay = new ArrayList<>(); @EventHandler public void onPlayerKill(LGPlayerKilledEvent e) { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChasseurDeVampire.java b/src/main/java/fr/leomelki/loupgarou/roles/RChasseurDeVampire.java index 901b577..a2ce288 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RChasseurDeVampire.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChasseurDeVampire.java @@ -1,19 +1,8 @@ package fr.leomelki.loupgarou.roles; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; -import fr.leomelki.loupgarou.classes.LGWinType; -import fr.leomelki.loupgarou.events.LGEndCheckEvent; -import fr.leomelki.loupgarou.events.LGGameEndEvent; -import fr.leomelki.loupgarou.events.LGNightEndEvent; -import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; -import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; -import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; public class RChasseurDeVampire extends Role{ public RChasseurDeVampire(LGGame game) { @@ -67,24 +56,21 @@ public class RChasseurDeVampire extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - // player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6."); - if(choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) { - getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE); - player.sendMessage("§7§l"+choosen.getName()+"§6 est un §5§lVampire§6, à l'attaque."); - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); - } else { - player.sendMessage("§7§l"+choosen.getName()+"§6 n'est pas un §5§lVampire§6..."); - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 n'est pas un §5§lVampire"); - } - - player.stopChoosing(); - player.hideView(); - callback.run(); + player.choose(choosen -> { + if(choosen != null && choosen != player) { + // player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6."); + if(choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) { + getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE); + player.sendMessage("§7§l"+choosen.getName()+"§6 est un §5§lVampire§6, à l'attaque."); + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); + } else { + player.sendMessage("§7§l"+choosen.getName()+"§6 n'est pas un §5§lVampire§6..."); + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 n'est pas un §5§lVampire"); } + + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java index d5eab75..6005e44 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java @@ -1,6 +1,7 @@ package fr.leomelki.loupgarou.roles; import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -19,7 +20,7 @@ import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; public class RChienLoup extends Role{ - static ItemStack[] items = new ItemStack[9]; + static final ItemStack[] items = new ItemStack[9]; static { items[3] = new ItemStack(Material.GOLDEN_APPLE); ItemMeta meta = items[3].getItemMeta(); @@ -30,7 +31,7 @@ public class RChienLoup extends Role{ items[5] = new ItemStack(Material.ROTTEN_FLESH); meta = items[5].getItemMeta(); meta.setDisplayName("§cDevenir Loup-Garou"); - meta.setLore(Arrays.asList("§cVous rejoindrez le camp des §c§lLoups")); + meta.setLore(Collections.singletonList("§cVous rejoindrez le camp des §c§lLoups")); items[5].setItemMeta(meta); } @@ -122,7 +123,7 @@ public class RChienLoup extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -160,7 +161,7 @@ public class RChienLoup extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java b/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java index c406567..c847ced 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java @@ -6,9 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable; import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGDayEndEvent; -import fr.leomelki.loupgarou.events.LGNightStart; import fr.leomelki.loupgarou.events.LGVoteEvent; public class RCorbeau extends Role{ @@ -56,20 +54,17 @@ public class RCorbeau extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); - - choosen.getCache().set("corbeau_selected", true); - - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui"); - player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6."); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null && choosen != player) { + //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); + + choosen.getCache().set("corbeau_selected", true); + + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui"); + player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6."); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } @@ -87,14 +82,14 @@ public class RCorbeau extends Role{ for(LGPlayer lgp : getGame().getAlive()) if(lgp.getCache().getBoolean("corbeau_selected")) { lgp.getCache().remove("corbeau_selected"); - LGPlayer lg = lgp; new BukkitRunnable() { @Override public void run() { - getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg); - getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg);//fix - getGame().broadcastMessage("§7§l"+lg.getName()+"§6 a reçu la visite du "+getName()+"§6."); + MainLg plugin = getGame().getPlugin(); + getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp); + getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);//fix + getGame().broadcastMessage("§7§l"+ lgp.getName()+"§6 a reçu la visite du "+getName()+"§6."); } }.runTask(MainLg.getInstance()); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java b/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java index 8c92f47..fba6749 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java @@ -26,7 +26,6 @@ import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLivin import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; @@ -85,34 +84,31 @@ public class RCupidon extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - if(player.getCache().has("cupidon_first")) { - LGPlayer first = player.getCache().remove("cupidon_first"); - if(first == choosen) { - int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId(); - WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); - destroy.setEntityIds(new int[] {entityId}); - destroy.sendPacket(player.getPlayer()); - } else { - // sendHead(player, choosen); - int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId(); - WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); - destroy.setEntityIds(new int[] {entityId}); - destroy.sendPacket(player.getPlayer()); - - setInLove(first, choosen); - player.sendMessage("§7§l"+first.getName()+"§9 et §7§l"+choosen.getName()+"§9 sont désormais follement amoureux."); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null) { + if(player.getCache().has("cupidon_first")) { + LGPlayer first = player.getCache().remove("cupidon_first"); + if(first == choosen) { + int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId(); + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + destroy.setEntityIds(new int[] {entityId}); + destroy.sendPacket(player.getPlayer()); } else { - sendHead(player, choosen); - player.getCache().set("cupidon_first", choosen); + // sendHead(player, choosen); + int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId(); + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + destroy.setEntityIds(new int[] {entityId}); + destroy.sendPacket(player.getPlayer()); + + setInLove(first, choosen); + player.sendMessage("§7§l"+first.getName()+"§9 et §7§l"+choosen.getName()+"§9 sont désormais follement amoureux."); + player.stopChoosing(); + player.hideView(); + callback.run(); } + } else { + sendHead(player, choosen); + player.getCache().set("cupidon_first", choosen); } } }); @@ -134,8 +130,8 @@ public class RCupidon extends Role{ player2.updatePrefix(); } - WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), - noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); + final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); + final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); protected void sendHead(LGPlayer to, LGPlayer ofWho) { int entityId = Integer.MAX_VALUE-ofWho.getPlayer().getEntityId(); WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); @@ -207,7 +203,7 @@ public class RCupidon extends Role{ public void onGameEnd(LGGameEndEvent e) { if(e.getGame() == getGame()) { WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); - ArrayList ids = new ArrayList(); + ArrayList ids = new ArrayList<>(); for(LGPlayer lgp : getGame().getInGame()) ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId()); int[] intList = new int[ids.size()]; @@ -237,7 +233,7 @@ public class RCupidon extends Role{ @EventHandler public void onEndCheck(LGEndCheckEvent e) { if(e.getGame() == getGame()) { - ArrayList winners = new ArrayList(); + ArrayList winners = new ArrayList<>(); for(LGPlayer lgp : getGame().getAlive()) if(lgp.getRoleWinType() != RoleWinType.NONE) winners.add(lgp); @@ -253,7 +249,7 @@ public class RCupidon extends Role{ @EventHandler(priority = EventPriority.LOWEST) public void onChat(AsyncPlayerChatEvent e) { - LGPlayer player = LGPlayer.thePlayer(e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), e.getPlayer()); if(player.getGame() == getGame()) { if(e.getMessage().startsWith("!")) { if(player.getCache().has("inlove")){ diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java b/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java index 48a39d8..84f7862 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java @@ -1,39 +1,7 @@ package fr.leomelki.loupgarou.roles; -import java.util.ArrayList; -import java.util.Arrays; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - -import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; -import com.comphenix.protocol.wrappers.WrappedWatchableObject; - -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy; -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityEquipment; -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityLook; -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityMetadata; -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLiving; -import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; -import fr.leomelki.loupgarou.classes.LGWinType; -import fr.leomelki.loupgarou.events.LGEndCheckEvent; -import fr.leomelki.loupgarou.events.LGGameEndEvent; -import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent; -import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; -import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; -import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent; public class RDetective extends Role{ public RDetective(LGGame game) { @@ -80,32 +48,29 @@ public class RDetective extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - if(choosen == player) { - player.sendMessage("§cVous ne pouvez pas vous sélectionner !"); - return; - } - if(player.getCache().has("detective_first")) { - LGPlayer first = player.getCache().remove("detective_first"); - if(first == choosen) { - player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !"); - } else { - if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType()) - player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp."); - else - player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp."); - - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null) { + if(choosen == player) { + player.sendMessage("§cVous ne pouvez pas vous sélectionner !"); + return; + } + if(player.getCache().has("detective_first")) { + LGPlayer first = player.getCache().remove("detective_first"); + if(first == choosen) { + player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !"); } else { - player.getCache().set("detective_first", choosen); - player.sendMessage("§9Choisis un joueur avec qui tu souhaites comparer le rôle de §7§l"+choosen.getName()); + if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType()) + player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp."); + else + player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp."); + + player.stopChoosing(); + player.hideView(); + callback.run(); } + } else { + player.getCache().set("detective_first", choosen); + player.sendMessage("§9Choisis un joueur avec qui tu souhaites comparer le rôle de §7§l"+choosen.getName()); } } }); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java b/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java index 0c5db74..dd46d08 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java @@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import org.bukkit.Bukkit; @@ -35,7 +36,7 @@ public class RDictateur extends Role{ items[3] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[3].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[3].setItemMeta(meta); items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER); meta = items[5].getItemMeta(); @@ -122,7 +123,7 @@ public class RDictateur extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -148,7 +149,7 @@ public class RDictateur extends Role{ @EventHandler public void onClick(PlayerInteractEvent e) { Player p = e.getPlayer(); - LGPlayer player = LGPlayer.thePlayer(p); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p); if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { getGame().cancelWait(); player.stopChoosing(); @@ -162,7 +163,7 @@ public class RDictateur extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { @@ -218,9 +219,7 @@ public class RDictateur extends Role{ lgp.getPlayer().getInventory().setItem(8, null); lgp.getPlayer().updateInventory(); this.run(); - }, (player, secondsLeft)->{ - return lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)"; - }); + }, (player, secondsLeft)-> lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)"); lgp.choose((choosen)->{ if(choosen != null) { getGame().cancelWait(); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java index 4dab69c..a03cbb4 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java @@ -7,9 +7,7 @@ import org.bukkit.event.EventPriority; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; -import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class REnfantSauvage extends Role{ public REnfantSauvage(LGGame game) { @@ -63,20 +61,16 @@ public class REnfantSauvage extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); player.sendMessage("§6Choisissez votre modèle."); - player.choose(new LGChooseCallback() { - - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - player.stopChoosing(); - player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6."); - player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle"); - player.getCache().set("enfant_svg", choosen); - choosen.getCache().set("enfant_svg_d", player); - getPlayers().remove(player);//Pour éviter qu'il puisse avoir plusieurs modèles - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null) { + player.stopChoosing(); + player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6."); + player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle"); + player.getCache().set("enfant_svg", choosen); + choosen.getCache().set("enfant_svg_d", player); + getPlayers().remove(player);//Pour éviter qu'il puisse avoir plusieurs modèles + player.hideView(); + callback.run(); } }, player); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java index 19d886b..967ae25 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java @@ -1,13 +1,13 @@ package fr.leomelki.loupgarou.roles; -import java.util.Comparator; - import org.bukkit.potion.PotionEffectType; import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; +import java.util.Comparator; + public class REnfantSauvageLG extends Role{ public REnfantSauvageLG(LGGame game) { super(game); @@ -71,12 +71,7 @@ public class REnfantSauvageLG extends Role{ if(lgRole == null) { getGame().getRoles().add(lgRole = new RLoupGarou(getGame())); - getGame().getRoles().sort(new Comparator() { - @Override - public int compare(Role role1, Role role2) { - return role1.getTurnOrder()-role2.getTurnOrder(); - } - }); + getGame().getRoles().sort(Comparator.comparingInt(Role::getTurnOrder)); } lgRole.join(player, false); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java b/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java index 8869355..a3fda61 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java @@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPreDayStartEvent; @@ -59,30 +58,27 @@ public class RGarde extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - LGPlayer lastProtected = player.getCache().get("garde_lastProtected"); - if(choosen == lastProtected) { - if(lastProtected == player) - player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière."); - else - player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière."); - } else { - if(choosen == player) { - player.sendMessage("§6Tu décides de te protéger toi-même cette nuit."); - player.sendActionBarMessage("§9Tu seras protégé."); - } else { - player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit."); - player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé."); - } - choosen.getCache().set("garde_protected", true); - player.getCache().set("garde_lastProtected", choosen); - player.stopChoosing(); - player.hideView(); - callback.run(); + player.choose(choosen -> { + if(choosen != null) { + LGPlayer lastProtected = player.getCache().get("garde_lastProtected"); + if(choosen == lastProtected) { + if(lastProtected == player) + player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière."); + else + player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière."); + } else { + if(choosen == player) { + player.sendMessage("§6Tu décides de te protéger toi-même cette nuit."); + player.sendActionBarMessage("§9Tu seras protégé."); + } else { + player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit."); + player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé."); } + choosen.getCache().set("garde_protected", true); + player.getCache().set("garde_lastProtected", choosen); + player.stopChoosing(); + player.hideView(); + callback.run(); } } }); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java b/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java index c0d22d7..3eb7702 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java @@ -1,21 +1,9 @@ package fr.leomelki.loupgarou.roles; -import java.util.Arrays; - -import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; -import fr.leomelki.loupgarou.classes.LGWinType; -import fr.leomelki.loupgarou.events.LGEndCheckEvent; -import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; @@ -79,17 +67,14 @@ public class RGrandMechantLoup extends Role{ this.callback = callback; player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit"); - player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6."); - getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null && choosen != player) { + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit"); + player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6."); + getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java index 7ae8cec..5826036 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java @@ -71,9 +71,7 @@ public class RLoupGarou extends Role{ return 30; } - @Getter private final LGChat chat = new LGChat((sender, message) -> { - return "§c"+sender.getName()+" §6» §f"+message; - }); + @Getter private final LGChat chat = new LGChat((sender, message) -> "§c"+sender.getName()+" §6» §f"+message); boolean showSkins = false; LGVote vote; @@ -86,9 +84,7 @@ public class RLoupGarou extends Role{ } public void onNightTurn(Runnable callback) { - vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> { - return !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l"+player.getCache().get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"; - }); + vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l"+player.getCache().get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); for(LGPlayer lgp : getGame().getAlive()) if(lgp.getRoleType() == RoleType.LOUP_GAROU) lgp.showView(); @@ -124,7 +120,7 @@ public class RLoupGarou extends Role{ equal = true; if(equal) { choosen = null; - ArrayList choosable = new ArrayList(); + ArrayList choosable = new ArrayList<>(); for(Entry> entry : vote.getVotes().entrySet()) if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.LOUP_GAROU) choosable.add(entry.getKey()); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java index 56516cb..b9dad12 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java @@ -1,6 +1,6 @@ package fr.leomelki.loupgarou.roles; -import java.util.Arrays; +import java.util.Collections; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -12,7 +12,6 @@ import org.bukkit.inventory.meta.ItemMeta; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; @@ -24,7 +23,7 @@ public class RLoupGarouBlanc extends Role{ skip = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = skip.getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); skip.setItemMeta(meta); } @@ -93,30 +92,27 @@ public class RLoupGarouBlanc extends Role{ RLoupGarou lg = lg_; player.showView(); player.getPlayer().getInventory().setItem(8, skip); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - if(!lg.getPlayers().contains(choosen)) { - player.sendMessage("§7§l"+choosen.getName()+"§4 n'est pas un Loup-Garou."); - return; - } - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit"); - player.sendMessage("§6Tu as choisi de dévorer §7§l"+choosen.getName()+"§6."); - player.getPlayer().getInventory().setItem(8, null); - player.getPlayer().updateInventory(); - getGame().kill(choosen, Reason.LOUP_BLANC); - player.stopChoosing(); - player.hideView(); - callback.run(); + player.choose(choosen -> { + if(choosen != null && choosen != player) { + if(!lg.getPlayers().contains(choosen)) { + player.sendMessage("§7§l"+choosen.getName()+"§4 n'est pas un Loup-Garou."); + return; } + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit"); + player.sendMessage("§6Tu as choisi de dévorer §7§l"+choosen.getName()+"§6."); + player.getPlayer().getInventory().setItem(8, null); + player.getPlayer().updateInventory(); + getGame().kill(choosen, Reason.LOUP_BLANC); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } @EventHandler public void onClick(PlayerInteractEvent e) { Player p = e.getPlayer(); - LGPlayer player = LGPlayer.thePlayer(p); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p); if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { player.stopChoosing(); p.getInventory().setItem(8, null); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java index 3e4a34f..f4b6f93 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java @@ -1,6 +1,7 @@ package fr.leomelki.loupgarou.roles; import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -26,13 +27,13 @@ import fr.leomelki.loupgarou.events.LGNightEndEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class RLoupGarouNoir extends Role{ - static ItemStack[] items = new ItemStack[9]; - static ItemStack[] skip = new ItemStack[9]; + static final ItemStack[] items = new ItemStack[9]; + static final ItemStack[] skip = new ItemStack[9]; static { items[3] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[3].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[3].setItemMeta(meta); items[5] = new ItemStack(Material.ROTTEN_FLESH); meta = items[5].getItemMeta(); @@ -137,7 +138,7 @@ public class RLoupGarouNoir extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -204,7 +205,7 @@ public class RLoupGarouNoir extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RMontreurDOurs.java b/src/main/java/fr/leomelki/loupgarou/roles/RMontreurDOurs.java index 3d1a811..6f30c33 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RMontreurDOurs.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RMontreurDOurs.java @@ -3,7 +3,6 @@ package fr.leomelki.loupgarou.roles; import java.util.List; import java.util.Random; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -11,8 +10,6 @@ import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.events.LGDayStartEvent; -import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; -import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class RMontreurDOurs extends Role{ public RMontreurDOurs(LGGame game) { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java b/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java index d3146ce..b049833 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java @@ -50,7 +50,7 @@ public class RPetiteFille extends Role{ return -1; } - List customNames = Arrays.asList("Loup Glouton", "Loup Méchant", "Loup Burlesque", "Loup Peureux", "Loup Malingre", "Loup Gentil", "Loup Tueur", "Loup Énervé", "Loup Docteur"); + final List customNames = Arrays.asList("Loup Glouton", "Loup Méchant", "Loup Burlesque", "Loup Peureux", "Loup Malingre", "Loup Gentil", "Loup Tueur", "Loup Énervé", "Loup Docteur"); @EventHandler public void onChangeRole(LGRoleTurnEndEvent e) { @@ -61,9 +61,7 @@ public class RPetiteFille extends Role{ RLoupGarou lgRole = (RLoupGarou)role; for(LGPlayer player : getPlayers()) if(!player.getCache().getBoolean("infected") && player.isRoleActive()) - player.joinChat(lgRole.getChat(), (sender, message)->{ - return "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message; - }, true); + player.joinChat(lgRole.getChat(), (sender, message)-> "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message, true); break; } if(e.getPreviousRole() instanceof RLoupGarou) diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java b/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java index 3d776ad..4f2694c 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java @@ -1,6 +1,7 @@ package fr.leomelki.loupgarou.roles; import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -20,17 +21,16 @@ import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class RPirate extends Role{ - static ItemStack[] items = new ItemStack[9]; + static final ItemStack[] items = new ItemStack[9]; static { items[3] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[3].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[3].setItemMeta(meta); items[5] = new ItemStack(Material.ROTTEN_FLESH); meta = items[5].getItemMeta(); @@ -124,7 +124,7 @@ public class RPirate extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -144,23 +144,19 @@ public class RPirate extends Role{ held.setSlot(0); held.sendPacket(player); lgp.sendMessage("§6Choisissez votre otage."); - lgp.choose(new LGChooseCallback() { - - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - player.getInventory().setItem(8, null); - player.updateInventory(); - lgp.stopChoosing(); - lgp.sendMessage("§6Tu as pris §7§l"+choosen.getName()+"§6 en otage."); - lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton otage"); - lgp.getCache().set("pirate_otage", choosen); - choosen.getCache().set("pirate_otage_d", lgp); - getPlayers().remove(lgp);//Pour éviter qu'il puisse prendre plusieurs otages - choosen.sendMessage("§7§l"+lgp.getName()+"§6 t'a pris en otage, il est "+getName()+"§6."); - lgp.hideView(); - callback.run(); - } + lgp.choose(choosen -> { + if(choosen != null) { + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.stopChoosing(); + lgp.sendMessage("§6Tu as pris §7§l"+choosen.getName()+"§6 en otage."); + lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton otage"); + lgp.getCache().set("pirate_otage", choosen); + choosen.getCache().set("pirate_otage_d", lgp); + getPlayers().remove(lgp);//Pour éviter qu'il puisse prendre plusieurs otages + choosen.sendMessage("§7§l"+lgp.getName()+"§6 t'a pris en otage, il est "+getName()+"§6."); + lgp.hideView(); + callback.run(); } }, lgp); } @@ -181,7 +177,7 @@ public class RPirate extends Role{ @EventHandler public void onClick(PlayerInteractEvent e) { Player player = e.getPlayer(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() == this) { if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { e.setCancelled(true); @@ -197,7 +193,7 @@ public class RPirate extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java b/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java index b84a065..173c4ac 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java @@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -28,17 +29,16 @@ import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGPreDayStartEvent; import fr.leomelki.loupgarou.utils.VariousUtils; public class RPretre extends Role{ - static ItemStack[] items = new ItemStack[9]; + static final ItemStack[] items = new ItemStack[9]; static { items[3] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[3].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[3].setItemMeta(meta); items[5] = new ItemStack(Material.ROTTEN_FLESH); meta = items[5].getItemMeta(); @@ -113,21 +113,21 @@ public class RPretre extends Role{ player.closeInventory(); player.openInventory(inventory); } - WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); + final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); @Override protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); for(LGPlayer lgp : getGame().getInGame()) if(lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == player.getRoleType())){ if(lgp.getPlayer() != null) { - player.getPlayer().showPlayer(lgp.getPlayer()); + player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer()); WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); meta.setEntityID(lgp.getPlayer().getEntityId()); - meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0))); + meta.setMetadata(Collections.singletonList(new WrappedWatchableObject(invisible, (byte) 0))); meta.sendPacket(player.getPlayer()); } }else - player.getPlayer().hidePlayer(lgp.getPlayer()); + player.getPlayer().hidePlayer(getGame().getPlugin(), lgp.getPlayer()); this.callback = callback; openInventory(player.getPlayer()); } @@ -147,12 +147,12 @@ public class RPretre extends Role{ if(player.getPlayer() != null) { for(LGPlayer lgp : getGame().getInGame()) if(lgp.getPlayer() != null && lgp != player) - player.getPlayer().hidePlayer(lgp.getPlayer()); + player.getPlayer().hidePlayer(getGame().getPlugin(), lgp.getPlayer()); } } boolean inMenu = false; - ArrayList ressucited = new ArrayList(); + final ArrayList ressucited = new ArrayList<>(); private void closeInventory(Player p) { inMenu = false; @@ -162,7 +162,7 @@ public class RPretre extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -184,33 +184,29 @@ public class RPretre extends Role{ held.sendPacket(player); lgp.sendMessage("§6Choisissez qui réssusciter."); lgp.canSelectDead = true; - lgp.choose(new LGChooseCallback() { - - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - if(!choosen.isDead()) - lgp.sendMessage("§7§l"+choosen.getName()+"§c n'est pas mort."); - else if(lgp.getRoleType() == RoleType.LOUP_GAROU && choosen.getRoleType() == RoleType.NEUTRAL) { - lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6."); - }else if(lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) { - lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait pas partie du §a§lVillage§6."); - } else { - player.getInventory().setItem(8, null); - player.updateInventory(); - lgp.stopChoosing(); - lgp.canSelectDead = false; - lgp.sendMessage("§6Tu as ramené §7§l"+choosen.getName()+"§6 à la vie."); - lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 sera réssuscité"); - - - ressucited.add(choosen); - getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes. - choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6."); - hidePlayers(lgp); - lgp.hideView(); - callback.run(); - } + lgp.choose(choosen -> { + if(choosen != null) { + if(!choosen.isDead()) + lgp.sendMessage("§7§l"+choosen.getName()+"§c n'est pas mort."); + else if(lgp.getRoleType() == RoleType.LOUP_GAROU && choosen.getRoleType() == RoleType.NEUTRAL) { + lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6."); + }else if(lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) { + lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait pas partie du §a§lVillage§6."); + } else { + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.stopChoosing(); + lgp.canSelectDead = false; + lgp.sendMessage("§6Tu as ramené §7§l"+choosen.getName()+"§6 à la vie."); + lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 sera réssuscité"); + + + ressucited.add(choosen); + getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes. + choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6."); + hidePlayers(lgp); + lgp.hideView(); + callback.run(); } } }, lgp); @@ -219,7 +215,7 @@ public class RPretre extends Role{ @EventHandler public void onClick(PlayerInteractEvent e) { Player player = e.getPlayer(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() == this) { if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { e.setCancelled(true); @@ -265,7 +261,7 @@ public class RPretre extends Role{ for(LGPlayer player : getGame().getInGame()) if(player.getPlayer() != null && player != lgp) { - player.getPlayer().showPlayer(lgp.getPlayer()); + player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer()); } } ressucited.clear(); @@ -274,7 +270,7 @@ public class RPretre extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPronostiqueur.java b/src/main/java/fr/leomelki/loupgarou/roles/RPronostiqueur.java index 605fbea..ffb25f1 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RPronostiqueur.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPronostiqueur.java @@ -2,7 +2,6 @@ package fr.leomelki.loupgarou.roles; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; public class RPronostiqueur extends Role{ public RPronostiqueur(LGGame game) { @@ -49,18 +48,15 @@ public class RPronostiqueur extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); - String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant"; - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est "+gentilMechant); - player.sendMessage("§6Votre instinct vous dit que §7§l"+choosen.getName()+"§6 est "+gentilMechant+"§6."); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null && choosen != player) { + //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); + String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant"; + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est "+gentilMechant); + player.sendMessage("§6Votre instinct vous dit que §7§l"+choosen.getName()+"§6 est "+gentilMechant+"§6."); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java b/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java index 31412ef..5b8b1fa 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java @@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.bukkit.Bukkit; @@ -23,7 +24,6 @@ import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGWinType; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; @@ -31,13 +31,14 @@ import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; public class RPyromane extends Role{ - static ItemStack[] items = new ItemStack[9]; - static ItemStack cancel, nothing; + static final ItemStack[] items = new ItemStack[9]; + static final ItemStack cancel; + static final ItemStack nothing; static { cancel = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = cancel.getItemMeta(); meta.setDisplayName("§7§lAnnuler"); - meta.setLore(Arrays.asList("§8Rouvrir le menu")); + meta.setLore(Collections.singletonList("§8Rouvrir le menu")); cancel.setItemMeta(meta); nothing = new ItemStack(Material.IRON_NUGGET); meta = nothing.getItemMeta(); @@ -53,7 +54,7 @@ public class RPyromane extends Role{ items[5] = new ItemStack(Material.LAVA_BUCKET); meta = items[5].getItemMeta(); meta.setDisplayName("§c§lRecouvrir d'essence"); - meta.setLore(Arrays.asList( + meta.setLore(Collections.singletonList( "§8Recouvres deux joueurs d'essence")); items[5].setItemMeta(meta); } @@ -111,7 +112,7 @@ public class RPyromane extends Role{ inMenu = true; Inventory inventory = Bukkit.createInventory(null, 9, "§7Que veux-tu faire ?"); ItemStack[] content = items.clone(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(!lgp.getCache().has("pyromane_essence")) lgp.getCache().set("pyromane_essence", new ArrayList<>()); if(lgp.getCache().>get("pyromane_essence").size() == 0) @@ -159,7 +160,7 @@ public class RPyromane extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; if(item.getItemMeta().getDisplayName().equals(nothing.getItemMeta().getDisplayName())) { @@ -195,31 +196,38 @@ public class RPyromane extends Role{ held.setSlot(0); held.sendPacket(player); lgp.sendMessage("§6Choisis deux joueurs à recouvrir de gasoil."); - lgp.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null) { - if(choosen == first) { - lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l"+choosen.getName()+"§6."); - return; + lgp.choose(choosen -> { + if(choosen != null) { + if(choosen == first) { + lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l"+choosen.getName()+"§6."); + return; + } + List liste = lgp.getCache().get("pyromane_essence"); + if(liste.contains(choosen)) { + lgp.sendMessage("§7§l"+choosen.getName()+"§c est déjà recouvert de gasoil."); + return; + } + if(first == choosen) { + lgp.sendMessage("§cVous avez déjà sélectionné §7§l"+choosen.getName()+"§c."); + return; + } + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.sendMessage("§6Tu as versé du gasoil sur §7§l"+choosen.getName()+"§6."); + lgp.sendActionBarMessage("§6§7§l"+choosen.getName()+"§6 est recouvert de gasoil"); + if(first != null || getGame().getAlive().size() == 2) { + lgp.hideView(); + lgp.stopChoosing(); + LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), choosen); + Bukkit.getPluginManager().callEvent(event); + if(event.isCancelled()) + lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée."); + else { + event.getPlayer().sendMessage("§6Tu es recouvert de gasoil..."); + liste.add(event.getPlayer()); } - List liste = lgp.getCache().get("pyromane_essence"); - if(liste.contains(choosen)) { - lgp.sendMessage("§7§l"+choosen.getName()+"§c est déjà recouvert de gasoil."); - return; - } - if(first == choosen) { - lgp.sendMessage("§cVous avez déjà sélectionné §7§l"+choosen.getName()+"§c."); - return; - } - player.getInventory().setItem(8, null); - player.updateInventory(); - lgp.sendMessage("§6Tu as versé du gasoil sur §7§l"+choosen.getName()+"§6."); - lgp.sendActionBarMessage("§6§7§l"+choosen.getName()+"§6 est recouvert de gasoil"); - if(first != null || getGame().getAlive().size() == 2) { - lgp.hideView(); - lgp.stopChoosing(); - LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), choosen); + if(first != null) { + event = new LGPyromaneGasoilEvent(getGame(), first); Bukkit.getPluginManager().callEvent(event); if(event.isCancelled()) lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée."); @@ -227,21 +235,11 @@ public class RPyromane extends Role{ event.getPlayer().sendMessage("§6Tu es recouvert de gasoil..."); liste.add(event.getPlayer()); } - if(first != null) { - event = new LGPyromaneGasoilEvent(getGame(), first); - Bukkit.getPluginManager().callEvent(event); - if(event.isCancelled()) - lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée."); - else { - event.getPlayer().sendMessage("§6Tu es recouvert de gasoil..."); - liste.add(event.getPlayer()); - } - } - callback.run(); - } else { - lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil."); - first = choosen; } + callback.run(); + } else { + lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil."); + first = choosen; } } }, lgp); @@ -250,7 +248,7 @@ public class RPyromane extends Role{ @EventHandler public void onClick(PlayerInteractEvent e) { Player player = e.getPlayer(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() == this) { if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(cancel.getItemMeta().getDisplayName())) { e.setCancelled(true); @@ -274,7 +272,7 @@ public class RPyromane extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java b/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java index dfa7c00..10545f4 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java @@ -1,6 +1,6 @@ package fr.leomelki.loupgarou.roles; -import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -14,7 +14,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.scheduler.BukkitRunnable; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; @@ -30,7 +29,7 @@ public class RSorciere extends Role{ items[0] = new ItemStack(Material.PURPLE_DYE, 1); ItemMeta meta = items[0].getItemMeta(); meta.setDisplayName("§a§lPotion de vie"); - meta.setLore(Arrays.asList("§2Sauve la cible des §c§lLoups§2.")); + meta.setLore(Collections.singletonList("§2Sauve la cible des §c§lLoups§2.")); items[0].setItemMeta(meta); items[1] = new ItemStack(Material.IRON_NUGGET); meta = items[1].getItemMeta(); @@ -39,7 +38,7 @@ public class RSorciere extends Role{ items[2] = new ItemStack(Material.LIGHT_BLUE_DYE, 1); meta = items[2].getItemMeta(); meta.setDisplayName("§c§lPotion de mort"); - meta.setLore(Arrays.asList("§cTue la personne de ton choix.")); + meta.setLore(Collections.singletonList("§cTue la personne de ton choix.")); items[2].setItemMeta(meta); cancel = new ItemStack(Material.IRON_NUGGET); meta = cancel.getItemMeta(); @@ -140,7 +139,7 @@ public class RSorciere extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player) e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if (lgp.getRole() != this || item == null || item.getItemMeta() == null) return; @@ -178,7 +177,7 @@ public class RSorciere extends Role{ @EventHandler public void onClick(PlayerInteractEvent e) { Player p = e.getPlayer(); - LGPlayer player = LGPlayer.thePlayer(p); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p); if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { player.stopChoosing(); p.getInventory().setItem(8, null); @@ -190,7 +189,7 @@ public class RSorciere extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java b/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java index 1f1309b..2d25f4b 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java @@ -1,6 +1,7 @@ package fr.leomelki.loupgarou.roles; import java.util.Arrays; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -70,12 +71,12 @@ public class RSurvivant extends Role{ inMenu = true; Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu te protéger ?"); ItemStack[] items = new ItemStack[9]; - VariableCache cache = LGPlayer.thePlayer(player).getCache(); + VariableCache cache = LGPlayer.thePlayer(getGame().getPlugin(), player).getCache(); if(cache.get("survivant_left") > 0) { items[3] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[3].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[3].setItemMeta(meta); items[5] = new ItemStack(Material.GOLD_NUGGET); meta = items[5].getItemMeta(); @@ -88,7 +89,7 @@ public class RSurvivant extends Role{ items[4] = new ItemStack(Material.IRON_NUGGET); ItemMeta meta = items[4].getItemMeta(); meta.setDisplayName("§7§lNe rien faire"); - meta.setLore(Arrays.asList("§8Passez votre tour")); + meta.setLore(Collections.singletonList("§8Passez votre tour")); items[4].setItemMeta(meta); } player.closeInventory(); @@ -123,7 +124,7 @@ public class RSurvivant extends Role{ public void onInventoryClick(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); Player player = (Player)e.getWhoClicked(); - LGPlayer lgp = LGPlayer.thePlayer(player); + LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; @@ -167,7 +168,7 @@ public class RSurvivant extends Role{ @EventHandler public void onQuitInventory(InventoryCloseEvent e) { if(e.getInventory() instanceof CraftInventoryCustom) { - LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); if(player.getRole() == this && inMenu) { new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RVampire.java b/src/main/java/fr/leomelki/loupgarou/roles/RVampire.java index ca2fe28..437ce66 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RVampire.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RVampire.java @@ -7,11 +7,8 @@ import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.inventory.ItemStack; -import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; import fr.leomelki.loupgarou.classes.LGCustomItems; -import fr.leomelki.loupgarou.classes.LGCustomSkin; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGVote; @@ -19,12 +16,9 @@ import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints; import fr.leomelki.loupgarou.classes.chat.LGChat; import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent; -import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGNightEndEvent; -import fr.leomelki.loupgarou.events.LGNightStart; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; -import fr.leomelki.loupgarou.events.LGSkinLoadEvent; import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent; import fr.leomelki.loupgarou.events.LGVampiredEvent; import lombok.Getter; @@ -82,9 +76,7 @@ public class RVampire extends Role{ return nextCanInfect < getGame().getNight() && super.hasPlayersLeft(); } - @Getter private final LGChat chat = new LGChat((sender, message) -> { - return "§5"+sender.getName()+" §6» §f"+message; - }); + @Getter private final LGChat chat = new LGChat((sender, message) -> "§5"+sender.getName()+" §6» §f"+message); int nextCanInfect = 0; LGVote vote; @Override @@ -95,9 +87,7 @@ public class RVampire extends Role{ } public void onNightTurn(Runnable callback) { - vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> { - return !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l"+player.getCache().get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"; - }); + vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l"+player.getCache().get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); for(LGPlayer lgp : getGame().getAlive()) if(lgp.getRoleType() == RoleType.VAMPIRE) lgp.showView(); @@ -132,7 +122,7 @@ public class RVampire extends Role{ equal = true; if(equal) { choosen = null; - ArrayList choosable = new ArrayList(); + ArrayList choosable = new ArrayList<>(); for(Entry> entry : vote.getVotes().entrySet()) if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.VAMPIRE) choosable.add(entry.getKey()); diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java b/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java index 1d2c7e3..6ac4940 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java @@ -2,7 +2,6 @@ package fr.leomelki.loupgarou.roles; import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGPlayer; -import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; public class RVoyante extends Role{ public RVoyante(LGGame game) { @@ -50,17 +49,14 @@ public class RVoyante extends Role{ protected void onNightTurn(LGPlayer player, Runnable callback) { player.showView(); - player.choose(new LGChooseCallback() { - @Override - public void callback(LGPlayer choosen) { - if(choosen != null && choosen != player) { - //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); - player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName()); - player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6."); - player.stopChoosing(); - player.hideView(); - callback.run(); - } + player.choose(choosen -> { + if(choosen != null && choosen != player) { + //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); + player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName()); + player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6."); + player.stopChoosing(); + player.hideView(); + callback.run(); } }); } diff --git a/src/main/java/fr/leomelki/loupgarou/roles/Role.java b/src/main/java/fr/leomelki/loupgarou/roles/Role.java index 52906f3..43b3d98 100644 --- a/src/main/java/fr/leomelki/loupgarou/roles/Role.java +++ b/src/main/java/fr/leomelki/loupgarou/roles/Role.java @@ -17,7 +17,7 @@ import lombok.Setter; public abstract class Role implements Listener{ @Getter @Setter private int waitedPlayers; - @Getter private final ArrayList players = new ArrayList(); + @Getter private final ArrayList players = new ArrayList<>(); @Getter private final LGGame game; public Role(LGGame game) { @@ -70,16 +70,12 @@ public abstract class Role implements Listener{ err.printStackTrace(); } this.run(); - }, (currentPlayer, secondsLeft)->{ - return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"; - }); + }, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); player.sendMessage("§6"+getTask()); // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); onNightTurn(player, this); } else { - getGame().wait(getTimeout(), ()->{}, (currentPlayer, secondsLeft)->{ - return currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"; - }); + getGame().wait(getTimeout(), ()->{}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); Runnable run = this; new BukkitRunnable() { diff --git a/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java index 847821d..b5ad7f9 100644 --- a/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java +++ b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java @@ -1,6 +1,6 @@ package fr.leomelki.loupgarou.scoreboard; -import java.util.Arrays; +import java.util.Collections; import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; import com.comphenix.protocol.wrappers.WrappedChatComponent; @@ -29,7 +29,7 @@ public class CustomScoreboardEntry { public void show() { if(prefix != null) { WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); - team.setPlayers(Arrays.asList(name)); + team.setPlayers(Collections.singletonList(name)); team.setName(name); team.setMode(0); team.setPrefix(prefix); @@ -77,7 +77,7 @@ public class CustomScoreboardEntry { show(); else { WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); - team.setPlayers(Arrays.asList(name)); + team.setPlayers(Collections.singletonList(name)); team.setName(name); team.setMode(2); team.setPrefix(prefix); diff --git a/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java b/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java index 1c75c9b..789bd65 100644 --- a/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java +++ b/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java @@ -7,14 +7,11 @@ import java.util.Map.Entry; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; public class MultipleValueMap { private final HashMap> map = new HashMap<>(); public void put(K key, V value) { - List list = map.get(key); - if(list == null) - map.put(key, list = new ArrayList<>()); + List list = map.computeIfAbsent(key, k -> new ArrayList<>()); list.add(value); } public V remove(K key, V value) { @@ -43,10 +40,10 @@ public class MultipleValueMap { return map.containsKey(key) ? map.get(key).get(0) : null; } public List> entrySet(){ - ArrayList> toReturn = new ArrayList>(); + ArrayList> toReturn = new ArrayList<>(); for(Entry> entry : map.entrySet()) for(V v : entry.getValue()) - toReturn.add(new MultipleValueKeyEntry(entry.getKey(), v)); + toReturn.add(new MultipleValueKeyEntry<>(entry.getKey(), v)); return toReturn; } diff --git a/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java b/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java index 8986e82..3280a26 100644 --- a/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java +++ b/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java @@ -3,7 +3,7 @@ package fr.leomelki.loupgarou.utils; import java.util.HashMap; public class VariableCache { - private final HashMap cache = new HashMap(); + private final HashMap cache = new HashMap<>(); public boolean getBoolean(String key) { Object object = get(key); return object != null && (boolean) object;