Reformat code

This commit is contained in:
Ethanell 2020-09-07 23:40:57 +02:00
parent 53f1508a01
commit 20b545b93d
108 changed files with 10123 additions and 9809 deletions

View file

@ -1,13 +1,13 @@
version: "3.0" version: "3.0"
services: services:
loup-garou: loup-garou:
build: build:
context: . context: .
dockerfile: ./docker/Dockerfile dockerfile: ./docker/Dockerfile
args: args:
SPIGOT_VERSION: 1.15.1 SPIGOT_VERSION: 1.15.1
volumes: volumes:
- ./minecraft_data:/minecraft - ./minecraft_data:/minecraft
ports: ports:
- 25565:25565 - 25565:25565

View file

@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>fr.leomelki</groupId> <groupId>fr.leomelki</groupId>

View file

@ -2,115 +2,114 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
public abstract class AbstractPacket { public abstract class AbstractPacket {
// The packet we will be modifying // The packet we will be modifying
protected PacketContainer handle; protected PacketContainer handle;
/** /**
* Constructs a new strongly typed wrapper for the given packet. * Constructs a new strongly typed wrapper for the given packet.
* *
* @param handle - handle to the raw packet data. * @param handle - handle to the raw packet data.
* @param type - the packet type. * @param type - the packet type.
*/ */
protected AbstractPacket(PacketContainer handle, PacketType type) { protected AbstractPacket(PacketContainer handle, PacketType type) {
// Make sure we're given a valid packet // Make sure we're given a valid packet
if (handle == null) if (handle == null)
throw new IllegalArgumentException("Packet handle cannot be NULL."); throw new IllegalArgumentException("Packet handle cannot be NULL.");
if (!Objects.equal(handle.getType(), type)) if (!Objects.equal(handle.getType(), type))
throw new IllegalArgumentException(handle.getHandle() throw new IllegalArgumentException(handle.getHandle()
+ " is not a packet of type " + type); + " is not a packet of type " + type);
this.handle = handle; this.handle = handle;
} }
/** /**
* Retrieve a handle to the raw packet data. * Retrieve a handle to the raw packet data.
* *
* @return Raw packet data. * @return Raw packet data.
*/ */
public PacketContainer getHandle() { public PacketContainer getHandle() {
return handle; return handle;
} }
/** /**
* Send the current packet to the given receiver. * Send the current packet to the given receiver.
* *
* @param receiver - the receiver. * @param receiver - the receiver.
* @throws RuntimeException If the packet cannot be sent. * @throws RuntimeException If the packet cannot be sent.
*/ */
public void sendPacket(Player receiver) { public void sendPacket(Player receiver) {
if(receiver == null) if (receiver == null)
return; return;
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
getHandle()); getHandle());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet.", e); throw new RuntimeException("Cannot send packet.", e);
} }
} }
/** /**
* Send the current packet to all online players. * Send the current packet to all online players.
*/ */
public void broadcastPacket() { public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
} }
/** /**
* Simulate receiving the current packet from the given sender. * Simulate receiving the current packet from the given sender.
* *
* @param sender - the sender. * @param sender - the sender.
* @throws RuntimeException If the packet cannot be received. * @throws RuntimeException If the packet cannot be received.
* @deprecated Misspelled. recieve to receive * @deprecated Misspelled. recieve to receive
* @see #receivePacket(Player) * @see #receivePacket(Player)
*/ */
@Deprecated @Deprecated
public void recievePacket(Player sender) { public void recievePacket(Player sender) {
try { try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle()); getHandle());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Cannot recieve packet.", e); throw new RuntimeException("Cannot recieve packet.", e);
} }
} }
/** /**
* Simulate receiving the current packet from the given sender. * Simulate receiving the current packet from the given sender.
* *
* @param sender - the sender. * @param sender - the sender.
* @throws RuntimeException if the packet cannot be received. * @throws RuntimeException if the packet cannot be received.
*/ */
public void receivePacket(Player sender) { public void receivePacket(Player sender) {
try { try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle()); getHandle());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Cannot receive packet.", e); throw new RuntimeException("Cannot receive packet.", e);
} }
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -21,8 +21,8 @@ package fr.leomelki.com.comphenix.packetwrapper;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class PacketWrapper extends JavaPlugin { public class PacketWrapper extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
// We don't really do much ... // We don't really do much ...
} }
} }

View file

