diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e673c30 --- /dev/null +++ b/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..4b71c21 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + LoupGarou + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2cb5633 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +## Table des matières + +- [À propos](#à-propos) +- [Installation](#installation) + - [Dépendances requises](#dépendances-requises) +- [Commandes](#commandes) +- [Crédits](#crédits) +- [Aide](#aide) + - [Questions fréquentes](#questions-fréquentes) + +## À propos + +Le mode Loup-Garou est un mode inspiré du jeu de société [Les Loups-Garous de Thiercelieux](https://fr.wikipedia.org/wiki/Les_Loups-garous_de_Thiercelieux) reprenant son fonctionnement ainsi que sa manière d'être joué, à la seule différence qu'aucun maître du jeu n'est requis, le déroulement de chaque partie étant entièrement automatisé : + +- Déroulement de la partie automatisé +- Rôles du jeu de base, et nouveaux rôles +- Utilisable sur n'importe quelle map + +## Installation + +**Minecraft 1.15.1 est requis.** +Déplacez simplement le plugin compilé [LoupGarou.jar](https://github.com/leomelki/LoupGarou/releases) dans le dossier `plugins` de votre serveur avant de le redémarrer. + +### Dépendances requises + +- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) + +## Commandes + +`/lg roles` : Retourne la liste des rôles dans la partie +`/lg roles set ` : Définit le nombre de joueurs pour un certain rôle +`/lg addSpawn` : Ajoute un point de spawn (emplacement de joueur) +`/lg start ` : Lance la partie +`/lg end ` : Arrête une partie +`/lg reloadConfig` : Recharge la configuration +`/lg joinAll` : À utiliser après avoir changé les rôles + +## Crédits + +- Chef de Projet : [Shytoos](https://twitter.com/shytoos_) +- Développement : [Leomelki](https://twitter.com/leomelki) +- Mapping : [Cosii](https://www.youtube.com/channel/UCwyOcA41QSk590fl9L0ys8A) + +## Aide + +Par soucis de temps, nous ne pouvons pas faire de support au cas par cas, mais vous pouvez rejoindre notre serveur [Discord](https://discord.gg/Squeezie) pour trouver de l'aide auprès de la communauté. + +### Questions fréquentes + +- Que faire en cas de problème d'affichage (votes bloqués au dessus des têtes, etc...) ? + +Cela arrive après avoir `reload` au cours d'une partie, tous les joueurs qui ont ce problème doivent se déconnecter et se reconnecter. + +- Pourquoi la partie ne se lance pas ? + +Il faut taper la commande `/lg start ` en mettant le pseudo d'un des joueurs qui sera présent dans la partie. Si cela ne fonctionne toujours pas, c'est parce qu'il n'y a pas suffisamment de rôles pour le nombre de joueurs, il doit y avoir le même nombre de rôles qu'il y aura de joueurs dans la partie. N'oubliez pas de taper `/lg joinAll` après avoir modifié la liste des rôles. + +- J'ai mal placés mes spawns ou je veux utiliser une nouvelle map, comment faire ? + +Il suffit d'ouvrir le fichier `plugins\LoupGarou\config.yml` et de supprimer les points de spawn. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2b7d444 --- /dev/null +++ b/pom.xml @@ -0,0 +1,90 @@ + + 4.0.0 + fr.leomelki + LoupGarou + 0.0.1-SNAPSHOT + + UTF-8 + UTF-8 + + + src + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-assembly-plugin + + ${project.java.version} + ${project.java.version} + ${project.build.sourceEncoding} + + jar-with-dependencies + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.0.2 + + ${project.build.sourceEncoding} + + + + + + src/main/java + + plugin.yml + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + dmulloy2-repo + http://repo.dmulloy2.net/nexus/repository/public/ + + + + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + + + + + org.spigotmc + spigot + 1.15.1-R0.1-SNAPSHOT + provided + + + org.json + json + 20180813 + + + com.comphenix.protocol + ProtocolLib + 4.4.0 + + + org.projectlombok + lombok + 1.18.10 + provided + + + \ No newline at end of file diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/AbstractPacket.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/AbstractPacket.java new file mode 100644 index 0000000..e81d3c2 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/AbstractPacket.java @@ -0,0 +1,116 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.entity.Player; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.google.common.base.Objects; + +public abstract class AbstractPacket { + // The packet we will be modifying + protected PacketContainer handle; + + /** + * Constructs a new strongly typed wrapper for the given packet. + * + * @param handle - handle to the raw packet data. + * @param type - the packet type. + */ + protected AbstractPacket(PacketContainer handle, PacketType type) { + // Make sure we're given a valid packet + if (handle == null) + throw new IllegalArgumentException("Packet handle cannot be NULL."); + if (!Objects.equal(handle.getType(), type)) + throw new IllegalArgumentException(handle.getHandle() + + " is not a packet of type " + type); + + this.handle = handle; + } + + /** + * Retrieve a handle to the raw packet data. + * + * @return Raw packet data. + */ + public PacketContainer getHandle() { + return handle; + } + + /** + * Send the current packet to the given receiver. + * + * @param receiver - the receiver. + * @throws RuntimeException If the packet cannot be sent. + */ + public void sendPacket(Player receiver) { + if(receiver == null) + return; + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, + getHandle()); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot send packet.", e); + } + } + + /** + * Send the current packet to all online players. + */ + public void broadcastPacket() { + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException If the packet cannot be received. + * @deprecated Misspelled. recieve to receive + * @see #receivePacket(Player) + */ + @Deprecated + public void recievePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot recieve packet.", e); + } + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException if the packet cannot be received. + */ + public void receivePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot receive packet.", e); + } + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/PacketWrapper.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/PacketWrapper.java new file mode 100644 index 0000000..27f1052 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/PacketWrapper.java @@ -0,0 +1,28 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.plugin.java.JavaPlugin; + +public class PacketWrapper extends JavaPlugin { + @Override + public void onEnable() { + // We don't really do much ... + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerChat.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerChat.java new file mode 100644 index 0000000..e335ed0 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerChat.java @@ -0,0 +1,104 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.Arrays; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.EnumWrappers.ChatType; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +public class WrapperPlayServerChat extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.CHAT; + + public WrapperPlayServerChat() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerChat(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve the chat message. + *

