Fix a lot of warnings

This commit is contained in:
Ethanell 2020-09-07 23:35:55 +02:00
parent 8a1602af63
commit 53f1508a01
46 changed files with 465 additions and 615 deletions

View file

@ -29,7 +29,6 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
public static final PacketType TYPE =

View file

@ -81,13 +81,12 @@ import fr.leomelki.loupgarou.roles.RVampire;
import fr.leomelki.loupgarou.roles.RVillageois;
import fr.leomelki.loupgarou.roles.RVoyante;
import fr.leomelki.loupgarou.roles.Role;
import fr.leomelki.loupgarou.utils.VariousUtils;
import lombok.Getter;
import lombok.Setter;
public class MainLg extends JavaPlugin{
private static MainLg instance;
@Getter private final HashMap<String, Constructor<? extends Role>> roles = new HashMap<String, Constructor<? extends Role>>();
@Getter private final HashMap<String, Constructor<? extends Role>> roles = new HashMap<>();
@Getter private static final String prefix = ""/*"§7[§9Loup-Garou§7] "*/;
@Getter @Setter private LGGame currentGame;//Because for now, only one game will be playable on one server (flemme)
@ -104,10 +103,10 @@ public class MainLg extends JavaPlugin{
saveConfig();
}
loadConfig();
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
Bukkit.getPluginManager().registerEvents(new CancelListener(), this);
Bukkit.getPluginManager().registerEvents(new VoteListener(), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(), this);
Bukkit.getPluginManager().registerEvents(new JoinListener(this), this);
Bukkit.getPluginManager().registerEvents(new CancelListener(this), this);
Bukkit.getPluginManager().registerEvents(new VoteListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this);
for(Player player : Bukkit.getOnlinePlayers())
@ -118,7 +117,7 @@ public class MainLg extends JavaPlugin{
@Override
public void onPacketSending(PacketEvent event) {
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket());
LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer());
LGPlayer lgp = LGPlayer.thePlayer(instance, event.getPlayer());
if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay())
event.setCancelled(true);
}
@ -137,11 +136,11 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket());
ArrayList<PlayerInfoData> datas = new ArrayList<PlayerInfoData>();
ArrayList<PlayerInfoData> datas = new ArrayList<>();
for(PlayerInfoData data : info.getData()) {
LGPlayer lgp = LGPlayer.thePlayer(Bukkit.getPlayer(data.getProfile().getUUID()));
LGPlayer lgp = LGPlayer.thePlayer(instance, Bukkit.getPlayer(data.getProfile().getUUID()));
if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
WrappedChatComponent displayName = data.getDisplayName();
@ -169,7 +168,7 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) {
@Override
public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
if(player.getGame() != null && player.getGame().isStarted()) {
WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket());
health.setFood(6);
@ -179,12 +178,12 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) {
@Override
public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket());
team.setColor(ChatColor.WHITE);
Player other = Bukkit.getPlayer(team.getName());
if(other == null)return;
LGPlayer lgp = LGPlayer.thePlayer(other);
LGPlayer lgp = LGPlayer.thePlayer(instance, other);
if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
Bukkit.getPluginManager().callEvent(evt2);
@ -198,7 +197,7 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
if(player.getGame() != null) {
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket());
if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId())
@ -237,7 +236,7 @@ public class MainLg extends JavaPlugin{
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'est pas connecté.");
return true;
}
LGGame game = LGPlayer.thePlayer(selected).getGame();
LGGame game = LGPlayer.thePlayer(instance, selected).getGame();
if(game == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+selected.getName()+"§c n'est pas dans une partie.");
return true;
@ -256,7 +255,7 @@ public class MainLg extends JavaPlugin{
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !");
return true;
}
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(instance, player);
if(lgp.getGame() == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+lgp.getName()+"§c n'est pas dans une partie.");
return true;
@ -318,7 +317,7 @@ public class MainLg extends JavaPlugin{
String role = null;
if(args[2].length() <= 2)
try {
Integer i = Integer.valueOf(args[2]);
int i = Integer.parseInt(args[2]);
Object[] array = getRoles().keySet().toArray();
if(array.length <= i) {
sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas.");
@ -369,7 +368,7 @@ public class MainLg extends JavaPlugin{
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if(!sender.hasPermission("loupgarou.admin"))
return new ArrayList<String>(0);
return new ArrayList<>(0);
if(args.length > 1) {
if(args[0].equalsIgnoreCase("roles"))
@ -381,11 +380,11 @@ public class MainLg extends JavaPlugin{
return Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
}else if(args.length == 1)
return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks");
return new ArrayList<String>(0);
return new ArrayList<>(0);
}
private List<String> getStartingList(String startsWith, String... list){
startsWith = startsWith.toLowerCase();
ArrayList<String> returnlist = new ArrayList<String>();
ArrayList<String> returnlist = new ArrayList<>();
if(startsWith.length() == 0)
return Arrays.asList(list);
for(String s : list)
@ -397,7 +396,7 @@ public class MainLg extends JavaPlugin{
int players = 0;
for(String role : roles.keySet())
players += getConfig().getInt("role."+role);
currentGame = new LGGame(players);
currentGame = new LGGame(this, players);
}
@Override
public void onDisable() {

File diff suppressed because one or more lines are too long

View file

@ -75,32 +75,30 @@ public class LGGame implements Listener{
@Getter private final SecureRandom random = new SecureRandom();
@Getter private final int maxPlayers;
@Getter private final ArrayList<LGPlayer> inGame = new ArrayList<LGPlayer>();
@Getter private final ArrayList<Role> roles = new ArrayList<Role>();
@Getter private final ArrayList<LGPlayer> inGame = new ArrayList<>();
@Getter private final ArrayList<Role> roles = new ArrayList<>();
@Getter private final MainLg plugin;
@Getter private boolean started;
@Getter private int night = 0;
private BukkitTask startingTask;
@Getter @Setter private int waitTicks;
@Getter private boolean day;
@Getter public long time = 0;
@Getter private final HashMap<Integer, LGPlayer> placements = new HashMap<Integer, LGPlayer>();
@Getter private final HashMap<Integer, LGPlayer> placements = new HashMap<>();
@Getter private final LGChat spectatorChat = new LGChat((sender, message) -> {
return "§7"+sender.getName()+" §6» §f"+message;
});
@Getter private final LGChat dayChat = new LGChat((sender, message) -> {
return "§e"+sender.getName()+" §6» §f"+message;
});
@Getter private final LGChat spectatorChat = new LGChat((sender, message) -> "§7"+sender.getName()+" §6» §f"+message);
@Getter private final LGChat dayChat = new LGChat((sender, message) -> "§e"+sender.getName()+" §6» §f"+message);
public LGGame(int maxPlayers) {
public LGGame(MainLg mainLg, int maxPlayers) {
this.plugin = mainLg;
this.maxPlayers = maxPlayers;
Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance());
}
@Getter
private final MultipleValueMap<LGPlayerKilledEvent.Reason, LGPlayer> deaths = new MultipleValueMap<LGPlayerKilledEvent.Reason, LGPlayer>();
private final MultipleValueMap<LGPlayerKilledEvent.Reason, LGPlayer> deaths = new MultipleValueMap<>();
public void sendActionBarMessage(String msg) {
WrapperPlayServerChat chat = new WrapperPlayServerChat();
@ -236,11 +234,11 @@ public class LGGame implements Listener{
for(LGPlayer other : getInGame()) {
other.updatePrefix();
if(lgp != other) {
player.hidePlayer(other.getPlayer());
player.showPlayer(other.getPlayer());
player.hidePlayer(plugin, other.getPlayer());
player.showPlayer(plugin, other.getPlayer());
other.getPlayer().hidePlayer(player);
other.getPlayer().showPlayer(player);
other.getPlayer().hidePlayer(plugin, player);
other.getPlayer().showPlayer(plugin, player);
}
}
@ -304,7 +302,7 @@ public class LGGame implements Listener{
//Registering roles
List<?> original = MainLg.getInstance().getConfig().getList("spawns");
List<Object> list = new ArrayList<Object>(original);
List<Object> list = new ArrayList<>(original);
for(LGPlayer lgp : getInGame()) {
List<Double> location = (List<Double>) list.remove(random.nextInt(list.size()));
Player p = lgp.getPlayer();
@ -383,12 +381,7 @@ public class LGGame implements Listener{
updateRoleScoreboard();
//Classe les roles afin de les appeler dans le bon ordre
roles.sort(new Comparator<Role>() {
@Override
public int compare(Role role1, Role role2) {
return role1.getTurnOrder()-role2.getTurnOrder();
}
});
roles.sort(Comparator.comparingInt(Role::getTurnOrder));
//Start day one
nextNight(10);
@ -400,7 +393,7 @@ public class LGGame implements Listener{
roles_.get(lgp.getRole()).increase();
else
roles_.put(lgp.getRole(), new IndexedRole(lgp.getRole()));
ArrayList<IndexedRole> roles = new ArrayList<IndexedRole>(roles_.values());
ArrayList<IndexedRole> roles = new ArrayList<>(roles_.values());
roles.sort((a, b)->{
//TODO fix dégueu juste ici pour le chien loup lg à changer (2x)
return (b.getNumber()+(b.getRole().getType() != RoleType.LOUP_GAROU || b.getRole() instanceof RChienLoupLG || b.getRole() instanceof REnfantSauvageLG ? b.getRole().getType() == RoleType.NEUTRAL ? 0 : 999 : 200) - a.getNumber()-(a.getRole().getType() != RoleType.LOUP_GAROU || a.getRole() instanceof RChienLoupLG || a.getRole() instanceof REnfantSauvageLG ? a.getRole().getType() == RoleType.NEUTRAL ? 0 : 999 : 200));
@ -419,7 +412,7 @@ public class LGGame implements Listener{
lgp.getScoreboard().getLine(i).delete();
}
public List<LGPlayer> getAlive(){
ArrayList<LGPlayer> alive = new ArrayList<LGPlayer>();
ArrayList<LGPlayer> alive = new ArrayList<>();
for(LGPlayer lgp : getInGame())
if(!lgp.isDead())
alive.add(lgp);
@ -444,9 +437,7 @@ public class LGGame implements Listener{
setMayor(getAlive().get(random.nextInt(getAlive().size())));
broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9.");
nextNight();
}, (player, secondsLeft)->{
return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)";
});
}, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)");
mayor.choose((choosen)->{
if(choosen != null) {
mayor.stopChoosing();
@ -474,9 +465,7 @@ public class LGGame implements Listener{
}
}
}.runTaskTimer(MainLg.getInstance(), 1, 1);
LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)->{
return "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "");
});
LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)-> "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : ""));
}
private void nextNight_() {
if(ended)return;
@ -534,13 +523,13 @@ public class LGGame implements Listener{
for(LGPlayer lgp : getInGame())
if(lgp == killed) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
ArrayList<PlayerInfoData> infos = new ArrayList<>();
info.setAction(PlayerInfoAction.REMOVE_PLAYER);
infos.add(new PlayerInfoData(new WrappedGameProfile(lgp.getPlayer().getUniqueId(), lgp.getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(lgp.getName())));
info.setData(infos);
info.sendPacket(lgp.getPlayer());
}else
lgp.getPlayer().hidePlayer(killed.getPlayer());
lgp.getPlayer().hidePlayer(plugin, killed.getPlayer());
if(vote != null)
vote.remove(killed);
@ -594,7 +583,7 @@ public class LGGame implements Listener{
public void endGame(LGWinType winType) {
if(ended)return;
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>();
ArrayList<LGPlayer> winners = new ArrayList<>();
LGGameEndEvent event = new LGGameEndEvent(this, winType, winners);
Bukkit.getPluginManager().callEvent(event);
@ -643,7 +632,7 @@ public class LGGame implements Listener{
team.setMode(1);
team.setName("you_are");
team.sendPacket(lgp.getPlayer());
LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame());
LGPlayer.thePlayer(plugin, lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame());
}
//A remettre pour activer le démarrage automatique
/* wait(30, ()->{
@ -747,9 +736,7 @@ public class LGGame implements Listener{
setMayor(getAlive().get(random.nextInt(getAlive().size())));
broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9.");
startDay();
}, (player, secondsLeft)->{
return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)";
});
}, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)");
mayor.choose((choosen)->{
if(choosen != null) {
mayor.stopChoosing();
@ -816,9 +803,7 @@ public class LGGame implements Listener{
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
broadcastMessage("§9Il est temps de voter pour élire un §5§lCapitaine§9.");
vote = new LGVote(180, 20, this, true, true, (player, secondsLeft)-> {
return player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter";
});
vote = new LGVote(180, 20, this, true, true, (player, secondsLeft)-> player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter");
vote.start(getAlive(), getInGame(), ()->{
if(vote.getChoosen() == null)
setMayor(getAlive().get(random.nextInt(getAlive().size())));
@ -851,9 +836,7 @@ public class LGGame implements Listener{
if(!event.isCancelled()) {
broadcastMessage("§9La phase des votes a commencé.");
isPeopleVote = true;
vote = new LGVote(180, 20, this, false, false, (player, secondsLeft)-> {
return player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter";
});
vote = new LGVote(180, 20, this, false, false, (player, secondsLeft)-> player.getCache().has("vote") ? "§6Tu votes pour §7§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter");
vote.start(getAlive(), getInGame(), ()->{
isPeopleVote = false;
if(vote.getChoosen() == null || (vote.isMayorVote() && getMayor() == null))

View file

@ -1,9 +1,6 @@
package fr.leomelki.loupgarou.classes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -42,11 +39,13 @@ import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn;
import net.minecraft.server.v1_15_R1.WorldType;
public class LGPlayer {
private static final HashMap<Player, LGPlayer> cachedPlayers = new HashMap<Player, LGPlayer>();
public static LGPlayer thePlayer(Player player) {
private static final HashMap<Player, LGPlayer> cachedPlayers = new HashMap<>();
private final MainLg plugin;
public static LGPlayer thePlayer(MainLg plugin, Player player) {
LGPlayer lgp = cachedPlayers.get(player);
if(lgp == null) {
lgp = new LGPlayer(player);
lgp = new LGPlayer(plugin, player);
cachedPlayers.put(player, lgp);
}
return lgp;
@ -64,10 +63,12 @@ public class LGPlayer {
@Getter @Setter private LGGame game;
@Getter @Setter private String latestObjective;
@Getter private CustomScoreboard scoreboard;
public LGPlayer(Player player) {
public LGPlayer(MainLg mainLg, Player player) {
this.plugin = mainLg;
this.player = player;
}
public LGPlayer(String name) {
public LGPlayer(MainLg mainLg, String name) {
this.plugin = mainLg;
this.name = name;
}
@ -139,7 +140,7 @@ public class LGPlayer {
return false;
}
public void choose(LGChooseCallback callback, LGPlayer... blacklisted) {
this.blacklistedChoice = blacklisted == null ? new ArrayList<LGPlayer>(0) : Arrays.asList(blacklisted);
this.blacklistedChoice = blacklisted == null ? new ArrayList<>(0) : Arrays.asList(blacklisted);
this.chooseCallback = callback;
//sendMessage("§7§oTIP: Regardez un joueur et tapez le afin de le sélectionner.");
}
@ -157,17 +158,17 @@ public class LGPlayer {
for(LGPlayer lgp : getGame().getAlive())
if(!lgp.isDead()) {
if(lgp != this && lgp.getPlayer() != null)
getPlayer().showPlayer(lgp.getPlayer());
getPlayer().showPlayer(plugin, lgp.getPlayer());
else{
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setMode(2);
team.setName(lgp.getName());
team.setPrefix(WrappedChatComponent.fromText(""));
team.setPlayers(Arrays.asList(lgp.getName()));
team.setPlayers(Collections.singletonList(lgp.getName()));
team.sendPacket(getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
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);
@ -182,10 +183,10 @@ public class LGPlayer {
//TODO Update prefix for only one guy
public void updatePrefix() {
if(getGame() != null && !isDead() && player != null) {
List<String> meList = Arrays.asList(getName());
List<String> meList = Collections.singletonList(getName());
for(LGPlayer lgp : getGame().getInGame()) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
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);
@ -203,13 +204,13 @@ public class LGPlayer {
public void hideView() {
if(getGame() != null && player != null) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
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(lgp.getPlayer());
getPlayer().hidePlayer(plugin, lgp.getPlayer());
}
info.setData(infos);
info.sendPacket(getPlayer());
@ -224,14 +225,14 @@ public class LGPlayer {
for(LGPlayer lgp : getGame().getInGame()) {
if(lgp == this) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
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(getPlayer());
lgp.getPlayer().showPlayer(getPlayer());
lgp.getPlayer().hidePlayer(plugin, getPlayer());
lgp.getPlayer().showPlayer(plugin, getPlayer());
}
}
}
@ -242,7 +243,7 @@ public class LGPlayer {
WrapperPlayServerPlayerInfo infos = new WrapperPlayServerPlayerInfo();
infos.setAction(PlayerInfoAction.ADD_PLAYER);
WrappedGameProfile gameProfile = new WrappedGameProfile(getPlayer().getUniqueId(), getPlayer().getName());
infos.setData(Arrays.asList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName()))));
infos.setData(Collections.singletonList(new PlayerInfoData(gameProfile, 10, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getPlayer().getName()))));
infos.sendPacket(getPlayer());
//Pour qu'il voit son skin changer (sa main et en f5), on lui dit qu'il respawn (alors qu'il n'est pas mort mais ça marche quand même mdr)
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(DimensionManager.OVERWORLD, 0, WorldType.NORMAL, EnumGamemode.ADVENTURE);
@ -304,7 +305,7 @@ public class LGPlayer {
if(player != null)
for(LGPlayer lgp : getGame().getInGame())
if(lgp != this && lgp.getPlayer() != null)
lgp.getPlayer().hidePlayer(getPlayer());
lgp.getPlayer().hidePlayer(plugin, getPlayer());
muted = true;
}
public void resetMuted() {

View file

@ -11,7 +11,8 @@ public enum LGSound {
AMBIANT_NIGHT(Sound.MUSIC_DISC_MALL),
AMBIANT_DAY(Sound.MUSIC_DISC_MELLOHI);
@Getter Sound sound;
@Getter
final Sound sound;
LGSound(Sound sound){
this.sound = sound;
}

View file

@ -1,13 +1,8 @@
package fr.leomelki.loupgarou.classes;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.StringJoiner;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -36,7 +31,6 @@ import fr.leomelki.loupgarou.utils.VariousUtils;
import lombok.Getter;
import net.minecraft.server.v1_15_R1.DataWatcher;
import net.minecraft.server.v1_15_R1.DataWatcherObject;
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityArmorStand;
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
@ -51,11 +45,11 @@ public class LGVote {
private final LGGame game;
@Getter private List<LGPlayer> participants, viewers;
private final TextGenerator generator;
@Getter private final HashMap<LGPlayer, List<LGPlayer>> votes = new HashMap<LGPlayer, List<LGPlayer>>();
@Getter private final HashMap<LGPlayer, List<LGPlayer>> votes = new HashMap<>();
private int votesSize = 0;
private LGPlayer mayor;
private ArrayList<LGPlayer> latestTop = new ArrayList<LGPlayer>(), blacklisted = new ArrayList<LGPlayer>();
private final boolean positiveVote, randomIfEqual;
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) {
@ -64,7 +58,6 @@ public class LGVote {
this.timeout = timeout;
this.game = game;
this.generator = generator;
this.positiveVote = positiveVote;
this.randomIfEqual = randomIfEqual;
}
public void start(List<LGPlayer> participants, List<LGPlayer> viewers, Runnable callback) {
@ -134,7 +127,7 @@ public class LGVote {
if(equal)
choosen = null;
if(equal && mayor == null && randomIfEqual) {
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>();
ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if(entry.getValue().size() == max)
choosable.add(entry.getKey());
@ -146,7 +139,7 @@ public class LGVote {
player.sendMessage("§9Égalité, le §5§lCapitaine§9 va départager les votes.");
mayor.sendMessage("§6Tu dois choisir qui va mourir.");
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>();
ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if(entry.getValue().size() == max)
choosable.add(entry.getKey());
@ -160,7 +153,7 @@ public class LGVote {
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<LGPlayer>();
ArrayList<LGPlayer> blackListed = new ArrayList<>();
for(LGPlayer player : participants)
if(!choosable.contains(player))
blackListed.add(player);
@ -186,26 +179,22 @@ public class LGVote {
timeout = secondsLeft;
return mayor == player ? "§6Il te reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour délibérer" : "§6Le §5§lCapitaine§6 délibère (§e"+secondsLeft+" s§6)";
});
mayor.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
if(blackListed.contains(choosen))
mayor.sendMessage("§4§oCe joueur n'est pas concerné par le choix.");
else {
for(LGPlayer player : participants)
if(choosable.contains(player))
VariousUtils.setWarning(player.getPlayer(), false);
mayor.choose(choosen -> {
if(choosen != null) {
if(blackListed.contains(choosen))
mayor.sendMessage("§4§oCe joueur n'est pas concerné par le choix.");
else {
for(LGPlayer player : participants)
if(choosable.contains(player))
VariousUtils.setWarning(player.getPlayer(), false);
for(int i = 0;i<choosable.size();i++) {
LGPlayer lgp = choosable.get(i);
showArrow(mayor, null, -mayor.getPlayer().getEntityId()-i);
}
game.cancelWait();
LGVote.this.choosen = choosen;
callback.run();
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();
}
}
});
@ -216,13 +205,9 @@ public class LGVote {
}
public LGChooseCallback getChooseCallback(LGPlayer who) {
return new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null)
vote(who, choosen);
}
return choosen -> {
if(choosen != null)
vote(who, choosen);
};
}
public void vote(LGPlayer voter, LGPlayer voted) {
@ -264,7 +249,7 @@ public class LGVote {
if(votes.containsKey(voted))
votes.get(voted).add(voter);
else
votes.put(voted, new ArrayList<LGPlayer>(Arrays.asList(voter)));
votes.put(voted, new ArrayList<>(Collections.singletonList(voter)));
voter.getCache().set("vote", voted);
updateVotes(voted);
}
@ -292,7 +277,7 @@ public class LGVote {
}
public List<LGPlayer> getVotes(LGPlayer voted){
return votes.containsKey(voted) ? votes.get(voted) : new ArrayList<LGPlayer>(0);
return votes.containsKey(voted) ? votes.get(voted) : new ArrayList<>(0);
}
private void updateVotes(LGPlayer voted) {
@ -311,7 +296,7 @@ public class LGVote {
if(entry.getValue().size() > max)
max = entry.getValue().size();
ArrayList<LGPlayer> last = latestTop;
latestTop = new ArrayList<LGPlayer>();
latestTop = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : votes.entrySet())
if(entry.getValue().size() == max)
latestTop.add(entry.getKey());
@ -383,11 +368,11 @@ public class LGVote {
// spawn.sendPacket(lgp.getPlayer());
}
}
WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)),
noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)),
customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class)),
customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class)),
item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class));
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
WrappedDataWatcherObject customNameVisible = new WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class));
WrappedDataWatcherObject customName = new WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(IChatBaseComponent.class));
WrappedDataWatcherObject item = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(net.minecraft.server.v1_15_R1.ItemStack.class));
private void showVoting(LGPlayer to, LGPlayer ofWho) {
int entityId = -to.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();

View file

@ -9,7 +9,7 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class LGChat {
@Getter private final HashMap<LGPlayer, LGChatCallback> viewers = new HashMap<LGPlayer, LGChatCallback>();
@Getter private final HashMap<LGPlayer, LGChatCallback> viewers = new HashMap<>();
@Getter private final LGChatCallback defaultCallback;
public interface LGChatCallback{

View file

@ -10,5 +10,6 @@ public class LGGameJoinEvent extends LGEvent{
this.player = player;
}
@Getter LGPlayer player;
@Getter
final LGPlayer player;
}

View file

@ -1,7 +1,5 @@
package fr.leomelki.loupgarou.events;
import org.bukkit.event.Cancellable;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import lombok.Getter;

View file

@ -16,7 +16,11 @@ public class LGVoteLeaderChange extends LGEvent{
this.vote = vote;
}
@Getter ArrayList<LGPlayer> latest, now;
@Getter LGVote vote;
@Getter
final ArrayList<LGPlayer> latest;
@Getter
final ArrayList<LGPlayer> now;
@Getter
final LGVote vote;
}

View file

@ -1,5 +1,6 @@
package fr.leomelki.loupgarou.listeners;
import fr.leomelki.loupgarou.MainLg;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -17,13 +18,18 @@ import org.bukkit.event.weather.WeatherChangeEvent;
import fr.leomelki.loupgarou.classes.LGPlayer;
public class CancelListener implements Listener{
private final MainLg plugin;
public CancelListener (MainLg mainLg) {
this.plugin = mainLg;
}
@EventHandler
public void onPluie(WeatherChangeEvent e) {
e.setCancelled(true);
}
@EventHandler
public void onMove(PlayerMoveEvent e) {
LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer());
LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer());
if(lgp.getGame() != null && lgp.getGame().isStarted() && e.getFrom().distanceSquared(e.getTo()) > 0.001)
e.setTo(e.getFrom());
}
@ -58,12 +64,12 @@ public class CancelListener implements Listener{
}
@EventHandler
public void onClickInventory(InventoryClickEvent e) {
if(LGPlayer.thePlayer((Player)e.getWhoClicked()).getGame() != null)
if(LGPlayer.thePlayer(plugin, (Player)e.getWhoClicked()).getGame() != null)
e.setCancelled(true);
}
@EventHandler
public void onClickInventory(PlayerSwapHandItemsEvent e) {
if(LGPlayer.thePlayer(e.getPlayer()).getGame() != null)
if(LGPlayer.thePlayer(plugin, e.getPlayer()).getGame() != null)
e.setCancelled(true);
}
}

View file

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

View file

@ -1,6 +1,6 @@
package fr.leomelki.loupgarou.listeners;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -21,6 +21,11 @@ import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class JoinListener implements Listener{
private final MainLg plugin;
public JoinListener(MainLg mainLg) {
this.plugin = mainLg;
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
@ -29,17 +34,17 @@ public class JoinListener implements Listener{
WrapperPlayServerScoreboardTeam myTeam = new WrapperPlayServerScoreboardTeam();
myTeam.setName(p.getName());
myTeam.setPrefix(WrappedChatComponent.fromText(""));
myTeam.setPlayers(Arrays.asList(p.getName()));
myTeam.setPlayers(Collections.singletonList(p.getName()));
myTeam.setMode(0);
boolean noSpec = p.getGameMode() != GameMode.SPECTATOR;
for (Player player : Bukkit.getOnlinePlayers())
if (player != p) {
if (player.getGameMode() != GameMode.SPECTATOR)
player.hidePlayer(p);
player.hidePlayer(plugin, p);
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setName(player.getName());
team.setPrefix(WrappedChatComponent.fromText(""));
team.setPlayers(Arrays.asList(player.getName()));
team.setPlayers(Collections.singletonList(player.getName()));
team.setMode(0);
team.sendPacket(p);
@ -49,7 +54,7 @@ public class JoinListener implements Listener{
if (e.getJoinMessage() == null || !e.getJoinMessage().equals("joinall")) {
//p.getPlayer().setResourcePack("http://leomelki.fr/mcgames/ressourcepacks/v32/loup_garou.zip");
} else {
LGPlayer lgp = LGPlayer.thePlayer(e.getPlayer());
LGPlayer lgp = LGPlayer.thePlayer(plugin, e.getPlayer());
lgp.showView();
lgp.join(MainLg.getInstance().getCurrentGame());
}
@ -64,7 +69,7 @@ public class JoinListener implements Listener{
public void onResoucePack(PlayerResourcePackStatusEvent e) {
if (e.getStatus() == Status.SUCCESSFULLY_LOADED) {
Player p = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(p);
LGPlayer lgp = LGPlayer.thePlayer(plugin, p);
lgp.showView();
lgp.join(MainLg.getInstance().getCurrentGame());
} else if(e.getStatus() == Status.DECLINED || e.getStatus() == Status.FAILED_DOWNLOAD)
@ -73,7 +78,7 @@ public class JoinListener implements Listener{
@EventHandler
public void onLeave(PlayerQuitEvent e) {
Player p = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(p);
LGPlayer lgp = LGPlayer.thePlayer(plugin, p);
if(lgp.getGame() != null) {
lgp.leaveChat();
if(lgp.getRole() != null && !lgp.isDead())

View file

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

View file

@ -10,8 +10,6 @@ import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGMayorVoteEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent;
import fr.leomelki.loupgarou.events.LGVoteEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
@ -93,7 +91,7 @@ public class RAnge extends Role{
vote = false;
}
}
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>();
final ArrayList<LGPlayer> winners = new ArrayList<>();
int night = 1;
@EventHandler
public void onDeath(LGPlayerGotKilledEvent e) {

View file

@ -5,7 +5,6 @@ import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -61,17 +60,14 @@ public class RAssassin extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
getGame().kill(choosen, Reason.ASSASSIN);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null && choosen != player) {
getGame().kill(choosen, Reason.ASSASSIN);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
});
}

View file

@ -67,9 +67,7 @@ public class RBouffon extends Role{
return;
}
LGPlayer player = players.remove(0);
getGame().wait(getTimeout(), ()->{RBouffon.this.onNightTurnTimeout(player);this.run();}, (currentPlayer, secondsLeft)->{
return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)";
});
getGame().wait(getTimeout(), ()->{RBouffon.this.onNightTurnTimeout(player);this.run();}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)");
player.sendMessage("§6"+getTask());
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
onNightTurn(player, this);
@ -121,7 +119,7 @@ public class RBouffon extends Role{
player.stopChoosing();
}
ArrayList<LGPlayer> needToPlay = new ArrayList<LGPlayer>();
final ArrayList<LGPlayer> needToPlay = new ArrayList<>();
@EventHandler
public void onPlayerKill(LGPlayerKilledEvent e) {

View file

@ -8,7 +8,6 @@ import org.bukkit.event.EventHandler;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGDayStartEvent;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
@ -60,9 +59,7 @@ public class RChasseur extends Role{
getGame().wait(getTimeout(), ()->{
this.onNightTurnTimeout(player);
callback.run();
}, (currentPlayer, secondsLeft)->{
return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e"+secondsLeft+" s§6)";
});
}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6Le Chasseur choisit sa cible (§e"+secondsLeft+" s§6)");
getGame().broadcastMessage("§9"+getBroadcastedTask());
player.sendMessage("§6"+getTask());
//player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 60);
@ -88,7 +85,7 @@ public class RChasseur extends Role{
player.stopChoosing();
}
ArrayList<LGPlayer> needToPlay = new ArrayList<LGPlayer>();
final ArrayList<LGPlayer> needToPlay = new ArrayList<>();
@EventHandler
public void onPlayerKill(LGPlayerKilledEvent e) {

View file

@ -1,19 +1,8 @@
package fr.leomelki.loupgarou.roles;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGRoleTurnEndEvent;
public class RChasseurDeVampire extends Role{
public RChasseurDeVampire(LGGame game) {
@ -67,24 +56,21 @@ public class RChasseurDeVampire extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
// player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6.");
if(choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) {
getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE);
player.sendMessage("§7§l"+choosen.getName()+"§6 est un §5§lVampire§6, à l'attaque.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
} else {
player.sendMessage("§7§l"+choosen.getName()+"§6 n'est pas un §5§lVampire§6...");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 n'est pas un §5§lVampire");
}
player.stopChoosing();
player.hideView();
callback.run();
player.choose(choosen -> {
if(choosen != null && choosen != player) {
// player.sendMessage("§6Tu as choisi de rendre visite à §7§l"+choosen.getName()+"§6.");
if(choosen.getCache().getBoolean("vampire") || choosen.getRole() instanceof RVampire) {
getGame().kill(choosen, Reason.CHASSEUR_DE_VAMPIRE);
player.sendMessage("§7§l"+choosen.getName()+"§6 est un §5§lVampire§6, à l'attaque.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
} else {
player.sendMessage("§7§l"+choosen.getName()+"§6 n'est pas un §5§lVampire§6...");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 n'est pas un §5§lVampire");
}
player.stopChoosing();
player.hideView();
callback.run();
}
});
}

View file

@ -1,6 +1,7 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -19,7 +20,7 @@ import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
public class RChienLoup extends Role{
static ItemStack[] items = new ItemStack[9];
static final ItemStack[] items = new ItemStack[9];
static {
items[3] = new ItemStack(Material.GOLDEN_APPLE);
ItemMeta meta = items[3].getItemMeta();
@ -30,7 +31,7 @@ public class RChienLoup extends Role{
items[5] = new ItemStack(Material.ROTTEN_FLESH);
meta = items[5].getItemMeta();
meta.setDisplayName("§cDevenir Loup-Garou");
meta.setLore(Arrays.asList("§cVous rejoindrez le camp des §c§lLoups"));
meta.setLore(Collections.singletonList("§cVous rejoindrez le camp des §c§lLoups"));
items[5].setItemMeta(meta);
}
@ -122,7 +123,7 @@ public class RChienLoup extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -160,7 +161,7 @@ public class RChienLoup extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -6,9 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGVoteEvent;
public class RCorbeau extends Role{
@ -56,20 +54,17 @@ public class RCorbeau extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
choosen.getCache().set("corbeau_selected", true);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui");
player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
choosen.getCache().set("corbeau_selected", true);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui");
player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
});
}
@ -87,14 +82,14 @@ public class RCorbeau extends Role{
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getCache().getBoolean("corbeau_selected")) {
lgp.getCache().remove("corbeau_selected");
LGPlayer lg = lgp;
new BukkitRunnable() {
@Override
public void run() {
getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg);
getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg);//fix
getGame().broadcastMessage("§7§l"+lg.getName()+"§6 a reçu la visite du "+getName()+"§6.");
MainLg plugin = getGame().getPlugin();
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);
getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);//fix
getGame().broadcastMessage("§7§l"+ lgp.getName()+"§6 a reçu la visite du "+getName()+"§6.");
}
}.runTask(MainLg.getInstance());

View file

@ -26,7 +26,6 @@ import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLivin
import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -85,34 +84,31 @@ public class RCupidon extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
if(player.getCache().has("cupidon_first")) {
LGPlayer first = player.getCache().remove("cupidon_first");
if(first == choosen) {
int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
} else {
// sendHead(player, choosen);
int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
setInLove(first, choosen);
player.sendMessage("§7§l"+first.getName()+"§9 et §7§l"+choosen.getName()+"§9 sont désormais follement amoureux.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null) {
if(player.getCache().has("cupidon_first")) {
LGPlayer first = player.getCache().remove("cupidon_first");
if(first == choosen) {
int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
} else {
sendHead(player, choosen);
player.getCache().set("cupidon_first", choosen);
// sendHead(player, choosen);
int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
setInLove(first, choosen);
player.sendMessage("§7§l"+first.getName()+"§9 et §7§l"+choosen.getName()+"§9 sont désormais follement amoureux.");
player.stopChoosing();
player.hideView();
callback.run();
}
} else {
sendHead(player, choosen);
player.getCache().set("cupidon_first", choosen);
}
}
});
@ -134,8 +130,8 @@ public class RCupidon extends Role{
player2.updatePrefix();
}
WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)),
noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
protected void sendHead(LGPlayer to, LGPlayer ofWho) {
int entityId = Integer.MAX_VALUE-ofWho.getPlayer().getEntityId();
WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
@ -207,7 +203,7 @@ public class RCupidon extends Role{
public void onGameEnd(LGGameEndEvent e) {
if(e.getGame() == getGame()) {
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
ArrayList<Integer> ids = new ArrayList<Integer>();
ArrayList<Integer> ids = new ArrayList<>();
for(LGPlayer lgp : getGame().getInGame())
ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId());
int[] intList = new int[ids.size()];
@ -237,7 +233,7 @@ public class RCupidon extends Role{
@EventHandler
public void onEndCheck(LGEndCheckEvent e) {
if(e.getGame() == getGame()) {
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>();
ArrayList<LGPlayer> winners = new ArrayList<>();
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleWinType() != RoleWinType.NONE)
winners.add(lgp);
@ -253,7 +249,7 @@ public class RCupidon extends Role{
@EventHandler(priority = EventPriority.LOWEST)
public void onChat(AsyncPlayerChatEvent e) {
LGPlayer player = LGPlayer.thePlayer(e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), e.getPlayer());
if(player.getGame() == getGame()) {
if(e.getMessage().startsWith("!")) {
if(player.getCache().has("inlove")){

View file

@ -1,39 +1,7 @@
package fr.leomelki.loupgarou.roles;
import java.util.ArrayList;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityEquipment;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityLook;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerEntityMetadata;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLiving;
import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerGotKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent;
public class RDetective extends Role{
public RDetective(LGGame game) {
@ -80,32 +48,29 @@ public class RDetective extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
if(choosen == player) {
player.sendMessage("§cVous ne pouvez pas vous sélectionner !");
return;
}
if(player.getCache().has("detective_first")) {
LGPlayer first = player.getCache().remove("detective_first");
if(first == choosen) {
player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !");
} else {
if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType())
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp.");
else
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null) {
if(choosen == player) {
player.sendMessage("§cVous ne pouvez pas vous sélectionner !");
return;
}
if(player.getCache().has("detective_first")) {
LGPlayer first = player.getCache().remove("detective_first");
if(first == choosen) {
player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !");
} else {
player.getCache().set("detective_first", choosen);
player.sendMessage("§9Choisis un joueur avec qui tu souhaites comparer le rôle de §7§l"+choosen.getName());
if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType())
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp.");
else
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp.");
player.stopChoosing();
player.hideView();
callback.run();
}
} else {
player.getCache().set("detective_first", choosen);
player.sendMessage("§9Choisis un joueur avec qui tu souhaites comparer le rôle de §7§l"+choosen.getName());
}
}
});

View file

@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import org.bukkit.Bukkit;
@ -35,7 +36,7 @@ public class RDictateur extends Role{
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[3].setItemMeta(meta);
items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER);
meta = items[5].getItemMeta();
@ -122,7 +123,7 @@ public class RDictateur extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -148,7 +149,7 @@ public class RDictateur extends Role{
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer();
LGPlayer player = LGPlayer.thePlayer(p);
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p);
if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
getGame().cancelWait();
player.stopChoosing();
@ -162,7 +163,7 @@ public class RDictateur extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {
@ -218,9 +219,7 @@ public class RDictateur extends Role{
lgp.getPlayer().getInventory().setItem(8, null);
lgp.getPlayer().updateInventory();
this.run();
}, (player, secondsLeft)->{
return lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)";
});
}, (player, secondsLeft)-> lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)");
lgp.choose((choosen)->{
if(choosen != null) {
getGame().cancelWait();

View file

@ -7,9 +7,7 @@ import org.bukkit.event.EventPriority;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class REnfantSauvage extends Role{
public REnfantSauvage(LGGame game) {
@ -63,20 +61,16 @@ public class REnfantSauvage extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.sendMessage("§6Choisissez votre modèle.");
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
player.stopChoosing();
player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6.");
player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle");
player.getCache().set("enfant_svg", choosen);
choosen.getCache().set("enfant_svg_d", player);
getPlayers().remove(player);//Pour éviter qu'il puisse avoir plusieurs modèles
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null) {
player.stopChoosing();
player.sendMessage("§6Si §7§l"+choosen.getName()+"§6 meurt, tu deviendras §c§lLoup-Garou§6.");
player.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton modèle");
player.getCache().set("enfant_svg", choosen);
choosen.getCache().set("enfant_svg_d", player);
getPlayers().remove(player);//Pour éviter qu'il puisse avoir plusieurs modèles
player.hideView();
callback.run();
}
}, player);
}

View file

@ -1,13 +1,13 @@
package fr.leomelki.loupgarou.roles;
import java.util.Comparator;
import org.bukkit.potion.PotionEffectType;
import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import java.util.Comparator;
public class REnfantSauvageLG extends Role{
public REnfantSauvageLG(LGGame game) {
super(game);
@ -71,12 +71,7 @@ public class REnfantSauvageLG extends Role{
if(lgRole == null) {
getGame().getRoles().add(lgRole = new RLoupGarou(getGame()));
getGame().getRoles().sort(new Comparator<Role>() {
@Override
public int compare(Role role1, Role role2) {
return role1.getTurnOrder()-role2.getTurnOrder();
}
});
getGame().getRoles().sort(Comparator.comparingInt(Role::getTurnOrder));
}
lgRole.join(player, false);

View file

@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGPreDayStartEvent;
@ -59,30 +58,27 @@ public class RGarde extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
LGPlayer lastProtected = player.getCache().get("garde_lastProtected");
if(choosen == lastProtected) {
if(lastProtected == player)
player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière.");
else
player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière.");
} else {
if(choosen == player) {
player.sendMessage("§6Tu décides de te protéger toi-même cette nuit.");
player.sendActionBarMessage("§9Tu seras protégé.");
} else {
player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit.");
player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé.");
}
choosen.getCache().set("garde_protected", true);
player.getCache().set("garde_lastProtected", choosen);
player.stopChoosing();
player.hideView();
callback.run();
player.choose(choosen -> {
if(choosen != null) {
LGPlayer lastProtected = player.getCache().get("garde_lastProtected");
if(choosen == lastProtected) {
if(lastProtected == player)
player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière.");
else
player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière.");
} else {
if(choosen == player) {
player.sendMessage("§6Tu décides de te protéger toi-même cette nuit.");
player.sendActionBarMessage("§9Tu seras protégé.");
} else {
player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit.");
player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé.");
}
choosen.getCache().set("garde_protected", true);
player.getCache().set("garde_lastProtected", choosen);
player.stopChoosing();
player.hideView();
callback.run();
}
}
});

View file

@ -1,21 +1,9 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
@ -79,17 +67,14 @@ public class RGrandMechantLoup extends Role{
this.callback = callback;
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit");
player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6.");
getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU);
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null && choosen != player) {
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit");
player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6.");
getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU);
player.stopChoosing();
player.hideView();
callback.run();
}
});
}

View file

@ -71,9 +71,7 @@ public class RLoupGarou extends Role{
return 30;
}
@Getter private final LGChat chat = new LGChat((sender, message) -> {
return "§c"+sender.getName()+" §6» §f"+message;
});
@Getter private final LGChat chat = new LGChat((sender, message) -> "§c"+sender.getName()+" §6» §f"+message);
boolean showSkins = false;
LGVote vote;
@ -86,9 +84,7 @@ public class RLoupGarou extends Role{
}
public void onNightTurn(Runnable callback) {
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> {
return !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter";
});
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez contre §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter");
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.LOUP_GAROU)
lgp.showView();
@ -124,7 +120,7 @@ public class RLoupGarou extends Role{
equal = true;
if(equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>();
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());

View file

@ -1,6 +1,6 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -12,7 +12,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -24,7 +23,7 @@ public class RLoupGarouBlanc extends Role{
skip = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = skip.getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
skip.setItemMeta(meta);
}
@ -93,30 +92,27 @@ public class RLoupGarouBlanc extends Role{
RLoupGarou lg = lg_;
player.showView();
player.getPlayer().getInventory().setItem(8, skip);
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
if(!lg.getPlayers().contains(choosen)) {
player.sendMessage("§7§l"+choosen.getName()+"§4 n'est pas un Loup-Garou.");
return;
}
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit");
player.sendMessage("§6Tu as choisi de dévorer §7§l"+choosen.getName()+"§6.");
player.getPlayer().getInventory().setItem(8, null);
player.getPlayer().updateInventory();
getGame().kill(choosen, Reason.LOUP_BLANC);
player.stopChoosing();
player.hideView();
callback.run();
player.choose(choosen -> {
if(choosen != null && choosen != player) {
if(!lg.getPlayers().contains(choosen)) {
player.sendMessage("§7§l"+choosen.getName()+"§4 n'est pas un Loup-Garou.");
return;
}
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit");
player.sendMessage("§6Tu as choisi de dévorer §7§l"+choosen.getName()+"§6.");
player.getPlayer().getInventory().setItem(8, null);
player.getPlayer().updateInventory();
getGame().kill(choosen, Reason.LOUP_BLANC);
player.stopChoosing();
player.hideView();
callback.run();
}
});
}
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer();
LGPlayer player = LGPlayer.thePlayer(p);
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p);
if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
player.stopChoosing();
p.getInventory().setItem(8, null);

View file

@ -1,6 +1,7 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -26,13 +27,13 @@ import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RLoupGarouNoir extends Role{
static ItemStack[] items = new ItemStack[9];
static ItemStack[] skip = new ItemStack[9];
static final ItemStack[] items = new ItemStack[9];
static final ItemStack[] skip = new ItemStack[9];
static {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[3].setItemMeta(meta);
items[5] = new ItemStack(Material.ROTTEN_FLESH);
meta = items[5].getItemMeta();
@ -137,7 +138,7 @@ public class RLoupGarouNoir extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -204,7 +205,7 @@ public class RLoupGarouNoir extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -3,7 +3,6 @@ package fr.leomelki.loupgarou.roles;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -11,8 +10,6 @@ import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.events.LGDayStartEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RMontreurDOurs extends Role{
public RMontreurDOurs(LGGame game) {

View file

@ -50,7 +50,7 @@ public class RPetiteFille extends Role{
return -1;
}
List<String> customNames = Arrays.asList("Loup Glouton", "Loup Méchant", "Loup Burlesque", "Loup Peureux", "Loup Malingre", "Loup Gentil", "Loup Tueur", "Loup Énervé", "Loup Docteur");
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");
@EventHandler
public void onChangeRole(LGRoleTurnEndEvent e) {
@ -61,9 +61,7 @@ public class RPetiteFille extends Role{
RLoupGarou lgRole = (RLoupGarou)role;
for(LGPlayer player : getPlayers())
if(!player.getCache().getBoolean("infected") && player.isRoleActive())
player.joinChat(lgRole.getChat(), (sender, message)->{
return "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message;
}, true);
player.joinChat(lgRole.getChat(), (sender, message)-> "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message, true);
break;
}
if(e.getPreviousRole() instanceof RLoupGarou)

View file

@ -1,6 +1,7 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -20,17 +21,16 @@ import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot;
import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RPirate extends Role{
static ItemStack[] items = new ItemStack[9];
static final ItemStack[] items = new ItemStack[9];
static {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[3].setItemMeta(meta);
items[5] = new ItemStack(Material.ROTTEN_FLESH);
meta = items[5].getItemMeta();
@ -124,7 +124,7 @@ public class RPirate extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -144,23 +144,19 @@ public class RPirate extends Role{
held.setSlot(0);
held.sendPacket(player);
lgp.sendMessage("§6Choisissez votre otage.");
lgp.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.stopChoosing();
lgp.sendMessage("§6Tu as pris §7§l"+choosen.getName()+"§6 en otage.");
lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton otage");
lgp.getCache().set("pirate_otage", choosen);
choosen.getCache().set("pirate_otage_d", lgp);
getPlayers().remove(lgp);//Pour éviter qu'il puisse prendre plusieurs otages
choosen.sendMessage("§7§l"+lgp.getName()+"§6 t'a pris en otage, il est "+getName()+"§6.");
lgp.hideView();
callback.run();
}
lgp.choose(choosen -> {
if(choosen != null) {
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.stopChoosing();
lgp.sendMessage("§6Tu as pris §7§l"+choosen.getName()+"§6 en otage.");
lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 est ton otage");
lgp.getCache().set("pirate_otage", choosen);
choosen.getCache().set("pirate_otage_d", lgp);
getPlayers().remove(lgp);//Pour éviter qu'il puisse prendre plusieurs otages
choosen.sendMessage("§7§l"+lgp.getName()+"§6 t'a pris en otage, il est "+getName()+"§6.");
lgp.hideView();
callback.run();
}
}, lgp);
}
@ -181,7 +177,7 @@ public class RPirate extends Role{
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) {
e.setCancelled(true);
@ -197,7 +193,7 @@ public class RPirate extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -28,17 +29,16 @@ import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGPreDayStartEvent;
import fr.leomelki.loupgarou.utils.VariousUtils;
public class RPretre extends Role{
static ItemStack[] items = new ItemStack[9];
static final ItemStack[] items = new ItemStack[9];
static {
items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[3].setItemMeta(meta);
items[5] = new ItemStack(Material.ROTTEN_FLESH);
meta = items[5].getItemMeta();
@ -113,21 +113,21 @@ public class RPretre extends Role{
player.closeInventory();
player.openInventory(inventory);
}
WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
@Override
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
for(LGPlayer lgp : getGame().getInGame())
if(lgp.isDead() && (lgp.getRoleType() == RoleType.VILLAGER || lgp.getRoleType() == player.getRoleType())){
if(lgp.getPlayer() != null) {
player.getPlayer().showPlayer(lgp.getPlayer());
player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer());
WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata();
meta.setEntityID(lgp.getPlayer().getEntityId());
meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0)));
meta.setMetadata(Collections.singletonList(new WrappedWatchableObject(invisible, (byte) 0)));
meta.sendPacket(player.getPlayer());
}
}else
player.getPlayer().hidePlayer(lgp.getPlayer());
player.getPlayer().hidePlayer(getGame().getPlugin(), lgp.getPlayer());
this.callback = callback;
openInventory(player.getPlayer());
}
@ -147,12 +147,12 @@ public class RPretre extends Role{
if(player.getPlayer() != null) {
for(LGPlayer lgp : getGame().getInGame())
if(lgp.getPlayer() != null && lgp != player)
player.getPlayer().hidePlayer(lgp.getPlayer());
player.getPlayer().hidePlayer(getGame().getPlugin(), lgp.getPlayer());
}
}
boolean inMenu = false;
ArrayList<LGPlayer> ressucited = new ArrayList<LGPlayer>();
final ArrayList<LGPlayer> ressucited = new ArrayList<>();
private void closeInventory(Player p) {
inMenu = false;
@ -162,7 +162,7 @@ public class RPretre extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -184,33 +184,29 @@ public class RPretre extends Role{
held.sendPacket(player);
lgp.sendMessage("§6Choisissez qui réssusciter.");
lgp.canSelectDead = true;
lgp.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
if(!choosen.isDead())
lgp.sendMessage("§7§l"+choosen.getName()+"§c n'est pas mort.");
else if(lgp.getRoleType() == RoleType.LOUP_GAROU && choosen.getRoleType() == RoleType.NEUTRAL) {
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6.");
}else if(lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) {
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait pas partie du §a§lVillage§6.");
} else {
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.stopChoosing();
lgp.canSelectDead = false;
lgp.sendMessage("§6Tu as ramené §7§l"+choosen.getName()+"§6 à la vie.");
lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 sera réssuscité");
ressucited.add(choosen);
getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes.
choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6.");
hidePlayers(lgp);
lgp.hideView();
callback.run();
}
lgp.choose(choosen -> {
if(choosen != null) {
if(!choosen.isDead())
lgp.sendMessage("§7§l"+choosen.getName()+"§c n'est pas mort.");
else if(lgp.getRoleType() == RoleType.LOUP_GAROU && choosen.getRoleType() == RoleType.NEUTRAL) {
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait ni partie du §a§lVillage§6 ni des §c§lLoups§6.");
}else if(lgp.getRoleType() != RoleType.LOUP_GAROU && choosen.getRoleType() != RoleType.VILLAGER) {
lgp.sendMessage("§7§l"+choosen.getName()+"§c ne faisait pas partie du §a§lVillage§6.");
} else {
player.getInventory().setItem(8, null);
player.updateInventory();
lgp.stopChoosing();
lgp.canSelectDead = false;
lgp.sendMessage("§6Tu as ramené §7§l"+choosen.getName()+"§6 à la vie.");
lgp.sendActionBarMessage("§7§l"+choosen.getName()+"§6 sera réssuscité");
ressucited.add(choosen);
getPlayers().remove(lgp);//Pour éviter qu'il puisse sauver plusieurs personnes.
choosen.sendMessage("§6Tu vas être réssuscité en tant que §a§lVillageois§6.");
hidePlayers(lgp);
lgp.hideView();
callback.run();
}
}
}, lgp);
@ -219,7 +215,7 @@ public class RPretre extends Role{
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(items[3].getItemMeta().getDisplayName())) {
e.setCancelled(true);
@ -265,7 +261,7 @@ public class RPretre extends Role{
for(LGPlayer player : getGame().getInGame())
if(player.getPlayer() != null && player != lgp) {
player.getPlayer().showPlayer(lgp.getPlayer());
player.getPlayer().showPlayer(getGame().getPlugin(), lgp.getPlayer());
}
}
ressucited.clear();
@ -274,7 +270,7 @@ public class RPretre extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -2,7 +2,6 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
public class RPronostiqueur extends Role{
public RPronostiqueur(LGGame game) {
@ -49,18 +48,15 @@ public class RPronostiqueur extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant";
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est "+gentilMechant);
player.sendMessage("§6Votre instinct vous dit que §7§l"+choosen.getName()+"§6 est "+gentilMechant+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
String gentilMechant = choosen.getRoleWinType() == RoleWinType.VILLAGE || choosen.getRoleWinType() == RoleWinType.NONE ? "§a§lgentil" : "§c§lméchant";
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est "+gentilMechant);
player.sendMessage("§6Votre instinct vous dit que §7§l"+choosen.getName()+"§6 est "+gentilMechant+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
});
}

View file

@ -2,6 +2,7 @@ package fr.leomelki.loupgarou.roles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
@ -23,7 +24,6 @@ import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent;
@ -31,13 +31,14 @@ import fr.leomelki.loupgarou.events.LGPyromaneGasoilEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
public class RPyromane extends Role{
static ItemStack[] items = new ItemStack[9];
static ItemStack cancel, nothing;
static final ItemStack[] items = new ItemStack[9];
static final ItemStack cancel;
static final ItemStack nothing;
static {
cancel = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = cancel.getItemMeta();
meta.setDisplayName("§7§lAnnuler");
meta.setLore(Arrays.asList("§8Rouvrir le menu"));
meta.setLore(Collections.singletonList("§8Rouvrir le menu"));
cancel.setItemMeta(meta);
nothing = new ItemStack(Material.IRON_NUGGET);
meta = nothing.getItemMeta();
@ -53,7 +54,7 @@ public class RPyromane extends Role{
items[5] = new ItemStack(Material.LAVA_BUCKET);
meta = items[5].getItemMeta();
meta.setDisplayName("§c§lRecouvrir d'essence");
meta.setLore(Arrays.asList(
meta.setLore(Collections.singletonList(
"§8Recouvres deux joueurs d'essence"));
items[5].setItemMeta(meta);
}
@ -111,7 +112,7 @@ public class RPyromane extends Role{
inMenu = true;
Inventory inventory = Bukkit.createInventory(null, 9, "§7Que veux-tu faire ?");
ItemStack[] content = items.clone();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(!lgp.getCache().has("pyromane_essence"))
lgp.getCache().set("pyromane_essence", new ArrayList<>());
if(lgp.getCache().<List<LGPlayer>>get("pyromane_essence").size() == 0)
@ -159,7 +160,7 @@ public class RPyromane extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
if(item.getItemMeta().getDisplayName().equals(nothing.getItemMeta().getDisplayName())) {
@ -195,31 +196,38 @@ public class RPyromane extends Role{
held.setSlot(0);
held.sendPacket(player);
lgp.sendMessage("§6Choisis deux joueurs à recouvrir de gasoil.");
lgp.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null) {
if(choosen == first) {
lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l"+choosen.getName()+"§6.");
return;
lgp.choose(choosen -> {
if(choosen != null) {
if(choosen == first) {
lgp.sendMessage("§cTu as déjà versé du gasoil sur §7§l"+choosen.getName()+"§6.");
return;
}
List<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());
}
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);
if(first != null) {
event = new LGPyromaneGasoilEvent(getGame(), first);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled())
lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée.");
@ -227,21 +235,11 @@ public class RPyromane extends Role{
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
if(first != null) {
event = new LGPyromaneGasoilEvent(getGame(), first);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled())
lgp.sendMessage("§7§l"+event.getPlayer().getName()+"§c est immunisée.");
else {
event.getPlayer().sendMessage("§6Tu es recouvert de gasoil...");
liste.add(event.getPlayer());
}
}
callback.run();
} else {
lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil.");
first = choosen;
}
callback.run();
} else {
lgp.sendMessage("§6Choisis un deuxième joueur à recouvrir de gasoil.");
first = choosen;
}
}
}, lgp);
@ -250,7 +248,7 @@ public class RPyromane extends Role{
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player player = e.getPlayer();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() == this) {
if(e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().getDisplayName().equals(cancel.getItemMeta().getDisplayName())) {
e.setCancelled(true);
@ -274,7 +272,7 @@ public class RPyromane extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -1,6 +1,6 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -14,7 +14,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerHeldItemSlot;
@ -30,7 +29,7 @@ public class RSorciere extends Role{
items[0] = new ItemStack(Material.PURPLE_DYE, 1);
ItemMeta meta = items[0].getItemMeta();
meta.setDisplayName("§a§lPotion de vie");
meta.setLore(Arrays.asList("§2Sauve la cible des §c§lLoups§2."));
meta.setLore(Collections.singletonList("§2Sauve la cible des §c§lLoups§2."));
items[0].setItemMeta(meta);
items[1] = new ItemStack(Material.IRON_NUGGET);
meta = items[1].getItemMeta();
@ -39,7 +38,7 @@ public class RSorciere extends Role{
items[2] = new ItemStack(Material.LIGHT_BLUE_DYE, 1);
meta = items[2].getItemMeta();
meta.setDisplayName("§c§lPotion de mort");
meta.setLore(Arrays.asList("§cTue la personne de ton choix."));
meta.setLore(Collections.singletonList("§cTue la personne de ton choix."));
items[2].setItemMeta(meta);
cancel = new ItemStack(Material.IRON_NUGGET);
meta = cancel.getItemMeta();
@ -140,7 +139,7 @@ public class RSorciere extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player) e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if (lgp.getRole() != this || item == null || item.getItemMeta() == null)
return;
@ -178,7 +177,7 @@ public class RSorciere extends Role{
@EventHandler
public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer();
LGPlayer player = LGPlayer.thePlayer(p);
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), p);
if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
player.stopChoosing();
p.getInventory().setItem(8, null);
@ -190,7 +189,7 @@ public class RSorciere extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -1,6 +1,7 @@
package fr.leomelki.loupgarou.roles;
import java.util.Arrays;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -70,12 +71,12 @@ public class RSurvivant extends Role{
inMenu = true;
Inventory inventory = Bukkit.createInventory(null, 9, "§7Veux-tu te protéger ?");
ItemStack[] items = new ItemStack[9];
VariableCache cache = LGPlayer.thePlayer(player).getCache();
VariableCache cache = LGPlayer.thePlayer(getGame().getPlugin(), player).getCache();
if(cache.<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(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[3].setItemMeta(meta);
items[5] = new ItemStack(Material.GOLD_NUGGET);
meta = items[5].getItemMeta();
@ -88,7 +89,7 @@ public class RSurvivant extends Role{
items[4] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[4].getItemMeta();
meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour"));
meta.setLore(Collections.singletonList("§8Passez votre tour"));
items[4].setItemMeta(meta);
}
player.closeInventory();
@ -123,7 +124,7 @@ public class RSurvivant extends Role{
public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked();
LGPlayer lgp = LGPlayer.thePlayer(player);
LGPlayer lgp = LGPlayer.thePlayer(getGame().getPlugin(), player);
if(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -167,7 +168,7 @@ public class RSurvivant extends Role{
@EventHandler
public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) {
LGPlayer player = LGPlayer.thePlayer((Player)e.getPlayer());
LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), (Player)e.getPlayer());
if(player.getRole() == this && inMenu) {
new BukkitRunnable() {

View file

@ -7,11 +7,8 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import fr.leomelki.com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam;
import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGCustomSkin;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGVote;
@ -19,12 +16,9 @@ import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints;
import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent;
import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGSkinLoadEvent;
import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent;
import fr.leomelki.loupgarou.events.LGVampiredEvent;
import lombok.Getter;
@ -82,9 +76,7 @@ public class RVampire extends Role{
return nextCanInfect < getGame().getNight() && super.hasPlayersLeft();
}
@Getter private final LGChat chat = new LGChat((sender, message) -> {
return "§5"+sender.getName()+" §6» §f"+message;
});
@Getter private final LGChat chat = new LGChat((sender, message) -> "§5"+sender.getName()+" §6» §f"+message);
int nextCanInfect = 0;
LGVote vote;
@Override
@ -95,9 +87,7 @@ public class RVampire extends Role{
}
public void onNightTurn(Runnable callback) {
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> {
return !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter";
});
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> !getPlayers().contains(player) ? "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)" : player.getCache().has("vote") ? "§l§9Vous votez pour §c§l"+player.getCache().<LGPlayer>get("vote").getName() : "§6Il vous reste §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "")+"§6 pour voter");
for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.VAMPIRE)
lgp.showView();
@ -132,7 +122,7 @@ public class RVampire extends Role{
equal = true;
if(equal) {
choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>();
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());

View file

@ -2,7 +2,6 @@ package fr.leomelki.loupgarou.roles;
import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
public class RVoyante extends Role{
public RVoyante(LGGame game) {
@ -50,17 +49,14 @@ public class RVoyante extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView();
player.choose(new LGChooseCallback() {
@Override
public void callback(LGPlayer choosen) {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName());
player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
player.choose(choosen -> {
if(choosen != null && choosen != player) {
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName());
player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6.");
player.stopChoosing();
player.hideView();
callback.run();
}
});
}

View file

@ -17,7 +17,7 @@ import lombok.Setter;
public abstract class Role implements Listener{
@Getter @Setter private int waitedPlayers;
@Getter private final ArrayList<LGPlayer> players = new ArrayList<LGPlayer>();
@Getter private final ArrayList<LGPlayer> players = new ArrayList<>();
@Getter private final LGGame game;
public Role(LGGame game) {
@ -70,16 +70,12 @@ public abstract class Role implements Listener{
err.printStackTrace();
}
this.run();
}, (currentPlayer, secondsLeft)->{
return currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)";
});
}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§9§lC'est à ton tour !" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)");
player.sendMessage("§6"+getTask());
// player.sendTitle("§6C'est à vous de jouer", "§a"+getTask(), 100);
onNightTurn(player, this);
} else {
getGame().wait(getTimeout(), ()->{}, (currentPlayer, secondsLeft)->{
return currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)";
});
getGame().wait(getTimeout(), ()->{}, (currentPlayer, secondsLeft)-> currentPlayer == player ? "§c§lTu ne peux pas jouer" : "§6C'est au tour "+getFriendlyName()+" §6(§e"+secondsLeft+" s§6)");
Runnable run = this;
new BukkitRunnable() {

View file

@ -1,6 +1,6 @@
package fr.leomelki.loupgarou.scoreboard;
import java.util.Arrays;
import java.util.Collections;
import com.comphenix.protocol.wrappers.EnumWrappers.ScoreboardAction;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
@ -29,7 +29,7 @@ public class CustomScoreboardEntry {
public void show() {
if(prefix != null) {
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setPlayers(Arrays.asList(name));
team.setPlayers(Collections.singletonList(name));
team.setName(name);
team.setMode(0);
team.setPrefix(prefix);
@ -77,7 +77,7 @@ public class CustomScoreboardEntry {
show();
else {
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setPlayers(Arrays.asList(name));
team.setPlayers(Collections.singletonList(name));
team.setName(name);
team.setMode(2);
team.setPrefix(prefix);

View file

@ -7,14 +7,11 @@ import java.util.Map.Entry;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
public class MultipleValueMap<K, V> {
private final HashMap<K, List<V>> map = new HashMap<>();
public void put(K key, V value) {
List<V> list = map.get(key);
if(list == null)
map.put(key, list = new ArrayList<>());
List<V> list = map.computeIfAbsent(key, k -> new ArrayList<>());
list.add(value);
}
public V remove(K key, V value) {
@ -43,10 +40,10 @@ public class MultipleValueMap<K, V> {
return map.containsKey(key) ? map.get(key).get(0) : null;
}
public List<Entry<K, V>> entrySet(){
ArrayList<Entry<K, V>> toReturn = new ArrayList<Entry<K,V>>();
ArrayList<Entry<K, V>> toReturn = new ArrayList<>();
for(Entry<K, List<V>> entry : map.entrySet())
for(V v : entry.getValue())
toReturn.add(new MultipleValueKeyEntry<K, V>(entry.getKey(), v));
toReturn.add(new MultipleValueKeyEntry<>(entry.getKey(), v));
return toReturn;
}

View file

@ -3,7 +3,7 @@ package fr.leomelki.loupgarou.utils;
import java.util.HashMap;
public class VariableCache {
private final HashMap<String, Object> cache = new HashMap<String, Object>();
private final HashMap<String, Object> cache = new HashMap<>();
public boolean getBoolean(String key) {
Object object = get(key);
return object != null && (boolean) object;