@ -2,103 +2,102 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import java.util.Arrays;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.EnumWrappers.ChatType; import com.comphenix.protocol.wrappers.EnumWrappers.ChatType;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import java.util.Arrays;
public class WrapperPlayServerChat extends AbstractPacket { public class WrapperPlayServerChat extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.CHAT; public static final PacketType TYPE = PacketType.Play.Server.CHAT;
public WrapperPlayServerChat() { public WrapperPlayServerChat() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerChat(PacketContainer packet) { public WrapperPlayServerChat(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve the chat message. * Retrieve the chat message.
* <p> * <p>
* Limited to 32767 bytes * Limited to 32767 bytes
* *
* @return The current message * @return The current message
*/ */
public WrappedChatComponent getMessage() { public WrappedChatComponent getMessage() {
return handle.getChatComponents().read(0); return handle.getChatComponents().read(0);
} }
/** /**
* Set the message. * Set the message.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setMessage(WrappedChatComponent value) { public void setMessage(WrappedChatComponent value) {
handle.getChatComponents().write(0, value); handle.getChatComponents().write(0, value);
} }
public ChatType getChatType() { public ChatType getChatType() {
return handle.getChatTypes().read(0); return handle.getChatTypes().read(0);
} }
public void setChatType(ChatType type) { public void setChatType(ChatType type) {
handle.getChatTypes().write(0, type); handle.getChatTypes().write(0, type);
} }
/** /**
* Retrieve Position. * Retrieve Position.
* <p> * <p>
* Notes: 0 - Chat (chat box) ,1 - System Message (chat box), 2 - Above * Notes: 0 - Chat (chat box) ,1 - System Message (chat box), 2 - Above
* action bar * action bar
* *
* @return The current Position * @return The current Position
* @deprecated Magic values replaced by enum * @deprecated Magic values replaced by enum
*/ */
@Deprecated @Deprecated
public byte getPosition() { public byte getPosition() {
Byte position = handle.getBytes().readSafely(0); Byte position = handle.getBytes().readSafely(0);
if (position != null) { if (position != null) {
return position; return position;
} else { } else {
return getChatType().getId(); return getChatType().getId();
} }
} }
/** /**
* Set Position. * Set Position.
* *
* @param value - new value. * @param value - new value.
* @deprecated Magic values replaced by enum * @deprecated Magic values replaced by enum
*/ */
@Deprecated @Deprecated
public void setPosition(byte value) { public void setPosition(byte value) {
handle.getBytes().writeSafely(0, value); handle.getBytes().writeSafely(0, value);
if (EnumWrappers.getChatTypeClass() != null) if (EnumWrappers.getChatTypeClass() != null) {
{ Arrays.stream(ChatType.values()).filter(t -> t.getId() == value).findAny()
Arrays.stream(ChatType.values()).filter(t -> t.getId() == value).findAny() .ifPresent(t -> handle.getChatTypes().writeSafely(0, t));
.ifPresent(t -> handle.getChatTypes().writeSafely(0, t)); }
} }
}
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -25,159 +25,159 @@ import com.comphenix.protocol.wrappers.MinecraftKey;
public class WrapperPlayServerCustomSoundEffect extends AbstractPacket { public class WrapperPlayServerCustomSoundEffect extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.CUSTOM_SOUND_EFFECT; PacketType.Play.Server.CUSTOM_SOUND_EFFECT;
public WrapperPlayServerCustomSoundEffect() { public WrapperPlayServerCustomSoundEffect() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerCustomSoundEffect(PacketContainer packet) { public WrapperPlayServerCustomSoundEffect(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Sound Name. * Retrieve Sound Name.
* <p> * <p>
* Notes: all known sound effect names can be seen here. * Notes: all known sound effect names can be seen here.
* *
* @return The current Sound Name * @return The current Sound Name
*/ */
public MinecraftKey getSoundName() { public MinecraftKey getSoundName() {
return handle.getMinecraftKeys().read(0); return handle.getMinecraftKeys().read(0);
} }
/** /**
* Set Sound Name. * Set Sound Name.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setSoundName(MinecraftKey value) { public void setSoundName(MinecraftKey value) {
handle.getMinecraftKeys().write(0, value); handle.getMinecraftKeys().write(0, value);
} }
/** /**
* Retrieve Sound Category. * Retrieve Sound Category.
* <p> * <p>
* Notes: the category that this sound will be played from (current * Notes: the category that this sound will be played from (current
* categories) * categories)
* *
* @return The current Sound Category * @return The current Sound Category
*/ */
public SoundCategory getSoundCategory() { public SoundCategory getSoundCategory() {
return handle.getSoundCategories().read(0); return handle.getSoundCategories().read(0);
} }
/** /**
* Set Sound Category. * Set Sound Category.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setSoundCategory(SoundCategory value) { public void setSoundCategory(SoundCategory value) {
handle.getSoundCategories().write(0, value); handle.getSoundCategories().write(0, value);
} }
/** /**
* Retrieve Effect Position X. * Retrieve Effect Position X.
* <p> * <p>
* Notes: effect X multiplied by 8 (fixed-point number with only 3 bits * Notes: effect X multiplied by 8 (fixed-point number with only 3 bits
* dedicated to the fractional part) * dedicated to the fractional part)
* *
* @return The current Effect Position X * @return The current Effect Position X
*/ */
public int getX() { public int getX() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Effect Position X. * Set Effect Position X.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setX(int value) { public void setX(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Effect Position Y. * Retrieve Effect Position Y.
* <p> * <p>
* Notes: effect Y multiplied by 8 (fixed-point number with only 3 bits * Notes: effect Y multiplied by 8 (fixed-point number with only 3 bits
* dedicated to the fractional part) * dedicated to the fractional part)
* *
* @return The current Effect Position Y * @return The current Effect Position Y
*/ */
public int getY() { public int getY() {
return handle.getIntegers().read(1); return handle.getIntegers().read(1);
} }
/** /**
* Set Effect Position Y. * Set Effect Position Y.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setY(int value) { public void setY(int value) {
handle.getIntegers().write(1, value); handle.getIntegers().write(1, value);
} }
/** /**
* Retrieve Effect Position Z. * Retrieve Effect Position Z.
* <p> * <p>
* Notes: effect Z multiplied by 8 (fixed-point number with only 3 bits * Notes: effect Z multiplied by 8 (fixed-point number with only 3 bits
* dedicated to the fractional part) * dedicated to the fractional part)
* *
* @return The current Effect Position Z * @return The current Effect Position Z
*/ */
public int getZ() { public int getZ() {
return handle.getIntegers().read(2); return handle.getIntegers().read(2);
} }
/** /**
* Set Effect Position Z. * Set Effect Position Z.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setZ(int value) { public void setZ(int value) {
handle.getIntegers().write(2, value); handle.getIntegers().write(2, value);
} }
/** /**
* Retrieve Volume. * Retrieve Volume.
* <p> * <p>
* Notes: 1 is 100%, can be more * Notes: 1 is 100%, can be more
* *
* @return The current Volume * @return The current Volume
*/ */
public float getVolume() { public float getVolume() {
return handle.getFloat().read(0); return handle.getFloat().read(0);
} }
/** /**
* Set Volume. * Set Volume.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setVolume(float value) { public void setVolume(float value) {
handle.getFloat().write(0, value); handle.getFloat().write(0, value);
} }
/** /**
* Retrieve Pitch. * Retrieve Pitch.
* <p> * <p>
* Notes: 63 is 100%, can be more * Notes: 63 is 100%, can be more
* *
* @return The current Pitch * @return The current Pitch
*/ */
public float getPitch() { public float getPitch() {
return handle.getFloat().read(1); return handle.getFloat().read(1);
} }
/** /**
* Set Pitch. * Set Pitch.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getFloat().write(1, value); handle.getFloat().write(1, value);
} }
} }

View file

@ -2,78 +2,77 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
public class WrapperPlayServerEntity extends AbstractPacket { public class WrapperPlayServerEntity extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.ENTITY; public static final PacketType TYPE = PacketType.Play.Server.ENTITY;
public WrapperPlayServerEntity() { public WrapperPlayServerEntity() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerEntity(PacketContainer packet) { public WrapperPlayServerEntity(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Entity ID. * Retrieve Entity ID.
* <p> * <p>
* Notes: entity's ID * Notes: entity's ID
* *
* @return The current Entity ID * @return The current Entity ID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Entity ID. * Set Entity ID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityID(int value) { public void setEntityID(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param world - the current world of the entity. * @param world - the current world of the entity.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(World world) { public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0); return handle.getEntityModifier(world).read(0);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param event - the packet event. * @param event - the packet event.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld()); return getEntity(event.getPlayer().getWorld());
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,46 +22,46 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerEntityDestroy extends AbstractPacket { public class WrapperPlayServerEntityDestroy extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY; public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY;
public WrapperPlayServerEntityDestroy() { public WrapperPlayServerEntityDestroy() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerEntityDestroy(PacketContainer packet) { public WrapperPlayServerEntityDestroy(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Count. * Retrieve Count.
* <p> * <p>
* Notes: length of following array * Notes: length of following array
* *
* @return The current Count * @return The current Count
*/ */
public int getCount() { public int getCount() {
return handle.getIntegerArrays().read(0).length; return handle.getIntegerArrays().read(0).length;
} }
/** /**
* Retrieve Entity IDs. * Retrieve Entity IDs.
* <p> * <p>
* Notes: the list of entities of destroy * Notes: the list of entities of destroy
* *
* @return The current Entity IDs * @return The current Entity IDs
*/ */
public int[] getEntityIDs() { public int[] getEntityIDs() {
return handle.getIntegerArrays().read(0); return handle.getIntegerArrays().read(0);
} }
/** /**
* Set Entity IDs. * Set Entity IDs.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityIds(int[] value) { public void setEntityIds(int[] value) {
handle.getIntegerArrays().write(0, value); handle.getIntegerArrays().write(0, value);
} }
} }

View file

@ -2,109 +2,108 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
public class WrapperPlayServerEntityEquipment extends AbstractPacket { public class WrapperPlayServerEntityEquipment extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.ENTITY_EQUIPMENT; PacketType.Play.Server.ENTITY_EQUIPMENT;
public WrapperPlayServerEntityEquipment() { public WrapperPlayServerEntityEquipment() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerEntityEquipment(PacketContainer packet) { public WrapperPlayServerEntityEquipment(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Entity ID. * Retrieve Entity ID.
* <p> * <p>
* Notes: entity's ID * Notes: entity's ID
* *
* @return The current Entity ID * @return The current Entity ID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Entity ID. * Set Entity ID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityID(int value) { public void setEntityID(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param world - the current world of the entity. * @param world - the current world of the entity.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(World world) { public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0); return handle.getEntityModifier(world).read(0);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param event - the packet event. * @param event - the packet event.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld()); return getEntity(event.getPlayer().getWorld());
} }
public ItemSlot getSlot() { public ItemSlot getSlot() {
return handle.getItemSlots().read(0); return handle.getItemSlots().read(0);
} }
public void setSlot(ItemSlot value) { public void setSlot(ItemSlot value) {
handle.getItemSlots().write(0, value); handle.getItemSlots().write(0, value);
} }
/** /**
* Retrieve Item. * Retrieve Item.
* <p> * <p>
* Notes: item in slot format * Notes: item in slot format
* *
* @return The current Item * @return The current Item
*/ */
public ItemStack getItem() { public ItemStack getItem() {
return handle.getItemModifier().read(0); return handle.getItemModifier().read(0);
} }
/** /**
* Set Item. * Set Item.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setItem(ItemStack value) { public void setItem(ItemStack value) {
handle.getItemModifier().write(0, value); handle.getItemModifier().write(0, value);
} }
} }

View file

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

View file

@ -2,100 +2,99 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import java.util.List;
public class WrapperPlayServerEntityMetadata extends AbstractPacket { public class WrapperPlayServerEntityMetadata extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.ENTITY_METADATA; PacketType.Play.Server.ENTITY_METADATA;
public WrapperPlayServerEntityMetadata() { public WrapperPlayServerEntityMetadata() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerEntityMetadata(PacketContainer packet) { public WrapperPlayServerEntityMetadata(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Entity ID. * Retrieve Entity ID.
* <p> * <p>
* Notes: entity's ID * Notes: entity's ID
* *
* @return The current Entity ID * @return The current Entity ID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Entity ID. * Set Entity ID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityID(int value) { public void setEntityID(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param world - the current world of the entity. * @param world - the current world of the entity.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(World world) { public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0); return handle.getEntityModifier(world).read(0);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param event - the packet event. * @param event - the packet event.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld()); return getEntity(event.getPlayer().getWorld());
} }
/** /**
* Retrieve Metadata. * Retrieve Metadata.
* *
* @return The current Metadata * @return The current Metadata
*/ */
public List<WrappedWatchableObject> getMetadata() { public List<WrappedWatchableObject> getMetadata() {
return handle.getWatchableCollectionModifier().read(0); return handle.getWatchableCollectionModifier().read(0);
} }
/** /**
* Set Metadata. * Set Metadata.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setMetadata(List<WrappedWatchableObject> value) { public void setMetadata(List<WrappedWatchableObject> value) {
handle.getWatchableCollectionModifier().write(0, value); handle.getWatchableCollectionModifier().write(0, value);
} }
} }

View file

@ -2,145 +2,144 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
public class WrapperPlayServerEntityTeleport extends AbstractPacket { public class WrapperPlayServerEntityTeleport extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.ENTITY_TELEPORT; PacketType.Play.Server.ENTITY_TELEPORT;
public WrapperPlayServerEntityTeleport() { public WrapperPlayServerEntityTeleport() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerEntityTeleport(PacketContainer packet) { public WrapperPlayServerEntityTeleport(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve entity ID. * Retrieve entity ID.
* *
* @return The current EID * @return The current EID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set entity ID. * Set entity ID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityID(int value) { public void setEntityID(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve the entity. * Retrieve the entity.
* *
* @param world - the current world of the entity. * @param world - the current world of the entity.
* @return The entity. * @return The entity.
*/ */
public Entity getEntity(World world) { public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0); return handle.getEntityModifier(world).read(0);
} }
/** /**
* Retrieve the entity. * Retrieve the entity.
* *
* @param event - the packet event. * @param event - the packet event.
* @return The entity. * @return The entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld()); return getEntity(event.getPlayer().getWorld());
} }
public double getX() { public double getX() {
return handle.getDoubles().read(0); return handle.getDoubles().read(0);
} }
public void setX(double value) { public void setX(double value) {
handle.getDoubles().write(0, value); handle.getDoubles().write(0, value);
} }
public double getY() { public double getY() {
return handle.getDoubles().read(1); return handle.getDoubles().read(1);
} }
public void setY(double value) { public void setY(double value) {
handle.getDoubles().write(1, value); handle.getDoubles().write(1, value);
} }
public double getZ() { public double getZ() {
return handle.getDoubles().read(2); return handle.getDoubles().read(2);
} }
public void setZ(double value) { public void setZ(double value) {
handle.getDoubles().write(2, value); handle.getDoubles().write(2, value);
} }
/** /**
* Retrieve the yaw of the current entity. * Retrieve the yaw of the current entity.
* *
* @return The current Yaw * @return The current Yaw
*/ */
public float getYaw() { public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F; return (handle.getBytes().read(0) * 360.F) / 256.0F;
} }
/** /**
* Set the yaw of the current entity. * Set the yaw of the current entity.
* *
* @param value - new yaw. * @param value - new yaw.
*/ */
public void setYaw(float value) { public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve the pitch of the current entity. * Retrieve the pitch of the current entity.
* *
* @return The current pitch * @return The current pitch
*/ */
public float getPitch() { public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F; return (handle.getBytes().read(1) * 360.F) / 256.0F;
} }
/** /**
* Set the pitch of the current entity. * Set the pitch of the current entity.
* *
* @param value - new pitch. * @param value - new pitch.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
} }
public boolean getOnGround() { public boolean getOnGround() {
return handle.getBooleans().read(0); return handle.getBooleans().read(0);
} }
public void setOnGround(boolean value) { public void setOnGround(boolean value) {
handle.getBooleans().write(0, value); handle.getBooleans().write(0, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,71 +22,71 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerExperience extends AbstractPacket { public class WrapperPlayServerExperience extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.EXPERIENCE; public static final PacketType TYPE = PacketType.Play.Server.EXPERIENCE;
public WrapperPlayServerExperience() { public WrapperPlayServerExperience() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerExperience(PacketContainer packet) { public WrapperPlayServerExperience(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Experience bar. * Retrieve Experience bar.
* <p> * <p>
* Notes: between 0 and 1 * Notes: between 0 and 1
* *
* @return The current Experience bar * @return The current Experience bar
*/ */
public float getExperienceBar() { public float getExperienceBar() {
return handle.getFloat().read(0); return handle.getFloat().read(0);
} }
/** /**
* Set Experience bar. * Set Experience bar.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setExperienceBar(float value) { public void setExperienceBar(float value) {
handle.getFloat().write(0, value); handle.getFloat().write(0, value);
} }
/** /**
* Retrieve Level. * Retrieve Level.
* *
* @return The current Level * @return The current Level
*/ */
public int getLevel() { public int getLevel() {
return handle.getIntegers().read(1); return handle.getIntegers().read(1);
} }
/** /**
* Set Level. * Set Level.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setLevel(int value) { public void setLevel(int value) {
handle.getIntegers().write(1, value); handle.getIntegers().write(1, value);
} }
/** /**
* Retrieve Total Experience. * Retrieve Total Experience.
* *
* @return The current Total Experience * @return The current Total Experience
*/ */
public int getTotalExperience() { public int getTotalExperience() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Total Experience. * Set Total Experience.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setTotalExperience(int value) { public void setTotalExperience(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,35 +22,35 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerHeldItemSlot extends AbstractPacket { public class WrapperPlayServerHeldItemSlot extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.HELD_ITEM_SLOT; public static final PacketType TYPE = PacketType.Play.Server.HELD_ITEM_SLOT;
public WrapperPlayServerHeldItemSlot() { public WrapperPlayServerHeldItemSlot() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerHeldItemSlot(PacketContainer packet) { public WrapperPlayServerHeldItemSlot(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Slot. * Retrieve Slot.
* <p> * <p>
* Notes: the slot which the player has selected (0-8) * Notes: the slot which the player has selected (0-8)
* *
* @return The current Slot * @return The current Slot
*/ */
public int getSlot() { public int getSlot() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Slot. * Set Slot.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setSlot(int value) { public void setSlot(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
} }

View file

@ -2,203 +2,202 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import java.util.UUID;
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket { public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.NAMED_ENTITY_SPAWN; PacketType.Play.Server.NAMED_ENTITY_SPAWN;
public WrapperPlayServerNamedEntitySpawn() { public WrapperPlayServerNamedEntitySpawn() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) { public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Entity ID. * Retrieve Entity ID.
* <p> * <p>
* Notes: entity's ID * Notes: entity's ID
* *
* @return The current Entity ID * @return The current Entity ID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Entity ID. * Set Entity ID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEntityID(int value) { public void setEntityID(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param world - the current world of the entity. * @param world - the current world of the entity.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(World world) { public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0); return handle.getEntityModifier(world).read(0);
} }
/** /**
* Retrieve the entity of the painting that will be spawned. * Retrieve the entity of the painting that will be spawned.
* *
* @param event - the packet event. * @param event - the packet event.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld()); return getEntity(event.getPlayer().getWorld());
} }
/** /**
* Retrieve Player UUID. * Retrieve Player UUID.
* <p> * <p>
* Notes: player's UUID * Notes: player's UUID
* *
* @return The current Player UUID * @return The current Player UUID
*/ */
public UUID getPlayerUUID() { public UUID getPlayerUUID() {
return handle.getUUIDs().read(0); return handle.getUUIDs().read(0);
} }
/** /**
* Set Player UUID. * Set Player UUID.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setPlayerUUID(UUID value) { public void setPlayerUUID(UUID value) {
handle.getUUIDs().write(0, value); handle.getUUIDs().write(0, value);
} }
/** /**
* Retrieve the position of the spawned entity as a vector. * Retrieve the position of the spawned entity as a vector.
* *
* @return The position as a vector. * @return The position as a vector.
*/ */
public Vector getPosition() { public Vector getPosition() {
return new Vector(getX(), getY(), getZ()); return new Vector(getX(), getY(), getZ());
} }
/** /**
* Set the position of the spawned entity using a vector. * Set the position of the spawned entity using a vector.
* *
* @param position - the new position. * @param position - the new position.
*/ */
public void setPosition(Vector position) { public void setPosition(Vector position) {
setX(position.getX()); setX(position.getX());
setY(position.getY()); setY(position.getY());
setZ(position.getZ()); setZ(position.getZ());
} }
public double getX() { public double getX() {
return handle.getDoubles().read(0); return handle.getDoubles().read(0);
} }
public void setX(double value) { public void setX(double value) {
handle.getDoubles().write(0, value); handle.getDoubles().write(0, value);
} }
public double getY() { public double getY() {
return handle.getDoubles().read(1); return handle.getDoubles().read(1);
} }
public void setY(double value) { public void setY(double value) {
handle.getDoubles().write(1, value); handle.getDoubles().write(1, value);
} }
public double getZ() { public double getZ() {
return handle.getDoubles().read(2); return handle.getDoubles().read(2);
} }
public void setZ(double value) { public void setZ(double value) {
handle.getDoubles().write(2, value); handle.getDoubles().write(2, value);
} }
/** /**
* Retrieve the yaw of the spawned entity. * Retrieve the yaw of the spawned entity.
* *
* @return The current Yaw * @return The current Yaw
*/ */
public float getYaw() { public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F; return (handle.getBytes().read(0) * 360.F) / 256.0F;
} }
/** /**
* Set the yaw of the spawned entity. * Set the yaw of the spawned entity.
* *
* @param value - new yaw. * @param value - new yaw.
*/ */
public void setYaw(float value) { public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve the pitch of the spawned entity. * Retrieve the pitch of the spawned entity.
* *
* @return The current pitch * @return The current pitch
*/ */
public float getPitch() { public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F; return (handle.getBytes().read(1) * 360.F) / 256.0F;
} }
/** /**
* Set the pitch of the spawned entity. * Set the pitch of the spawned entity.
* *
* @param value - new pitch. * @param value - new pitch.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve Metadata. * Retrieve Metadata.
* <p> * <p>
* Notes: the client will crash if no metadata is sent * Notes: the client will crash if no metadata is sent
* *
* @return The current Metadata * @return The current Metadata
*/ */
public WrappedDataWatcher getMetadata() { public WrappedDataWatcher getMetadata() {
return handle.getDataWatcherModifier().read(0); return handle.getDataWatcherModifier().read(0);
} }
/** /**
* Set Metadata. * Set Metadata.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setMetadata(WrappedDataWatcher value) { public void setMetadata(WrappedDataWatcher value) {
handle.getDataWatcherModifier().write(0, value); handle.getDataWatcherModifier().write(0, value);
} }
} }

View file

@ -2,155 +2,154 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import org.bukkit.Sound;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory;
import org.bukkit.Sound;
public class WrapperPlayServerNamedSoundEffect extends AbstractPacket { public class WrapperPlayServerNamedSoundEffect extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.NAMED_SOUND_EFFECT; PacketType.Play.Server.NAMED_SOUND_EFFECT;
public WrapperPlayServerNamedSoundEffect() { public WrapperPlayServerNamedSoundEffect() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerNamedSoundEffect(PacketContainer packet) { public WrapperPlayServerNamedSoundEffect(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
public Sound getSoundEffect() { public Sound getSoundEffect() {
return handle.getSoundEffects().read(0); return handle.getSoundEffects().read(0);
} }
public void setSoundEffect(Sound value) { public void setSoundEffect(Sound value) {
handle.getSoundEffects().write(0, value); handle.getSoundEffects().write(0, value);
} }
public SoundCategory getSoundCategory() { public SoundCategory getSoundCategory() {
return handle.getSoundCategories().read(0); return handle.getSoundCategories().read(0);
} }
public void setSoundCategory(SoundCategory value) { public void setSoundCategory(SoundCategory value) {
handle.getSoundCategories().write(0, value); handle.getSoundCategories().write(0, value);
} }
/** /**
* Retrieve Effect position X. * Retrieve Effect position X.
* <p> * <p>
* Notes: effect X multiplied by 8 * Notes: effect X multiplied by 8
* *
* @return The current Effect position X * @return The current Effect position X
*/ */
public int getEffectPositionX() { public int getEffectPositionX() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Effect position X. * Set Effect position X.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEffectPositionX(int value) { public void setEffectPositionX(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Effect position Y. * Retrieve Effect position Y.
* <p> * <p>
* Notes: effect Y multiplied by 8 * Notes: effect Y multiplied by 8
* *
* @return The current Effect position Y * @return The current Effect position Y
*/ */
public int getEffectPositionY() { public int getEffectPositionY() {
return handle.getIntegers().read(1); return handle.getIntegers().read(1);
} }
/** /**
* Set Effect position Y. * Set Effect position Y.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEffectPositionY(int value) { public void setEffectPositionY(int value) {
handle.getIntegers().write(1, value); handle.getIntegers().write(1, value);
} }
/** /**
* Retrieve Effect position Z. * Retrieve Effect position Z.
* <p> * <p>
* Notes: effect Z multiplied by 8 * Notes: effect Z multiplied by 8
* *
* @return The current Effect position Z * @return The current Effect position Z
*/ */
public int getEffectPositionZ() { public int getEffectPositionZ() {
return handle.getIntegers().read(2); return handle.getIntegers().read(2);
} }
/** /**
* Set Effect position Z. * Set Effect position Z.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setEffectPositionZ(int value) { public void setEffectPositionZ(int value) {
handle.getIntegers().write(2, value); handle.getIntegers().write(2, value);
} }
/** /**
* Retrieve Volume. * Retrieve Volume.
* <p> * <p>
* Notes: 1 is 100%, can be more * Notes: 1 is 100%, can be more
* *
* @return The current Volume * @return The current Volume
*/ */
public float getVolume() { public float getVolume() {
return handle.getFloat().read(0); return handle.getFloat().read(0);
} }
/** /**
* Set Volume. * Set Volume.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setVolume(float value) { public void setVolume(float value) {
handle.getFloat().write(0, value); handle.getFloat().write(0, value);
} }
/** /**
* Retrieve Pitch. * Retrieve Pitch.
* <p> * <p>
* Notes: 63 is 100%, can be more * Notes: 63 is 100%, can be more
* *
* @return The current Pitch * @return The current Pitch
*/ */
public float getPitch() { public float getPitch() {
return handle.getFloat().read(1); return handle.getFloat().read(1);
} }
/** /**
* Set Pitch. * Set Pitch.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getFloat().write(1, value); handle.getFloat().write(1, value);
} }
} }

View file

@ -2,54 +2,54 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import java.util.List;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.PlayerInfoData;
import java.util.List;
public class WrapperPlayServerPlayerInfo extends AbstractPacket { public class WrapperPlayServerPlayerInfo extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO; public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
public WrapperPlayServerPlayerInfo() { public WrapperPlayServerPlayerInfo() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerPlayerInfo(PacketContainer packet) { public WrapperPlayServerPlayerInfo(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
public PlayerInfoAction getAction() { public PlayerInfoAction getAction() {
return handle.getPlayerInfoAction().read(0); return handle.getPlayerInfoAction().read(0);
} }
public void setAction(PlayerInfoAction value) { public void setAction(PlayerInfoAction value) {
handle.getPlayerInfoAction().write(0, value); handle.getPlayerInfoAction().write(0, value);
} }
public List<PlayerInfoData> getData() { public List<PlayerInfoData> getData() {
return handle.getPlayerInfoDataLists().read(0); return handle.getPlayerInfoDataLists().read(0);
} }
public void setData(List<PlayerInfoData> value) { public void setData(List<PlayerInfoData> value) {
handle.getPlayerInfoDataLists().write(0, value); handle.getPlayerInfoDataLists().write(0, value);
} }
} }

View file

@ -2,160 +2,159 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import java.util.Set;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.Set;
public class WrapperPlayServerPosition extends AbstractPacket { public class WrapperPlayServerPosition extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.POSITION; public static final PacketType TYPE = PacketType.Play.Server.POSITION;
private static final Class<?> FLAGS_CLASS = MinecraftReflection
.getMinecraftClass("EnumPlayerTeleportFlags",
"PacketPlayOutPosition$EnumPlayerTeleportFlags");
public WrapperPlayServerPosition() { public WrapperPlayServerPosition() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerPosition(PacketContainer packet) { public WrapperPlayServerPosition(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve X. * Retrieve X.
* <p> * <p>
* Notes: absolute/Relative position * Notes: absolute/Relative position
* *
* @return The current X * @return The current X
*/ */
public double getX() { public double getX() {
return handle.getDoubles().read(0); return handle.getDoubles().read(0);
} }
/** /**
* Set X. * Set X.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setX(double value) { public void setX(double value) {
handle.getDoubles().write(0, value); handle.getDoubles().write(0, value);
} }
/** /**
* Retrieve Y. * Retrieve Y.
* <p> * <p>
* Notes: absolute/Relative position * Notes: absolute/Relative position
* *
* @return The current Y * @return The current Y
*/ */
public double getY() { public double getY() {
return handle.getDoubles().read(1); return handle.getDoubles().read(1);
} }
/** /**
* Set Y. * Set Y.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setY(double value) { public void setY(double value) {
handle.getDoubles().write(1, value); handle.getDoubles().write(1, value);
} }
/** /**
* Retrieve Z. * Retrieve Z.
* <p> * <p>
* Notes: absolute/Relative position * Notes: absolute/Relative position
* *
* @return The current Z * @return The current Z
*/ */
public double getZ() { public double getZ() {
return handle.getDoubles().read(2); return handle.getDoubles().read(2);
} }
/** /**
* Set Z. * Set Z.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setZ(double value) { public void setZ(double value) {
handle.getDoubles().write(2, value); handle.getDoubles().write(2, value);
} }
/** /**
* Retrieve Yaw. * Retrieve Yaw.
* <p> * <p>
* Notes: absolute/Relative rotation on the X Axis, in degrees * Notes: absolute/Relative rotation on the X Axis, in degrees
* *
* @return The current Yaw * @return The current Yaw
*/ */
public float getYaw() { public float getYaw() {
return handle.getFloat().read(0); return handle.getFloat().read(0);
} }
/** /**
* Set Yaw. * Set Yaw.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setYaw(float value) { public void setYaw(float value) {
handle.getFloat().write(0, value); handle.getFloat().write(0, value);
} }
/** /**
* Retrieve Pitch. * Retrieve Pitch.
* <p> * <p>
* Notes: absolute/Relative rotation on the Y Axis, in degrees * Notes: absolute/Relative rotation on the Y Axis, in degrees
* *
* @return The current Pitch * @return The current Pitch
*/ */
public float getPitch() { public float getPitch() {
return handle.getFloat().read(1); return handle.getFloat().read(1);
} }
/** /**
* Set Pitch. * Set Pitch.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getFloat().write(1, value); handle.getFloat().write(1, value);
} }
private static final Class<?> FLAGS_CLASS = MinecraftReflection private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier() {
.getMinecraftClass("EnumPlayerTeleportFlags", return handle.getSets(
"PacketPlayOutPosition$EnumPlayerTeleportFlags"); EnumWrappers.getGenericConverter(FLAGS_CLASS, PlayerTeleportFlag.class));
}
public enum PlayerTeleportFlag { public Set<PlayerTeleportFlag> getFlags() {
X, Y, Z, Y_ROT, X_ROT return getFlagsModifier().read(0);
} }
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier() { public void setFlags(Set<PlayerTeleportFlag> value) {
return handle.getSets( getFlagsModifier().write(0, value);
EnumWrappers.getGenericConverter(FLAGS_CLASS, PlayerTeleportFlag.class)); }
}
public Set<PlayerTeleportFlag> getFlags() { public enum PlayerTeleportFlag {
return getFlagsModifier().read(0); X, Y, Z, Y_ROT, X_ROT
} }
public void setFlags(Set<PlayerTeleportFlag> value) {
getFlagsModifier().write(0, value);
}
} }

View file

@ -2,120 +2,119 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import org.bukkit.WorldType;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import org.bukkit.WorldType;
public class WrapperPlayServerRespawn extends AbstractPacket { public class WrapperPlayServerRespawn extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
public WrapperPlayServerRespawn() { public WrapperPlayServerRespawn() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerRespawn(PacketContainer packet) { public WrapperPlayServerRespawn(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Dimension. * Retrieve Dimension.
* <p> * <p>
* Notes: -1: The Nether, 0: The Overworld, 1: The End * Notes: -1: The Nether, 0: The Overworld, 1: The End
* *
* @return The current Dimension * @return The current Dimension
*/ */
public int getDimension() { public int getDimension() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Dimension. * Set Dimension.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setDimension(int value) { public void setDimension(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Difficulty. * Retrieve Difficulty.
* <p> * <p>
* Notes: 0 thru 3 for Peaceful, Easy, Normal, Hard. * Notes: 0 thru 3 for Peaceful, Easy, Normal, Hard.
* *
* @return The current Difficulty * @return The current Difficulty
*/ */
public Difficulty getDifficulty() { public Difficulty getDifficulty() {
return handle.getDifficulties().read(0); return handle.getDifficulties().read(0);
} }
/** /**
* Set Difficulty. * Set Difficulty.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setDifficulty(Difficulty value) { public void setDifficulty(Difficulty value) {
handle.getDifficulties().write(0, value); handle.getDifficulties().write(0, value);
} }
/** /**
* Retrieve Gamemode. * Retrieve Gamemode.
* <p> * <p>
* Notes: 0: survival, 1: creative, 2: adventure. The hardcore flag is not * Notes: 0: survival, 1: creative, 2: adventure. The hardcore flag is not
* included * included
* *
* @return The current Gamemode * @return The current Gamemode
*/ */
public NativeGameMode getGamemode() { public NativeGameMode getGamemode() {
return handle.getGameModes().read(0); return handle.getGameModes().read(0);
} }
/** /**
* Set Gamemode. * Set Gamemode.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setGamemode(NativeGameMode value) { public void setGamemode(NativeGameMode value) {
handle.getGameModes().write(0, value); handle.getGameModes().write(0, value);
} }
/** /**
* Retrieve Level Type. * Retrieve Level Type.
* <p> * <p>
* Notes: same as Join Game * Notes: same as Join Game
* *
* @return The current Level Type * @return The current Level Type
*/ */
public WorldType getLevelType() { public WorldType getLevelType() {
return handle.getWorldTypeModifier().read(0); return handle.getWorldTypeModifier().read(0);
} }
/** /**
* Set Level Type. * Set Level Type.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setLevelType(WorldType value) { public void setLevelType(WorldType value) {
handle.getWorldTypeModifier().write(0, value); handle.getWorldTypeModifier().write(0, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,57 +22,57 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerScoreboardDisplayObjective extends AbstractPacket { public class WrapperPlayServerScoreboardDisplayObjective extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE; PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE;
public WrapperPlayServerScoreboardDisplayObjective() { public WrapperPlayServerScoreboardDisplayObjective() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerScoreboardDisplayObjective(PacketContainer packet) { public WrapperPlayServerScoreboardDisplayObjective(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Position. * Retrieve Position.
* <p> * <p>
* Notes: the position of the scoreboard. 0 = list, 1 = sidebar, 2 = * Notes: the position of the scoreboard. 0 = list, 1 = sidebar, 2 =
* belowName. * belowName.
* *
* @return The current Position * @return The current Position
*/ */
public int getPosition() { public int getPosition() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Position. * Set Position.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setPosition(int value) { public void setPosition(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Score Name. * Retrieve Score Name.
* <p> * <p>
* Notes: the unique name for the scoreboard to be displayed. * Notes: the unique name for the scoreboard to be displayed.
* *
* @return The current Score Name * @return The current Score Name
*/ */
public String getScoreName() { public String getScoreName() {
return handle.getStrings().read(0); return handle.getStrings().read(0);
} }
/** /**
* Set Score Name. * Set Score Name.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setScoreName(String value) { public void setScoreName(String value) {
handle.getStrings().write(0, value); handle.getStrings().write(0, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -24,118 +24,118 @@ import com.comphenix.protocol.reflect.IntEnum;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
public class WrapperPlayServerScoreboardObjective extends AbstractPacket { public class WrapperPlayServerScoreboardObjective extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.SCOREBOARD_OBJECTIVE; PacketType.Play.Server.SCOREBOARD_OBJECTIVE;
public WrapperPlayServerScoreboardObjective() { public WrapperPlayServerScoreboardObjective() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerScoreboardObjective(PacketContainer packet) { public WrapperPlayServerScoreboardObjective(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Enum containing all known packet modes. * Retrieve Objective name.
* * <p>
* @author dmulloy2 * Notes: an unique name for the objective
*/ *
public static class Mode extends IntEnum { * @return The current Objective name
public static final int ADD_OBJECTIVE = 0; */
public static final int REMOVE_OBJECTIVE = 1; public String getName() {
public static final int UPDATE_VALUE = 2; return handle.getStrings().read(0);
}
private static final Mode INSTANCE = new Mode(); /**
* Set Objective name.
*
* @param value - new value.
*/
public void setName(String value) {
handle.getStrings().write(0, value);
}
public static Mode getInstance() { /**
return INSTANCE; * Retrieve Objective DisplayName.
} * <p>
} * 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);
}
/** /**
* Retrieve Objective name. * Set Objective DisplayName.
* <p> *
* Notes: an unique name for the objective * @param value - new value.
* */
* @return The current Objective name public void setDisplayName(WrappedChatComponent value) {
*/ handle.getChatComponents().write(0, value);
public String getName() { }
return handle.getStrings().read(0);
}
/** /**
* Set Objective name. * Retrieve health display.
* * <p>
* @param value - new value. * Notes: Can be either INTEGER or HEARTS
*/ *
public void setName(String value) { * @return the current health display value
handle.getStrings().write(0, value); */
} public HealthDisplay getHealthDisplay() {
return handle.getEnumModifier(HealthDisplay.class, 2).read(0);
}
/** /**
* Retrieve Objective DisplayName. * Set health display.
* <p> *
* Notes: only if mode is 0 or 2. The text to be displayed for the score. * @param value - value
* * @see #getHealthDisplay()
* @return The current Objective value */
*/ public void setHealthDisplay(HealthDisplay value) {
public WrappedChatComponent getDisplayName() { handle.getEnumModifier(HealthDisplay.class, 2).write(0, value);
return handle.getChatComponents().read(0); }
}
/** /**
* Set Objective DisplayName. * Retrieve Mode.
* * <p>
* @param value - new value. * Notes: 0 to create the scoreboard. 1 to remove the scoreboard. 2 to
*/ * update the display text.
public void setDisplayName(WrappedChatComponent value) { *
handle.getChatComponents().write(0, value); * @return The current Mode
} */
public int getMode() {
return handle.getIntegers().read(0);
}
/** /**
* Retrieve health display. * Set Mode.
* <p> *
* Notes: Can be either INTEGER or HEARTS * @param value - new value.
* */
* @return the current health display value public void setMode(int value) {
*/ handle.getIntegers().write(0, value);
public HealthDisplay getHealthDisplay() { }
return handle.getEnumModifier(HealthDisplay.class, 2).read(0);
}
/** public enum HealthDisplay {
* Set health display. INTEGER, HEARTS
* }
* @param value - value
* @see #getHealthDisplay()
*/
public void setHealthDisplay(HealthDisplay value) {
handle.getEnumModifier(HealthDisplay.class, 2).write(0, value);
}
/** /**
* Retrieve Mode. * Enum containing all known packet modes.
* <p> *
* Notes: 0 to create the scoreboard. 1 to remove the scoreboard. 2 to * @author dmulloy2
* update the display text. */
* public static class Mode extends IntEnum {
* @return The current Mode public static final int ADD_OBJECTIVE = 0;
*/ public static final int REMOVE_OBJECTIVE = 1;
public int getMode() { public static final int UPDATE_VALUE = 2;
return handle.getIntegers().read(0);
}
/** private static final Mode INSTANCE = new Mode();
* Set Mode.
*
* @param value - new value.
*/
public void setMode(int value) {
handle.getIntegers().write(0, value);
}
public enum HealthDisplay { public static Mode getInstance() {
INTEGER, HEARTS return INSTANCE;
} }
}
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -23,85 +23,85 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction;
public class WrapperPlayServerScoreboardScore extends AbstractPacket { public class WrapperPlayServerScoreboardScore extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.SCOREBOARD_SCORE; PacketType.Play.Server.SCOREBOARD_SCORE;
public WrapperPlayServerScoreboardScore() { public WrapperPlayServerScoreboardScore() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerScoreboardScore(PacketContainer packet) { public WrapperPlayServerScoreboardScore(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Score name. * Retrieve Score name.
* <p> * <p>
* Notes: the name of the score to be updated or removed. * Notes: the name of the score to be updated or removed.
* *
* @return The current Score name * @return The current Score name
*/ */
public String getScoreName() { public String getScoreName() {
return handle.getStrings().read(0); return handle.getStrings().read(0);
} }
/** /**
* Set Score name. * Set Score name.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setScoreName(String value) { public void setScoreName(String value) {
handle.getStrings().write(0, value); handle.getStrings().write(0, value);
} }
/** /**
* Retrieve Objective Name. * Retrieve Objective Name.
* <p> * <p>
* Notes: the name of the objective the score belongs to. * Notes: the name of the objective the score belongs to.
* *
* @return The current Objective Name * @return The current Objective Name
*/ */
public String getObjectiveName() { public String getObjectiveName() {
return handle.getStrings().read(1); return handle.getStrings().read(1);
} }
/** /**
* Set Objective Name. * Set Objective Name.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setObjectiveName(String value) { public void setObjectiveName(String value) {
handle.getStrings().write(1, value); handle.getStrings().write(1, value);
} }
/** /**
* Retrieve Value. * Retrieve Value.
* <p> * <p>
* Notes: the score to be displayed next to the entry. Only sent when * Notes: the score to be displayed next to the entry. Only sent when
* Update/Remove does not equal 1. * Update/Remove does not equal 1.
* *
* @return The current Value * @return The current Value
*/ */
public int getValue() { public int getValue() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Value. * Set Value.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setValue(int value) { public void setValue(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
public ScoreboardAction getAction() { public ScoreboardAction getAction() {
return handle.getScoreboardActions().read(0); return handle.getScoreboardActions().read(0);
} }
public void setScoreboardAction(ScoreboardAction value) { public void setScoreboardAction(ScoreboardAction value) {
handle.getScoreboardActions().write(0, value); handle.getScoreboardActions().write(0, value);
} }
} }

View file

@ -2,278 +2,277 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; package fr.leomelki.com.comphenix.packetwrapper;
import java.util.Collection;
import java.util.List;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.IntEnum; import com.comphenix.protocol.reflect.IntEnum;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.Collection;
import java.util.List;
public class WrapperPlayServerScoreboardTeam extends AbstractPacket { public class WrapperPlayServerScoreboardTeam extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.SCOREBOARD_TEAM; PacketType.Play.Server.SCOREBOARD_TEAM;
public WrapperPlayServerScoreboardTeam() { public WrapperPlayServerScoreboardTeam() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerScoreboardTeam(PacketContainer packet) { public WrapperPlayServerScoreboardTeam(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Enum containing all known modes. * Retrieve Team Name.
* * <p>
* @author dmulloy2 * Notes: a unique name for the team. (Shared with scoreboard).
*/ *
public static class Mode extends IntEnum { * @return The current Team Name
public static final int TEAM_CREATED = 0; */
public static final int TEAM_REMOVED = 1; public String getName() {
public static final int TEAM_UPDATED = 2; return handle.getStrings().read(0);
public static final int PLAYERS_ADDED = 3; }
public static final int PLAYERS_REMOVED = 4;
private static final Mode INSTANCE = new Mode(); /**
* Set Team Name.
*
* @param value - new value.
*/
public void setName(String value) {
handle.getStrings().write(0, value);
}
public static Mode getInstance() { /**
return INSTANCE; * Retrieve Team Display Name.
} * <p>
} * Notes: only if Mode = 0 or 2.
*
* @return The current Team Display Name
*/
public WrappedChatComponent getDisplayName() {
return handle.getChatComponents().read(0);
}
/** /**
* Retrieve Team Name. * Set Team Display Name.
* <p> *
* Notes: a unique name for the team. (Shared with scoreboard). * @param value - new value.
* */
* @return The current Team Name public void setDisplayName(WrappedChatComponent value) {
*/ handle.getChatComponents().write(0, value);
public String getName() { }
return handle.getStrings().read(0);
}
/** /**
* Set Team Name. * Retrieve Team Prefix.
* * <p>
* @param value - new value. * Notes: only if Mode = 0 or 2. Displayed before the players' name that are
*/ * part of this team.
public void setName(String value) { *
handle.getStrings().write(0, value); * @return The current Team Prefix
} */
public WrappedChatComponent getPrefix() {
return handle.getChatComponents().read(1);
}
/** /**
* Retrieve Team Display Name. * Set Team Prefix.
* <p> *
* Notes: only if Mode = 0 or 2. * @param value - new value.
* */
* @return The current Team Display Name public void setPrefix(WrappedChatComponent value) {
*/ handle.getChatComponents().write(1, value);
public WrappedChatComponent getDisplayName() { }
return handle.getChatComponents().read(0);
}
/** /**
* Set Team Display Name. * Retrieve Team Suffix.
* * <p>
* @param value - new value. * Notes: only if Mode = 0 or 2. Displayed after the players' name that are
*/ * part of this team.
public void setDisplayName(WrappedChatComponent value) { *
handle.getChatComponents().write(0, value); * @return The current Team Suffix
} */
public WrappedChatComponent getSuffix() {
return handle.getChatComponents().read(2);
}
/** /**
* Retrieve Team Prefix. * Set Team Suffix.
* <p> *
* Notes: only if Mode = 0 or 2. Displayed before the players' name that are * @param value - new value.
* part of this team. */
* public void setSuffix(WrappedChatComponent value) {
* @return The current Team Prefix handle.getChatComponents().write(2, value);
*/ }
public WrappedChatComponent getPrefix() {
return handle.getChatComponents().read(1);
}
/** /**
* Set Team Prefix. * Retrieve Name Tag Visibility.
* * <p>
* @param value - new value. * Notes: only if Mode = 0 or 2. always, hideForOtherTeams, hideForOwnTeam,
*/ * never.
public void setPrefix(WrappedChatComponent value) { *
handle.getChatComponents().write(1, value); * @return The current Name Tag Visibility
} */
public String getNameTagVisibility() {
return handle.getStrings().read(1);
}
/** /**
* Retrieve Team Suffix. * Set Name Tag Visibility.
* <p> *
* Notes: only if Mode = 0 or 2. Displayed after the players' name that are * @param value - new value.
* part of this team. */
* public void setNameTagVisibility(String value) {
* @return The current Team Suffix handle.getStrings().write(1, value);
*/ }
public WrappedChatComponent getSuffix() {
return handle.getChatComponents().read(2);
}
/** /**
* Set Team Suffix. * Retrieve Color.
* * <p>
* @param value - new value. * Notes: only if Mode = 0 or 2. Same as Chat colors.
*/ *
public void setSuffix(WrappedChatComponent value) { * @return The current Color
handle.getChatComponents().write(2, value); */
} public ChatColor getColor() {
return handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).read(0);
}
/** /**
* Retrieve Name Tag Visibility. * Set Color.
* <p> *
* Notes: only if Mode = 0 or 2. always, hideForOtherTeams, hideForOwnTeam, * @param value - new value.
* never. */
* public void setColor(ChatColor value) {
* @return The current Name Tag Visibility handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, value);
*/ }
public String getNameTagVisibility() {
return handle.getStrings().read(1);
}
/** /**
* Set Name Tag Visibility. * Get the collision rule.
* * Notes: only if Mode = 0 or 2. always, pushOtherTeams, pushOwnTeam, never.
* @param value - new value. * @return The current collision rule
*/ */
public void setNameTagVisibility(String value) { public String getCollisionRule() {
handle.getStrings().write(1, value); return handle.getStrings().read(2);
} }
/** /**
* Retrieve Color. * Sets the collision rule.
* <p> * @param value - new value.
* Notes: only if Mode = 0 or 2. Same as Chat colors. */
* public void setCollisionRule(String value) {
* @return The current Color handle.getStrings().write(2, value);
*/ }
public ChatColor getColor() {
return handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).read(0);
}
/** /**
* Set Color. * Retrieve Players.
* * <p>
* @param value - new value. * 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
public void setColor(ChatColor value) { *
handle.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, value); * @return The current Players
} */
@SuppressWarnings("unchecked")
public List<String> getPlayers() {
return (List<String>) handle.getSpecificModifier(Collection.class)
.read(0);
}
/** /**
* Get the collision rule. * Set Players.
* Notes: only if Mode = 0 or 2. always, pushOtherTeams, pushOwnTeam, never. *
* @return The current collision rule * @param value - new value.
*/ */
public String getCollisionRule() { public void setPlayers(List<String> value) {
return handle.getStrings().read(2); handle.getSpecificModifier(Collection.class).write(0, value);
} }
/** /**
* Sets the collision rule. * Retrieve Mode.
* @param value - new value. * <p>
*/ * Notes: if 0 then the team is created. If 1 then the team is removed. If 2
public void setCollisionRule(String value) { * the team team information is updated. If 3 then new players are added to
handle.getStrings().write(2, value); * the team. If 4 then players are removed from the team.
} *
* @return The current Mode
*/
public int getMode() {
return handle.getIntegers().read(0);
}
/** /**
* Retrieve Players. * Set Mode.
* <p> *
* Notes: only if Mode = 0 or 3 or 4. Players to be added/remove from the * @param value - new value.
* team. Max 40 characters so may be uuid's later */
* public void setMode(int value) {
* @return The current Players handle.getIntegers().write(0, value);
*/ }
@SuppressWarnings("unchecked")
public List<String> getPlayers() {
return (List<String>) handle.getSpecificModifier(Collection.class)
.read(0);
}
/** /**
* Set Players. * Retrieve pack option data. Pack data is calculated as follows:
* *
* @param value - new value. * <pre>
*/ * <code>
public void setPlayers(List<String> value) { * int data = 0;
handle.getSpecificModifier(Collection.class).write(0, value); * if (team.allowFriendlyFire()) {
} * data |= 1;
* }
* if (team.canSeeFriendlyInvisibles()) {
* data |= 2;
* }
* </code>
* </pre>
*
* @return The current pack option data
*/
public int getPackOptionData() {
return handle.getIntegers().read(1);
}
/** /**
* Retrieve Mode. * Set pack option data.
* <p> *
* Notes: if 0 then the team is created. If 1 then the team is removed. If 2 * @param value - new value
* the team team information is updated. If 3 then new players are added to * @see #getPackOptionData()
* the team. If 4 then players are removed from the team. */
* public void setPackOptionData(int value) {
* @return The current Mode handle.getIntegers().write(1, value);
*/ }
public int getMode() {
return handle.getIntegers().read(0);
}
/** /**
* Set Mode. * Enum containing all known modes.
* *
* @param value - new value. * @author dmulloy2
*/ */
public void setMode(int value) { public static class Mode extends IntEnum {
handle.getIntegers().write(0, value); 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();
* Retrieve pack option data. Pack data is calculated as follows:
*
* <pre>
* <code>
* int data = 0;
* if (team.allowFriendlyFire()) {
* data |= 1;
* }
* if (team.canSeeFriendlyInvisibles()) {
* data |= 2;
* }
* </code>
* </pre>
*
* @return The current pack option data
*/
public int getPackOptionData() {
return handle.getIntegers().read(1);
}
/** public static Mode getInstance() {
* Set pack option data. return INSTANCE;
* }
* @param value - new value }
* @see #getPackOptionData()
*/
public void setPackOptionData(int value) {
handle.getIntegers().write(1, value);
}
} }

View file

@ -2,377 +2,376 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.IntEnum; import com.comphenix.protocol.reflect.IntEnum;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import java.util.UUID;
public class WrapperPlayServerSpawnEntity extends AbstractPacket { public class WrapperPlayServerSpawnEntity extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY; public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
private static PacketConstructor entityConstructor; private static PacketConstructor entityConstructor;
/** public WrapperPlayServerSpawnEntity() {
* Represents the different object types. super(new PacketContainer(TYPE), TYPE);
* handle.getModifier().writeDefaults();
* @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;
/** public WrapperPlayServerSpawnEntity(PacketContainer packet) {
* The singleton instance. Can also be retrieved from the parent class. super(packet, TYPE);
*/ }
private static final ObjectTypes INSTANCE = new ObjectTypes();
/** public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) {
* Retrieve an instance of the object types enum. super(fromEntity(entity, type, objectData), TYPE);
* }
* @return Object type enum.
*/
public static ObjectTypes getInstance() {
return INSTANCE;
}
}
public WrapperPlayServerSpawnEntity() { // Useful constructor
super(new PacketContainer(TYPE), TYPE); private static PacketContainer fromEntity(Entity entity, int type,
handle.getModifier().writeDefaults(); int objectData) {
} if (entityConstructor == null)
entityConstructor =
ProtocolLibrary.getProtocolManager()
.createPacketConstructor(TYPE, entity, type,
objectData);
return entityConstructor.createPacket(entity, type, objectData);
}
public WrapperPlayServerSpawnEntity(PacketContainer packet) { /**
super(packet, TYPE); * Retrieve entity ID of the Object.
} *
* @return The current EID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) { /**
super(fromEntity(entity, type, objectData), TYPE); * Set entity ID of the Object.
} *
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
// Useful constructor /**
private static PacketContainer fromEntity(Entity entity, int type, * Retrieve the entity that will be spawned.
int objectData) { *
if (entityConstructor == null) * @param world - the current world of the entity.
entityConstructor = * @return The spawned entity.
ProtocolLibrary.getProtocolManager() */
.createPacketConstructor(TYPE, entity, type, public Entity getEntity(World world) {
objectData); return handle.getEntityModifier(world).read(0);
return entityConstructor.createPacket(entity, type, objectData); }
}
/** /**
* Retrieve entity ID of the Object. * Retrieve the entity that will be spawned.
* *
* @return The current EID * @param event - the packet event.
*/ * @return The spawned entity.
public int getEntityID() { */
return handle.getIntegers().read(0); public Entity getEntity(PacketEvent event) {
} return getEntity(event.getPlayer().getWorld());
}
/** public UUID getUniqueId() {
* Retrieve the entity that will be spawned. return handle.getUUIDs().read(0);
* }
* @param world - the current world of the entity.
* @return The spawned entity.
*/
public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0);
}
/** public void setUniqueId(UUID value) {
* Retrieve the entity that will be spawned. handle.getUUIDs().write(0, value);
* }
* @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. * Retrieve the x position of the object.
* * <p>
* @param value - new value. * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
*/ *
public void setEntityID(int value) { * @return The current X
handle.getIntegers().write(0, value); */
} public double getX() {
return handle.getDoubles().read(0);
}
public UUID getUniqueId() { /**
return handle.getUUIDs().read(0); * Set the x position of the object.
} *
* @param value - new value.
*/
public void setX(double value) {
handle.getDoubles().write(0, value);
}
public void setUniqueId(UUID value) { /**
handle.getUUIDs().write(0, value); * Retrieve the y position of the object.
} * <p>
* 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);
}
/** /**
* Retrieve the x position of the object. * Set the y position of the object.
* <p> *
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * @param value - new value.
* */
* @return The current X public void setY(double value) {
*/ handle.getDoubles().write(1, value);
public double getX() { }
return handle.getDoubles().read(0);
}
/** /**
* Set the x position of the object. * Retrieve the z position of the object.
* * <p>
* @param value - new value. * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
*/ *
public void setX(double value) { * @return The current z
handle.getDoubles().write(0, value); */
} public double getZ() {
return handle.getDoubles().read(2);
}
/** /**
* Retrieve the y position of the object. * Set the z position of the object.
* <p> *
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * @param value - new value.
* */
* @return The current y public void setZ(double value) {
*/ handle.getDoubles().write(2, value);
public double getY() { }
return handle.getDoubles().read(1);
}
/** /**
* Set the y position of the object. * Retrieve the optional speed x.
* * <p>
* @param value - new value. * This is ignored if {@link #getObjectData()} is zero.
*/ *
public void setY(double value) { * @return The optional speed x.
handle.getDoubles().write(1, value); */
} public double getOptionalSpeedX() {
return handle.getIntegers().read(1) / 8000.0D;
}
/** /**
* Retrieve the z position of the object. * Set the optional speed x.
* <p> *
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * @param value - new value.
* */
* @return The current z public void setOptionalSpeedX(double value) {
*/ handle.getIntegers().write(1, (int) (value * 8000.0D));
public double getZ() { }
return handle.getDoubles().read(2);
}
/** /**
* Set the z position of the object. * Retrieve the optional speed y.
* * <p>
* @param value - new value. * This is ignored if {@link #getObjectData()} is zero.
*/ *
public void setZ(double value) { * @return The optional speed y.
handle.getDoubles().write(2, value); */
} public double getOptionalSpeedY() {
return handle.getIntegers().read(2) / 8000.0D;
}
/** /**
* Retrieve the optional speed x. * Set the optional speed y.
* <p> *
* This is ignored if {@link #getObjectData()} is zero. * @param value - new value.
* */
* @return The optional speed x. public void setOptionalSpeedY(double value) {
*/ handle.getIntegers().write(2, (int) (value * 8000.0D));
public double getOptionalSpeedX() { }
return handle.getIntegers().read(1) / 8000.0D;
}
/** /**
* Set the optional speed x. * Retrieve the optional speed z.
* * <p>
* @param value - new value. * This is ignored if {@link #getObjectData()} is zero.
*/ *
public void setOptionalSpeedX(double value) { * @return The optional speed z.
handle.getIntegers().write(1, (int) (value * 8000.0D)); */
} public double getOptionalSpeedZ() {
return handle.getIntegers().read(3) / 8000.0D;
}
/** /**
* Retrieve the optional speed y. * Set the optional speed z.
* <p> *
* This is ignored if {@link #getObjectData()} is zero. * @param value - new value.
* */
* @return The optional speed y. public void setOptionalSpeedZ(double value) {
*/ handle.getIntegers().write(3, (int) (value * 8000.0D));
public double getOptionalSpeedY() { }
return handle.getIntegers().read(2) / 8000.0D;
}
/** /**
* Set the optional speed y. * Retrieve the pitch.
* *
* @param value - new value. * @return The current pitch.
*/ */
public void setOptionalSpeedY(double value) { public float getPitch() {
handle.getIntegers().write(2, (int) (value * 8000.0D)); return (handle.getIntegers().read(4) * 360.F) / 256.0F;
} }
/** /**
* Retrieve the optional speed z. * Set the pitch.
* <p> *
* This is ignored if {@link #getObjectData()} is zero. * @param value - new pitch.
* */
* @return The optional speed z. public void setPitch(float value) {
*/ handle.getIntegers().write(4, (int) (value * 256.0F / 360.0F));
public double getOptionalSpeedZ() { }
return handle.getIntegers().read(3) / 8000.0D;
}
/** /**
* Set the optional speed z. * Retrieve the yaw.
* *
* @param value - new value. * @return The current Yaw
*/ */
public void setOptionalSpeedZ(double value) { public float getYaw() {
handle.getIntegers().write(3, (int) (value * 8000.0D)); return (handle.getIntegers().read(5) * 360.F) / 256.0F;
} }
/** /**
* Retrieve the pitch. * Set the yaw of the object spawned.
* *
* @return The current pitch. * @param value - new yaw.
*/ */
public float getPitch() { public void setYaw(float value) {
return (handle.getIntegers().read(4) * 360.F) / 256.0F; handle.getIntegers().write(5, (int) (value * 256.0F / 360.0F));
} }
/** /**
* Set the pitch. * Retrieve the type of object. See {@link ObjectTypes}
* *
* @param value - new pitch. * @return The current Type
*/ */
public void setPitch(float value) { public int getType() {
handle.getIntegers().write(4, (int) (value * 256.0F / 360.0F)); return handle.getIntegers().read(6);
} }
/** /**
* Retrieve the yaw. * Set the type of object. See {@link ObjectTypes}.
* *
* @return The current Yaw * @param value - new value.
*/ */
public float getYaw() { public void setType(int value) {
return (handle.getIntegers().read(5) * 360.F) / 256.0F; handle.getIntegers().write(6, value);
} }
/** /**
* Set the yaw of the object spawned. * Retrieve object data.
* * <p>
* @param value - new yaw. * The content depends on the object type:
*/ * <table border="1" cellpadding="4">
public void setYaw(float value) { * <tr>
handle.getIntegers().write(5, (int) (value * 256.0F / 360.0F)); * <th>Object Type:</th>
} * <th>Name:</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>ITEM_FRAME</td>
* <td>Orientation</td>
* <td>0-3: South, West, North, East</td>
* </tr>
* <tr>
* <td>FALLING_BLOCK</td>
* <td>Block Type</td>
* <td>BlockID | (Metadata << 0xC)</td>
* </tr>
* <tr>
* <td>Projectiles</td>
* <td>Entity ID</td>
* <td>The entity ID of the thrower</td>
* </tr>
* <tr>
* <td>Splash Potions</td>
* <td>Data Value</td>
* <td>Potion data value.</td>
* </tr>
* </table>
*
* @return The current object Data
*/
public int getObjectData() {
return handle.getIntegers().read(7);
}
/** /**
* Retrieve the type of object. See {@link ObjectTypes} * Set object Data.
* * <p>
* @return The current Type * The content depends on the object type. See {@link #getObjectData()} for
*/ * more information.
public int getType() { *
return handle.getIntegers().read(6); * @param value - new object data.
} */
public void setObjectData(int value) {
handle.getIntegers().write(7, value);
}
/** /**
* Set the type of object. See {@link ObjectTypes}. * Represents the different object types.
* *
* @param value - new value. * @author Kristian
*/ */
public void setType(int value) { public static class ObjectTypes extends IntEnum {
handle.getIntegers().write(6, value); 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;
/** /**
* Retrieve object data. * The singleton instance. Can also be retrieved from the parent class.
* <p> */
* The content depends on the object type: private static final ObjectTypes INSTANCE = new ObjectTypes();
* <table border="1" cellpadding="4">
* <tr>
* <th>Object Type:</th>
* <th>Name:</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>ITEM_FRAME</td>
* <td>Orientation</td>
* <td>0-3: South, West, North, East</td>
* </tr>
* <tr>
* <td>FALLING_BLOCK</td>
* <td>Block Type</td>
* <td>BlockID | (Metadata << 0xC)</td>
* </tr>
* <tr>
* <td>Projectiles</td>
* <td>Entity ID</td>
* <td>The entity ID of the thrower</td>
* </tr>
* <tr>
* <td>Splash Potions</td>
* <td>Data Value</td>
* <td>Potion data value.</td>
* </tr>
* </table>
*
* @return The current object Data
*/
public int getObjectData() {
return handle.getIntegers().read(7);
}
/** /**
* Set object Data. * Retrieve an instance of the object types enum.
* <p> *
* The content depends on the object type. See {@link #getObjectData()} for * @return Object type enum.
* more information. */
* public static ObjectTypes getInstance() {
* @param value - new object data. return INSTANCE;
*/ }
public void setObjectData(int value) { }
handle.getIntegers().write(7, value);
}
} }

View file

@ -2,312 +2,311 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.leomelki.com.comphenix.packetwrapper; 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.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import java.util.UUID;
public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket { public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
public static final PacketType TYPE = public static final PacketType TYPE =
PacketType.Play.Server.SPAWN_ENTITY_LIVING; PacketType.Play.Server.SPAWN_ENTITY_LIVING;
private static PacketConstructor entityConstructor; private static PacketConstructor entityConstructor;
public WrapperPlayServerSpawnEntityLiving() { public WrapperPlayServerSpawnEntityLiving() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerSpawnEntityLiving(PacketContainer packet) { public WrapperPlayServerSpawnEntityLiving(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
public WrapperPlayServerSpawnEntityLiving(Entity entity) { public WrapperPlayServerSpawnEntityLiving(Entity entity) {
super(fromEntity(entity), TYPE); super(fromEntity(entity), TYPE);
} }
// Useful constructor // Useful constructor
private static PacketContainer fromEntity(Entity entity) { private static PacketContainer fromEntity(Entity entity) {
if (entityConstructor == null) if (entityConstructor == null)
entityConstructor = entityConstructor =
ProtocolLibrary.getProtocolManager() ProtocolLibrary.getProtocolManager()
.createPacketConstructor(TYPE, entity); .createPacketConstructor(TYPE, entity);
return entityConstructor.createPacket(entity); return entityConstructor.createPacket(entity);
} }
/** /**
* Retrieve entity ID. * Retrieve entity ID.
* *
* @return The current EID * @return The current EID
*/ */
public int getEntityID() { public int getEntityID() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Retrieve the entity that will be spawned. * Set entity ID.
* *
* @param world - the current world of the entity. * @param value - new value.
* @return The spawned entity. */
*/ public void setEntityID(int value) {
public Entity getEntity(World world) { handle.getIntegers().write(0, value);
return handle.getEntityModifier(world).read(0); }
}
/** /**
* Retrieve the entity that will be spawned. * Retrieve the entity that will be spawned.
* *
* @param event - the packet event. * @param world - the current world of the entity.
* @return The spawned entity. * @return The spawned entity.
*/ */
public Entity getEntity(PacketEvent event) { public Entity getEntity(World world) {
return getEntity(event.getPlayer().getWorld()); return handle.getEntityModifier(world).read(0);
} }
public UUID getUniqueId() { /**
return handle.getUUIDs().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 void setUniqueId(UUID value) { public UUID getUniqueId() {
handle.getUUIDs().write(0, value); return handle.getUUIDs().read(0);
} }
/** public void setUniqueId(UUID value) {
* Set entity ID. handle.getUUIDs().write(0, value);
* }
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
/** /**
* Retrieve the type of mob. * Retrieve the type of mob.
* *
* @return The current Type * @return The current Type
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public EntityType getType() { public EntityType getType() {
return EntityType.fromId(handle.getIntegers().read(1)); return EntityType.fromId(handle.getIntegers().read(1));
} }
/** /**
* Set the type of mob. * Set the type of mob.
* *
* @param value - new value. * @param value - new value.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void setType(EntityType value) { public void setType(EntityType value) {
handle.getIntegers().write(1, (int) value.getTypeId()); handle.getIntegers().write(1, (int) value.getTypeId());
} }
/** /**
* Retrieve the x position of the object. * Retrieve the x position of the object.
* <p> * <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* *
* @return The current X * @return The current X
*/ */
public double getX() { public double getX() {
return handle.getDoubles().read(0); return handle.getDoubles().read(0);
} }
/** /**
* Set the x position of the object. * Set the x position of the object.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setX(double value) { public void setX(double value) {
handle.getDoubles().write(0, value); handle.getDoubles().write(0, value);
} }
/** /**
* Retrieve the y position of the object. * Retrieve the y position of the object.
* <p> * <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* *
* @return The current y * @return The current y
*/ */
public double getY() { public double getY() {
return handle.getDoubles().read(1); return handle.getDoubles().read(1);
} }
/** /**
* Set the y position of the object. * Set the y position of the object.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setY(double value) { public void setY(double value) {
handle.getDoubles().write(1, value); handle.getDoubles().write(1, value);
} }
/** /**
* Retrieve the z position of the object. * Retrieve the z position of the object.
* <p> * <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter. * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* *
* @return The current z * @return The current z
*/ */
public double getZ() { public double getZ() {
return handle.getDoubles().read(2); return handle.getDoubles().read(2);
} }
/** /**
* Set the z position of the object. * Set the z position of the object.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setZ(double value) { public void setZ(double value) {
handle.getDoubles().write(2, value); handle.getDoubles().write(2, value);
} }
/** /**
* Retrieve the yaw. * Retrieve the yaw.
* *
* @return The current Yaw * @return The current Yaw
*/ */
public float getYaw() { public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F; return (handle.getBytes().read(0) * 360.F) / 256.0F;
} }
/** /**
* Set the yaw of the spawned mob. * Set the yaw of the spawned mob.
* *
* @param value - new yaw. * @param value - new yaw.
*/ */
public void setYaw(float value) { public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve the pitch. * Retrieve the pitch.
* *
* @return The current pitch * @return The current pitch
*/ */
public float getPitch() { public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F; return (handle.getBytes().read(1) * 360.F) / 256.0F;
} }
/** /**
* Set the pitch of the spawned mob. * Set the pitch of the spawned mob.
* *
* @param value - new pitch. * @param value - new pitch.
*/ */
public void setPitch(float value) { public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve the yaw of the mob's head. * Retrieve the yaw of the mob's head.
* *
* @return The current yaw. * @return The current yaw.
*/ */
public float getHeadPitch() { public float getHeadPitch() {
return (handle.getBytes().read(2) * 360.F) / 256.0F; return (handle.getBytes().read(2) * 360.F) / 256.0F;
} }
/** /**
* Set the yaw of the mob's head. * Set the yaw of the mob's head.
* *
* @param value - new yaw. * @param value - new yaw.
*/ */
public void setHeadPitch(float value) { public void setHeadPitch(float value) {
handle.getBytes().write(2, (byte) (value * 256.0F / 360.0F)); handle.getBytes().write(2, (byte) (value * 256.0F / 360.0F));
} }
/** /**
* Retrieve the velocity in the x axis. * Retrieve the velocity in the x axis.
* *
* @return The current velocity X * @return The current velocity X
*/ */
public double getVelocityX() { public double getVelocityX() {
return handle.getIntegers().read(2) / 8000.0D; return handle.getIntegers().read(2) / 8000.0D;
} }
/** /**
* Set the velocity in the x axis. * Set the velocity in the x axis.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setVelocityX(double value) { public void setVelocityX(double value) {
handle.getIntegers().write(2, (int) (value * 8000.0D)); handle.getIntegers().write(2, (int) (value * 8000.0D));
} }
/** /**
* Retrieve the velocity in the y axis. * Retrieve the velocity in the y axis.
* *
* @return The current velocity y * @return The current velocity y
*/ */
public double getVelocityY() { public double getVelocityY() {
return handle.getIntegers().read(3) / 8000.0D; return handle.getIntegers().read(3) / 8000.0D;
} }
/** /**
* Set the velocity in the y axis. * Set the velocity in the y axis.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setVelocityY(double value) { public void setVelocityY(double value) {
handle.getIntegers().write(3, (int) (value * 8000.0D)); handle.getIntegers().write(3, (int) (value * 8000.0D));
} }
/** /**
* Retrieve the velocity in the z axis. * Retrieve the velocity in the z axis.
* *
* @return The current velocity z * @return The current velocity z
*/ */
public double getVelocityZ() { public double getVelocityZ() {
return handle.getIntegers().read(4) / 8000.0D; return handle.getIntegers().read(4) / 8000.0D;
} }
/** /**
* Set the velocity in the z axis. * Set the velocity in the z axis.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setVelocityZ(double value) { public void setVelocityZ(double value) {
handle.getIntegers().write(4, (int) (value * 8000.0D)); handle.getIntegers().write(4, (int) (value * 8000.0D));
} }
/** /**
* Retrieve the data watcher. * Retrieve the data watcher.
* <p> * <p>
* Content varies by mob, see Entities. * Content varies by mob, see Entities.
* *
* @return The current Metadata * @return The current Metadata
*/ */
/* public WrappedDataWatcher getMetadata() { /* public WrappedDataWatcher getMetadata() {
return handle.getDataWatcherModifier().read(0); return handle.getDataWatcherModifier().read(0);
}*/ }*/
/** /**
* Set the data watcher. * Set the data watcher.
* *
* @param value - new value. * @param value - new value.
*/ */
/*public void setMetadata(WrappedDataWatcher value) { /*public void setMetadata(WrappedDataWatcher value) {
handle.getDataWatcherModifier().write(0, value); handle.getDataWatcherModifier().write(0, value);
}*/ }*/

View file

@ -2,17 +2,17 @@
* This file is part of PacketWrapper. * This file is part of PacketWrapper.
* Copyright (C) 2012-2015 Kristian S. Strangeland * Copyright (C) 2012-2015 Kristian S. Strangeland
* Copyright (C) 2015 dmulloy2 * Copyright (C) 2015 dmulloy2
* * <p>
* PacketWrapper is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* PacketWrapper is distributed in the hope that it will be useful, * PacketWrapper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with PacketWrapper. If not, see <http://www.gnu.org/licenses/>. * along with PacketWrapper. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -26,16 +26,16 @@ import com.comphenix.protocol.wrappers.MinecraftKey;
public class WrapperPlayServerStopSound extends AbstractPacket { public class WrapperPlayServerStopSound extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.STOP_SOUND; public static final PacketType TYPE = PacketType.Play.Server.STOP_SOUND;
public WrapperPlayServerStopSound() { public WrapperPlayServerStopSound() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerStopSound(PacketContainer packet) { public WrapperPlayServerStopSound(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
public MinecraftKey getSoundEffect() { public MinecraftKey getSoundEffect() {
return handle.getMinecraftKeys().readSafely(0); return handle.getMinecraftKeys().readSafely(0);
} }
@ -45,10 +45,10 @@ public class WrapperPlayServerStopSound extends AbstractPacket {
} }
public EnumWrappers.SoundCategory getCategory() { public EnumWrappers.SoundCategory getCategory() {
return handle.getSoundCategories().readSafely(0); return handle.getSoundCategories().readSafely(0);
} }
public void setCategory(EnumWrappers.SoundCategory value) { public void setCategory(EnumWrappers.SoundCategory value) {
handle.getSoundCategories().writeSafely(0, value); handle.getSoundCategories().writeSafely(0, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -24,108 +24,108 @@ import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
public class WrapperPlayServerTitle extends AbstractPacket { public class WrapperPlayServerTitle extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.TITLE; public static final PacketType TYPE = PacketType.Play.Server.TITLE;
public WrapperPlayServerTitle() { public WrapperPlayServerTitle() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerTitle(PacketContainer packet) { public WrapperPlayServerTitle(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Action. * Retrieve Action.
* *
* @return The current Action * @return The current Action
*/ */
public TitleAction getAction() { public TitleAction getAction() {
return handle.getTitleActions().read(0); return handle.getTitleActions().read(0);
} }
/** /**
* Set Action. * Set Action.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setAction(TitleAction value) { public void setAction(TitleAction value) {
handle.getTitleActions().write(0, value); handle.getTitleActions().write(0, value);
} }
/** /**
* Retrieve 0 (TITLE). * Retrieve 0 (TITLE).
* <p> * <p>
* Notes: chat * Notes: chat
* *
* @return The current 0 (TITLE) * @return The current 0 (TITLE)
*/ */
public WrappedChatComponent getTitle() { public WrappedChatComponent getTitle() {
return handle.getChatComponents().read(0); return handle.getChatComponents().read(0);
} }
/** /**
* Set 0 (TITLE). * Set 0 (TITLE).
* *
* @param value - new value. * @param value - new value.
*/ */
public void setTitle(WrappedChatComponent value) { public void setTitle(WrappedChatComponent value) {
handle.getChatComponents().write(0, value); handle.getChatComponents().write(0, value);
} }
/** /**
* Retrieve 2 (TIMES). * Retrieve 2 (TIMES).
* <p> * <p>
* Notes: int * Notes: int
* *
* @return The current 2 (TIMES) * @return The current 2 (TIMES)
*/ */
public int getFadeIn() { public int getFadeIn() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set 2 (TIMES). * Set 2 (TIMES).
* *
* @param value - new value. * @param value - new value.
*/ */
public void setFadeIn(int value) { public void setFadeIn(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Stay. * Retrieve Stay.
* *
* @return The current Stay * @return The current Stay
*/ */
public int getStay() { public int getStay() {
return handle.getIntegers().read(1); return handle.getIntegers().read(1);
} }
/** /**
* Set Stay. * Set Stay.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setStay(int value) { public void setStay(int value) {
handle.getIntegers().write(1, value); handle.getIntegers().write(1, value);
} }
/** /**
* Retrieve Fade Out. * Retrieve Fade Out.
* *
* @return The current Fade Out * @return The current Fade Out
*/ */
public int getFadeOut() { public int getFadeOut() {
return handle.getIntegers().read(2); return handle.getIntegers().read(2);
} }
/** /**
* Set Fade Out. * Set Fade Out.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setFadeOut(int value) { public void setFadeOut(int value) {
handle.getIntegers().write(2, value); handle.getIntegers().write(2, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,75 +22,75 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerUpdateHealth extends AbstractPacket { public class WrapperPlayServerUpdateHealth extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.UPDATE_HEALTH; public static final PacketType TYPE = PacketType.Play.Server.UPDATE_HEALTH;
public WrapperPlayServerUpdateHealth() { public WrapperPlayServerUpdateHealth() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerUpdateHealth(PacketContainer packet) { public WrapperPlayServerUpdateHealth(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Health. * Retrieve Health.
* <p> * <p>
* Notes: 0 or less = dead, 20 = full HP * Notes: 0 or less = dead, 20 = full HP
* *
* @return The current Health * @return The current Health
*/ */
public float getHealth() { public float getHealth() {
return handle.getFloat().read(0); return handle.getFloat().read(0);
} }
/** /**
* Set Health. * Set Health.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setHealth(float value) { public void setHealth(float value) {
handle.getFloat().write(0, value); handle.getFloat().write(0, value);
} }
/** /**
* Retrieve Food. * Retrieve Food.
* <p> * <p>
* Notes: 0 - 20 * Notes: 0 - 20
* *
* @return The current Food * @return The current Food
*/ */
public int getFood() { public int getFood() {
return handle.getIntegers().read(0); return handle.getIntegers().read(0);
} }
/** /**
* Set Food. * Set Food.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setFood(int value) { public void setFood(int value) {
handle.getIntegers().write(0, value); handle.getIntegers().write(0, value);
} }
/** /**
* Retrieve Food Saturation. * Retrieve Food Saturation.
* <p> * <p>
* Notes: seems to vary from 0.0 to 5.0 in integer increments * Notes: seems to vary from 0.0 to 5.0 in integer increments
* *
* @return The current Food Saturation * @return The current Food Saturation
*/ */
public float getFoodSaturation() { public float getFoodSaturation() {
return handle.getFloat().read(1); return handle.getFloat().read(1);
} }
/** /**
* Set Food Saturation. * Set Food Saturation.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setFoodSaturation(float value) { public void setFoodSaturation(float value) {
handle.getFloat().write(1, value); handle.getFloat().write(1, value);
} }
} }

View file

@ -2,17 +2,17 @@
* PacketWrapper - ProtocolLib wrappers for Minecraft packets * PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net> * Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland * Copyright (C) Kristian S. Strangeland
* * <p>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -22,56 +22,56 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerUpdateTime extends AbstractPacket { public class WrapperPlayServerUpdateTime extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.UPDATE_TIME; public static final PacketType TYPE = PacketType.Play.Server.UPDATE_TIME;
public WrapperPlayServerUpdateTime() { public WrapperPlayServerUpdateTime() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
public WrapperPlayServerUpdateTime(PacketContainer packet) { public WrapperPlayServerUpdateTime(PacketContainer packet) {
super(packet, TYPE); super(packet, TYPE);
} }
/** /**
* Retrieve Age of the world. * Retrieve Age of the world.
* <p> * <p>
* Notes: in ticks; not changed by server commands * Notes: in ticks; not changed by server commands
* *
* @return The current Age of the world * @return The current Age of the world
*/ */
public long getAgeOfTheWorld() { public long getAgeOfTheWorld() {
return handle.getLongs().read(0); return handle.getLongs().read(0);
} }
/** /**
* Set Age of the world. * Set Age of the world.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setAgeOfTheWorld(long value) { public void setAgeOfTheWorld(long value) {
handle.getLongs().write(0, value); handle.getLongs().write(0, value);
} }
/** /**
* Retrieve Time of day. * Retrieve Time of day.
* <p> * <p>
* Notes: the world (or region) time, in ticks. If negative the sun will * Notes: the world (or region) time, in ticks. If negative the sun will
* stop moving at the Math.abs of the time * stop moving at the Math.abs of the time
* *
* @return The current Time of day * @return The current Time of day
*/ */
public long getTimeOfDay() { public long getTimeOfDay() {
return handle.getLongs().read(1); return handle.getLongs().read(1);
} }
/** /**
* Set Time of day. * Set Time of day.
* *
* @param value - new value. * @param value - new value.
*/ */
public void setTimeOfDay(long value) { public void setTimeOfDay(long value) {
handle.getLongs().write(1, value); handle.getLongs().write(1, value);
} }
} }

View file

@ -1,18 +1,26 @@
package fr.leomelki.loupgarou; package fr.leomelki.loupgarou;
import java.io.File; import com.comphenix.protocol.PacketType;
import java.lang.reflect.Constructor; import com.comphenix.protocol.ProtocolLibrary;
import java.util.ArrayList; import com.comphenix.protocol.ProtocolManager;
import java.util.Arrays; import com.comphenix.protocol.events.ListenerPriority;
import java.util.HashMap; import com.comphenix.protocol.events.PacketAdapter;
import java.util.List; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import org.bukkit.Bukkit; import com.comphenix.protocol.wrappers.PlayerInfoData;
import org.bukkit.ChatColor; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import org.bukkit.Location; import fr.leomelki.com.comphenix.packetwrapper.*;
import org.bukkit.Material; import fr.leomelki.loupgarou.classes.LGGame;
import org.bukkit.Sound; 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.*;
import fr.leomelki.loupgarou.roles.*;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.*;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -25,419 +33,378 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.comphenix.protocol.PacketType; import java.io.File;
import com.comphenix.protocol.ProtocolLibrary; import java.lang.reflect.Constructor;
import com.comphenix.protocol.ProtocolManager; import java.util.ArrayList;
import com.comphenix.protocol.events.ListenerPriority; import java.util.Arrays;
import com.comphenix.protocol.events.PacketAdapter; import java.util.HashMap;
import com.comphenix.protocol.events.PacketEvent; import java.util.List;
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; public class MainLg extends JavaPlugin {
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerNamedSoundEffect; @Getter
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo; private static final String prefix = ""/*"§7[§9Loup-Garou§7] "*/;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; private static MainLg instance;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateHealth; @Getter
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerUpdateTime; private final HashMap<String, Constructor<? extends Role>> roles = new HashMap<>();
import fr.leomelki.loupgarou.classes.LGGame; @Getter
import fr.leomelki.loupgarou.classes.LGPlayer; @Setter
import fr.leomelki.loupgarou.classes.LGWinType; private LGGame currentGame;//Because for now, only one game will be playable on one server (flemme)
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.RChasseurDeVampire;
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.RMontreurDOurs;
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.RVampire;
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{ public static MainLg getInstance() {
private static MainLg instance; return instance;
@Getter private final HashMap<String, Constructor<? extends Role>> roles = new HashMap<>(); }
@Getter private static final String prefix = ""/*"§7[§9Loup-Garou§7] "*/;
@Override
@Getter @Setter private LGGame currentGame;//Because for now, only one game will be playable on one server (flemme) public void onEnable() {
instance = this;
@Override loadRoles();
public void onEnable() { if (!new File(getDataFolder(), "config.yml").exists()) {//Créer la config
instance = this; FileConfiguration config = getConfig();
loadRoles(); config.set("spawns", new ArrayList<List<Double>>());
if(!new File(getDataFolder(), "config.yml").exists()) {//Créer la config for (String role : roles.keySet())//Nombre de participant pour chaque rôle
FileConfiguration config = getConfig(); config.set("role." + role, 1);
config.set("spawns", new ArrayList<List<Double>>()); saveConfig();
for(String role : roles.keySet())//Nombre de participant pour chaque rôle }
config.set("role."+role, 1); loadConfig();
saveConfig(); Bukkit.getPluginManager().registerEvents(new JoinListener(this), this);
} Bukkit.getPluginManager().registerEvents(new CancelListener(this), this);
loadConfig(); Bukkit.getPluginManager().registerEvents(new VoteListener(this), this);
Bukkit.getPluginManager().registerEvents(new JoinListener(this), this); Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new CancelListener(this), this); Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this);
Bukkit.getPluginManager().registerEvents(new VoteListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this); for (Player player : Bukkit.getOnlinePlayers())
Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this); Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, "is connected"));
for(Player player : Bukkit.getOnlinePlayers()) ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, "is connected")); protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) {
@Override
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); public void onPacketSending(PacketEvent event) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) { WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket());
@Override LGPlayer lgp = LGPlayer.thePlayer(instance, event.getPlayer());
public void onPacketSending(PacketEvent event) { if (lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay())
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket()); event.setCancelled(true);
LGPlayer lgp = LGPlayer.thePlayer(instance, 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
//Éviter que les gens s'entendent quand ils se sélectionnent et qu'ils sont trop proche public void onPacketSending(PacketEvent event) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_SOUND_EFFECT) { WrapperPlayServerNamedSoundEffect sound = new WrapperPlayServerNamedSoundEffect(event.getPacket());
@Override if (sound.getSoundEffect() == Sound.ENTITY_PLAYER_ATTACK_NODAMAGE)
public void onPacketSending(PacketEvent event) { event.setCancelled(true);
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) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
@Override WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket());
public void onPacketSending(PacketEvent event) { ArrayList<PlayerInfoData> datas = new ArrayList<>();
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); for (PlayerInfoData data : info.getData()) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket()); LGPlayer lgp = LGPlayer.thePlayer(instance, Bukkit.getPlayer(data.getProfile().getUUID()));
ArrayList<PlayerInfoData> datas = new ArrayList<>(); if (player.getGame() != null && player.getGame() == lgp.getGame()) {
for(PlayerInfoData data : info.getData()) { LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
LGPlayer lgp = LGPlayer.thePlayer(instance, Bukkit.getPlayer(data.getProfile().getUUID())); WrappedChatComponent displayName = data.getDisplayName();
if(player.getGame() != null && player.getGame() == lgp.getGame()) { Bukkit.getPluginManager().callEvent(evt2);
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); if (evt2.getPrefix().length() > 0) {
WrappedChatComponent displayName = data.getDisplayName(); try {
Bukkit.getPluginManager().callEvent(evt2); if (displayName != null) {
if(evt2.getPrefix().length() > 0) { JSONObject obj = (JSONObject) new JSONParser().parse(displayName.getJson());
try { displayName = WrappedChatComponent.fromText(evt2.getPrefix() + obj.get("text"));
if(displayName != null) { } else
JSONObject obj = (JSONObject) new JSONParser().parse(displayName.getJson()); displayName = WrappedChatComponent.fromText(evt2.getPrefix() + data.getProfile().getName());
displayName = WrappedChatComponent.fromText(evt2.getPrefix()+obj.get("text")); } catch (ParseException e) {
} else e.printStackTrace();
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));
LGSkinLoadEvent evt = new LGSkinLoadEvent(lgp.getGame(), lgp, player, data.getProfile()); } else
Bukkit.getPluginManager().callEvent(evt); datas.add(data);
datas.add(new PlayerInfoData(evt.getProfile(), data.getLatency(), data.getGameMode(), displayName)); }
}else info.setData(datas);
datas.add(data); }
} });
info.setData(datas); protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) {
} @Override
}); public void onPacketSending(PacketEvent event) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) { LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
@Override if (player.getGame() != null && player.getGame().isStarted()) {
public void onPacketSending(PacketEvent event) { WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); health.setFood(6);
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) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) { LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
@Override WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket());
public void onPacketSending(PacketEvent event) { team.setColor(ChatColor.WHITE);
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); Player other = Bukkit.getPlayer(team.getName());
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket()); if (other == null) return;
team.setColor(ChatColor.WHITE); LGPlayer lgp = LGPlayer.thePlayer(instance, other);
Player other = Bukkit.getPlayer(team.getName()); if (player.getGame() != null && player.getGame() == lgp.getGame()) {
if(other == null)return; LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
LGPlayer lgp = LGPlayer.thePlayer(instance, other); Bukkit.getPluginManager().callEvent(evt2);
if(player.getGame() != null && player.getGame() == lgp.getGame()) { if (evt2.getPrefix().length() > 0)
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); team.setPrefix(WrappedChatComponent.fromText(evt2.getPrefix()));
Bukkit.getPluginManager().callEvent(evt2); else
if(evt2.getPrefix().length() > 0) team.setPrefix(WrappedChatComponent.fromText("§f"));
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) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) { LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
@Override if (player.getGame() != null) {
public void onPacketSending(PacketEvent event) { WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer()); if (equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId())
if(player.getGame() != null) { equip.setItem(new ItemStack(Material.AIR));
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) {
@SuppressWarnings("unchecked") if (label.equalsIgnoreCase("ww")) {
@Override if (!sender.hasPermission("loupgarou.admin")) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(prefix + "§4Erreur: Vous n'avez pas la permission...");
if(label.equalsIgnoreCase("ww")) { return true;
if(!sender.hasPermission("loupgarou.admin")) { }
sender.sendMessage(prefix+"§4Erreur: Vous n'avez pas la permission..."); if (args.length >= 1) {
return true; if (args[0].equalsIgnoreCase("addspawn")) {
} Player player = (Player) sender;
if(args.length >= 1) { Location loc = player.getLocation();
if(args[0].equalsIgnoreCase("addspawn")) { List<Object> list = (List<Object>) getConfig().getList("spawns");
Player player = (Player)sender; list.add(Arrays.asList((double) loc.getBlockX(), loc.getY(), (double) loc.getBlockZ(), (double) loc.getYaw(), (double) loc.getPitch()));
Location loc = player.getLocation(); saveConfig();
List<Object> list = (List<Object>) getConfig().getList("spawns"); loadConfig();
list.add(Arrays.asList((double)loc.getBlockX(), loc.getY(), (double)loc.getBlockZ(), (double)loc.getYaw(), (double)loc.getPitch())); sender.sendMessage(prefix + "§aLa position a bien été ajoutée !");
saveConfig(); return true;
loadConfig(); } else if (args[0].equalsIgnoreCase("end")) {
sender.sendMessage(prefix+"§aLa position a bien été ajoutée !"); if (args.length != 2) {
return true; sender.sendMessage("§4Utilisation : §c/lg end <pseudo>");
}else if(args[0].equalsIgnoreCase("end")) { return true;
if(args.length != 2) { }
sender.sendMessage("§4Utilisation : §c/lg end <pseudo>"); Player selected = Bukkit.getPlayer(args[1]);
return true; if (selected == null) {
} sender.sendMessage("§4Erreur : §cLe joueur §4" + args[1] + "§c n'est pas connecté.");
Player selected = Bukkit.getPlayer(args[1]); return true;
if(selected == null) { }
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'est pas connecté."); LGGame game = LGPlayer.thePlayer(instance, selected).getGame();
return true; if (game == null) {
} sender.sendMessage("§4Erreur : §cLe joueur §4" + selected.getName() + "§c n'est pas dans une partie.");
LGGame game = LGPlayer.thePlayer(instance, selected).getGame(); return true;
if(game == null) { }
sender.sendMessage("§4Erreur : §cLe joueur §4"+selected.getName()+"§c n'est pas dans une partie."); game.cancelWait();
return true; game.endGame(LGWinType.EQUAL);
} game.broadcastMessage("§cLa partie a été arrêtée de force !");
game.cancelWait(); return true;
game.endGame(LGWinType.EQUAL); } else if (args[0].equalsIgnoreCase("start")) {
game.broadcastMessage("§cLa partie a été arrêtée de force !"); if (args.length < 2) {
return true; sender.sendMessage("§4Utilisation : §c/lg start <pseudo>");
}else if(args[0].equalsIgnoreCase("start")) { return true;
if(args.length < 2) { }
sender.sendMessage("§4Utilisation : §c/lg start <pseudo>"); Player player = Bukkit.getPlayer(args[1]);
return true; if (player == null) {
} sender.sendMessage("§4Erreur : §cLe joueur §4" + args[1] + "§c n'existe pas !");
Player player = Bukkit.getPlayer(args[1]); return true;
if(player == null) { }
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !"); LGPlayer lgp = LGPlayer.thePlayer(instance, player);
return true; if (lgp.getGame() == null) {
} sender.sendMessage("§4Erreur : §cLe joueur §4" + lgp.getName() + "§c n'est pas dans une partie.");
LGPlayer lgp = LGPlayer.thePlayer(instance, player); return true;
if(lgp.getGame() == null) { }
sender.sendMessage("§4Erreur : §cLe joueur §4"+lgp.getName()+"§c n'est pas dans une partie."); if (MainLg.getInstance().getConfig().getList("spawns").size() < lgp.getGame().getMaxPlayers()) {
return true; sender.sendMessage("§4Erreur : §cIl n'y a pas assez de points de spawn !");
} sender.sendMessage("§8§oPour les définir, merci de faire §7/lg addSpawn");
if(MainLg.getInstance().getConfig().getList("spawns").size() < lgp.getGame().getMaxPlayers()) { return true;
sender.sendMessage("§4Erreur : §cIl n'y a pas assez de points de spawn !"); }
sender.sendMessage("§8§oPour les définir, merci de faire §7/lg addSpawn"); sender.sendMessage("§aVous avez bien démarré une nouvelle partie !");
return true; lgp.getGame().updateStart();
} return true;
sender.sendMessage("§aVous avez bien démarré une nouvelle partie !"); } else if (args[0].equalsIgnoreCase("reloadconfig")) {
lgp.getGame().updateStart(); sender.sendMessage("§aVous avez bien reload la config !");
return true; sender.sendMessage("§7§oSi vous avez changé les rôles, écriver §8§o/lg joinall§7§o !");
}else if(args[0].equalsIgnoreCase("reloadconfig")) { loadConfig();
sender.sendMessage("§aVous avez bien reload la config !"); return true;
sender.sendMessage("§7§oSi vous avez changé les rôles, écriver §8§o/lg joinall§7§o !"); } else if (args[0].equalsIgnoreCase("joinall")) {
loadConfig(); for (Player p : Bukkit.getOnlinePlayers())
return true; Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "joinall"));
}else if(args[0].equalsIgnoreCase("joinall")) { for (Player p : Bukkit.getOnlinePlayers())
for(Player p : Bukkit.getOnlinePlayers()) Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "joinall"));
Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "joinall")); return true;
for(Player p : Bukkit.getOnlinePlayers()) } else if (args[0].equalsIgnoreCase("reloadPacks")) {
Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "joinall")); for (Player p : Bukkit.getOnlinePlayers())
return true; Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "reloadPacks"));
}else if(args[0].equalsIgnoreCase("reloadPacks")) { for (Player p : Bukkit.getOnlinePlayers())
for(Player p : Bukkit.getOnlinePlayers()) Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "reloadPacks"));
Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(p, "reloadPacks")); return true;
for(Player p : Bukkit.getOnlinePlayers()) } else if (args[0].equalsIgnoreCase("nextNight")) {
Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(p, "reloadPacks")); sender.sendMessage("§aVous êtes passé à la prochaine nuit");
return true; if (getCurrentGame() != null) {
}else if(args[0].equalsIgnoreCase("nextNight")) { getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine nuit a été forcé !");
sender.sendMessage("§aVous êtes passé à la prochaine nuit"); for (LGPlayer lgp : getCurrentGame().getInGame())
if(getCurrentGame() != null) { lgp.stopChoosing();
getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine nuit a été forcé !"); getCurrentGame().cancelWait();
for(LGPlayer lgp : getCurrentGame().getInGame()) getCurrentGame().nextNight();
lgp.stopChoosing(); }
getCurrentGame().cancelWait(); return true;
getCurrentGame().nextNight(); } else if (args[0].equalsIgnoreCase("nextDay")) {
} sender.sendMessage("§aVous êtes passé à la prochaine journée");
return true; if (getCurrentGame() != null) {
}else if(args[0].equalsIgnoreCase("nextDay")) { getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine journée a été forcé !");
sender.sendMessage("§aVous êtes passé à la prochaine journée"); getCurrentGame().cancelWait();
if(getCurrentGame() != null) { for (LGPlayer lgp : getCurrentGame().getInGame())
getCurrentGame().broadcastMessage("§2§lLe passage à la prochaine journée a été forcé !"); lgp.stopChoosing();
getCurrentGame().cancelWait(); getCurrentGame().endNight();
for(LGPlayer lgp : getCurrentGame().getInGame()) }
lgp.stopChoosing(); return true;
getCurrentGame().endNight(); } else if (args[0].equalsIgnoreCase("roles")) {
} if (args.length == 1 || args[1].equalsIgnoreCase("list")) {
return true; sender.sendMessage(prefix + "§6Voici la liste des rôles:");
}else if(args[0].equalsIgnoreCase("roles")) { int index = 0;
if(args.length == 1 || args[1].equalsIgnoreCase("list")) { for (String role : getRoles().keySet())
sender.sendMessage(prefix+"§6Voici la liste des rôles:"); sender.sendMessage(prefix + " §e- " + index++ + " - §6" + role + " §e> " + MainLg.getInstance().getConfig().getInt("role." + role));
int index = 0; sender.sendMessage("\n" + prefix + " §7Écrivez §8§o/lg roles set <role_id/role_name> <nombre>§7 pour définir le nombre de joueurs qui devrons avoir ce rôle.");
for(String role : getRoles().keySet()) } else {
sender.sendMessage(prefix+" §e- "+index+++" - §6"+role+" §e> "+MainLg.getInstance().getConfig().getInt("role."+role)); if (args[1].equalsIgnoreCase("set") && args.length == 4) {
sender.sendMessage("\n"+prefix+" §7Écrivez §8§o/lg roles set <role_id/role_name> <nombre>§7 pour définir le nombre de joueurs qui devrons avoir ce rôle."); String role = null;
} else { if (args[2].length() <= 2)
if(args[1].equalsIgnoreCase("set") && args.length == 4) { try {
String role = null; int i = Integer.parseInt(args[2]);
if(args[2].length() <= 2) Object[] array = getRoles().keySet().toArray();
try { if (array.length <= i) {
int i = Integer.parseInt(args[2]); sender.sendMessage(prefix + "§4Erreur: §cCe rôle n'existe pas.");
Object[] array = getRoles().keySet().toArray(); return true;
if(array.length <= i) { } else
sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas."); role = (String) array[i];
return true; } catch (Exception err) {
}else sender.sendMessage(prefix + "§4Erreur: §cCeci n'est pas un nombre");
role = (String)array[i]; }
}catch(Exception err) {sender.sendMessage(prefix+"§4Erreur: §cCeci n'est pas un nombre");} else
else role = args[2];
role = args[2];
if (role != null) {
if(role != null) { String real_role = null;
String real_role = null; for (String real : getRoles().keySet())
for(String real : getRoles().keySet()) if (real.equalsIgnoreCase(role)) {
if(real.equalsIgnoreCase(role)) { real_role = real;
real_role = real; break;
break; }
}
if (real_role != null) {
if(real_role != null) { try {
try { MainLg.getInstance().getConfig().set("role." + real_role, Integer.valueOf(args[3]));
MainLg.getInstance().getConfig().set("role."+real_role, Integer.valueOf(args[3])); sender.sendMessage(prefix + "§6Il y aura §e" + args[3] + " §6" + real_role);
sender.sendMessage(prefix+"§6Il y aura §e"+args[3]+" §6"+real_role); saveConfig();
saveConfig(); loadConfig();
loadConfig(); sender.sendMessage("§7§oSi vous avez fini de changer les rôles, écriver §8§o/lg joinall§7§o !");
sender.sendMessage("§7§oSi vous avez fini de changer les rôles, écriver §8§o/lg joinall§7§o !"); } catch (Exception err) {
}catch(Exception err) { sender.sendMessage(prefix + "§4Erreur: §c" + args[3] + " n'est pas un nombre");
sender.sendMessage(prefix+"§4Erreur: §c"+args[3]+" n'est pas un nombre"); }
} return true;
return true; }
} }
} sender.sendMessage(prefix + "§4Erreur: §cLe rôle que vous avez entré est incorrect");
sender.sendMessage(prefix+"§4Erreur: §cLe rôle que vous avez entré est incorrect");
} else {
} else { sender.sendMessage(prefix + "§4Erreur: §cCommande incorrecte.");
sender.sendMessage(prefix+"§4Erreur: §cCommande incorrecte."); sender.sendMessage(prefix + "§4Essayez §c/lg roles set <role_id/role_name> <nombre>§4 ou §c/lg roles list");
sender.sendMessage(prefix+"§4Essayez §c/lg roles set <role_id/role_name> <nombre>§4 ou §c/lg roles list"); }
} }
} return true;
return true; }
} }
} sender.sendMessage(prefix + "§4Erreur: §cCommande incorrecte.");
sender.sendMessage(prefix+"§4Erreur: §cCommande incorrecte."); sender.sendMessage(prefix + "§4Essayez /lg §caddSpawn/end/start/nextNight/nextDay/reloadConfig/roles/reloadPacks/joinAll");
sender.sendMessage(prefix+"§4Essayez /lg §caddSpawn/end/start/nextNight/nextDay/reloadConfig/roles/reloadPacks/joinAll"); return true;
return true; }
} return false;
return false; }
}
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if(!sender.hasPermission("loupgarou.admin")) if (!sender.hasPermission("loupgarou.admin"))
return new ArrayList<>(0); return new ArrayList<>(0);
if(args.length > 1) { if (args.length > 1) {
if(args[0].equalsIgnoreCase("roles")) if (args[0].equalsIgnoreCase("roles"))
if(args.length == 2) if (args.length == 2)
return getStartingList(args[1], "list", "set"); return getStartingList(args[1], "list", "set");
else if(args.length == 3 && args[1].equalsIgnoreCase("set")) else if (args.length == 3 && args[1].equalsIgnoreCase("set"))
return getStartingList(args[2], getRoles().keySet().toArray(new String[getRoles().size()])); return getStartingList(args[2], getRoles().keySet().toArray(new String[getRoles().size()]));
else if(args.length == 4) else if (args.length == 4)
return Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); return Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
}else if(args.length == 1) } else if (args.length == 1)
return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks"); return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks");
return new ArrayList<>(0); return new ArrayList<>(0);
} }
private List<String> getStartingList(String startsWith, String... list){
startsWith = startsWith.toLowerCase(); private List<String> getStartingList(String startsWith, String... list) {
ArrayList<String> returnlist = new ArrayList<>(); startsWith = startsWith.toLowerCase();
if(startsWith.length() == 0) ArrayList<String> returnlist = new ArrayList<>();
return Arrays.asList(list); if (startsWith.length() == 0)
for(String s : list) return Arrays.asList(list);
if(s.toLowerCase().startsWith(startsWith)) for (String s : list)
returnlist.add(s); if (s.toLowerCase().startsWith(startsWith))
return returnlist; returnlist.add(s);
} return returnlist;
public void loadConfig() { }
int players = 0;
for(String role : roles.keySet()) public void loadConfig() {
players += getConfig().getInt("role."+role); int players = 0;
currentGame = new LGGame(this, players); for (String role : roles.keySet())
} players += getConfig().getInt("role." + role);
@Override currentGame = new LGGame(this, players);
public void onDisable() { }
ProtocolLibrary.getProtocolManager().removePacketListeners(this);
} @Override
public static MainLg getInstance() { public void onDisable() {
return instance; ProtocolLibrary.getProtocolManager().removePacketListeners(this);
} }
private void loadRoles() {
try { private void loadRoles() {
roles.put("LoupGarou", RLoupGarou.class.getConstructor(LGGame.class)); try {
roles.put("LoupGarouNoir", RLoupGarouNoir.class.getConstructor(LGGame.class)); roles.put("LoupGarou", RLoupGarou.class.getConstructor(LGGame.class));
roles.put("Garde", RGarde.class.getConstructor(LGGame.class)); roles.put("LoupGarouNoir", RLoupGarouNoir.class.getConstructor(LGGame.class));
roles.put("Sorciere", RSorciere.class.getConstructor(LGGame.class)); roles.put("Garde", RGarde.class.getConstructor(LGGame.class));
roles.put("Voyante", RVoyante.class.getConstructor(LGGame.class)); roles.put("Sorciere", RSorciere.class.getConstructor(LGGame.class));
roles.put("Chasseur", RChasseur.class.getConstructor(LGGame.class)); roles.put("Voyante", RVoyante.class.getConstructor(LGGame.class));
roles.put("Villageois", RVillageois.class.getConstructor(LGGame.class)); roles.put("Chasseur", RChasseur.class.getConstructor(LGGame.class));
roles.put("Medium", RMedium.class.getConstructor(LGGame.class)); roles.put("Villageois", RVillageois.class.getConstructor(LGGame.class));
roles.put("Dictateur", RDictateur.class.getConstructor(LGGame.class)); roles.put("Medium", RMedium.class.getConstructor(LGGame.class));
roles.put("Cupidon", RCupidon.class.getConstructor(LGGame.class)); roles.put("Dictateur", RDictateur.class.getConstructor(LGGame.class));
roles.put("PetiteFille", RPetiteFille.class.getConstructor(LGGame.class)); roles.put("Cupidon", RCupidon.class.getConstructor(LGGame.class));
roles.put("ChaperonRouge", RChaperonRouge.class.getConstructor(LGGame.class)); roles.put("PetiteFille", RPetiteFille.class.getConstructor(LGGame.class));
roles.put("LoupGarouBlanc", RLoupGarouBlanc.class.getConstructor(LGGame.class)); roles.put("ChaperonRouge", RChaperonRouge.class.getConstructor(LGGame.class));
roles.put("Bouffon", RBouffon.class.getConstructor(LGGame.class)); roles.put("LoupGarouBlanc", RLoupGarouBlanc.class.getConstructor(LGGame.class));
roles.put("Ange", RAnge.class.getConstructor(LGGame.class)); roles.put("Bouffon", RBouffon.class.getConstructor(LGGame.class));
roles.put("Survivant", RSurvivant.class.getConstructor(LGGame.class)); roles.put("Ange", RAnge.class.getConstructor(LGGame.class));
roles.put("Assassin", RAssassin.class.getConstructor(LGGame.class)); roles.put("Survivant", RSurvivant.class.getConstructor(LGGame.class));
roles.put("GrandMechantLoup", RGrandMechantLoup.class.getConstructor(LGGame.class)); roles.put("Assassin", RAssassin.class.getConstructor(LGGame.class));
roles.put("Corbeau", RCorbeau.class.getConstructor(LGGame.class)); roles.put("GrandMechantLoup", RGrandMechantLoup.class.getConstructor(LGGame.class));
roles.put("Detective", RDetective.class.getConstructor(LGGame.class)); roles.put("Corbeau", RCorbeau.class.getConstructor(LGGame.class));
roles.put("ChienLoup", RChienLoup.class.getConstructor(LGGame.class)); roles.put("Detective", RDetective.class.getConstructor(LGGame.class));
roles.put("Pirate", RPirate.class.getConstructor(LGGame.class)); roles.put("ChienLoup", RChienLoup.class.getConstructor(LGGame.class));
roles.put("Pyromane", RPyromane.class.getConstructor(LGGame.class)); roles.put("Pirate", RPirate.class.getConstructor(LGGame.class));
roles.put("Pretre", RPretre.class.getConstructor(LGGame.class)); roles.put("Pyromane", RPyromane.class.getConstructor(LGGame.class));
roles.put("Faucheur", RFaucheur.class.getConstructor(LGGame.class)); roles.put("Pretre", RPretre.class.getConstructor(LGGame.class));
roles.put("EnfantSauvage", REnfantSauvage.class.getConstructor(LGGame.class)); roles.put("Faucheur", RFaucheur.class.getConstructor(LGGame.class));
roles.put("MontreurDOurs", RMontreurDOurs.class.getConstructor(LGGame.class)); roles.put("EnfantSauvage", REnfantSauvage.class.getConstructor(LGGame.class));
roles.put("Vampire", RVampire.class.getConstructor(LGGame.class)); roles.put("MontreurDOurs", RMontreurDOurs.class.getConstructor(LGGame.class));
roles.put("ChasseurDeVampire", RChasseurDeVampire.class.getConstructor(LGGame.class)); roles.put("Vampire", RVampire.class.getConstructor(LGGame.class));
} catch (NoSuchMethodException | SecurityException e) { roles.put("ChasseurDeVampire", RChasseurDeVampire.class.getConstructor(LGGame.class));
e.printStackTrace(); } catch (NoSuchMethodException | SecurityException e) {
} e.printStackTrace();
} }
}
} }

View file

@ -6,9 +6,12 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class IndexedRole { public class IndexedRole {
@Getter private final Role role; @Getter
@Getter private int number = 1; private final Role role;
public void increase() { @Getter
number++; private int number = 1;
}
public void increase() {
number++;
}
} }

File diff suppressed because one or more lines are too long

View file

@ -1,14 +1,14 @@
package fr.leomelki.loupgarou.classes; package fr.leomelki.loupgarou.classes;
import com.comphenix.protocol.wrappers.WrappedSignedProperty; import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public enum LGCustomSkin { 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=")), 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")), 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=")); 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; @Getter
private final WrappedSignedProperty property;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,22 +1,11 @@
package fr.leomelki.loupgarou.classes; package fr.leomelki.loupgarou.classes;
import java.util.*;
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.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction;
import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerChat; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerChat;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam;
@ -37,336 +26,373 @@ import net.minecraft.server.v1_15_R1.DimensionManager;
import net.minecraft.server.v1_15_R1.EnumGamemode; import net.minecraft.server.v1_15_R1.EnumGamemode;
import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn;
import net.minecraft.server.v1_15_R1.WorldType; import net.minecraft.server.v1_15_R1.WorldType;
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 java.util.*;
public class LGPlayer { public class LGPlayer {
private static final HashMap<Player, LGPlayer> cachedPlayers = new HashMap<>(); private static final HashMap<Player, LGPlayer> cachedPlayers = new HashMap<>();
private final MainLg plugin; private final MainLg plugin;
@Getter
private final VariableCache cache = new VariableCache();
public boolean canSelectDead;
@Getter
boolean muted;
long lastChoose;
@Getter
@Setter
private int place;
@Getter
private Player player;
@Getter
@Setter
private boolean dead;
@Setter
@Getter
private Role role;
private LGChooseCallback chooseCallback;
private List<LGPlayer> blacklistedChoice = new ArrayList<>(0);
@Getter
@Setter
private LGGame game;
@Getter
@Setter
private String latestObjective;
@Getter
private CustomScoreboard scoreboard;
private String name;
@Getter
private LGChat chat;
public static LGPlayer thePlayer(MainLg plugin, Player player) { public LGPlayer(MainLg mainLg, Player player) {
LGPlayer lgp = cachedPlayers.get(player); this.plugin = mainLg;
if(lgp == null) { this.player = player;
lgp = new LGPlayer(plugin, player); }
cachedPlayers.put(player, lgp);
} public LGPlayer(MainLg mainLg, String name) {
return lgp; this.plugin = mainLg;
} this.name = name;
public static LGPlayer removePlayer(Player player) { }
return cachedPlayers.remove(player);//.remove();
} public static LGPlayer thePlayer(MainLg plugin, Player player) {
@Getter @Setter private int place; LGPlayer lgp = cachedPlayers.get(player);
@Getter private Player player; if (lgp == null) {
@Getter @Setter private boolean dead; lgp = new LGPlayer(plugin, player);
@Setter @Getter private Role role; cachedPlayers.put(player, lgp);
private LGChooseCallback chooseCallback; }
private List<LGPlayer> blacklistedChoice = new ArrayList<>(0); return lgp;
@Getter private final VariableCache cache = new VariableCache(); }
@Getter @Setter private LGGame game;
@Getter @Setter private String latestObjective; public static LGPlayer removePlayer(Player player) {
@Getter private CustomScoreboard scoreboard; return cachedPlayers.remove(player);//.remove();
public LGPlayer(MainLg mainLg, Player player) { }
this.plugin = mainLg;
this.player = player; public void setScoreboard(CustomScoreboard scoreboard) {
} if (player != null) {
public LGPlayer(MainLg mainLg, String name) { if (this.scoreboard != null)
this.plugin = mainLg; this.scoreboard.hide();
this.name = name;
} this.scoreboard = scoreboard;
public void setScoreboard(CustomScoreboard scoreboard) { if (scoreboard != null)
if(player != null) { scoreboard.show();
if(this.scoreboard != null) }
this.scoreboard.hide(); }
this.scoreboard = scoreboard; public void sendActionBarMessage(String msg) {
if (this.player != null) {
if(scoreboard != null) WrapperPlayServerChat chat = new WrapperPlayServerChat();
scoreboard.show(); chat.setPosition((byte) 2);
} chat.setMessage(WrappedChatComponent.fromText(msg));
} chat.sendPacket(getPlayer());
}
public void sendActionBarMessage(String msg) { }
if(this.player != null) {
WrapperPlayServerChat chat = new WrapperPlayServerChat(); public void sendMessage(String msg) {
chat.setPosition((byte)2); if (this.player != null)
chat.setMessage(WrappedChatComponent.fromText(msg)); getPlayer().sendMessage(MainLg.getPrefix() + msg);
chat.sendPacket(getPlayer()); }
}
} public void sendTitle(String title, String subTitle, int stay) {
public void sendMessage(String msg) { if (this.player != null) {
if(this.player != null) WrapperPlayServerTitle titlePacket = new WrapperPlayServerTitle();
getPlayer().sendMessage(MainLg.getPrefix()+msg); titlePacket.setAction(TitleAction.TIMES);
} titlePacket.setFadeIn(10);
public void sendTitle(String title, String subTitle, int stay) { titlePacket.setStay(stay);
if(this.player != null) { titlePacket.setFadeOut(10);
WrapperPlayServerTitle titlePacket = new WrapperPlayServerTitle(); titlePacket.sendPacket(player);
titlePacket.setAction(TitleAction.TIMES);
titlePacket.setFadeIn(10); titlePacket = new WrapperPlayServerTitle();
titlePacket.setStay(stay); titlePacket.setAction(TitleAction.TITLE);
titlePacket.setFadeOut(10); titlePacket.setTitle(WrappedChatComponent.fromText(title));
titlePacket.sendPacket(player); titlePacket.sendPacket(player);
titlePacket = new WrapperPlayServerTitle(); titlePacket = new WrapperPlayServerTitle();
titlePacket.setAction(TitleAction.TITLE); titlePacket.setAction(TitleAction.SUBTITLE);
titlePacket.setTitle(WrappedChatComponent.fromText(title)); titlePacket.setTitle(WrappedChatComponent.fromText(subTitle));
titlePacket.sendPacket(player); titlePacket.sendPacket(player);
}
titlePacket = new WrapperPlayServerTitle(); }
titlePacket.setAction(TitleAction.SUBTITLE);
titlePacket.setTitle(WrappedChatComponent.fromText(subTitle)); public void remove() {
titlePacket.sendPacket(player); this.player = null;
} }
}
public void remove() { public String getName() {
this.player = null; return player != null ? getPlayer().getName() : name;
} }
private String name;
public String getName() { public boolean join(LGGame game) {
return player != null ? getPlayer().getName() : name; 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 void showView() {
if (getGame() != null && player != null)
for (LGPlayer lgp : getGame().getAlive())
if (!lgp.isDead()) {
if (lgp != this && lgp.getPlayer() != null)
getPlayer().showPlayer(plugin, lgp.getPlayer());
else {
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setMode(2);
team.setName(lgp.getName());
team.setPrefix(WrappedChatComponent.fromText(""));
team.setPlayers(Collections.singletonList(lgp.getName()));
team.sendPacket(getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> 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<String> meList = Collections.singletonList(getName());
for (LGPlayer lgp : getGame().getInGame()) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> 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<PlayerInfoData> 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(plugin, 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<PlayerInfoData> 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(plugin, getPlayer());
lgp.getPlayer().showPlayer(plugin, 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(Collections.singletonList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName()))));
infos.sendPacket(getPlayer());
//Pour qu'il voit son skin changer (sa main et en f5), on lui dit qu'il respawn (alors qu'il n'est pas mort mais ça marche quand même mdr)
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(DimensionManager.OVERWORLD, 0, WorldType.NORMAL, EnumGamemode.ADVENTURE);
((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 LGPlayer getPlayerOnCursor(List<LGPlayer> list) {
Location loc = getPlayer().getLocation();
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) {
return player;
}
}
}
return null;
}
public RoleType getRoleType() {
return this.getCache().getBoolean("vampire") ? RoleType.VAMPIRE : this.getCache().getBoolean("infected") ? RoleType.LOUP_GAROU : getRole().getType(this);
}
public RoleWinType getRoleWinType() {
return this.getCache().getBoolean("vampire") ? RoleWinType.VAMPIRE : this.getCache().getBoolean("infected") ? RoleWinType.LOUP_GAROU : getRole().getWinType(this);
}
public boolean isRoleActive() {
return !this.getCache().getBoolean("vampire");
}
public void die() {
setMuted();
}
private void setMuted() {
if (player != null)
for (LGPlayer lgp : getGame().getInGame())
if (lgp != this && lgp.getPlayer() != null)
lgp.getPlayer().hidePlayer(plugin, getPlayer());
muted = true;
}
public void resetMuted() {
muted = false;
}
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 boolean join(LGGame game) { public void leaveChat() {
if(getPlayer().getGameMode() == GameMode.SPECTATOR) { joinChat(new LGNoChat(), null);
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 interface LGChooseCallback{
void callback(LGPlayer choosen);
}
public void showView() { public void onChat(String message) {
if(getGame() != null && player != null) if (chat != null) {
for(LGPlayer lgp : getGame().getAlive()) chat.sendMessage(this, message);
if(!lgp.isDead()) { }
if(lgp != this && lgp.getPlayer() != null) }
getPlayer().showPlayer(plugin, lgp.getPlayer());
else{
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setMode(2);
team.setName(lgp.getName());
team.setPrefix(WrappedChatComponent.fromText(""));
team.setPlayers(Collections.singletonList(lgp.getName()));
team.sendPacket(getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> 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<String> meList = Collections.singletonList(getName());
for(LGPlayer lgp : getGame().getInGame()) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> 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(); public void playAudio(LGSound sound, double volume) {
team.setMode(2); if (player != null)
team.setName(getName()); getPlayer().playSound(getPlayer().getLocation(), sound.getSound(), (float) volume, 1);
team.setPrefix(WrappedChatComponent.fromText("")); }
team.setPlayers(meList);
team.sendPacket(lgp.getPlayer());
}
}
}
public void hideView() {
if(getGame() != null && player != null) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> 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(plugin, lgp.getPlayer());
}
info.setData(infos);
info.sendPacket(getPlayer());
}
getPlayer().removePotionEffect(PotionEffectType.BLINDNESS); public void stopAudio(LGSound sound) {
getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 999999, 1, false, false)); if (player != null)
} getPlayer().stopSound(sound.getSound());
}
public void updateSkin() {
if(getGame() != null && player != null) { public void chooseAction() {
for(LGPlayer lgp : getGame().getInGame()) { long now = System.currentTimeMillis();
if(lgp == this) { if (lastChoose + 200 < now) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); if (chooseCallback != null)
ArrayList<PlayerInfoData> infos = new ArrayList<>(); chooseCallback.callback(getPlayerOnCursor(getGame().getInGame()));
info.setAction(PlayerInfoAction.ADD_PLAYER); lastChoose = now;
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){ @Override
lgp.getPlayer().hidePlayer(plugin, getPlayer()); public String toString() {
lgp.getPlayer().showPlayer(plugin, getPlayer()); return super.toString() + " (" + getName() + ")";
} }
}
} public interface LGChooseCallback {
} void callback(LGPlayer choosen);
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(Collections.singletonList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName()))));
infos.sendPacket(getPlayer());
//Pour qu'il voit son skin changer (sa main et en f5), on lui dit qu'il respawn (alors qu'il n'est pas mort mais ça marche quand même mdr)
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(DimensionManager.OVERWORLD, 0, WorldType.NORMAL, EnumGamemode.ADVENTURE);
((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<LGPlayer> list) {
Location loc = getPlayer().getLocation();
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) {
return player;
}
}
}
return null;
}
public RoleType getRoleType() {
return this.getCache().getBoolean("vampire") ? RoleType.VAMPIRE : this.getCache().getBoolean("infected") ? RoleType.LOUP_GAROU : getRole().getType(this);
}
public RoleWinType getRoleWinType() {
return this.getCache().getBoolean("vampire") ? RoleWinType.VAMPIRE : this.getCache().getBoolean("infected") ? RoleWinType.LOUP_GAROU : getRole().getWinType(this);
}
public boolean isRoleActive() {
return !this.getCache().getBoolean("vampire");
}
@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(plugin, getPlayer());
muted = true;
}
public void resetMuted() {
muted = false;
}
@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);
}
}
public void playAudio(LGSound sound, double volume) {
if(player != null)
getPlayer().playSound(getPlayer().getLocation(), sound.getSound(), (float)volume, 1);
}
public void stopAudio(LGSound sound) {
if(player != null)
getPlayer().stopSound(sound.getSound());
}
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()+")";
}
} }

View file

@ -1,19 +1,19 @@
package fr.leomelki.loupgarou.classes; package fr.leomelki.loupgarou.classes;
import lombok.Getter;
import org.bukkit.Sound; import org.bukkit.Sound;
import lombok.Getter;
public enum LGSound { public enum LGSound {
KILL(Sound.ENTITY_BLAZE_DEATH), KILL(Sound.ENTITY_BLAZE_DEATH),
START_NIGHT(Sound.ENTITY_SKELETON_DEATH), START_NIGHT(Sound.ENTITY_SKELETON_DEATH),
START_DAY(Sound.ENTITY_ZOMBIE_DEATH), START_DAY(Sound.ENTITY_ZOMBIE_DEATH),
AMBIANT_NIGHT(Sound.MUSIC_DISC_MALL), AMBIANT_NIGHT(Sound.MUSIC_DISC_MALL),
AMBIANT_DAY(Sound.MUSIC_DISC_MELLOHI); AMBIANT_DAY(Sound.MUSIC_DISC_MELLOHI);
@Getter @Getter
final Sound sound; final Sound sound;
LGSound(Sound sound){
this.sound = sound; LGSound(Sound sound) {
} this.sound = sound;
}
} }

View file

@ -1,9 +1,17 @@
package fr.leomelki.loupgarou.classes; package fr.leomelki.loupgarou.classes;
import java.lang.reflect.Field; import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import java.util.*; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import java.util.Map.Entry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import fr.leomelki.com.comphenix.packetwrapper.*;
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.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -13,336 +21,336 @@ import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; import java.lang.reflect.Field;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import java.util.*;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import java.util.Map.Entry;
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.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 { public class LGVote {
@Getter LGPlayer choosen; private static final EntityArmorStand eas = new EntityArmorStand(((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(), 0, 0, 0);
private int timeout;
private final int initialTimeout;
private final int littleTimeout;
private Runnable callback;
private final LGGame game;
@Getter private List<LGPlayer> participants, viewers;
private final TextGenerator generator;
@Getter private final HashMap<LGPlayer, List<LGPlayer>> votes = new HashMap<>();
private int votesSize = 0;
private LGPlayer mayor;
private ArrayList<LGPlayer> latestTop = new ArrayList<>(), blacklisted = new ArrayList<>();
private final boolean randomIfEqual;
@Getter private boolean mayorVote;
private boolean ended;
public LGVote(int timeout, int littleTimeout, LGGame game, boolean positiveVote, boolean randomIfEqual, TextGenerator generator) {
this.littleTimeout = littleTimeout;
this.initialTimeout = timeout;
this.timeout = timeout;
this.game = game;
this.generator = generator;
this.randomIfEqual = randomIfEqual;
}
public void start(List<LGPlayer> participants, List<LGPlayer> 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<LGPlayer> participants, List<LGPlayer> viewers, Runnable callback, ArrayList<LGPlayer> blacklisted) {
this.callback = callback;
this.participants = participants;
this.viewers = viewers;
game.wait(timeout, this::end, generator);
for(LGPlayer player : participants)
player.choose(getChooseCallback(player));
this.blacklisted = blacklisted;
}
public void start(List<LGPlayer> participants, List<LGPlayer> 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<Optional<IChatBaseComponent>> az; private static DataWatcherObject<Optional<IChatBaseComponent>> az;
private static DataWatcherObject<Boolean> aA; private static DataWatcherObject<Boolean> aA;
private static DataWatcherObject<Byte> T; private static DataWatcherObject<Byte> T;
private static final EntityArmorStand eas = new EntityArmorStand(((CraftWorld)Bukkit.getWorlds().get(0)).getHandle(), 0, 0, 0);
static { static {
try { try {
Field f = Entity.class.getDeclaredField("az"); Field f = Entity.class.getDeclaredField("az");
f.setAccessible(true); f.setAccessible(true);
az = (DataWatcherObject<Optional<IChatBaseComponent>>) f.get(null); az = (DataWatcherObject<Optional<IChatBaseComponent>>) f.get(null);
f = Entity.class.getDeclaredField("aA"); f = Entity.class.getDeclaredField("aA");
f.setAccessible(true); f.setAccessible(true);
aA = (DataWatcherObject<Boolean>) f.get(null); aA = (DataWatcherObject<Boolean>) f.get(null);
f = Entity.class.getDeclaredField("T"); f = Entity.class.getDeclaredField("T");
f.setAccessible(true); f.setAccessible(true);
T = (DataWatcherObject<Byte>) f.get(null); T = (DataWatcherObject<Byte>) f.get(null);
}catch(Exception err) { } catch (Exception err) {
err.printStackTrace(); err.printStackTrace();
} }
} }
private void end() {
ended = true;
for(LGPlayer lgp : viewers)
showVoting(lgp, null);
for(LGPlayer lgp : votes.keySet())
updateVotes(lgp, true);
int max = 0;
boolean equal = false;
for(Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if(entry.getValue().size() > max) {
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<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> 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<LGPlayer> choosable = new ArrayList<>(); final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
for(Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet()) final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
if(entry.getValue().size() == max) private final int initialTimeout;
choosable.add(entry.getKey()); private final int littleTimeout;
private final LGGame game;
for(int i = 0;i<choosable.size();i++) { private final TextGenerator generator;
LGPlayer lgp = choosable.get(i); @Getter
showArrow(mayor, lgp, -mayor.getPlayer().getEntityId()-i); private final HashMap<LGPlayer, List<LGPlayer>> votes = new HashMap<>();
} private final boolean randomIfEqual;
@Getter
StringJoiner sj = new StringJoiner(", "); LGPlayer choosen;
for(int i = 0;i<choosable.size()-1;i++) WrappedDataWatcherObject customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class));
sj.add(choosable.get(0).getName()); WrappedDataWatcherObject customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class));
//mayor.sendTitle("§6C'est à vous de délibérer", "Faut-il tuer "+sj+" ou "+choosable.get(choosable.size()-1).getName()+" ?", 100); WrappedDataWatcherObject item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class));
ArrayList<LGPlayer> blackListed = new ArrayList<>(); private int timeout;
for(LGPlayer player : participants) private Runnable callback;
if(!choosable.contains(player)) @Getter
blackListed.add(player); private List<LGPlayer> participants, viewers;
else { private int votesSize = 0;
VariousUtils.setWarning(player.getPlayer(), true); private LGPlayer mayor;
//player.sendMessage("§4§lVous êtes un des principaux suspects ! Défendez vous !"); private ArrayList<LGPlayer> latestTop = new ArrayList<>(), blacklisted = new ArrayList<>();
//player.sendTitle("§4§lDéfendez vous !", "§cVous êtes l'un des principaux suspects", 100); @Getter
} private boolean mayorVote;
mayorVote = true; private boolean ended;
game.wait(30, ()->{
for(LGPlayer player : participants)
if(choosable.contains(player))
VariousUtils.setWarning(player.getPlayer(), false);
for(int i = 0;i<choosable.size();i++) { public LGVote(int timeout, int littleTimeout, LGGame game, boolean positiveVote, boolean randomIfEqual, TextGenerator generator) {
LGPlayer lgp = choosable.get(i); this.littleTimeout = littleTimeout;
showArrow(mayor, null, -mayor.getPlayer().getEntityId()-i); this.initialTimeout = timeout;
} this.timeout = timeout;
//Choix au hasard d'un joueur si personne n'a été désigné this.game = game;
choosen = choosable.get(game.getRandom().nextInt(choosable.size())); this.generator = generator;
callback.run(); this.randomIfEqual = randomIfEqual;
}, (player, secondsLeft)->{ }
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(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<choosable.size();i++) { public void start(List<LGPlayer> participants, List<LGPlayer> viewers, Runnable callback) {
LGPlayer lgp = choosable.get(i); this.callback = callback;
showArrow(mayor, null, -mayor.getPlayer().getEntityId()-i); this.participants = participants;
} this.viewers = viewers;
game.cancelWait(); game.wait(timeout, this::end, generator);
LGVote.this.choosen = choosen; for (LGPlayer player : participants)
callback.run(); player.choose(getChooseCallback(player));
} }
}
});
} else {
game.cancelWait();
callback.run();
}
}
public LGChooseCallback getChooseCallback(LGPlayer who) {
return choosen -> {
if(choosen != null)
vote(who, choosen);
};
}
public void vote(LGPlayer voter, LGPlayer voted) {
if(blacklisted.contains(voted)) {
voter.sendMessage("§cVous ne pouvez pas votre pour §7§l"+voted.getName()+"§c.");
return;
}
if(voted == voter.getCache().get("vote"))
voted = null;
if(voted != null && voter.getPlayer() != null)
votesSize++;
if(voter.getCache().has("vote"))
votesSize--;
if(votesSize == participants.size() && game.getWaitTicks() > littleTimeout*20) {
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<LGPlayer> 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<>(Collections.singletonList(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<LGPlayer> 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<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if(entry.getValue().size() > max)
max = entry.getValue().size();
ArrayList<LGPlayer> last = latestTop;
latestTop = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> 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(); public void start(List<LGPlayer> participants, List<LGPlayer> viewers, Runnable callback, ArrayList<LGPlayer> blacklisted) {
spawn.setEntityID(entityId); this.callback = callback;
spawn.setType(EntityType.DROPPED_ITEM); this.participants = participants;
//spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(0, (byte)0x20), new WrappedWatchableObject(5, true)))); this.viewers = viewers;
spawn.setX(loc.getX()); game.wait(timeout, this::end, generator);
spawn.setY(loc.getY()+0.3); for (LGPlayer player : participants)
spawn.setZ(loc.getZ()); player.choose(getChooseCallback(player));
this.blacklisted = blacklisted;
int votesNbr = votes.get(voted).size(); }
final int numberOfParticipants = participants.size();
final double votePercentage = ((double)votesNbr / numberOfParticipants) * 100; public void start(List<LGPlayer> participants, List<LGPlayer> viewers, Runnable callback, LGPlayer mayor) {
final String votePercentageFormated = String.format("%.0f%%", votePercentage); this.callback = callback;
final String voteContent = "§6§l" + votesNbr + " / " + numberOfParticipants + "§e vote" + (votesNbr > 1 ? "s" : "") + " (§6§l" + votePercentageFormated + "§e)"; this.participants = participants;
this.viewers = viewers;
this.mayor = mayor;
game.wait(timeout, this::end, generator);
for (LGPlayer player : participants)
player.choose(getChooseCallback(player));
}
private void end() {
ended = true;
for (LGPlayer lgp : viewers)
showVoting(lgp, null);
for (LGPlayer lgp : votes.keySet())
updateVotes(lgp, true);
int max = 0;
boolean equal = false;
for (Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if (entry.getValue().size() > max) {
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<LGPlayer> choosable = new ArrayList<>();
for (Entry<LGPlayer, List<LGPlayer>> 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<LGPlayer> choosable = new ArrayList<>();
for (Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if (entry.getValue().size() == max)
choosable.add(entry.getKey());
for (int i = 0; i < choosable.size(); i++) {
LGPlayer lgp = choosable.get(i);
showArrow(mayor, lgp, -mayor.getPlayer().getEntityId() - i);
}
StringJoiner sj = new StringJoiner(", ");
for (int i = 0; i < choosable.size() - 1; i++)
sj.add(choosable.get(0).getName());
//mayor.sendTitle("§6C'est à vous de délibérer", "Faut-il tuer "+sj+" ou "+choosable.get(choosable.size()-1).getName()+" ?", 100);
ArrayList<LGPlayer> 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 < choosable.size(); i++) {
LGPlayer lgp = choosable.get(i);
showArrow(mayor, null, -mayor.getPlayer().getEntityId() - i);
}
//Choix au hasard d'un joueur si personne n'a été désigné
choosen = choosable.get(game.getRandom().nextInt(choosable.size()));
callback.run();
}, (player, secondsLeft) -> {
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(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 < choosable.size(); i++) {
LGPlayer lgp = choosable.get(i);
showArrow(mayor, null, -mayor.getPlayer().getEntityId() - i);
}
game.cancelWait();
LGVote.this.choosen = choosen;
callback.run();
}
}
});
} else {
game.cancelWait();
callback.run();
}
}
public LGChooseCallback getChooseCallback(LGPlayer who) {
return choosen -> {
if (choosen != null)
vote(who, choosen);
};
}
public void vote(LGPlayer voter, LGPlayer voted) {
if (blacklisted.contains(voted)) {
voter.sendMessage("§cVous ne pouvez pas votre pour §7§l" + voted.getName() + "§c.");
return;
}
if (voted == voter.getCache().get("vote"))
voted = null;
if (voted != null && voter.getPlayer() != null)
votesSize++;
if (voter.getCache().has("vote"))
votesSize--;
if (votesSize == participants.size() && game.getWaitTicks() > littleTimeout * 20) {
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<LGPlayer> 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<>(Collections.singletonList(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<LGPlayer> 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<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if (entry.getValue().size() > max)
max = entry.getValue().size();
ArrayList<LGPlayer> last = latestTop;
latestTop = new ArrayList<>();
for (Entry<LGPlayer, List<LGPlayer>> 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();
final int numberOfParticipants = participants.size();
final double votePercentage = ((double) votesNbr / numberOfParticipants) * 100;
final String votePercentageFormated = String.format("%.0f%%", votePercentage);
final String voteContent = "§6§l" + votesNbr + " / " + numberOfParticipants + "§e vote" + (votesNbr > 1 ? "s" : "") + " (§6§l" + votePercentageFormated + "§e)";
/*WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); /*WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
meta.setEntityID(entityId); 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" : ""))))); 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 datawatcher = new DataWatcher(eas);
datawatcher.register(T, (byte)0x20); datawatcher.register(T, (byte) 0x20);
datawatcher.register(az, Optional.ofNullable(IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + voteContent + "\"}"))); datawatcher.register(az, Optional.ofNullable(IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + voteContent + "\"}")));
datawatcher.register(aA, true); datawatcher.register(aA, true);
PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(entityId, datawatcher, true); PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(entityId, datawatcher, true);
for(LGPlayer lgp : viewers) { for (LGPlayer lgp : viewers) {
spawn.sendPacket(lgp.getPlayer()); spawn.sendPacket(lgp.getPlayer());
((CraftPlayer)lgp.getPlayer()).getHandle().playerConnection.sendPacket(meta); ((CraftPlayer) lgp.getPlayer()).getHandle().playerConnection.sendPacket(meta);
} }
/* EntityArmorStand ea = new EntityArmorStand(((CraftWorld)loc.getWorld()).getHandle(), loc.getX(), loc.getY()+0.3, loc.getZ()); /* 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.setPosition(loc.getX(), loc.getY()+0.3, loc.getZ());
ea.setInvisible(true); ea.setInvisible(true);
ea.setCustomNameVisible(true); ea.setCustomNameVisible(true);
int votesNbr = votes.get(voted).size(); int votesNbr = votes.get(voted).size();
ea.setCustomName((IChatBaseComponent) WrappedChatComponent.fromText("§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : "")).getHandle()); ea.setCustomName((IChatBaseComponent) WrappedChatComponent.fromText("§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : "")).getHandle());
PacketPlayOutSpawnEntityLiving spawn = new PacketPlayOutSpawnEntityLiving(ea); PacketPlayOutSpawnEntityLiving spawn = new PacketPlayOutSpawnEntityLiving(ea);
try { try {
Field field = spawn.getClass().getDeclaredField("a"); Field field = spawn.getClass().getDeclaredField("a");
@ -365,115 +373,112 @@ public class LGVote {
spawn.setZ(loc.getZ());*/ spawn.setZ(loc.getZ());*/
/* for(LGPlayer lgp : viewers) /* for(LGPlayer lgp : viewers)
((CraftPlayer)lgp.getPlayer()).getHandle().playerConnection.sendPacket(spawn);*/ ((CraftPlayer)lgp.getPlayer()).getHandle().playerConnection.sendPacket(spawn);*/
// spawn.sendPacket(lgp.getPlayer()); // spawn.sendPacket(lgp.getPlayer());
} }
} }
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); private void showVoting(LGPlayer to, LGPlayer ofWho) {
WrappedDataWatcherObject customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class)); int entityId = -to.getPlayer().getEntityId();
WrappedDataWatcherObject customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class)); WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
WrappedDataWatcherObject item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class)); destroy.setEntityIds(new int[]{entityId});
private void showVoting(LGPlayer to, LGPlayer ofWho) { destroy.sendPacket(to.getPlayer());
int entityId = -to.getPlayer().getEntityId(); if (ofWho != null) {
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
destroy.setEntityIds(new int[] {entityId}); spawn.setEntityID(entityId);
destroy.sendPacket(to.getPlayer()); spawn.setType(EntityType.DROPPED_ITEM);
if(ofWho != null) { //spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(0, (byte)0x20), new WrappedWatchableObject(5, true))));
WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); Location loc = ofWho.getPlayer().getLocation();
spawn.setEntityID(entityId); spawn.setX(loc.getX());
spawn.setType(EntityType.DROPPED_ITEM); spawn.setY(loc.getY() + 1.3);
//spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(0, (byte)0x20), new WrappedWatchableObject(5, true)))); spawn.setZ(loc.getZ());
Location loc = ofWho.getPlayer().getLocation(); spawn.setHeadPitch(0);
spawn.setX(loc.getX()); Location toLoc = to.getPlayer().getLocation();
spawn.setY(loc.getY()+1.3); double diffX = loc.getX() - toLoc.getX(),
spawn.setZ(loc.getZ()); diffZ = loc.getZ() - toLoc.getZ();
spawn.setHeadPitch(0); float yaw = 180 - ((float) Math.toDegrees(Math.atan2(diffX, diffZ)));
Location toLoc = to.getPlayer().getLocation();
double diffX = loc.getX()-toLoc.getX(), spawn.setYaw(yaw);
diffZ = loc.getZ()-toLoc.getZ(); spawn.sendPacket(to.getPlayer());
float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ)));
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
spawn.setYaw(yaw); meta.setEntityID(entityId);
spawn.sendPacket(to.getPlayer()); meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte) 0x20), new WrappedWatchableObject(noGravity, true)));
meta.sendPacket(to.getPlayer());
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
meta.setEntityID(entityId); WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook();
meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))); look.setEntityID(entityId);
meta.sendPacket(to.getPlayer()); look.setPitch(0);
look.setYaw(yaw);
WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); look.sendPacket(to.getPlayer());
look.setEntityID(entityId);
look.setPitch(0); new BukkitRunnable() {
look.setYaw(yaw);
look.sendPacket(to.getPlayer()); @Override
public void run() {
new BukkitRunnable() { WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment();
equip.setEntityID(entityId);
@Override equip.setSlot(ItemSlot.HEAD);
public void run() { ItemStack skull = new ItemStack(Material.EMERALD);
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); equip.setItem(skull);
equip.setEntityID(entityId); equip.sendPacket(to.getPlayer());
equip.setSlot(ItemSlot.HEAD); }
ItemStack skull = new ItemStack(Material.EMERALD); }.runTaskLater(MainLg.getInstance(), 2);
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());
private void showArrow(LGPlayer to, LGPlayer ofWho, int entityId) { if (ofWho != null) {
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
destroy.setEntityIds(new int[] {entityId}); spawn.setEntityID(entityId);
destroy.sendPacket(to.getPlayer()); spawn.setType(EntityType.DROPPED_ITEM);
if(ofWho != null) { //spawn.setMetadata(new WrappedDataWatcher());
WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); Location loc = ofWho.getPlayer().getLocation();
spawn.setEntityID(entityId); spawn.setX(loc.getX());
spawn.setType(EntityType.DROPPED_ITEM); spawn.setY(loc.getY() + 1.3);
//spawn.setMetadata(new WrappedDataWatcher()); spawn.setZ(loc.getZ());
Location loc = ofWho.getPlayer().getLocation(); spawn.setHeadPitch(0);
spawn.setX(loc.getX()); Location toLoc = to.getPlayer().getLocation();
spawn.setY(loc.getY()+1.3); double diffX = loc.getX() - toLoc.getX(),
spawn.setZ(loc.getZ()); diffZ = loc.getZ() - toLoc.getZ();
spawn.setHeadPitch(0); float yaw = 180 - ((float) Math.toDegrees(Math.atan2(diffX, diffZ)));
Location toLoc = to.getPlayer().getLocation();
double diffX = loc.getX()-toLoc.getX(), spawn.setYaw(yaw);
diffZ = loc.getZ()-toLoc.getZ(); spawn.sendPacket(to.getPlayer());
float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ)));
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
spawn.setYaw(yaw); meta.setEntityID(entityId);
spawn.sendPacket(to.getPlayer()); meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte) 0x20), new WrappedWatchableObject(noGravity, true)));
meta.sendPacket(to.getPlayer());
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
meta.setEntityID(entityId); WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook();
meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))); look.setEntityID(entityId);
meta.sendPacket(to.getPlayer()); look.setPitch(0);
look.setYaw(yaw);
WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); look.sendPacket(to.getPlayer());
look.setEntityID(entityId);
look.setPitch(0); new BukkitRunnable() {
look.setYaw(yaw);
look.sendPacket(to.getPlayer()); @Override
public void run() {
new BukkitRunnable() { WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment();
equip.setEntityID(entityId);
@Override equip.setSlot(ItemSlot.HEAD);
public void run() { ItemStack skull = new ItemStack(Material.EMERALD);
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); equip.setItem(skull);
equip.setEntityID(entityId); equip.sendPacket(to.getPlayer());
equip.setSlot(ItemSlot.HEAD); }
ItemStack skull = new ItemStack(Material.EMERALD); }.runTaskLater(MainLg.getInstance(), 2);
equip.setItem(skull); }
equip.sendPacket(to.getPlayer()); }
}
}.runTaskLater(MainLg.getInstance(), 2); public void remove(LGPlayer killed) {
} participants.remove(killed);
} if (!ended) {
public void remove(LGPlayer killed) { votes.remove(killed);
participants.remove(killed); latestTop.remove(killed);
if(!ended) { }
votes.remove(killed); }
latestTop.remove(killed);
}
}
} }