+ * Limited to 32767 bytes + * + * @return The current message + */ + public WrappedChatComponent getMessage() { + return handle.getChatComponents().read(0); + } + + /** + * Set the message. + * + * @param value - new value. + */ + public void setMessage(WrappedChatComponent value) { + handle.getChatComponents().write(0, value); + } + + public ChatType getChatType() { + return handle.getChatTypes().read(0); + } + + public void setChatType(ChatType type) { + handle.getChatTypes().write(0, type); + } + + /** + * Retrieve Position. + *

+ * Notes: 0 - Chat (chat box) ,1 - System Message (chat box), 2 - Above + * action bar + * + * @return The current Position + * @deprecated Magic values replaced by enum + */ + @Deprecated + public byte getPosition() { + Byte position = handle.getBytes().readSafely(0); + if (position != null) { + return position; + } else { + return getChatType().getId(); + } + } + + /** + * Set Position. + * + * @param value - new value. + * @deprecated Magic values replaced by enum + */ + @Deprecated + public void setPosition(byte value) { + handle.getBytes().writeSafely(0, value); + + if (EnumWrappers.getChatTypeClass() != null) + { + Arrays.stream(ChatType.values()).filter(t -> t.getId() == value).findAny() + .ifPresent(t -> handle.getChatTypes().writeSafely(0, t)); + } + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerCustomSoundEffect.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerCustomSoundEffect.java new file mode 100644 index 0000000..2cc79e6 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerCustomSoundEffect.java @@ -0,0 +1,183 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; +import com.comphenix.protocol.wrappers.MinecraftKey; + +public class WrapperPlayServerCustomSoundEffect extends AbstractPacket { + + public static final PacketType TYPE = + PacketType.Play.Server.CUSTOM_SOUND_EFFECT; + + public WrapperPlayServerCustomSoundEffect() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerCustomSoundEffect(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Sound Name. + *

+ * Notes: all known sound effect names can be seen here. + * + * @return The current Sound Name + */ + public MinecraftKey getSoundName() { + return handle.getMinecraftKeys().read(0); + } + + /** + * Set Sound Name. + * + * @param value - new value. + */ + public void setSoundName(MinecraftKey value) { + handle.getMinecraftKeys().write(0, value); + } + + /** + * Retrieve Sound Category. + *

+ * Notes: the category that this sound will be played from (current + * categories) + * + * @return The current Sound Category + */ + public SoundCategory getSoundCategory() { + return handle.getSoundCategories().read(0); + } + + /** + * Set Sound Category. + * + * @param value - new value. + */ + public void setSoundCategory(SoundCategory value) { + handle.getSoundCategories().write(0, value); + } + + /** + * Retrieve Effect Position X. + *

+ * Notes: effect X multiplied by 8 (fixed-point number with only 3 bits + * dedicated to the fractional part) + * + * @return The current Effect Position X + */ + public int getX() { + return handle.getIntegers().read(0); + } + + /** + * Set Effect Position X. + * + * @param value - new value. + */ + public void setX(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Effect Position Y. + *

+ * Notes: effect Y multiplied by 8 (fixed-point number with only 3 bits + * dedicated to the fractional part) + * + * @return The current Effect Position Y + */ + public int getY() { + return handle.getIntegers().read(1); + } + + /** + * Set Effect Position Y. + * + * @param value - new value. + */ + public void setY(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Effect Position Z. + *

+ * Notes: effect Z multiplied by 8 (fixed-point number with only 3 bits + * dedicated to the fractional part) + * + * @return The current Effect Position Z + */ + public int getZ() { + return handle.getIntegers().read(2); + } + + /** + * Set Effect Position Z. + * + * @param value - new value. + */ + public void setZ(int value) { + handle.getIntegers().write(2, value); + } + + /** + * Retrieve Volume. + *

+ * Notes: 1 is 100%, can be more + * + * @return The current Volume + */ + public float getVolume() { + return handle.getFloat().read(0); + } + + /** + * Set Volume. + * + * @param value - new value. + */ + public void setVolume(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Pitch. + *

+ * Notes: 63 is 100%, can be more + * + * @return The current Pitch + */ + public float getPitch() { + return handle.getFloat().read(1); + } + + /** + * Set Pitch. + * + * @param value - new value. + */ + public void setPitch(float value) { + handle.getFloat().write(1, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntity.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntity.java new file mode 100644 index 0000000..6070a9d --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntity.java @@ -0,0 +1,79 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; + +public class WrapperPlayServerEntity extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.ENTITY; + + public WrapperPlayServerEntity() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntity(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java new file mode 100644 index 0000000..89523f7 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java @@ -0,0 +1,67 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerEntityDestroy extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY; + + public WrapperPlayServerEntityDestroy() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityDestroy(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Count. + *

+ * Notes: length of following array + * + * @return The current Count + */ + public int getCount() { + return handle.getIntegerArrays().read(0).length; + } + + /** + * Retrieve Entity IDs. + *

+ * Notes: the list of entities of destroy + * + * @return The current Entity IDs + */ + public int[] getEntityIDs() { + return handle.getIntegerArrays().read(0); + } + + /** + * Set Entity IDs. + * + * @param value - new value. + */ + public void setEntityIds(int[] value) { + handle.getIntegerArrays().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityEquipment.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityEquipment.java new file mode 100644 index 0000000..6b07fe1 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityEquipment.java @@ -0,0 +1,110 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; + +public class WrapperPlayServerEntityEquipment extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.ENTITY_EQUIPMENT; + + public WrapperPlayServerEntityEquipment() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityEquipment(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + public ItemSlot getSlot() { + return handle.getItemSlots().read(0); + } + + public void setSlot(ItemSlot value) { + handle.getItemSlots().write(0, value); + } + + /** + * Retrieve Item. + *

+ * Notes: item in slot format + * + * @return The current Item + */ + public ItemStack getItem() { + return handle.getItemModifier().read(0); + } + + /** + * Set Item. + * + * @param value - new value. + */ + public void setItem(ItemStack value) { + handle.getItemModifier().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityLook.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityLook.java new file mode 100644 index 0000000..2445f3d --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityLook.java @@ -0,0 +1,133 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; + +public class WrapperPlayServerEntityLook extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.ENTITY_LOOK; + + public WrapperPlayServerEntityLook() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityLook(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Retrieve the yaw of the current entity. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getBytes().read(0) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the current entity. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the pitch of the current entity. + * + * @return The current pitch + */ + public float getPitch() { + return (handle.getBytes().read(1) * 360.F) / 256.0F; + } + + /** + * Set the pitch of the current entity. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve On Ground. + * + * @return The current On Ground + */ + public boolean getOnGround() { + return handle.getBooleans().read(0); + } + + /** + * Set On Ground. + * + * @param value - new value. + */ + public void setOnGround(boolean value) { + handle.getBooleans().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityMetadata.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityMetadata.java new file mode 100644 index 0000000..0a6f57a --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityMetadata.java @@ -0,0 +1,101 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.List; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.WrappedWatchableObject; + +public class WrapperPlayServerEntityMetadata extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.ENTITY_METADATA; + + public WrapperPlayServerEntityMetadata() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityMetadata(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Retrieve Metadata. + * + * @return The current Metadata + */ + public List getMetadata() { + return handle.getWatchableCollectionModifier().read(0); + } + + /** + * Set Metadata. + * + * @param value - new value. + */ + public void setMetadata(List value) { + handle.getWatchableCollectionModifier().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityTeleport.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityTeleport.java new file mode 100644 index 0000000..49f9f96 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerEntityTeleport.java @@ -0,0 +1,146 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; + +public class WrapperPlayServerEntityTeleport extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.ENTITY_TELEPORT; + + public WrapperPlayServerEntityTeleport() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityTeleport(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve entity ID. + * + * @return The current EID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity. + * + * @param world - the current world of the entity. + * @return The entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity. + * + * @param event - the packet event. + * @return The entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + public double getX() { + return handle.getDoubles().read(0); + } + + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + public double getY() { + return handle.getDoubles().read(1); + } + + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + public double getZ() { + return handle.getDoubles().read(2); + } + + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve the yaw of the current entity. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getBytes().read(0) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the current entity. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the pitch of the current entity. + * + * @return The current pitch + */ + public float getPitch() { + return (handle.getBytes().read(1) * 360.F) / 256.0F; + } + + /** + * Set the pitch of the current entity. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); + } + + public boolean getOnGround() { + return handle.getBooleans().read(0); + } + + public void setOnGround(boolean value) { + handle.getBooleans().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerExperience.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerExperience.java new file mode 100644 index 0000000..8526374 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerExperience.java @@ -0,0 +1,92 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerExperience extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.EXPERIENCE; + + public WrapperPlayServerExperience() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerExperience(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Experience bar. + *

+ * Notes: between 0 and 1 + * + * @return The current Experience bar + */ + public float getExperienceBar() { + return handle.getFloat().read(0); + } + + /** + * Set Experience bar. + * + * @param value - new value. + */ + public void setExperienceBar(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Level. + * + * @return The current Level + */ + public int getLevel() { + return handle.getIntegers().read(1); + } + + /** + * Set Level. + * + * @param value - new value. + */ + public void setLevel(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Total Experience. + * + * @return The current Total Experience + */ + public int getTotalExperience() { + return handle.getIntegers().read(0); + } + + /** + * Set Total Experience. + * + * @param value - new value. + */ + public void setTotalExperience(int value) { + handle.getIntegers().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerHeldItemSlot.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerHeldItemSlot.java new file mode 100644 index 0000000..e56fb02 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerHeldItemSlot.java @@ -0,0 +1,56 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerHeldItemSlot extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.HELD_ITEM_SLOT; + + public WrapperPlayServerHeldItemSlot() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerHeldItemSlot(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Slot. + *

+ * Notes: the slot which the player has selected (0-8) + * + * @return The current Slot + */ + public int getSlot() { + return handle.getIntegers().read(0); + } + + /** + * Set Slot. + * + * @param value - new value. + */ + public void setSlot(int value) { + handle.getIntegers().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java new file mode 100644 index 0000000..2c20ffb --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java @@ -0,0 +1,204 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.UUID; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; + +public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.NAMED_ENTITY_SPAWN; + + public WrapperPlayServerNamedEntitySpawn() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Retrieve Player UUID. + *

+ * Notes: player's UUID + * + * @return The current Player UUID + */ + public UUID getPlayerUUID() { + return handle.getUUIDs().read(0); + } + + /** + * Set Player UUID. + * + * @param value - new value. + */ + public void setPlayerUUID(UUID value) { + handle.getUUIDs().write(0, value); + } + + /** + * Retrieve the position of the spawned entity as a vector. + * + * @return The position as a vector. + */ + public Vector getPosition() { + return new Vector(getX(), getY(), getZ()); + } + + /** + * Set the position of the spawned entity using a vector. + * + * @param position - the new position. + */ + public void setPosition(Vector position) { + setX(position.getX()); + setY(position.getY()); + setZ(position.getZ()); + } + + public double getX() { + return handle.getDoubles().read(0); + } + + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + public double getY() { + return handle.getDoubles().read(1); + } + + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + public double getZ() { + return handle.getDoubles().read(2); + } + + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve the yaw of the spawned entity. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getBytes().read(0) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the spawned entity. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the pitch of the spawned entity. + * + * @return The current pitch + */ + public float getPitch() { + return (handle.getBytes().read(1) * 360.F) / 256.0F; + } + + /** + * Set the pitch of the spawned entity. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve Metadata. + *

+ * Notes: the client will crash if no metadata is sent + * + * @return The current Metadata + */ + public WrappedDataWatcher getMetadata() { + return handle.getDataWatcherModifier().read(0); + } + + /** + * Set Metadata. + * + * @param value - new value. + */ + public void setMetadata(WrappedDataWatcher value) { + handle.getDataWatcherModifier().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedSoundEffect.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedSoundEffect.java new file mode 100644 index 0000000..c124ee2 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerNamedSoundEffect.java @@ -0,0 +1,156 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.Sound; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; + +public class WrapperPlayServerNamedSoundEffect extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.NAMED_SOUND_EFFECT; + + public WrapperPlayServerNamedSoundEffect() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerNamedSoundEffect(PacketContainer packet) { + super(packet, TYPE); + } + + public Sound getSoundEffect() { + return handle.getSoundEffects().read(0); + } + + public void setSoundEffect(Sound value) { + handle.getSoundEffects().write(0, value); + } + + public SoundCategory getSoundCategory() { + return handle.getSoundCategories().read(0); + } + + public void setSoundCategory(SoundCategory value) { + handle.getSoundCategories().write(0, value); + } + + /** + * Retrieve Effect position X. + *

+ * Notes: effect X multiplied by 8 + * + * @return The current Effect position X + */ + public int getEffectPositionX() { + return handle.getIntegers().read(0); + } + + /** + * Set Effect position X. + * + * @param value - new value. + */ + public void setEffectPositionX(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Effect position Y. + *

+ * Notes: effect Y multiplied by 8 + * + * @return The current Effect position Y + */ + public int getEffectPositionY() { + return handle.getIntegers().read(1); + } + + /** + * Set Effect position Y. + * + * @param value - new value. + */ + public void setEffectPositionY(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Effect position Z. + *

+ * Notes: effect Z multiplied by 8 + * + * @return The current Effect position Z + */ + public int getEffectPositionZ() { + return handle.getIntegers().read(2); + } + + /** + * Set Effect position Z. + * + * @param value - new value. + */ + public void setEffectPositionZ(int value) { + handle.getIntegers().write(2, value); + } + + /** + * Retrieve Volume. + *

+ * Notes: 1 is 100%, can be more + * + * @return The current Volume + */ + public float getVolume() { + return handle.getFloat().read(0); + } + + /** + * Set Volume. + * + * @param value - new value. + */ + public void setVolume(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Pitch. + *

+ * Notes: 63 is 100%, can be more + * + * @return The current Pitch + */ + public float getPitch() { + return handle.getFloat().read(1); + } + + /** + * Set Pitch. + * + * @param value - new value. + */ + public void setPitch(float value) { + handle.getFloat().write(1, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java new file mode 100644 index 0000000..7d51070 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java @@ -0,0 +1,55 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.List; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; +import com.comphenix.protocol.wrappers.PlayerInfoData; + +public class WrapperPlayServerPlayerInfo extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO; + + public WrapperPlayServerPlayerInfo() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerPlayerInfo(PacketContainer packet) { + super(packet, TYPE); + } + + public PlayerInfoAction getAction() { + return handle.getPlayerInfoAction().read(0); + } + + public void setAction(PlayerInfoAction value) { + handle.getPlayerInfoAction().write(0, value); + } + + public List getData() { + return handle.getPlayerInfoDataLists().read(0); + } + + public void setData(List value) { + handle.getPlayerInfoDataLists().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPosition.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPosition.java new file mode 100644 index 0000000..0f05436 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerPosition.java @@ -0,0 +1,161 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.Set; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.utility.MinecraftReflection; +import com.comphenix.protocol.wrappers.EnumWrappers; + +public class WrapperPlayServerPosition extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.POSITION; + + public WrapperPlayServerPosition() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerPosition(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve X. + *

+ * Notes: absolute/Relative position + * + * @return The current X + */ + public double getX() { + return handle.getDoubles().read(0); + } + + /** + * Set X. + * + * @param value - new value. + */ + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + /** + * Retrieve Y. + *

+ * Notes: absolute/Relative position + * + * @return The current Y + */ + public double getY() { + return handle.getDoubles().read(1); + } + + /** + * Set Y. + * + * @param value - new value. + */ + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + /** + * Retrieve Z. + *

+ * Notes: absolute/Relative position + * + * @return The current Z + */ + public double getZ() { + return handle.getDoubles().read(2); + } + + /** + * Set Z. + * + * @param value - new value. + */ + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve Yaw. + *

+ * Notes: absolute/Relative rotation on the X Axis, in degrees + * + * @return The current Yaw + */ + public float getYaw() { + return handle.getFloat().read(0); + } + + /** + * Set Yaw. + * + * @param value - new value. + */ + public void setYaw(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Pitch. + *

+ * Notes: absolute/Relative rotation on the Y Axis, in degrees + * + * @return The current Pitch + */ + public float getPitch() { + return handle.getFloat().read(1); + } + + /** + * Set Pitch. + * + * @param value - new value. + */ + public void setPitch(float value) { + handle.getFloat().write(1, value); + } + + private static final Class FLAGS_CLASS = MinecraftReflection + .getMinecraftClass("EnumPlayerTeleportFlags", + "PacketPlayOutPosition$EnumPlayerTeleportFlags"); + + public enum PlayerTeleportFlag { + X, Y, Z, Y_ROT, X_ROT + } + + private StructureModifier> getFlagsModifier() { + return handle.getSets( + EnumWrappers.getGenericConverter(FLAGS_CLASS, PlayerTeleportFlag.class)); + } + + public Set getFlags() { + return getFlagsModifier().read(0); + } + + public void setFlags(Set value) { + getFlagsModifier().write(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerRespawn.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerRespawn.java new file mode 100644 index 0000000..2e7ab88 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerRespawn.java @@ -0,0 +1,121 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import org.bukkit.WorldType; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; +import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; + +public class WrapperPlayServerRespawn extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; + + public WrapperPlayServerRespawn() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerRespawn(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Dimension. + *

+ * Notes: -1: The Nether, 0: The Overworld, 1: The End + * + * @return The current Dimension + */ + public int getDimension() { + return handle.getIntegers().read(0); + } + + /** + * Set Dimension. + * + * @param value - new value. + */ + public void setDimension(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Difficulty. + *

+ * Notes: 0 thru 3 for Peaceful, Easy, Normal, Hard. + * + * @return The current Difficulty + */ + public Difficulty getDifficulty() { + return handle.getDifficulties().read(0); + } + + /** + * Set Difficulty. + * + * @param value - new value. + */ + public void setDifficulty(Difficulty value) { + handle.getDifficulties().write(0, value); + } + + /** + * Retrieve Gamemode. + *

+ * Notes: 0: survival, 1: creative, 2: adventure. The hardcore flag is not + * included + * + * @return The current Gamemode + */ + public NativeGameMode getGamemode() { + return handle.getGameModes().read(0); + } + + /** + * Set Gamemode. + * + * @param value - new value. + */ + public void setGamemode(NativeGameMode value) { + handle.getGameModes().write(0, value); + } + + /** + * Retrieve Level Type. + *

+ * Notes: same as Join Game + * + * @return The current Level Type + */ + public WorldType getLevelType() { + return handle.getWorldTypeModifier().read(0); + } + + /** + * Set Level Type. + * + * @param value - new value. + */ + public void setLevelType(WorldType value) { + handle.getWorldTypeModifier().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardDisplayObjective.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardDisplayObjective.java new file mode 100644 index 0000000..af9d950 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardDisplayObjective.java @@ -0,0 +1,78 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerScoreboardDisplayObjective extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE; + + public WrapperPlayServerScoreboardDisplayObjective() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerScoreboardDisplayObjective(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Position. + *

+ * Notes: the position of the scoreboard. 0 = list, 1 = sidebar, 2 = + * belowName. + * + * @return The current Position + */ + public int getPosition() { + return handle.getIntegers().read(0); + } + + /** + * Set Position. + * + * @param value - new value. + */ + public void setPosition(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Score Name. + *

+ * Notes: the unique name for the scoreboard to be displayed. + * + * @return The current Score Name + */ + public String getScoreName() { + return handle.getStrings().read(0); + } + + /** + * Set Score Name. + * + * @param value - new value. + */ + public void setScoreName(String value) { + handle.getStrings().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardObjective.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardObjective.java new file mode 100644 index 0000000..bd0560e --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardObjective.java @@ -0,0 +1,141 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.IntEnum; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +public class WrapperPlayServerScoreboardObjective extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.SCOREBOARD_OBJECTIVE; + + public WrapperPlayServerScoreboardObjective() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerScoreboardObjective(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Enum containing all known packet modes. + * + * @author dmulloy2 + */ + public static class Mode extends IntEnum { + public static final int ADD_OBJECTIVE = 0; + public static final int REMOVE_OBJECTIVE = 1; + public static final int UPDATE_VALUE = 2; + + private static final Mode INSTANCE = new Mode(); + + public static Mode getInstance() { + return INSTANCE; + } + } + + /** + * Retrieve Objective name. + *

+ * Notes: an unique name for the objective + * + * @return The current Objective name + */ + public String getName() { + return handle.getStrings().read(0); + } + + /** + * Set Objective name. + * + * @param value - new value. + */ + public void setName(String value) { + handle.getStrings().write(0, value); + } + + /** + * Retrieve Objective DisplayName. + *

+ * Notes: only if mode is 0 or 2. The text to be displayed for the score. + * + * @return The current Objective value + */ + public WrappedChatComponent getDisplayName() { + return handle.getChatComponents().read(0); + } + + /** + * Set Objective DisplayName. + * + * @param value - new value. + */ + public void setDisplayName(WrappedChatComponent value) { + handle.getChatComponents().write(0, value); + } + + /** + * Retrieve health display. + *

+ * Notes: Can be either INTEGER or HEARTS + * + * @return the current health display value + */ + public HealthDisplay getHealthDisplay() { + return handle.getEnumModifier(HealthDisplay.class, 2).read(0); + } + + /** + * Set health display. + * + * @param value - value + * @see #getHealthDisplay() + */ + public void setHealthDisplay(HealthDisplay value) { + handle.getEnumModifier(HealthDisplay.class, 2).write(0, value); + } + + /** + * Retrieve Mode. + *

+ * Notes: 0 to create the scoreboard. 1 to remove the scoreboard. 2 to + * update the display text. + * + * @return The current Mode + */ + public int getMode() { + return handle.getIntegers().read(0); + } + + /** + * Set Mode. + * + * @param value - new value. + */ + public void setMode(int value) { + handle.getIntegers().write(0, value); + } + + public enum HealthDisplay { + INTEGER, HEARTS + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardScore.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardScore.java new file mode 100644 index 0000000..4fc86a6 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardScore.java @@ -0,0 +1,107 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; + +public class WrapperPlayServerScoreboardScore extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.SCOREBOARD_SCORE; + + public WrapperPlayServerScoreboardScore() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerScoreboardScore(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Score name. + *

+ * Notes: the name of the score to be updated or removed. + * + * @return The current Score name + */ + public String getScoreName() { + return handle.getStrings().read(0); + } + + /** + * Set Score name. + * + * @param value - new value. + */ + public void setScoreName(String value) { + handle.getStrings().write(0, value); + } + + /** + * Retrieve Objective Name. + *

+ * Notes: the name of the objective the score belongs to. + * + * @return The current Objective Name + */ + public String getObjectiveName() { + return handle.getStrings().read(1); + } + + /** + * Set Objective Name. + * + * @param value - new value. + */ + public void setObjectiveName(String value) { + handle.getStrings().write(1, value); + } + + /** + * Retrieve Value. + *

+ * Notes: the score to be displayed next to the entry. Only sent when + * Update/Remove does not equal 1. + * + * @return The current Value + */ + public int getValue() { + return handle.getIntegers().read(0); + } + + /** + * Set Value. + * + * @param value - new value. + */ + public void setValue(int value) { + handle.getIntegers().write(0, value); + } + + public ScoreboardAction getAction() { + return handle.getScoreboardActions().read(0); + } + + public void setScoreboardAction(ScoreboardAction value) { + handle.getScoreboardActions().write(0, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardTeam.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardTeam.java new file mode 100644 index 0000000..b132a65 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerScoreboardTeam.java @@ -0,0 +1,279 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.Collection; +import java.util.List; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.IntEnum; +import com.comphenix.protocol.utility.MinecraftReflection; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +import org.bukkit.ChatColor; + +public class WrapperPlayServerScoreboardTeam extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.SCOREBOARD_TEAM; + + public WrapperPlayServerScoreboardTeam() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerScoreboardTeam(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Enum containing all known modes. + * + * @author dmulloy2 + */ + public static class Mode extends IntEnum { + public static final int TEAM_CREATED = 0; + public static final int TEAM_REMOVED = 1; + public static final int TEAM_UPDATED = 2; + public static final int PLAYERS_ADDED = 3; + public static final int PLAYERS_REMOVED = 4; + + private static final Mode INSTANCE = new Mode(); + + public static Mode getInstance() { + return INSTANCE; + } + } + + /** + * Retrieve Team Name. + *

+ * Notes: a unique name for the team. (Shared with scoreboard). + * + * @return The current Team Name + */ + public String getName() { + return handle.getStrings().read(0); + } + + /** + * Set Team Name. + * + * @param value - new value. + */ + public void setName(String value) { + handle.getStrings().write(0, value); + } + + /** + * Retrieve Team Display Name. + *

+ * Notes: only if Mode = 0 or 2. + * + * @return The current Team Display Name + */ + public WrappedChatComponent getDisplayName() { + return handle.getChatComponents().read(0); + } + + /** + * Set Team Display Name. + * + * @param value - new value. + */ + public void setDisplayName(WrappedChatComponent value) { + handle.getChatComponents().write(0, value); + } + + /** + * Retrieve Team Prefix. + *

+ * Notes: only if Mode = 0 or 2. Displayed before the players' name that are + * part of this team. + * + * @return The current Team Prefix + */ + public WrappedChatComponent getPrefix() { + return handle.getChatComponents().read(1); + } + + /** + * Set Team Prefix. + * + * @param value - new value. + */ + public void setPrefix(WrappedChatComponent value) { + handle.getChatComponents().write(1, value); + } + + /** + * Retrieve Team Suffix. + *

+ * Notes: only if Mode = 0 or 2. Displayed after the players' name that are + * part of this team. + * + * @return The current Team Suffix + */ + public WrappedChatComponent getSuffix() { + return handle.getChatComponents().read(2); + } + + /** + * Set Team Suffix. + * + * @param value - new value. + */ + public void setSuffix(WrappedChatComponent value) { + handle.getChatComponents().write(2, value); + } + + /** + * Retrieve Name Tag Visibility. + *

+ * Notes: only if Mode = 0 or 2. always, hideForOtherTeams, hideForOwnTeam, + * never. + * + * @return The current Name Tag Visibility + */ + public String getNameTagVisibility() { + return handle.getStrings().read(1); + } + + /** + * Set Name Tag Visibility. + * + * @param value - new value. + */ + public void setNameTagVisibility(String value) { + handle.getStrings().write(1, value); + } + + /** + * Retrieve Color. + *

+ * Notes: only if Mode = 0 or 2. Same as Chat colors. + * + * @return The current Color + */ + public ChatColor getColor() { + return handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).read(0); + } + + /** + * Set Color. + * + * @param value - new value. + */ + public void setColor(ChatColor value) { + handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, value); + } + + /** + * Get the collision rule. + * Notes: only if Mode = 0 or 2. always, pushOtherTeams, pushOwnTeam, never. + * @return The current collision rule + */ + public String getCollisionRule() { + return handle.getStrings().read(2); + } + + /** + * Sets the collision rule. + * @param value - new value. + */ + public void setCollisionRule(String value) { + handle.getStrings().write(2, value); + } + + /** + * Retrieve Players. + *

+ * Notes: only if Mode = 0 or 3 or 4. Players to be added/remove from the + * team. Max 40 characters so may be uuid's later + * + * @return The current Players + */ + @SuppressWarnings("unchecked") + public List getPlayers() { + return (List) handle.getSpecificModifier(Collection.class) + .read(0); + } + + /** + * Set Players. + * + * @param value - new value. + */ + public void setPlayers(List value) { + handle.getSpecificModifier(Collection.class).write(0, value); + } + + /** + * Retrieve Mode. + *

+ * Notes: if 0 then the team is created. If 1 then the team is removed. If 2 + * the team team information is updated. If 3 then new players are added to + * the team. If 4 then players are removed from the team. + * + * @return The current Mode + */ + public int getMode() { + return handle.getIntegers().read(0); + } + + /** + * Set Mode. + * + * @param value - new value. + */ + public void setMode(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve pack option data. Pack data is calculated as follows: + * + *

+	 * 
+	 * int data = 0;
+	 * if (team.allowFriendlyFire()) {
+	 *     data |= 1;
+	 * }
+	 * if (team.canSeeFriendlyInvisibles()) {
+	 *     data |= 2;
+	 * }
+	 * 
+	 * 
+ * + * @return The current pack option data + */ + public int getPackOptionData() { + return handle.getIntegers().read(1); + } + + /** + * Set pack option data. + * + * @param value - new value + * @see #getPackOptionData() + */ + public void setPackOptionData(int value) { + handle.getIntegers().write(1, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntity.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntity.java new file mode 100644 index 0000000..414b2a7 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntity.java @@ -0,0 +1,378 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.UUID; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.PacketType; +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.reflect.IntEnum; + +public class WrapperPlayServerSpawnEntity extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY; + + private static PacketConstructor entityConstructor; + + /** + * Represents the different object types. + * + * @author Kristian + */ + public static class ObjectTypes extends IntEnum { + public static final int BOAT = 1; + public static final int ITEM_STACK = 2; + public static final int AREA_EFFECT_CLOUD = 3; + public static final int MINECART = 10; + public static final int ACTIVATED_TNT = 50; + public static final int ENDER_CRYSTAL = 51; + public static final int TIPPED_ARROW_PROJECTILE = 60; + public static final int SNOWBALL_PROJECTILE = 61; + public static final int EGG_PROJECTILE = 62; + public static final int GHAST_FIREBALL = 63; + public static final int BLAZE_FIREBALL = 64; + public static final int THROWN_ENDERPEARL = 65; + public static final int WITHER_SKULL_PROJECTILE = 66; + public static final int SHULKER_BULLET = 67; + public static final int FALLING_BLOCK = 70; + public static final int ITEM_FRAME = 71; + public static final int EYE_OF_ENDER = 72; + public static final int THROWN_POTION = 73; + public static final int THROWN_EXP_BOTTLE = 75; + public static final int FIREWORK_ROCKET = 76; + public static final int LEASH_KNOT = 77; + public static final int ARMORSTAND = 78; + public static final int FISHING_FLOAT = 90; + public static final int SPECTRAL_ARROW = 91; + public static final int DRAGON_FIREBALL = 93; + + /** + * The singleton instance. Can also be retrieved from the parent class. + */ + private static ObjectTypes INSTANCE = new ObjectTypes(); + + /** + * Retrieve an instance of the object types enum. + * + * @return Object type enum. + */ + public static ObjectTypes getInstance() { + return INSTANCE; + } + } + + public WrapperPlayServerSpawnEntity() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerSpawnEntity(PacketContainer packet) { + super(packet, TYPE); + } + + public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) { + super(fromEntity(entity, type, objectData), TYPE); + } + + // Useful constructor + private static PacketContainer fromEntity(Entity entity, int type, + int objectData) { + if (entityConstructor == null) + entityConstructor = + ProtocolLibrary.getProtocolManager() + .createPacketConstructor(TYPE, entity, type, + objectData); + return entityConstructor.createPacket(entity, type, objectData); + } + + /** + * Retrieve entity ID of the Object. + * + * @return The current EID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Retrieve the entity that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Set entity ID of the Object. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + public UUID getUniqueId() { + return handle.getUUIDs().read(0); + } + + public void setUniqueId(UUID value) { + handle.getUUIDs().write(0, value); + } + + /** + * Retrieve the x position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current X + */ + public double getX() { + return handle.getDoubles().read(0); + } + + /** + * Set the x position of the object. + * + * @param value - new value. + */ + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + /** + * Retrieve the y position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current y + */ + public double getY() { + return handle.getDoubles().read(1); + } + + /** + * Set the y position of the object. + * + * @param value - new value. + */ + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + /** + * Retrieve the z position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current z + */ + public double getZ() { + return handle.getDoubles().read(2); + } + + /** + * Set the z position of the object. + * + * @param value - new value. + */ + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve the optional speed x. + *

+ * This is ignored if {@link #getObjectData()} is zero. + * + * @return The optional speed x. + */ + public double getOptionalSpeedX() { + return handle.getIntegers().read(1) / 8000.0D; + } + + /** + * Set the optional speed x. + * + * @param value - new value. + */ + public void setOptionalSpeedX(double value) { + handle.getIntegers().write(1, (int) (value * 8000.0D)); + } + + /** + * Retrieve the optional speed y. + *

+ * This is ignored if {@link #getObjectData()} is zero. + * + * @return The optional speed y. + */ + public double getOptionalSpeedY() { + return handle.getIntegers().read(2) / 8000.0D; + } + + /** + * Set the optional speed y. + * + * @param value - new value. + */ + public void setOptionalSpeedY(double value) { + handle.getIntegers().write(2, (int) (value * 8000.0D)); + } + + /** + * Retrieve the optional speed z. + *

+ * This is ignored if {@link #getObjectData()} is zero. + * + * @return The optional speed z. + */ + public double getOptionalSpeedZ() { + return handle.getIntegers().read(3) / 8000.0D; + } + + /** + * Set the optional speed z. + * + * @param value - new value. + */ + public void setOptionalSpeedZ(double value) { + handle.getIntegers().write(3, (int) (value * 8000.0D)); + } + + /** + * Retrieve the pitch. + * + * @return The current pitch. + */ + public float getPitch() { + return (handle.getIntegers().read(4) * 360.F) / 256.0F; + } + + /** + * Set the pitch. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getIntegers().write(4, (int) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the yaw. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getIntegers().read(5) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the object spawned. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getIntegers().write(5, (int) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the type of object. See {@link ObjectTypes} + * + * @return The current Type + */ + public int getType() { + return handle.getIntegers().read(6); + } + + /** + * Set the type of object. See {@link ObjectTypes}. + * + * @param value - new value. + */ + public void setType(int value) { + handle.getIntegers().write(6, value); + } + + /** + * Retrieve object data. + *

+ * The content depends on the object type: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Object Type:Name:Description
ITEM_FRAMEOrientation0-3: South, West, North, East
FALLING_BLOCKBlock TypeBlockID | (Metadata << 0xC)
ProjectilesEntity IDThe entity ID of the thrower
Splash PotionsData ValuePotion data value.
+ * + * @return The current object Data + */ + public int getObjectData() { + return handle.getIntegers().read(7); + } + + /** + * Set object Data. + *

+ * The content depends on the object type. See {@link #getObjectData()} for + * more information. + * + * @param value - new object data. + */ + public void setObjectData(int value) { + handle.getIntegers().write(7, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java new file mode 100644 index 0000000..2dda2ff --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityLiving.java @@ -0,0 +1,315 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import java.util.UUID; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import com.comphenix.protocol.PacketType; +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 = + PacketType.Play.Server.SPAWN_ENTITY_LIVING; + + private static PacketConstructor entityConstructor; + + public WrapperPlayServerSpawnEntityLiving() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerSpawnEntityLiving(PacketContainer packet) { + super(packet, TYPE); + } + + public WrapperPlayServerSpawnEntityLiving(Entity entity) { + super(fromEntity(entity), TYPE); + } + + // Useful constructor + private static PacketContainer fromEntity(Entity entity) { + if (entityConstructor == null) + entityConstructor = + ProtocolLibrary.getProtocolManager() + .createPacketConstructor(TYPE, entity); + return entityConstructor.createPacket(entity); + } + + /** + * Retrieve entity ID. + * + * @return The current EID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Retrieve the entity that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + public UUID getUniqueId() { + return handle.getUUIDs().read(0); + } + + public void setUniqueId(UUID value) { + handle.getUUIDs().write(0, value); + } + + /** + * Set entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the type of mob. + * + * @return The current Type + */ + @SuppressWarnings("deprecation") + public EntityType getType() { + return EntityType.fromId(handle.getIntegers().read(1)); + } + + /** + * Set the type of mob. + * + * @param value - new value. + */ + @SuppressWarnings("deprecation") + public void setType(EntityType value) { + handle.getIntegers().write(1, (int) value.getTypeId()); + } + + /** + * Retrieve the x position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current X + */ + public double getX() { + return handle.getDoubles().read(0); + } + + /** + * Set the x position of the object. + * + * @param value - new value. + */ + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + /** + * Retrieve the y position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current y + */ + public double getY() { + return handle.getDoubles().read(1); + } + + /** + * Set the y position of the object. + * + * @param value - new value. + */ + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + /** + * Retrieve the z position of the object. + *

+ * Note that the coordinate is rounded off to the nearest 1/32 of a meter. + * + * @return The current z + */ + public double getZ() { + return handle.getDoubles().read(2); + } + + /** + * Set the z position of the object. + * + * @param value - new value. + */ + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve the yaw. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getBytes().read(0) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the spawned mob. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the pitch. + * + * @return The current pitch + */ + public float getPitch() { + return (handle.getBytes().read(1) * 360.F) / 256.0F; + } + + /** + * Set the pitch of the spawned mob. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the yaw of the mob's head. + * + * @return The current yaw. + */ + public float getHeadPitch() { + return (handle.getBytes().read(2) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the mob's head. + * + * @param value - new yaw. + */ + public void setHeadPitch(float value) { + handle.getBytes().write(2, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the velocity in the x axis. + * + * @return The current velocity X + */ + public double getVelocityX() { + return handle.getIntegers().read(2) / 8000.0D; + } + + /** + * Set the velocity in the x axis. + * + * @param value - new value. + */ + public void setVelocityX(double value) { + handle.getIntegers().write(2, (int) (value * 8000.0D)); + } + + /** + * Retrieve the velocity in the y axis. + * + * @return The current velocity y + */ + public double getVelocityY() { + return handle.getIntegers().read(3) / 8000.0D; + } + + /** + * Set the velocity in the y axis. + * + * @param value - new value. + */ + public void setVelocityY(double value) { + handle.getIntegers().write(3, (int) (value * 8000.0D)); + } + + /** + * Retrieve the velocity in the z axis. + * + * @return The current velocity z + */ + public double getVelocityZ() { + return handle.getIntegers().read(4) / 8000.0D; + } + + /** + * Set the velocity in the z axis. + * + * @param value - new value. + */ + public void setVelocityZ(double value) { + handle.getIntegers().write(4, (int) (value * 8000.0D)); + } + + /** + * Retrieve the data watcher. + *

+ * Content varies by mob, see Entities. + * + * @return The current Metadata + */ +/* public WrappedDataWatcher getMetadata() { + return handle.getDataWatcherModifier().read(0); + }*/ + + /** + * Set the data watcher. + * + * @param value - new value. + */ + /*public void setMetadata(WrappedDataWatcher value) { + handle.getDataWatcherModifier().write(0, value); + }*/ +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerStopSound.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerStopSound.java new file mode 100644 index 0000000..b4ac3ee --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerStopSound.java @@ -0,0 +1,54 @@ +/** + * This file is part of PacketWrapper. + * Copyright (C) 2012-2015 Kristian S. Strangeland + * Copyright (C) 2015 dmulloy2 + * + * PacketWrapper is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PacketWrapper is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with PacketWrapper. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.MinecraftKey; + +public class WrapperPlayServerStopSound extends AbstractPacket { + + public static final PacketType TYPE = PacketType.Play.Server.STOP_SOUND; + + public WrapperPlayServerStopSound() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerStopSound(PacketContainer packet) { + super(packet, TYPE); + } + + public MinecraftKey getSoundEffect() { + return handle.getMinecraftKeys().readSafely(0); + } + + public void setSoundEffect(MinecraftKey value) { + handle.getMinecraftKeys().writeSafely(0, value); + } + + public EnumWrappers.SoundCategory getCategory() { + return handle.getSoundCategories().readSafely(0); + } + + public void setCategory(EnumWrappers.SoundCategory value) { + handle.getSoundCategories().writeSafely(0, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerTitle.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerTitle.java new file mode 100644 index 0000000..0f31de7 --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerTitle.java @@ -0,0 +1,131 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +public class WrapperPlayServerTitle extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.TITLE; + + public WrapperPlayServerTitle() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerTitle(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Action. + * + * @return The current Action + */ + public TitleAction getAction() { + return handle.getTitleActions().read(0); + } + + /** + * Set Action. + * + * @param value - new value. + */ + public void setAction(TitleAction value) { + handle.getTitleActions().write(0, value); + } + + /** + * Retrieve 0 (TITLE). + *

+ * Notes: chat + * + * @return The current 0 (TITLE) + */ + public WrappedChatComponent getTitle() { + return handle.getChatComponents().read(0); + } + + /** + * Set 0 (TITLE). + * + * @param value - new value. + */ + public void setTitle(WrappedChatComponent value) { + handle.getChatComponents().write(0, value); + } + + /** + * Retrieve 2 (TIMES). + *

+ * Notes: int + * + * @return The current 2 (TIMES) + */ + public int getFadeIn() { + return handle.getIntegers().read(0); + } + + /** + * Set 2 (TIMES). + * + * @param value - new value. + */ + public void setFadeIn(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Stay. + * + * @return The current Stay + */ + public int getStay() { + return handle.getIntegers().read(1); + } + + /** + * Set Stay. + * + * @param value - new value. + */ + public void setStay(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Fade Out. + * + * @return The current Fade Out + */ + public int getFadeOut() { + return handle.getIntegers().read(2); + } + + /** + * Set Fade Out. + * + * @param value - new value. + */ + public void setFadeOut(int value) { + handle.getIntegers().write(2, value); + } +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateHealth.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateHealth.java new file mode 100644 index 0000000..2a1c48f --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateHealth.java @@ -0,0 +1,96 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerUpdateHealth extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.UPDATE_HEALTH; + + public WrapperPlayServerUpdateHealth() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerUpdateHealth(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Health. + *

+ * Notes: 0 or less = dead, 20 = full HP + * + * @return The current Health + */ + public float getHealth() { + return handle.getFloat().read(0); + } + + /** + * Set Health. + * + * @param value - new value. + */ + public void setHealth(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Food. + *

+ * Notes: 0 - 20 + * + * @return The current Food + */ + public int getFood() { + return handle.getIntegers().read(0); + } + + /** + * Set Food. + * + * @param value - new value. + */ + public void setFood(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Food Saturation. + *

+ * Notes: seems to vary from 0.0 to 5.0 in integer increments + * + * @return The current Food Saturation + */ + public float getFoodSaturation() { + return handle.getFloat().read(1); + } + + /** + * Set Food Saturation. + * + * @param value - new value. + */ + public void setFoodSaturation(float value) { + handle.getFloat().write(1, value); + } + +} diff --git a/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateTime.java b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateTime.java new file mode 100644 index 0000000..49b56ef --- /dev/null +++ b/src/main/java/fr/leomelki/com/comphenix/packetwrapper/WrapperPlayServerUpdateTime.java @@ -0,0 +1,77 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.leomelki.com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class WrapperPlayServerUpdateTime extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.UPDATE_TIME; + + public WrapperPlayServerUpdateTime() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerUpdateTime(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Age of the world. + *

+ * Notes: in ticks; not changed by server commands + * + * @return The current Age of the world + */ + public long getAgeOfTheWorld() { + return handle.getLongs().read(0); + } + + /** + * Set Age of the world. + * + * @param value - new value. + */ + public void setAgeOfTheWorld(long value) { + handle.getLongs().write(0, value); + } + + /** + * Retrieve Time of day. + *

+ * Notes: the world (or region) time, in ticks. If negative the sun will + * stop moving at the Math.abs of the time + * + * @return The current Time of day + */ + public long getTimeOfDay() { + return handle.getLongs().read(1); + } + + /** + * Set Time of day. + * + * @param value - new value. + */ + public void setTimeOfDay(long value) { + handle.getLongs().write(1, value); + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/MainLg.java b/src/main/java/fr/leomelki/loupgarou/MainLg.java new file mode 100644 index 0000000..8ce4dff --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/MainLg.java @@ -0,0 +1,414 @@ +package fr.leomelki.loupgarou; + + +import java.io.File; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityEquipment; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerNamedSoundEffect; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateHealth; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateTime; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.LGWinType; +import fr.leomelki.loupgarou.events.LGSkinLoadEvent; +import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent; +import fr.leomelki.loupgarou.listeners.CancelListener; +import fr.leomelki.loupgarou.listeners.ChatListener; +import fr.leomelki.loupgarou.listeners.JoinListener; +import fr.leomelki.loupgarou.listeners.LoupGarouListener; +import fr.leomelki.loupgarou.listeners.VoteListener; +import fr.leomelki.loupgarou.roles.RAnge; +import fr.leomelki.loupgarou.roles.RAssassin; +import fr.leomelki.loupgarou.roles.RBouffon; +import fr.leomelki.loupgarou.roles.RChaperonRouge; +import fr.leomelki.loupgarou.roles.RChasseur; +import fr.leomelki.loupgarou.roles.RChienLoup; +import fr.leomelki.loupgarou.roles.RCorbeau; +import fr.leomelki.loupgarou.roles.RCupidon; +import fr.leomelki.loupgarou.roles.RDetective; +import fr.leomelki.loupgarou.roles.RDictateur; +import fr.leomelki.loupgarou.roles.REnfantSauvage; +import fr.leomelki.loupgarou.roles.RFaucheur; +import fr.leomelki.loupgarou.roles.RGarde; +import fr.leomelki.loupgarou.roles.RGrandMechantLoup; +import fr.leomelki.loupgarou.roles.RLoupGarou; +import fr.leomelki.loupgarou.roles.RLoupGarouBlanc; +import fr.leomelki.loupgarou.roles.RLoupGarouNoir; +import fr.leomelki.loupgarou.roles.RMedium; +import fr.leomelki.loupgarou.roles.RPetiteFille; +import fr.leomelki.loupgarou.roles.RPirate; +import fr.leomelki.loupgarou.roles.RPretre; +import fr.leomelki.loupgarou.roles.RPyromane; +import fr.leomelki.loupgarou.roles.RSorciere; +import fr.leomelki.loupgarou.roles.RSurvivant; +import fr.leomelki.loupgarou.roles.RVillageois; +import fr.leomelki.loupgarou.roles.RVoyante; +import fr.leomelki.loupgarou.roles.Role; +import lombok.Getter; +import lombok.Setter; + +public class MainLg extends JavaPlugin{ + private static MainLg instance; + @Getter private HashMap> roles = new HashMap>(); + @Getter private static String prefix = ""/*"§7[§9Loup-Garou§7] "*/; + + @Getter @Setter private LGGame currentGame;//Because for now, only one game will be playable on one server (flemme) + + @Override + public void onEnable() { + // Audio4WebPlugin.getMain().unRegisterPackets(); + instance = this; + loadRoles(); + if(!new File(getDataFolder(), "config.yml").exists()) {//Créer la config + FileConfiguration config = getConfig(); + config.set("spawns", new ArrayList>()); + for(String role : roles.keySet())//Nombre de participant pour chaque rôle + config.set("role."+role, 1); + saveConfig(); + } + loadConfig(); + Bukkit.getConsoleSender().sendMessage("/"); + 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 LoupGarouListener(), this); + + for(Player player : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, "is connected")); + + ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) { + @Override + public void onPacketSending(PacketEvent event) { + // if (event.getPacketType() == PacketType.Play.Server.UPDATE_TIME) { + WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket()); + LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer()); + if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay()) + event.setCancelled(true); + // } + } + } + ); + //Éviter que les gens s'entendent quand ils se sélectionnent et qu'ils sont trop proche + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_SOUND_EFFECT) { + @Override + public void onPacketSending(PacketEvent event) { + WrapperPlayServerNamedSoundEffect sound = new WrapperPlayServerNamedSoundEffect(event.getPacket()); + if(sound.getSoundEffect() == Sound.ENTITY_PLAYER_ATTACK_NODAMAGE) + event.setCancelled(true); + } + } + ); + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { + @Override + public void onPacketSending(PacketEvent event) { + // if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) { + LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket()); + ArrayList datas = new ArrayList(); + for(PlayerInfoData data : info.getData()) { + LGPlayer lgp = LGPlayer.thePlayer(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(); + Bukkit.getPluginManager().callEvent(evt2); + if(evt2.getPrefix().length() > 0) { + try { + if(displayName != null) { + JSONObject obj = (JSONObject) new JSONParser().parse(displayName.getJson()); + displayName = WrappedChatComponent.fromText(evt2.getPrefix()+obj.get("text")); + } else + displayName = WrappedChatComponent.fromText(evt2.getPrefix()+data.getProfile().getName()); + } catch (ParseException e) { + e.printStackTrace(); + } + } + LGSkinLoadEvent evt = new LGSkinLoadEvent(lgp.getGame(), lgp, player, data.getProfile()); + Bukkit.getPluginManager().callEvent(evt); + datas.add(new PlayerInfoData(evt.getProfile(), data.getLatency(), data.getGameMode(), displayName)); + }else + datas.add(data); + } + info.setData(datas); + // } + } + }); + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) { + @Override + public void onPacketSending(PacketEvent event) { + // if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) { + LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + if(player.getGame() != null && player.getGame().isStarted()) { + WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket()); + health.setFood(6); + } + // } + } + }); + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) { + @Override + public void onPacketSending(PacketEvent event) { + LGPlayer player = LGPlayer.thePlayer(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); + if(player.getGame() != null && player.getGame() == lgp.getGame()) { + LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); + Bukkit.getPluginManager().callEvent(evt2); + if(evt2.getPrefix().length() > 0) + team.setPrefix(WrappedChatComponent.fromText(evt2.getPrefix())); + else + team.setPrefix(WrappedChatComponent.fromText("§f")); + } + } + }); + protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) { + @Override + public void onPacketSending(PacketEvent event) { + // if (event.getPacketType() == PacketType.Play.Server.ENTITY_EQUIPMENT) { + LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); + if(player.getGame() != null) { + WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket()); + if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId()) + equip.setItem(new ItemStack(Material.AIR)); + } + // } + } + }); + + } + + @SuppressWarnings("unchecked") + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(label.equalsIgnoreCase("lg")) { + if(!sender.hasPermission("loupgarou.admin")) { + sender.sendMessage(prefix+"§4Erreur: Vous n'avez pas la permission..."); + return true; + } + if(args.length >= 1) { + if(args[0].equalsIgnoreCase("addspawn")) { + Player player = (Player)sender; + Location loc = player.getLocation(); + List list = (List) getConfig().getList("spawns"); + list.add(Arrays.asList((double)loc.getBlockX(), loc.getY(), (double)loc.getBlockZ(), (double)loc.getYaw(), (double)loc.getPitch())); + saveConfig(); + loadConfig(); + sender.sendMessage(prefix+"§aLa position a bien été ajoutée !"); + return true; + }else if(args[0].equalsIgnoreCase("end")) { + LGPlayer.thePlayer(Bukkit.getPlayer(args[1])).getGame().cancelWait(); + LGPlayer.thePlayer(Bukkit.getPlayer(args[1])).getGame().endGame(LGWinType.EQUAL); + LGPlayer.thePlayer(Bukkit.getPlayer(args[1])).getGame().broadcastMessage("§cLa partie a été arrêtée de force !"); + return true; + }else if(args[0].equalsIgnoreCase("start")) { + sender.sendMessage("§aVous avez bien démarré une nouvelle partie !"); + LGPlayer.thePlayer(Bukkit.getPlayer(args[1])).getGame().updateStart(); + return true; + }else if(args[0].equalsIgnoreCase("reloadconfig")) { + sender.sendMessage("§aVous avez bien reload la config !"); + sender.sendMessage("§7§oSi vous avez changé les rôles, écriver §8§o/lg joinall§7§o !"); + loadConfig(); + return true; + }else if(args[0].equalsIgnoreCase("joinall")) { + for(Player p : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "joinall")); + for(Player p : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "joinall")); + return true; + }else if(args[0].equalsIgnoreCase("reloadPacks")) { + for(Player p : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "reloadPacks")); + for(Player p : Bukkit.getOnlinePlayers()) + Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "reloadPacks")); + return true; + }else if(args[0].equalsIgnoreCase("nextNight")) { + sender.sendMessage("§aVous êtes passé à la prochaine nuit"); + if(getCurrentGame() != null) { + getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine nuit a été forcé !"); + for(LGPlayer lgp : getCurrentGame().getInGame()) + lgp.stopChoosing(); + getCurrentGame().cancelWait(); + getCurrentGame().nextNight(); + } + return true; + }else if(args[0].equalsIgnoreCase("nextDay")) { + sender.sendMessage("§aVous êtes passé à la prochaine journée"); + if(getCurrentGame() != null) { + getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine journée a été forcé !"); + getCurrentGame().cancelWait(); + for(LGPlayer lgp : getCurrentGame().getInGame()) + lgp.stopChoosing(); + getCurrentGame().endNight(); + } + 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 role set §7 pour définir le nombre de joueurs qui devrons avoir ce rôle."); + } else { + if(args[1].equalsIgnoreCase("set") && args.length == 4) { + String role = null; + if(args[2].length() <= 2) + try { + Integer i = Integer.valueOf(args[2]); + Object[] array = getRoles().keySet().toArray(); + if(array.length <= i) { + sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas."); + return true; + }else + role = (String)array[i]; + }catch(Exception err) {sender.sendMessage(prefix+"§4Erreur: §cCeci n'est pas un nombre");} + else + role = args[2]; + + if(role != null) { + String real_role = null; + for(String real : getRoles().keySet()) + if(real.equalsIgnoreCase(role)) { + real_role = real; + break; + } + + if(real_role != null) { + try { + MainLg.getInstance().getConfig().set("role."+real_role, Integer.valueOf(args[3])); + sender.sendMessage(prefix+"§6Il y aura §e"+args[3]+" §6"+real_role); + saveConfig(); + loadConfig(); + sender.sendMessage("§7§oSi vous avez fini de changer les rôles, écriver §8§o/lg joinall§7§o !"); + }catch(Exception err) { + sender.sendMessage(prefix+"§4Erreur: §c"+args[3]+" n'est pas un nombre"); + } + return true; + } + } + sender.sendMessage(prefix+"§4Erreur: §cLe rôle que vous avez entré est incorrect"); + + } else { + sender.sendMessage(prefix+"§4Erreur: §cCommande incorrecte."); + sender.sendMessage(prefix+"§4Essayez §c/lg roles set §4 ou §c/lg roles list"); + } + } + return true; + } + } + sender.sendMessage(prefix+"§4Erreur: §cCommande incorrecte."); + sender.sendMessage(prefix+"§4Essayez /lg §caddSpawn/end/start/nextNight/nextDay/reloadConfig/roles/reloadPacks/joinAll"); + return true; + } + return false; + } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + if(!sender.hasPermission("loupgarou.admin")) + return new ArrayList(0); + + if(args.length > 1) { + if(args[0].equalsIgnoreCase("roles")) + if(args.length == 2) + return getStartingList(args[1], "list", "set"); + else if(args.length == 3 && args[1].equalsIgnoreCase("set")) + return getStartingList(args[2], getRoles().keySet().toArray(new String[getRoles().size()])); + else if(args.length == 4) + 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); + } + private List getStartingList(String startsWith, String... list){ + startsWith = startsWith.toLowerCase(); + ArrayList returnlist = new ArrayList(); + if(startsWith.length() == 0) + return Arrays.asList(list); + for(String s : list) + if(s.toLowerCase().startsWith(startsWith)) + returnlist.add(s); + return returnlist; + } + public void loadConfig() { + int players = 0; + for(String role : roles.keySet()) + players += getConfig().getInt("role."+role); + currentGame = new LGGame(players); + } + @Override + public void onDisable() { + ProtocolLibrary.getProtocolManager().removePacketListeners(this); + } + public static MainLg getInstance() { + return instance; + } + private void loadRoles() { + try { + roles.put("LoupGarou", RLoupGarou.class.getConstructor(LGGame.class)); + roles.put("LoupGarouNoir", RLoupGarouNoir.class.getConstructor(LGGame.class)); + roles.put("Garde", RGarde.class.getConstructor(LGGame.class)); + roles.put("Sorciere", RSorciere.class.getConstructor(LGGame.class)); + roles.put("Voyante", RVoyante.class.getConstructor(LGGame.class)); + roles.put("Chasseur", RChasseur.class.getConstructor(LGGame.class)); + roles.put("Villageois", RVillageois.class.getConstructor(LGGame.class)); + roles.put("Medium", RMedium.class.getConstructor(LGGame.class)); + roles.put("Dictateur", RDictateur.class.getConstructor(LGGame.class)); + roles.put("Cupidon", RCupidon.class.getConstructor(LGGame.class)); + roles.put("PetiteFille", RPetiteFille.class.getConstructor(LGGame.class)); + roles.put("ChaperonRouge", RChaperonRouge.class.getConstructor(LGGame.class)); + roles.put("LoupGarouBlanc", RLoupGarouBlanc.class.getConstructor(LGGame.class)); + roles.put("Bouffon", RBouffon.class.getConstructor(LGGame.class)); + roles.put("Ange", RAnge.class.getConstructor(LGGame.class)); + roles.put("Survivant", RSurvivant.class.getConstructor(LGGame.class)); + roles.put("Assassin", RAssassin.class.getConstructor(LGGame.class)); + roles.put("GrandMechantLoup", RGrandMechantLoup.class.getConstructor(LGGame.class)); + roles.put("Corbeau", RCorbeau.class.getConstructor(LGGame.class)); + roles.put("Detective", RDetective.class.getConstructor(LGGame.class)); + roles.put("ChienLoup", RChienLoup.class.getConstructor(LGGame.class)); + roles.put("Pirate", RPirate.class.getConstructor(LGGame.class)); + roles.put("Pyromane", RPyromane.class.getConstructor(LGGame.class)); + roles.put("Pretre", RPretre.class.getConstructor(LGGame.class)); + roles.put("Faucheur", RFaucheur.class.getConstructor(LGGame.class)); + roles.put("EnfantSauvage", REnfantSauvage.class.getConstructor(LGGame.class)); + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/IndexedRole.java b/src/main/java/fr/leomelki/loupgarou/classes/IndexedRole.java new file mode 100644 index 0000000..28ff51f --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/IndexedRole.java @@ -0,0 +1,14 @@ +package fr.leomelki.loupgarou.classes; + +import fr.leomelki.loupgarou.roles.Role; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class IndexedRole { + @Getter private final Role role; + @Getter private int number = 1; + public void increase() { + number++; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java new file mode 100644 index 0000000..6a3d8d6 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomItems.java @@ -0,0 +1,76 @@ +package fr.leomelki.loupgarou.classes; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.StringJoiner; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent; +import fr.leomelki.loupgarou.roles.Role; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class LGCustomItems { + static HashMap, HashMap> mappings = new HashMap, HashMap>(); + static { + JSONParser parser = new JSONParser(); + try { + JSONObject mappings = (JSONObject)parser.parse("{\"PetiteFille\":{\"\":\"SCUTE\",\"infecte\":\"ORANGE_CONCRETE\",\"infecte_mort\":\"WOODEN_SHOVEL\",\"infecte_maire\":\"SOUL_SAND\",\"maire\":\"EXPERIENCE_BOTTLE\",\"mort\":\"STRING\",\"maire_mort\":\"DARK_OAK_SIGN\",\"infecte_maire_mort\":\"PURPLE_SHULKER_BOX\"},\"LoupGarou\":{\"\":\"OAK_PLANKS\",\"infecte\":\"DRAGON_BREATH\",\"infecte_mort\":\"GOLDEN_PICKAXE\",\"infecte_maire\":\"WITHER_SKELETON_SKULL\",\"maire\":\"TRAPPED_CHEST\",\"maire_mort\":\"BRICK_WALL\",\"mort\":\"MELON\",\"infecte_maire_mort\":\"DARK_OAK_LEAVES\"},\"Corbeau\":{\"infecte_mort\":\"RED_TULIP\",\"infecte\":\"PURPLE_STAINED_GLASS\",\"\":\"HEAVY_WEIGHTED_PRESSURE_PLATE\",\"infecte_maire\":\"PUFFERFISH_BUCKET\",\"maire\":\"DIAMOND_CHESTPLATE\",\"maire_mort\":\"SPRUCE_PLANKS\",\"mort\":\"DARK_OAK_BOAT\",\"infecte_maire_mort\":\"WOODEN_PICKAXE\"},\"LoupGarouBlanc\":{\"infecte_mort\":\"DEAD_TUBE_CORAL_WALL_FAN\",\"infecte\":\"CORNFLOWER\",\"\":\"ANDESITE\",\"infecte_maire\":\"GRINDSTONE\",\"maire\":\"TUBE_CORAL\",\"mort\":\"STONE_PICKAXE\",\"maire_mort\":\"PURPLE_CONCRETE\",\"infecte_maire_mort\":\"CYAN_DYE\"},\"Assassin\":{\"infecte\":\"WITHER_ROSE\",\"\":\"GRAY_CONCRETE_POWDER\",\"infecte_mort\":\"ACACIA_DOOR\",\"infecte_maire\":\"ENCHANTING_TABLE\",\"maire\":\"DEAD_HORN_CORAL_FAN\",\"maire_mort\":\"WOODEN_AXE\",\"mort\":\"HOPPER\",\"infecte_maire_mort\":\"RED_STAINED_GLASS\"},\"Voyante\":{\"infecte_mort\":\"OAK_DOOR\",\"\":\"RED_CONCRETE_POWDER\",\"infecte\":\"END_STONE_BRICKS\",\"infecte_maire\":\"FARMLAND\",\"maire\":\"POPPY\",\"maire_mort\":\"PINK_CONCRETE_POWDER\",\"mort\":\"MUSHROOM_STEM\",\"infecte_maire_mort\":\"WHITE_BANNER\"},\"Dictateur\":{\"\":\"PRISMARINE_SHARD\",\"infecte_mort\":\"CYAN_TERRACOTTA\",\"infecte\":\"CYAN_GLAZED_TERRACOTTA\",\"infecte_maire\":\"REPEATER\",\"maire\":\"GREEN_BED\",\"maire_mort\":\"SPRUCE_TRAPDOOR\",\"mort\":\"DRIED_KELP_BLOCK\",\"infecte_maire_mort\":\"LIME_STAINED_GLASS_PANE\"},\"LoupGarouNoir\":{\"infecte_mort\":\"COBBLESTONE_WALL\",\"\":\"SLIME_BLOCK\",\"infecte\":\"TORCH\",\"infecte_maire\":\"CHORUS_FLOWER\",\"maire\":\"LANTERN\",\"maire_mort\":\"BRAIN_CORAL_WALL_FAN\",\"mort\":\"YELLOW_CARPET\",\"infecte_maire_mort\":\"MOJANG_BANNER_PATTERN\"},\"ChaperonRouge\":{\"\":\"GRASS\",\"infecte\":\"LIME_BANNER\",\"infecte_mort\":\"ORANGE_SHULKER_BOX\",\"infecte_maire\":\"STONE_SLAB\",\"maire\":\"BLUE_GLAZED_TERRACOTTA\",\"mort\":\"PURPLE_TERRACOTTA\",\"maire_mort\":\"YELLOW_DYE\",\"infecte_maire_mort\":\"EMERALD_ORE\"},\"EnfantSauvage\":{\"infecte\":\"GREEN_CARPET\",\"\":\"BLACK_STAINED_GLASS\",\"infecte_mort\":\"CHEST_MINECART\",\"infecte_maire\":\"MAGENTA_STAINED_GLASS\",\"maire\":\"ACACIA_SIGN\",\"mort\":\"GRAY_BANNER\",\"maire_mort\":\"POLISHED_DIORITE_SLAB\",\"infecte_maire_mort\":\"WHITE_STAINED_GLASS_PANE\"},\"Faucheur\":{\"infecte_mort\":\"RED_STAINED_GLASS_PANE\",\"infecte\":\"CYAN_WOOL\",\"\":\"MOSSY_COBBLESTONE_SLAB\",\"infecte_maire\":\"PISTON\",\"maire\":\"GOLDEN_HELMET\",\"maire_mort\":\"BIRCH_FENCE\",\"mort\":\"SKELETON_SKULL\",\"infecte_maire_mort\":\"LIGHT_BLUE_TERRACOTTA\"},\"Cupidon\":{\"\":\"CHORUS_PLANT\",\"infecte_mort\":\"SPRUCE_SIGN\",\"infecte\":\"TRIDENT\",\"infecte_maire\":\"GLOBE_BANNER_PATTERN\",\"maire\":\"YELLOW_STAINED_GLASS_PANE\",\"maire_mort\":\"BROWN_STAINED_GLASS_PANE\",\"mort\":\"GOLDEN_BOOTS\",\"infecte_maire_mort\":\"SEA_LANTERN\"},\"EnfantSauvageLG\":{\"\":\"HORN_CORAL_FAN\",\"infecte_mort\":\"JUNGLE_LOG\",\"infecte\":\"CARTOGRAPHY_TABLE\",\"infecte_maire\":\"BLACK_STAINED_GLASS_PANE\",\"maire\":\"YELLOW_GLAZED_TERRACOTTA\",\"maire_mort\":\"OXEYE_DAISY\",\"mort\":\"STICK\",\"infecte_maire_mort\":\"BROWN_MUSHROOM_BLOCK\"},\"Chasseur\":{\"infecte_mort\":\"COAL\",\"infecte\":\"PRISMARINE_SLAB\",\"\":\"DIORITE\",\"infecte_maire\":\"BLUE_CONCRETE\",\"maire\":\"DEAD_TUBE_CORAL_BLOCK\",\"maire_mort\":\"MAGENTA_TERRACOTTA\",\"mort\":\"CAKE\",\"infecte_maire_mort\":\"YELLOW_WOOL\"},\"Bouffon\":{\"infecte\":\"BIRCH_PLANKS\",\"\":\"LECTERN\",\"infecte_mort\":\"GREEN_CONCRETE_POWDER\",\"infecte_maire\":\"RABBIT_FOOT\",\"maire\":\"FIRE_CORAL_BLOCK\",\"maire_mort\":\"STRIPPED_OAK_WOOD\",\"mort\":\"DEAD_HORN_CORAL_WALL_FAN\",\"infecte_maire_mort\":\"LAPIS_BLOCK\"},\"Detective\":{\"\":\"GLASS_PANE\",\"infecte_mort\":\"RED_BED\",\"infecte\":\"MAGENTA_WOOL\",\"infecte_maire\":\"CHEST\",\"maire\":\"FEATHER\",\"mort\":\"REDSTONE_TORCH\",\"maire_mort\":\"DARK_OAK_BUTTON\",\"infecte_maire_mort\":\"GREEN_WOOL\"},\"GrandMechantLoup\":{\"infecte_mort\":\"LIGHT_BLUE_WOOL\",\"\":\"CHISELED_RED_SANDSTONE\",\"infecte\":\"LIGHT_GRAY_BED\",\"infecte_maire\":\"RABBIT_HIDE\",\"maire\":\"COCOA_BEANS\",\"maire_mort\":\"MILK_BUCKET\",\"mort\":\"PURPLE_GLAZED_TERRACOTTA\",\"infecte_maire_mort\":\"YELLOW_CONCRETE\"},\"Survivant\":{\"\":\"SLIME_BALL\",\"infecte_mort\":\"POPPED_CHORUS_FRUIT\",\"infecte\":\"INFESTED_COBBLESTONE\",\"infecte_maire\":\"GRAY_TERRACOTTA\",\"maire\":\"CHARCOAL\",\"mort\":\"PINK_STAINED_GLASS_PANE\",\"maire_mort\":\"MAGENTA_DYE\",\"infecte_maire_mort\":\"NETHER_BRICK_FENCE\"},\"ChienLoupLG\":{\"\":\"LEATHER_HORSE_ARMOR\",\"infecte\":\"BIRCH_BUTTON\",\"infecte_mort\":\"BLAST_FURNACE\",\"infecte_maire\":\"GLASS_BOTTLE\",\"maire\":\"PODZOL\",\"mort\":\"END_ROD\",\"maire_mort\":\"SPRUCE_LOG\",\"infecte_maire_mort\":\"MAGENTA_CARPET\"},\"Garde\":{\"\":\"BRICK_SLAB\",\"infecte\":\"GRAY_STAINED_GLASS\",\"infecte_mort\":\"DARK_OAK_PLANKS\",\"infecte_maire\":\"PURPUR_SLAB\",\"maire\":\"BLACK_TERRACOTTA\",\"maire_mort\":\"IRON_HELMET\",\"mort\":\"DIRT\",\"infecte_maire_mort\":\"ACACIA_WOOD\"},\"Villageois\":{\"\":\"DEAD_BUSH\",\"infecte_mort\":\"DIAMOND_AXE\",\"infecte\":\"CYAN_BED\",\"infecte_maire\":\"PINK_CONCRETE\",\"maire\":\"LEAD\",\"maire_mort\":\"LIME_CONCRETE\",\"mort\":\"DEAD_BRAIN_CORAL\",\"infecte_maire_mort\":\"SUNFLOWER\"},\"Ange\":{\"\":\"POLISHED_GRANITE_SLAB\",\"infecte\":\"BROWN_BED\",\"infecte_mort\":\"MOSSY_STONE_BRICK_WALL\",\"infecte_maire\":\"DEAD_FIRE_CORAL_WALL_FAN\",\"maire\":\"SANDSTONE\",\"maire_mort\":\"POLISHED_DIORITE\",\"mort\":\"NETHER_BRICK_SLAB\",\"infecte_maire_mort\":\"BONE_MEAL\"},\"ChienLoup\":{\"\":\"GRANITE_SLAB\",\"infecte_mort\":\"JUNGLE_PLANKS\",\"infecte\":\"PAINTING\",\"infecte_maire\":\"MOSSY_COBBLESTONE\",\"maire\":\"SUGAR_CANE\",\"mort\":\"MOSSY_STONE_BRICK_SLAB\",\"maire_mort\":\"RED_BANNER\",\"infecte_maire_mort\":\"END_CRYSTAL\"},\"Medium\":{\"infecte_mort\":\"GRAY_SHULKER_BOX\",\"infecte\":\"LIGHT_BLUE_BANNER\",\"\":\"OAK_TRAPDOOR\",\"infecte_maire\":\"LIGHT_BLUE_STAINED_GLASS_PANE\",\"maire\":\"FERN\",\"maire_mort\":\"WHITE_TERRACOTTA\",\"mort\":\"STICKY_PISTON\",\"infecte_maire_mort\":\"CYAN_SHULKER_BOX\"},\"Pyromane\":{\"\":\"BLUE_ICE\",\"infecte_mort\":\"PURPLE_WOOL\",\"infecte\":\"BEDROCK\",\"infecte_maire\":\"STONE_BRICK_WALL\",\"maire\":\"DEAD_BUBBLE_CORAL_BLOCK\",\"mort\":\"ORANGE_TULIP\",\"maire_mort\":\"PINK_STAINED_GLASS\",\"infecte_maire_mort\":\"GREEN_TERRACOTTA\"},\"Pirate\":{\"infecte\":\"BLUE_STAINED_GLASS\",\"\":\"RED_MUSHROOM_BLOCK\",\"infecte_mort\":\"SPAWNER\",\"infecte_maire\":\"STRIPPED_DARK_OAK_LOG\",\"maire\":\"DROPPER\",\"maire_mort\":\"COBBLESTONE_SLAB\",\"mort\":\"ENDER_CHEST\",\"infecte_maire_mort\":\"IRON_INGOT\"},\"Pretre\":{\"\":\"SNOWBALL\",\"infecte_mort\":\"PINK_BANNER\",\"infecte\":\"ORANGE_BED\",\"infecte_maire\":\"SPRUCE_LEAVES\",\"maire\":\"PRISMARINE_WALL\",\"maire_mort\":\"DEAD_BUBBLE_CORAL\",\"mort\":\"WHITE_SHULKER_BOX\",\"infecte_maire_mort\":\"FLINT\"},\"Sorciere\":{\"\":\"NETHERRACK\",\"infecte_mort\":\"OAK_SIGN\",\"infecte\":\"CONDUIT\",\"infecte_maire\":\"IRON_HORSE_ARMOR\",\"maire\":\"STRIPPED_OAK_LOG\",\"mort\":\"HORN_CORAL_BLOCK\",\"maire_mort\":\"COMPOSTER\",\"infecte_maire_mort\":\"BIRCH_FENCE_GATE\"}}"); + for(Object key : mappings.keySet()) { + 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))); + try { + LGCustomItems.mappings.put((Class)Class.forName("fr.leomelki.loupgarou.roles.R"+key), map); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static Material getItem(Role role) { + return mappings.get(role.getClass()).get(""); + } + public static Material getItem(LGPlayer player, ArrayList constraints) { + Bukkit.getPluginManager().callEvent(new LGCustomItemChangeEvent(player.getGame(), player, constraints)); + + Collections.sort(constraints); + HashMap mapps = mappings.get(player.getRole().getClass()); + StringJoiner sj = new StringJoiner("_"); + for(String s : constraints) + sj.add(s); + return mapps.get(sj.toString()); + } + public static Material getItem(LGPlayer player) { + return getItem(player, new ArrayList()); + } + + public static void updateItem(LGPlayer lgp) { + lgp.getPlayer().getInventory().setItemInOffHand(new ItemStack(getItem(lgp))); + lgp.getPlayer().updateInventory(); + } + + public static void updateItem(LGPlayer lgp, ArrayList constraints) { + lgp.getPlayer().getInventory().setItemInOffHand(new ItemStack(getItem(lgp, constraints))); + lgp.getPlayer().updateInventory(); + } + + @RequiredArgsConstructor + public static enum LGCustomItemsConstraints{ + INFECTED("infecte"), + MAYOR("maire"), + DEAD("mort"); + @Getter private final String name; + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGCustomSkin.java b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomSkin.java new file mode 100644 index 0000000..06162bb --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGCustomSkin.java @@ -0,0 +1,14 @@ +package fr.leomelki.loupgarou.classes; + +import com.comphenix.protocol.wrappers.WrappedSignedProperty; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum LGCustomSkin { + VILLAGER(new WrappedSignedProperty("textures", "eyJ0aW1lc3RhbXAiOjE1NzcwNTE5MDIyNDgsInByb2ZpbGVJZCI6Ijc4YWQzMjI2YmJkYTQwMGZiNTExMjAzMDY4MGNjN2I0IiwicHJvZmlsZU5hbWUiOiJTaHl0b29zIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzYxZmE3Y2UyYmQxMmJmMzBjOTcxZjUwZjJiMGIyYTZkZWUyOWU4MWM5MmJkZmFhZjFkMDJlNjM5YzJiZjMzNWEiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==", "Qk3Gh9IbVwqIvzv0t3vNrGhzW1ejvKls/7n1vqC7UozJYFotECsBla3DFrxrLvTVsCMAQ3cXGq9QjfFF1U/q0NYvWNXVPbrIxX6LH2t2SI9F1+WLQ7LGYwwABzMGDClJXkuUr0yEOPtCwoTgvinVkCZmNRrN0VDAwd+ie3LCnuBjo3iabjA4dxXLE59mnvCGKo5pGdqThn/KikUldvYGBjpQa+X5F+jQhj7TucZ8t0VJ2t05TkKHS+bcIcmCD+UorGG1N5uiNkQe89BMXZKQEebydtnH5RT8efqHfYT5aZY/6IJKTMqIeclcWy2f6LIfRb97AeifOPPHTfjl2Q6wjvOdnvGuNa+Xk6biNM7cLz1KQzdMM0CvkiZZ9XtFul5+PXEobx2IjIEcrStZX0fl/NZid+kf+2RXbPKx4Z+07q5PbeCzr1UD3DMWlrEMQQppIB26uhPLS9mh3IvM9bhx+vIbByr1Z5p3aT4J2mbhwwmf/LUpNUyMn6oHt19zX6cEcSbncGBLgEHOrUXgxdK/Sm4lJKA1Mr3M0o8CSt7ldLc6mA4oBPMK/OV/c0rwb1W2GWOUyw99dNT/jFSFXyyjCHW0+5FkAW+H+8Y0dZ3U4UWaAmX4JNfdxiih97eTBKEvIC8V48hiFS/UV9A9LBVPNkca/4lanh/jNZ7VRQ+/vU8=")), + MAYOR(new WrappedSignedProperty("textures", "eyJ0aW1lc3RhbXAiOjE1NzcwNTE4NjcxMDcsInByb2ZpbGVJZCI6Ijc4YWQzMjI2YmJkYTQwMGZiNTExMjAzMDY4MGNjN2I0IiwicHJvZmlsZU5hbWUiOiJTaHl0b29zIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzUzYTk5NjljMjU0YWRkYmZkNjdmNDJlZmMxODNkZDg5ZWE3ZTliOGE4NDY2YWNkOWZhMWZmMTYzMTQ0MTczMDMifX19", "fq/bN78Y70k2clbfg6sLRuj4mhvDTz58fKI3/0XvzJH/bQF5Mf+jcFwpXJN+ZiupMaHFHI1bBQ20lrzlGvtrCoYu9+Bx4otin0NQVxc3pOEewikzYub64niMPq8irGJrS2pB1B2Uym5F+/wX8TXOkySyAo1r3lzh6qmfe1bpNG7gcc9+ulYdAbnyhxTko3d8poBsjLnadpo0/rBNMkNIua9ryIE3WHW+DOxLwpLpd3TAB15RnA3/qvyBlqQBny1M24ccjmzxjiUbzF66EtTC+BRs3eS8or/vxvdmi70e295gMoERZJ5pFukxe9LB0IEg9cLHwuEl7OC8FcuLUQFnm1EVPjfSlSF36Sd+iVwjFE/x1zINKYsDHwF/TM+yAWOv+PwgGxgQj1C97VaWEkrHXDMEzgxi8DAcPbDBwcyBZXRgOJTHRSH2ATvGDqeT7iQbPrP+y0YNFUDXyBrKYgscgA7bMtBgWvW75SdvcIhqQEVe/jMivMWDuvwhQF4lUGonHc0B5wi1216fqTypEcOeaa5ab+siNssFXpEsaFP9l+1o6uYjNbBpptEAsIlKbnjDaVSkCTvsW7ICaPAZcZCavpyST5MYTv6C7n/bwl3nfzzI7U1LYvYi/gMEHKWfNwLs4T+4VQ3xZD0DpkEQgDrax+Wt182K6OvrAcOcCAfWySo=\",\"name")), + WEREWOLF(new WrappedSignedProperty("textures", "eyJ0aW1lc3RhbXAiOjE1NzcwNTE3NTU1NDgsInByb2ZpbGVJZCI6Ijc4YWQzMjI2YmJkYTQwMGZiNTExMjAzMDY4MGNjN2I0IiwicHJvZmlsZU5hbWUiOiJTaHl0b29zIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2U1NGE2MmRhNGMzZTI5YjdiZWM4ZTI0YzhiNTAyZGZjNWNmMTNmYjc0NjFhN2I5YWY2NGY2Yjc1ZGFhNmE2MDUifX19", "k0cT/rDkBW3QMqSavKc0Nbu39ft3i0TLLhxLht7LKKuA+Q+amCmzw/NZjZRtJc/R87uyl2B+JHLTWTOcbDQX2bE7fIzEvYFhvbb2dasxeYA03wBwZ+OuJlhhxWSSX2NoAI6gEGcWQ3k4xcf+xhtD+5eddjL5k+Dv/kVW6qCWprfPSmd4+KQ0aVwyBkbheyTBSaamtpPj24UYM1EL9POF/PrbmiipfSthp7DkwL4PprW+0Z3pzFMgY46Ay2VJYxa+Q6q3IlYqSXMkjJccf3msyOTGe3JSiQc1Du/djffvLIoyjybolNb5rQ/OrnYIEtnqCuXstJJd3J+a6F8w4DkS2ZMVY4lvidb4coVeFmm9Nk/afqqyG99TDmvZNFWFSeaaxGSWeZPkneAEFuFQXn76sl1xdtXkgXmP8H0yvs9SwA9UnGoldIay6D1HzAOGo3n3stV6188K0ucey1KsH6nNlZfT2hnqvI1lfKD67oQNFfl4kDLRwArfZJUmcQOJh9/fk6/bJvgYuElEkGy++0FkuKKkRJHPIW5+kPZguNo96cAAGxhSH3IIscLoxDdn53iSnngpKttWfG6ccI/XMGTWp4wCq6IC2IBZcmKEqK+fN5dVbR4tn79pXlQ2Yyk7kvXaZjdVHrKC1Buw1gjjC1EvmiJjTRZVHPYlCTkfy+hdqzE=")); + @Getter private final WrappedSignedProperty property; +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java new file mode 100644 index 0000000..6562234 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGGame.java @@ -0,0 +1,895 @@ +package fr.leomelki.loupgarou.classes; + +import java.lang.reflect.Constructor; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.comphenix.protocol.wrappers.WrappedGameProfile; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerChat; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerExperience; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardObjective; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateHealth; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateTime; +import fr.leomelki.loupgarou.MainLg; +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.LGDayStartEvent; +import fr.leomelki.loupgarou.events.LGEndCheckEvent; +import fr.leomelki.loupgarou.events.LGGameEndEvent; +import fr.leomelki.loupgarou.events.LGGameJoinEvent; +import fr.leomelki.loupgarou.events.LGMayorVoteEvent; +import fr.leomelki.loupgarou.events.LGNightEndEvent; +import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; +import fr.leomelki.loupgarou.events.LGNightStart; +import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import fr.leomelki.loupgarou.events.LGPreDayStartEvent; +import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; +import fr.leomelki.loupgarou.events.LGSkinLoadEvent; +import fr.leomelki.loupgarou.events.LGVoteEvent; +import fr.leomelki.loupgarou.events.LGVoteLeaderChange; +import fr.leomelki.loupgarou.roles.RChienLoupLG; +import fr.leomelki.loupgarou.roles.REnfantSauvageLG; +import fr.leomelki.loupgarou.roles.Role; +import fr.leomelki.loupgarou.roles.RoleType; +import fr.leomelki.loupgarou.roles.RoleWinType; +import fr.leomelki.loupgarou.scoreboard.CustomScoreboard; +import fr.leomelki.loupgarou.utils.MultipleValueMap; +import fr.leomelki.loupgarou.utils.VariousUtils; +import lombok.Getter; +import lombok.Setter; + +public class LGGame implements Listener{ + @Getter private final SecureRandom random = new SecureRandom(); + @Getter private final int maxPlayers; + @Getter private ArrayList inGame = new ArrayList(); + @Getter private ArrayList roles = new ArrayList(); + + @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 HashMap placements = new HashMap(); + + @Getter private LGChat spectatorChat = new LGChat((sender, message) -> { + return "§7"+sender.getName()+" §6» §f"+message; + }); + @Getter private LGChat dayChat = new LGChat((sender, message) -> { + return "§e"+sender.getName()+" §6» §f"+message; + }); + + + public LGGame(int maxPlayers) { + this.maxPlayers = maxPlayers; + Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance()); + } + + @Getter + private MultipleValueMap deaths = new MultipleValueMap(); + + public void sendActionBarMessage(String msg) { + WrapperPlayServerChat chat = new WrapperPlayServerChat(); + chat.setPosition((byte)2); + chat.setMessage(WrappedChatComponent.fromText(msg)); + for(LGPlayer lgp : inGame) + chat.sendPacket(lgp.getPlayer()); + } + public void broadcastMessage(String msg) { + for(LGPlayer lgp : inGame) + lgp.sendMessage(msg); + } + public void broadcastSpacer() { + for(LGPlayer lgp : inGame) + lgp.getPlayer().sendMessage("\n"); + } + + private BukkitTask waitTask; + public void wait(int seconds, Runnable callback) { + wait(seconds, callback, null); + } + public void wait(int seconds, Runnable callback, TextGenerator generator) { + cancelWait(); + waitTicks = seconds*20; + waitTask = new BukkitRunnable() { + @Override + public void run() { + WrapperPlayServerExperience exp = new WrapperPlayServerExperience(); + exp.setLevel((short)(Math.floorDiv(waitTicks, 20)+1)); + exp.setExperienceBar((float)waitTicks/(seconds*20F)); + for(LGPlayer player : getInGame()) { + exp.sendPacket(player.getPlayer()); + if(generator != null) + player.sendActionBarMessage(generator.generate(player, Math.floorDiv(waitTicks, 20)+1)); + } + if(waitTicks == 0) { + for(LGPlayer player : getInGame()) + player.sendActionBarMessage(""); + waitTask = null; + cancel(); + callback.run(); + } + waitTicks--; + } + }.runTaskTimer(MainLg.getInstance(), 0, 1); + } + public void wait(int seconds, int initialSeconds, Runnable callback, TextGenerator generator) { + cancelWait(); + waitTicks = seconds*20; + waitTask = new BukkitRunnable() { + @Override + public void run() { + WrapperPlayServerExperience exp = new WrapperPlayServerExperience(); + exp.setLevel((short)(Math.floorDiv(waitTicks, 20)+1)); + exp.setExperienceBar((float)waitTicks/(initialSeconds*20F)); + for(LGPlayer player : getInGame()) { + exp.sendPacket(player.getPlayer()); + if(generator != null) + player.sendActionBarMessage(generator.generate(player, Math.floorDiv(waitTicks, 20)+1)); + } + if(waitTicks == 0) { + for(LGPlayer player : getInGame()) + player.sendActionBarMessage(""); + waitTask = null; + cancel(); + callback.run(); + } + waitTicks--; + } + }.runTaskTimer(MainLg.getInstance(), 0, 1); + } + + public static interface TextGenerator{ + public String generate(LGPlayer player, int secondsLeft); + } + public void cancelWait() { + if(waitTask != null) { + waitTask.cancel(); + waitTask = null; + } + } + + public void kill(LGPlayer player, Reason reason) { + System.out.println("Kill "+player.getName()+" ("+player.getRole()+") for "+reason+" ("+(!deaths.containsValue(player) && !player.isDead())+")"); + if(!deaths.containsValue(player) && !player.isDead()){ + LGNightPlayerPreKilledEvent event = new LGNightPlayerPreKilledEvent(this, player, reason); + Bukkit.getPluginManager().callEvent(event); + System.out.println("Mort de "+player.getName()+" cancel:"+event.isCancelled()); + if(!event.isCancelled()) + deaths.put(event.getReason(), player); + } + } + + @SuppressWarnings("deprecation") + public boolean tryToJoin(LGPlayer lgp) { + if(ended)return false; + if(!started && inGame.size() < maxPlayers) {//Si la partie n'a pas démarrée et qu'il reste de la place + lgp.getPlayer().removePotionEffect(PotionEffectType.INVISIBILITY); + VariousUtils.setWarning(lgp.getPlayer(), false); + if(lgp.isMuted()) + lgp.resetMuted(); + + lgp.getPlayer().getInventory().clear(); + lgp.getPlayer().updateInventory(); + lgp.getPlayer().closeInventory(); + + lgp.joinChat(dayChat); + + /* WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setMode(1); + team.setName("you_are"); + team.sendPacket(lgp.getPlayer());*/ + + lgp.setGame(this); + inGame.add(lgp); + System.out.println("add > "+inGame); + + lgp.setScoreboard(null); + + for(LGPlayer other : getInGame()) { + other.updatePrefix(); + if(lgp != other) { + lgp.getPlayer().hidePlayer(other.getPlayer()); + lgp.getPlayer().showPlayer(other.getPlayer()); + + other.getPlayer().hidePlayer(lgp.getPlayer()); + other.getPlayer().showPlayer(lgp.getPlayer()); + } + } + + lgp.getPlayer().setGameMode(GameMode.ADVENTURE); + //broadcastMessage("§7Le joueur §8"+lgp.getName()+"§7 a rejoint la partie §9(§8"+inGame.size()+"§7/§8"+maxPlayers+"§9)"); + + //Reset scoreboard + WrapperPlayServerScoreboardObjective obj = new WrapperPlayServerScoreboardObjective(); + obj.setName("lg_scoreboard"); + obj.setMode(1); + obj.sendPacket(lgp.getPlayer()); + + Bukkit.getPluginManager().callEvent(new LGGameJoinEvent(this, lgp)); + //updateStart(); + return true; + } + return false; + } + public void checkLeave() { + if(startingTask != null) { + startingTask.cancel(); + startingTask = null; + broadcastMessage("§c§oUn joueur s'est déconnecté. Le décompte de lancement a donc été arrêté."); + } + } + public void updateStart() { + if(!isStarted()) + if(inGame.size() == maxPlayers) {//Il faut que la partie soit totalement remplie pour qu'elle démarre car sinon, tous les rôles ne seraient pas distribués + for(LGPlayer lgp : getInGame()) { + CustomScoreboard scoreboard = new CustomScoreboard("§7"/*[§9Loup-Garou§7]*/, lgp); + scoreboard.getLine(0).setDisplayName("§6La partie va démarrer..."); + lgp.setScoreboard(scoreboard); + } + if(startingTask == null) { + startingTask = new BukkitRunnable() { + int timeLeft = 5+1; + @Override + public void run() { + if(--timeLeft == 0)//start + start(); + else + sendActionBarMessage("§6Démarrage dans §e"+timeLeft+"§6..."); + } + }.runTaskTimer(MainLg.getInstance(), 20, 20); + } + }else if(startingTask != null) { + startingTask.cancel(); + broadcastMessage("§c§oLe démarrage de la partie a été annulé car une personne l'a quittée !"); + } + } + public void start() { + if(startingTask != null) { + startingTask.cancel(); + startingTask = null; + } + MainLg.getInstance().loadConfig(); + started = true; + MainLg main = MainLg.getInstance(); + + //Registering roles + List original = MainLg.getInstance().getConfig().getList("spawns"); + List list = new ArrayList(original); + for(LGPlayer lgp : getInGame()) { + List location = (List) list.remove(random.nextInt(list.size())); + Player p = lgp.getPlayer(); + p.setWalkSpeed(0); + p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 99999, 180, false, false)); + lgp.setPlace(original.indexOf(location)); + placements.put(lgp.getPlace(), lgp); + p.teleport(new Location(p.getWorld(), location.get(0)+0.5, location.get(1), location.get(2)+0.5, location.get(3).floatValue(), location.get(4).floatValue())); + WrapperPlayServerUpdateHealth update = new WrapperPlayServerUpdateHealth(); + update.setFood(6); + update.setFoodSaturation(1); + update.setHealth(20); + update.sendPacket(p); + lgp.getScoreboard().getLine(0).setDisplayName("§6Attribution des rôles..."); + } + + try { + for(Entry> role : main.getRoles().entrySet()) + if(main.getConfig().getInt("role."+role.getKey()) > 0) + roles.add(role.getValue().newInstance(this)); + }catch(Exception err) { + Bukkit.broadcastMessage("§4§lUne erreur est survenue lors de la création des roles... Regardez la console !"); + err.printStackTrace(); + } + + new BukkitRunnable() { + int timeLeft = 5*2; + int actualRole = getRoles().size(); + @Override + public void run() { + if(--timeLeft == 0) { + cancel(); + _start(); + return; + } + if(timeLeft == 5*2-1) { + broadcastMessage("§2Attribution des rôles..."); + for(LGPlayer lgp : getInGame()) { + lgp.getPlayer().getInventory().clear(); + lgp.getPlayer().updateInventory(); + } + } + + if(--actualRole < 0) + actualRole = getRoles().size()-1; + + ItemStack stack = new ItemStack(LGCustomItems.getItem(getRoles().get(actualRole))); + for(LGPlayer lgp : getInGame()) { + lgp.getPlayer().getInventory().setItemInOffHand(stack); + lgp.getPlayer().updateInventory(); + } + } + }.runTaskTimer(MainLg.getInstance(), 0, 4); + } + private void _start() { + broadcastMessage("§8§oDébut de la partie..."); + //Give roles... + ArrayList toGive = (ArrayList) inGame.clone(); + started = false; + for(Role role : getRoles()) + while(role.getWaitedPlayers() > 0) { + int randomized = random.nextInt(toGive.size()); + LGPlayer player = toGive.remove(randomized); + + role.join(player); + WrapperPlayServerUpdateHealth update = new WrapperPlayServerUpdateHealth(); + update.setFood(6); + update.setFoodSaturation(1); + update.setHealth(20); + update.sendPacket(player.getPlayer()); + } + started = true; + + 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(); + } + }); + + //Start day one + nextNight(10); + } + public void updateRoleScoreboard() { + HashMap roles_ = new HashMap<>(); + for(LGPlayer lgp : getAlive()) + if(roles_.containsKey(lgp.getRole())) + roles_.get(lgp.getRole()).increase(); + else + roles_.put(lgp.getRole(), new IndexedRole(lgp.getRole())); + ArrayList roles = new ArrayList(roles_.values()); + for(IndexedRole role : roles) { + System.out.println(role.getRole().getName()+" -> "+role.getNumber()); + } + System.out.println(roles); + 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)); + }); + for(int i = 0;i=roles.size();i--) + for(LGPlayer lgp : getInGame()) + lgp.getScoreboard().getLine(i).delete(); + } + public List getAlive(){ + ArrayList alive = new ArrayList(); + for(LGPlayer lgp : getInGame()) + if(!lgp.isDead()) + alive.add(lgp); + return alive; + } + + public void nextNight() { + nextNight(5); + } + public void nextNight(int timeout) { + if(ended)return; + LGNightStart event = new LGNightStart(this); + Bukkit.getPluginManager().callEvent(event); + if(event.isCancelled()) + return; + + if(mayorKilled()) {//mort du maire + broadcastMessage("§9Le §5§lCapitaine§9 est mort, il désigne un joueur en remplaçant."); + getMayor().sendMessage("§6Choisis un joueur qui deviendra §5§lCapitaine§6 à son tour."); + LGGame.this.wait(30, ()->{ + mayor.stopChoosing(); + 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)"; + }); + mayor.choose((choosen)->{ + if(choosen != null) { + mayor.stopChoosing(); + cancelWait(); + setMayor(choosen); + broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); + nextNight(); + } + }, mayor); + return; + } + + new BukkitRunnable() { + int timeoutLeft = timeout*20; + @Override + public void run() { + if(--timeoutLeft <= 20+20*2) { + if(timeoutLeft == 20) + cancel(); + WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(); + time.setAgeOfTheWorld(0); + time.setTimeOfDay(LGGame.this.time = (long)(18000-(timeoutLeft-20D)/(20*2D)*12000D)); + for(LGPlayer lgp : getInGame()) + time.sendPacket(lgp.getPlayer()); + } + } + }.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" : ""); + }); + } + private void nextNight_() { + if(ended)return; + night++; + broadcastSpacer(); + broadcastMessage("§9----------- §lNuit n°"+night+"§9 -----------"); + broadcastMessage("§8§oLa nuit tombe sur le village..."); + for(LGPlayer player : getAlive()) + player.leaveChat(); + for(LGPlayer player : getInGame()) { + player.stopAudio(LGSound.AMBIANT_DAY); + player.playAudio(LGSound.START_NIGHT, 0.5); + player.playAudio(LGSound.AMBIANT_NIGHT, 0.07); + } + day = false; + Bukkit.getPluginManager().callEvent(new LGDayEndEvent(this)); + for(LGPlayer player : getInGame()) + player.hideView(); + + ArrayList roles = (ArrayList) getRoles().clone(); + new Runnable() { + Role lastRole; + + public void run() { + Runnable run = this; + new BukkitRunnable() { + + @Override + public void run() { + if(roles.size() == 0) { + Bukkit.getPluginManager().callEvent(new LGRoleTurnEndEvent(LGGame.this, null, lastRole)); + lastRole = null; + endNight(); + return; + } + Role role = roles.remove(0); + Bukkit.getPluginManager().callEvent(new LGRoleTurnEndEvent(LGGame.this, role, lastRole)); + lastRole = role; + if(role.getTurnOrder() == -1 || !role.hasPlayersLeft()) + this.run(); + else { + broadcastMessage("§9"+role.getBroadcastedTask()); + role.onNightTurn(run); + } + } + }.runTaskLater(MainLg.getInstance(), 60); + } + }.run(); + } + public boolean kill(LGPlayer killed, Reason reason, boolean endGame) { + if(killed.getPlayer() != null){ + killed.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 1, false, false)); + killed.die(); + + for(LGPlayer lgp : getInGame()) + if(lgp == killed) { + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); + 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()); + + if(vote != null) + vote.remove(killed); + + broadcastMessage(String.format(reason.getMessage(), killed.getName())+", il était "+killed.getRole().getName()+(killed.getCache().getBoolean("infected") ? " §c§l(Infecté)" : "")+"§4."); + + //Lightning effect + killed.getPlayer().getWorld().strikeLightningEffect(killed.getPlayer().getLocation()); + + for(Role role : getRoles()) + if(role.getPlayers().contains(killed)) + role.getPlayers().remove(killed); + + killed.setDead(true); + + Bukkit.getPluginManager().callEvent(new LGPlayerGotKilledEvent(this, killed, reason, !checkEndGame(false) && endGame)); + + /*PlayerInventory inv = killed.getPlayer().getInventory(); + ItemStack is = new ItemStack(Material.CYAN_DYE); + ItemMeta meta = is.getItemMeta(); + meta.setDisplayName("§a"); + is.setItemMeta(meta); + for(int i = 0;i<9;i++) + inv.setItem(i, is); + killed.getPlayer().updateInventory();*/ + VariousUtils.setWarning(killed.getPlayer(), true); + + killed.getPlayer().getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN)); + + LGCustomItems.updateItem(killed); + + //killed.leaveChat(); + killed.joinChat(spectatorChat); + killed.joinChat(dayChat, true); + } + + //Update scoreboard + + updateRoleScoreboard(); + + //End update scoreboard + + if(!checkEndGame(false)) + return false; + if(endGame) + checkEndGame(); + return true; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onGameEnd(LGGameEndEvent e) { + if(e.getGame() == this && e.getWinType() == LGWinType.VILLAGEOIS) + for(LGPlayer lgp : getInGame()) + if(lgp.getRoleType() == RoleType.VILLAGER) + e.getWinners().add(lgp); + } + + @Setter + boolean ended; + public void endGame(LGWinType winType) { + if(ended)return; + + ArrayList winners = new ArrayList(); + LGGameEndEvent event = new LGGameEndEvent(this, winType, winners); + Bukkit.getPluginManager().callEvent(event); + + if(event.isCancelled()) + return; + + ended = true; + //We unregister every role listener because they are unused after the game's end ! + for(Role role : getRoles()) + HandlerList.unregisterAll(role); + + broadcastMessage(winType.getMessage()); + for(LGPlayer lgp : getInGame()) { + System.out.println(lgp.getName()+" (spec)"); + lgp.leaveChat(); + lgp.joinChat(spectatorChat); + + lgp.setScoreboard(null); + + lgp.sendTitle("§7§lÉgalité", "§8Personne n'a gagné...", 200); + + if(winners.contains(lgp)) + lgp.sendTitle("§a§lVictoire !", "§6Vous avez gagné la partie.", 200); + else + if(winType == LGWinType.EQUAL || winType == LGWinType.NONE) + lgp.sendTitle("§7§lÉgalité", "§8Personne n'a gagné...", 200); + else + lgp.sendTitle("§c§lDéfaite...", "§4Vous avez perdu la partie.", 200); + + + Player p = lgp.getPlayer(); + /* p.getInventory().clear(); + p.updateInventory();*/ + lgp.showView(); + p.removePotionEffect(PotionEffectType.JUMP); + // p.removePotionEffect(PotionEffectType.INVISIBILITY); + p.setWalkSpeed(0.2f); + } + + for(LGPlayer lgp : getInGame()) + if(lgp.getPlayer().isOnline()) { + LGPlayer.removePlayer(lgp.getPlayer()); + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setMode(1); + team.setName("you_are"); + team.sendPacket(lgp.getPlayer()); + LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); + } + /* wait(30, ()->{ + for(LGPlayer lgp : getInGame()) + if(lgp.getPlayer().isOnline()) { + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setMode(1); + team.setName("you_are"); + team.sendPacket(lgp.getPlayer()); + LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); + } + }, (player, secondsLeft)->{ + return "§6Démarrage d'une nouvelle partie dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : ""); + });*/ + } + public boolean mayorKilled() { + return getMayor() != null && getMayor().isDead(); + } + public void endNight() { + if(ended)return; + broadcastSpacer(); + broadcastMessage("§9----------- §lJour n°"+night+"§9 -----------"); + broadcastMessage("§8§oLe jour se lève sur le village..."); + + for(LGPlayer p : getInGame()) { + p.stopAudio(LGSound.AMBIANT_NIGHT); + p.playAudio(LGSound.START_DAY, 0.5); + p.playAudio(LGSound.AMBIANT_DAY, 0.07); + } + + LGNightEndEvent eventNightEnd = new LGNightEndEvent(this); + Bukkit.getPluginManager().callEvent(eventNightEnd); + if(eventNightEnd.isCancelled()) + return; + + int died = 0; + boolean endGame = false; + + //Play rooster crowing sound ! + //p.playAudio("https://leomelki.fr/a4w/gamemode/loupgarou/Rooster-crowing-sound.mp3", 0.3); + + for(Entry entry : deaths.entrySet()) { + if(entry.getKey() == Reason.DONT_DIE) + continue; + if(entry.getValue().isDead())//On ne fait pas mourir quelqu'un qui est déjà mort (résout le problème du dictateur tué par le chasseur) + continue; + if(entry.getValue().getPlayer() != null) {//S'il a deco bah au moins ça crash pas hehe + LGPlayerKilledEvent event = new LGPlayerKilledEvent(this, entry.getValue(), entry.getKey()); + Bukkit.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + endGame |= kill(event.getKilled(), event.getReason(), false); + died++; + } + } + } + deaths.clear(); + if(died == 0) + broadcastMessage("§9Étonnamment, personne n'est mort cette nuit."); + + day = true; + for(LGPlayer player : getInGame()) + player.showView(); + + + new BukkitRunnable() { + int timeoutLeft = 20; + @Override + public void run() { + if(timeoutLeft++ > 20) { + if(timeoutLeft == 20+(2*20)) + cancel(); + WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(); + time.setAgeOfTheWorld(0); + time.setTimeOfDay(LGGame.this.time = (long)(18000-(timeoutLeft-20D)/(20*2D)*12000D)); + for(LGPlayer lgp : getInGame()) + time.sendPacket(lgp.getPlayer()); + } + } + }.runTaskTimer(MainLg.getInstance(), 1, 1); + + LGPreDayStartEvent dayStart = new LGPreDayStartEvent(this); + Bukkit.getPluginManager().callEvent(dayStart); + if(!dayStart.isCancelled()) { + if(endGame) + checkEndGame(); + else + startDay(); + } + } + public void startDay() { + for(LGPlayer player : getInGame()) { + player.joinChat(dayChat, player.isDead()); + System.out.println(player.getName()+" > "+player.isDead()+" (startDay)"); + } + LGDayStartEvent dayStart = new LGDayStartEvent(this); + Bukkit.getPluginManager().callEvent(dayStart); + if(dayStart.isCancelled()) + return; + if(mayorKilled()) {//mort du maire + broadcastMessage("§9Le §5§lCapitaine§9 est mort, il désigne un joueur en remplaçant."); + getMayor().sendMessage("§6Choisis un joueur qui deviendra §5§lCapitaine§6 à son tour."); + LGGame.this.wait(30, ()->{ + mayor.stopChoosing(); + 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)"; + }); + mayor.choose((choosen)->{ + if(choosen != null) { + mayor.stopChoosing(); + cancelWait(); + setMayor(choosen); + broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); + startDay(); + } + }, mayor); + return; + } + new BukkitRunnable() { + + @Override + public void run() { + if(getMayor() == null && getAlive().size() > 2) + mayorVote(); + else + peopleVote(); + } + }.runTaskLater(MainLg.getInstance(), 40); + + } + @Getter private LGPlayer mayor; + + public void setMayor(LGPlayer mayor) { + LGPlayer latestMayor = this.mayor; + this.mayor = mayor; + if(mayor != null && mayor.getPlayer().isOnline()) { + LGCustomItems.updateItem(mayor); + mayor.updateSkin(); + mayor.updateOwnSkin(); + } + if(latestMayor != null && latestMayor.getPlayer() != null && latestMayor.getPlayer().isOnline()) { + LGCustomItems.updateItem(latestMayor); + latestMayor.updateSkin(); + latestMayor.updateOwnSkin(); + } + } + + @EventHandler + public void onCustomItemChange(LGCustomItemChangeEvent e) { + if(e.getGame() == this) { + if(getMayor() == e.getPlayer()) + e.getConstraints().add(LGCustomItemsConstraints.MAYOR.getName()); + if(e.getPlayer().isDead()) + e.getConstraints().add(LGCustomItemsConstraints.DEAD.getName()); + } + } + @EventHandler(priority = EventPriority.LOWEST) + public void onSkinChange(LGSkinLoadEvent e) { + if(e.getGame() == this) { + e.getProfile().getProperties().removeAll("textures"); + if(getMayor() == e.getPlayer()) + e.getProfile().getProperties().put("textures", LGCustomSkin.MAYOR.getProperty()); + else + e.getProfile().getProperties().put("textures", LGCustomSkin.VILLAGER.getProperty()); + } + } + + private void mayorVote() { + if(ended)return; + LGMayorVoteEvent event = new LGMayorVoteEvent(this); + 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.start(getAlive(), getInGame(), ()->{ + if(vote.getChoosen() == null) + setMayor(getAlive().get(random.nextInt(getAlive().size()))); + else + setMayor(vote.getChoosen()); + + broadcastMessage("§7§l"+mayor.getName()+"§6 devient le §5§lCapitaine §6du village."); + /*LGGame.this.wait(5, this::peopleVote, (player, secondsLeft)->{ + return "§6Le peuple va voter dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : ""); + });*/ + peopleVote(); + }); + } + } + @Getter private LGVote vote; + boolean isPeopleVote = false; + @EventHandler + public void leaderChange(LGVoteLeaderChange e) { + if(isPeopleVote && vote != null && e.getGame() == this) { + for(LGPlayer player : e.getLatest()) + if(!e.getNow().contains(player)) + VariousUtils.setWarning(player.getPlayer(), false); + + for(LGPlayer player : e.getNow()) + if(!e.getLatest().contains(player)) + VariousUtils.setWarning(player.getPlayer(), true); + } + } + private void peopleVote() { + if(ended)return; + LGVoteEvent event = new LGVoteEvent(this); + Bukkit.getPluginManager().callEvent(event); + 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.start(getAlive(), getInGame(), ()->{ + isPeopleVote = false; + if(vote.getChoosen() == null || (vote.isMayorVote() && getMayor() == null)) + broadcastMessage(/*getMayor() != null ? "§9Le maire a décidé de gracier les accusés." : */"§9Personne n'est mort aujourd'hui."); + else { + LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(this, vote.getChoosen(), Reason.VOTE); + Bukkit.getPluginManager().callEvent(killEvent); + if(killEvent.isCancelled())//chassou ? + return; + if(kill(killEvent.getKilled(), killEvent.getReason(), true)) + return; + } + nextNight(); + }, mayor); + }//Sinon c'est à celui qui a cancel de s'en occuper + } + + public boolean checkEndGame() { + return checkEndGame(true); + } + public boolean checkEndGame(boolean doEndGame) { + int goodGuy = 0, badGuy = 0, solo = 0; + for(LGPlayer lgp : getAlive()) + if(lgp.getRoleWinType() == RoleWinType.LOUP_GAROU) + badGuy++; + else if(lgp.getRoleWinType() == RoleWinType.VILLAGE) + goodGuy++; + else if(lgp.getRoleWinType() == RoleWinType.SEUL) + solo++; + LGEndCheckEvent event = new LGEndCheckEvent(this, goodGuy == 0 || badGuy == 0 ? (goodGuy+badGuy == 0 ? LGWinType.EQUAL : (goodGuy > 0 ? LGWinType.VILLAGEOIS : LGWinType.LOUPGAROU)) : LGWinType.NONE); + + if((badGuy+goodGuy > 0 && solo > 0) || solo > 1) + event.setWinType(LGWinType.NONE); + + if(badGuy+goodGuy == 0 && solo == 1) + event.setWinType(LGWinType.SOLO); + + Bukkit.getPluginManager().callEvent(event); + if(doEndGame && event.getWinType() != LGWinType.NONE) + endGame(event.getWinType()); + System.out.println("Endgame check result > "+event.getWinType()+" ("+doEndGame+")"); + return event.getWinType() != LGWinType.NONE; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java b/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java new file mode 100644 index 0000000..508968a --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGPlayer.java @@ -0,0 +1,414 @@ +package fr.leomelki.loupgarou.classes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; + +import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; +import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.comphenix.protocol.wrappers.WrappedGameProfile; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerChat; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerTitle; +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.chat.LGChat; +import fr.leomelki.loupgarou.classes.chat.LGChat.LGChatCallback; +import fr.leomelki.loupgarou.classes.chat.LGNoChat; +import fr.leomelki.loupgarou.roles.Role; +import fr.leomelki.loupgarou.roles.RoleType; +import fr.leomelki.loupgarou.roles.RoleWinType; +import fr.leomelki.loupgarou.scoreboard.CustomScoreboard; +import fr.leomelki.loupgarou.utils.VariableCache; +import fr.leomelki.loupgarou.utils.VariousUtils; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.server.v1_15_R1.DimensionManager; +import net.minecraft.server.v1_15_R1.EnumGamemode; +import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn; +import net.minecraft.server.v1_15_R1.WorldType; + +public class LGPlayer { + private static HashMap cachedPlayers = new HashMap(); + public static LGPlayer thePlayer(Player player) { + LGPlayer lgp = cachedPlayers.get(player); + if(lgp == null) { + lgp = new LGPlayer(player); + cachedPlayers.put(player, lgp); + } + return lgp; + } + public static LGPlayer removePlayer(Player player) { + return cachedPlayers.remove(player);//.remove(); + } + @Getter @Setter private int place; + @Getter private Player player; + @Getter @Setter private boolean dead; + @Setter @Getter private Role role; + private LGChooseCallback chooseCallback; + private List blacklistedChoice = new ArrayList<>(0); + @Getter private VariableCache cache = new VariableCache(); + @Getter @Setter private LGGame game; + @Getter @Setter private String latestObjective; + @Getter private CustomScoreboard scoreboard; + public LGPlayer(Player player) { + this.player = player; + } + public LGPlayer(String name) { + this.name = name; + } + + public void setScoreboard(CustomScoreboard scoreboard) { + if(player != null) { + if(this.scoreboard != null) + this.scoreboard.hide(); + + this.scoreboard = scoreboard; + + if(scoreboard != null) + scoreboard.show(); + } + } + + public void sendActionBarMessage(String msg) { + if(this.player != null) { + WrapperPlayServerChat chat = new WrapperPlayServerChat(); + chat.setPosition((byte)2); + chat.setMessage(WrappedChatComponent.fromText(msg)); + chat.sendPacket(getPlayer()); + } + } + public void sendMessage(String msg) { + if(this.player != null) + getPlayer().sendMessage(MainLg.getPrefix()+msg); + } + public void sendTitle(String title, String subTitle, int stay) { + if(this.player != null) { + WrapperPlayServerTitle titlePacket = new WrapperPlayServerTitle(); + titlePacket.setAction(TitleAction.TIMES); + titlePacket.setFadeIn(10); + titlePacket.setStay(stay); + titlePacket.setFadeOut(10); + titlePacket.sendPacket(player); + //player.sendTitle(title, subTitle); + + titlePacket = new WrapperPlayServerTitle(); + titlePacket.setAction(TitleAction.TITLE); + titlePacket.setTitle(WrappedChatComponent.fromText(title)); + titlePacket.sendPacket(player); + + titlePacket = new WrapperPlayServerTitle(); + titlePacket.setAction(TitleAction.SUBTITLE); + titlePacket.setTitle(WrappedChatComponent.fromText(subTitle)); + titlePacket.sendPacket(player); + } + } + public void remove() { + this.player = null; + } + private String name; + public String getName() { + return player != null ? getPlayer().getName() : name; + } + + + public boolean join(LGGame game) { + if(getPlayer().getGameMode() == GameMode.SPECTATOR) { + sendMessage("§cÉtant en mode spectateur, vous ne rejoignez pas la partie !"); + return false; + } + if(game.tryToJoin(this)) { + //To update the skin + updateOwnSkin(); + getPlayer().setWalkSpeed(0.2f); + // sendMessage("§2Vous venez de rejoindre une partie de Loup-Garou. §aBon jeu!"); + return true; + } + return false; + } + public void choose(LGChooseCallback callback, LGPlayer... 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."); + } + public void stopChoosing() { + this.blacklistedChoice = null; + this.chooseCallback = null; + } + + public static interface LGChooseCallback{ + public void callback(LGPlayer choosen); + } + + public void showView() { + if(getGame() != null && player != null) + for(LGPlayer lgp : getGame().getAlive()) + if(!lgp.isDead()) { + if(lgp != this && lgp.getPlayer() != null) + getPlayer().showPlayer(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.sendPacket(getPlayer()); + + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); + 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()); + } + } + + getPlayer().removePotionEffect(PotionEffectType.BLINDNESS); + getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 2, false, false)); + } + + //TODO Update prefix for only one guy + public void updatePrefix() { + if(getGame() != null && !isDead() && player != null) { + List meList = Arrays.asList(getName()); + for(LGPlayer lgp : getGame().getInGame()) { + /* WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + LGUpdatePrefixEvent event = new LGUpdatePrefixEvent(getGame(), this, lgp, ""); + Bukkit.getPluginManager().callEvent(event); + team.setPrefix(WrappedChatComponent.fromText(event.getPrefix())); + team.setMode(2); + team.setName(getName()); + team.setPlayers(meList); + team.sendPacket(lgp.getPlayer());*/ + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); + 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(lgp.getPlayer()); + + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setMode(2); + team.setName(getName()); + team.setPrefix(WrappedChatComponent.fromText("")); + team.setPlayers(meList); + team.sendPacket(lgp.getPlayer()); + } + } + } + public void hideView() { + if(getGame() != null && player != null) { + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); + 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()); + } + info.setData(infos); + info.sendPacket(getPlayer()); + } + + getPlayer().removePotionEffect(PotionEffectType.BLINDNESS); + getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 999999, 1, false, false)); + } + + public void updateSkin() { + if(getGame() != null && player != null) { + for(LGPlayer lgp : getGame().getInGame()) { + if(lgp == this) { + WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); + 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()); + } + } + } + } + public void updateOwnSkin() { + if(player != null) { + //On change son skin avec un packet de PlayerInfo (dans le tab) + 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.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); + ((CraftPlayer)getPlayer()).getHandle().playerConnection.sendPacket(respawn); + //Enfin, on le téléporte à sa potion actuelle car sinon il se verra dans le vide + getPlayer().teleport(getPlayer().getLocation()); + float speed = getPlayer().getWalkSpeed(); + getPlayer().setWalkSpeed(0.2f); + new BukkitRunnable() { + + @Override + public void run() { + getPlayer().updateInventory(); + getPlayer().setWalkSpeed(speed); + } + }.runTaskLater(MainLg.getInstance(), 5); + //Et c'est bon, le joueur se voit avec un nouveau skin avec quasiment aucun problème visible à l'écran :D + } + } + public boolean canSelectDead; + public LGPlayer getPlayerOnCursor(List list) { + Location loc = getPlayer().getLocation(); + System.out.println("hit > "+blacklistedChoice.size()+" > "+blacklistedChoice+" > "+list); + if(loc.getPitch() > 60) + if(blacklistedChoice.contains(this)) + return null; + else + return this; + for(int i = 0;i<50;i++) { + loc.add(loc.getDirection()); + for(LGPlayer player : list) { + if(player != this && !blacklistedChoice.contains(player) && (!player.isDead() || canSelectDead) && VariousUtils.distanceSquaredXZ(loc, player.getPlayer().getLocation()) < 0.35 && Math.abs(loc.getY()-player.getPlayer().getLocation().getY()) < 2) { + System.out.println("detect"); + return player; + } + } + } + return null; + } + + public RoleType getRoleType() { + return this.getCache().getBoolean("infected") ? RoleType.LOUP_GAROU : getRole().getType(this); + } + public RoleWinType getRoleWinType() { + return this.getCache().getBoolean("infected") ? RoleWinType.LOUP_GAROU : getRole().getWinType(this); + } + + @Getter + boolean muted; + + public void die() { + setMuted(); + } + + + private void setMuted() { + if(player != null) + for(LGPlayer lgp : getGame().getInGame()) + if(lgp != this && lgp.getPlayer() != null) + lgp.getPlayer().hidePlayer(getPlayer()); + muted = true; + /* for(Player player : Bukkit.getOnlinePlayers()) + Audio4WebPlugin.getMain().mute(getPlayer(), player);//On mute le joueur pour tout le monnde*/ + } + public void resetMuted() { + muted = false; + } + //@Getter private ArrayList sendTo = new ArrayList(); + + @Getter private LGChat chat; + + public void joinChat(LGChat chat, LGChatCallback callback) { + joinChat(chat, callback, false); + } + public void joinChat(LGChat chat) { + joinChat(chat, null, false); + } + public void joinChat(LGChat chat, boolean muted) { + joinChat(chat, null, muted); + } + public void joinChat(LGChat chat, LGChatCallback callback, boolean muted) { + if(this.chat != null && !muted) + this.chat.leave(this); + + if(!muted) + this.chat = chat; + + if(chat != null && player != null) + chat.join(this, callback == null ? chat.getDefaultCallback() : callback); + } + + + public void leaveChat() { + joinChat(new LGNoChat(), null); + } + + public void onChat(String message) { + if(chat != null) { + chat.sendMessage(this, message); + /* if(getGame().isStarted()) { + if(isDead()) { + for(LGPlayer lgp : getGame().getInGame()) + if(lgp.isDead() || sendTo.contains(lgp)) + lgp.sendMessage("§8Spectateur §o§l"+getName()+" > §7§o"+message); + }else if(sendTo.size() != 0) { + for(LGPlayer lgp : getSendTo()) + lgp.sendMessage("§6§o§l"+getName()+" > §e§o"+message); + sendMessage("§6§o§l"+getName()+" > §e§o"+message); + } + } else + getGame().broadcastMessage("§8§l"+getName()+" > §7"+message);*/ + } + } + + + + /*public void mute(LGPlayer toMute) { + toMute.getSendTo().remove(this); + // Audio4WebPlugin.getMain().mute(toMute.getPlayer(), getPlayer()); + }*/ + /*public void unMute(LGPlayer toUnMute) { + toUnMute.getSendTo().add(this); + // Audio4WebPlugin.getMain().unMute(toUnMute.getPlayer(), getPlayer()); + }*/ + public void playAudio(LGSound sound, double volume) { + if(player != null) + getPlayer().playSound(getPlayer().getLocation(), sound.getSound(), (float)volume, 1); + /* try { + System.out.println("send "+url+" to "+getName()+" at "+volume); + Audio4WebPlugin.getMain().askPlay(getPlayer(), url, volume); + } catch (IOException e) { + e.printStackTrace(); + }*/ + } + public void stopAudio(LGSound sound) { + if(player != null) + getPlayer().stopSound(sound.getSound()); + /* try { + System.out.println("send "+url+" to "+getName()+" at "+volume); + Audio4WebPlugin.getMain().askPlay(getPlayer(), url, volume); + } catch (IOException e) { + e.printStackTrace(); + }*/ + } + + long lastChoose; + public void chooseAction() { + long now = System.currentTimeMillis(); + if(lastChoose+200 < now) { + if(chooseCallback != null) + chooseCallback.callback(getPlayerOnCursor(getGame().getInGame())); + lastChoose = now; + } + } + + @Override + public String toString() { + return super.toString()+" ("+getName()+")"; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java b/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java new file mode 100644 index 0000000..e5dee26 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGSound.java @@ -0,0 +1,18 @@ +package fr.leomelki.loupgarou.classes; + +import org.bukkit.Sound; + +import lombok.Getter; + +public enum LGSound { + KILL(Sound.ENTITY_BLAZE_DEATH), + START_NIGHT(Sound.ENTITY_SKELETON_DEATH), + START_DAY(Sound.ENTITY_ZOMBIE_DEATH), + AMBIANT_NIGHT(Sound.MUSIC_DISC_MALL), + AMBIANT_DAY(Sound.MUSIC_DISC_MELLOHI); + + @Getter 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 new file mode 100644 index 0000000..307f358 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java @@ -0,0 +1,478 @@ +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.Map.Entry; +import java.util.Optional; +import java.util.StringJoiner; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.EntityType; +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.TextGenerator; +import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback; +import fr.leomelki.loupgarou.events.LGVoteLeaderChange; +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; +import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; + +public class LGVote { + @Getter LGPlayer choosen; + private int timeout, initialTimeout, littleTimeout; + private Runnable callback; + private final LGGame game; + @Getter private List participants, viewers; + private final TextGenerator generator; + @Getter private final HashMap> votes = new HashMap>(); + private int votesSize = 0; + private LGPlayer mayor; + private ArrayList latestTop = new ArrayList(); + private final boolean positiveVote, randomIfEqual; + @Getter private boolean mayorVote; + private boolean ended; + public LGVote(int timeout, int littleTimeout, LGGame game, boolean positiveVote, boolean randomIfEqual, TextGenerator generator) { + this.littleTimeout = littleTimeout; + this.initialTimeout = timeout; + this.timeout = timeout; + this.game = game; + this.generator = generator; + this.positiveVote = positiveVote; + this.randomIfEqual = randomIfEqual; + } + public void start(List participants, List viewers, Runnable callback) { + this.callback = callback; + this.participants = participants; + this.viewers = viewers; + game.wait(timeout, this::end, generator); + for(LGPlayer player : participants) + player.choose(getChooseCallback(player)); + } + public void start(List participants, List viewers, Runnable callback, LGPlayer mayor) { + this.callback = callback; + this.participants = participants; + this.viewers = viewers; + this.mayor = mayor; + game.wait(timeout, this::end, generator); + for(LGPlayer player : participants) + player.choose(getChooseCallback(player)); + } + private static DataWatcherObject> az; + private static DataWatcherObject aA; + private static DataWatcherObject T; + private static final EntityArmorStand eas = new EntityArmorStand(null, 0, 0, 0); + static { + try { + Field f = Entity.class.getDeclaredField("az"); + f.setAccessible(true); + az = (DataWatcherObject>) f.get(null); + f = Entity.class.getDeclaredField("aA"); + f.setAccessible(true); + aA = (DataWatcherObject) f.get(null); + f = Entity.class.getDeclaredField("T"); + f.setAccessible(true); + T = (DataWatcherObject) f.get(null); + }catch(Exception err) { + err.printStackTrace(); + } + } + private void end() { + ended = true; + System.out.println("end "+votes+" this"); + for(LGPlayer lgp : viewers) + showVoting(lgp, null); + for(LGPlayer lgp : votes.keySet()) + updateVotes(lgp, true); + int max = 0; + boolean equal = false; + for(Entry> entry : votes.entrySet()) + if(entry.getValue().size() > max) { + System.out.println(entry.getKey()+" has "+entry.getValue().size()+" vote(s)"); + equal = false; + max = entry.getValue().size(); + choosen = entry.getKey(); + }else if(entry.getValue().size() == max) + equal = true; + for(LGPlayer player : participants) { + player.getCache().remove("vote"); + player.stopChoosing(); + } + if(equal) + choosen = null; + if(equal && mayor == null && randomIfEqual) { + ArrayList choosable = new ArrayList(); + for(Entry> entry : votes.entrySet()) + if(entry.getValue().size() == max) + choosable.add(entry.getKey()); + choosen = choosable.get(game.getRandom().nextInt(choosable.size())); + } + + if(equal && mayor != null && max != 0) { + for(LGPlayer player : viewers) + 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(); + for(Entry> entry : votes.entrySet()) + if(entry.getValue().size() == max) + choosable.add(entry.getKey()); + + for(int i = 0;i blackListed = new ArrayList(); + for(LGPlayer player : participants) + if(!choosable.contains(player)) + blackListed.add(player); + else { + VariousUtils.setWarning(player.getPlayer(), true); + //player.sendMessage("§4§lVous êtes un des principaux suspects ! Défendez vous !"); + //player.sendTitle("§4§lDéfendez vous !", "§cVous êtes l'un des principaux suspects", 100); + } + mayorVote = true; + game.wait(30, ()->{ + for(LGPlayer player : participants) + if(choosable.contains(player)) + VariousUtils.setWarning(player.getPlayer(), false); + + for(int i = 0;i{ + 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); + + for(int i = 0;i littleTimeout) { + votesSize = 999; + game.wait(littleTimeout, initialTimeout, this::end, generator); + } + String italic = game.isDay() ? "" : "§o"; + boolean changeVote = false; + if(voter.getCache().has("vote")) {//On enlève l'ancien vote + LGPlayer devoted = voter.getCache().get("vote"); + if(votes.containsKey(devoted)) { + List voters = votes.get(devoted); + if(voters != null) { + voters.remove(voter); + if(voters.size() == 0) + votes.remove(devoted); + } + } + voter.getCache().remove("vote"); + updateVotes(devoted); + changeVote = true; + } + + if(voted != null) {//Si il vient de voter, on ajoute le nouveau vote + //voter.sendTitle("", "§7Tu as voté pour §7§l"+voted.getName(), 40); + if(votes.containsKey(voted)) + votes.get(voted).add(voter); + else + votes.put(voted, new ArrayList(Arrays.asList(voter))); + voter.getCache().set("vote", voted); + updateVotes(voted); + } + + if(voter.getPlayer() != null) { + showVoting(voter, voted); + String message; + if(voted != null) { + if(changeVote) { + message = "§7§l"+voter.getName()+"§6 a changé son vote pour §7§l"+voted.getName()+"§6."; + voter.sendMessage("§6Tu as changé de vote pour §7§l"+voted.getName()+"§6."); + } else { + message = "§7§l"+voter.getName()+"§6 a voté pour §7§l"+voted.getName()+"§6."; + voter.sendMessage("§6Tu as voté pour §7§l"+voted.getName()+"§6."); + } + } else { + message = "§7§l"+voter.getName()+"§6 a annulé son vote."; + voter.sendMessage("§6Tu as annulé ton vote."); + } + + for(LGPlayer player : viewers) + if(player != voter) + player.sendMessage(message); + } + } + + public List getVotes(LGPlayer voted){ + return votes.containsKey(voted) ? votes.get(voted) : new ArrayList(0); + } + + private void updateVotes(LGPlayer voted) { + updateVotes(voted, false); + } + private void updateVotes(LGPlayer voted, boolean kill) { + int entityId = Integer.MIN_VALUE+voted.getPlayer().getEntityId(); + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + destroy.setEntityIds(new int[] {entityId}); + for(LGPlayer lgp : viewers) + destroy.sendPacket(lgp.getPlayer()); + + if(!kill) { + int max = 0; + for(Entry> entry : votes.entrySet()) + if(entry.getValue().size() > max) + max = entry.getValue().size(); + ArrayList last = latestTop; + latestTop = new ArrayList(); + for(Entry> entry : votes.entrySet()) + if(entry.getValue().size() == max) + latestTop.add(entry.getKey()); + Bukkit.getPluginManager().callEvent(new LGVoteLeaderChange(game, this, last, latestTop)); + } + + if(votes.containsKey(voted) && !kill) { + Location loc = voted.getPlayer().getLocation(); + + WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); + spawn.setEntityID(entityId); + spawn.setType(EntityType.DROPPED_ITEM); + //spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(0, (byte)0x20), new WrappedWatchableObject(5, true)))); + spawn.setX(loc.getX()); + spawn.setY(loc.getY()+0.3); + spawn.setZ(loc.getZ()); + + + int votesNbr = votes.get(voted).size(); + /*WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); + meta.setEntityID(entityId); + meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true), new WrappedWatchableObject(customNameVisible, true), new WrappedWatchableObject(customName, IChatBaseComponent.ChatSerializer.b("§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : ""))))); + */ + DataWatcher datawatcher = new DataWatcher(eas); + datawatcher.register(T, (byte)0x20); + datawatcher.register(az, Optional.ofNullable(IChatBaseComponent.ChatSerializer.a("{\"text\":\"§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : "")+"\"}"))); + datawatcher.register(aA, true); + PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(entityId, datawatcher, true); + + for(LGPlayer lgp : viewers) { + spawn.sendPacket(lgp.getPlayer()); + ((CraftPlayer)lgp.getPlayer()).getHandle().playerConnection.sendPacket(meta); + } + + + /* EntityArmorStand ea = new EntityArmorStand(((CraftWorld)loc.getWorld()).getHandle(), loc.getX(), loc.getY()+0.3, loc.getZ()); + ea.setPosition(loc.getX(), loc.getY()+0.3, loc.getZ()); + ea.setInvisible(true); + ea.setCustomNameVisible(true); + int votesNbr = votes.get(voted).size(); + ea.setCustomName((IChatBaseComponent) WrappedChatComponent.fromText("§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : "")).getHandle()); + + PacketPlayOutSpawnEntityLiving spawn = new PacketPlayOutSpawnEntityLiving(ea); + try { + Field field = spawn.getClass().getDeclaredField("a"); + field.setAccessible(true); + field.set(spawn, entityId); + } catch (Exception e) { + e.printStackTrace(); + }*/ + /* WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); + spawn.setEntityID(entityId); + spawn.setType(EntityType.ARMOR_STAND); + WrappedDataWatcher meta = new WrappedDataWatcher(); + meta.setObject(0, (byte)0x20); + meta.setObject(2, "§6§l"+votes.get(voted)+"§e votes"); + // meta.setObject(3, true); + spawn.setMetadata(meta); + Location loc = voted.getPlayer().getLocation(); + spawn.setX(loc.getX()); + spawn.setY(loc.getY()+0.3); + spawn.setZ(loc.getZ());*/ + /* for(LGPlayer lgp : viewers) + ((CraftPlayer)lgp.getPlayer()).getHandle().playerConnection.sendPacket(spawn);*/ + // 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)); + private void showVoting(LGPlayer to, LGPlayer ofWho) { + int entityId = -to.getPlayer().getEntityId(); + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + destroy.setEntityIds(new int[] {entityId}); + destroy.sendPacket(to.getPlayer()); + if(ofWho != null) { + WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); + spawn.setEntityID(entityId); + spawn.setType(EntityType.DROPPED_ITEM); + //spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(0, (byte)0x20), new WrappedWatchableObject(5, true)))); + Location loc = ofWho.getPlayer().getLocation(); + spawn.setX(loc.getX()); + spawn.setY(loc.getY()+1.3); + spawn.setZ(loc.getZ()); + spawn.setHeadPitch(0); + Location toLoc = to.getPlayer().getLocation(); + double diffX = loc.getX()-toLoc.getX(), + diffZ = loc.getZ()-toLoc.getZ(); + float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ))); + + spawn.setYaw(yaw); + spawn.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); + meta.setEntityID(entityId); + meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))); + meta.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); + look.setEntityID(entityId); + look.setPitch(0); + look.setYaw(yaw); + look.sendPacket(to.getPlayer()); + + new BukkitRunnable() { + + @Override + public void run() { + WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); + equip.setEntityID(entityId); + equip.setSlot(ItemSlot.HEAD); + ItemStack skull = new ItemStack(Material.EMERALD); + equip.setItem(skull); + equip.sendPacket(to.getPlayer()); + } + }.runTaskLater(MainLg.getInstance(), 2); + } + } + + private void showArrow(LGPlayer to, LGPlayer ofWho, int entityId) { + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + destroy.setEntityIds(new int[] {entityId}); + destroy.sendPacket(to.getPlayer()); + if(ofWho != null) { + WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); + spawn.setEntityID(entityId); + spawn.setType(EntityType.DROPPED_ITEM); + //spawn.setMetadata(new WrappedDataWatcher()); + Location loc = ofWho.getPlayer().getLocation(); + spawn.setX(loc.getX()); + spawn.setY(loc.getY()+1.3); + spawn.setZ(loc.getZ()); + spawn.setHeadPitch(0); + Location toLoc = to.getPlayer().getLocation(); + double diffX = loc.getX()-toLoc.getX(), + diffZ = loc.getZ()-toLoc.getZ(); + float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ))); + + spawn.setYaw(yaw); + spawn.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); + meta.setEntityID(entityId); + meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))); + meta.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); + look.setEntityID(entityId); + look.setPitch(0); + look.setYaw(yaw); + look.sendPacket(to.getPlayer()); + + new BukkitRunnable() { + + @Override + public void run() { + WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); + equip.setEntityID(entityId); + equip.setSlot(ItemSlot.HEAD); + ItemStack skull = new ItemStack(Material.EMERALD); + equip.setItem(skull); + equip.sendPacket(to.getPlayer()); + } + }.runTaskLater(MainLg.getInstance(), 2); + } + } + public void remove(LGPlayer killed) { + participants.remove(killed); + if(!ended) { + votes.remove(killed); + latestTop.remove(killed); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGWinType.java b/src/main/java/fr/leomelki/loupgarou/classes/LGWinType.java new file mode 100644 index 0000000..f5d8bc4 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGWinType.java @@ -0,0 +1,20 @@ +package fr.leomelki.loupgarou.classes; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum LGWinType { + VILLAGEOIS("§6§l§oLa partie a été gagnée par le §2§lVillage§6§l§o !"), + LOUPGAROU("§6§l§oLa partie a été gagnée par les §c§lLoups-Garous§6§l§o !"), + LOUPGAROUBLANC("§6§l§oLa partie a été gagnée par le §c§lLoup-Garou Blanc§6§l§o !"), + COUPLE("§6§l§oLa partie a été gagnée par le §d§lcouple§6§l§o !"), + ANGE("§6§l§oLa partie a été gagnée par l'§d§lAnge§6§l§o !"), + EQUAL("§7§l§oÉgalité§6§l§o, personne n'a gagné la partie !"), + SOLO("§6§l§oUn joueur solitaire a gagné la partie!"),//bug si ça s'affiche + ASSASSIN("§6§l§oLa partie a été gagnée par l'§1§lAssassin§6§l§o !"), + PYROMANE("§6§l§oLa partie a été gagnée par le §6§lPyromane§6§l§o !"), + NONE("§4Erreur: §cpersonne n'a gagné la partie."); + + @Getter private final String message; +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java new file mode 100644 index 0000000..559627b --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGChat.java @@ -0,0 +1,40 @@ +package fr.leomelki.loupgarou.classes.chat; + +import java.util.HashMap; +import java.util.Map.Entry; + +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class LGChat { + @Getter private final HashMap viewers = new HashMap(); + @Getter private final LGChatCallback defaultCallback; + + public static interface LGChatCallback{ + public String receive(LGPlayer sender, String message); + public default String send(LGPlayer sender, String message) {return null;}; + } + + public void sendMessage(LGPlayer sender, String message) { + System.out.println("sendmessage of "+sender.getName()+" "+this); + String sendMessage = getViewers().get(sender).send(sender, message); + for(Entry entry : viewers.entrySet()) { + System.out.println(" to "+entry.getKey().getName()); + entry.getKey().sendMessage(sendMessage != null ? sendMessage : entry.getValue().receive(sender, message)); + } + } + + public void join(LGPlayer player, LGChatCallback callback) { + System.out.println("join "+player.getName()+" ! "+this); + if(getViewers().containsKey(player)) + getViewers().replace(player, callback); + else + getViewers().put(player, callback); + } + public void leave(LGPlayer player) { + System.out.println("leave "+player.getName()+" ! "+this); + getViewers().remove(player); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/classes/chat/LGNoChat.java b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGNoChat.java new file mode 100644 index 0000000..032f205 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/classes/chat/LGNoChat.java @@ -0,0 +1,18 @@ +package fr.leomelki.loupgarou.classes.chat; + +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class LGNoChat extends LGChat{ + public LGNoChat() { + super(null); + } + + public void sendMessage(LGPlayer sender, String message) {} + + public void join(LGPlayer player, LGChatCallback callback) { + + } + public void leave(LGPlayer player) { + + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGCustomItemChangeEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGCustomItemChangeEvent.java new file mode 100644 index 0000000..1f50472 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGCustomItemChangeEvent.java @@ -0,0 +1,18 @@ +package fr.leomelki.loupgarou.events; + +import java.util.List; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; + +public class LGCustomItemChangeEvent extends LGEvent { + @Getter private final LGPlayer player; + @Getter private final List constraints; + + public LGCustomItemChangeEvent(LGGame game, LGPlayer player, List constraints) { + super(game); + this.player = player; + this.constraints = constraints; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGDayEndEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGDayEndEvent.java new file mode 100644 index 0000000..44675be --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGDayEndEvent.java @@ -0,0 +1,9 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; + +public class LGDayEndEvent extends LGEvent{ + public LGDayEndEvent(LGGame game) { + super(game); + } +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGDayStartEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGDayStartEvent.java new file mode 100644 index 0000000..f42bb4a --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGDayStartEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGDayStartEvent extends LGEvent implements Cancellable{ + public LGDayStartEvent(LGGame game) { + super(game); + } + + @Getter @Setter private boolean cancelled; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGEndCheckEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGEndCheckEvent.java new file mode 100644 index 0000000..be36697 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGEndCheckEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGWinType; +import lombok.Getter; +import lombok.Setter; + +public class LGEndCheckEvent extends LGEvent{ + public LGEndCheckEvent(LGGame game, LGWinType winType) { + super(game); + this.winType = winType; + } + + @Getter @Setter private LGWinType winType; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGEvent.java new file mode 100644 index 0000000..085fa2d --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGEvent.java @@ -0,0 +1,22 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class LGEvent extends Event{ + @Getter final LGGame game; + + private static final HandlerList handlers = new HandlerList(); + @Override + public HandlerList getHandlers() { + return handlers; + } + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGGameEndEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGGameEndEvent.java new file mode 100644 index 0000000..4c31177 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGGameEndEvent.java @@ -0,0 +1,22 @@ +package fr.leomelki.loupgarou.events; + +import java.util.List; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.LGWinType; +import lombok.Getter; +import lombok.Setter; + +public class LGGameEndEvent extends LGEvent implements Cancellable{ + @Getter @Setter private boolean cancelled; + @Getter private final LGWinType winType; + @Getter private final List winners; + public LGGameEndEvent(LGGame game, LGWinType winType, List winners) { + super(game); + this.winType = winType; + this.winners = winners; + } +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java new file mode 100644 index 0000000..d4b0a03 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGGameJoinEvent.java @@ -0,0 +1,14 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; + +public class LGGameJoinEvent extends LGEvent{ + public LGGameJoinEvent(LGGame game, LGPlayer player) { + super(game); + this.player = player; + } + + @Getter LGPlayer player; +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGMayorVoteEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGMayorVoteEvent.java new file mode 100644 index 0000000..6079e72 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGMayorVoteEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGMayorVoteEvent extends LGEvent implements Cancellable{ + public LGMayorVoteEvent(LGGame game) { + super(game); + } + + @Getter @Setter private boolean cancelled; +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGNightEndEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGNightEndEvent.java new file mode 100644 index 0000000..fb0f311 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGNightEndEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGNightEndEvent extends LGEvent implements Cancellable{ + public LGNightEndEvent(LGGame game) { + super(game); + } + + @Getter @Setter private boolean cancelled; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGNightPlayerPreKilledEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGNightPlayerPreKilledEvent.java new file mode 100644 index 0000000..95c3399 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGNightPlayerPreKilledEvent.java @@ -0,0 +1,23 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import lombok.Getter; +import lombok.Setter; + +public class LGNightPlayerPreKilledEvent extends LGEvent implements Cancellable{ + public LGNightPlayerPreKilledEvent(LGGame game, LGPlayer killed, Reason reason) { + super(game); + this.killed = killed; + this.reason = reason; + } + + @Getter @Setter boolean cancelled; + + @Getter private final LGPlayer killed; + @Getter @Setter private Reason reason; + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGNightStart.java b/src/main/java/fr/leomelki/loupgarou/events/LGNightStart.java new file mode 100644 index 0000000..ecb92b3 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGNightStart.java @@ -0,0 +1,17 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGNightStart extends LGEvent implements Cancellable{ + + public LGNightStart(LGGame game) { + super(game); + } + + @Getter @Setter boolean cancelled; + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGPlayerGotKilledEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGPlayerGotKilledEvent.java new file mode 100644 index 0000000..a9cd955 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGPlayerGotKilledEvent.java @@ -0,0 +1,20 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import lombok.Getter; + +public class LGPlayerGotKilledEvent extends LGEvent { + public LGPlayerGotKilledEvent(LGGame game, LGPlayer killed, Reason reason, boolean endGame) { + super(game); + this.killed = killed; + this.reason = reason; + this.endGame = endGame; + } + + @Getter private final boolean endGame; + @Getter private final LGPlayer killed; + @Getter private Reason reason; + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGPlayerKilledEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGPlayerKilledEvent.java new file mode 100644 index 0000000..e0784c0 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGPlayerKilledEvent.java @@ -0,0 +1,46 @@ +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; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +public class LGPlayerKilledEvent extends LGEvent implements Cancellable{ + public LGPlayerKilledEvent(LGGame game, LGPlayer killed, Reason reason) { + super(game); + this.killed = killed; + this.reason = reason; + } + + @Getter @Setter boolean cancelled; + + @Getter @Setter private LGPlayer killed; + @Getter @Setter private Reason reason; + + @RequiredArgsConstructor + public static enum Reason{ + LOUP_GAROU("§7§l%s§4 est mort pendant la nuit"), + GM_LOUP_GAROU("§7§l%s§4 est mort pendant la nuit"), + LOUP_BLANC(LOUP_GAROU.getMessage()), + SORCIERE(LOUP_GAROU.getMessage()), + VOTE("§7§l%s§4 a été victime du vote"), + CHASSEUR("§7§l%s§4 est mort sur le coup"), + DICTATOR("§7§l%s§4 a été désigné"), + DICTATOR_SUICIDE("§7§l%s§4 s'est suicidé par culpabilité"), + DISCONNECTED("§7§l%s§4 est mort d'une déconnexion"), + LOVE("§7§l%s§4 s'est suicidé par amour"), + BOUFFON("§7§l%s§4 est mort de peur"), + ASSASSIN("§7§l%s§4 s'est fait poignarder"), + PYROMANE("§7§l%s§4 est parti en fumée"), + PIRATE("§7§l%s§4 était l'otage"), + FAUCHEUR("§7§l%s§4 a égaré son âme"), + + DONT_DIE("§7§l%s§4 est mort pour rien"); + + @Getter private final String message; + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGPreDayStartEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGPreDayStartEvent.java new file mode 100644 index 0000000..7213a2f --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGPreDayStartEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGPreDayStartEvent extends LGEvent implements Cancellable{ + public LGPreDayStartEvent(LGGame game) { + super(game); + } + + @Getter @Setter private boolean cancelled; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGPyromaneGasoilEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGPyromaneGasoilEvent.java new file mode 100644 index 0000000..e4803bd --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGPyromaneGasoilEvent.java @@ -0,0 +1,18 @@ +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; +import lombok.Setter; + +public class LGPyromaneGasoilEvent extends LGEvent implements Cancellable{ + public LGPyromaneGasoilEvent(LGGame game, LGPlayer player) { + super(game); + this.player = player; + } + + @Getter @Setter private boolean cancelled; + @Getter @Setter private LGPlayer player; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGRoleTurnEndEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGRoleTurnEndEvent.java new file mode 100644 index 0000000..0a70cbd --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGRoleTurnEndEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.roles.Role; +import lombok.Getter; + +public class LGRoleTurnEndEvent extends LGEvent{ + public LGRoleTurnEndEvent(LGGame game, Role newRole, Role previousRole) { + super(game); + this.newRole = newRole; + this.previousRole = previousRole; + } + + @Getter private final Role newRole, previousRole; +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGSkinLoadEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGSkinLoadEvent.java new file mode 100644 index 0000000..fe2889a --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGSkinLoadEvent.java @@ -0,0 +1,21 @@ +package fr.leomelki.loupgarou.events; + +import com.comphenix.protocol.wrappers.WrappedGameProfile; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; +import lombok.Setter; + +public class LGSkinLoadEvent extends LGEvent { + + @Getter private final LGPlayer player, to; + @Getter @Setter private WrappedGameProfile profile; + public LGSkinLoadEvent(LGGame game, LGPlayer player, LGPlayer to, WrappedGameProfile profile) { + super(game); + this.player = player; + this.to = to; + this.profile = profile; + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGUpdatePrefixEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGUpdatePrefixEvent.java new file mode 100644 index 0000000..44f41ab --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGUpdatePrefixEvent.java @@ -0,0 +1,18 @@ +package fr.leomelki.loupgarou.events; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; +import lombok.Setter; + +public class LGUpdatePrefixEvent extends LGEvent { + @Getter @Setter private String prefix; + @Getter private final LGPlayer player, to; + public LGUpdatePrefixEvent(LGGame game, LGPlayer player, LGPlayer to, String prefix) { + super(game); + this.player = player; + this.prefix = prefix; + this.to = to; + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGVoteEvent.java b/src/main/java/fr/leomelki/loupgarou/events/LGVoteEvent.java new file mode 100644 index 0000000..9f614fb --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGVoteEvent.java @@ -0,0 +1,15 @@ +package fr.leomelki.loupgarou.events; + +import org.bukkit.event.Cancellable; + +import fr.leomelki.loupgarou.classes.LGGame; +import lombok.Getter; +import lombok.Setter; + +public class LGVoteEvent extends LGEvent implements Cancellable{ + public LGVoteEvent(LGGame game) { + super(game); + } + + @Getter @Setter private boolean cancelled; +} diff --git a/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java b/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java new file mode 100644 index 0000000..4a9864b --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/events/LGVoteLeaderChange.java @@ -0,0 +1,22 @@ +package fr.leomelki.loupgarou.events; + +import java.util.ArrayList; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.LGVote; +import lombok.Getter; + +public class LGVoteLeaderChange extends LGEvent{ + + public LGVoteLeaderChange(LGGame game, LGVote vote, ArrayList latest, ArrayList now) { + super(game); + this.latest = latest; + this.now = now; + this.vote = vote; + } + + @Getter ArrayList latest, now; + @Getter LGVote vote; + +} diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java new file mode 100644 index 0000000..47b0123 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/CancelListener.java @@ -0,0 +1,75 @@ +package fr.leomelki.loupgarou.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; +import org.bukkit.event.weather.WeatherChangeEvent; + +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class CancelListener implements Listener{ + @EventHandler + public void onPluie(WeatherChangeEvent e) { + e.setCancelled(true); + } + @EventHandler + public void onMove(PlayerMoveEvent e) { + LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer()); + if(lgp.getGame() != null && lgp.getGame().isStarted() && e.getFrom().distanceSquared(e.getTo()) > 0.001) + e.setTo(e.getFrom()); + } + @EventHandler + public void onDamage(EntityDamageEvent e) { + e.setCancelled(true); + } + @EventHandler + public void onFood(FoodLevelChangeEvent e) { + e.setFoodLevel(6); + } + @EventHandler + public void onRespawn(PlayerRespawnEvent e) { + e.setRespawnLocation(e.getPlayer().getLocation()); + } + @EventHandler + public void onRespawn(PlayerDeathEvent e) { + e.setDeathMessage(""); + e.setKeepInventory(true); + } +/* @EventHandler + public void onAchievement(PlayerAchievementAwardedEvent e) { + e.setCancelled(true); + }*/ + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) { + e.setCancelled(true); + //TODO here + System.out.println("\r\n" + + " //TODO here\r\n" + + " //ERREUR : LE LGN PEUT NE PAS AVOIR SON MENU SI IL A LE CHAT OUVERT PAR EX..AVOIR.\r\n" + + " //SI QQN VOIT PLUS SON PERSO -> sneak"); + //TODO : REMPLACER LE MUTE / UNNMUTE PAR UN SYSTEME DE CHAT AVEC UNE LISTE DES PARTICIPANTS DU CHAT DEDANS (ET DU COUP DES SUR CLASSES DE CHAT QUI OVERRIDE LA FONCTION QUI FORMATTE LES MESSAGES DU COUP POSSIBILITE DUTILISER CA POUR FAIRE UN SYSTEME SUR DISCORD (ET FAIRE UN TYPE DE SALON NOCHAT QUAND ON PEUT PAS PARLER)) + } + @EventHandler + public void onDrop(PlayerDropItemEvent e) { + e.setCancelled(true); + } + @EventHandler + public void onClickInventory(InventoryClickEvent e) { + if(LGPlayer.thePlayer((Player)e.getWhoClicked()).getGame() != null) + e.setCancelled(true); + } + @EventHandler + public void onClickInventory(PlayerSwapHandItemsEvent e) { + if(LGPlayer.thePlayer(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 new file mode 100644 index 0000000..34d6021 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/ChatListener.java @@ -0,0 +1,19 @@ +package fr.leomelki.loupgarou.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class ChatListener implements Listener{ + @EventHandler(priority = EventPriority.HIGHEST) + public void onChat(AsyncPlayerChatEvent e) { + if(!e.isCancelled()) { + LGPlayer player = LGPlayer.thePlayer(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 new file mode 100644 index 0000000..e2b4d4c --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/JoinListener.java @@ -0,0 +1,89 @@ +package fr.leomelki.loupgarou.listeners; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status; +import org.bukkit.potion.PotionEffectType; + +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class JoinListener implements Listener{ + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + WrapperPlayServerScoreboardTeam myTeam = new WrapperPlayServerScoreboardTeam(); + myTeam.setName(p.getName()); + myTeam.setPrefix(WrappedChatComponent.fromText("")); + myTeam.setPlayers(Arrays.asList(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); + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setName(player.getName()); + team.setPrefix(WrappedChatComponent.fromText("")); + team.setPlayers(Arrays.asList(player.getName())); + team.setMode(0); + + team.sendPacket(p); + myTeam.sendPacket(player); + } + p.setFoodLevel(6); + if(e.getJoinMessage() == null || !e.getJoinMessage().equals("joinall")) + p.getPlayer().setResourcePack("http://leomelki.fr/mcgames/ressourcepacks/v29/loup_garou.zip"); + else { + LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer()); + lgp.showView(); + lgp.join(MainLg.getInstance().getCurrentGame()); + } + if(noSpec) + p.setGameMode(GameMode.ADVENTURE); + e.setJoinMessage(""); + p.removePotionEffect(PotionEffectType.JUMP); + p.removePotionEffect(PotionEffectType.INVISIBILITY); + p.setWalkSpeed(0.2f); + } + @EventHandler + public void onResoucePack(PlayerResourcePackStatusEvent e) { + if(e.getStatus() == Status.SUCCESSFULLY_LOADED) { + Player p = e.getPlayer(); + LGPlayer lgp = LGPlayer.thePlayer(p); + lgp.showView(); + lgp.join(MainLg.getInstance().getCurrentGame()); + }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()+")"); + } + @EventHandler + public void onLeave(PlayerQuitEvent e) { + Player p = e.getPlayer(); + LGPlayer lgp = LGPlayer.thePlayer(p); + if(lgp.getGame() != null) { + lgp.leaveChat(); + if(lgp.getRole() != null && !lgp.isDead()) + lgp.getGame().kill(lgp, Reason.DISCONNECTED, true); + lgp.getGame().getInGame().remove(lgp); + System.out.println("rem > "+lgp.getGame().getInGame()); + lgp.getGame().checkLeave(); + } + LGPlayer.removePlayer(p); + lgp.remove(); + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/LoupGarouListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/LoupGarouListener.java new file mode 100644 index 0000000..f1311e5 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/LoupGarouListener.java @@ -0,0 +1,30 @@ +package fr.leomelki.loupgarou.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardScore; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.loupgarou.events.LGGameJoinEvent; + +public class LoupGarouListener implements Listener { + @EventHandler + public void onGameJoin(LGGameJoinEvent e) { + //Tous les loups-garous + WrapperPlayServerScoreboardTeam teamDelete = new WrapperPlayServerScoreboardTeam(); + teamDelete.setMode(1); + teamDelete.setName("loup_garou_list"); + + teamDelete.sendPacket(e.getPlayer().getPlayer()); + + //Loup-Garou noir + WrapperPlayServerScoreboardScore score = new WrapperPlayServerScoreboardScore(); + score.setObjectiveName("lg_scoreboard"); + score.setValue(0); + score.setScoreName("été"); + score.setScoreboardAction(ScoreboardAction.REMOVE); + score.sendPacket(e.getPlayer().getPlayer()); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java b/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java new file mode 100644 index 0000000..47669c3 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/listeners/VoteListener.java @@ -0,0 +1,21 @@ +package fr.leomelki.loupgarou.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerAnimationType; + +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class VoteListener implements Listener{ + @EventHandler + public void onClick(PlayerAnimationEvent e) { + if(e.getAnimationType() == PlayerAnimationType.ARM_SWING) + LGPlayer.thePlayer(e.getPlayer()).chooseAction(); + } + @EventHandler + public void onBreak(BlockBreakEvent e) { + e.setCancelled(true); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java b/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java new file mode 100644 index 0000000..6617e24 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RAnge.java @@ -0,0 +1,117 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; + +import org.bukkit.event.EventHandler; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +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; + +public class RAnge extends Role{ + public RAnge(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.NEUTRAL; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§d§lAnge"; + } + @Override + public String getFriendlyName() { + return "de l'"+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes si tu remplis ton objectif"; + } + @Override + public String getDescription() { + return "Tu es §d§lNeutre§f et tu gagnes si tu remplis ton objectif. Ton objectif est d'être éliminé par le village lors du premier vote de jour. Si tu réussis, tu gagnes la partie. Sinon, tu deviens un §a§lVillageois§f."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + return -1; + } + @EventHandler + public void onVoteStart(LGVoteEvent e) { + if(e.getGame() == getGame()) { + night = getGame().getNight(); + vote = true; + for(LGPlayer lgp : getPlayers()) + if(!lgp.isDead()) + lgp.sendMessage("§9§oFais en sorte que les autres votent contre toi !"); + } + } + boolean vote; + @EventHandler + public void onDayEnd(LGDayEndEvent e) { + if(e.getGame() == getGame()) { + if(getPlayers().size() > 0 && getGame().getNight() == night+1 && vote) { + Role villageois = null; + for(Role role : getGame().getRoles()) { + if(role instanceof RVillageois) + villageois = role; + } + + if(villageois == null) + getGame().getRoles().add(villageois = new RVillageois(getGame())); + + for(LGPlayer lgp : getPlayers()) { + lgp.sendMessage("§4§oTu as échoué, tu deviens §a§l§oVillageois§4§o..."); + lgp.setRole(villageois); + villageois.join(lgp); + } + + getPlayers().clear(); + getGame().updateRoleScoreboard(); + } + vote = false; + } + } + ArrayList winners = new ArrayList(); + int night = 1; + @EventHandler + public void onDeath(LGPlayerGotKilledEvent e) { + if(e.getGame() == getGame()) + if(e.getReason() == Reason.VOTE && e.getKilled().getRole() == this && getGame().getNight() == night) + winners.add(e.getKilled()); + } + + @EventHandler + public void onWinCheck(LGEndCheckEvent e) { + if(e.getGame() == getGame()) + if(winners.size() > 0) + e.setWinType(winners.size() == 1 && winners.get(0).getCache().has("inlove") ? LGWinType.COUPLE : LGWinType.ANGE); + } + + @EventHandler + public void onWin(LGGameEndEvent e) { + if(e.getGame() == getGame()) + if(e.getWinType() == LGWinType.ANGE) + e.getWinners().addAll(winners); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java b/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java new file mode 100644 index 0000000..dfedc3c --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RAssassin.java @@ -0,0 +1,145 @@ +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 RAssassin extends Role{ + public RAssassin(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.NEUTRAL; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.SEUL; + } + @Override + public String getName() { + return "§1§lAssassin"; + } + @Override + public String getFriendlyName() { + return "de l'"+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes §7§lSEUL"; + } + @Override + public String getDescription() { + return "Tu gagnes §7§lSEUL§f. Chaque nuit, tu peux choisir un joueur à éliminer. Tu es immunisé contre l'attaque des §c§lLoups§f."; + } + @Override + public String getTask() { + return "Choisis un joueur à éliminer."; + } + @Override + public String getBroadcastedTask() { + return "L'"+getName()+"§9 ne controle plus ses pulsions..."; + } + @Override + public int getTimeout() { + return 15; + } + + @Override + 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(); + } + } + }); + } + + @EventHandler + public void onKill(LGNightPlayerPreKilledEvent e) { + if(e.getKilled().getRole() == this && e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU) {//Les assassins ne peuvent pas mourir la nuit ! + e.setReason(Reason.DONT_DIE); + e.getKilled().getCache().set("assassin_protected", true); + } + } + + @EventHandler + public void onTour(LGRoleTurnEndEvent e) { + if(e.getGame() == getGame()) { + System.out.println(e.getPreviousRole()); + if(e.getPreviousRole() instanceof RLoupGarou) { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().getBoolean("assassin_protected")) { + for(LGPlayer l : getGame().getInGame()) + if(l.getRoleType() == RoleType.LOUP_GAROU) + l.sendMessage("§cVotre cible est immunisée."); + } + }else if(e.getPreviousRole() instanceof RGrandMechantLoup) { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().getBoolean("assassin_protected")) { + for(LGPlayer l : e.getPreviousRole().getPlayers()) + l.sendMessage("§cVotre cible est immunisée."); + } + } + } + } + + @EventHandler + public void onPyroGasoil(LGPyromaneGasoilEvent e) { + if(e.getPlayer().getRole() == this) + e.setCancelled(true); + } + + @EventHandler + public void onDayStart(LGNightEndEvent e) { + if(e.getGame() == getGame()) { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().getBoolean("assassin_protected")) + lgp.getCache().remove("assassin_protected"); + } + } + + @EventHandler + public void onEndgameCheck(LGEndCheckEvent e) { + if(e.getGame() == getGame() && e.getWinType() == LGWinType.SOLO) { + if(getPlayers().size() > 0) + e.setWinType(LGWinType.ASSASSIN); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEndGame(LGGameEndEvent e) { + if(e.getWinType() == LGWinType.ASSASSIN) { + e.getWinners().clear(); + e.getWinners().addAll(getPlayers()); + } + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java b/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java new file mode 100644 index 0000000..76ecb0b --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RBouffon.java @@ -0,0 +1,148 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringJoiner; + +import org.bukkit.event.EventHandler; +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.events.LGGameEndEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class RBouffon extends Role{ + public RBouffon(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.NEUTRAL; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.NONE; + } + @Override + public String getName() { + return "§d§lBouffon"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes si tu remplis ton objectif"; + } + @Override + public String getDescription() { + return "Tu es §d§lNeutre§f et tu gagnes si tu remplis ton objectif. Ton objectif est d'être éliminé par le village lors de n’importe quel vote de jour. Si tu réussis, tu gagnes la partie, mais celle-ci continue. Tu pourras tuer l'une des personnes qui t'ont condamné."; + } + @Override + public String getTask() { + return "Choisis quelqu’un à hanter parmi ceux qui ont voté pour ta mort."; + } + @Override + public String getBroadcastedTask() { + return "L'esprit vengeur du "+getName()+"§9 rôde sur le village..."; + } + @Override + public int getTimeout() { + return 15; + } + + public void onNightTurn(Runnable callback) { + ArrayList players = (ArrayList) needToPlay.clone(); + new Runnable() { + + @Override + public void run() { + getGame().cancelWait(); + if(players.size() == 0) { + onTurnFinish(callback); + 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)"; + }); + player.sendMessage("§6"+getTask()); + // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); + onNightTurn(player, this); + } + }.run(); + } + public boolean hasPlayersLeft() { + return needToPlay.size() > 0; + } + + + + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + needToPlay.remove(player); + player.showView(); + player.getCache().set("bouffon_win", true); + System.out.println(getGame().getVote()); + List choosable = getGame().getVote().getVotes(player); + StringJoiner sj = new StringJoiner("§6§o, §6§o§l"); + for(LGPlayer lgp : choosable) + if(lgp.getPlayer() != null && lgp.getPlayer() != player) + sj.add(lgp.getName()); + + player.sendMessage("§6§o§l"+sj+"§6§o "+(sj.length() > 1 ? "ont" : "a")+" voté pour toi."); + + player.choose((choosen)->{ + if(choosen != null) { + System.out.println(choosable+" / "+getGame().getVote().getVotes()+" "+getGame().getVote()); + if(!choosable.contains(choosen)) + player.sendMessage("§7§l"+choosen.getName()+"§4 n'a pas voté pour vous."); + else if(choosen.isDead()) + player.sendMessage("§7§l"+choosen.getName()+"§4 est mort.");//fix + else { + player.stopChoosing(); + player.sendMessage("§6Ton fantôme va hanter l'esprit de §7§l"+choosen.getName()+"§6."); + getGame().kill(choosen, Reason.BOUFFON); + player.hideView(); + callback.run(); + } + } + }, player); + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + } + + ArrayList needToPlay = new ArrayList(); + + @EventHandler + public void onPlayerKill(LGPlayerKilledEvent e) { + if(e.getKilled().getRole() == this && e.getReason() == Reason.VOTE) { + needToPlay.add(e.getKilled()); + getGame().broadcastMessage("§9§oQuelle erreur, le "+getName()+"§9§o aura droit à sa vengeance..."); + e.getKilled().sendMessage("§6Tu as rempli ta mission, l'heure de la vengeance a sonné."); + } + } + + @EventHandler + public void onWin(LGGameEndEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getGame().getInGame()) + if(lgp.getRole() == this && lgp.getCache().getBoolean("bouffon_win")) { + e.getWinners().add(lgp); + new BukkitRunnable() { + + @Override + public void run() { + getGame().broadcastMessage("§6§oLe "+getName()+"§6§o a rempli son objectif."); + } + }.runTaskAsynchronously(MainLg.getInstance()); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChaperonRouge.java b/src/main/java/fr/leomelki/loupgarou/roles/RChaperonRouge.java new file mode 100644 index 0000000..77a11c3 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChaperonRouge.java @@ -0,0 +1,96 @@ +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.events.LGNightEndEvent; +import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; + +public class RChaperonRouge extends Role{ + public RChaperonRouge(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lChaperon Rouge"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Tant que le §a§lChasseur§f est en vie, tu ne peux pas te faire tuer par les §c§lLoups§f pendant la nuit."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + return -1; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onKill(LGNightPlayerPreKilledEvent e) { + if(e.getKilled().getRole() == this && e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU) { + for(Role role : getGame().getRoles()) + if(role instanceof RChasseur) + if(role.getPlayers().size() > 0){ + e.getKilled().getCache().set("chaperon_kill", true); + e.setReason(Reason.DONT_DIE); + break; + } + } + } + @EventHandler + public void onTour(LGRoleTurnEndEvent e) { + if(e.getGame() == getGame()) { + System.out.println(e.getPreviousRole()); + if(e.getPreviousRole() instanceof RLoupGarou) { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().getBoolean("chaperon_kill")) { + for(LGPlayer l : getGame().getInGame()) + if(l.getRoleType() == RoleType.LOUP_GAROU) + l.sendMessage("§cVotre cible est immunisée."); + } + }else if(e.getPreviousRole() instanceof RGrandMechantLoup) { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().getBoolean("chaperon_kill")) { + for(LGPlayer l : e.getPreviousRole().getPlayers()) + l.sendMessage("§cVotre cible est immunisée."); + } + } + } + } + @EventHandler(priority = EventPriority.HIGHEST) + public void onDayStart(LGNightEndEvent e) { + if(e.getGame() == getGame()) { + for(LGPlayer lgp : getPlayers()) + if(lgp.getCache().getBoolean("chaperon_kill")) { + lgp.getCache().remove("chaperon_kill"); + lgp.sendMessage("§9§oTu as été attaqué cette nuit."); + } + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java b/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java new file mode 100644 index 0000000..5282492 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChasseur.java @@ -0,0 +1,189 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; + +import org.bukkit.Bukkit; +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; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class RChasseur extends Role{ + public RChasseur(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lChasseur"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. À ta mort, tu dois éliminer un joueur en utilisant ta dernière balle."; + } + @Override + public String getTask() { + return "Tu dois choisir qui va mourir avec toi."; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 choisit qui il va emporter avec lui."; + } + @Override + public int getTimeout() { + return 15; + } + + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + 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)"; + }); + System.out.println("tour de "+player.getName()); + getGame().broadcastMessage("§9"+getBroadcastedTask()); + player.sendMessage("§6"+getTask()); + //player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 60); + player.choose((choosen)->{ + if(choosen != null) { + player.stopChoosing(); + getGame().cancelWait(); + LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), choosen, Reason.CHASSEUR); + Bukkit.getPluginManager().callEvent(killEvent); + if(killEvent.isCancelled()) + return; + + if(getGame().kill(killEvent.getKilled(), killEvent.getReason(), true)) + return; + callback.run(); + } + }, player); + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + getGame().broadcastMessage("§9Il n'a pas tiré sur la détente..."); + player.stopChoosing(); + } + + ArrayList needToPlay = new ArrayList(); + + @EventHandler + public void onPlayerKill(LGPlayerKilledEvent e) { + System.out.println(e.getKilled().getRole()+" "+this); + if(e.getKilled().getRole() == this && e.getReason() != Reason.DISCONNECTED) { + needToPlay.add(e.getKilled()); + System.out.println("added"); + } + } + @EventHandler + public void onDayStart(LGDayStartEvent e) { + if(e.getGame() != getGame())return; + System.out.println("day start "+needToPlay.size()); + + if(needToPlay.size() > 0) + e.setCancelled(true); + + if(!e.isCancelled())return; + System.out.println("cancel"); + new Runnable() { + public void run() { + if(needToPlay.size() == 0) { + System.out.println("finish"); + e.getGame().startDay(); + return; + } + LGPlayer player = needToPlay.remove(0); + System.out.println("> "+player.getName()); + onNightTurn(player, this); + } + }.run(); + } + + @EventHandler + public void onEndGame(LGGameEndEvent e) { + if(e.getGame() != getGame())return; + System.out.println("game end "+needToPlay.size()); + + if(needToPlay.size() > 0) + e.setCancelled(true); + + if(!e.isCancelled())return; + System.out.println("cancel"); + new Runnable() { + public void run() { + if(needToPlay.size() == 0) { + System.out.println("finish game"); + e.getGame().checkEndGame(true); + return; + } + LGPlayer player = needToPlay.remove(0); + System.out.println(">>- "+player.getName()); + onNightTurn(player, this); + } + }.run(); + } + +/* Deprecated by #onDayStart(LGDayStartEvent) + * + * @EventHandler + public void onVote(LGVoteEvent e) { + if(e.getGame() == getGame()) { + if(needToPlay.size() > 0) { + e.setCancelled(true); + new Runnable() { + public void run() { + if(needToPlay.size() == 0) { + e.getGame().nextNight(); + return; + } + LGPlayer player = needToPlay.remove(0); + onNightTurn(player, this); + } + }.run(); + } + } + }*/ + + @EventHandler + public void onNight(LGNightStart e) { + if(e.getGame() == getGame() && !e.isCancelled()) { + if(needToPlay.size() > 0) { + e.setCancelled(true); + new Runnable() { + public void run() { + if(needToPlay.size() == 0) { + e.getGame().nextNight(); + return; + } + LGPlayer player = needToPlay.remove(0); + onNightTurn(player, this); + } + }.run(); + } + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java new file mode 100644 index 0000000..d5eab75 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoup.java @@ -0,0 +1,176 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitRunnable; + +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class RChienLoup extends Role{ + static ItemStack[] items = new ItemStack[9]; + static { + items[3] = new ItemStack(Material.GOLDEN_APPLE); + ItemMeta meta = items[3].getItemMeta(); + meta.setDisplayName("§2Devenir Villageois"); + meta.setLore(Arrays.asList("§7§lVous n'aurez aucun pouvoir mais", + "§7§lresterez dans le camp du §a§lVillage§7§l.")); + items[3].setItemMeta(meta); + 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")); + items[5].setItemMeta(meta); + } + + public RChienLoup(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§a§lChien-Loup"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Au début de la première nuit, tu peux choisir entre rester fidèle aux §a§lVillageois§f ou alors rejoindre le clan des §c§lLoups-Garous§f."; + } + + @Override + public String getTask() { + return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 pourrait trouver de nouveaux amis..."; + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + public boolean hasPlayersLeft() { + return super.hasPlayersLeft() && !already; + } + + Runnable callback; + boolean already; + + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Choisis ton camp."); + inventory.setContents(items.clone()); + player.closeInventory(); + player.openInventory(inventory); + } + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + already = true; + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + closeInventory(player.getPlayer()); + player.hideView(); + //player.sendTitle("§cVous n'infectez personne", "§4Vous avez mis trop de temps à vous décider...", 80); + player.sendActionBarMessage("§6Tu rejoins le §a§lVillage."); + player.sendMessage("§6Tu rejoins le §a§lVillage."); + } + + boolean inMenu; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + lgp.sendActionBarMessage("§6Tu resteras fidèle au §a§lVillage§6."); + lgp.sendMessage("§6Tu resteras fidèle au §a§lVillage§6."); + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + + lgp.sendActionBarMessage("§6Tu as changé de camp."); + lgp.sendMessage("§6Tu as changé de camp."); + + //On le fait aussi rejoindre le camp des loups pour le tour pendant la nuit. + RChienLoupLG lgChienLoup = null; + for(Role role : getGame().getRoles()) + if(role instanceof RChienLoupLG) + lgChienLoup = (RChienLoupLG)role; + + if(lgChienLoup == null) + getGame().getRoles().add(lgChienLoup = new RChienLoupLG(getGame())); + + lgChienLoup.join(lgp, false); + lgp.updateOwnSkin(); + + lgp.hideView(); + callback.run(); + } + } + + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RChienLoupLG.java b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoupLG.java new file mode 100644 index 0000000..72b8447 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RChienLoupLG.java @@ -0,0 +1,74 @@ +package fr.leomelki.loupgarou.roles; + +import org.bukkit.potion.PotionEffectType; + +import fr.leomelki.loupgarou.classes.LGCustomItems; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; + +public class RChienLoupLG extends Role{ + public RChienLoupLG(LGGame game) { + super(game); + } + @Override + public String getName() { + for(LGPlayer lgp : getPlayers()) + if(lgp.getPlayer() != null && lgp.getPlayer().hasPotionEffect(PotionEffectType.INVISIBILITY)) + return "§c§lChien-Loup"; + return (getPlayers().size() > 0 ? "§a" : "§c")+"§lChien-Loup"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Au début de la première nuit, tu peux choisir entre rester fidèle aux §a§lVillageois§f ou alors rejoindre le clan des §c§lLoups-Garous§f."; + } + + @Override + public String getTask() { + return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 pourrait trouver de nouveaux amis..."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.LOUP_GAROU; + } + + @Override + public int getTimeout() { + return -1; + } + + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + System.out.println(player.getName()+" a rejoint les LG (Chien Loup)"); + player.setRole(this); + LGCustomItems.updateItem(player); + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) { + role.join(player, false); + System.out.println(player.getName()+" -> Chien LG -> Camp trouvé & join"); + for(LGPlayer lgp : role.getPlayers()) + if(lgp != player) + lgp.sendMessage("§7§l"+player.getName()+"§6 a rejoint les §c§lLoups-Garous§6."); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java b/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java new file mode 100644 index 0000000..c406567 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RCorbeau.java @@ -0,0 +1,111 @@ +package fr.leomelki.loupgarou.roles; + +import org.bukkit.event.EventHandler; +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{ + public RCorbeau(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lCorbeau"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux désigner un joueur qui se retrouvera le lendemain avec deux voix contre lui au vote."; + } + @Override + public String getTask() { + return "Tu peux choisir un joueur qui aura deux votes contre lui."; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 s'apprête à diffamer quelqu'un..."; + } + @Override + public int getTimeout() { + return 15; + } + + @Override + 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(); + } + } + }); + } + + @EventHandler + public void onNightStart(LGDayEndEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getGame().getAlive()) + lgp.getCache().remove("corbeau_selected"); + } + + @EventHandler + public void onVoteStart(LGVoteEvent e) { + if(e.getGame() == getGame()) + 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."); + } + }.runTask(MainLg.getInstance()); + + } + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java b/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java new file mode 100644 index 0000000..1d559e2 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RCupidon.java @@ -0,0 +1,280 @@ +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 RCupidon extends Role{ + public RCupidon(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lCupidon"; + } + @Override + public String getFriendlyName() { + return "de "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Dès le début de la partie, tu dois former un couple de deux joueurs. Leur objectif sera de survivre ensemble, car si l'un d'eux meurt, l'autre se suicidera."; + } + @Override + public String getTask() { + return "Choisis deux joueurs à mettre en couple."; + } + @Override + public String getBroadcastedTask() { + return getName()+"§9 choisit deux âmes à unir."; + } + + @Override + public int getTimeout() { + return 15; + } + @Override + public boolean hasPlayersLeft() { + return getGame().getNight() == 1; + } + + @Override + 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(); + } + } else { + sendHead(player, choosen); + player.getCache().set("cupidon_first", choosen); + } + } + } + }); + } + protected void setInLove(LGPlayer player1, LGPlayer player2) { + player1.getCache().set("inlove", player2); + player1.sendMessage("§9Tu tombes amoureux de §7§l"+player2.getName()+"§9, il est "+player2.getRole().getName()); + player1.sendMessage("§9§oTu peux lui parler en mettant un §e!§9 devant ton message."); + + player2.getCache().set("inlove", player1); + player2.sendMessage("§9Tu tombes amoureux de §7§l"+player1.getName()+"§9, il est "+player1.getRole().getName()); + player2.sendMessage("§9§oTu peux lui parler en mettant un §e!§9 devant ton message."); + + /* sendHead(player1, player2); + sendHead(player2, player1);*/ + + //On peut créer des cheats grâce à ça (qui permettent de savoir qui est en couple) + player1.updatePrefix(); + player2.updatePrefix(); + } + + WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), + 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(); + spawn.setEntityID(entityId); + spawn.setType(EntityType.DROPPED_ITEM); + //spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true)))); + Location loc = ofWho.getPlayer().getLocation(); + spawn.setX(loc.getX()); + spawn.setY(loc.getY()+1.9); + spawn.setZ(loc.getZ()); + spawn.setHeadPitch(0); + Location toLoc = to.getPlayer().getLocation(); + double diffX = loc.getX()-toLoc.getX(), + diffZ = loc.getZ()-toLoc.getZ(); + float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ))); + + spawn.setYaw(yaw); + spawn.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); + look.setEntityID(entityId); + look.setPitch(0); + look.setYaw(yaw); + look.sendPacket(to.getPlayer()); + + WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); + meta.setEntityID(entityId); + meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))); + meta.sendPacket(to.getPlayer()); + + + + new BukkitRunnable() { + + @Override + public void run() { + WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); + equip.setEntityID(entityId); + equip.setSlot(ItemSlot.HEAD); + ItemStack skull = new ItemStack(Material.SUGAR); + equip.setItem(skull); + equip.sendPacket(to.getPlayer()); + } + }.runTaskLater(MainLg.getInstance(), 2); + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getCache().remove("cupidon_first"); + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez mis personne en couple", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§9Tu n'as pas créé de couple."); + } + + + @EventHandler + public void onPlayerKill(LGPlayerGotKilledEvent e) { + if(e.getGame() == getGame() && e.getKilled().getCache().has("inlove") && !e.getKilled().getCache().get("inlove").isDead()) { + LGPlayer killed = e.getKilled().getCache().get("inlove"); + LGPlayerKilledEvent event = new LGPlayerKilledEvent(getGame(), killed, Reason.LOVE); + Bukkit.getPluginManager().callEvent(event); + if(!event.isCancelled()) + getGame().kill(event.getKilled(), event.getReason(), false); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onGameEnd(LGGameEndEvent e) { + if(e.getGame() == getGame()) { + WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); + ArrayList ids = new ArrayList(); + for(LGPlayer lgp : getGame().getInGame()) + ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId()); + int[] intList = new int[ids.size()]; + for(int i = 0;iget("inlove"); + boolean winEnCouple = (lgp.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU) || lgp.getRoleWinType() == RoleWinType.SEUL || player2.getRoleWinType() == RoleWinType.SEUL; + if(winEnCouple) { + System.out.println(lgp.getName()+" ne peut pas gagner car il était en couple !"); + e.getWinners().remove(lgp); + } + } + } + } + } + + @EventHandler + public void onEndCheck(LGEndCheckEvent e) { + if(e.getGame() == getGame()) { + ArrayList winners = new ArrayList(); + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getRoleWinType() != RoleWinType.NONE) + winners.add(lgp); + if(winners.size() == 2) { + LGPlayer player1 = winners.get(0), + player2 = winners.get(1); + boolean winEnCouple = (player1.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU) || player1.getRoleWinType() == RoleWinType.SEUL || player2.getRoleWinType() == RoleWinType.SEUL; + if(player1.getCache().get("inlove") == player2 && /*player1.isABadGuy() != player2.isABadGuy()*/ (player1.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU)) + e.setWinType(LGWinType.COUPLE); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onChat(AsyncPlayerChatEvent e) { + LGPlayer player = LGPlayer.thePlayer(e.getPlayer()); + if(player.getGame() == getGame()) { + if(e.getMessage().startsWith("!") && player.getCache().has("inlove")) { + player.sendMessage("§d\u2764 "+player.getName()+" §6» §f"+e.getMessage().substring(1)); + player.getCache().get("inlove").sendMessage("§d\u2764 "+player.getName()+" §6» §f"+e.getMessage().substring(1)); + e.setCancelled(true); + } + } + } + @EventHandler(priority = EventPriority.HIGH) + public void onUpdatePrefix (LGUpdatePrefixEvent e) { + if(e.getGame() == getGame()) + if(e.getTo().getCache().get("inlove") == e.getPlayer() || ((e.getTo() == e.getPlayer() || e.getTo().getRole() == this) && e.getPlayer().getCache().has("inlove"))) + e.setPrefix("§d\u2764 §f"+e.getPrefix()); + } + +/* @EventHandler + public void onNight(LGDayEndEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getCache().has("inlove")) + lgp.unMute(lgp.getCache().get("inlove")); + }*/ + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java b/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java new file mode 100644 index 0000000..48a39d8 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RDetective.java @@ -0,0 +1,124 @@ +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) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lDétective"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu mènes l'enquête sur deux joueurs pour découvrir s'ils font partie du même camp."; + } + @Override + public String getTask() { + return "Choisis deux joueurs à étudier."; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 est sur une enquête..."; + } + + @Override + public int getTimeout() { + return 15; + } + @Override + 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(); + } + } 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()); + } + } + } + }); + } + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getCache().remove("detective_first"); + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez mis personne en couple", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§9Tu n'as pas créé de couple."); + } + + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java b/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java new file mode 100644 index 0000000..fe3b961 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RDictateur.java @@ -0,0 +1,273 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +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.scheduler.BukkitRunnable; + +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.events.LGDayEndEvent; +import fr.leomelki.loupgarou.events.LGMayorVoteEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import fr.leomelki.loupgarou.events.LGVoteEvent; + +public class RDictateur extends Role{ + static private ItemStack[] items = new ItemStack[9]; + static private Inventory inventory; + 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")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER); + meta = items[5].getItemMeta(); + meta.setDisplayName("§e§lCoup d'État"); + meta.setLore(Arrays.asList( + "§8Prends le contrôle du village", + "§8et choisis seul qui mourra demain.", + "", + "§8Si tu tues un §a§lVillageois§8, tu", + "§8l'auras sur la conscience.")); + items[5].setItemMeta(meta); + inventory = Bukkit.createInventory(null, 9, "§7Veux-tu faire un coup d'état ?"); + inventory.setContents(items.clone()); + } + public RDictateur(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lDictateur"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Une fois dans la partie, tu peux choisir d'effectuer un §e§o§lcoup d'état§f, tu choisiras alors seul qui mourra au jour suivant. Si tu fais le bon choix, tu deviendras §5§lCapitaine§f mais si tu tues un §a§lVillageois§f, tu te suicideras la nuit qui suit."; + } + @Override + public String getTask() { + return "Veux-tu réaliser un coup d'état ?"; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 décide s'il veut se dévoiler."; + } + + @Override + public int getTimeout() { + return 15; + } + + public void openInventory(Player player) { + inMenu = true; + player.closeInventory(); + player.openInventory(inventory); + } + Runnable callback, run; + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.hideView(); + closeInventory(player.getPlayer()); + /*player.sendTitle("§cVous ne faites pas votre coup d'état.", "§4Vous avez mis trop de temps à vous décider...", 80); + player.sendMessage("§cVous ne faites pas votre coup d'état."); + player.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/ + } + + boolean inMenu = false; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + /*lgp.sendMessage("§cVous ne faites pas votre coup d'état."); + lgp.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/ + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + lgp.sendActionBarMessage("§9§lTu effectueras un coup d'état"); + lgp.sendMessage("§6Tu as décidé de faire un coup d'état."); + lgp.getCache().set("coup_d_etat", true); + lgp.getCache().set("just_coup_d_etat", true); + lgp.hideView(); + callback.run(); + } + } + + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player p = e.getPlayer(); + LGPlayer player = LGPlayer.thePlayer(p); + if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { + getGame().cancelWait(); + player.stopChoosing(); + p.getInventory().setItem(8, null); + p.updateInventory(); + getGame().broadcastMessage("§7§l"+player.getName()+"§9 n'a tué personne."); + run.run(); + } + } + + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + + @EventHandler + public void onMayorVote(LGMayorVoteEvent e) { + if(e.getGame() == getGame()) + onTurn(e); + } + + @EventHandler + public void onVote(LGVoteEvent e) { + if(e.getGame() == getGame()) + onTurn(e); + } + public void onTurn(Cancellable e) { + for(LGPlayer lgp : getPlayers()) + if(lgp.getCache().getBoolean("just_coup_d_etat")) + e.setCancelled(true); + + if(!e.isCancelled()) + return; + + Iterator ite = ((ArrayList)getPlayers().clone()).iterator(); + new Runnable() { + public void run() { + run = this; + if(ite.hasNext()) { + LGPlayer lgp = ite.next(); + if(lgp.getCache().getBoolean("just_coup_d_etat")) { + getPlayers().remove(lgp); + lgp.getCache().remove("just_coup_d_etat"); + getGame().broadcastMessage("§7§l"+lgp.getName()+" §9réalise un coup d'état."); + //lgp.sendTitle("§6Vous faites votre coup d'état", "§aChoisissez qui tuer", 60); + + //On le met sur le slot 0 pour éviter un missclick sur la croix + WrapperPlayServerHeldItemSlot hold = new WrapperPlayServerHeldItemSlot(); + hold.setSlot(0); + hold.sendPacket(lgp.getPlayer()); + + lgp.sendMessage("§6Choisis un joueur à exécuter."); + getGame().wait(60, ()->{ + lgp.stopChoosing(); + getGame().broadcastMessage("§7§l"+lgp.getName()+"§9 n'a tué personne."); + 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)"; + }); + lgp.choose((choosen)->{ + if(choosen != null) { + getGame().cancelWait(); + lgp.stopChoosing(); + lgp.getPlayer().getInventory().setItem(8, null); + lgp.getPlayer().updateInventory(); + kill(choosen, lgp, this); + } + }); + lgp.getPlayer().getInventory().setItem(8, items[3]); + lgp.getPlayer().updateInventory(); + } + }else + getGame().nextNight(); + } + }.run(); + } + protected void kill(LGPlayer choosen, LGPlayer dicta, Runnable callback) { + RoleType roleType = choosen.getRoleType(); + + LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), choosen, Reason.DICTATOR); + Bukkit.getPluginManager().callEvent(killEvent); + if(killEvent.isCancelled())return; + if(getGame().kill(killEvent.getKilled(), killEvent.getReason(), true)) + return; + + if(roleType != RoleType.VILLAGER) { + getGame().broadcastMessage("§7§l"+dicta.getName()+" §9devient le §5§lCapitaine§9 du village."); + getGame().setMayor(dicta); + } else { + getGame().kill(dicta, Reason.DICTATOR_SUICIDE); + for(LGPlayer lgp : getGame().getInGame()) { + if(lgp == dicta) + lgp.sendMessage("§9§oÇa ne s'est pas passé comme prévu..."); + else + lgp.sendMessage("§9Le "+getName()+"§9 s'est trompé, il mourra la nuit suivante."); + } + } + callback.run(); + } + + @EventHandler + public void onNight(LGDayEndEvent e) { + if(e.getGame() == getGame()) { + LGPlayer lgp = getGame().getDeaths().get(Reason.DICTATOR_SUICIDE); + if(lgp != null) + lgp.sendMessage("§8§oDes pensées sombres hantent ton esprit..."); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java new file mode 100644 index 0000000..a4087c6 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvage.java @@ -0,0 +1,118 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Random; + +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.events.LGPlayerKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class REnfantSauvage extends Role{ + public REnfantSauvage(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§a§lEnfant-Sauvage"; + } + + @Override + public String getFriendlyName() { + return "de l'"+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Au début de la première nuit, tu dois choisir un joueur comme modèle. S'il meurt au cours de la partie, tu deviendras un §c§lLoup-Garou§f."; + } + + @Override + public String getTask() { + return "Qui veux-tu prendre comme modèle ?"; + } + + @Override + public String getBroadcastedTask() { + return "L'"+getName()+"§9 cherche ses marques..."; + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + 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); + } + private static Random random = new Random(); + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.hideView(); + LGPlayer choosen = null; + while(choosen == null || choosen == player) + choosen = getGame().getAlive().get(random.nextInt(getGame().getAlive().size())); + 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); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerKilled(LGPlayerKilledEvent e) { + if(e.getGame() == getGame()) + if(e.getKilled().getCache().has("enfant_svg_d")) { + LGPlayer enfant = e.getKilled().getCache().remove("enfant_svg_d"); + if(!enfant.isDead() && enfant.getCache().remove("enfant_svg") == e.getKilled()) { + enfant.sendMessage("§7§l"+e.getKilled().getName()+"§6 est mort, tu deviens un §c§lLoup-Garou§6."); + REnfantSauvageLG lgEnfantSvg = null; + for(Role role : getGame().getRoles()) + if(role instanceof REnfantSauvageLG) + lgEnfantSvg = (REnfantSauvageLG)role; + + if(lgEnfantSvg == null) + getGame().getRoles().add(lgEnfantSvg = new REnfantSauvageLG(getGame())); + + lgEnfantSvg.join(enfant, false); + } + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java new file mode 100644 index 0000000..1d86041 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/REnfantSauvageLG.java @@ -0,0 +1,89 @@ +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; + +public class REnfantSauvageLG extends Role{ + public REnfantSauvageLG(LGGame game) { + super(game); + } + @Override + public String getName() { + for(LGPlayer lgp : getPlayers()) + if(lgp.getPlayer() != null && lgp.getPlayer().hasPotionEffect(PotionEffectType.INVISIBILITY)) + return "§c§lEnfant-Sauvage"; + return (getPlayers().size() > 0 ? "§a" : "§c")+"§lEnfant-Sauvage"; + } + + @Override + public String getFriendlyName() { + return "de l'"+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Au début de la première nuit, tu dois choisir un joueur comme modèle. S'il meurt au cours de la partie, tu deviendras un §c§lLoup-Garou§f."; + } + + @Override + public String getTask() { + return "Qui veux-tu prendre comme modèle ?"; + } + + @Override + public String getBroadcastedTask() { + return "L'"+getName()+"§9 cherche ses marques..."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.LOUP_GAROU; + } + + @Override + public int getTimeout() { + return -1; + } + + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + System.out.println(player.getName()+" a rejoint les LG (Enfant Sauvage)"); + player.setRole(this); + LGCustomItems.updateItem(player); + RLoupGarou lgRole = null; + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) + lgRole = (RLoupGarou)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(); + } + }); + } + + lgRole.join(player, false); + System.out.println(player.getName()+" -> Enfant Sauvage -> Camp trouvé & join"); + for(LGPlayer lgp : lgRole.getPlayers()) + if(lgp != player) + lgp.sendMessage("§7§l"+player.getName()+"§6 a rejoint les §c§lLoups-Garous§6."); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RFaucheur.java b/src/main/java/fr/leomelki/loupgarou/roles/RFaucheur.java new file mode 100644 index 0000000..3356469 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RFaucheur.java @@ -0,0 +1,136 @@ +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; + +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class RFaucheur extends Role{ + public RFaucheur(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lFaucheur"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Si les §c§lLoups-Garous§f te tuent pendant la nuit, tu emporteras l’un d’entre eux dans ta mort, mais si tu meurs lors du vote du §a§lvillage§f, ce sont tes deux voisins qui en paieront le prix."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + return -1; + } + + private static Random random = new Random(); + + @EventHandler(priority = EventPriority.LOWEST) + public void onKill(LGPlayerKilledEvent e) { + if (e.getKilled().getRole() == this) { + LGPlayer killed = e.getKilled(); + if(killed.getCache().getBoolean("faucheur_did"))//A déjà fait son coup de faucheur ! + return; + killed.getCache().set("faucheur_did", true); + if (e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU) {//car le switch buggait (wtf) + // Mort par les LG + // Tue un lg au hasard + LGPlayer selected = null; + for (Role role : getGame().getRoles()) + if (role instanceof RLoupGarou) + selected = role.getPlayers().get(random.nextInt(role.getPlayers().size())); + if (selected != null) { + LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), e.getKilled(), e.getReason()); + Bukkit.getPluginManager().callEvent(killEvent); + e.setKilled(selected); + e.setReason(Reason.FAUCHEUR); + if (killEvent.isCancelled()) + return; + getGame().kill(killEvent.getKilled(), killEvent.getReason(), false); + } + } else if (e.getReason() == Reason.VOTE) { + List original = MainLg.getInstance().getConfig().getList("spawns"); + int size = original.size(); + // double middle = ((double)size)/2D; + int killedPlace = killed.getPlace(); + + LGPlayer droite = null, gauche = null; + for (int i = killedPlace + 1;; i++) { + if (i == size) + i = 0; + LGPlayer lgp = getGame().getPlacements().get(i); + if (lgp != null && !lgp.isDead()) { + droite = lgp; + break; + } + if (lgp == killed)// Fait un tour complet + break; + } + for (int i = killedPlace - 1;; i--) { + if (i == -1) + i = size - 1; + LGPlayer lgp = getGame().getPlacements().get(i); + if (lgp != null && !lgp.isDead()) { + gauche = lgp; + break; + } + if (lgp == killed)// Fait un tour complet + break; + } + if (droite != null) { + LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), e.getKilled(), e.getReason()); + Bukkit.getPluginManager().callEvent(killEvent); + + e.setKilled(droite); + e.setReason(Reason.FAUCHEUR); + + if (!killEvent.isCancelled()) + getGame().kill(killEvent.getKilled(), killEvent.getReason(), false); + } + if (gauche != null) { + LGPlayerKilledEvent killEvent; + if (droite == null) { + killEvent = new LGPlayerKilledEvent(getGame(), e.getKilled(), e.getReason()); + e.setKilled(gauche); + e.setReason(Reason.FAUCHEUR); + } else + killEvent = new LGPlayerKilledEvent(getGame(), gauche, Reason.FAUCHEUR); + Bukkit.getPluginManager().callEvent(killEvent); + if (!killEvent.isCancelled()) + getGame().kill(killEvent.getKilled(), killEvent.getReason(), false); + } + } + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java b/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java new file mode 100644 index 0000000..733fe18 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RGarde.java @@ -0,0 +1,113 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; +import java.util.List; + +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; + +public class RGarde extends Role{ + public RGarde(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lGarde"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux te protéger toi ou quelqu'un d'autre des attaques §c§lhostiles§f. Tu ne peux pas protéger deux fois d’affilé la même personne."; + } + @Override + public String getTask() { + return "Choisis un joueur à protéger."; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 choisit un joueur à protéger."; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + 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(); + } + } + } + }); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getCache().remove("garde_lastProtected"); + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez protégé personne.", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§cVous n'avez protégé personne cette nuit."); + } + + private static List reasonsProtected = Arrays.asList(Reason.LOUP_GAROU, Reason.LOUP_BLANC, Reason.GM_LOUP_GAROU, Reason.ASSASSIN); + + @EventHandler + public void onPlayerKill(LGNightPlayerPreKilledEvent e) { + if(e.getGame() == getGame() && reasonsProtected.contains(e.getReason()) && e.getKilled().getCache().getBoolean("garde_protected")) { + e.getKilled().getCache().remove("garde_protected"); + e.setReason(Reason.DONT_DIE); + } + } + @EventHandler + public void onDayStart(LGPreDayStartEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getGame().getInGame()) + lgp.getCache().remove("garde_protected"); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java b/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java new file mode 100644 index 0000000..c0d22d7 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RGrandMechantLoup.java @@ -0,0 +1,121 @@ +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; + +public class RGrandMechantLoup extends Role{ + + public RGrandMechantLoup(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§c§lGrand Méchant Loup"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec les §c§lLoups-Garous"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec les §c§lLoups-Garous§f. Chaque nuit, tu te réunis avec tes compères pour décider d'une victime à éliminer... Tant qu'aucun autre §c§lLoup§f n'est mort, tu peux, chaque nuit, dévorer une victime supplémentaire."; + } + + @Override + public String getTask() { + return "Choisis un joueur à dévorer."; + } + + @Override + public String getBroadcastedTask() { + return "Le §c§lGrand Méchant Loup§9 n'en a pas terminé..."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.LOUP_GAROU; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + public boolean hasPlayersLeft() { + return super.hasPlayersLeft() && !lgDied; + } + boolean lgDied; + Runnable callback; + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + 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(); + } + } + }); + } + + @EventHandler + public void onPlayerDie(LGPlayerKilledEvent e) {//Quand un Loup-Garou meurt, les grands méchants loups ne peuvent plus jouer. + if(e.getGame() == getGame()) + if(e.getKilled().getRoleType() == RoleType.LOUP_GAROU) + lgDied = true; + } + + + + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.hideView(); + player.sendMessage("§6Tu n'as tué personne."); + } + + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) + role.join(player, false); + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java new file mode 100644 index 0000000..8e647ca --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarou.java @@ -0,0 +1,201 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.loupgarou.classes.LGCustomSkin; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.LGVote; +import fr.leomelki.loupgarou.classes.LGWinType; +import fr.leomelki.loupgarou.classes.chat.LGChat; +import fr.leomelki.loupgarou.events.LGDayEndEvent; +import fr.leomelki.loupgarou.events.LGGameEndEvent; +import fr.leomelki.loupgarou.events.LGNightEndEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import fr.leomelki.loupgarou.events.LGSkinLoadEvent; +import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent; +import lombok.Getter; + +public class RLoupGarou extends Role{ + + public RLoupGarou(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§c§lLoup-Garou"; + } + + @Override + public String getFriendlyName() { + return "des §c§lLoups-Garous"; + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec les §c§lLoups-Garous"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec les §c§lLoups-Garous§f. Chaque nuit, tu te réunis avec tes compères pour décider d'une victime à éliminer."; + } + + @Override + public String getTask() { + return "Vote pour la cible à tuer."; + } + + @Override + public String getBroadcastedTask() { + return "Les §c§lLoups-Garous§9 choisissent leur cible."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.LOUP_GAROU; + } + + @Override + public int getTimeout() { + return 30; + } + + @Getter private LGChat chat = new LGChat((sender, message) -> { + return "§c"+sender.getName()+" §6» §f"+message; + }); + + boolean showSkins = false; + LGVote vote; + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + //On peut créer des cheats grâce à ça (qui permettent de savoir qui est lg/inf) + for(LGPlayer p : getPlayers()) + p.updatePrefix(); + } + + 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"; + }); + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getRoleType() == RoleType.LOUP_GAROU) + lgp.showView(); + for(LGPlayer player : getPlayers()) { + player.sendMessage("§6"+getTask()); + // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); + player.joinChat(chat); + } + vote.start(getPlayers(), getPlayers(), ()->{ + onNightTurnEnd(); + callback.run(); + }); + } + private void onNightTurnEnd() { + for(LGPlayer lgp : getGame().getAlive()) + if(lgp.getRoleType() == RoleType.LOUP_GAROU) + lgp.hideView(); + for(LGPlayer player : getPlayers()) { + player.leaveChat(); + } + + LGPlayer choosen = vote.getChoosen(); + if(choosen == null) { + if(vote.getVotes().size() > 0) { + int max = 0; + boolean equal = false; + for(Entry> entry : vote.getVotes().entrySet()) + if(entry.getValue().size() > max) { + System.out.println(entry.getKey()+" has "+entry.getValue().size()+" vote(s)"); + equal = false; + max = entry.getValue().size(); + choosen = entry.getKey(); + }else if(entry.getValue().size() == max) + equal = true; + if(equal) { + choosen = null; + 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()); + System.out.println("Random choice for LG (removed lg from vote)"); + if(choosable.size() > 0) + choosen = choosable.get(getGame().getRandom().nextInt(choosable.size())); + } + } + } + if(choosen != null) { + getGame().kill(choosen, Reason.LOUP_GAROU); + for(LGPlayer player : getPlayers()) + player.sendMessage("§6Les §c§lLoups§6 ont décidé de tuer §7§l"+choosen.getName()+"§6."); + }else + for(LGPlayer player : getPlayers()) + player.sendMessage("§6Personne n'a été désigné pour mourir."); + } + + @EventHandler + public void onGameJoin(LGGameEndEvent e) { + if(e.getGame() == getGame()) { + WrapperPlayServerScoreboardTeam teamDelete = new WrapperPlayServerScoreboardTeam(); + teamDelete.setMode(1); + teamDelete.setName("loup_garou_list"); + + for(LGPlayer lgp : getGame().getInGame()) + teamDelete.sendPacket(lgp.getPlayer()); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onSkinChange(LGSkinLoadEvent e) { + if(e.getGame() == getGame()) + if(getPlayers().contains(e.getPlayer()) && getPlayers().contains(e.getTo()) && showSkins) { + e.getProfile().getProperties().removeAll("textures"); + e.getProfile().getProperties().put("textures", LGCustomSkin.WEREWOLF.getProperty()); + } + } + @EventHandler + public void onGameEnd(LGGameEndEvent e) { + if(e.getGame() == getGame() && e.getWinType() == LGWinType.LOUPGAROU) + for(LGPlayer lgp : getGame().getInGame()) + if(lgp.getRoleWinType() == RoleWinType.LOUP_GAROU)//Changed to wintype + e.getWinners().add(lgp); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onUpdatePrefix (LGUpdatePrefixEvent e) { + if(e.getGame() == getGame()) + if(getPlayers().contains(e.getTo()) && getPlayers().contains(e.getPlayer())) { + System.out.println("Prefix of "+e.getPlayer().getName()+" updated (lg) for "+e.getTo().getName()); + e.setPrefix(e.getPrefix()+"§c"); + } + } + + @EventHandler + public void onDay(LGNightEndEvent e) { + if(e.getGame() == getGame()) { + showSkins = false; + for(LGPlayer player : getPlayers()) + player.updateOwnSkin(); + } + } + @EventHandler + public void onNight(LGDayEndEvent e) { + if(e.getGame() == getGame()) { + showSkins = true; + for(LGPlayer player : getPlayers()) + player.updateOwnSkin(); + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java new file mode 100644 index 0000000..4c61464 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouBlanc.java @@ -0,0 +1,167 @@ +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.Reason; + +public class RLoupGarouBlanc extends Role{ + private static ItemStack skip; + static { + skip = new ItemStack(Material.IRON_NUGGET); + ItemMeta meta = skip.getItemMeta(); + meta.setDisplayName("§7§lNe rien faire"); + meta.setLore(Arrays.asList("§8Passez votre tour")); + skip.setItemMeta(meta); + } + + public RLoupGarouBlanc(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§c§lLoup Blanc"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes §7§lSEUL"; + } + + @Override + public String getDescription() { + return "Tu gagnes §7§lSEUL§f. Les autres §c§lLoups§f croient que tu es un loup normal, mais une nuit sur deux, tu peux assassiner l'un d'eux au choix."; + } + + @Override + public String getTask() { + return "Tu peux choisir un §c§lLoup-Garou§6 à éliminer, ou te rendormir."; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 pourrait faire un ravage cette nuit..."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.SEUL; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + public boolean hasPlayersLeft() { + return super.hasPlayersLeft() && getGame().getNight()%2 == 0; + } + Runnable callback; + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + this.callback = callback; + RLoupGarou lg_ = null; + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) { + lg_ = (RLoupGarou)role; + break; + } + + 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(); + } + } + }); + } + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player p = e.getPlayer(); + LGPlayer player = LGPlayer.thePlayer(p); + if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { + player.stopChoosing(); + p.getInventory().setItem(8, null); + p.updateInventory(); + player.hideView(); + player.sendMessage("§6Tu n'as tué personne."); + callback.run(); + } + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.getPlayer().getInventory().setItem(8, null); + player.getPlayer().updateInventory(); + player.hideView(); + player.sendMessage("§6Tu n'as tué personne."); + } + + RLoupGarou lg; + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) + (lg = (RLoupGarou) role).join(player, false); + } + + @EventHandler + public void onEndgameCheck(LGEndCheckEvent e) { + if(e.getGame() == getGame() && e.getWinType() == LGWinType.SOLO) { + if(getPlayers().size() > 0) { + if(lg.getPlayers().size() > getPlayers().size()) + e.setWinType(LGWinType.NONE); + else if(lg.getPlayers().size() == getPlayers().size()) + e.setWinType(LGWinType.LOUPGAROUBLANC); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEndGame(LGGameEndEvent e) { + if(e.getWinType() == LGWinType.LOUPGAROUBLANC) { + e.getWinners().clear(); + e.getWinners().addAll(getPlayers()); + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java new file mode 100644 index 0000000..3e4a34f --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RLoupGarouNoir.java @@ -0,0 +1,227 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitRunnable; + +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGCustomItems; +import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.LGVote; +import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent; +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 { + 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")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material.ROTTEN_FLESH); + meta = items[5].getItemMeta(); + meta.setDisplayName("§c§lInfecter"); + meta.setLore(Arrays.asList( + "§8Tu peux infecter la cible du vote.", + "§8Le joueur tiendra avec les Loups.")); + items[5].setItemMeta(meta); + skip[4] = items[3]; + } + + public RLoupGarouNoir(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§c§lLoup Noir"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec les §c§lLoups-Garous"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec les §c§lLoups-Garous§f. Chaque nuit, tu te réunis avec tes compères pour décider d'une victime à éliminer... Une fois dans la partie, tu peux transformer la personne désignée en §c§lLoup§f. L'infecté conserve ses pouvoirs mais gagne désormais avec les §c§lLoups§f."; + } + + @Override + public String getTask() { + return "Veux-tu infecter la cible du vote ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 décide s'il veut infecter sa cible."; + } + @Override + public RoleType getType() { + return RoleType.LOUP_GAROU; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.LOUP_GAROU; + } + + @Override + public int getTimeout() { + return 15; + } + + @Override + public boolean hasPlayersLeft() { + return super.hasPlayersLeft() && getGame().getDeaths().containsKey(Reason.LOUP_GAROU); + } + + LGVote vote; + Runnable callback; + LGPlayer toInfect; + + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Infecter "+toInfect.getName()+" ?"); + inventory.setContents(toInfect == null ? skip.clone() : items.clone()); + player.closeInventory(); + player.openInventory(inventory); + } + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + toInfect = getGame().getDeaths().get(Reason.LOUP_GAROU); + if(toInfect.getRoleType() == RoleType.LOUP_GAROU) + toInfect = null; + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getPlayer().getInventory().setItem(8, null); + player.stopChoosing(); + closeInventory(player.getPlayer()); + player.getPlayer().updateInventory(); + player.hideView(); + //player.sendTitle("§cVous n'infectez personne", "§4Vous avez mis trop de temps à vous décider...", 80); + player.sendMessage("§6Tu n'as rien fait cette nuit."); + } + + boolean inMenu = false; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName()) && toInfect != null) { + e.setCancelled(true); + closeInventory(player); + player.updateInventory(); + closeInventory(player); + + lgp.getCache().set("has_infected", true); + toInfect.getCache().set("infected", true); + getPlayers().remove(lgp); + toInfect.getCache().set("just_infected", true); + lgp.sendActionBarMessage("§9§lVous infectez §9"+toInfect.getName()); + lgp.sendMessage("§6Tu as infecté §7§l"+toInfect.getName()+"§6."); + lgp.stopChoosing(); + getGame().getDeaths().remove(Reason.LOUP_GAROU, toInfect); + lgp.hideView(); + callback.run(); + } + } + @EventHandler(priority = EventPriority.HIGHEST) + public void onDayStart(LGNightEndEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer player : getGame().getAlive()) { + if(player.getCache().getBoolean("just_infected")) { + player.getCache().remove("just_infected"); + player.sendMessage("§6Tu as été infecté pendant la nuit."); + player.sendMessage("§6§oTu gagnes désormais avec les §c§l§oLoups-Garous§6§o."); + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) + if(!player.isDead()) {//Si il n'a pas été tué je ne sais comment + role.join(player, false); + player.getPlayer().getInventory().setItemInOffHand(new ItemStack(LGCustomItems.getItem(player))); + } + + for(LGPlayer lgp : getGame().getInGame()) { + if(lgp.getRoleType() == RoleType.LOUP_GAROU) + lgp.sendMessage("§7§l"+player.getName()+"§6 s'est fait infecter pendant la nuit."); + else + lgp.sendMessage("§6Un joueur a été §c§linfecté§6 pendant la nuit."); + } + + if(getGame().checkEndGame()) + e.setCancelled(true); + } + } + } + + @Override + public void join(LGPlayer player, boolean sendMessage) { + super.join(player, sendMessage); + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) + role.join(player, false); + } + + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + + @EventHandler + public void onCustomItemChange(LGCustomItemChangeEvent e) { + if(e.getGame() == getGame()) + if(e.getPlayer().getCache().getBoolean("infected")) + e.getConstraints().add(LGCustomItemsConstraints.INFECTED.getName()); + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RMedium.java b/src/main/java/fr/leomelki/loupgarou/roles/RMedium.java new file mode 100644 index 0000000..690d719 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RMedium.java @@ -0,0 +1,95 @@ +package fr.leomelki.loupgarou.roles; + +import org.bukkit.event.EventHandler; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.classes.chat.LGChat; +import fr.leomelki.loupgarou.events.LGDayEndEvent; +import fr.leomelki.loupgarou.events.LGPreDayStartEvent; +import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; + +public class RMedium extends Role{ + public RMedium(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lMédium"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux communiquer avec les morts pour tenter de récupérer des informations cruciales."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + return -1; + } + + @EventHandler + public void onNight(LGDayEndEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getPlayers()) { + lgp.sendMessage("§8§oTu entres en contact avec le monde des morts..."); + joinChat(lgp); + } + } + + + private void joinChat(LGPlayer lgp) { + lgp.joinChat(getGame().getSpectatorChat(), new LGChat.LGChatCallback() { + + @Override + public String receive(LGPlayer sender, String message) { + return "§7"+sender.getName()+"§6 » §f"+message; + } + + @Override + public String send(LGPlayer sender, String message) { + return getName()+"§6 » §f"+message; + } + + }); + } + @EventHandler + public void onRoleTurn(LGRoleTurnEndEvent e) { + if(e.getGame() == getGame()) + if(e.getPreviousRole() instanceof RLoupGarou) + for(LGPlayer lgp : getPlayers()) + if(lgp.getChat() != getGame().getSpectatorChat()) { + lgp.sendMessage("§6§oTu peux de nouveau parler aux morts..."); + joinChat(lgp); + } + } + + @EventHandler + public void onDay(LGPreDayStartEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getPlayers()) + lgp.leaveChat(); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java b/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java new file mode 100644 index 0000000..ca4d334 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPetiteFille.java @@ -0,0 +1,75 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; +import java.util.List; + +import org.bukkit.event.EventHandler; + +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; + +public class RPetiteFille extends Role{ + public RPetiteFille(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lPetite Fille"; + } + @Override + public String getFriendlyName() { + return "de la "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner les §c§lLoups§f."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + 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"); + + @EventHandler + public void onChangeRole(LGRoleTurnEndEvent e) { + if(e.getGame() == getGame()) { + if(e.getNewRole() instanceof RLoupGarou) + for(Role role : getGame().getRoles()) + if(role instanceof RLoupGarou) { + RLoupGarou lgRole = (RLoupGarou)role; + for(LGPlayer player : getPlayers()) + if(!player.getCache().getBoolean("infected")) + player.joinChat(lgRole.getChat(), (sender, message)->{ + return "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message; + }, true); + break; + } + if(e.getPreviousRole() instanceof RLoupGarou) + for(LGPlayer player : getPlayers()) + if(!player.getCache().getBoolean("infected")) + player.leaveChat(); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java b/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java new file mode 100644 index 0000000..138c02d --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPirate.java @@ -0,0 +1,213 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +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.scheduler.BukkitRunnable; + +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 { + 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")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material.ROTTEN_FLESH); + meta = items[5].getItemMeta(); + meta.setDisplayName("§6§lPrendre un otage"); + meta.setLore(Arrays.asList( + "§8Tu peux prendre un joueur en otage", + "§8Si tu meurs du vote, il mourra à ta place.")); + items[5].setItemMeta(meta); + } + + public RPirate(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§a§lPirate"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Une fois dans la partie, tu peux prendre en otage un autre joueur. Si tu es désigné à l'issue du vote de jour, ton §lotage§f mourra à ta place et ton rôle sera dévoilé au reste du village"; + } + + @Override + public String getTask() { + return "Veux-tu prendre quelqu'un en otage ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 aiguise son crochet..."; + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + + @Override + public int getTimeout() { + return 15; + } + + Runnable callback; + + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu prendre un otage ?"); + inventory.setContents(items.clone()); + player.closeInventory(); + player.openInventory(inventory); + } + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getPlayer().getInventory().setItem(8, null); + player.stopChoosing(); + closeInventory(player.getPlayer()); + player.getPlayer().updateInventory(); + player.hideView(); + //player.sendTitle("§cVous n'infectez personne", "§4Vous avez mis trop de temps à vous décider...", 80); + player.sendMessage("§6Tu n'as rien fait cette nuit."); + } + + boolean inMenu = false; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + player.getInventory().setItem(8, items[3]); + player.updateInventory(); + //Pour éviter les missclick + WrapperPlayServerHeldItemSlot held = new WrapperPlayServerHeldItemSlot(); + 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); + } + } + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerKilled(LGPlayerKilledEvent e) { + if(e.getGame() == getGame() && e.getReason() == Reason.VOTE) + if(e.getKilled().getCache().has("pirate_otage")) { + LGPlayer otage = e.getKilled().getCache().remove("pirate_otage"); + if(!otage.isDead() && otage.getCache().get("pirate_otage_d") == e.getKilled()) { + getGame().broadcastMessage("§7§l"+e.getKilled().getName()+"§6 est "+getName()+"§6, c'est son otage qui va mourir."); + e.setKilled(otage); + e.setReason(Reason.PIRATE); + } + } + } + + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player player = e.getPlayer(); + LGPlayer lgp = LGPlayer.thePlayer(player); + if(lgp.getRole() == this) { + if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.stopChoosing(); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + lgp.hideView(); + callback.run(); + } + } + } + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java b/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java new file mode 100644 index 0000000..3eeba2e --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPretre.java @@ -0,0 +1,292 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +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.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; + +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.WrapperPlayServerEntityMetadata; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; +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 { + 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")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material.ROTTEN_FLESH); + meta = items[5].getItemMeta(); + meta.setDisplayName("§2§lRessuciter"); + meta.setLore(Arrays.asList( + "§8Tu peux ressusciter un §a§lVillageois", + "§8mort précédemment pendant la partie.")); + items[5].setItemMeta(meta); + } + + public RPretre(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§a§lPrêtre"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Une fois dans la partie, tu peux ressusciter parmi les morts un membre du §a§lVillage§f, qui reviendra à la vie sans ses pouvoirs."; + } + + @Override + public String getTask() { + return "Veux-tu ressusciter un allié défunt ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 récite ses ouvrages..."; + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + + @Override + public int getTimeout() { + return 30; + } + @Override + public boolean hasPlayersLeft() { + for(LGPlayer pretre : getPlayers()) + for(LGPlayer lgp : getGame().getInGame()) + if(lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == pretre.getRoleType())) + return super.hasPlayersLeft(); + return false; + } + + Runnable callback; + + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu réssuciter quelqu'un ?"); + inventory.setContents(items.clone()); + player.closeInventory(); + player.openInventory(inventory); + } + WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); + @SuppressWarnings("deprecation") + @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()); + WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); + meta.setEntityID(lgp.getPlayer().getEntityId()); + meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0))); + meta.sendPacket(player.getPlayer()); + System.out.println("Spawning "+lgp.getName()+" for prêtre ("+player.getName()+")"); + } + }else + player.getPlayer().hidePlayer(lgp.getPlayer()); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getPlayer().getInventory().setItem(8, null); + player.stopChoosing(); + closeInventory(player.getPlayer()); + player.canSelectDead = false; + player.getPlayer().updateInventory(); + hidePlayers(player); + //player.sendTitle("§cVous n'infectez personne", "§4Vous avez mis trop de temps à vous décider...", 80); + player.sendMessage("§6Tu n'as rien fait cette nuit."); + } + + private void hidePlayers(LGPlayer player) { + if(player.getPlayer() != null) { + for(LGPlayer lgp : getGame().getInGame()) + if(lgp.getPlayer() != null && lgp != player) + player.getPlayer().hidePlayer(lgp.getPlayer()); + } + } + + boolean inMenu = false; + ArrayList ressucited = new ArrayList(); + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + hidePlayers(lgp); + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + player.getInventory().setItem(8, items[3]); + player.updateInventory(); + //Pour éviter les missclick + WrapperPlayServerHeldItemSlot held = new WrapperPlayServerHeldItemSlot(); + held.setSlot(0); + held.sendPacket(player); + lgp.sendMessage("§6Choisissez qui réssuciter."); + 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éssucité"); + + + ressucited.add(choosen); + getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes. + choosen.sendMessage("§6Tu vas être réssucité en tant que §a§lVillageois§6."); + hidePlayers(lgp); + lgp.hideView(); + callback.run(); + } + } + } + }, lgp); + } + } + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player player = e.getPlayer(); + LGPlayer lgp = LGPlayer.thePlayer(player); + if(lgp.getRole() == this) { + if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.stopChoosing(); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + lgp.canSelectDead = false; + hidePlayers(lgp); + callback.run(); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onDayStart(LGPreDayStartEvent e) { + if(e.getGame() == getGame()) + if(ressucited.size() > 0) { + for(LGPlayer lgp : ressucited) { + if(lgp.getPlayer() == null || !lgp.isDead()) + continue; + lgp.setDead(false); + lgp.getCache().reset(); + RVillageois villagers = null; + for(Role role : getGame().getRoles()) + if(role instanceof RVillageois) + villagers = (RVillageois)role; + if(villagers == null) + getGame().getRoles().add(villagers = new RVillageois(getGame())); + villagers.join(lgp, false);//Le joueur réssucité rejoint les villageois. + lgp.setRole(villagers); + lgp.getPlayer().removePotionEffect(PotionEffectType.INVISIBILITY); + lgp.getPlayer().getInventory().setHelmet(null); + lgp.getPlayer().updateInventory(); + LGCustomItems.updateItem(lgp); + + lgp.joinChat(getGame().getDayChat());//Pour qu'il ne parle plus dans le chat des morts (et ne le voit plus) et qu'il parle dans le chat des vivants + VariousUtils.setWarning(lgp.getPlayer(), true); + + getGame().updateRoleScoreboard(); + + getGame().broadcastMessage("§7§l"+lgp.getName()+"§6 a été ressuscité cette nuit."); + + for(LGPlayer player : getGame().getInGame()) + if(player.getPlayer() != null && player != lgp) { + player.getPlayer().showPlayer(lgp.getPlayer()); + } + } + ressucited.clear(); + } + } + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java b/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java new file mode 100644 index 0000000..4c5970d --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RPyromane.java @@ -0,0 +1,312 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +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.scheduler.BukkitRunnable; + +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.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; +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 { + cancel = new ItemStack(Material.IRON_NUGGET); + ItemMeta meta = cancel.getItemMeta(); + meta.setDisplayName("§7§lAnnuler"); + meta.setLore(Arrays.asList("§8Rouvrir le menu")); + cancel.setItemMeta(meta); + nothing = new ItemStack(Material.IRON_NUGGET); + meta = nothing.getItemMeta(); + meta.setDisplayName("§7§lNe rien faire"); + nothing.setItemMeta(meta); + items[3] = new ItemStack(Material.FLINT_AND_STEEL); + meta = items[3].getItemMeta(); + meta.setDisplayName("§e§lMettre le feu"); + meta.setLore(Arrays.asList( + "§8Tuez les joueurs que vous avez", + "§8Précédemment recouvert de gasoil.")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material.LAVA_BUCKET); + meta = items[5].getItemMeta(); + meta.setDisplayName("§c§lRecouvrir d'essence"); + meta.setLore(Arrays.asList( + "§8Recouvres deux joueurs d'essence")); + items[5].setItemMeta(meta); + } + + public RPyromane(LGGame game) { + super(game); + } + + @Override + public String getName() { + return "§6§lPyromane"; + } + + @Override + public String getFriendlyName() { + return "du "+getName(); + } + + @Override + public String getShortDescription() { + return "Tu gagnes §7§lSEUL"; + } + + @Override + public String getDescription() { + return "Tu gagnes §7§lSEUL§f. Chaque nuit, tu peux recouvrir de gasoil deux joueurs au choix, ou immoler tous ceux que tu as précédemment visités. Les joueurs sauront qu'ils ont été recouverts de gasoil."; + } + + @Override + public String getTask() { + return "Que veux-tu faire cette nuit ?"; + } + + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 joue avec une allumette..."; + } + @Override + public RoleType getType() { + return RoleType.NEUTRAL; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.SEUL; + } + + @Override + public int getTimeout() { + return 30; + } + + Runnable callback; + + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Que veux-tu faire ?"); + ItemStack[] content = items.clone(); + LGPlayer lgp = LGPlayer.thePlayer(player); + if(!lgp.getCache().has("pyromane_essence")) + lgp.getCache().set("pyromane_essence", new ArrayList<>()); + if(lgp.getCache().>get("pyromane_essence").size() == 0) + content[3] = nothing; + inventory.setContents(content); + player.closeInventory(); + player.openInventory(inventory); + } + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + first = null; + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + if(first != null) { + List liste = player.getCache().>get("pyromane_essence"); + LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), first); + Bukkit.getPluginManager().callEvent(event); + System.out.println("Gasoil of "+event.getPlayer().getName()+" cancelled : "+event.isCancelled()); + if(event.isCancelled()) + player.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisé."); + else { + event.getPlayer().sendMessage("§6Tu es recouvert de gasoil..."); + liste.add(event.getPlayer()); + } + } + player.getPlayer().getInventory().setItem(8, null); + player.stopChoosing(); + closeInventory(player.getPlayer()); + player.getPlayer().updateInventory(); + player.hideView(); + player.sendMessage("§6Tu n'as rien fait cette nuit."); + } + + boolean inMenu = false; + LGPlayer first; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + if(item.getItemMeta().getDisplayName().equals(nothing.getItemMeta().getDisplayName())) { + lgp.stopChoosing(); + closeInventory(player); + lgp.hideView(); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + if(lgp.getCache().>get("pyromane_essence").size() != 0) { + List liste = lgp.getCache().>get("pyromane_essence"); + System.out.println(liste+" < liste des joueurs à kill par le pyro"); + for(LGPlayer scndPlayer : liste) { + System.out.println(scndPlayer.getName()+" mort: "+scndPlayer.isDead()+" & player: "+scndPlayer.getPlayer()+" / role:"+scndPlayer.getRole()); + if(!scndPlayer.isDead() && scndPlayer.getPlayer() != null) { + getGame().kill(scndPlayer, Reason.PYROMANE); + } + } + liste.clear(); + lgp.sendMessage("§6§lTu as décidé de brûler tes victimes ce soir."); + lgp.sendActionBarMessage("§6Tes victimes brûleront ce soir."); + }else + lgp.sendMessage("§6§lPersonne n'a pris feu."); + lgp.hideView(); + callback.run(); + }else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { + e.setCancelled(true); + closeInventory(player); + player.getInventory().setItem(8, cancel); + player.updateInventory(); + //Pour éviter les missclick + WrapperPlayServerHeldItemSlot held = new WrapperPlayServerHeldItemSlot(); + 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; + } + 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); + System.out.println("Gasoil of "+event.getPlayer().getName()+" cancelled : "+event.isCancelled()); + 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()); + } + if(first != null) { + event = new LGPyromaneGasoilEvent(getGame(), first); + Bukkit.getPluginManager().callEvent(event); + System.out.println("Gasoil of "+event.getPlayer().getName()+" cancelled : "+event.isCancelled()); + 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; + } + } + } + }, lgp); + } + } + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player player = e.getPlayer(); + LGPlayer lgp = LGPlayer.thePlayer(player); + if(lgp.getRole() == this) { + if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(cancel.getItemMeta().getDisplayName())) { + e.setCancelled(true); + player.getInventory().setItem(8, null); + player.updateInventory(); + lgp.stopChoosing(); + openInventory(player); + } + } + } + @EventHandler + public void onKilled(LGPlayerKilledEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getPlayers()) + if(lgp.getCache().has("pyromane_essence")) { + List liste = lgp.getCache().>get("pyromane_essence"); + if(liste.contains(e.getKilled()))//Au cas où le mec soit rez + liste.remove(e.getKilled()); + } + } + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + + //Win condition + + @EventHandler + public void onEndgameCheck(LGEndCheckEvent e) { + if(e.getGame() == getGame() && e.getWinType() == LGWinType.SOLO) { + if(getPlayers().size() > 0) + e.setWinType(LGWinType.PYROMANE); + } + } + @EventHandler(priority = EventPriority.HIGHEST) + public void onEndGame(LGGameEndEvent e) { + if(e.getWinType() == LGWinType.PYROMANE) { + e.getWinners().clear(); + e.getWinners().addAll(getPlayers()); + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java b/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java new file mode 100644 index 0000000..3bd827f --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RSorciere.java @@ -0,0 +1,224 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +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; +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; + +public class RSorciere extends Role{ + private static ItemStack[] items = new ItemStack[4]; + private static ItemStack cancel; + static { + 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.")); + items[0].setItemMeta(meta); + items[1] = new ItemStack(Material.IRON_NUGGET); + meta = items[1].getItemMeta(); + meta.setDisplayName("§7§lNe rien faire"); + items[1].setItemMeta(meta); + 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.")); + items[2].setItemMeta(meta); + cancel = new ItemStack(Material.IRON_NUGGET); + meta = cancel.getItemMeta(); + meta.setDisplayName("§c§lRevenir au choix des potions"); + cancel.setItemMeta(meta); + } + + + public RSorciere(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lSorcière"; + } + @Override + public String getFriendlyName() { + return "de la "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Tu disposes de deux potions : une §e§o§lpotion de vie§f pour sauver la victime des §c§lLoups§f, et une §e§o§lpotion de mort§f pour assassiner quelqu'un."; + } + @Override + public String getTask() { + return "Que veux-tu faire cette nuit ?"; + } + @Override + public String getBroadcastedTask() { + return "La "+getName()+"§9 est en train de concocter un nouvel élixir."; + } + @Override + public int getTimeout() { + return 30; + } + + private LGPlayer sauver; + private Runnable callback; + + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + player.showView(); + this.callback = callback; + sauver = getGame().getDeaths().get(Reason.LOUP_GAROU); + if(sauver == null) + sauver = getGame().getDeaths().get(Reason.DONT_DIE); + + openInventory(player); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.getPlayer().getInventory().setItem(8, null); + player.stopChoosing(); + closeInventory(player.getPlayer()); + player.getPlayer().updateInventory(); + player.hideView(); + //player.sendTitle("§cVous n'avez utilisé aucune potion", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§6Tu n'as rien fait cette nuit."); + } + private void openInventory(LGPlayer player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, InventoryType.BREWING, sauver == null ? "§7Personne n'a été ciblé" : "§7§l"+sauver.getName()+" §7est ciblé"); + inventory.setContents(items.clone());//clone au cas où Bukkit prenne directement la liste pour éviter de la modifier avec setItem (jsp) + if(sauver == null || player.getCache().getBoolean("witch_used_life")) + inventory.setItem(0, null); + + if(sauver != null) { + ItemStack head = new ItemStack(Material.ARROW); + ItemMeta meta = head.getItemMeta(); + meta.setDisplayName("§7§l"+sauver.getName()+"§c est ciblé"); + head.setItemMeta(meta); + inventory.setItem(4, head); + } + if(player.getCache().getBoolean("witch_used_death")) + inventory.setItem(2, null); + player.getPlayer().closeInventory(); + player.getPlayer().openInventory(inventory); + } + boolean inMenu = false; + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player) e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if (lgp.getRole() != this || item == null || item.getItemMeta() == null) + return; + + if (item.getItemMeta().getDisplayName().equals(items[0].getItemMeta().getDisplayName()) && sauver != null) {// Potion de vie + e.setCancelled(true); + closeInventory(player); + saveLife(lgp); + } else if (item.getItemMeta().getDisplayName().equals(items[1].getItemMeta().getDisplayName())) {// Cancel + e.setCancelled(true); + closeInventory(player); + lgp.sendMessage("§6Tu n'as rien fait cette nuit."); + lgp.hideView(); + callback.run(); + } else if (item.getItemMeta().getDisplayName().equals(items[2].getItemMeta().getDisplayName())) {// Potion de mort + e.setCancelled(true); + player.getInventory().setItem(8, cancel); + player.updateInventory(); + + //On le met sur le slot 0 pour éviter un missclick sur la croix + WrapperPlayServerHeldItemSlot hold = new WrapperPlayServerHeldItemSlot(); + hold.setSlot(0); + hold.sendPacket(lgp.getPlayer()); + + closeInventory(player); + lgp.choose((choosen) -> { + if (choosen != null) { + lgp.stopChoosing(); + kill(choosen, lgp); + } + }/*, sauver*/);//On peut tuer la personne qui a été tué par les loups (bien que cela ne serve à rien) + } + } + + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player p = e.getPlayer(); + LGPlayer player = LGPlayer.thePlayer(p); + if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) { + player.stopChoosing(); + p.getInventory().setItem(8, null); + p.updateInventory(); + + openInventory(player); + } + } + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + + private void kill(LGPlayer choosen, LGPlayer player) { + player.getPlayer().getInventory().setItem(8, null); + player.getPlayer().updateInventory(); + player.getCache().set("witch_used_death", true); + getGame().kill(choosen, Reason.SORCIERE); + player.sendMessage("§6Tu as décidé d'assassiner §7§l"+choosen.getName()+"§6."); + player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 a été tué."); + player.hideView(); + callback.run(); + } + private void saveLife(LGPlayer player) { + player.getCache().set("witch_used_life", true); + getGame().getDeaths().remove(Reason.LOUP_GAROU, sauver); + player.sendMessage("§6Tu as décidé de sauver §7§l"+sauver.getName()+"§6."); + player.sendActionBarMessage("§7§l"+sauver.getName()+"§9 a été sauvé."); + player.hideView(); + callback.run(); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java b/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java new file mode 100644 index 0000000..443bdfd --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RSurvivant.java @@ -0,0 +1,194 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +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.LGWinType; +import fr.leomelki.loupgarou.events.LGGameEndEvent; +import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; +import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; +import fr.leomelki.loupgarou.events.LGPreDayStartEvent; +import fr.leomelki.loupgarou.utils.VariableCache; + +public class RSurvivant extends Role{ + public RSurvivant(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.NEUTRAL; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.NONE; + } + @Override + public String getName() { + return "§d§lSurvivant"; + } + @Override + public String getFriendlyName() { + return "du "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes si tu remplis ton objectif"; + } + @Override + public String getDescription() { + return "Tu es §d§lNeutre§f et tu gagnes si tu remplis ton objectif. Ton objectif est de survivre. Tu disposes de §l2§f protections. Chaque nuit, tu peux utiliser une protection pour ne pas être tué par les §c§lLoups§f. Tu peux gagner aussi bien avec les §a§lVillageois§f qu'avec les §c§lLoups§f, tu dois juste rester en vie jusqu'à la fin de la partie."; + } + @Override + public String getTask() { + return "Veux-tu utiliser une protection cette nuit ?"; + } + @Override + public String getBroadcastedTask() { + return "Le "+getName()+"§9 décide s'il veut se protéger."; + } + @Override + public int getTimeout() { + return 15; + } + boolean inMenu; + public void openInventory(Player player) { + inMenu = true; + Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu te protéger ?"); + ItemStack[] items = new ItemStack[9]; + VariableCache cache = LGPlayer.thePlayer(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")); + items[3].setItemMeta(meta); + items[5] = new ItemStack(Material.GOLD_NUGGET); + meta = items[5].getItemMeta(); + meta.setDisplayName("§2§lSe protéger (§6§l"+cache.get("survivant_left")+"§2§l restant)"); + meta.setLore(Arrays.asList( + "§8Tu ne pourras pas être tué par", + "§8 les §c§lLoups§8 cette nuit.")); + items[5].setItemMeta(meta); + } else { + 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")); + items[4].setItemMeta(meta); + } + player.closeInventory(); + inventory.setContents(items); + player.openInventory(inventory); + } + @Override + public void join(LGPlayer player) { + super.join(player); + player.getCache().set("survivant_left", 2); + } + + Runnable callback; + @Override + protected void onNightTurn(LGPlayer player, Runnable callback) { + player.showView(); + this.callback = callback; + openInventory(player.getPlayer()); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.hideView(); + closeInventory(player.getPlayer()); + player.sendMessage("§4§oTu es sans défense..."); + } + + private void closeInventory(Player p) { + inMenu = false; + p.closeInventory(); + } + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + ItemStack item = e.getCurrentItem(); + Player player = (Player)e.getWhoClicked(); + LGPlayer lgp = LGPlayer.thePlayer(player); + + if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; + + if(item.getType() == Material.IRON_NUGGET) { + e.setCancelled(true); + lgp.sendMessage("§4§oTu es sans défense..."); + closeInventory(player); + lgp.hideView(); + callback.run(); + }else if(item.getType() == Material.GOLD_NUGGET) { + e.setCancelled(true); + closeInventory(player); + lgp.sendActionBarMessage("§9§lTu as décidé de te protéger."); + lgp.sendMessage("§6Tu as décidé de te protéger."); + lgp.getCache().set("survivant_left", lgp.getCache().get("survivant_left")-1); + lgp.getCache().set("survivant_protected", true); + lgp.hideView(); + callback.run(); + } + } + + @EventHandler + public void onPlayerKill(LGNightPlayerPreKilledEvent e) { + if(e.getGame() == getGame() && (e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.LOUP_BLANC || e.getReason() == Reason.GM_LOUP_GAROU || e.getReason() == Reason.ASSASSIN) && e.getKilled().getCache().getBoolean("survivant_protected")) { + e.setReason(Reason.DONT_DIE); + } + } + @EventHandler + public void onDayStart(LGPreDayStartEvent e) { + if(e.getGame() == getGame()) + for(LGPlayer lgp : getGame().getInGame()) + lgp.getCache().remove("survivant_protected"); + } + + @EventHandler + public void onQuitInventory(InventoryCloseEvent e) { + if(e.getInventory() instanceof CraftInventoryCustom) { + LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer()); + if(player.getRole() == this && inMenu) { + new BukkitRunnable() { + + @Override + public void run() { + e.getPlayer().openInventory(e.getInventory()); + } + }.runTaskLater(MainLg.getInstance(), 1); + } + } + } + + + + + + @EventHandler + public void onWin(LGGameEndEvent e) { + if(e.getGame() == getGame() && getPlayers().size() > 0 && e.getWinType() != LGWinType.ANGE) { + for(LGPlayer lgp : getPlayers()) + e.getWinners().add(lgp); + new BukkitRunnable() { + + @Override + public void run() { + getGame().broadcastMessage("§6§oLe "+getName()+"§6§o a rempli son objectif."); + } + }.runTaskAsynchronously(MainLg.getInstance()); + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RVillageois.java b/src/main/java/fr/leomelki/loupgarou/roles/RVillageois.java new file mode 100644 index 0000000..6263f4c --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RVillageois.java @@ -0,0 +1,45 @@ +package fr.leomelki.loupgarou.roles; + +import fr.leomelki.loupgarou.classes.LGGame; + +public class RVillageois extends Role{ + public RVillageois(LGGame game) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lVillageois"; + } + @Override + public String getFriendlyName() { + return "des "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Tu ne disposes d'aucun pouvoir particulier, uniquement ta perspicacité et ta force de persuasion."; + } + @Override + public String getTask() { + return ""; + } + @Override + public String getBroadcastedTask() { + return ""; + } + @Override + public int getTimeout() { + return -1; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java b/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java new file mode 100644 index 0000000..02613f7 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RVoyante.java @@ -0,0 +1,73 @@ +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) { + super(game); + } + @Override + public RoleType getType() { + return RoleType.VILLAGER; + } + @Override + public RoleWinType getWinType() { + return RoleWinType.VILLAGE; + } + @Override + public String getName() { + return "§a§lVoyante"; + } + @Override + public String getFriendlyName() { + return "de la "+getName(); + } + @Override + public String getShortDescription() { + return "Tu gagnes avec le §a§lVillage"; + } + @Override + public String getDescription() { + return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner un joueur et découvrir sa véritable identité..."; + } + @Override + public String getTask() { + return "Choisis un joueur dont tu veux connnaître l'identité."; + } + @Override + public String getBroadcastedTask() { + return "La "+getName()+"§9 s'apprête à sonder un joueur..."; + } + @Override + public int getTimeout() { + return 15; + } + + @Override + 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(); + } + } + }); + } + @Override + protected void onNightTurnTimeout(LGPlayer player) { + player.stopChoosing(); + player.hideView(); + //player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); + //player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/Role.java b/src/main/java/fr/leomelki/loupgarou/roles/Role.java new file mode 100644 index 0000000..36bf4e6 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/Role.java @@ -0,0 +1,111 @@ +package fr.leomelki.loupgarou.roles; + +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.Listener; + +import fr.leomelki.loupgarou.MainLg; +import fr.leomelki.loupgarou.classes.LGCustomItems; +import fr.leomelki.loupgarou.classes.LGGame; +import fr.leomelki.loupgarou.classes.LGPlayer; +import lombok.Getter; +import lombok.Setter; + +public abstract class Role implements Listener{ + @Getter @Setter private int waitedPlayers; + @Getter private ArrayList players = new ArrayList(); + @Getter private final LGGame game; + + public Role(LGGame game) { + this.game = game; + Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance()); + FileConfiguration config = MainLg.getInstance().getConfig(); + String roleConfigName = "role."+getClass().getSimpleName().substring(1); + if(config.contains(roleConfigName)) + waitedPlayers = config.getInt(roleConfigName); + } + + + public abstract String getName(); + public abstract String getFriendlyName(); + public abstract String getShortDescription(); + public abstract String getDescription(); + public abstract String getTask(); + public abstract String getBroadcastedTask(); + public RoleType getType(LGPlayer lgp) { + return getType(); + } + public RoleWinType getWinType(LGPlayer lgp) { + return getWinType(); + } + public RoleType getType() {return null;} + public RoleWinType getWinType() {return null;} + /** + * @return Timeout in second for this role + */ + public abstract int getTimeout(); + + public void onNightTurn(Runnable callback) { + ArrayList players = (ArrayList) getPlayers().clone(); + new Runnable() { + + @Override + public void run() { + getGame().cancelWait(); + if(players.size() == 0) { + onTurnFinish(callback); + return; + } + LGPlayer player = players.remove(0); + getGame().wait(getTimeout(), ()->{ + try { + Role.this.onNightTurnTimeout(player); + }catch(Exception err) { + System.out.println("Error when timeout role"); + err.printStackTrace(); + } + this.run(); + }, (currentPlayer, secondsLeft)->{ + return 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); + } + }.run(); + } + public void join(LGPlayer player, boolean sendMessage) { + System.out.println(player.getName()+" est "+getName()); + players.add(player); + if(player.getRole() == null) + player.setRole(this); + waitedPlayers--; + if(sendMessage) { + player.sendTitle("§6Tu es "+getName(), "§e"+getShortDescription(), 200); + player.sendMessage("§6Tu es "+getName()+"§6."); + player.sendMessage("§6Description : §f"+getDescription()); + } + } + public void join(LGPlayer player) { + join(player, !getGame().isStarted()); + LGCustomItems.updateItem(player); + } + public boolean hasPlayersLeft() { + return getPlayers().size() > 0; + } + protected void onNightTurnTimeout(LGPlayer player) {} + protected void onNightTurn(LGPlayer player, Runnable callback) {} + protected void onTurnFinish(Runnable callback) { + callback.run(); + } + public int getTurnOrder() { + try { + RoleSort role = RoleSort.valueOf(getClass().getSimpleName().substring(1)); + return role == null ? -1 : role.ordinal(); + }catch(Throwable e) { + return -1; + } + }//En combientième ce rôle doit être appellé +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RoleSort.java b/src/main/java/fr/leomelki/loupgarou/roles/RoleSort.java new file mode 100644 index 0000000..4b90a95 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RoleSort.java @@ -0,0 +1,23 @@ +package fr.leomelki.loupgarou.roles; + +public enum RoleSort { + ChienLoup, + EnfantSauvage, + Cupidon, + Garde, + Survivant, + Voyante, + Detective, + Dictateur, + Pretre, + LoupGarou, + LoupGarouNoir, + GrandMechantLoup, + LoupGarouBlanc, + Assassin, + Pyromane, + Pirate, + Bouffon, + Sorciere, + Corbeau; +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RoleType.java b/src/main/java/fr/leomelki/loupgarou/roles/RoleType.java new file mode 100644 index 0000000..cabc4d6 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RoleType.java @@ -0,0 +1,7 @@ +package fr.leomelki.loupgarou.roles; + +public enum RoleType { + VILLAGER, + LOUP_GAROU, + NEUTRAL; +} diff --git a/src/main/java/fr/leomelki/loupgarou/roles/RoleWinType.java b/src/main/java/fr/leomelki/loupgarou/roles/RoleWinType.java new file mode 100644 index 0000000..d4580d3 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/roles/RoleWinType.java @@ -0,0 +1,8 @@ +package fr.leomelki.loupgarou.roles; + +public enum RoleWinType { + SEUL, + VILLAGE, + LOUP_GAROU, + NONE; +} diff --git a/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboard.java b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboard.java new file mode 100644 index 0000000..b4bc739 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboard.java @@ -0,0 +1,59 @@ +package fr.leomelki.loupgarou.scoreboard; + +import java.util.Arrays; +import java.util.List; + +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardDisplayObjective; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardObjective; +import fr.leomelki.loupgarou.classes.LGPlayer; +import fr.leomelki.loupgarou.utils.RandomString; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class CustomScoreboard { + @Getter private final String name = RandomString.generate(16); + @Getter private final String displayName; + private final List entries = Arrays.asList(new CustomScoreboardEntry(15, this), new CustomScoreboardEntry(14, this), new CustomScoreboardEntry(13, this), + new CustomScoreboardEntry(12, this), new CustomScoreboardEntry(11, this), new CustomScoreboardEntry(10, this), + new CustomScoreboardEntry(9, this), new CustomScoreboardEntry(8, this), new CustomScoreboardEntry(7, this), + new CustomScoreboardEntry(6, this), new CustomScoreboardEntry(5, this), new CustomScoreboardEntry(4, this), + new CustomScoreboardEntry(3, this), new CustomScoreboardEntry(2, this), new CustomScoreboardEntry(1, this), + new CustomScoreboardEntry(0, this)); + @Getter private final LGPlayer player; + @Getter private boolean shown; + + public CustomScoreboardEntry getLine(int index) { + return entries.get(index); + } + + public void show() { + WrapperPlayServerScoreboardObjective objective = new WrapperPlayServerScoreboardObjective(); + objective.setMode(0); + objective.setName(name); + objective.setDisplayName(WrappedChatComponent.fromText(displayName)); + objective.sendPacket(player.getPlayer()); + WrapperPlayServerScoreboardDisplayObjective display = new WrapperPlayServerScoreboardDisplayObjective(); + display.setPosition(1); + display.setScoreName(name); + display.sendPacket(player.getPlayer()); + shown = true; + + for(CustomScoreboardEntry entry : entries) + entry.show(); + } + + public void hide() { + WrapperPlayServerScoreboardObjective remove = new WrapperPlayServerScoreboardObjective(); + remove.setMode(1); + remove.setName(name); + remove.sendPacket(player.getPlayer()); + + for(CustomScoreboardEntry entry : entries) + entry.hide(); + + shown = false; + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java new file mode 100644 index 0000000..d403a85 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/scoreboard/CustomScoreboardEntry.java @@ -0,0 +1,109 @@ +package fr.leomelki.loupgarou.scoreboard; + +import java.util.Arrays; + +import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardScore; +import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; +import fr.leomelki.loupgarou.utils.VariousUtils; +import lombok.Getter; +import lombok.Setter; + +public class CustomScoreboardEntry { + private static WrappedChatComponent nullComponent = WrappedChatComponent.fromText(""); + + //setter car flemme de modifier le systeme pour le rendre plus logique + @Getter @Setter private int score; + private final String name; + private final CustomScoreboard scoreboard; + private WrappedChatComponent prefix, suffix; + + public CustomScoreboardEntry(int score, CustomScoreboard scoreboard) { + this.score = score; + this.scoreboard = scoreboard; + this.name = "§"+VariousUtils.toHex(score); + } + + public void show() { + if(prefix != null) { + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setPlayers(Arrays.asList(name)); + team.setName(name); + team.setMode(0); + team.setPrefix(prefix); + if(suffix != null) + team.setSuffix(suffix); + team.sendPacket(scoreboard.getPlayer().getPlayer()); + + WrapperPlayServerScoreboardScore score = new WrapperPlayServerScoreboardScore(); + score.setObjectiveName(scoreboard.getName()); + score.setScoreboardAction(ScoreboardAction.CHANGE); + score.setScoreName(name); + score.setValue(this.score); + score.sendPacket(scoreboard.getPlayer().getPlayer()); + } + } + + public void setDisplayName(String displayName) { + boolean spawn = prefix == null; + if(displayName.length() > 16) { + char colorCode = 'f'; + int limit = displayName.charAt(14) == '§' && displayName.charAt(13) != '§' ? 14 : displayName.charAt(15) == '§' ? 15 : 16; + String prefixStr = displayName.substring(0, limit); + + prefix = WrappedChatComponent.fromText(prefixStr); + + if(limit == 16) { + boolean storeColorCode = false; + for(char c : prefixStr.toCharArray()) + if(storeColorCode) { + storeColorCode = false; + colorCode = c; + }else + if(c == '§') + storeColorCode = true; + suffix = WrappedChatComponent.fromText("§"+colorCode+displayName.substring(limit)); + }else + suffix = WrappedChatComponent.fromText(displayName.substring(limit)); + } else { + prefix = WrappedChatComponent.fromText(displayName); + suffix = nullComponent; + } + + if(scoreboard.isShown()) { + if(spawn) + show(); + else { + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setPlayers(Arrays.asList(name)); + team.setName(name); + team.setMode(2); + team.setPrefix(prefix); + if(suffix != null) + team.setSuffix(suffix); + team.sendPacket(scoreboard.getPlayer().getPlayer()); + } + } + } + public void delete() { + hide(); + prefix = null; + } + public void hide() { + if(prefix != null && scoreboard.isShown()) { + WrapperPlayServerScoreboardScore score = new WrapperPlayServerScoreboardScore(); + score.setObjectiveName(scoreboard.getName()); + score.setScoreboardAction(ScoreboardAction.REMOVE); + score.setScoreName(name); + score.sendPacket(scoreboard.getPlayer().getPlayer()); + + WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); + team.setName(name); + team.setMode(1); + team.sendPacket(scoreboard.getPlayer().getPlayer()); + } + } + +} diff --git a/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java b/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java new file mode 100644 index 0000000..fc221a5 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/utils/MultipleValueMap.java @@ -0,0 +1,67 @@ +package fr.leomelki.loupgarou.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +public class MultipleValueMap { + private 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.add(value); + } + public V remove(K key, V value) { + List list = map.get(key); + if(list != null) { + boolean removed = list.remove(value); + if(list.size() == 0) + map.remove(key); + if(removed) + return value; + } + return null; + } + public boolean containsKey(K key) { + return map.containsKey(key); + } + public boolean containsValue(V value) { + if(value != null) + for(List list : map.values()) + for(V v : list) + if(v != null && v.equals(value)) + return true; + return false; + } + public V get(K key) { + return map.containsKey(key) ? map.get(key).get(0) : null; + } + public List> entrySet(){ + ArrayList> toReturn = new ArrayList>(); + for(Entry> entry : map.entrySet()) + for(V v : entry.getValue()) + toReturn.add(new MultipleValueKeyEntry(entry.getKey(), v)); + + return toReturn; + } + public void clear() { + map.clear(); + } + @AllArgsConstructor + public static class MultipleValueKeyEntry implements Entry{ + @Getter + private K key; + @Getter + private V value; + @Override + public V setValue(V value) { + return this.value = value; + } + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/utils/RandomString.java b/src/main/java/fr/leomelki/loupgarou/utils/RandomString.java new file mode 100644 index 0000000..1927c04 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/utils/RandomString.java @@ -0,0 +1,21 @@ +package fr.leomelki.loupgarou.utils; + +import java.security.SecureRandom; + +public class RandomString { + private static final String ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; + private static final SecureRandom RANDOM = new SecureRandom(); + + /** + * Generates random string of given length from Base65 alphabet (numbers, lowercase letters, uppercase letters). + * + * @param count length + * @return random string of given length + */ + public static String generate(int count) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < count; ++i) + sb.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length()))); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java b/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java new file mode 100644 index 0000000..040690c --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/utils/VariableCache.java @@ -0,0 +1,29 @@ +package fr.leomelki.loupgarou.utils; + +import java.util.HashMap; + +public class VariableCache { + private HashMap cache = new HashMap(); + public boolean getBoolean(String key) { + Object object = get(key); + return object == null ? false : (boolean)object; + } + public void set(String key, Object value) { + if(cache.containsKey(key)) + cache.replace(key, value); + else + cache.put(key, value); + } + public boolean has(String key) { + return cache.containsKey(key); + } + public T get(String key) { + return (T)cache.get(key); + } + public T remove(String key) { + return (T)cache.remove(key); + } + public void reset() { + cache.clear(); + } +} diff --git a/src/main/java/fr/leomelki/loupgarou/utils/VariousUtils.java b/src/main/java/fr/leomelki/loupgarou/utils/VariousUtils.java new file mode 100644 index 0000000..5138c23 --- /dev/null +++ b/src/main/java/fr/leomelki/loupgarou/utils/VariousUtils.java @@ -0,0 +1,48 @@ +package fr.leomelki.loupgarou.utils; + +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.Location; +import org.bukkit.WorldBorder; +import org.bukkit.entity.Player; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers; + +public class VariousUtils { + public static double distanceSquaredXZ(Location from, Location to) { + return Math.pow(from.getX()-to.getX(), 2)+Math.pow(from.getZ()-to.getZ(), 2); + } + public static void setWarning(Player p, boolean warning) { + PacketContainer container = new PacketContainer(PacketType.Play.Server.WORLD_BORDER); + WorldBorder wb = p.getWorld().getWorldBorder(); + + container.getWorldBorderActions().write(0, EnumWrappers.WorldBorderAction.INITIALIZE); + + container.getIntegers().write(0, 29999984); + + container.getDoubles().write(0, p.getLocation().getX()); + container.getDoubles().write(1, p.getLocation().getZ()); + + container.getDoubles().write(3, wb.getSize()); + container.getDoubles().write(2, wb.getSize()); + + container.getIntegers().write(2, (int) (warning ? wb.getSize() : wb.getWarningDistance())); + container.getIntegers().write(1, 0); + + container.getLongs().write(0, (long) 0); + + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(p, container); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + private static char[] hex = "0123456789abcdef".toCharArray(); + public static char toHex(int i) { + return hex[i]; + } + +} diff --git a/src/main/java/plugin.yml b/src/main/java/plugin.yml new file mode 100644 index 0000000..f0669f2 --- /dev/null +++ b/src/main/java/plugin.yml @@ -0,0 +1,8 @@ +name: LoupGarou +version: 0.0.2 +description: Permet de jouer au jeu du loup garou +main: fr.leomelki.loupgarou.MainLg +depend: [ProtocolLib] +api-version: 1.13 +commands: + lg: \ No newline at end of file