diff --git a/src/main/java/fr/leomelki/loupgarou/MainLg.java b/src/main/java/fr/leomelki/loupgarou/MainLg.java index 74e9e3c..af3b20f 100644 --- a/src/main/java/fr/leomelki/loupgarou/MainLg.java +++ b/src/main/java/fr/leomelki/loupgarou/MainLg.java @@ -104,6 +104,8 @@ public void onEnable() { saveConfig(); } loadConfig(); + Bukkit.getConsoleSender().sendMessage("/"); + Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(getRoles()), this); Bukkit.getPluginManager().registerEvents(new JoinListener(), this); Bukkit.getPluginManager().registerEvents(new CancelListener(), this); Bukkit.getPluginManager().registerEvents(new VoteListener(), this); @@ -213,6 +215,22 @@ public void onPacketSending(PacketEvent event) { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(label.equalsIgnoreCase("lg")) { + if(args[0].equalsIgnoreCase("roles") && args.length == 1){ + sender.sendMessage(prefix + "§6Voici la liste des rôles:"); + int index = 0; + for (String role : getRoles().keySet()) + if (MainLg.getInstance().getConfig().getInt("role." + role) > 0) { + sender.sendMessage(prefix + " §e- §6" + role + " §e: " + MainLg.getInstance().getConfig().getInt("role." + role)); + } + } else if (args[0].equalsIgnoreCase("roles") && args.length == 2){ + if(args[1].equalsIgnoreCase("list")){ + sender.sendMessage(prefix + "§6Voici la liste des rôles:"); + int index = 0; + for (String role : getRoles().keySet()) + sender.sendMessage(prefix + " §e- " + index++ + " - §6" + role + " §e> " + MainLg.getInstance().getConfig().getInt("role." + role)); + sender.sendMessage("\n" + prefix + " §7Écrivez §8§o/lg roles set §7 pour définir le nombre de joueurs qui devrons avoir ce rôle."); + } + } if(!sender.hasPermission("loupgarou.admin")) { sender.sendMessage(prefix+"§4Erreur: Vous n'avez pas la permission..."); return true; @@ -275,8 +293,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St }else if(args[0].equalsIgnoreCase("joinall")) { for(Player p : Bukkit.getOnlinePlayers()) Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "joinall")); - for(Player p : Bukkit.getOnlinePlayers()) + for(Player p : Bukkit.getOnlinePlayers()){ Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "joinall")); + if(p.getPlayer().hasPermission("loupgarou.admin")){ + p.getPlayer().getInventory().setItem(1,new ItemBuilder(Material.ENDER_EYE).setName("Choisir les rôles").build()); + p.getPlayer().getInventory().setItem(3,new ItemBuilder(Material.EMERALD).setName("Lancer la partie").build()); + } + } return true; }else if(args[0].equalsIgnoreCase("reloadPacks")) { for(Player p : Bukkit.getOnlinePlayers()) @@ -305,13 +328,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } return true; }else if(args[0].equalsIgnoreCase("roles")) { - if(args.length == 1 || args[1].equalsIgnoreCase("list")) { - sender.sendMessage(prefix+"§6Voici la liste des rôles:"); - int index = 0; - for(String role : getRoles().keySet()) - sender.sendMessage(prefix+" §e- "+index+++" - §6"+role+" §e> "+MainLg.getInstance().getConfig().getInt("role."+role)); - sender.sendMessage("\n"+prefix+" §7Écrivez §8§o/lg roles set §7 pour définir le nombre de joueurs qui devrons avoir ce rôle."); - } else { + if(args.length != 1 && !args[1].equalsIgnoreCase("list")) { if(args[1].equalsIgnoreCase("set") && args.length == 4) { String role = null; if(args[2].length() <= 2) diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java index db9bb9d..78cc782 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java @@ -664,6 +664,10 @@ public void endGame(LGWinType winType) { team.setName("you_are"); team.sendPacket(lgp.getPlayer()); LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); + if(lgp.getPlayer().hasPermission("loupgarou.admin")){ + lgp.getPlayer().getInventory().setItem(1,new ItemBuilder(Material.ENDER_EYE).setName("Choisir les rôles").build()); + lgp.getPlayer().getInventory().setItem(3,new ItemBuilder(Material.EMERALD).setName("Lancer la partie").build()); + } } //A remettre pour activer le démarrage automatique /* wait(30, ()->{ diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java index 5d5f25f..5d1042b 100644 --- a/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java +++ b/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -67,6 +68,10 @@ public void onResoucePack(PlayerResourcePackStatusEvent e) { LGPlayer lgp = LGPlayer.thePlayer(p); lgp.showView(); lgp.join(MainLg.getInstance().getCurrentGame()); + if(p.hasPermission("loupgarou.admin")){ + p.getInventory().setItem(1,new fr.leomelki.loupgarou.utils.ItemBuilder(Material.ENDER_EYE).setName("Choisir les rôles").build()); + p.getInventory().setItem(3,new fr.leomelki.loupgarou.utils.ItemBuilder(Material.EMERALD).setName("Lancer la partie").build()); + } }else if(e.getStatus() == Status.DECLINED || e.getStatus() == Status.FAILED_DOWNLOAD) e.getPlayer().kickPlayer(MainLg.getPrefix()+"§cIl vous faut le resourcepack pour jouer ! ("+e.getStatus()+")"); } diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/PlayerInteractListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/PlayerInteractListener.java new file mode 100644 index 0000000..a90d727 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/PlayerInteractListener.java @@ -0,0 +1,86 @@ +package fr.leomelki.loupgarou.listeners; + +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.roles.Role; +import fr.leomelki.loupgarou.utils.ItemBuilder; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Constructor; +import java.util.HashMap; + +public class PlayerInteractListener implements Listener { + + @Getter + private HashMap> roles = new HashMap>(); + public PlayerInteractListener(HashMap> roles) { + this.roles = roles; + } + + @EventHandler + public void onInteract(PlayerInteractEvent e){ + int index = 0; + ItemStack item = e.getItem(); + + if(item == null) return; + + if(item.getType().equals(Material.ENDER_EYE)){ + Player p = e.getPlayer(); + + Inventory gui = Bukkit.createInventory(null, 4*9, "Rôles"); + for (String role : getRoles().keySet()) + gui.setItem(index++, new ItemBuilder(Material.HEART_OF_THE_SEA).setName(role).build()); + gui.setItem(35, new ItemBuilder(Material.GOLD_NUGGET).setName("Valider").build()); + p.openInventory(gui); + } else if (item.getType().equals(Material.EMERALD)){ + Bukkit.dispatchCommand(e.getPlayer(), "lg start " + e.getPlayer().getDisplayName()); + } + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e){ + Player p = (Player) e.getWhoClicked(); + if(e.getView().getTitle().equals("Rôles")){ + int index = 0; + Integer n = null; + + if(e.getCurrentItem().getType() == Material.GOLD_NUGGET){ + for (Player pl : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(pl, "joinall")); + for (Player pl : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(pl, "joinall")); + p.getInventory().setItem(3,new ItemBuilder(Material.EMERALD).setName("Lancer la partie").build()); + p.getInventory().setItem(1,new ItemBuilder(Material.ENDER_EYE).setName("Choisir les rôles").build()); + } else if(e.isLeftClick()){ + for(String role : getRoles().keySet()){ + if(role.equals(e.getCurrentItem().getItemMeta().getDisplayName())){ + n = MainLg.getInstance().getConfig().getInt("role." + role); + Bukkit.dispatchCommand(p, "lg roles set " + index + " " + (n+1)); + return; + } + index++; + } + } else if(e.isRightClick()){ + for(String role : getRoles().keySet()){ + if(role.equals(e.getCurrentItem().getItemMeta().getDisplayName())){ + n = MainLg.getInstance().getConfig().getInt("role." + role); + if(n > 0) + Bukkit.dispatchCommand(p, "lg roles set " + index + " " + (n-1)); + return; + } + index++; + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/utils/ItemBuilder.java b/src/main/java/fr/leomelki/loupgarou/utils/ItemBuilder.java new file mode 100644 index 0000000..4bbd27b --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/utils/ItemBuilder.java @@ -0,0 +1,78 @@ +package fr.leomelki.loupgarou.utils; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.beans.ConstructorProperties; + +public class ItemBuilder implements Cloneable { + private ItemStack is; + + /** + * Create a new ItemBuilder from scratch. + * + * @param material The material to create the ItemBuilder with. + */ + @ConstructorProperties({"material"}) + public ItemBuilder(Material material) + { + this(material, 1); + } + + /** + * Create a new ItemBuilder over an existing itemstack. + * + * @param is The itemstack to create the ItemBuilder over. + */ + public ItemBuilder(ItemStack is) + { + this.is = is; + } + + /** + * Create a new ItemBuilder from scratch. + * + * @param m The material of the item. + * @param amount The amount of the item. + */ + public ItemBuilder(Material m, int amount) + { + is = new ItemStack(m, amount); + } + + /** + * Clone the ItemBuilder into a new one. + * + * @return The cloned instance. + */ + @Override + public ItemBuilder clone() + { + return new ItemBuilder(is); + } + + /** + * Set the displayname of the item. + * + * @param name The name to change it to. + * @return + */ + public ItemBuilder setName(String name) + { + ItemMeta im = is.getItemMeta(); + im.setDisplayName(name); + is.setItemMeta(im); + return this; + } + + /** + * Retrieves the itemstack from the ItemBuilder. + * + * @return The itemstack created/modified by the ItemBuilder instance. + */ + public ItemStack build() + { + return is; + } +}