View file

@ -5,17 +5,18 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public enum LGWinType { public enum LGWinType {
VILLAGEOIS("§6§l§oLa partie a été gagnée par le §2§lVillage§6§l§o !"), 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 !"), 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 !"), 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 !"), 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 !"), 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 !"), 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 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 !"), 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 !"), PYROMANE("§6§l§oLa partie a été gagnée par le §6§lPyromane§6§l§o !"),
VAMPIRE("§6§l§oLa partie a été gagnée par les §5§lVampires§6§l§o !"), VAMPIRE("§6§l§oLa partie a été gagnée par les §5§lVampires§6§l§o !"),
NONE("§4Erreur: §cpersonne n'a gagné la partie."); NONE("§4Erreur: §cpersonne n'a gagné la partie.");
@Getter private final String message; @Getter
private final String message;
} }

View file

@ -1,35 +1,41 @@
package fr.leomelki.loupgarou.classes.chat; package fr.leomelki.loupgarou.classes.chat;
import java.util.HashMap;
import java.util.Map.Entry;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.Map.Entry;
@RequiredArgsConstructor @RequiredArgsConstructor
public class LGChat { public class LGChat {
@Getter private final HashMap<LGPlayer, LGChatCallback> viewers = new HashMap<>(); @Getter
@Getter private final LGChatCallback defaultCallback; private final HashMap<LGPlayer, LGChatCallback> viewers = new HashMap<>();
@Getter
public interface LGChatCallback{ private final LGChatCallback defaultCallback;
String receive(LGPlayer sender, String message);
default String send(LGPlayer sender, String message) {return null;}
}
public void sendMessage(LGPlayer sender, String message) { public void sendMessage(LGPlayer sender, String message) {
String sendMessage = getViewers().get(sender).send(sender, message); String sendMessage = getViewers().get(sender).send(sender, message);
for(Entry<LGPlayer, LGChatCallback> entry : viewers.entrySet()) for (Entry<LGPlayer, LGChatCallback> entry : viewers.entrySet())
entry.getKey().sendMessage(sendMessage != null ? sendMessage : entry.getValue().receive(sender, message)); entry.getKey().sendMessage(sendMessage != null ? sendMessage : entry.getValue().receive(sender, message));
} }
public void join(LGPlayer player, LGChatCallback callback) { public void join(LGPlayer player, LGChatCallback callback) {
if(getViewers().containsKey(player)) if (getViewers().containsKey(player))
getViewers().replace(player, callback); getViewers().replace(player, callback);
else else
getViewers().put(player, callback); getViewers().put(player, callback);
} }
public void leave(LGPlayer player) {
getViewers().remove(player); public void leave(LGPlayer player) {
} getViewers().remove(player);
}
public interface LGChatCallback {
String receive(LGPlayer sender, String message);
default String send(LGPlayer sender, String message) {
return null;
}
}
} }

View file

@ -2,17 +2,19 @@ package fr.leomelki.loupgarou.classes.chat;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
public class LGNoChat extends LGChat{ public class LGNoChat extends LGChat {
public LGNoChat() { public LGNoChat() {
super(null); super(null);
} }
public void sendMessage(LGPlayer sender, String message) {} public void sendMessage(LGPlayer sender, String message) {
}
public void join(LGPlayer player, LGChatCallback callback) { public void join(LGPlayer player, LGChatCallback callback) {
} }
public void leave(LGPlayer player) {
public void leave(LGPlayer player) {
}
}
} }

View file

@ -1,18 +1,20 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import java.util.List;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import java.util.List;
public class LGCustomItemChangeEvent extends LGEvent { public class LGCustomItemChangeEvent extends LGEvent {
@Getter private final LGPlayer player; @Getter
@Getter private final List<String> constraints; private final LGPlayer player;
@Getter
public LGCustomItemChangeEvent(LGGame game, LGPlayer player, List<String> constraints) { private final List<String> constraints;
super(game);
this.player = player; public LGCustomItemChangeEvent(LGGame game, LGPlayer player, List<String> constraints) {
this.constraints = constraints; super(game);
} this.player = player;
this.constraints = constraints;
}
} }

View file

@ -2,8 +2,8 @@ package fr.leomelki.loupgarou.events;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
public class LGDayEndEvent extends LGEvent{ public class LGDayEndEvent extends LGEvent {
public LGDayEndEvent(LGGame game) { public LGDayEndEvent(LGGame game) {
super(game); super(game);
} }
} }

View file

@ -1,15 +1,16 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGDayStartEvent extends LGEvent implements Cancellable{ public class LGDayStartEvent extends LGEvent implements Cancellable {
public LGDayStartEvent(LGGame game) { @Getter
super(game); @Setter
} private boolean cancelled;
@Getter @Setter private boolean cancelled; public LGDayStartEvent(LGGame game) {
super(game);
}
} }

View file

@ -5,11 +5,13 @@ import fr.leomelki.loupgarou.classes.LGWinType;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
public class LGEndCheckEvent extends LGEvent{ public class LGEndCheckEvent extends LGEvent {
public LGEndCheckEvent(LGGame game, LGWinType winType) { @Getter
super(game); @Setter
this.winType = winType; private LGWinType winType;
}
@Getter @Setter private LGWinType winType; public LGEndCheckEvent(LGGame game, LGWinType winType) {
super(game);
this.winType = winType;
}
} }

View file

@ -1,22 +1,23 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@RequiredArgsConstructor @RequiredArgsConstructor
public class LGEvent extends Event{ public class LGEvent extends Event {
@Getter final LGGame game;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override @Getter
public HandlerList getHandlers() { final LGGame game;
return handlers;
}
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
@Override
public HandlerList getHandlers() {
return handlers;
}
} }

View file

@ -1,22 +1,26 @@
package fr.leomelki.loupgarou.events; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGGameEndEvent extends LGEvent implements Cancellable{ import java.util.List;
@Getter @Setter private boolean cancelled;
@Getter private final LGWinType winType; public class LGGameEndEvent extends LGEvent implements Cancellable {
@Getter private final List<LGPlayer> winners; @Getter
public LGGameEndEvent(LGGame game, LGWinType winType, List<LGPlayer> winners) { private final LGWinType winType;
super(game); @Getter
this.winType = winType; private final List<LGPlayer> winners;
this.winners = winners; @Getter
} @Setter
private boolean cancelled;
public LGGameEndEvent(LGGame game, LGWinType winType, List<LGPlayer> winners) {
super(game);
this.winType = winType;
this.winners = winners;
}
} }

View file

@ -4,12 +4,12 @@ import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
public class LGGameJoinEvent extends LGEvent{ public class LGGameJoinEvent extends LGEvent {
public LGGameJoinEvent(LGGame game, LGPlayer player) { @Getter
super(game);
this.player = player;
}
@Getter
final LGPlayer player; final LGPlayer player;
public LGGameJoinEvent(LGGame game, LGPlayer player) {
super(game);
this.player = player;
}
} }

View file

@ -1,15 +1,16 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGMayorVoteEvent extends LGEvent implements Cancellable{ public class LGMayorVoteEvent extends LGEvent implements Cancellable {
public LGMayorVoteEvent(LGGame game) { @Getter
super(game); @Setter
} private boolean cancelled;
@Getter @Setter private boolean cancelled; public LGMayorVoteEvent(LGGame game) {
super(game);
}
} }

View file

@ -1,15 +1,16 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGNightEndEvent extends LGEvent implements Cancellable{ public class LGNightEndEvent extends LGEvent implements Cancellable {
public LGNightEndEvent(LGGame game) { @Getter
super(game); @Setter
} private boolean cancelled;
@Getter @Setter private boolean cancelled; public LGNightEndEvent(LGGame game) {
super(game);
}
} }

View file

@ -1,23 +1,25 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGNightPlayerPreKilledEvent extends LGEvent implements Cancellable{ public class LGNightPlayerPreKilledEvent extends LGEvent implements Cancellable {
public LGNightPlayerPreKilledEvent(LGGame game, LGPlayer killed, Reason reason) { @Getter
super(game); private final LGPlayer killed;
this.killed = killed; @Getter
this.reason = reason; @Setter
} boolean cancelled;
@Getter
@Setter
private Reason reason;
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;
} }

View file

@ -1,17 +1,18 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGNightStart extends LGEvent implements Cancellable{ public class LGNightStart extends LGEvent implements Cancellable {
public LGNightStart(LGGame game) { @Getter
super(game); @Setter
} boolean cancelled;
@Getter @Setter boolean cancelled; public LGNightStart(LGGame game) {
super(game);
}
} }

View file

@ -6,15 +6,17 @@ import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import lombok.Getter; import lombok.Getter;
public class LGPlayerGotKilledEvent extends LGEvent { public class LGPlayerGotKilledEvent extends LGEvent {
public LGPlayerGotKilledEvent(LGGame game, LGPlayer killed, Reason reason, boolean endGame) { @Getter
super(game); private final boolean endGame;
this.killed = killed; @Getter
this.reason = reason; private final LGPlayer killed;
this.endGame = endGame; @Getter
} private final Reason reason;
public LGPlayerGotKilledEvent(LGGame game, LGPlayer killed, Reason reason, boolean endGame) {
@Getter private final boolean endGame; super(game);
@Getter private final LGPlayer killed; this.killed = killed;
@Getter private final Reason reason; this.reason = reason;
this.endGame = endGame;
}
} }

View file

@ -1,47 +1,51 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGPlayerKilledEvent extends LGEvent implements Cancellable{ public class LGPlayerKilledEvent extends LGEvent implements Cancellable {
public LGPlayerKilledEvent(LGGame game, LGPlayer killed, Reason reason) { @Getter
super(game); @Setter
this.killed = killed; boolean cancelled;
this.reason = reason; @Getter
} @Setter
private LGPlayer killed;
@Getter
@Setter
private Reason reason;
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 @RequiredArgsConstructor
public enum Reason{ public enum Reason {
LOUP_GAROU("§7§l%s§4 est mort pendant la nuit"), LOUP_GAROU("§7§l%s§4 est mort pendant la nuit"),
GM_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()), LOUP_BLANC(LOUP_GAROU.getMessage()),
SORCIERE(LOUP_GAROU.getMessage()), SORCIERE(LOUP_GAROU.getMessage()),
CHASSEUR_DE_VAMPIRE("§7§l%s§4 s'est fait purifier"), CHASSEUR_DE_VAMPIRE("§7§l%s§4 s'est fait purifier"),
VOTE("§7§l%s§4 a été victime du vote"), VOTE("§7§l%s§4 a été victime du vote"),
CHASSEUR("§7§l%s§4 est mort sur le coup"), CHASSEUR("§7§l%s§4 est mort sur le coup"),
DICTATOR("§7§l%s§4 a été désigné"), DICTATOR("§7§l%s§4 a été désigné"),
DICTATOR_SUICIDE("§7§l%s§4 s'est suicidé par culpabilité"), DICTATOR_SUICIDE("§7§l%s§4 s'est suicidé par culpabilité"),
DISCONNECTED("§7§l%s§4 est mort d'une déconnexion"), DISCONNECTED("§7§l%s§4 est mort d'une déconnexion"),
LOVE("§7§l%s§4 s'est suicidé par amour"), LOVE("§7§l%s§4 s'est suicidé par amour"),
BOUFFON("§7§l%s§4 est mort de peur"), BOUFFON("§7§l%s§4 est mort de peur"),
ASSASSIN("§7§l%s§4 s'est fait poignarder"), ASSASSIN("§7§l%s§4 s'est fait poignarder"),
PYROMANE("§7§l%s§4 est parti en fumée"), PYROMANE("§7§l%s§4 est parti en fumée"),
PIRATE("§7§l%s§4 était l'otage"), PIRATE("§7§l%s§4 était l'otage"),
FAUCHEUR("§7§l%s§4 a égaré son âme"), FAUCHEUR("§7§l%s§4 a égaré son âme"),
DONT_DIE("§7§l%s§4 est mort pour rien"); DONT_DIE("§7§l%s§4 est mort pour rien");
@Getter private final String message; @Getter
} private final String message;
}
} }

View file

@ -1,15 +1,16 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGPreDayStartEvent extends LGEvent implements Cancellable{ public class LGPreDayStartEvent extends LGEvent implements Cancellable {
public LGPreDayStartEvent(LGGame game) { @Getter
super(game); @Setter
} private boolean cancelled;
@Getter @Setter private boolean cancelled; public LGPreDayStartEvent(LGGame game) {
super(game);
}
} }

View file

@ -1,18 +1,20 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGPyromaneGasoilEvent extends LGEvent implements Cancellable{ public class LGPyromaneGasoilEvent extends LGEvent implements Cancellable {
public LGPyromaneGasoilEvent(LGGame game, LGPlayer player) { @Getter
super(game); @Setter
this.player = player; private boolean cancelled;
} @Getter
@Setter
@Getter @Setter private boolean cancelled; private LGPlayer player;
@Getter @Setter private LGPlayer player; public LGPyromaneGasoilEvent(LGGame game, LGPlayer player) {
super(game);
this.player = player;
}
} }

View file

@ -4,12 +4,13 @@ import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.roles.Role; import fr.leomelki.loupgarou.roles.Role;
import lombok.Getter; import lombok.Getter;
public class LGRoleTurnEndEvent extends LGEvent{ public class LGRoleTurnEndEvent extends LGEvent {
public LGRoleTurnEndEvent(LGGame game, Role newRole, Role previousRole) { @Getter
super(game); private final Role newRole, previousRole;
this.newRole = newRole;
this.previousRole = previousRole; public LGRoleTurnEndEvent(LGGame game, Role newRole, Role previousRole) {
} super(game);
this.newRole = newRole;
@Getter private final Role newRole, previousRole; this.previousRole = previousRole;
}
} }

View file

@ -1,7 +1,6 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
@ -9,13 +8,17 @@ import lombok.Setter;
public class LGSkinLoadEvent extends LGEvent { public class LGSkinLoadEvent extends LGEvent {
@Getter private final LGPlayer player, to; @Getter
@Getter @Setter private WrappedGameProfile profile; private final LGPlayer player, to;
public LGSkinLoadEvent(LGGame game, LGPlayer player, LGPlayer to, WrappedGameProfile profile) { @Getter
super(game); @Setter
this.player = player; private WrappedGameProfile profile;
this.to = to;
this.profile = profile; public LGSkinLoadEvent(LGGame game, LGPlayer player, LGPlayer to, WrappedGameProfile profile) {
} super(game);
this.player = player;
this.to = to;
this.profile = profile;
}
} }

View file

@ -6,13 +6,17 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
public class LGUpdatePrefixEvent extends LGEvent { public class LGUpdatePrefixEvent extends LGEvent {
@Getter @Setter private String prefix; @Getter
@Getter private final LGPlayer player, to; private final LGPlayer player, to;
public LGUpdatePrefixEvent(LGGame game, LGPlayer player, LGPlayer to, String prefix) { @Getter
super(game); @Setter
this.player = player; private String prefix;
this.prefix = prefix;
this.to = to; public LGUpdatePrefixEvent(LGGame game, LGPlayer player, LGPlayer to, String prefix) {
} super(game);
this.player = player;
this.prefix = prefix;
this.to = to;
}
} }

View file

@ -5,12 +5,15 @@ import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
public class LGVampiredEvent extends LGEvent{ public class LGVampiredEvent extends LGEvent {
public LGVampiredEvent(LGGame game, LGPlayer player) { @Getter
super(game); @Setter
this.player = player; private boolean immuned, protect;
} @Getter
@Setter
@Getter @Setter private boolean immuned, protect; private LGPlayer player;
@Getter @Setter private LGPlayer player; public LGVampiredEvent(LGGame game, LGPlayer player) {
super(game);
this.player = player;
}
} }

View file

@ -1,15 +1,16 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.event.Cancellable;
public class LGVoteEvent extends LGEvent implements Cancellable{ public class LGVoteEvent extends LGEvent implements Cancellable {
public LGVoteEvent(LGGame game) { @Getter
super(game); @Setter
} private boolean cancelled;
@Getter @Setter private boolean cancelled; public LGVoteEvent(LGGame game) {
super(game);
}
} }

View file

@ -1,26 +1,25 @@
package fr.leomelki.loupgarou.events; package fr.leomelki.loupgarou.events;
import java.util.ArrayList;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGVote; import fr.leomelki.loupgarou.classes.LGVote;
import lombok.Getter; import lombok.Getter;
public class LGVoteLeaderChange extends LGEvent{ import java.util.ArrayList;
public LGVoteLeaderChange(LGGame game, LGVote vote, ArrayList<LGPlayer> latest, ArrayList<LGPlayer> now) { public class LGVoteLeaderChange extends LGEvent {
super(game);
this.latest = latest; @Getter
this.now = now;
this.vote = vote;
}
@Getter
final ArrayList<LGPlayer> latest; final ArrayList<LGPlayer> latest;
@Getter @Getter
final ArrayList<LGPlayer> now; final ArrayList<LGPlayer> now;
@Getter @Getter
final LGVote vote; final LGVote vote;
public LGVoteLeaderChange(LGGame game, LGVote vote, ArrayList<LGPlayer> latest, ArrayList<LGPlayer> now) {
super(game);
this.latest = latest;
this.now = now;
this.vote = vote;
}
} }

View file

@ -1,6 +1,7 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -15,61 +16,69 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
import fr.leomelki.loupgarou.classes.LGPlayer; public class CancelListener implements Listener {
private final MainLg plugin;
public class CancelListener implements Listener{ public CancelListener(MainLg mainLg) {
private final MainLg plugin; this.plugin = mainLg;
}
public CancelListener (MainLg mainLg) { @EventHandler
this.plugin = mainLg; public void onPluie(WeatherChangeEvent e) {
} e.setCancelled(true);
@EventHandler }
public void onPluie(WeatherChangeEvent e) {
e.setCancelled(true); @EventHandler
} public void onMove(PlayerMoveEvent e) {
@EventHandler LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer());
public void onMove(PlayerMoveEvent e) { if (lgp.getGame() != null && lgp.getGame().isStarted() && e.getFrom().distanceSquared(e.getTo()) > 0.001)
LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer()); e.setTo(e.getFrom());
if(lgp.getGame() != null && lgp.getGame().isStarted() && e.getFrom().distanceSquared(e.getTo()) > 0.001) }
e.setTo(e.getFrom());
} @EventHandler
@EventHandler public void onDamage(EntityDamageEvent e) {
public void onDamage(EntityDamageEvent e) { e.setCancelled(true);
e.setCancelled(true); }
}
@EventHandler @EventHandler
public void onFood(FoodLevelChangeEvent e) { public void onFood(FoodLevelChangeEvent e) {
e.setFoodLevel(6); e.setFoodLevel(6);
} }
@EventHandler
public void onRespawn(PlayerRespawnEvent e) { @EventHandler
e.setRespawnLocation(e.getPlayer().getLocation()); public void onRespawn(PlayerRespawnEvent e) {
} e.setRespawnLocation(e.getPlayer().getLocation());
@EventHandler }
public void onRespawn(PlayerDeathEvent e) {
e.setDeathMessage(""); @EventHandler
e.setKeepInventory(true); public void onRespawn(PlayerDeathEvent e) {
} e.setDeathMessage("");
/* @EventHandler e.setKeepInventory(true);
public void onAchievement(PlayerAchievementAwardedEvent e) { }
e.setCancelled(true);
}*/ /* @EventHandler
@EventHandler public void onAchievement(PlayerAchievementAwardedEvent e) {
public void onEntitySpawn(EntitySpawnEvent e) { e.setCancelled(true);
e.setCancelled(true); }*/
} @EventHandler
@EventHandler public void onEntitySpawn(EntitySpawnEvent e) {
public void onDrop(PlayerDropItemEvent e) { e.setCancelled(true);
e.setCancelled(true); }
}
@EventHandler @EventHandler
public void onClickInventory(InventoryClickEvent e) { public void onDrop(PlayerDropItemEvent e) {
if(LGPlayer.thePlayer(plugin, (Player)e.getWhoClicked()).getGame() != null) e.setCancelled(true);
e.setCancelled(true); }
}
@EventHandler @EventHandler
public void onClickInventory(PlayerSwapHandItemsEvent e) { public void onClickInventory(InventoryClickEvent e) {
if(LGPlayer.thePlayer(plugin, e.getPlayer()).getGame() != null) if (LGPlayer.thePlayer(plugin, (Player) e.getWhoClicked()).getGame() != null)
e.setCancelled(true); e.setCancelled(true);
} }
@EventHandler
public void onClickInventory(PlayerSwapHandItemsEvent e) {
if (LGPlayer.thePlayer(plugin, e.getPlayer()).getGame() != null)
e.setCancelled(true);
}
} }

View file

@ -1,27 +1,26 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import fr.leomelki.loupgarou.classes.LGPlayer; public class ChatListener implements Listener {
public class ChatListener implements Listener{ private final MainLg plugin;
private final MainLg plugin; public ChatListener(MainLg mainLg) {
this.plugin = mainLg;
}
public ChatListener(MainLg mainLg) { @EventHandler(priority = EventPriority.HIGHEST)
this.plugin = mainLg; public void onChat(AsyncPlayerChatEvent e) {
} if (!e.isCancelled()) {
LGPlayer player = LGPlayer.thePlayer(plugin, e.getPlayer());
@EventHandler(priority = EventPriority.HIGHEST) player.onChat(e.getMessage());
public void onChat(AsyncPlayerChatEvent e) { e.setCancelled(true);
if(!e.isCancelled()) { }
LGPlayer player = LGPlayer.thePlayer(plugin, e.getPlayer()); }
player.onChat(e.getMessage());
e.setCancelled(true);
}
}
} }

View file

@ -1,7 +1,10 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import java.util.Collections; 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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,81 +16,78 @@ import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status; import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import java.util.Collections;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; public class JoinListener implements Listener {
import fr.leomelki.loupgarou.MainLg; private final MainLg plugin;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class JoinListener implements Listener{ public JoinListener(MainLg mainLg) {
private final MainLg plugin; this.plugin = mainLg;
}
public JoinListener(MainLg mainLg) { @EventHandler
this.plugin = mainLg; public void onJoin(PlayerJoinEvent e) {
} Player p = e.getPlayer();
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
WrapperPlayServerScoreboardTeam myTeam = new WrapperPlayServerScoreboardTeam(); WrapperPlayServerScoreboardTeam myTeam = new WrapperPlayServerScoreboardTeam();
myTeam.setName(p.getName()); myTeam.setName(p.getName());
myTeam.setPrefix(WrappedChatComponent.fromText("")); myTeam.setPrefix(WrappedChatComponent.fromText(""));
myTeam.setPlayers(Collections.singletonList(p.getName())); myTeam.setPlayers(Collections.singletonList(p.getName()));
myTeam.setMode(0); myTeam.setMode(0);
boolean noSpec = p.getGameMode() != GameMode.SPECTATOR; boolean noSpec = p.getGameMode() != GameMode.SPECTATOR;
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
if (player != p) { if (player != p) {
if (player.getGameMode() != GameMode.SPECTATOR) if (player.getGameMode() != GameMode.SPECTATOR)
player.hidePlayer(plugin, p); player.hidePlayer(plugin, p);
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(); WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setName(player.getName()); team.setName(player.getName());
team.setPrefix(WrappedChatComponent.fromText("")); team.setPrefix(WrappedChatComponent.fromText(""));
team.setPlayers(Collections.singletonList(player.getName())); team.setPlayers(Collections.singletonList(player.getName()));
team.setMode(0); 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/v32/loup_garou.zip");
} else {
LGPlayer lgp = LGPlayer.thePlayer(plugin, 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(plugin, 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(plugin, 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);
lgp.getGame().checkLeave();
}
LGPlayer.removePlayer(p);
lgp.remove();
}
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/v32/loup_garou.zip");
} else {
LGPlayer lgp = LGPlayer.thePlayer(plugin, 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(plugin, 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(plugin, 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);
lgp.getGame().checkLeave();
}
LGPlayer.removePlayer(p);
lgp.remove();
}
} }

View file

@ -1,30 +1,28 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction; import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardScore; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardScore;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam;
import fr.leomelki.loupgarou.events.LGGameJoinEvent; import fr.leomelki.loupgarou.events.LGGameJoinEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class LoupGarouListener implements Listener { public class LoupGarouListener implements Listener {
@EventHandler @EventHandler
public void onGameJoin(LGGameJoinEvent e) { public void onGameJoin(LGGameJoinEvent e) {
//Tous les loups-garous //Tous les loups-garous
WrapperPlayServerScoreboardTeam teamDelete = new WrapperPlayServerScoreboardTeam(); WrapperPlayServerScoreboardTeam teamDelete = new WrapperPlayServerScoreboardTeam();
teamDelete.setMode(1); teamDelete.setMode(1);
teamDelete.setName("loup_garou_list"); teamDelete.setName("loup_garou_list");
teamDelete.sendPacket(e.getPlayer().getPlayer()); teamDelete.sendPacket(e.getPlayer().getPlayer());
//Loup-Garou noir //Loup-Garou noir
WrapperPlayServerScoreboardScore score = new WrapperPlayServerScoreboardScore(); WrapperPlayServerScoreboardScore score = new WrapperPlayServerScoreboardScore();
score.setObjectiveName("lg_scoreboard"); score.setObjectiveName("lg_scoreboard");
score.setValue(0); score.setValue(0);
score.setScoreName("été"); score.setScoreName("été");
score.setScoreboardAction(ScoreboardAction.REMOVE); score.setScoreboardAction(ScoreboardAction.REMOVE);
score.sendPacket(e.getPlayer().getPlayer()); score.sendPacket(e.getPlayer().getPlayer());
} }
} }

View file

@ -1,27 +1,28 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType; import org.bukkit.event.player.PlayerAnimationType;
import fr.leomelki.loupgarou.classes.LGPlayer; public class VoteListener implements Listener {
private final MainLg plugin;
public class VoteListener implements Listener{ public VoteListener(MainLg mainLg) {
private final MainLg plugin; this.plugin = mainLg;
}
public VoteListener(MainLg mainLg) { @EventHandler
this.plugin = mainLg; public void onClick(PlayerAnimationEvent e) {
} if (e.getAnimationType() == PlayerAnimationType.ARM_SWING)
@EventHandler LGPlayer.thePlayer(plugin, e.getPlayer()).chooseAction();
public void onClick(PlayerAnimationEvent e) { }
if(e.getAnimationType() == PlayerAnimationType.ARM_SWING)
LGPlayer.thePlayer(plugin, e.getPlayer()).chooseAction(); @EventHandler
} public void onBreak(BlockBreakEvent e) {
@EventHandler e.setCancelled(true);
public void onBreak(BlockBreakEvent e) { }
e.setCancelled(true);
}
} }

View file

@ -1,116 +1,124 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.*;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent;
import fr.leomelki.loupgarou.events.LGVoteEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.event.EventHandler;
public class RAnge extends Role{ import java.util.ArrayList;
public RAnge(LGGame game) {
super(game); public class RAnge extends Role {
} final ArrayList<LGPlayer> winners = new ArrayList<>();
@Override boolean vote;
public RoleType getType() { int night = 1;
return RoleType.NEUTRAL;
} public RAnge(LGGame game) {
@Override super(game);
public RoleWinType getWinType() { }
return RoleWinType.VILLAGE;
} @Override
@Override public RoleType getType() {
public String getName() { return RoleType.NEUTRAL;
return "§d§lAnge"; }
}
@Override @Override
public String getFriendlyName() { public RoleWinType getWinType() {
return "de l'"+getName(); return RoleWinType.VILLAGE;
} }
@Override
public String getShortDescription() { @Override
return "Tu gagnes si tu remplis ton objectif"; public String getName() {
} return "§d§lAnge";
@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 getFriendlyName() {
@Override return "de l'" + getName();
public String getTask() { }
return "";
} @Override
@Override public String getShortDescription() {
public String getBroadcastedTask() { return "Tu gagnes si tu remplis ton objectif";
return ""; }
}
@Override @Override
public int getTimeout() { public String getDescription() {
return -1; 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.";
} }
@EventHandler
public void onVoteStart(LGVoteEvent e) { @Override
if(e.getGame() == getGame()) { public String getTask() {
night = getGame().getNight(); return "";
vote = true; }
for(LGPlayer lgp : getPlayers())
if(!lgp.isDead() && lgp.isRoleActive()) @Override
lgp.sendMessage("§9§oFais en sorte que les autres votent contre toi !"); public String getBroadcastedTask() {
} return "";
} }
boolean vote;
@EventHandler @Override
public void onDayEnd(LGDayEndEvent e) { public int getTimeout() {
if(e.getGame() == getGame()) { return -1;
if(getPlayers().size() > 0 && getGame().getNight() == night+1 && vote) { }
Role villageois = null;
for(Role role : getGame().getRoles()) { @EventHandler
if(role instanceof RVillageois) public void onVoteStart(LGVoteEvent e) {
villageois = role; if (e.getGame() == getGame()) {
} night = getGame().getNight();
vote = true;
if(villageois == null) for (LGPlayer lgp : getPlayers())
getGame().getRoles().add(villageois = new RVillageois(getGame())); if (!lgp.isDead() && lgp.isRoleActive())
lgp.sendMessage("§9§oFais en sorte que les autres votent contre toi !");
for(LGPlayer lgp : getPlayers()) { }
if(lgp.isRoleActive()) }
lgp.sendMessage("§4§oTu as échoué, tu deviens §a§l§oVillageois§4§o...");
lgp.setRole(villageois); @EventHandler
villageois.join(lgp); public void onDayEnd(LGDayEndEvent e) {
} if (e.getGame() == getGame()) {
if (getPlayers().size() > 0 && getGame().getNight() == night + 1 && vote) {
getPlayers().clear(); Role villageois = null;
getGame().updateRoleScoreboard(); for (Role role : getGame().getRoles()) {
} if (role instanceof RVillageois)
vote = false; villageois = role;
} }
}
final ArrayList<LGPlayer> winners = new ArrayList<>(); if (villageois == null)
int night = 1; getGame().getRoles().add(villageois = new RVillageois(getGame()));
@EventHandler
public void onDeath(LGPlayerGotKilledEvent e) { for (LGPlayer lgp : getPlayers()) {
if(e.getGame() == getGame()) if (lgp.isRoleActive())
if(e.getReason() == Reason.VOTE && e.getKilled().getRole() == this && getGame().getNight() == night && e.getKilled().isRoleActive()) lgp.sendMessage("§4§oTu as échoué, tu deviens §a§l§oVillageois§4§o...");
winners.add(e.getKilled()); lgp.setRole(villageois);
} villageois.join(lgp);
}
@EventHandler
public void onWinCheck(LGEndCheckEvent e) { getPlayers().clear();
if(e.getGame() == getGame()) getGame().updateRoleScoreboard();
if(winners.size() > 0) }
e.setWinType(winners.size() == 1 && winners.get(0).getCache().has("inlove") ? LGWinType.COUPLE : LGWinType.ANGE); vote = false;
} }
}
@EventHandler
public void onWin(LGGameEndEvent e) { @EventHandler
if(e.getGame() == getGame()) public void onDeath(LGPlayerGotKilledEvent e) {
if(e.getWinType() == LGWinType.ANGE) if (e.getGame() == getGame())
e.getWinners().addAll(winners); if (e.getReason() == Reason.VOTE && e.getKilled().getRole() == this && getGame().getNight() == night && e.getKilled().isRoleActive())
} 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);
}
} }

View file

@ -1,151 +1,154 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.*;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent; import org.bukkit.event.EventHandler;
import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.events.LGVampiredEvent;
public class RAssassin extends Role{ public class RAssassin extends Role {
public RAssassin(LGGame game) { public RAssassin(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.NEUTRAL; public RoleType getType() {
} return RoleType.NEUTRAL;
@Override }
public RoleWinType getWinType() {
return RoleWinType.SEUL; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.SEUL;
public String getName() { }
return "§1§lAssassin";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§1§lAssassin";
return "de l'"+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes §7§lSEUL"; return "de l'" + getName();
} }
@Override
public String getDescription() { @Override
return "Tu gagnes §7§lSEUL§f. Chaque nuit, tu peux choisir un joueur à éliminer. Tu es immunisé contre l'attaque des §c§lLoups§f."; public String getShortDescription() {
} return "Tu gagnes §7§lSEUL";
@Override }
public String getTask() {
return "Choisis un joueur à éliminer."; @Override
} public String getDescription() {
@Override return "Tu gagnes §7§lSEUL§f. Chaque nuit, tu peux choisir un joueur à éliminer. Tu es immunisé contre l'attaque des §c§lLoups§f.";
public String getBroadcastedTask() { }
return "L'"+getName()+"§9 ne controle plus ses pulsions...";
} @Override
@Override public String getTask() {
public int getTimeout() { return "Choisis un joueur à éliminer.";
return 15; }
}
@Override
@Override public String getBroadcastedTask() {
protected void onNightTurn(LGPlayer player, Runnable callback) { return "L'" + getName() + "§9 ne controle plus ses pulsions...";
player.showView(); }
player.choose(choosen -> { @Override
if(choosen != null && choosen != player) { public int getTimeout() {
getGame().kill(choosen, Reason.ASSASSIN); return 15;
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); }
player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6.");
player.stopChoosing(); @Override
player.hideView(); protected void onNightTurn(LGPlayer player, Runnable callback) {
callback.run(); player.showView();
}
}); player.choose(choosen -> {
} if (choosen != null && choosen != player) {
getGame().kill(choosen, Reason.ASSASSIN);
@EventHandler player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 va mourir");
public void onKill(LGNightPlayerPreKilledEvent e) { player.sendMessage("§6Tu as choisi de tuer §7§l" + choosen.getName() + "§6.");
if(e.getKilled().getRole() == this && e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU && e.getKilled().isRoleActive()) {//Les assassins ne peuvent pas mourir la nuit ! player.stopChoosing();
e.setReason(Reason.DONT_DIE); player.hideView();
e.getKilled().getCache().set("assassin_protected", true); callback.run();
} }
} });
}
@EventHandler
public void onTour(LGRoleTurnEndEvent e) { @EventHandler
if(e.getGame() == getGame()) { public void onKill(LGNightPlayerPreKilledEvent e) {
if(e.getPreviousRole() instanceof RLoupGarou) { if (e.getKilled().getRole() == this && e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU && e.getKilled().isRoleActive()) {//Les assassins ne peuvent pas mourir la nuit !
for(LGPlayer lgp : getGame().getAlive()) e.setReason(Reason.DONT_DIE);
if(lgp.getCache().getBoolean("assassin_protected")) { e.getKilled().getCache().set("assassin_protected", true);
for(LGPlayer l : getGame().getInGame()) }
if(l.getRoleType() == RoleType.LOUP_GAROU) }
l.sendMessage("§cVotre cible est immunisée.");
} @EventHandler
}else if(e.getPreviousRole() instanceof RGrandMechantLoup) { public void onTour(LGRoleTurnEndEvent e) {
for(LGPlayer lgp : getGame().getAlive()) if (e.getGame() == getGame()) {
if(lgp.getCache().getBoolean("assassin_protected")) { if (e.getPreviousRole() instanceof RLoupGarou) {
for(LGPlayer l : e.getPreviousRole().getPlayers()) for (LGPlayer lgp : getGame().getAlive())
l.sendMessage("§cVotre cible est immunisée."); 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) {
@EventHandler for (LGPlayer lgp : getGame().getAlive())
public void onPyroGasoil(LGPyromaneGasoilEvent e) { if (lgp.getCache().getBoolean("assassin_protected")) {
if(e.getPlayer().getRole() == this && e.getPlayer().isRoleActive()) for (LGPlayer l : e.getPreviousRole().getPlayers())
e.setCancelled(true); l.sendMessage("§cVotre cible est immunisée.");
} }
@EventHandler }
public void onVampired(LGVampiredEvent e) { }
if(e.getPlayer().getRole() == this && e.getPlayer().isRoleActive()) }
e.setImmuned(true);
} @EventHandler
public void onPyroGasoil(LGPyromaneGasoilEvent e) {
@EventHandler if (e.getPlayer().getRole() == this && e.getPlayer().isRoleActive())
public void onDayStart(LGNightEndEvent e) { e.setCancelled(true);
if(e.getGame() == getGame()) { }
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getCache().getBoolean("assassin_protected")) @EventHandler
lgp.getCache().remove("assassin_protected"); public void onVampired(LGVampiredEvent e) {
} if (e.getPlayer().getRole() == this && e.getPlayer().isRoleActive())
} e.setImmuned(true);
}
@EventHandler
public void onEndgameCheck(LGEndCheckEvent e) { @EventHandler
if(e.getGame() == getGame() && e.getWinType() == LGWinType.SOLO) { public void onDayStart(LGNightEndEvent e) {
if(getPlayers().size() > 0) { if (e.getGame() == getGame()) {
if(getPlayers().size() > 1) for (LGPlayer lgp : getGame().getAlive())
for(LGPlayer lgp : getPlayers()) if (lgp.getCache().getBoolean("assassin_protected"))
if(!lgp.isRoleActive()) lgp.getCache().remove("assassin_protected");
return; }
e.setWinType(LGWinType.ASSASSIN); }
}
} @EventHandler
} public void onEndgameCheck(LGEndCheckEvent e) {
if (e.getGame() == getGame() && e.getWinType() == LGWinType.SOLO) {
@EventHandler(priority = EventPriority.HIGHEST) if (getPlayers().size() > 0) {
public void onEndGame(LGGameEndEvent e) { if (getPlayers().size() > 1)
if(e.getWinType() == LGWinType.ASSASSIN) { for (LGPlayer lgp : getPlayers())
e.getWinners().clear(); if (!lgp.isRoleActive())
e.getWinners().addAll(getPlayers()); return;
} e.setWinType(LGWinType.ASSASSIN);
} }
}
@Override }
protected void onNightTurnTimeout(LGPlayer player) {
player.stopChoosing(); @EventHandler(priority = EventPriority.HIGHEST)
player.hideView(); public void onEndGame(LGGameEndEvent e) {
//player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); if (e.getWinType() == LGWinType.ASSASSIN) {
//player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); 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.");
}
} }

View file

@ -1,148 +1,158 @@
package fr.leomelki.loupgarou.roles; 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.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.event.EventHandler;
import org.bukkit.scheduler.BukkitRunnable;
public class RBouffon extends Role{ import java.util.ArrayList;
public RBouffon(LGGame game) { import java.util.List;
super(game); import java.util.StringJoiner;
}
@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 nimporte 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 quelquun à 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) { public class RBouffon extends Role {
ArrayList<LGPlayer> players = (ArrayList<LGPlayer>) needToPlay.clone(); final ArrayList<LGPlayer> needToPlay = new ArrayList<>();
new Runnable() {
public RBouffon(LGGame game) {
@Override super(game);
public void run() { }
getGame().cancelWait();
if(players.size() == 0) { @Override
onTurnFinish(callback); public RoleType getType() {
return; return RoleType.NEUTRAL;
} }
LGPlayer player = players.remove(0);
getGame().wait(getTimeout(), ()->{RBouffon.this.onNightTurnTimeout(player);this.run();}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); @Override
player.sendMessage("§6"+getTask()); public RoleWinType getWinType() {
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); return RoleWinType.NONE;
onNightTurn(player, this); }
}
}.run(); @Override
} public String getName() {
public boolean hasPlayersLeft() { return "§d§lBouffon";
return needToPlay.size() > 0; }
}
@Override
public String getFriendlyName() {
return "du " + getName();
@Override }
protected void onNightTurn(LGPlayer player, Runnable callback) {
needToPlay.remove(player); @Override
player.showView(); public String getShortDescription() {
player.getCache().set("bouffon_win", true); return "Tu gagnes si tu remplis ton objectif";
List<LGPlayer> choosable = getGame().getVote().getVotes(player); }
StringJoiner sj = new StringJoiner("§6§o, §6§o§l");
for(LGPlayer lgp : choosable) @Override
if(lgp.getPlayer() != null && lgp != player) public String getDescription() {
sj.add(lgp.getName()); 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 nimporte 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é.";
}
String toPut = sj.toString();
if(toPut.length() == 0) @Override
player.sendMessage("§6§o§lPersonne§6§o n'a voté pour toi."); public String getTask() {
else return "Choisis quelquun à hanter parmi ceux qui ont voté pour ta mort.";
player.sendMessage("§6§o§l"+toPut+"§6§o "+(toPut.contains(",") ? "ont" : "a")+" voté pour toi."); }
player.choose((choosen)->{ @Override
if(choosen != null) { public String getBroadcastedTask() {
if(!choosable.contains(choosen)) return "L'esprit vengeur du " + getName() + "§9 rôde sur le village...";
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 @Override
else { public int getTimeout() {
player.stopChoosing(); return 15;
player.sendMessage("§6Ton fantôme va hanter l'esprit de §7§l"+choosen.getName()+"§6."); }
getGame().kill(choosen, Reason.BOUFFON);
player.hideView(); public void onNightTurn(Runnable callback) {
callback.run(); ArrayList<LGPlayer> players = (ArrayList<LGPlayer>) needToPlay.clone();
} new Runnable() {
}
}, player); @Override
} public void run() {
getGame().cancelWait();
@Override if (players.size() == 0) {
protected void onNightTurnTimeout(LGPlayer player) { onTurnFinish(callback);
player.stopChoosing(); return;
} }
LGPlayer player = players.remove(0);
final ArrayList<LGPlayer> needToPlay = new ArrayList<>(); getGame().wait(getTimeout(), () -> {
RBouffon.this.onNightTurnTimeout(player);
@EventHandler this.run();
public void onPlayerKill(LGPlayerKilledEvent e) { }, (currentPlayer, secondsLeft) -> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour " + getFriendlyName() + " §6(§e" + secondsLeft + " s§6)");
if(e.getKilled().getRole() == this && e.getReason() == Reason.VOTE && e.getKilled().isRoleActive()) { player.sendMessage("§6" + getTask());
needToPlay.add(e.getKilled()); // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
getGame().broadcastMessage("§9§oQuelle erreur, le "+getName()+"§9§o aura droit à sa vengeance..."); onNightTurn(player, this);
e.getKilled().sendMessage("§6Tu as rempli ta mission, l'heure de la vengeance a sonné."); }
} }.run();
} }
@EventHandler public boolean hasPlayersLeft() {
public void onWin(LGGameEndEvent e) { return needToPlay.size() > 0;
if(e.getGame() == getGame()) }
for(LGPlayer lgp : getGame().getInGame())
if(lgp.getRole() == this && lgp.getCache().getBoolean("bouffon_win")) { @Override
e.getWinners().add(lgp); protected void onNightTurn(LGPlayer player, Runnable callback) {
new BukkitRunnable() { needToPlay.remove(player);
player.showView();
@Override player.getCache().set("bouffon_win", true);
public void run() { List<LGPlayer> choosable = getGame().getVote().getVotes(player);
getGame().broadcastMessage("§6§oLe "+getName()+"§6§o a rempli son objectif."); StringJoiner sj = new StringJoiner("§6§o, §6§o§l");
} for (LGPlayer lgp : choosable)
}.runTaskAsynchronously(MainLg.getInstance()); if (lgp.getPlayer() != null && lgp != player)
} sj.add(lgp.getName());
}
String toPut = sj.toString();
if (toPut.length() == 0)
player.sendMessage("§6§o§lPersonne§6§o n'a voté pour toi.");
else
player.sendMessage("§6§o§l" + toPut + "§6§o " + (toPut.contains(",") ? "ont" : "a") + " voté pour toi.");
player.choose((choosen) -> {
if (choosen != null) {
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();
}
@EventHandler
public void onPlayerKill(LGPlayerKilledEvent e) {
if (e.getKilled().getRole() == this && e.getReason() == Reason.VOTE && e.getKilled().isRoleActive()) {
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());
}
}
} }

View file

@ -1,95 +1,105 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGNightEndEvent; import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class RChaperonRouge extends Role{ public class RChaperonRouge extends Role {
public RChaperonRouge(LGGame game) { public RChaperonRouge(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.VILLAGER; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getName() { }
return "§a§lChaperon Rouge";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§a§lChaperon Rouge";
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "du " + getName();
} }
@Override
public String getDescription() { @Override
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."; public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
@Override }
public String getTask() {
return ""; @Override
} public String getDescription() {
@Override 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.";
public String getBroadcastedTask() { }
return "";
} @Override
@Override public String getTask() {
public int getTimeout() { return "";
return -1; }
}
@Override
@EventHandler(priority = EventPriority.LOWEST) public String getBroadcastedTask() {
public void onKill(LGNightPlayerPreKilledEvent e) { return "";
if(e.getKilled().getRole() == this && e.getReason() == Reason.LOUP_GAROU || e.getReason() == Reason.GM_LOUP_GAROU && e.getKilled().isRoleActive()) { }
for(Role role : getGame().getRoles())
if(role instanceof RChasseur) @Override
if(role.getPlayers().size() > 0){ public int getTimeout() {
e.getKilled().getCache().set("chaperon_kill", true); return -1;
e.setReason(Reason.DONT_DIE); }
break;
} @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 && e.getKilled().isRoleActive()) {
@EventHandler for (Role role : getGame().getRoles())
public void onTour(LGRoleTurnEndEvent e) { if (role instanceof RChasseur)
if(e.getGame() == getGame()) { if (role.getPlayers().size() > 0) {
if(e.getPreviousRole() instanceof RLoupGarou) { e.getKilled().getCache().set("chaperon_kill", true);
for(LGPlayer lgp : getGame().getAlive()) e.setReason(Reason.DONT_DIE);
if(lgp.getCache().getBoolean("chaperon_kill") && lgp.isRoleActive()) { break;
for(LGPlayer l : getGame().getInGame()) }
if(l.getRoleType() == RoleType.LOUP_GAROU) }
l.sendMessage("§cVotre cible est immunisée."); }
}
}else if(e.getPreviousRole() instanceof RGrandMechantLoup) { @EventHandler
for(LGPlayer lgp : getGame().getAlive()) public void onTour(LGRoleTurnEndEvent e) {
if(lgp.getCache().getBoolean("chaperon_kill") && lgp.isRoleActive()) { if (e.getGame() == getGame()) {
for(LGPlayer l : e.getPreviousRole().getPlayers()) if (e.getPreviousRole() instanceof RLoupGarou) {
l.sendMessage("§cVotre cible est immunisée."); for (LGPlayer lgp : getGame().getAlive())
} if (lgp.getCache().getBoolean("chaperon_kill") && lgp.isRoleActive()) {
} for (LGPlayer l : getGame().getInGame())
} if (l.getRoleType() == RoleType.LOUP_GAROU)
} l.sendMessage("§cVotre cible est immunisée.");
@EventHandler(priority = EventPriority.HIGHEST) }
public void onDayStart(LGNightEndEvent e) { } else if (e.getPreviousRole() instanceof RGrandMechantLoup) {
if(e.getGame() == getGame()) { for (LGPlayer lgp : getGame().getAlive())
for(LGPlayer lgp : getPlayers()) if (lgp.getCache().getBoolean("chaperon_kill") && lgp.isRoleActive()) {
if(lgp.getCache().getBoolean("chaperon_kill")) { for (LGPlayer l : e.getPreviousRole().getPlayers())
lgp.getCache().remove("chaperon_kill"); l.sendMessage("§cVotre cible est immunisée.");
lgp.sendMessage("§9§oTu as été attaqué cette nuit."); }
} }
} }
} }
@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.");
}
}
}
} }

View file

@ -1,10 +1,5 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGDayStartEvent; import fr.leomelki.loupgarou.events.LGDayStartEvent;
@ -12,125 +7,139 @@ import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart; import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
public class RChasseur extends Role{ import java.util.ArrayList;
public RChasseur(LGGame game) {
super(game); public class RChasseur extends Role {
} final ArrayList<LGPlayer> needToPlay = new ArrayList<>();
@Override
public RoleType getType() { public RChasseur(LGGame game) {
return RoleType.VILLAGER; super(game);
} }
@Override
public RoleWinType getWinType() { @Override
return RoleWinType.VILLAGE; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public String getName() {
return "§a§lChasseur"; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getFriendlyName() { }
return "du "+getName();
} @Override
@Override public String getName() {
public String getShortDescription() { return "§a§lChasseur";
return "Tu gagnes avec le §a§lVillage"; }
}
@Override @Override
public String getDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage§f. À ta mort, tu dois éliminer un joueur en utilisant ta dernière balle."; return "du " + getName();
} }
@Override
public String getTask() { @Override
return "Tu dois choisir qui va mourir avec toi."; public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
@Override }
public String getBroadcastedTask() {
return "Le "+getName()+"§9 choisit qui il va emporter avec lui."; @Override
} public String getDescription() {
@Override return "Tu gagnes avec le §a§lVillage§f. À ta mort, tu dois éliminer un joueur en utilisant ta dernière balle.";
public int getTimeout() { }
return 15;
} @Override
public String getTask() {
@Override return "Tu dois choisir qui va mourir avec toi.";
protected void onNightTurn(LGPlayer player, Runnable callback) { }
getGame().wait(getTimeout(), ()->{
this.onNightTurnTimeout(player); @Override
callback.run(); public String getBroadcastedTask() {
}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e"+secondsLeft+" s§6)"); return "Le " + getName() + "§9 choisit qui il va emporter avec lui.";
getGame().broadcastMessage("§9"+getBroadcastedTask()); }
player.sendMessage("§6"+getTask());
//player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 60); @Override
player.choose((choosen)->{ public int getTimeout() {
if(choosen != null) { return 15;
player.stopChoosing(); }
getGame().cancelWait();
LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), choosen, Reason.CHASSEUR); @Override
Bukkit.getPluginManager().callEvent(killEvent); protected void onNightTurn(LGPlayer player, Runnable callback) {
if(killEvent.isCancelled()) getGame().wait(getTimeout(), () -> {
return; this.onNightTurnTimeout(player);
callback.run();
if(getGame().kill(killEvent.getKilled(), killEvent.getReason(), true)) }, (currentPlayer, secondsLeft) -> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e" + secondsLeft + " s§6)");
return; getGame().broadcastMessage("§9" + getBroadcastedTask());
callback.run(); player.sendMessage("§6" + getTask());
} //player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 60);
}, player); player.choose((choosen) -> {
} if (choosen != null) {
player.stopChoosing();
@Override getGame().cancelWait();
protected void onNightTurnTimeout(LGPlayer player) { LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), choosen, Reason.CHASSEUR);
getGame().broadcastMessage("§9Il n'a pas tiré sur la détente..."); Bukkit.getPluginManager().callEvent(killEvent);
player.stopChoosing(); if (killEvent.isCancelled())
} return;
final ArrayList<LGPlayer> needToPlay = new ArrayList<>(); if (getGame().kill(killEvent.getKilled(), killEvent.getReason(), true))
return;
@EventHandler callback.run();
public void onPlayerKill(LGPlayerKilledEvent e) { }
if(e.getKilled().getRole() == this && e.getReason() != Reason.DISCONNECTED && e.getKilled().isRoleActive()) }, player);
needToPlay.add(e.getKilled()); }
}
@EventHandler @Override
public void onDayStart(LGDayStartEvent e) { protected void onNightTurnTimeout(LGPlayer player) {
if(e.getGame() != getGame())return; getGame().broadcastMessage("§9Il n'a pas tiré sur la détente...");
player.stopChoosing();
if(needToPlay.size() > 0) }
e.setCancelled(true);
@EventHandler
if(!e.isCancelled())return; public void onPlayerKill(LGPlayerKilledEvent e) {
new Runnable() { if (e.getKilled().getRole() == this && e.getReason() != Reason.DISCONNECTED && e.getKilled().isRoleActive())
public void run() { needToPlay.add(e.getKilled());
if(needToPlay.size() == 0) { }
e.getGame().startDay();
return; @EventHandler
} public void onDayStart(LGDayStartEvent e) {
LGPlayer player = needToPlay.remove(0); if (e.getGame() != getGame()) return;
onNightTurn(player, this);
} if (needToPlay.size() > 0)
}.run(); e.setCancelled(true);
}
if (!e.isCancelled()) return;
@EventHandler new Runnable() {
public void onEndGame(LGGameEndEvent e) { public void run() {
if(e.getGame() != getGame())return; if (needToPlay.size() == 0) {
e.getGame().startDay();
if(needToPlay.size() > 0) return;
e.setCancelled(true); }
LGPlayer player = needToPlay.remove(0);
if(!e.isCancelled())return; onNightTurn(player, this);
new Runnable() { }
public void run() { }.run();
if(needToPlay.size() == 0) { }
e.getGame().checkEndGame(true);
return; @EventHandler
} public void onEndGame(LGGameEndEvent e) {
LGPlayer player = needToPlay.remove(0); if (e.getGame() != getGame()) return;
onNightTurn(player, this);
} if (needToPlay.size() > 0)
}.run(); e.setCancelled(true);
}
if (!e.isCancelled()) return;
new Runnable() {
public void run() {
if (needToPlay.size() == 0) {
e.getGame().checkEndGame(true);
return;
}
LGPlayer player = needToPlay.remove(0);
onNightTurn(player, this);
}
}.run();
}
/* Deprecated by #onDayStart(LGDayStartEvent) /* Deprecated by #onDayStart(LGDayStartEvent)
* *
@ -152,23 +161,23 @@ public class RChasseur extends Role{
} }
} }
}*/ }*/
@EventHandler @EventHandler
public void onNight(LGNightStart e) { public void onNight(LGNightStart e) {
if(e.getGame() == getGame() && !e.isCancelled()) { if (e.getGame() == getGame() && !e.isCancelled()) {
if(needToPlay.size() > 0) { if (needToPlay.size() > 0) {
e.setCancelled(true); e.setCancelled(true);
new Runnable() { new Runnable() {
public void run() { public void run() {
if(needToPlay.size() == 0) { if (needToPlay.size() == 0) {
e.getGame().nextNight(); e.getGame().nextNight();
return; return;
} }
LGPlayer player = needToPlay.remove(0); LGPlayer player = needToPlay.remove(0);
onNightTurn(player, this); onNightTurn(player, this);
} }
}.run(); }.run();
} }
} }
} }
} }

View file

@ -4,83 +4,93 @@ import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RChasseurDeVampire extends Role{ public class RChasseurDeVampire extends Role {
public RChasseurDeVampire(LGGame game) { public RChasseurDeVampire(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override
public String getName() {
return "§a§lChasseur de Vampires";
}
@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 traquer un joueur pour découvrir s'il s'agit d'un Vampire. Si c'est le cas, tu le tueras dans son sommeil. Si les §5§lVampires§f te prennent pour cible, tu seras immunisé contre leur attaque, et tu tueras le plus jeune d'entre eux.";
}
@Override
public String getTask() {
return "Choisis un joueur à pister.";
}
@Override
public String getBroadcastedTask() {
return "Le "+getName()+"§9 traque ses proies...";
}
@Override
public int getTimeout() {
return 15;
}
@Override
public boolean hasPlayersLeft() {
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.VAMPIRE)
return super.hasPlayersLeft();
return false;
}
@Override
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(choosen -> {
if(choosen != null && choosen != player) {
// player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6.");
if(choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) {
getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE);
player.sendMessage("§7§l"+choosen.getName()+"§6 est un §5§lVampire§6, à l'attaque.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
} else {
player.sendMessage("§7§l"+choosen.getName()+"§6 n'est pas un §5§lVampire§6...");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 n'est pas un §5§lVampire");
}
player.stopChoosing(); @Override
player.hideView(); public RoleType getType() {
callback.run(); return RoleType.VILLAGER;
} }
});
} @Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
@Override }
protected void onNightTurnTimeout(LGPlayer player) {
player.stopChoosing(); @Override
player.hideView(); public String getName() {
//player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); return "§a§lChasseur de Vampires";
//player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); }
}
@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 traquer un joueur pour découvrir s'il s'agit d'un Vampire. Si c'est le cas, tu le tueras dans son sommeil. Si les §5§lVampires§f te prennent pour cible, tu seras immunisé contre leur attaque, et tu tueras le plus jeune d'entre eux.";
}
@Override
public String getTask() {
return "Choisis un joueur à pister.";
}
@Override
public String getBroadcastedTask() {
return "Le " + getName() + "§9 traque ses proies...";
}
@Override
public int getTimeout() {
return 15;
}
@Override
public boolean hasPlayersLeft() {
for (LGPlayer lgp : getGame().getAlive())
if (lgp.getRoleType() == RoleType.VAMPIRE)
return super.hasPlayersLeft();
return false;
}
@Override
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(choosen -> {
if (choosen != null && choosen != player) {
// player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6.");
if (choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) {
getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE);
player.sendMessage("§7§l" + choosen.getName() + "§6 est un §5§lVampire§6, à l'attaque.");
player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 va mourir");
} else {
player.sendMessage("§7§l" + choosen.getName() + "§6 n'est pas un §5§lVampire§6...");
player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 n'est pas un §5§lVampire");
}
player.stopChoosing();
player.hideView();
callback.run();
}
});
}
@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.");
}
} }

View file

@ -1,8 +1,8 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Arrays; import fr.leomelki.loupgarou.MainLg;
import java.util.Collections; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -15,163 +15,167 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import java.util.Arrays;
import fr.leomelki.loupgarou.classes.LGGame; import java.util.Collections;
import fr.leomelki.loupgarou.classes.LGPlayer;
public class RChienLoup extends Role{ public class RChienLoup extends Role {
static final ItemStack[] items = new ItemStack[9]; static final ItemStack[] items = new ItemStack[9];
static {
items[3] = new ItemStack(Material.GOLDEN_APPLE);
ItemMeta meta = items[3].getItemMeta();
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(Collections.singletonList("§cVous rejoindrez le camp des §c§lLoups"));
items[5].setItemMeta(meta);
}
public RChienLoup(LGGame game) { static {
super(game); 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(Collections.singletonList("§cVous rejoindrez le camp des §c§lLoups"));
items[5].setItemMeta(meta);
}
@Override Runnable callback;
public String getName() { boolean already;
return "§a§lChien-Loup"; boolean inMenu;
}
@Override public RChienLoup(LGGame game) {
public String getFriendlyName() { super(game);
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lChien-Loup";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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."; return "du " + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?"; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "Le "+getName()+"§9 pourrait trouver de nouveaux amis..."; 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 RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override @Override
public int getTimeout() { public String getTask() {
return 15; return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?";
} }
@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; @Override
public String getBroadcastedTask() {
private void closeInventory(Player p) { return "Le " + getName() + "§9 pourrait trouver de nouveaux amis...";
inMenu = false; }
p.closeInventory();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { @Override
e.setCancelled(true); public RoleType getType() {
closeInventory(player); return RoleType.VILLAGER;
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."); @Override
lgp.sendMessage("§6Tu as changé de camp."); public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
//On le fait aussi rejoindre le camp des loups pour le tour pendant la nuit. }
RChienLoupLG lgChienLoup = null;
for(Role role : getGame().getRoles()) @Override
if(role instanceof RChienLoupLG) public int getTimeout() {
lgChienLoup = (RChienLoupLG)role; return 15;
}
if(lgChienLoup == null)
getGame().getRoles().add(lgChienLoup = new RChienLoupLG(getGame())); @Override
public boolean hasPlayersLeft() {
lgChienLoup.join(lgp, false); return super.hasPlayersLeft() && !already;
lgp.updateOwnSkin(); }
lgp.hideView(); public void openInventory(Player player) {
callback.run(); 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.");
}
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(getGame().getPlugin(), 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(getGame().getPlugin(), (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 onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().openInventory(e.getInventory());
}
}.runTaskLater(MainLg.getInstance(), 1);
}
}
}
} }

View file

@ -1,72 +1,74 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import org.bukkit.potion.PotionEffectType;
import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.potion.PotionEffectType;
public class RChienLoupLG extends Role{ public class RChienLoupLG extends Role {
public RChienLoupLG(LGGame game) { public RChienLoupLG(LGGame game) {
super(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 @Override
public String getFriendlyName() { public String getName() {
return "du "+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 @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "du " + getName();
} }
@Override @Override
public String getDescription() { public String getShortDescription() {
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."; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getTask() { public String getDescription() {
return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?"; 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 @Override
public String getBroadcastedTask() { public String getTask() {
return "Le "+getName()+"§9 pourrait trouver de nouveaux amis..."; return "Souhaites-tu devenir un §c§lLoup-Garou§6 ?";
} }
@Override
public RoleType getType() {
return RoleType.LOUP_GAROU;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.LOUP_GAROU;
}
@Override @Override
public int getTimeout() { public String getBroadcastedTask() {
return -1; return "Le " + getName() + "§9 pourrait trouver de nouveaux amis...";
} }
@Override @Override
public void join(LGPlayer player, boolean sendMessage) { public RoleType getType() {
super.join(player, sendMessage); return RoleType.LOUP_GAROU;
player.setRole(this); }
LGCustomItems.updateItem(player);
for(Role role : getGame().getRoles()) @Override
if(role instanceof RLoupGarou) { public RoleWinType getWinType() {
role.join(player, false); return RoleWinType.LOUP_GAROU;
for(LGPlayer lgp : role.getPlayers()) }
if(lgp != player)
lgp.sendMessage("§7§l"+player.getName()+"§6 a rejoint les §c§lLoups-Garous§6."); @Override
} public int getTimeout() {
} return -1;
}
@Override
public void join(LGPlayer player, boolean sendMessage) {
super.join(player, sendMessage);
player.setRole(this);
LGCustomItems.updateItem(player);
for (Role role : getGame().getRoles())
if (role instanceof RLoupGarou) {
role.join(player, false);
for (LGPlayer lgp : role.getPlayers())
if (lgp != player)
lgp.sendMessage("§7§l" + player.getName() + "§6 a rejoint les §c§lLoups-Garous§6.");
}
}
} }

View file

@ -1,106 +1,114 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import org.bukkit.event.EventHandler;
import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGVoteEvent; import fr.leomelki.loupgarou.events.LGVoteEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.scheduler.BukkitRunnable;
public class RCorbeau extends Role{ public class RCorbeau extends Role {
public RCorbeau(LGGame game) { public RCorbeau(LGGame game) {
super(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(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); @Override
public RoleType getType() {
return RoleType.VILLAGER;
}
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui"); @Override
player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6."); public RoleWinType getWinType() {
player.stopChoosing(); return RoleWinType.VILLAGE;
player.hideView(); }
callback.run();
} @Override
}); public String getName() {
} return "§a§lCorbeau";
}
@EventHandler
public void onNightStart(LGDayEndEvent e) { @Override
if(e.getGame() == getGame()) public String getFriendlyName() {
for(LGPlayer lgp : getGame().getAlive()) return "du " + getName();
lgp.getCache().remove("corbeau_selected"); }
}
@Override
@EventHandler public String getShortDescription() {
public void onVoteStart(LGVoteEvent e) { return "Tu gagnes avec le §a§lVillage";
if(e.getGame() == getGame()) }
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getCache().getBoolean("corbeau_selected")) { @Override
lgp.getCache().remove("corbeau_selected"); public String getDescription() {
new BukkitRunnable() { 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 void run() { @Override
MainLg plugin = getGame().getPlugin(); public String getTask() {
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp); return "Tu peux choisir un joueur qui aura deux votes contre lui.";
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);//fix }
getGame().broadcastMessage("§7§l"+ lgp.getName()+"§6 a reçu la visite du "+getName()+"§6.");
} @Override
}.runTask(MainLg.getInstance()); public String getBroadcastedTask() {
return "Le " + getName() + "§9 s'apprête à diffamer quelqu'un...";
} }
}
@Override
@Override public int getTimeout() {
protected void onNightTurnTimeout(LGPlayer player) { return 15;
player.stopChoosing(); }
player.hideView();
//player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); @Override
//player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); protected void onNightTurn(LGPlayer player, Runnable callback) {
} player.showView();
player.choose(choosen -> {
if (choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
choosen.getCache().set("corbeau_selected", true);
player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 aura deux votes contre lui");
player.sendMessage("§6Tu nuis à la réputation de §7§l" + choosen.getName() + "§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
});
}
@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");
new BukkitRunnable() {
@Override
public void run() {
MainLg plugin = getGame().getPlugin();
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);//fix
getGame().broadcastMessage("§7§l" + lgp.getName() + "§6 a reçu la visite du " + getName() + "§6.");
}
}.runTask(MainLg.getInstance());
}
}
@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.");
}
} }

View file

@ -1,8 +1,16 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.ArrayList; import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import java.util.Arrays; 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.*;
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.*;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -13,260 +21,253 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot; import java.util.ArrayList;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import java.util.Arrays;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy; public class RCupidon extends Role {
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityEquipment; final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityLook; final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
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.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) {
public RCupidon(LGGame game) { super(game);
super(game); }
}
@Override @Override
public RoleType getType() { public RoleType getType() {
return RoleType.VILLAGER; return RoleType.VILLAGER;
} }
@Override
public RoleWinType getWinType() { @Override
return RoleWinType.VILLAGE; public RoleWinType getWinType() {
} return RoleWinType.VILLAGE;
@Override }
public String getName() {
return "§a§lCupidon"; @Override
} public String getName() {
@Override return "§a§lCupidon";
public String getFriendlyName() { }
return "de "+getName();
} @Override
@Override public String getFriendlyName() {
public String getShortDescription() { return "de " + getName();
return "Tu gagnes avec le §a§lVillage"; }
}
@Override @Override
public String getDescription() { public String getShortDescription() {
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."; return "Tu gagnes avec le §a§lVillage";
} }
@Override
public String getTask() { @Override
return "Choisis deux joueurs à mettre en couple."; 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 getBroadcastedTask() {
return getName()+"§9 choisit deux âmes à unir."; @Override
} public String getTask() {
return "Choisis deux joueurs à mettre en couple.";
@Override }
public int getTimeout() {
return 15; @Override
} public String getBroadcastedTask() {
@Override return getName() + "§9 choisit deux âmes à unir.";
public boolean hasPlayersLeft() { }
return getGame().getNight() == 1;
} @Override
public int getTimeout() {
@Override return 15;
protected void onNightTurn(LGPlayer player, Runnable callback) { }
player.showView();
@Override
player.choose(choosen -> { public boolean hasPlayersLeft() {
if(choosen != null) { return getGame().getNight() == 1;
if(player.getCache().has("cupidon_first")) { }
LGPlayer first = player.getCache().remove("cupidon_first");
if(first == choosen) { @Override
int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId(); protected void onNightTurn(LGPlayer player, Runnable callback) {
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); player.showView();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer()); player.choose(choosen -> {
} else { if (choosen != null) {
// sendHead(player, choosen); if (player.getCache().has("cupidon_first")) {
int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId(); LGPlayer first = player.getCache().remove("cupidon_first");
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); if (first == choosen) {
destroy.setEntityIds(new int[] {entityId}); int entityId = Integer.MAX_VALUE - choosen.getPlayer().getEntityId();
destroy.sendPacket(player.getPlayer()); 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.");
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(player1, player2);
sendHead(player2, player1);*/ sendHead(player2, player1);*/
//On peut créer des cheats grâce à ça (qui permettent de savoir qui est en couple)
player1.updatePrefix();
player2.updatePrefix();
}
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)); //On peut créer des cheats grâce à ça (qui permettent de savoir qui est en couple)
final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); player1.updatePrefix();
protected void sendHead(LGPlayer to, LGPlayer ofWho) { player2.updatePrefix();
int entityId = Integer.MAX_VALUE-ofWho.getPlayer().getEntityId(); }
WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
spawn.setEntityID(entityId); protected void sendHead(LGPlayer to, LGPlayer ofWho) {
spawn.setType(EntityType.DROPPED_ITEM); int entityId = Integer.MAX_VALUE - ofWho.getPlayer().getEntityId();
//spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true)))); WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
Location loc = ofWho.getPlayer().getLocation(); spawn.setEntityID(entityId);
spawn.setX(loc.getX()); spawn.setType(EntityType.DROPPED_ITEM);
spawn.setY(loc.getY()+1.9); //spawn.setMetadata(new WrappedDataWatcher(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true))));
spawn.setZ(loc.getZ()); Location loc = ofWho.getPlayer().getLocation();
spawn.setHeadPitch(0); spawn.setX(loc.getX());
Location toLoc = to.getPlayer().getLocation(); spawn.setY(loc.getY() + 1.9);
double diffX = loc.getX()-toLoc.getX(), spawn.setZ(loc.getZ());
diffZ = loc.getZ()-toLoc.getZ(); spawn.setHeadPitch(0);
float yaw = 180-((float) Math.toDegrees(Math.atan2(diffX, diffZ))); Location toLoc = to.getPlayer().getLocation();
double diffX = loc.getX() - toLoc.getX(),
spawn.setYaw(yaw); diffZ = loc.getZ() - toLoc.getZ();
spawn.sendPacket(to.getPlayer()); float yaw = 180 - ((float) Math.toDegrees(Math.atan2(diffX, diffZ)));
WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook(); spawn.setYaw(yaw);
look.setEntityID(entityId); spawn.sendPacket(to.getPlayer());
look.setPitch(0);
look.setYaw(yaw); WrapperPlayServerEntityLook look = new WrapperPlayServerEntityLook();
look.sendPacket(to.getPlayer()); look.setEntityID(entityId);
look.setPitch(0);
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); look.setYaw(yaw);
meta.setEntityID(entityId); look.sendPacket(to.getPlayer());
meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true)));
meta.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 new BukkitRunnable() {
public void run() {
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(); @Override
equip.setEntityID(entityId); public void run() {
equip.setSlot(ItemSlot.HEAD); WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment();
ItemStack skull = new ItemStack(Material.SUGAR); equip.setEntityID(entityId);
equip.setItem(skull); equip.setSlot(ItemSlot.HEAD);
equip.sendPacket(to.getPlayer()); ItemStack skull = new ItemStack(Material.SUGAR);
} equip.setItem(skull);
}.runTaskLater(MainLg.getInstance(), 2); equip.sendPacket(to.getPlayer());
} }
}.runTaskLater(MainLg.getInstance(), 2);
@Override }
protected void onNightTurnTimeout(LGPlayer player) {
player.getCache().remove("cupidon_first"); @Override
player.stopChoosing(); protected void onNightTurnTimeout(LGPlayer player) {
player.hideView(); player.getCache().remove("cupidon_first");
//player.sendTitle("§cVous n'avez mis personne en couple", "§4Vous avez mis trop de temps à vous décider...", 80); player.stopChoosing();
//player.sendMessage("§9Tu n'as pas créé de couple."); 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().<LGPlayer>get("inlove").isDead()) { @EventHandler
LGPlayer killed = e.getKilled().getCache().get("inlove"); public void onPlayerKill(LGPlayerGotKilledEvent e) {
LGPlayerKilledEvent event = new LGPlayerKilledEvent(getGame(), killed, Reason.LOVE); if (e.getGame() == getGame() && e.getKilled().getCache().has("inlove") && !e.getKilled().getCache().<LGPlayer>get("inlove").isDead()) {
Bukkit.getPluginManager().callEvent(event); LGPlayer killed = e.getKilled().getCache().get("inlove");
if(!event.isCancelled()) LGPlayerKilledEvent event = new LGPlayerKilledEvent(getGame(), killed, Reason.LOVE);
getGame().kill(event.getKilled(), event.getReason(), false); 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()) { @EventHandler(priority = EventPriority.HIGH)
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); public void onGameEnd(LGGameEndEvent e) {
ArrayList<Integer> ids = new ArrayList<>(); if (e.getGame() == getGame()) {
for(LGPlayer lgp : getGame().getInGame()) WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId()); ArrayList<Integer> ids = new ArrayList<>();
int[] intList = new int[ids.size()]; for (LGPlayer lgp : getGame().getInGame())
for(int i = 0;i<ids.size();i++) ids.add(Integer.MAX_VALUE - lgp.getPlayer().getEntityId());
intList[i] = ids.get(i); int[] intList = new int[ids.size()];
destroy.setEntityIds(intList); for (int i = 0; i < ids.size(); i++)
for(LGPlayer lgp : getGame().getInGame()) intList[i] = ids.get(i);
destroy.sendPacket(lgp.getPlayer()); destroy.setEntityIds(intList);
for (LGPlayer lgp : getGame().getInGame())
for(LGPlayer lgp : getGame().getInGame()) destroy.sendPacket(lgp.getPlayer());
if(lgp.getCache().has("inlove")) {
if(e.getWinType() == LGWinType.COUPLE) { for (LGPlayer lgp : getGame().getInGame())
if(!e.getWinners().contains(lgp)) if (lgp.getCache().has("inlove")) {
e.getWinners().add(lgp); if (e.getWinType() == LGWinType.COUPLE) {
} else { if (!e.getWinners().contains(lgp))
LGPlayer player2 = lgp.getCache().get("inlove"); e.getWinners().add(lgp);
boolean winEnCouple = (lgp.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU) || lgp.getRoleWinType() == RoleWinType.SEUL || player2.getRoleWinType() == RoleWinType.SEUL; } else {
if(winEnCouple) { LGPlayer player2 = lgp.getCache().get("inlove");
System.out.println(lgp.getName()+" ne peut pas gagner car il était en couple !"); boolean winEnCouple = (lgp.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU) || lgp.getRoleWinType() == RoleWinType.SEUL || player2.getRoleWinType() == RoleWinType.SEUL;
e.getWinners().remove(lgp); 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()) { @EventHandler
ArrayList<LGPlayer> winners = new ArrayList<>(); public void onEndCheck(LGEndCheckEvent e) {
for(LGPlayer lgp : getGame().getAlive()) if (e.getGame() == getGame()) {
if(lgp.getRoleWinType() != RoleWinType.NONE) ArrayList<LGPlayer> winners = new ArrayList<>();
winners.add(lgp); for (LGPlayer lgp : getGame().getAlive())
if(winners.size() == 2) { if (lgp.getRoleWinType() != RoleWinType.NONE)
LGPlayer player1 = winners.get(0), winners.add(lgp);
player2 = winners.get(1); if (winners.size() == 2) {
boolean winEnCouple = (player1.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU) || player1.getRoleWinType() == RoleWinType.SEUL || player2.getRoleWinType() == RoleWinType.SEUL; LGPlayer player1 = winners.get(0),
if(player1.getCache().get("inlove") == player2 && /*player1.isABadGuy() != player2.isABadGuy()*/ (player1.getRoleType() == RoleType.LOUP_GAROU) != (player2.getRoleType() == RoleType.LOUP_GAROU)) player2 = winners.get(1);
e.setWinType(LGWinType.COUPLE); 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(getGame().getPlugin(), e.getPlayer()); @EventHandler(priority = EventPriority.LOWEST)
if(player.getGame() == getGame()) { public void onChat(AsyncPlayerChatEvent e) {
if(e.getMessage().startsWith("!")) { LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), e.getPlayer());
if(player.getCache().has("inlove")){ if (player.getGame() == getGame()) {
player.sendMessage("§d\u2764 "+player.getName()+" §6» §f"+e.getMessage().substring(1)); if (e.getMessage().startsWith("!")) {
player.getCache().<LGPlayer>get("inlove").sendMessage("§d\u2764 "+player.getName()+" §6» §f"+e.getMessage().substring(1)); if (player.getCache().has("inlove")) {
}else player.sendMessage("§d\u2764 " + player.getName() + " §6» §f" + e.getMessage().substring(1));
player.sendMessage("§4Erreur : §cVous n'êtes pas en couple !"); player.getCache().<LGPlayer>get("inlove").sendMessage("§d\u2764 " + player.getName() + " §6» §f" + e.getMessage().substring(1));
e.setCancelled(true); } else
} player.sendMessage("§4Erreur : §cVous n'êtes pas en couple !");
} 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"))) @EventHandler(priority = EventPriority.HIGH)
e.setPrefix("§d\u2764 §f"+e.getPrefix()); 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 /* @EventHandler
public void onNight(LGDayEndEvent e) { public void onNight(LGDayEndEvent e) {
@ -275,5 +276,5 @@ public class RCupidon extends Role{
if(lgp.getCache().has("inlove")) if(lgp.getCache().has("inlove"))
lgp.unMute(lgp.getCache().get("inlove")); lgp.unMute(lgp.getCache().get("inlove"));
}*/ }*/
} }

View file

@ -3,87 +3,96 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
public class RDetective extends Role{ public class RDetective extends Role {
public RDetective(LGGame game) { public RDetective(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.VILLAGER; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getName() { }
return "§a§lDétective";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§a§lDétective";
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "du " + getName();
} }
@Override
public String getDescription() { @Override
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."; public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
@Override }
public String getTask() {
return "Choisis deux joueurs à étudier."; @Override
} public String getDescription() {
@Override 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.";
public String getBroadcastedTask() { }
return "Le "+getName()+"§9 est sur une enquête...";
} @Override
public String getTask() {
@Override return "Choisis deux joueurs à étudier.";
public int getTimeout() { }
return 15;
} @Override
@Override public String getBroadcastedTask() {
protected void onNightTurn(LGPlayer player, Runnable callback) { return "Le " + getName() + "§9 est sur une enquête...";
player.showView(); }
player.choose(choosen -> { @Override
if(choosen != null) { public int getTimeout() {
if(choosen == player) { return 15;
player.sendMessage("§cVous ne pouvez pas vous sélectionner !"); }
return;
} @Override
if(player.getCache().has("detective_first")) { protected void onNightTurn(LGPlayer player, Runnable callback) {
LGPlayer first = player.getCache().remove("detective_first"); player.showView();
if(first == choosen) {
player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !"); player.choose(choosen -> {
} else { if (choosen != null) {
if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType()) if (choosen == player) {
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp."); player.sendMessage("§cVous ne pouvez pas vous sélectionner !");
else return;
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp."); }
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.");
}
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.");
}
} }

View file

@ -1,10 +1,14 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.ArrayList; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot;
import java.util.Arrays; import fr.leomelki.loupgarou.MainLg;
import java.util.Collections; import fr.leomelki.loupgarou.classes.LGGame;
import java.util.Iterator; 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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -19,254 +23,264 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; import java.util.ArrayList;
import fr.leomelki.loupgarou.MainLg; import java.util.Arrays;
import fr.leomelki.loupgarou.classes.LGGame; import java.util.Collections;
import fr.leomelki.loupgarou.classes.LGPlayer; import java.util.Iterator;
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{ public class RDictateur extends Role {
static private final ItemStack[] items = new ItemStack[9]; static private final ItemStack[] items = new ItemStack[9];
static private final Inventory inventory; static private final Inventory inventory;
static {
items[3] = new ItemStack(Material.IRON_NUGGET); static {
ItemMeta meta = items[3].getItemMeta(); items[3] = new ItemStack(Material.IRON_NUGGET);
meta.setDisplayName("§7§lNe rien faire"); ItemMeta meta = items[3].getItemMeta();
meta.setLore(Collections.singletonList("§8Passez votre tour")); meta.setDisplayName("§7§lNe rien faire");
items[3].setItemMeta(meta); meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER); items[3].setItemMeta(meta);
meta = items[5].getItemMeta(); items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER);
meta.setDisplayName("§e§lCoup d'État"); meta = items[5].getItemMeta();
meta.setLore(Arrays.asList( meta.setDisplayName("§e§lCoup d'État");
"§8Prends le contrôle du village", meta.setLore(Arrays.asList(
"§8et choisis seul qui mourra demain.", "§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.")); "§8Si tu tues un §a§lVillageois§8, tu",
items[5].setItemMeta(meta); "§8l'auras sur la conscience."));
inventory = Bukkit.createInventory(null, 9, "§7Veux-tu faire un coup d'état ?"); items[5].setItemMeta(meta);
inventory.setContents(items.clone()); inventory = Bukkit.createInventory(null, 9, "§7Veux-tu faire un coup d'état ?");
} inventory.setContents(items.clone());
public RDictateur(LGGame game) { }
super(game);
} Runnable callback, run;
@Override boolean inMenu = false;
public RoleType getType() {
return RoleType.VILLAGER; public RDictateur(LGGame game) {
} super(game);
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleType getType() {
@Override return RoleType.VILLAGER;
public String getName() { }
return "§a§lDictateur";
} @Override
@Override public RoleWinType getWinType() {
public String getFriendlyName() { return RoleWinType.VILLAGE;
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lDictateur";
} }
@Override
public String getDescription() { @Override
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."; public String getFriendlyName() {
} return "du " + getName();
@Override }
public String getTask() {
return "Veux-tu réaliser un coup d'état ?"; @Override
} public String getShortDescription() {
@Override return "Tu gagnes avec le §a§lVillage";
public String getBroadcastedTask() { }
return "Le "+getName()+"§9 décide s'il veut se dévoiler.";
} @Override
public String getDescription() {
@Override 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.";
public int getTimeout() { }
return 15;
} @Override
public String getTask() {
public void openInventory(Player player) { return "Veux-tu réaliser un coup d'état ?";
inMenu = true; }
player.closeInventory();
player.openInventory(inventory); @Override
} public String getBroadcastedTask() {
Runnable callback, run; return "Le " + getName() + "§9 décide s'il veut se dévoiler.";
@Override }
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); @Override
this.callback = callback; public int getTimeout() {
openInventory(player.getPlayer()); return 15;
} }
@Override
protected void onNightTurnTimeout(LGPlayer player) { public void openInventory(Player player) {
player.hideView(); inMenu = true;
closeInventory(player.getPlayer()); 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.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.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("§cVous ne faites pas votre coup d'état.");
player.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/ player.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/
} }
boolean inMenu = false; private void closeInventory(Player p) {
inMenu = false;
private void closeInventory(Player p) { p.closeInventory();
inMenu = false; }
p.closeInventory();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { @EventHandler
e.setCancelled(true); public void onInventoryClick(InventoryClickEvent e) {
closeInventory(player); ItemStack item = e.getCurrentItem();
Player player = (Player) e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), 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("§cVous ne faites pas votre coup d'état.");
lgp.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/ lgp.sendMessage("§7§oVous aurez de nouveau le choix lors de la prochaine nuit.");*/
lgp.hideView(); lgp.hideView();
callback.run(); callback.run();
}else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { } else if (item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) {
e.setCancelled(true); e.setCancelled(true);
closeInventory(player); closeInventory(player);
lgp.sendActionBarMessage("§9§lTu effectueras un coup d'état"); lgp.sendActionBarMessage("§9§lTu effectueras un coup d'état");
lgp.sendMessage("§6Tu as décidé de faire 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("coup_d_etat", true);
lgp.getCache().set("just_coup_d_etat", true); lgp.getCache().set("just_coup_d_etat", true);
lgp.hideView(); lgp.hideView();
callback.run(); callback.run();
} }
} }
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer();
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), 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(getGame().getPlugin(), (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 @EventHandler
public void onVote(LGVoteEvent e) { public void onClick(PlayerInteractEvent e) {
if(e.getGame() == getGame()) Player p = e.getPlayer();
onTurn(e); LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p);
} if (e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
public void onTurn(Cancellable e) { getGame().cancelWait();
for(LGPlayer lgp : getPlayers()) player.stopChoosing();
if(lgp.getCache().getBoolean("just_coup_d_etat") && lgp.isRoleActive()) p.getInventory().setItem(8, null);
e.setCancelled(true); p.updateInventory();
getGame().broadcastMessage("§7§l" + player.getName() + "§9 n'a tué personne.");
if(!e.isCancelled()) run.run();
return; }
}
Iterator<LGPlayer> ite = ((ArrayList<LGPlayer>)getPlayers().clone()).iterator();
new Runnable() { @EventHandler
public void run() { public void onQuitInventory(InventoryCloseEvent e) {
run = this; if (e.getInventory() instanceof CraftInventoryCustom) {
if(ite.hasNext()) { LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player) e.getPlayer());
LGPlayer lgp = ite.next(); if (player.getRole() == this && inMenu) {
if(lgp.getCache().getBoolean("just_coup_d_etat")) { new BukkitRunnable() {
getPlayers().remove(lgp);
lgp.getCache().remove("just_coup_d_etat"); @Override
getGame().broadcastMessage("§7§l"+lgp.getName()+" §9réalise un coup d'état."); public void run() {
//lgp.sendTitle("§6Vous faites votre coup d'état", "§aChoisissez qui tuer", 60); e.getPlayer().openInventory(e.getInventory());
}
//On le met sur le slot 0 pour éviter un missclick sur la croix }.runTaskLater(MainLg.getInstance(), 1);
WrapperPlayServerHeldItemSlot hold = new WrapperPlayServerHeldItemSlot(); }
hold.setSlot(0); }
hold.sendPacket(lgp.getPlayer()); }
lgp.sendMessage("§6Choisis un joueur à exécuter."); @EventHandler
getGame().wait(60, ()->{ public void onMayorVote(LGMayorVoteEvent e) {
lgp.stopChoosing(); if (e.getGame() == getGame())
getGame().broadcastMessage("§7§l"+lgp.getName()+"§9 n'a tué personne."); onTurn(e);
lgp.getPlayer().getInventory().setItem(8, null); }
lgp.getPlayer().updateInventory();
this.run(); @EventHandler
}, (player, secondsLeft)-> lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)"); public void onVote(LGVoteEvent e) {
lgp.choose((choosen)->{ if (e.getGame() == getGame())
if(choosen != null) { onTurn(e);
getGame().cancelWait(); }
lgp.stopChoosing();
lgp.getPlayer().getInventory().setItem(8, null); public void onTurn(Cancellable e) {
lgp.getPlayer().updateInventory(); for (LGPlayer lgp : getPlayers())
kill(choosen, lgp, this); if (lgp.getCache().getBoolean("just_coup_d_etat") && lgp.isRoleActive())
} e.setCancelled(true);
});
lgp.getPlayer().getInventory().setItem(8, items[3]); if (!e.isCancelled())
lgp.getPlayer().updateInventory(); return;
}
}else Iterator<LGPlayer> ite = ((ArrayList<LGPlayer>) getPlayers().clone()).iterator();
getGame().nextNight(); new Runnable() {
} public void run() {
}.run(); run = this;
} if (ite.hasNext()) {
protected void kill(LGPlayer choosen, LGPlayer dicta, Runnable callback) { LGPlayer lgp = ite.next();
RoleType roleType = choosen.getRoleType(); if (lgp.getCache().getBoolean("just_coup_d_etat")) {
getPlayers().remove(lgp);
LGPlayerKilledEvent killEvent = new LGPlayerKilledEvent(getGame(), choosen, Reason.DICTATOR); lgp.getCache().remove("just_coup_d_etat");
Bukkit.getPluginManager().callEvent(killEvent); getGame().broadcastMessage("§7§l" + lgp.getName() + " §9réalise un coup d'état.");
if(killEvent.isCancelled())return; //lgp.sendTitle("§6Vous faites votre coup d'état", "§aChoisissez qui tuer", 60);
if(getGame().kill(killEvent.getKilled(), killEvent.getReason(), true))
return; //On le met sur le slot 0 pour éviter un missclick sur la croix
WrapperPlayServerHeldItemSlot hold = new WrapperPlayServerHeldItemSlot();
if(roleType != RoleType.VILLAGER) { hold.setSlot(0);
getGame().broadcastMessage("§7§l"+dicta.getName()+" §9devient le §5§lCapitaine§9 du village."); hold.sendPacket(lgp.getPlayer());
getGame().setMayor(dicta);
} else { lgp.sendMessage("§6Choisis un joueur à exécuter.");
getGame().kill(dicta, Reason.DICTATOR_SUICIDE); getGame().wait(60, () -> {
for(LGPlayer lgp : getGame().getInGame()) { lgp.stopChoosing();
if(lgp == dicta) getGame().broadcastMessage("§7§l" + lgp.getName() + "§9 n'a tué personne.");
lgp.sendMessage("§9§oÇa ne s'est pas passé comme prévu..."); lgp.getPlayer().getInventory().setItem(8, null);
else lgp.getPlayer().updateInventory();
lgp.sendMessage("§9Le "+getName()+"§9 s'est trompé, il mourra la nuit suivante."); this.run();
} }, (player, secondsLeft) -> lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e" + secondsLeft + " s§6)");
} lgp.choose((choosen) -> {
callback.run(); if (choosen != null) {
} getGame().cancelWait();
lgp.stopChoosing();
@EventHandler lgp.getPlayer().getInventory().setItem(8, null);
public void onNight(LGDayEndEvent e) { lgp.getPlayer().updateInventory();
if(e.getGame() == getGame()) { kill(choosen, lgp, this);
LGPlayer lgp = getGame().getDeaths().get(Reason.DICTATOR_SUICIDE); }
if(lgp != null) });
lgp.sendMessage("§8§oDes pensées sombres hantent ton esprit..."); 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...");
}
}
} }

View file

@ -1,112 +1,115 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class REnfantSauvage extends Role{ import java.util.Random;
public REnfantSauvage(LGGame game) {
super(game);
}
@Override public class REnfantSauvage extends Role {
public String getName() { private static final Random random = new Random();
return "§a§lEnfant-Sauvage";
}
@Override public REnfantSauvage(LGGame game) {
public String getFriendlyName() { super(game);
return "de l'"+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lEnfant-Sauvage";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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."; return "de l'" + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Qui veux-tu prendre comme modèle ?"; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "L'"+getName()+"§9 cherche ses marques..."; 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 RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override @Override
public int getTimeout() { public String getTask() {
return 15; return "Qui veux-tu prendre comme modèle ?";
} }
@Override @Override
protected void onNightTurn(LGPlayer player, Runnable callback) { public String getBroadcastedTask() {
player.showView(); return "L'" + getName() + "§9 cherche ses marques...";
player.sendMessage("§6Choisissez votre modèle."); }
player.choose(choosen -> {
if(choosen != null) { @Override
player.stopChoosing(); public RoleType getType() {
player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6."); return RoleType.VILLAGER;
player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle"); }
player.getCache().set("enfant_svg", choosen);
choosen.getCache().set("enfant_svg_d", player); @Override
getPlayers().remove(player);//Pour éviter qu'il puisse avoir plusieurs modèles public RoleWinType getWinType() {
player.hideView(); return RoleWinType.VILLAGE;
callback.run(); }
}
}, player); @Override
} public int getTimeout() {
private static final Random random = new Random(); return 15;
@Override }
protected void onNightTurnTimeout(LGPlayer player) {
player.stopChoosing(); @Override
player.hideView(); protected void onNightTurn(LGPlayer player, Runnable callback) {
LGPlayer choosen = null; player.showView();
while(choosen == null || choosen == player) player.sendMessage("§6Choisissez votre modèle.");
choosen = getGame().getAlive().get(random.nextInt(getGame().getAlive().size())); player.choose(choosen -> {
player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6."); if (choosen != null) {
player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle"); player.stopChoosing();
player.getCache().set("enfant_svg", choosen); player.sendMessage("§6Si §7§l" + choosen.getName() + "§6 meurt, tu deviendras §c§lLoup-Garou§6.");
choosen.getCache().set("enfant_svg_d", player); player.sendActionBarMessage("§7§l" + choosen.getName() + "§6 est ton modèle");
getPlayers().remove(player); 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);
}
@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.isRoleActive()) {
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);
}
}
}
@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.isRoleActive()) {
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);
}
}
}
} }

View file

@ -1,82 +1,84 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import org.bukkit.potion.PotionEffectType;
import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import org.bukkit.potion.PotionEffectType;
import java.util.Comparator; import java.util.Comparator;
public class REnfantSauvageLG extends Role{ public class REnfantSauvageLG extends Role {
public REnfantSauvageLG(LGGame game) { public REnfantSauvageLG(LGGame game) {
super(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 @Override
public String getFriendlyName() { public String getName() {
return "de l'"+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 @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "de l'" + getName();
} }
@Override @Override
public String getDescription() { public String getShortDescription() {
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."; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getTask() { public String getDescription() {
return "Qui veux-tu prendre comme modèle ?"; 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 @Override
public String getBroadcastedTask() { public String getTask() {
return "L'"+getName()+"§9 cherche ses marques..."; return "Qui veux-tu prendre comme modèle ?";
} }
@Override
public RoleType getType() {
return RoleType.LOUP_GAROU;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.LOUP_GAROU;
}
@Override @Override
public int getTimeout() { public String getBroadcastedTask() {
return -1; return "L'" + getName() + "§9 cherche ses marques...";
} }
@Override
public void join(LGPlayer player, boolean sendMessage) {
super.join(player, sendMessage);
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(Comparator.comparingInt(Role::getTurnOrder)); @Override
} public RoleType getType() {
return RoleType.LOUP_GAROU;
lgRole.join(player, false); }
for(LGPlayer lgp : lgRole.getPlayers())
if(lgp != player) @Override
lgp.sendMessage("§7§l"+player.getName()+"§6 a rejoint les §c§lLoups-Garous§6."); 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);
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(Comparator.comparingInt(Role::getTurnOrder));
}
lgRole.join(player, false);
for (LGPlayer lgp : lgRole.getPlayers())
if (lgp != player)
lgp.sendMessage("§7§l" + player.getName() + "§6 a rejoint les §c§lLoups-Garous§6.");
}
} }

View file

@ -1,136 +1,144 @@
package fr.leomelki.loupgarou.roles; 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.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class RFaucheur extends Role{ import java.util.List;
public RFaucheur(LGGame game) { import java.util.Random;
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 lun dentre 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 final Random random = new Random();
@EventHandler(priority = EventPriority.LOWEST) public class RFaucheur extends Role {
public void onKill(LGPlayerKilledEvent e) { private static final Random random = new Random();
if (e.getKilled().getRole() == this && e.getKilled().isRoleActive()) {
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; public RFaucheur(LGGame game) {
for (int i = killedPlace + 1;; i++) { super(game);
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); @Override
e.setReason(Reason.FAUCHEUR); public RoleType getType() {
return RoleType.VILLAGER;
}
if (!killEvent.isCancelled()) @Override
getGame().kill(killEvent.getKilled(), killEvent.getReason(), false); public RoleWinType getWinType() {
} return RoleWinType.VILLAGE;
if (gauche != null) { }
LGPlayerKilledEvent killEvent;
if (droite == null) { @Override
killEvent = new LGPlayerKilledEvent(getGame(), e.getKilled(), e.getReason()); public String getName() {
e.setKilled(gauche); return "§a§lFaucheur";
e.setReason(Reason.FAUCHEUR); }
} else
killEvent = new LGPlayerKilledEvent(getGame(), gauche, Reason.FAUCHEUR); @Override
Bukkit.getPluginManager().callEvent(killEvent); public String getFriendlyName() {
if (!killEvent.isCancelled()) return "du " + getName();
getGame().kill(killEvent.getKilled(), killEvent.getReason(), false); }
}
} @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 lun dentre 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;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onKill(LGPlayerKilledEvent e) {
if (e.getKilled().getRole() == this && e.getKilled().isRoleActive()) {
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);
}
}
}
}
} }

View file

@ -1,115 +1,125 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGPreDayStartEvent; import fr.leomelki.loupgarou.events.LGPreDayStartEvent;
import fr.leomelki.loupgarou.events.LGVampiredEvent; import fr.leomelki.loupgarou.events.LGVampiredEvent;
import org.bukkit.event.EventHandler;
public class RGarde extends Role{ import java.util.Arrays;
public RGarde(LGGame game) { import java.util.List;
super(game);
} public class RGarde extends Role {
@Override private static final List<Reason> reasonsProtected = Arrays.asList(Reason.LOUP_GAROU, Reason.LOUP_BLANC, Reason.GM_LOUP_GAROU, Reason.ASSASSIN);
public RoleType getType() {
return RoleType.VILLAGER; public RGarde(LGGame game) {
} super(game);
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleType getType() {
@Override return RoleType.VILLAGER;
public String getName() { }
return "§a§lGarde";
} @Override
@Override public RoleWinType getWinType() {
public String getFriendlyName() { return RoleWinType.VILLAGE;
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lGarde";
} }
@Override
public String getDescription() { @Override
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 daffilé la même personne."; public String getFriendlyName() {
} return "du " + getName();
@Override }
public String getTask() {
return "Choisis un joueur à protéger."; @Override
} public String getShortDescription() {
@Override return "Tu gagnes avec le §a§lVillage";
public String getBroadcastedTask() { }
return "Le "+getName()+"§9 choisit un joueur à protéger.";
} @Override
public String getDescription() {
@Override 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 daffilé la même personne.";
public int getTimeout() { }
return 15;
} @Override
public String getTask() {
@Override return "Choisis un joueur à protéger.";
protected void onNightTurn(LGPlayer player, Runnable callback) { }
player.showView();
@Override
player.choose(choosen -> { public String getBroadcastedTask() {
if(choosen != null) { return "Le " + getName() + "§9 choisit un joueur à protéger.";
LGPlayer lastProtected = player.getCache().get("garde_lastProtected"); }
if(choosen == lastProtected) {
if(lastProtected == player) @Override
player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière."); public int getTimeout() {
else return 15;
player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière."); }
} else {
if(choosen == player) { @Override
player.sendMessage("§6Tu décides de te protéger toi-même cette nuit."); protected void onNightTurn(LGPlayer player, Runnable callback) {
player.sendActionBarMessage("§9Tu seras protégé."); player.showView();
} else {
player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit."); player.choose(choosen -> {
player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé."); if (choosen != null) {
} LGPlayer lastProtected = player.getCache().get("garde_lastProtected");
choosen.getCache().set("garde_protected", true); if (choosen == lastProtected) {
player.getCache().set("garde_lastProtected", choosen); if (lastProtected == player)
player.stopChoosing(); player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière.");
player.hideView(); else
callback.run(); 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é.");
@Override } else {
protected void onNightTurnTimeout(LGPlayer player) { player.sendMessage("§6Tu vas protéger §7§l" + choosen.getName() + "§6 cette nuit.");
player.getCache().remove("garde_lastProtected"); player.sendActionBarMessage("§7§l" + choosen.getName() + "§9 sera protégé.");
player.stopChoosing(); }
player.hideView(); choosen.getCache().set("garde_protected", true);
//player.sendTitle("§cVous n'avez protégé personne.", "§4Vous avez mis trop de temps à vous décider...", 80); player.getCache().set("garde_lastProtected", choosen);
//player.sendMessage("§cVous n'avez protégé personne cette nuit."); player.stopChoosing();
} player.hideView();
callback.run();
private static final List<Reason> 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"); @Override
e.setReason(Reason.DONT_DIE); protected void onNightTurnTimeout(LGPlayer player) {
} player.getCache().remove("garde_lastProtected");
} player.stopChoosing();
@EventHandler player.hideView();
public void onVampired(LGVampiredEvent e) { //player.sendTitle("§cVous n'avez protégé personne.", "§4Vous avez mis trop de temps à vous décider...", 80);
if(e.getGame() == getGame() && e.getPlayer().getCache().getBoolean("garde_protected")) //player.sendMessage("§cVous n'avez protégé personne cette nuit.");
e.setProtect(true); }
}
@EventHandler @EventHandler
public void onDayStart(LGPreDayStartEvent e) { public void onPlayerKill(LGNightPlayerPreKilledEvent e) {
if(e.getGame() == getGame()) if (e.getGame() == getGame() && reasonsProtected.contains(e.getReason()) && e.getKilled().getCache().getBoolean("garde_protected")) {
for(LGPlayer lgp : getGame().getInGame()) e.getKilled().getCache().remove("garde_protected");
lgp.getCache().remove("garde_protected"); e.setReason(Reason.DONT_DIE);
} }
}
@EventHandler
public void onVampired(LGVampiredEvent e) {
if (e.getGame() == getGame() && e.getPlayer().getCache().getBoolean("garde_protected"))
e.setProtect(true);
}
@EventHandler
public void onDayStart(LGPreDayStartEvent e) {
if (e.getGame() == getGame())
for (LGPlayer lgp : getGame().getInGame())
lgp.getCache().remove("garde_protected");
}
} }

View file

@ -1,106 +1,108 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import org.bukkit.event.EventHandler;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import org.bukkit.event.EventHandler;
public class RGrandMechantLoup extends Role{ public class RGrandMechantLoup extends Role {
public RGrandMechantLoup(LGGame game) { boolean lgDied;
super(game); Runnable callback;
}
@Override public RGrandMechantLoup(LGGame game) {
public String getName() { super(game);
return "§c§lGrand Méchant Loup"; }
}
@Override @Override
public String getFriendlyName() { public String getName() {
return "du "+getName(); return "§c§lGrand Méchant Loup";
} }
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec les §c§lLoups-Garous"; return "du " + getName();
} }
@Override @Override
public String getDescription() { public String getShortDescription() {
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."; return "Tu gagnes avec les §c§lLoups-Garous";
} }
@Override @Override
public String getTask() { public String getDescription() {
return "Choisis un joueur à dévorer."; 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 @Override
public String getBroadcastedTask() { public String getTask() {
return "Le §c§lGrand Méchant Loup§9 n'en a pas terminé..."; return "Choisis un joueur à dévorer.";
} }
@Override
public RoleType getType() { @Override
return RoleType.LOUP_GAROU; public String getBroadcastedTask() {
} return "Le §c§lGrand Méchant Loup§9 n'en a pas terminé...";
@Override }
public RoleWinType getWinType() {
return RoleWinType.LOUP_GAROU; @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;
}
@Override
protected void onNightTurn(LGPlayer player, Runnable callback) {
this.callback = callback;
player.showView();
player.choose(choosen -> {
if (choosen != null && choosen != player) {
player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 va mourir cette nuit");
player.sendMessage("§6Tu as choisi de manger §7§l" + choosen.getName() + "§6.");
getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU);
player.stopChoosing();
player.hideView();
callback.run();
}
});
}
@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);
}
@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(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);
}
} }

View file

@ -1,193 +1,190 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam;
import fr.leomelki.loupgarou.classes.*;
import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.*;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import lombok.Getter;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.event.EventHandler; public class RLoupGarou extends Role {
import org.bukkit.event.EventPriority;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam; @Getter
import fr.leomelki.loupgarou.classes.LGCustomSkin; private final LGChat chat = new LGChat((sender, message) -> "§c" + sender.getName() + " §6» §f" + message);
import fr.leomelki.loupgarou.classes.LGGame; boolean showSkins = false;
import fr.leomelki.loupgarou.classes.LGPlayer; LGVote vote;
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);
}
public RLoupGarou(LGGame game) { @Override
super(game); public String getName() {
} return "§c§lLoup-Garou";
}
@Override @Override
public String getName() { public String getFriendlyName() {
return "§c§lLoup-Garou"; return "des §c§lLoups-Garous";
} }
@Override @Override
public String getFriendlyName() { public String getShortDescription() {
return "des §c§lLoups-Garous"; return "Tu gagnes avec les §c§lLoups-Garous";
} }
@Override @Override
public String getShortDescription() { public String getDescription() {
return "Tu gagnes avec les §c§lLoups-Garous"; 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 @Override
public String getDescription() { public String getTask() {
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."; return "Vote pour la cible à tuer.";
} }
@Override @Override
public String getTask() { public String getBroadcastedTask() {
return "Vote pour la cible à tuer."; return "Les §c§lLoups-Garous§9 choisissent leur cible.";
} }
@Override @Override
public String getBroadcastedTask() { public RoleType getType() {
return "Les §c§lLoups-Garous§9 choisissent leur cible."; return RoleType.LOUP_GAROU;
} }
@Override
public RoleType getType() {
return RoleType.LOUP_GAROU;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.LOUP_GAROU;
}
@Override @Override
public int getTimeout() { public RoleWinType getWinType() {
return 30; return RoleWinType.LOUP_GAROU;
} }
@Getter private final LGChat chat = new LGChat((sender, message) -> "§c"+sender.getName()+" §6» §f"+message);
boolean showSkins = false; @Override
LGVote vote; public int getTimeout() {
@Override return 30;
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) { @Override
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); public void join(LGPlayer player, boolean sendMessage) {
for(LGPlayer lgp : getGame().getAlive()) super.join(player, sendMessage);
if(lgp.getRoleType() == RoleType.LOUP_GAROU) //On peut créer des cheats grâce à ça (qui permettent de savoir qui est lg/inf)
lgp.showView(); for (LGPlayer p : getPlayers())
for(LGPlayer player : getPlayers()) { p.updatePrefix();
player.sendMessage("§6"+getTask()); }
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
player.joinChat(chat); public void onNightTurn(Runnable callback) {
} vote = new LGVote(getTimeout(), getTimeout() / 3, getGame(), false, false, (player, secondsLeft) -> !getPlayers().contains(player) ? "§6C'est au tour " + getFriendlyName() + " §6(§e" + secondsLeft + " s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l" + player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e" + secondsLeft + " seconde" + (secondsLeft > 1 ? "s" : "") + "§6 pour voter");
vote.start(getPlayers(), getPlayers(), ()->{ for (LGPlayer lgp : getGame().getAlive())
onNightTurnEnd(); if (lgp.getRoleType() == RoleType.LOUP_GAROU)
callback.run(); lgp.showView();
}); for (LGPlayer player : getPlayers()) {
} player.sendMessage("§6" + getTask());
private void onNightTurnEnd() { // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
for(LGPlayer lgp : getGame().getAlive()) player.joinChat(chat);
if(lgp.getRoleType() == RoleType.LOUP_GAROU) }
lgp.hideView(); vote.start(getPlayers(), getPlayers(), () -> {
for(LGPlayer player : getPlayers()) { onNightTurnEnd();
player.leaveChat(); 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<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if (entry.getValue().size() > max) {
equal = false;
max = entry.getValue().size();
choosen = entry.getKey();
} else if (entry.getValue().size() == max)
equal = true;
if (equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<>();
for (Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if (entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.LOUP_GAROU)
choosable.add(entry.getKey());
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()))
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();
}
}
LGPlayer choosen = vote.getChoosen();
if(choosen == null) {
if(vote.getVotes().size() > 0) {
int max = 0;
boolean equal = false;
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() > max) {
equal = false;
max = entry.getValue().size();
choosen = entry.getKey();
}else if(entry.getValue().size() == max)
equal = true;
if(equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.LOUP_GAROU)
choosable.add(entry.getKey());
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()))
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();
}
}
} }

View file

@ -1,7 +1,11 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Collections; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
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;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -10,154 +14,156 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import fr.leomelki.loupgarou.classes.LGGame; import java.util.Collections;
import fr.leomelki.loupgarou.classes.LGPlayer;
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{ public class RLoupGarouBlanc extends Role {
private static final ItemStack skip; private static final ItemStack skip;
static {
skip = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = skip.getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§8Passez votre tour"));
skip.setItemMeta(meta);
}
public RLoupGarouBlanc(LGGame game) { static {
super(game); skip = new ItemStack(Material.IRON_NUGGET);
} ItemMeta meta = skip.getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§8Passez votre tour"));
skip.setItemMeta(meta);
}
@Override Runnable callback;
public String getName() { RLoupGarou lg;
return "§c§lLoup Blanc";
}
@Override public RLoupGarouBlanc(LGGame game) {
public String getFriendlyName() { super(game);
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes §7§lSEUL"; return "§c§lLoup Blanc";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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."; return "du " + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Tu peux choisir un §c§lLoup-Garou§6 à éliminer, ou te rendormir."; return "Tu gagnes §7§lSEUL";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "Le "+getName()+"§9 pourrait faire un ravage cette nuit..."; 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 RoleType getType() { @Override
return RoleType.LOUP_GAROU; public String getTask() {
} return "Tu peux choisir un §c§lLoup-Garou§6 à éliminer, ou te rendormir.";
@Override }
public RoleWinType getWinType() {
return RoleWinType.SEUL; @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;
}
@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(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(getGame().getPlugin(), 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.");
}
@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());
}
}
@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(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(getGame().getPlugin(), 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());
}
}
} }

View file

@ -1,8 +1,14 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Arrays; import fr.leomelki.loupgarou.MainLg;
import java.util.Collections; 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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -16,213 +22,212 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import java.util.Arrays;
import fr.leomelki.loupgarou.classes.LGCustomItems; import java.util.Collections;
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{ public class RLoupGarouNoir extends Role {
static final ItemStack[] items = new ItemStack[9]; static final ItemStack[] items = new ItemStack[9];
static final ItemStack[] skip = new ItemStack[9]; static final ItemStack[] skip = new ItemStack[9];
static {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§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) { static {
super(game); items[3] = new ItemStack(Material.IRON_NUGGET);
} ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§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];
}
@Override LGVote vote;
public String getName() { Runnable callback;
return "§c§lLoup Noir"; LGPlayer toInfect;
} boolean inMenu = false;
@Override public RLoupGarouNoir(LGGame game) {
public String getFriendlyName() { super(game);
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec les §c§lLoups-Garous"; return "§c§lLoup Noir";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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."; return "du " + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Veux-tu infecter la cible du vote ?"; return "Tu gagnes avec les §c§lLoups-Garous";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "Le "+getName()+"§9 décide s'il veut infecter sa cible."; 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 RoleType getType() {
return RoleType.LOUP_GAROU;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.LOUP_GAROU;
}
@Override @Override
public int getTimeout() { public String getTask() {
return 15; return "Veux-tu infecter la cible du vote ?";
} }
@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; @Override
public String getBroadcastedTask() {
private void closeInventory(Player p) { return "Le " + getName() + "§9 décide s'il veut infecter sa cible.";
inMenu = false; }
p.closeInventory();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { @Override
e.setCancelled(true); public RoleType getType() {
closeInventory(player); return RoleType.LOUP_GAROU;
lgp.sendMessage("§6Tu n'as rien fait cette nuit."); }
lgp.hideView();
callback.run(); @Override
}else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName()) && toInfect != null) { public RoleWinType getWinType() {
e.setCancelled(true); return RoleWinType.LOUP_GAROU;
closeInventory(player); }
player.updateInventory();
closeInventory(player); @Override
public int getTimeout() {
lgp.getCache().set("has_infected", true); return 15;
toInfect.getCache().set("infected", true); }
getPlayers().remove(lgp);
toInfect.getCache().set("just_infected", true); @Override
lgp.sendActionBarMessage("§9§lVous infectez §9"+toInfect.getName()); public boolean hasPlayersLeft() {
lgp.sendMessage("§6Tu as infecté §7§l"+toInfect.getName()+"§6."); return super.hasPlayersLeft() && getGame().getDeaths().containsKey(Reason.LOUP_GAROU);
lgp.stopChoosing(); }
getGame().getDeaths().remove(Reason.LOUP_GAROU, toInfect);
lgp.hideView(); public void openInventory(Player player) {
callback.run(); inMenu = true;
} Inventory inventory = Bukkit.createInventory(null, 9, "§7Infecter " + toInfect.getName() + " ?");
} inventory.setContents(toInfect == null ? skip.clone() : items.clone());
@EventHandler(priority = EventPriority.HIGHEST) player.closeInventory();
public void onDayStart(LGNightEndEvent e) { player.openInventory(inventory);
if(e.getGame() == getGame()) }
for(LGPlayer player : getGame().getAlive()) {
if(player.getCache().getBoolean("just_infected")) { @Override
player.getCache().remove("just_infected"); protected void onNightTurn(LGPlayer player, Runnable callback) {
player.sendMessage("§6Tu as été infecté pendant la nuit."); toInfect = getGame().getDeaths().get(Reason.LOUP_GAROU);
player.sendMessage("§6§oTu gagnes désormais avec les §c§l§oLoups-Garous§6§o."); if (toInfect.getRoleType() == RoleType.LOUP_GAROU)
for(Role role : getGame().getRoles()) toInfect = null;
if(role instanceof RLoupGarou) player.showView();
if(!player.isDead()) {//Si il n'a pas été tué je ne sais comment this.callback = callback;
role.join(player, false); openInventory(player.getPlayer());
player.getPlayer().getInventory().setItemInOffHand(new ItemStack(LGCustomItems.getItem(player))); }
}
@Override
for(LGPlayer lgp : getGame().getInGame()) { protected void onNightTurnTimeout(LGPlayer player) {
if(lgp.getRoleType() == RoleType.LOUP_GAROU) player.getPlayer().getInventory().setItem(8, null);
lgp.sendMessage("§7§l"+player.getName()+"§6 s'est fait infecter pendant la nuit."); player.stopChoosing();
else closeInventory(player.getPlayer());
lgp.sendMessage("§6Un joueur a été §c§linfecté§6 pendant la nuit."); player.getPlayer().updateInventory();
} player.hideView();
//player.sendTitle("§cVous n'infectez personne", "§4Vous avez mis trop de temps à vous décider...", 80);
if(getGame().checkEndGame()) player.sendMessage("§6Tu n'as rien fait cette nuit.");
e.setCancelled(true); }
}
} private void closeInventory(Player p) {
} inMenu = false;
p.closeInventory();
@Override }
public void join(LGPlayer player, boolean sendMessage) {
super.join(player, sendMessage); @EventHandler
for(Role role : getGame().getRoles()) public void onInventoryClick(InventoryClickEvent e) {
if(role instanceof RLoupGarou) ItemStack item = e.getCurrentItem();
role.join(player, false); Player player = (Player) e.getWhoClicked();
} LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), 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(getGame().getPlugin(), (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());
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (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());
}
} }

View file

@ -1,96 +1,105 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import org.bukkit.event.EventHandler;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.chat.LGChat; import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGPreDayStartEvent; import fr.leomelki.loupgarou.events.LGPreDayStartEvent;
import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent;
import org.bukkit.event.EventHandler;
public class RMedium extends Role{ public class RMedium extends Role {
public RMedium(LGGame game) { public RMedium(LGGame game) {
super(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 @Override
public String receive(LGPlayer sender, String message) { public RoleType getType() {
return "§7"+sender.getName()+"§6 » §f"+message; return RoleType.VILLAGER;
} }
@Override @Override
public String send(LGPlayer sender, String message) { public RoleWinType getWinType() {
return getName()+"§6 » §f"+message; return RoleWinType.VILLAGE;
} }
}); @Override
} public String getName() {
@EventHandler return "§a§lMédium";
public void onRoleTurn(LGRoleTurnEndEvent e) { }
if(e.getGame() == getGame())
if(e.getPreviousRole() instanceof RLoupGarou) @Override
for(LGPlayer lgp : getPlayers()) public String getFriendlyName() {
if(lgp.getChat() != getGame().getSpectatorChat() && lgp.isRoleActive()) { return "du " + getName();
lgp.sendMessage("§6§oTu peux de nouveau parler aux morts..."); }
joinChat(lgp);
} @Override
} public String getShortDescription() {
return "Tu gagnes avec le §a§lVillage";
@EventHandler }
public void onDay(LGPreDayStartEvent e) {
if(e.getGame() == getGame()) @Override
for(LGPlayer lgp : getPlayers()) public String getDescription() {
if(lgp.isRoleActive()) 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.";
lgp.leaveChat(); }
}
@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.isRoleActive()) {
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())
if (lgp.isRoleActive())
lgp.leaveChat();
}
} }

View file

@ -1,104 +1,112 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.List;
import java.util.Random;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGDayStartEvent; import fr.leomelki.loupgarou.events.LGDayStartEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class RMontreurDOurs extends Role{ import java.util.List;
public RMontreurDOurs(LGGame game) { import java.util.Random;
super(game);
}
@Override
public RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override
public String getName() {
return "§a§lMontreur d'Ours";
}
@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 matin, ton Ours va renifler tes voisins et grognera si l'un d'eux est hostile aux Villageois.";
}
@Override
public String getTask() {
return "";
}
@Override
public String getBroadcastedTask() {
return "";
}
@Override
public int getTimeout() {
return -1;
}
private static final Random random = new Random();
private int lastNight = -1;
@EventHandler(priority = EventPriority.LOWEST) public class RMontreurDOurs extends Role {
public void onDay(LGDayStartEvent e) { private static final Random random = new Random();
if (e.getGame() == getGame() && getPlayers().size() > 0) { private int lastNight = -1;
if(lastNight == getGame().getNight())
return;
lastNight = getGame().getNight();
List<?> original = MainLg.getInstance().getConfig().getList("spawns");
for(LGPlayer target : getPlayers()) {
if(!target.isRoleActive())
continue;
int size = original.size();
int killedPlace = target.getPlace();
for (int i = killedPlace + 1;; i++) { public RMontreurDOurs(LGGame game) {
if (i == size) super(game);
i = 0; }
LGPlayer lgp = getGame().getPlacements().get(i);
if (lgp != null && !lgp.isDead()) { @Override
if(lgp.getRoleWinType() == RoleWinType.VILLAGE || lgp.getRoleWinType() == RoleWinType.NONE) public RoleType getType() {
break; return RoleType.VILLAGER;
else{ }
getGame().broadcastMessage("§6La bête du "+getName()+"§6 grogne...");
return; @Override
} public RoleWinType getWinType() {
} return RoleWinType.VILLAGE;
if (lgp == target)// Fait un tour complet }
break;
} @Override
for (int i = killedPlace - 1;; i--) { public String getName() {
if (i == -1) return "§a§lMontreur d'Ours";
i = size - 1; }
LGPlayer lgp = getGame().getPlacements().get(i);
if (lgp != null && !lgp.isDead()) { @Override
if(lgp.getRoleWinType() == RoleWinType.VILLAGE || lgp.getRoleWinType() == RoleWinType.NONE) public String getFriendlyName() {
break; return "du " + getName();
else{ }
getGame().broadcastMessage("§6La bête du "+getName()+"§6 grogne...");
return; @Override
} public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
if (lgp == target)// Fait un tour complet }
break;
} @Override
} public String getDescription() {
} return "Tu gagnes avec le §a§lVillage§f. Chaque matin, ton Ours va renifler tes voisins et grognera si l'un d'eux est hostile aux Villageois.";
} }
@Override
public String getTask() {
return "";
}
@Override
public String getBroadcastedTask() {
return "";
}
@Override
public int getTimeout() {
return -1;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onDay(LGDayStartEvent e) {
if (e.getGame() == getGame() && getPlayers().size() > 0) {
if (lastNight == getGame().getNight())
return;
lastNight = getGame().getNight();
List<?> original = MainLg.getInstance().getConfig().getList("spawns");
for (LGPlayer target : getPlayers()) {
if (!target.isRoleActive())
continue;
int size = original.size();
int killedPlace = target.getPlace();
for (int i = killedPlace + 1; ; i++) {
if (i == size)
i = 0;
LGPlayer lgp = getGame().getPlacements().get(i);
if (lgp != null && !lgp.isDead()) {
if (lgp.getRoleWinType() == RoleWinType.VILLAGE || lgp.getRoleWinType() == RoleWinType.NONE)
break;
else {
getGame().broadcastMessage("§6La bête du " + getName() + "§6 grogne...");
return;
}
}
if (lgp == target)// 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()) {
if (lgp.getRoleWinType() == RoleWinType.VILLAGE || lgp.getRoleWinType() == RoleWinType.NONE)
break;
else {
getGame().broadcastMessage("§6La bête du " + getName() + "§6 grogne...");
return;
}
}
if (lgp == target)// Fait un tour complet
break;
}
}
}
}
} }

View file

@ -1,73 +1,81 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent; import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent;
import org.bukkit.event.EventHandler;
public class RPetiteFille extends Role{ import java.util.Arrays;
public RPetiteFille(LGGame game) { import java.util.List;
super(game);
} public class RPetiteFille extends Role {
@Override final List<String> customNames = Arrays.asList("Loup Glouton", "Loup Méchant", "Loup Burlesque", "Loup Peureux", "Loup Malingre", "Loup Gentil", "Loup Tueur", "Loup Énervé", "Loup Docteur");
public RoleType getType() {
return RoleType.VILLAGER; public RPetiteFille(LGGame game) {
} super(game);
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleType getType() {
@Override return RoleType.VILLAGER;
public String getName() { }
return "§a§lPetite Fille";
} @Override
@Override public RoleWinType getWinType() {
public String getFriendlyName() { return RoleWinType.VILLAGE;
return "de la "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lPetite Fille";
} }
@Override
public String getDescription() { @Override
return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner les §c§lLoups§f."; public String getFriendlyName() {
} return "de la " + getName();
@Override }
public String getTask() {
return ""; @Override
} public String getShortDescription() {
@Override return "Tu gagnes avec le §a§lVillage";
public String getBroadcastedTask() { }
return "";
} @Override
@Override public String getDescription() {
public int getTimeout() { return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner les §c§lLoups§f.";
return -1; }
}
@Override
final List<String> customNames = Arrays.asList("Loup Glouton", "Loup Méchant", "Loup Burlesque", "Loup Peureux", "Loup Malingre", "Loup Gentil", "Loup Tueur", "Loup Énervé", "Loup Docteur"); public String getTask() {
return "";
@EventHandler }
public void onChangeRole(LGRoleTurnEndEvent e) {
if(e.getGame() == getGame()) { @Override
if(e.getNewRole() instanceof RLoupGarou) public String getBroadcastedTask() {
for(Role role : getGame().getRoles()) return "";
if(role instanceof RLoupGarou) { }
RLoupGarou lgRole = (RLoupGarou)role;
for(LGPlayer player : getPlayers()) @Override
if(!player.getCache().getBoolean("infected") && player.isRoleActive()) public int getTimeout() {
player.joinChat(lgRole.getChat(), (sender, message)-> "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message, true); return -1;
break; }
}
if(e.getPreviousRole() instanceof RLoupGarou) @EventHandler
for(LGPlayer player : getPlayers()) public void onChangeRole(LGRoleTurnEndEvent e) {
if(!player.getCache().getBoolean("infected") && player.isRoleActive()) if (e.getGame() == getGame()) {
player.leaveChat(); 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.isRoleActive())
player.joinChat(lgRole.getChat(), (sender, message) -> "§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.isRoleActive())
player.leaveChat();
}
}
} }

View file

@ -1,8 +1,11 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Arrays; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot;
import java.util.Collections; 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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -17,193 +20,196 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; import java.util.Arrays;
import fr.leomelki.loupgarou.MainLg; import java.util.Collections;
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 RPirate extends Role{ public class RPirate extends Role {
static final ItemStack[] items = new ItemStack[9]; static final ItemStack[] items = new ItemStack[9];
static {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§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) { static {
super(game); items[3] = new ItemStack(Material.IRON_NUGGET);
} ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§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);
}
@Override Runnable callback;
public String getName() { boolean inMenu = false;
return "§a§lPirate";
}
@Override public RPirate(LGGame game) {
public String getFriendlyName() { super(game);
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes avec le §a§lVillage"; return "§a§lPirate";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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"; return "du " + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Veux-tu prendre quelqu'un en otage ?"; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "Le "+getName()+"§9 aiguise son crochet..."; 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 RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override @Override
public int getTimeout() { public String getTask() {
return 15; return "Veux-tu prendre quelqu'un en otage ?";
} }
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; @Override
public String getBroadcastedTask() {
private void closeInventory(Player p) { return "Le " + getName() + "§9 aiguise son crochet...";
inMenu = false; }
p.closeInventory();
} @Override
@EventHandler public RoleType getType() {
public void onInventoryClick(InventoryClickEvent e) { return RoleType.VILLAGER;
ItemStack item = e.getCurrentItem(); }
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player); @Override
public RoleWinType getWinType() {
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return; return RoleWinType.VILLAGE;
}
@Override
public int getTimeout() {
return 15;
}
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.");
}
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(getGame().getPlugin(), 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(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") && e.getKilled().isRoleActive()) {
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(getGame().getPlugin(), player);
if (lgp.getRole() == this) {
if (e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) {
e.setCancelled(true);
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(getGame().getPlugin(), (Player) e.getPlayer());
if (player.getRole() == this && inMenu) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().openInventory(e.getInventory());
}
}.runTaskLater(MainLg.getInstance(), 1);
}
}
}
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(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") && e.getKilled().isRoleActive()) {
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(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) {
e.setCancelled(true);
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(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().openInventory(e.getInventory());
}
}.runTaskLater(MainLg.getInstance(), 1);
}
}
}
} }

View file

@ -1,9 +1,16 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.ArrayList; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import java.util.Arrays; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import java.util.Collections; 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.events.LGPreDayStartEvent;
import fr.leomelki.loupgarou.utils.VariousUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -19,268 +26,267 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import java.util.ArrayList;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import java.util.Arrays;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import java.util.Collections;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityMetadata; public class RPretre extends Role {
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; static final ItemStack[] items = new ItemStack[9];
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.events.LGPreDayStartEvent;
import fr.leomelki.loupgarou.utils.VariousUtils;
public class RPretre extends Role{ static {
static final ItemStack[] items = new ItemStack[9]; items[3] = new ItemStack(Material.IRON_NUGGET);
static { ItemMeta meta = items[3].getItemMeta();
items[3] = new ItemStack(Material.IRON_NUGGET); meta.setDisplayName("§7§lNe rien faire");
ItemMeta meta = items[3].getItemMeta(); meta.setLore(Collections.singletonList("§8Passez votre tour"));
meta.setDisplayName("§7§lNe rien faire"); items[3].setItemMeta(meta);
meta.setLore(Collections.singletonList("§8Passez votre tour")); items[5] = new ItemStack(Material.ROTTEN_FLESH);
items[3].setItemMeta(meta); meta = items[5].getItemMeta();
items[5] = new ItemStack(Material.ROTTEN_FLESH); meta.setDisplayName("§2§lRessuciter");
meta = items[5].getItemMeta(); meta.setLore(Arrays.asList(
meta.setDisplayName("§2§lRessuciter"); "§8Tu peux ressusciter un §a§lVillageois",
meta.setLore(Arrays.asList( "§8mort précédemment pendant la partie."));
"§8Tu peux ressusciter un §a§lVillageois", items[5].setItemMeta(meta);
"§8mort précédemment pendant la partie.")); }
items[5].setItemMeta(meta);
}
public RPretre(LGGame game) { final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
super(game); final ArrayList<LGPlayer> ressucited = new ArrayList<>();
} Runnable callback;
boolean inMenu = false;
@Override public RPretre(LGGame game) {
public String getName() { super(game);
return "§a§lPrêtre"; }
}
@Override @Override
public String getFriendlyName() { public String getName() {
return "du "+getName(); return "§a§lPrêtre";
} }
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "du " + getName();
} }
@Override @Override
public String getDescription() { public String getShortDescription() {
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."; return "Tu gagnes avec le §a§lVillage";
} }
@Override @Override
public String getTask() { public String getDescription() {
return "Veux-tu ressusciter un allié défunt ?"; 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 @Override
public String getBroadcastedTask() { public String getTask() {
return "Le "+getName()+"§9 récite ses ouvrages..."; return "Veux-tu ressusciter un allié défunt ?";
} }
@Override
public RoleType getType() {
return RoleType.VILLAGER;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
}
@Override @Override
public int getTimeout() { public String getBroadcastedTask() {
return 30; return "Le " + getName() + "§9 récite ses ouvrages...";
} }
@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éssusciter quelqu'un ?");
inventory.setContents(items.clone());
player.closeInventory();
player.openInventory(inventory);
}
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
@Override
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
for(LGPlayer lgp : getGame().getInGame())
if(lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == player.getRoleType())){
if(lgp.getPlayer() != null) {
player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer());
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
meta.setEntityID(lgp.getPlayer().getEntityId());
meta.setMetadata(Collections.singletonList(new WrappedWatchableObject(invisible, (byte) 0)));
meta.sendPacket(player.getPlayer());
}
}else
player.getPlayer().hidePlayer(getGame().getPlugin(), 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) { @Override
if(player.getPlayer() != null) { public RoleType getType() {
for(LGPlayer lgp : getGame().getInGame()) return RoleType.VILLAGER;
if(lgp.getPlayer() != null && lgp != player) }
player.getPlayer().hidePlayer(getGame().getPlugin(), lgp.getPlayer());
}
}
boolean inMenu = false; @Override
final ArrayList<LGPlayer> ressucited = new ArrayList<>(); public RoleWinType getWinType() {
return RoleWinType.VILLAGE;
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(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) { @Override
e.setCancelled(true); public int getTimeout() {
closeInventory(player); return 30;
lgp.sendMessage("§6Tu n'as rien fait cette nuit."); }
hidePlayers(lgp);
lgp.hideView(); @Override
callback.run(); public boolean hasPlayersLeft() {
}else if(item.getItemMeta().getDisplayName().equals(items[5].getItemMeta().getDisplayName())) { for (LGPlayer pretre : getPlayers())
e.setCancelled(true); for (LGPlayer lgp : getGame().getInGame())
closeInventory(player); if (lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == pretre.getRoleType()))
player.getInventory().setItem(8, items[3]); return super.hasPlayersLeft();
player.updateInventory(); return false;
//Pour éviter les missclick }
WrapperPlayServerHeldItemSlot held = new WrapperPlayServerHeldItemSlot();
held.setSlot(0); public void openInventory(Player player) {
held.sendPacket(player); inMenu = true;
lgp.sendMessage("§6Choisissez qui réssusciter."); Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu réssusciter quelqu'un ?");
lgp.canSelectDead = true; inventory.setContents(items.clone());
lgp.choose(choosen -> { player.closeInventory();
if(choosen != null) { player.openInventory(inventory);
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) { @Override
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6."); protected void onNightTurn(LGPlayer player, Runnable callback) {
}else if(lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) { player.showView();
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait pas partie du §a§lVillage§6."); for (LGPlayer lgp : getGame().getInGame())
} else { if (lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == player.getRoleType())) {
player.getInventory().setItem(8, null); if (lgp.getPlayer() != null) {
player.updateInventory(); player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer());
lgp.stopChoosing(); WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
lgp.canSelectDead = false; meta.setEntityID(lgp.getPlayer().getEntityId());
lgp.sendMessage("§6Tu as ramené §7§l"+choosen.getName()+"§6 à la vie."); meta.setMetadata(Collections.singletonList(new WrappedWatchableObject(invisible, (byte) 0)));
lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 sera réssuscité"); meta.sendPacket(player.getPlayer());
}
} else
player.getPlayer().hidePlayer(getGame().getPlugin(), 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(getGame().getPlugin(), lgp.getPlayer());
}
}
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(getGame().getPlugin(), 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éssusciter.");
lgp.canSelectDead = true;
lgp.choose(choosen -> {
if (choosen != null) {
if (!choosen.isDead())
lgp.sendMessage("§7§l" + choosen.getName() + "§c n'est pas mort.");
else if (lgp.getRoleType() == RoleType.LOUP_GAROU && choosen.getRoleType() == RoleType.NEUTRAL) {
lgp.sendMessage("§7§l" + choosen.getName() + "§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6.");
} else if (lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) {
lgp.sendMessage("§7§l" + choosen.getName() + "§c ne faisait pas partie du §a§lVillage§6.");
} else {
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.stopChoosing();
lgp.canSelectDead = false;
lgp.sendMessage("§6Tu as ramené §7§l" + choosen.getName() + "§6 à la vie.");
lgp.sendActionBarMessage("§7§l" + choosen.getName() + "§6 sera réssuscité");
ressucited.add(choosen); ressucited.add(choosen);
getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes. getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes.
choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6."); choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6.");
hidePlayers(lgp); hidePlayers(lgp);
lgp.hideView(); lgp.hideView();
callback.run(); callback.run();
} }
} }
}, lgp); }, lgp);
} }
} }
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) {
e.setCancelled(true);
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éssuscité 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 @EventHandler
VariousUtils.setWarning(lgp.getPlayer(), true); public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
getGame().updateRoleScoreboard(); LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if (lgp.getRole() == this) {
getGame().broadcastMessage("§7§l"+lgp.getName()+"§6 a été ressuscité cette nuit."); 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éssuscité 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(getGame().getPlugin(), lgp.getPlayer());
}
}
ressucited.clear();
}
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if (e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player) e.getPlayer());
if (player.getRole() == this && inMenu) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().openInventory(e.getInventory());
}
}.runTaskLater(MainLg.getInstance(), 1);
}
}
}
for(LGPlayer player : getGame().getInGame())
if(player.getPlayer() != null && player != lgp) {
player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer());
}
}
ressucited.clear();
}
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().openInventory(e.getInventory());
}
}.runTaskLater(MainLg.getInstance(), 1);
}
}
}
} }

View file

@ -3,66 +3,76 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
public class RPronostiqueur extends Role{ public class RPronostiqueur extends Role {
public RPronostiqueur(LGGame game) { public RPronostiqueur(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.VILLAGER; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getName() { }
return "§a§lPronostiqueur";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§a§lPronostiqueur";
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "du " + getName();
} }
@Override
public String getDescription() { @Override
return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner un joueur et découvrir s'il est gentil ou non. Cependant, dans certaines parties, vos pronostiques ne sont pas exacts..."; public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
@Override }
public String getTask() {
return "Choisis un joueur sur lequel pronostiquer."; @Override
} public String getDescription() {
@Override return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner un joueur et découvrir s'il est gentil ou non. Cependant, dans certaines parties, vos pronostiques ne sont pas exacts...";
public String getBroadcastedTask() { }
return "Le "+getName()+"§9 s'apprête à pronostiquer...";
} @Override
@Override public String getTask() {
public int getTimeout() { return "Choisis un joueur sur lequel pronostiquer.";
return 15; }
}
@Override
@Override public String getBroadcastedTask() {
protected void onNightTurn(LGPlayer player, Runnable callback) { return "Le " + getName() + "§9 s'apprête à pronostiquer...";
player.showView(); }
player.choose(choosen -> { @Override
if(choosen != null && choosen != player) { public int getTimeout() {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); return 15;
String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant"; }
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est "+gentilMechant);
player.sendMessage("§6Votre instinct vous dit que §7§l"+choosen.getName()+"§6 est "+gentilMechant+"§6."); @Override
player.stopChoosing(); protected void onNightTurn(LGPlayer player, Runnable callback) {
player.hideView(); player.showView();
callback.run();
} player.choose(choosen -> {
}); if (choosen != null && choosen != player) {
} //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
@Override String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant";
protected void onNightTurnTimeout(LGPlayer player) { player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 est " + gentilMechant);
player.stopChoosing(); player.sendMessage("§6Votre instinct vous dit que §7§l" + choosen.getName() + "§6 est " + gentilMechant + "§6.");
player.hideView(); player.stopChoosing();
} player.hideView();
callback.run();
}
});
}
@Override
protected void onNightTurnTimeout(LGPlayer player) {
player.stopChoosing();
player.hideView();
}
} }

View file

@ -1,10 +1,15 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.ArrayList; import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot;
import java.util.Arrays; import fr.leomelki.loupgarou.MainLg;
import java.util.Collections; import fr.leomelki.loupgarou.classes.LGGame;
import java.util.List; import fr.leomelki.loupgarou.classes.LGPlayer;
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;
import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -19,287 +24,290 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; import java.util.ArrayList;
import fr.leomelki.loupgarou.MainLg; import java.util.Arrays;
import fr.leomelki.loupgarou.classes.LGGame; import java.util.Collections;
import fr.leomelki.loupgarou.classes.LGPlayer; import java.util.List;
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.LGPyromaneGasoilEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RPyromane extends Role{ public class RPyromane extends Role {
static final ItemStack[] items = new ItemStack[9]; static final ItemStack[] items = new ItemStack[9];
static final ItemStack cancel; static final ItemStack cancel;
static final ItemStack nothing; static final ItemStack nothing;
static {
cancel = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = cancel.getItemMeta();
meta.setDisplayName("§7§lAnnuler");
meta.setLore(Collections.singletonList("§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(Collections.singletonList(
"§8Recouvres deux joueurs d'essence"));
items[5].setItemMeta(meta);
}
public RPyromane(LGGame game) { static {
super(game); cancel = new ItemStack(Material.IRON_NUGGET);
} ItemMeta meta = cancel.getItemMeta();
meta.setDisplayName("§7§lAnnuler");
meta.setLore(Collections.singletonList("§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(Collections.singletonList(
"§8Recouvres deux joueurs d'essence"));
items[5].setItemMeta(meta);
}
@Override Runnable callback;
public String getName() { boolean inMenu = false;
return "§6§lPyromane"; LGPlayer first;
}
@Override public RPyromane(LGGame game) {
public String getFriendlyName() { super(game);
return "du "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getName() {
return "Tu gagnes §7§lSEUL"; return "§6§lPyromane";
} }
@Override @Override
public String getDescription() { public String getFriendlyName() {
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."; return "du " + getName();
} }
@Override @Override
public String getTask() { public String getShortDescription() {
return "Que veux-tu faire cette nuit ?"; return "Tu gagnes §7§lSEUL";
} }
@Override @Override
public String getBroadcastedTask() { public String getDescription() {
return "Le "+getName()+"§9 joue avec une allumette..."; 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 RoleType getType() { @Override
return RoleType.NEUTRAL; public String getTask() {
} return "Que veux-tu faire cette nuit ?";
@Override }
public RoleWinType getWinType() {
return RoleWinType.SEUL; @Override
} public String getBroadcastedTask() {
return "Le " + getName() + "§9 joue avec une allumette...";
@Override }
public int getTimeout() {
return 30; @Override
} public RoleType getType() {
return RoleType.NEUTRAL;
Runnable callback; }
public void openInventory(Player player) { @Override
inMenu = true; public RoleWinType getWinType() {
Inventory inventory = Bukkit.createInventory(null, 9, "§7Que veux-tu faire ?"); return RoleWinType.SEUL;
ItemStack[] content = items.clone(); }
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(!lgp.getCache().has("pyromane_essence")) @Override
lgp.getCache().set("pyromane_essence", new ArrayList<>()); public int getTimeout() {
if(lgp.getCache().<List<LGPlayer>>get("pyromane_essence").size() == 0) return 30;
content[3] = nothing; }
inventory.setContents(content);
player.closeInventory(); public void openInventory(Player player) {
player.openInventory(inventory); inMenu = true;
} Inventory inventory = Bukkit.createInventory(null, 9, "§7Que veux-tu faire ?");
@Override ItemStack[] content = items.clone();
protected void onNightTurn(LGPlayer player, Runnable callback) { LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
first = null; if (!lgp.getCache().has("pyromane_essence"))
player.showView(); lgp.getCache().set("pyromane_essence", new ArrayList<>());
this.callback = callback; if (lgp.getCache().<List<LGPlayer>>get("pyromane_essence").size() == 0)
openInventory(player.getPlayer()); content[3] = nothing;
} inventory.setContents(content);
@Override player.closeInventory();
protected void onNightTurnTimeout(LGPlayer player) { player.openInventory(inventory);
if(first != null) { }
List<LGPlayer> liste = player.getCache().get("pyromane_essence");
LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), first); @Override
Bukkit.getPluginManager().callEvent(event); protected void onNightTurn(LGPlayer player, Runnable callback) {
if(event.isCancelled()) first = null;
player.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisé."); player.showView();
else { this.callback = callback;
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil..."); openInventory(player.getPlayer());
liste.add(event.getPlayer()); }
}
} @Override
player.getPlayer().getInventory().setItem(8, null); protected void onNightTurnTimeout(LGPlayer player) {
player.stopChoosing(); if (first != null) {
closeInventory(player.getPlayer()); List<LGPlayer> liste = player.getCache().get("pyromane_essence");
player.getPlayer().updateInventory(); LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), first);
player.hideView(); Bukkit.getPluginManager().callEvent(event);
player.sendMessage("§6Tu n'as rien fait cette nuit."); 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.");
}
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(getGame().getPlugin(), 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().<List<LGPlayer>>get("pyromane_essence").size() != 0) {
List<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
for (LGPlayer scndPlayer : liste) {
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(choosen -> {
if (choosen != null) {
if (choosen == first) {
lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l" + choosen.getName() + "§6.");
return;
}
List<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
if (liste.contains(choosen)) {
lgp.sendMessage("§7§l" + choosen.getName() + "§c est déjà recouvert de gasoil.");
return;
}
if (first == choosen) {
lgp.sendMessage("§cVous avez déjà sélectionné §7§l" + choosen.getName() + "§c.");
return;
}
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.sendMessage("§6Tu as versé du gasoil sur §7§l" + choosen.getName() + "§6.");
lgp.sendActionBarMessage("§6§7§l" + choosen.getName() + "§6 est recouvert de gasoil");
if (first != null || getGame().getAlive().size() == 2) {
lgp.hideView();
lgp.stopChoosing();
LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), choosen);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
lgp.sendMessage("§7§l" + event.getPlayer().getName() + "§c est immunisée.");
else {
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
if (first != null) {
event = new LGPyromaneGasoilEvent(getGame(), first);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
lgp.sendMessage("§7§l" + event.getPlayer().getName() + "§c est immunisée.");
else {
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
}
callback.run();
} else {
lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil.");
first = choosen;
}
}
}, lgp);
}
}
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if (lgp.getRole() == this) {
if (e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(cancel.getItemMeta().getDisplayName())) {
e.setCancelled(true);
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<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
//Au cas le mec soit rez
liste.remove(e.getKilled());
}
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if (e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (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());
}
}
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(getGame().getPlugin(), 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().<List<LGPlayer>>get("pyromane_essence").size() != 0) {
List<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
for(LGPlayer scndPlayer : liste) {
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(choosen -> {
if(choosen != null) {
if(choosen == first) {
lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l"+choosen.getName()+"§6.");
return;
}
List<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
if(liste.contains(choosen)) {
lgp.sendMessage("§7§l"+choosen.getName()+"§c est déjà recouvert de gasoil.");
return;
}
if(first == choosen) {
lgp.sendMessage("§cVous avez déjà sélectionné §7§l"+choosen.getName()+"§c.");
return;
}
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.sendMessage("§6Tu as versé du gasoil sur §7§l"+choosen.getName()+"§6.");
lgp.sendActionBarMessage("§6§7§l"+choosen.getName()+"§6 est recouvert de gasoil");
if(first != null || getGame().getAlive().size() == 2) {
lgp.hideView();
lgp.stopChoosing();
LGPyromaneGasoilEvent event = new LGPyromaneGasoilEvent(getGame(), choosen);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled())
lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée.");
else {
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
if(first != null) {
event = new LGPyromaneGasoilEvent(getGame(), first);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled())
lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée.");
else {
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
}
callback.run();
} else {
lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil.");
first = choosen;
}
}
}, lgp);
}
}
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(cancel.getItemMeta().getDisplayName())) {
e.setCancelled(true);
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<LGPlayer> liste = lgp.getCache().get("pyromane_essence");
//Au cas le mec soit rez
liste.remove(e.getKilled());
}
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (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());
}
}
} }

View file

@ -1,7 +1,10 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Collections; 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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -16,208 +19,218 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot; import java.util.Collections;
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{ public class RSorciere extends Role {
private static final ItemStack[] items = new ItemStack[4]; private static final ItemStack[] items = new ItemStack[4];
private static final ItemStack cancel; private static final ItemStack cancel;
static {
items[0] = new ItemStack(Material.PURPLE_DYE, 1);
ItemMeta meta = items[0].getItemMeta();
meta.setDisplayName("§a§lPotion de vie");
meta.setLore(Collections.singletonList("§2Sauve la cible des §c§lLoups§2."));
items[0].setItemMeta(meta);
items[1] = new ItemStack(Material.IRON_NUGGET);
meta = items[1].getItemMeta();
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(Collections.singletonList("§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 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(getGame().getPlugin(), player);
if (lgp.getRole() != this || item == null || item.getItemMeta() == null) static {
return; items[0] = new ItemStack(Material.PURPLE_DYE, 1);
ItemMeta meta = items[0].getItemMeta();
meta.setDisplayName("§a§lPotion de vie");
meta.setLore(Collections.singletonList("§2Sauve la cible des §c§lLoups§2."));
items[0].setItemMeta(meta);
items[1] = new ItemStack(Material.IRON_NUGGET);
meta = items[1].getItemMeta();
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(Collections.singletonList("§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);
}
if (item.getItemMeta().getDisplayName().equals(items[0].getItemMeta().getDisplayName()) && sauver != null) {// Potion de vie boolean inMenu = false;
e.setCancelled(true); private LGPlayer sauver;
closeInventory(player); private Runnable callback;
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(getGame().getPlugin(), 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); public RSorciere(LGGame game) {
} super(game);
} }
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) { @Override
if(e.getInventory() instanceof CraftInventoryCustom) { public RoleType getType() {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); return RoleType.VILLAGER;
if(player.getRole() == this && inMenu) { }
new BukkitRunnable() {
@Override
@Override public RoleWinType getWinType() {
public void run() { return RoleWinType.VILLAGE;
e.getPlayer().openInventory(e.getInventory()); }
}
}.runTaskLater(MainLg.getInstance(), 1); @Override
} public String getName() {
} return "§a§lSorcière";
} }
private void kill(LGPlayer choosen, LGPlayer player) { @Override
player.getPlayer().getInventory().setItem(8, null); public String getFriendlyName() {
player.getPlayer().updateInventory(); return "de la " + getName();
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."); @Override
player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 a été tué."); public String getShortDescription() {
player.hideView(); return "Tu gagnes avec le §a§lVillage";
callback.run(); }
}
private void saveLife(LGPlayer player) { @Override
player.getCache().set("witch_used_life", true); public String getDescription() {
getGame().getDeaths().remove(Reason.LOUP_GAROU, sauver); 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.";
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(); @Override
callback.run(); 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;
}
@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 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);
}
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(getGame().getPlugin(), 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(getGame().getPlugin(), 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(getGame().getPlugin(), (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();
}
} }

View file

@ -1,8 +1,15 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Arrays; import fr.leomelki.loupgarou.MainLg;
import java.util.Collections; 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.events.LGVampiredEvent;
import fr.leomelki.loupgarou.utils.VariableCache;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
@ -15,188 +22,193 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import java.util.Arrays;
import fr.leomelki.loupgarou.classes.LGGame; import java.util.Collections;
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.events.LGVampiredEvent;
import fr.leomelki.loupgarou.utils.VariableCache;
public class RSurvivant extends Role{ public class RSurvivant extends Role {
public RSurvivant(LGGame game) { boolean inMenu;
super(game); Runnable callback;
}
@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(getGame().getPlugin(), player).getCache();
if(cache.<Integer>get("survivant_left") > 0) {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Collections.singletonList("§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.<Integer>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(Collections.singletonList("§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; public RSurvivant(LGGame game) {
@Override super(game);
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(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getType() == Material.IRON_NUGGET) { @Override
e.setCancelled(true); public RoleType getType() {
lgp.sendMessage("§4§oTu es sans défense..."); return RoleType.NEUTRAL;
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().<Integer>get("survivant_left")-1);
lgp.getCache().set("survivant_protected", true);
lgp.hideView();
callback.run();
}
}
@EventHandler @Override
public void onPlayerKill(LGNightPlayerPreKilledEvent e) { public RoleWinType getWinType() {
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.getKilled().isRoleActive()) { return RoleWinType.NONE;
e.setReason(Reason.DONT_DIE); }
}
} @Override
@EventHandler public String getName() {
public void onVampired(LGVampiredEvent e) { return "§d§lSurvivant";
if(e.getGame() == getGame() && e.getPlayer().getCache().getBoolean("survivant_protected")) }
e.setProtect(true);
} @Override
@EventHandler public String getFriendlyName() {
public void onDayStart(LGPreDayStartEvent e) { return "du " + getName();
if(e.getGame() == getGame()) }
for(LGPlayer lgp : getGame().getInGame())
if(lgp.isRoleActive()) @Override
lgp.getCache().remove("survivant_protected"); public String getShortDescription() {
} return "Tu gagnes si tu remplis ton objectif";
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) { @Override
if(e.getInventory() instanceof CraftInventoryCustom) { public String getDescription() {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer()); 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.";
if(player.getRole() == this && inMenu) { }
new BukkitRunnable() {
@Override
@Override public String getTask() {
public void run() { return "Veux-tu utiliser une protection cette nuit ?";
e.getPlayer().openInventory(e.getInventory()); }
}
}.runTaskLater(MainLg.getInstance(), 1); @Override
} public String getBroadcastedTask() {
} return "Le " + getName() + "§9 décide s'il veut se protéger.";
} }
@Override
public int getTimeout() {
return 15;
}
@EventHandler
public void onWin(LGGameEndEvent e) { public void openInventory(Player player) {
if(e.getGame() == getGame() && getPlayers().size() > 0 && e.getWinType() != LGWinType.ANGE) { inMenu = true;
for(LGPlayer lgp : getPlayers()) Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu te protéger ?");
e.getWinners().add(lgp); ItemStack[] items = new ItemStack[9];
new BukkitRunnable() { VariableCache cache = LGPlayer.thePlayer(getGame().getPlugin(), player).getCache();
if (cache.<Integer>get("survivant_left") > 0) {
@Override items[3] = new ItemStack(Material.IRON_NUGGET);
public void run() { ItemMeta meta = items[3].getItemMeta();
getGame().broadcastMessage("§6§oLe "+getName()+"§6§o a rempli son objectif."); meta.setDisplayName("§7§lNe rien faire");
} meta.setLore(Collections.singletonList("§8Passez votre tour"));
}.runTaskAsynchronously(MainLg.getInstance()); items[3].setItemMeta(meta);
} items[5] = new ItemStack(Material.GOLD_NUGGET);
} meta = items[5].getItemMeta();
meta.setDisplayName("§2§lSe protéger (§6§l" + cache.<Integer>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(Collections.singletonList("§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);
}
@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(getGame().getPlugin(), 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().<Integer>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.getKilled().isRoleActive()) {
e.setReason(Reason.DONT_DIE);
}
}
@EventHandler
public void onVampired(LGVampiredEvent e) {
if (e.getGame() == getGame() && e.getPlayer().getCache().getBoolean("survivant_protected"))
e.setProtect(true);
}
@EventHandler
public void onDayStart(LGPreDayStartEvent e) {
if (e.getGame() == getGame())
for (LGPlayer lgp : getGame().getInGame())
if (lgp.isRoleActive())
lgp.getCache().remove("survivant_protected");
}
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if (e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (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());
}
}
} }

View file

@ -1,219 +1,217 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.*;
import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints;
import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.*;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; public class RVampire extends Role {
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.classes.LGCustomItems; @Getter
import fr.leomelki.loupgarou.classes.LGGame; private final LGChat chat = new LGChat((sender, message) -> "§5" + sender.getName() + " §6» §f" + message);
import fr.leomelki.loupgarou.classes.LGPlayer; int nextCanInfect = 0;
import fr.leomelki.loupgarou.classes.LGVote; LGVote vote;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints;
import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent;
import fr.leomelki.loupgarou.events.LGVampiredEvent;
import lombok.Getter;
public class RVampire extends Role{ public RVampire(LGGame game) {
super(game);
}
public RVampire(LGGame game) { @Override
super(game); public String getName() {
} return "§5§lVampire";
}
@Override @Override
public String getName() { public String getFriendlyName() {
return "§5§lVampire"; return "des §5§lVampires";
} }
@Override @Override
public String getFriendlyName() { public String getShortDescription() {
return "des §5§lVampires"; return "Tu gagnes avec les §5§lVampires";
} }
@Override @Override
public String getShortDescription() { public String getDescription() {
return "Tu gagnes avec les §5§lVampires"; return "Tu gagnes avec les §5§lVampires§f. Chaque nuit, tu te réunis avec tes compères pour décider d'une victime à transformer en §5§lVampire§f... Lorsqu'une transformation a lieu, tous les §5§lVampires§f doivent se reposer la nuit suivante. Un joueur transformé perd tous les pouvoirs liés à son ancien rôle, et gagne avec les §5§lVampires§f.";
} }
@Override @Override
public String getDescription() { public String getTask() {
return "Tu gagnes avec les §5§lVampires§f. Chaque nuit, tu te réunis avec tes compères pour décider d'une victime à transformer en §5§lVampire§f... Lorsqu'une transformation a lieu, tous les §5§lVampires§f doivent se reposer la nuit suivante. Un joueur transformé perd tous les pouvoirs liés à son ancien rôle, et gagne avec les §5§lVampires§f."; return "Votez pour une cible à mordre.";
} }
@Override @Override
public String getTask() { public String getBroadcastedTask() {
return "Votez pour une cible à mordre."; return "Les §5§lVampires§9 choisissent leur cible.";
} }
@Override @Override
public String getBroadcastedTask() { public RoleType getType() {
return "Les §5§lVampires§9 choisissent leur cible."; return RoleType.VAMPIRE;
} }
@Override
public RoleType getType() {
return RoleType.VAMPIRE;
}
@Override
public RoleWinType getWinType() {
return RoleWinType.VAMPIRE;
}
@Override @Override
public int getTimeout() { public RoleWinType getWinType() {
return 30; return RoleWinType.VAMPIRE;
} }
@Override
public boolean hasPlayersLeft() {
return nextCanInfect < getGame().getNight() && super.hasPlayersLeft();
}
@Getter private final LGChat chat = new LGChat((sender, message) -> "§5"+sender.getName()+" §6» §f"+message);
int nextCanInfect = 0;
LGVote vote;
@Override
public void join(LGPlayer player, boolean sendMessage) {
super.join(player, sendMessage);
for(LGPlayer p : getPlayers())
p.updatePrefix();
}
public void onNightTurn(Runnable callback) { @Override
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter"); public int getTimeout() {
for(LGPlayer lgp : getGame().getAlive()) return 30;
if(lgp.getRoleType() == RoleType.VAMPIRE) }
lgp.showView();
for(LGPlayer player : getPlayers()) { @Override
player.sendMessage("§6"+getTask()); public boolean hasPlayersLeft() {
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100); return nextCanInfect < getGame().getNight() && super.hasPlayersLeft();
player.joinChat(chat); }
}
vote.start(getPlayers(), getPlayers(), ()->{ @Override
onNightTurnEnd(); public void join(LGPlayer player, boolean sendMessage) {
callback.run(); super.join(player, sendMessage);
}, getPlayers()); for (LGPlayer p : getPlayers())
} p.updatePrefix();
private void onNightTurnEnd() { }
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.VAMPIRE) public void onNightTurn(Runnable callback) {
lgp.hideView(); vote = new LGVote(getTimeout(), getTimeout() / 3, getGame(), false, false, (player, secondsLeft) -> !getPlayers().contains(player) ? "§6C'est au tour " + getFriendlyName() + " §6(§e" + secondsLeft + " s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l" + player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e" + secondsLeft + " seconde" + (secondsLeft > 1 ? "s" : "") + "§6 pour voter");
for(LGPlayer player : getPlayers()) for (LGPlayer lgp : getGame().getAlive())
player.leaveChat(); if (lgp.getRoleType() == RoleType.VAMPIRE)
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();
}, getPlayers());
}
private void onNightTurnEnd() {
for (LGPlayer lgp : getGame().getAlive())
if (lgp.getRoleType() == RoleType.VAMPIRE)
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<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if (entry.getValue().size() > max) {
equal = false;
max = entry.getValue().size();
choosen = entry.getKey();
} else if (entry.getValue().size() == max)
equal = true;
if (equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<>();
for (Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if (entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.VAMPIRE)
choosable.add(entry.getKey());
if (choosable.size() > 0)
choosen = choosable.get(getGame().getRandom().nextInt(choosable.size()));
}
}
}
if (choosen != null) {
if (choosen.getRoleType() == RoleType.LOUP_GAROU || choosen.getRoleType() == RoleType.VAMPIRE) {
for (LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
return;
} else if (choosen.getRole() instanceof RChasseurDeVampire) {
for (LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
getGame().kill(getPlayers().get(getPlayers().size() - 1), Reason.CHASSEUR_DE_VAMPIRE);
return;
}
LGVampiredEvent event = new LGVampiredEvent(getGame(), choosen);
Bukkit.getPluginManager().callEvent(event);
if (event.isImmuned()) {
for (LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
return;
} else if (event.isProtect()) {
for (LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est protégée.");
return;
}
for (LGPlayer player : getPlayers())
player.sendMessage("§7§l" + choosen.getName() + " s'est transformé en §5§lVampire§6.");
choosen.sendMessage("§6Tu as été infecté par les §5§lVampires §6pendant la nuit. Tu as perdu tes pouvoirs.");
choosen.sendMessage("§6§oTu gagnes désormais avec les §5§l§oVampires§6§o.");
choosen.getCache().set("vampire", true);
choosen.getCache().set("just_vampire", true);
nextCanInfect = getGame().getNight() + 1;
join(choosen, false);
LGCustomItems.updateItem(choosen);
} else
for (LGPlayer player : getPlayers())
player.sendMessage("§6Personne n'a été infecté.");
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onDayStart(LGNightEndEvent e) {
if (e.getGame() == getGame())
for (LGPlayer player : getGame().getAlive()) {
if (player.getCache().getBoolean("just_vampire")) {
player.getCache().remove("just_vampire");
for (LGPlayer lgp : getGame().getInGame()) {
if (lgp.getRoleType() == RoleType.VAMPIRE)
lgp.sendMessage("§7§l" + player.getName() + "§6 s'est transformé en §5§lVampire§6...");
else
lgp.sendMessage("§6Quelqu'un s'est transformé en §5§lVampire§6...");
}
if (getGame().checkEndGame())
e.setCancelled(true);
}
}
}
/* @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.VAMPIRE)
for (LGPlayer lgp : getGame().getInGame())
if (lgp.getRoleWinType() == RoleWinType.VAMPIRE)//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()))
e.setPrefix(e.getPrefix() + "§5");
}
@EventHandler
public void onCustomItemChange(LGCustomItemChangeEvent e) {
if (e.getGame() == getGame())
if (e.getPlayer().getCache().getBoolean("vampire"))
e.getConstraints().add(LGCustomItemsConstraints.VAMPIRE_INFECTE.getName());
}
LGPlayer choosen = vote.getChoosen();
if(choosen == null) {
if(vote.getVotes().size() > 0) {
int max = 0;
boolean equal = false;
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() > max) {
equal = false;
max = entry.getValue().size();
choosen = entry.getKey();
}else if(entry.getValue().size() == max)
equal = true;
if(equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.VAMPIRE)
choosable.add(entry.getKey());
if(choosable.size() > 0)
choosen = choosable.get(getGame().getRandom().nextInt(choosable.size()));
}
}
}
if(choosen != null) {
if(choosen.getRoleType() == RoleType.LOUP_GAROU || choosen.getRoleType() == RoleType.VAMPIRE) {
for(LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
return;
}else if(choosen.getRole() instanceof RChasseurDeVampire) {
for(LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
getGame().kill(getPlayers().get(getPlayers().size()-1), Reason.CHASSEUR_DE_VAMPIRE);
return;
}
LGVampiredEvent event = new LGVampiredEvent(getGame(), choosen);
Bukkit.getPluginManager().callEvent(event);
if(event.isImmuned()) {
for(LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est immunisée.");
return;
}else if(event.isProtect()) {
for(LGPlayer player : getPlayers())
player.sendMessage("§cVotre cible est protégée.");
return;
}
for(LGPlayer player : getPlayers())
player.sendMessage("§7§l"+choosen.getName()+" s'est transformé en §5§lVampire§6.");
choosen.sendMessage("§6Tu as été infecté par les §5§lVampires §6pendant la nuit. Tu as perdu tes pouvoirs.");
choosen.sendMessage("§6§oTu gagnes désormais avec les §5§l§oVampires§6§o.");
choosen.getCache().set("vampire", true);
choosen.getCache().set("just_vampire", true);
nextCanInfect = getGame().getNight()+1;
join(choosen, false);
LGCustomItems.updateItem(choosen);
}else
for(LGPlayer player : getPlayers())
player.sendMessage("§6Personne n'a été infecté.");
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onDayStart(LGNightEndEvent e) {
if(e.getGame() == getGame())
for(LGPlayer player : getGame().getAlive()) {
if(player.getCache().getBoolean("just_vampire")) {
player.getCache().remove("just_vampire");
for(LGPlayer lgp : getGame().getInGame()) {
if(lgp.getRoleType() == RoleType.VAMPIRE)
lgp.sendMessage("§7§l"+player.getName()+"§6 s'est transformé en §5§lVampire§6...");
else
lgp.sendMessage("§6Quelqu'un s'est transformé en §5§lVampire§6...");
}
if(getGame().checkEndGame())
e.setCancelled(true);
}
}
}
/* @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.VAMPIRE)
for(LGPlayer lgp : getGame().getInGame())
if(lgp.getRoleWinType() == RoleWinType.VAMPIRE)//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()))
e.setPrefix(e.getPrefix()+"§5");
}
@EventHandler
public void onCustomItemChange(LGCustomItemChangeEvent e) {
if(e.getGame() == getGame())
if(e.getPlayer().getCache().getBoolean("vampire"))
e.getConstraints().add(LGCustomItemsConstraints.VAMPIRE_INFECTE.getName());
}
} }

View file

@ -2,44 +2,53 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
public class RVillageois extends Role{ public class RVillageois extends Role {
public RVillageois(LGGame game) { public RVillageois(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.VILLAGER; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getName() { }
return "§a§lVillageois";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§a§lVillageois";
return "des "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "des " + getName();
} }
@Override
public String getDescription() { @Override
return "Tu gagnes avec le §a§lVillage§f. Tu ne disposes d'aucun pouvoir particulier, uniquement ta perspicacité et ta force de persuasion."; public String getShortDescription() {
} return "Tu gagnes avec le §a§lVillage";
@Override }
public String getTask() {
return ""; @Override
} public String getDescription() {
@Override return "Tu gagnes avec le §a§lVillage§f. Tu ne disposes d'aucun pouvoir particulier, uniquement ta perspicacité et ta force de persuasion.";
public String getBroadcastedTask() { }
return "";
} @Override
@Override public String getTask() {
public int getTimeout() { return "";
return -1; }
}
@Override
public String getBroadcastedTask() {
return "";
}
@Override
public int getTimeout() {
return -1;
}
} }

View file

@ -3,68 +3,77 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
public class RVoyante extends Role{ public class RVoyante extends Role {
public RVoyante(LGGame game) { public RVoyante(LGGame game) {
super(game); super(game);
} }
@Override
public RoleType getType() { @Override
return RoleType.VILLAGER; public RoleType getType() {
} return RoleType.VILLAGER;
@Override }
public RoleWinType getWinType() {
return RoleWinType.VILLAGE; @Override
} public RoleWinType getWinType() {
@Override return RoleWinType.VILLAGE;
public String getName() { }
return "§a§lVoyante";
} @Override
@Override public String getName() {
public String getFriendlyName() { return "§a§lVoyante";
return "de la "+getName(); }
}
@Override @Override
public String getShortDescription() { public String getFriendlyName() {
return "Tu gagnes avec le §a§lVillage"; return "de la " + getName();
} }
@Override @Override
public String getDescription() { public String getShortDescription() {
return "Tu gagnes avec le §a§lVillage§f. Chaque nuit, tu peux espionner un joueur et découvrir sa véritable identité..."; return "Tu gagnes avec le §a§lVillage";
} }
@Override
public String getTask() { @Override
return "Choisis un joueur dont tu veux connnaître l'identité."; 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 getBroadcastedTask() {
return "La "+getName()+"§9 s'apprête à sonder un joueur..."; @Override
} public String getTask() {
@Override return "Choisis un joueur dont tu veux connnaître l'identité.";
public int getTimeout() { }
return 15;
} @Override
public String getBroadcastedTask() {
@Override return "La " + getName() + "§9 s'apprête à sonder un joueur...";
protected void onNightTurn(LGPlayer player, Runnable callback) { }
player.showView();
@Override
player.choose(choosen -> { public int getTimeout() {
if(choosen != null && choosen != player) { return 15;
//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."); @Override
player.stopChoosing(); protected void onNightTurn(LGPlayer player, Runnable callback) {
player.hideView(); player.showView();
callback.run();
} player.choose(choosen -> {
}); if (choosen != null && choosen != player) {
} //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
@Override player.sendActionBarMessage("§e§l" + choosen.getName() + "§6 est §e§l" + choosen.getRole().getName());
protected void onNightTurnTimeout(LGPlayer player) { player.sendMessage("§6Tu découvres que §7§l" + choosen.getName() + "§6 est " + choosen.getRole().getName() + "§6.");
player.stopChoosing(); player.stopChoosing();
player.hideView(); player.hideView();
//player.sendTitle("§cVous n'avez regardé aucun rôle", "§4Vous avez mis trop de temps à vous décider...", 80); callback.run();
//player.sendMessage("§cVous n'avez pas utilisé votre pouvoir cette nuit."); }
} });
}
@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.");
}
} }

View file

@ -1,123 +1,150 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
public abstract class Role implements Listener{ import java.util.ArrayList;
@Getter @Setter private int waitedPlayers; import java.util.concurrent.ThreadLocalRandom;
@Getter private final ArrayList<LGPlayer> 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 class Role implements Listener {
public abstract String getFriendlyName(); @Getter
public abstract String getShortDescription(); private final ArrayList<LGPlayer> players = new ArrayList<>();
public abstract String getDescription(); @Getter
public abstract String getTask(); private final LGGame game;
public abstract String getBroadcastedTask(); @Getter
public RoleType getType(LGPlayer lgp) { @Setter
return getType(); private int waitedPlayers;
}
public RoleWinType getWinType(LGPlayer lgp) { public Role(LGGame game) {
return getWinType(); this.game = game;
} Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance());
public RoleType getType() {return null;} FileConfiguration config = MainLg.getInstance().getConfig();
public RoleWinType getWinType() {return null;} String roleConfigName = "role." + getClass().getSimpleName().substring(1);
/** if (config.contains(roleConfigName))
* @return Timeout in second for this role waitedPlayers = config.getInt(roleConfigName);
*/ }
public abstract int getTimeout();
public void onNightTurn(Runnable callback) { public abstract String getName();
ArrayList<LGPlayer> players = (ArrayList<LGPlayer>) getPlayers().clone();
new Runnable() { public abstract String getFriendlyName();
@Override public abstract String getShortDescription();
public void run() {
getGame().cancelWait(); public abstract String getDescription();
if(players.size() == 0) {
onTurnFinish(callback); public abstract String getTask();
return;
} public abstract String getBroadcastedTask();
LGPlayer player = players.remove(0);
if(player.isRoleActive()) { public RoleType getType(LGPlayer lgp) {
getGame().wait(getTimeout(), ()->{ return getType();
try { }
Role.this.onNightTurnTimeout(player);
}catch(Exception err) { public RoleWinType getWinType(LGPlayer lgp) {
System.out.println("Error when timeout role"); return getWinType();
err.printStackTrace(); }
}
this.run(); public RoleType getType() {
}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); return null;
player.sendMessage("§6"+getTask()); }
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
onNightTurn(player, this); public RoleWinType getWinType() {
} else { return null;
getGame().wait(getTimeout(), ()->{}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)"); }
Runnable run = this;
new BukkitRunnable() { /**
* @return Timeout in second for this role
@Override */
public void run() { public abstract int getTimeout();
run.run();
} public void onNightTurn(Runnable callback) {
}.runTaskLater(MainLg.getInstance(), 20*(ThreadLocalRandom.current().nextInt(getTimeout()/3*2-4)+4)); ArrayList<LGPlayer> players = (ArrayList<LGPlayer>) getPlayers().clone();
} new Runnable() {
}
}.run(); @Override
} public void run() {
public void join(LGPlayer player, boolean sendMessage) { getGame().cancelWait();
System.out.println(player.getName()+" est "+getName()); if (players.size() == 0) {
players.add(player); onTurnFinish(callback);
if(player.getRole() == null) return;
player.setRole(this); }
waitedPlayers--; LGPlayer player = players.remove(0);
if(sendMessage) { if (player.isRoleActive()) {
player.sendTitle("§6Tu es "+getName(), "§e"+getShortDescription(), 200); getGame().wait(getTimeout(), () -> {
player.sendMessage("§6Tu es "+getName()+"§6."); try {
player.sendMessage("§6Description : §f"+getDescription()); Role.this.onNightTurnTimeout(player);
} } catch (Exception err) {
} System.out.println("Error when timeout role");
public void join(LGPlayer player) { err.printStackTrace();
join(player, !getGame().isStarted()); }
LGCustomItems.updateItem(player); this.run();
} }, (currentPlayer, secondsLeft) -> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour " + getFriendlyName() + " §6(§e" + secondsLeft + " s§6)");
public boolean hasPlayersLeft() { player.sendMessage("§6" + getTask());
return getPlayers().size() > 0; // player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
} onNightTurn(player, this);
protected void onNightTurnTimeout(LGPlayer player) {} } else {
protected void onNightTurn(LGPlayer player, Runnable callback) {} getGame().wait(getTimeout(), () -> {
protected void onTurnFinish(Runnable callback) { }, (currentPlayer, secondsLeft) -> currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour " + getFriendlyName() + " §6(§e" + secondsLeft + " s§6)");
callback.run(); Runnable run = this;
} new BukkitRunnable() {
public int getTurnOrder() {
try { @Override
RoleSort role = RoleSort.valueOf(getClass().getSimpleName().substring(1)); public void run() {
return role == null ? -1 : role.ordinal(); run.run();
}catch(Throwable e) { }
return -1; }.runTaskLater(MainLg.getInstance(), 20 * (ThreadLocalRandom.current().nextInt(getTimeout() / 3 * 2 - 4) + 4));
} }
}//En combientième ce rôle doit être appellé }
}.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é
} }

View file

@ -1,25 +1,25 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
public enum RoleSort { public enum RoleSort {
ChienLoup, ChienLoup,
EnfantSauvage, EnfantSauvage,
Cupidon, Cupidon,
Garde, Garde,
Survivant, Survivant,
Voyante, Voyante,
Detective, Detective,
Dictateur, Dictateur,
Pretre, Pretre,
LoupGarou, LoupGarou,
LoupGarouNoir, LoupGarouNoir,
GrandMechantLoup, GrandMechantLoup,
LoupGarouBlanc, LoupGarouBlanc,
Assassin, Assassin,
Pyromane, Pyromane,
ChasseurDeVampire, ChasseurDeVampire,
Vampire, Vampire,
Pirate, Pirate,
Bouffon, Bouffon,
Sorciere, Sorciere,
Corbeau Corbeau
} }

Some files were not shown because too many files have changed in this diff Show more