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.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket { public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
public static final PacketType TYPE = 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.RVillageois;
import fr.leomelki.loupgarou.roles.RVoyante; import fr.leomelki.loupgarou.roles.RVoyante;
import fr.leomelki.loupgarou.roles.Role; import fr.leomelki.loupgarou.roles.Role;
import fr.leomelki.loupgarou.utils.VariousUtils;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
public class MainLg extends JavaPlugin{ public class MainLg extends JavaPlugin{
private static MainLg instance; 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 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) @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(); saveConfig();
} }
loadConfig(); loadConfig();
Bukkit.getPluginManager().registerEvents(new JoinListener(), this); Bukkit.getPluginManager().registerEvents(new JoinListener(this), this);
Bukkit.getPluginManager().registerEvents(new CancelListener(), this); Bukkit.getPluginManager().registerEvents(new CancelListener(this), this);
Bukkit.getPluginManager().registerEvents(new VoteListener(), this); Bukkit.getPluginManager().registerEvents(new VoteListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(), this); Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this); Bukkit.getPluginManager().registerEvents(new LoupGarouListener(), this);
for(Player player : Bukkit.getOnlinePlayers()) for(Player player : Bukkit.getOnlinePlayers())
@ -118,7 +117,7 @@ public class MainLg extends JavaPlugin{
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket()); 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()) if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay())
event.setCancelled(true); event.setCancelled(true);
} }
@ -137,11 +136,11 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket()); WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket());
ArrayList<PlayerInfoData> datas = new ArrayList<PlayerInfoData>(); ArrayList<PlayerInfoData> datas = new ArrayList<>();
for(PlayerInfoData data : info.getData()) { 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()) { if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
WrappedChatComponent displayName = data.getDisplayName(); 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) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) {
@Override @Override
public void onPacketSending(PacketEvent event) { 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()) { if(player.getGame() != null && player.getGame().isStarted()) {
WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket()); WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket());
health.setFood(6); health.setFood(6);
@ -179,12 +178,12 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket()); WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam(event.getPacket());
team.setColor(ChatColor.WHITE); team.setColor(ChatColor.WHITE);
Player other = Bukkit.getPlayer(team.getName()); Player other = Bukkit.getPlayer(team.getName());
if(other == null)return; if(other == null)return;
LGPlayer lgp = LGPlayer.thePlayer(other); LGPlayer lgp = LGPlayer.thePlayer(instance, other);
if(player.getGame() != null && player.getGame() == lgp.getGame()) { if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, ""); LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
Bukkit.getPluginManager().callEvent(evt2); 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) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(instance, event.getPlayer());
if(player.getGame() != null) { if(player.getGame() != null) {
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket()); WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket());
if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId()) 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é."); sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'est pas connecté.");
return true; return true;
} }
LGGame game = LGPlayer.thePlayer(selected).getGame(); LGGame game = LGPlayer.thePlayer(instance, selected).getGame();
if(game == null) { if(game == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+selected.getName()+"§c n'est pas dans une partie."); sender.sendMessage("§4Erreur : §cLe joueur §4"+selected.getName()+"§c n'est pas dans une partie.");
return true; return true;
@ -256,7 +255,7 @@ public class MainLg extends JavaPlugin{
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !"); sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !");
return true; return true;
} }
LGPlayer lgp = LGPlayer.thePlayer(player); LGPlayer lgp = LGPlayer.thePlayer(instance, player);
if(lgp.getGame() == null) { if(lgp.getGame() == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+lgp.getName()+"§c n'est pas dans une partie."); sender.sendMessage("§4Erreur : §cLe joueur §4"+lgp.getName()+"§c n'est pas dans une partie.");
return true; return true;
@ -318,7 +317,7 @@ public class MainLg extends JavaPlugin{
String role = null; String role = null;
if(args[2].length() <= 2) if(args[2].length() <= 2)
try { try {
Integer i = Integer.valueOf(args[2]); int i = Integer.parseInt(args[2]);
Object[] array = getRoles().keySet().toArray(); Object[] array = getRoles().keySet().toArray();
if(array.length <= i) { if(array.length <= i) {
sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas."); sender.sendMessage(prefix+"§4Erreur: §cCe rôle n'existe pas.");
@ -369,7 +368,7 @@ public class MainLg extends JavaPlugin{
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if(!sender.hasPermission("loupgarou.admin")) if(!sender.hasPermission("loupgarou.admin"))
return new ArrayList<String>(0); return new ArrayList<>(0);
if(args.length > 1) { if(args.length > 1) {
if(args[0].equalsIgnoreCase("roles")) 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"); return Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
}else if(args.length == 1) }else if(args.length == 1)
return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks"); return getStartingList(args[0], "addSpawn", "end", "start", "nextNight", "nextDay", "reloadConfig", "roles", "joinAll", "reloadPacks");
return new ArrayList<String>(0); return new ArrayList<>(0);
} }
private List<String> getStartingList(String startsWith, String... list){ private List<String> getStartingList(String startsWith, String... list){
startsWith = startsWith.toLowerCase(); startsWith = startsWith.toLowerCase();
ArrayList<String> returnlist = new ArrayList<String>(); ArrayList<String> returnlist = new ArrayList<>();
if(startsWith.length() == 0) if(startsWith.length() == 0)
return Arrays.asList(list); return Arrays.asList(list);
for(String s : list) for(String s : list)
@ -397,7 +396,7 @@ public class MainLg extends JavaPlugin{
int players = 0; int players = 0;
for(String role : roles.keySet()) for(String role : roles.keySet())
players += getConfig().getInt("role."+role); players += getConfig().getInt("role."+role);
currentGame = new LGGame(players); currentGame = new LGGame(this, players);
} }
@Override @Override
public void onDisable() { 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 SecureRandom random = new SecureRandom();
@Getter private final int maxPlayers; @Getter private final int maxPlayers;
@Getter private final ArrayList<LGPlayer> inGame = new ArrayList<LGPlayer>(); @Getter private final ArrayList<LGPlayer> inGame = new ArrayList<>();
@Getter private final ArrayList<Role> roles = new ArrayList<Role>(); @Getter private final ArrayList<Role> roles = new ArrayList<>();
@Getter private final MainLg plugin;
@Getter private boolean started; @Getter private boolean started;
@Getter private int night = 0; @Getter private int night = 0;
private BukkitTask startingTask; private BukkitTask startingTask;
@Getter @Setter private int waitTicks; @Getter @Setter private int waitTicks;
@Getter private boolean day; @Getter private boolean day;
@Getter public long time = 0; @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) -> { @Getter private final LGChat spectatorChat = new LGChat((sender, message) -> "§7"+sender.getName()+" §6» §f"+message);
return "§7"+sender.getName()+" §6» §f"+message; @Getter private final LGChat dayChat = new LGChat((sender, message) -> "§e"+sender.getName()+" §6» §f"+message);
});
@Getter private final LGChat dayChat = new LGChat((sender, message) -> {
return "§e"+sender.getName()+" §6» §f"+message;
});
public LGGame(int maxPlayers) { public LGGame(MainLg mainLg, int maxPlayers) {
this.plugin = mainLg;
this.maxPlayers = maxPlayers; this.maxPlayers = maxPlayers;
Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance()); Bukkit.getPluginManager().registerEvents(this, MainLg.getInstance());
} }
@Getter @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) { public void sendActionBarMessage(String msg) {
WrapperPlayServerChat chat = new WrapperPlayServerChat(); WrapperPlayServerChat chat = new WrapperPlayServerChat();
@ -236,11 +234,11 @@ public class LGGame implements Listener{
for(LGPlayer other : getInGame()) { for(LGPlayer other : getInGame()) {
other.updatePrefix(); other.updatePrefix();
if(lgp != other) { if(lgp != other) {
player.hidePlayer(other.getPlayer()); player.hidePlayer(plugin, other.getPlayer());
player.showPlayer(other.getPlayer()); player.showPlayer(plugin, other.getPlayer());
other.getPlayer().hidePlayer(player); other.getPlayer().hidePlayer(plugin, player);
other.getPlayer().showPlayer(player); other.getPlayer().showPlayer(plugin, player);
} }
} }
@ -304,7 +302,7 @@ public class LGGame implements Listener{
//Registering roles //Registering roles
List<?> original = MainLg.getInstance().getConfig().getList("spawns"); List<?> original = MainLg.getInstance().getConfig().getList("spawns");
List<Object> list = new ArrayList<Object>(original); List<Object> list = new ArrayList<>(original);
for(LGPlayer lgp : getInGame()) { for(LGPlayer lgp : getInGame()) {
List<Double> location = (List<Double>) list.remove(random.nextInt(list.size())); List<Double> location = (List<Double>) list.remove(random.nextInt(list.size()));
Player p = lgp.getPlayer(); Player p = lgp.getPlayer();
@ -383,12 +381,7 @@ public class LGGame implements Listener{
updateRoleScoreboard(); updateRoleScoreboard();
//Classe les roles afin de les appeler dans le bon ordre //Classe les roles afin de les appeler dans le bon ordre
roles.sort(new Comparator<Role>() { roles.sort(Comparator.comparingInt(Role::getTurnOrder));
@Override
public int compare(Role role1, Role role2) {
return role1.getTurnOrder()-role2.getTurnOrder();
}
});
//Start day one //Start day one
nextNight(10); nextNight(10);
@ -400,7 +393,7 @@ public class LGGame implements Listener{
roles_.get(lgp.getRole()).increase(); roles_.get(lgp.getRole()).increase();
else else
roles_.put(lgp.getRole(), new IndexedRole(lgp.getRole())); 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)->{ roles.sort((a, b)->{
//TODO fix dégueu juste ici pour le chien loup lg à changer (2x) //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)); 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(); lgp.getScoreboard().getLine(i).delete();
} }
public List<LGPlayer> getAlive(){ public List<LGPlayer> getAlive(){
ArrayList<LGPlayer> alive = new ArrayList<LGPlayer>(); ArrayList<LGPlayer> alive = new ArrayList<>();
for(LGPlayer lgp : getInGame()) for(LGPlayer lgp : getInGame())
if(!lgp.isDead()) if(!lgp.isDead())
alive.add(lgp); alive.add(lgp);
@ -444,9 +437,7 @@ public class LGGame implements Listener{
setMayor(getAlive().get(random.nextInt(getAlive().size()))); setMayor(getAlive().get(random.nextInt(getAlive().size())));
broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9.");
nextNight(); nextNight();
}, (player, secondsLeft)->{ }, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)");
return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)";
});
mayor.choose((choosen)->{ mayor.choose((choosen)->{
if(choosen != null) { if(choosen != null) {
mayor.stopChoosing(); mayor.stopChoosing();
@ -474,9 +465,7 @@ public class LGGame implements Listener{
} }
} }
}.runTaskTimer(MainLg.getInstance(), 1, 1); }.runTaskTimer(MainLg.getInstance(), 1, 1);
LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)->{ LGGame.this.wait(timeout, this::nextNight_, (player, secondsLeft)-> "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : ""));
return "§6La nuit va tomber dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "");
});
} }
private void nextNight_() { private void nextNight_() {
if(ended)return; if(ended)return;
@ -534,13 +523,13 @@ public class LGGame implements Listener{
for(LGPlayer lgp : getInGame()) for(LGPlayer lgp : getInGame())
if(lgp == killed) { if(lgp == killed) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>(); ArrayList<PlayerInfoData> infos = new ArrayList<>();
info.setAction(PlayerInfoAction.REMOVE_PLAYER); info.setAction(PlayerInfoAction.REMOVE_PLAYER);
infos.add(new PlayerInfoData(new WrappedGameProfile(lgp.getPlayer().getUniqueId(), lgp.getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(lgp.getName()))); infos.add(new PlayerInfoData(new WrappedGameProfile(lgp.getPlayer().getUniqueId(), lgp.getName()), 0, NativeGameMode.ADVENTURE, WrappedChatComponent.fromText(lgp.getName())));
info.setData(infos); info.setData(infos);
info.sendPacket(lgp.getPlayer()); info.sendPacket(lgp.getPlayer());
}else }else
lgp.getPlayer().hidePlayer(killed.getPlayer()); lgp.getPlayer().hidePlayer(plugin, killed.getPlayer());
if(vote != null) if(vote != null)
vote.remove(killed); vote.remove(killed);
@ -594,7 +583,7 @@ public class LGGame implements Listener{
public void endGame(LGWinType winType) { public void endGame(LGWinType winType) {
if(ended)return; if(ended)return;
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>(); ArrayList<LGPlayer> winners = new ArrayList<>();
LGGameEndEvent event = new LGGameEndEvent(this, winType, winners); LGGameEndEvent event = new LGGameEndEvent(this, winType, winners);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -643,7 +632,7 @@ public class LGGame implements Listener{
team.setMode(1); team.setMode(1);
team.setName("you_are"); team.setName("you_are");
team.sendPacket(lgp.getPlayer()); 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 //A remettre pour activer le démarrage automatique
/* wait(30, ()->{ /* wait(30, ()->{
@ -747,9 +736,7 @@ public class LGGame implements Listener{
setMayor(getAlive().get(random.nextInt(getAlive().size()))); setMayor(getAlive().get(random.nextInt(getAlive().size())));
broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9."); broadcastMessage("§7§l"+mayor.getName()+"§9 devient le nouveau §5§lCapitaine§9.");
startDay(); startDay();
}, (player, secondsLeft)->{ }, (player, secondsLeft)-> "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)");
return "§e"+mayor.getName()+"§6 choisit qui sera le nouveau §5§lCapitaine§6 (§e"+secondsLeft+" s§6)";
});
mayor.choose((choosen)->{ mayor.choose((choosen)->{
if(choosen != null) { if(choosen != null) {
mayor.stopChoosing(); mayor.stopChoosing();
@ -816,9 +803,7 @@ public class LGGame implements Listener{
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) { if(!event.isCancelled()) {
broadcastMessage("§9Il est temps de voter pour élire un §5§lCapitaine§9."); broadcastMessage("§9Il est temps de voter pour élire un §5§lCapitaine§9.");
vote = new LGVote(180, 20, this, true, true, (player, secondsLeft)-> { 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");
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.start(getAlive(), getInGame(), ()->{ vote.start(getAlive(), getInGame(), ()->{
if(vote.getChoosen() == null) if(vote.getChoosen() == null)
setMayor(getAlive().get(random.nextInt(getAlive().size()))); setMayor(getAlive().get(random.nextInt(getAlive().size())));
@ -851,9 +836,7 @@ public class LGGame implements Listener{
if(!event.isCancelled()) { if(!event.isCancelled()) {
broadcastMessage("§9La phase des votes a commencé."); broadcastMessage("§9La phase des votes a commencé.");
isPeopleVote = true; isPeopleVote = true;
vote = new LGVote(180, 20, this, false, false, (player, secondsLeft)-> { 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");
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.start(getAlive(), getInGame(), ()->{ vote.start(getAlive(), getInGame(), ()->{
isPeopleVote = false; isPeopleVote = false;
if(vote.getChoosen() == null || (vote.isMayorVote() && getMayor() == null)) if(vote.getChoosen() == null || (vote.isMayorVote() && getMayor() == null))

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class LGChat { 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; @Getter private final LGChatCallback defaultCallback;
public interface LGChatCallback{ public interface LGChatCallback{

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package fr.leomelki.loupgarou.listeners; package fr.leomelki.loupgarou.listeners;
import fr.leomelki.loupgarou.MainLg;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@ -9,10 +10,15 @@ import org.bukkit.event.player.PlayerAnimationType;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
public class VoteListener implements Listener{ public class VoteListener implements Listener{
private final MainLg plugin;
public VoteListener(MainLg mainLg) {
this.plugin = mainLg;
}
@EventHandler @EventHandler
public void onClick(PlayerAnimationEvent e) { public void onClick(PlayerAnimationEvent e) {
if(e.getAnimationType() == PlayerAnimationType.ARM_SWING) if(e.getAnimationType() == PlayerAnimationType.ARM_SWING)
LGPlayer.thePlayer(e.getPlayer()).chooseAction(); LGPlayer.thePlayer(plugin, e.getPlayer()).chooseAction();
} }
@EventHandler @EventHandler
public void onBreak(BlockBreakEvent e) { 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.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent; 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.LGPlayerGotKilledEvent;
import fr.leomelki.loupgarou.events.LGVoteEvent; import fr.leomelki.loupgarou.events.LGVoteEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
@ -93,7 +91,7 @@ public class RAnge extends Role{
vote = false; vote = false;
} }
} }
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>(); final ArrayList<LGPlayer> winners = new ArrayList<>();
int night = 1; int night = 1;
@EventHandler @EventHandler
public void onDeath(LGPlayerGotKilledEvent e) { 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -61,17 +60,14 @@ public class RAssassin extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null && choosen != player) {
public void callback(LGPlayer choosen) { getGame().kill(choosen, Reason.ASSASSIN);
if(choosen != null && choosen != player) { player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir");
getGame().kill(choosen, Reason.ASSASSIN); player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir"); player.stopChoosing();
player.sendMessage("§6Tu as choisi de tuer §7§l"+choosen.getName()+"§6."); player.hideView();
player.stopChoosing(); callback.run();
player.hideView();
callback.run();
}
} }
}); });
} }

View file

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

View file

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

View file

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

View file

@ -6,9 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import fr.leomelki.loupgarou.MainLg; import fr.leomelki.loupgarou.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGDayEndEvent; import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGVoteEvent; import fr.leomelki.loupgarou.events.LGVoteEvent;
public class RCorbeau extends Role{ public class RCorbeau extends Role{
@ -56,20 +54,17 @@ public class RCorbeau extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null && choosen != player) {
public void callback(LGPlayer choosen) { //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
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);
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.sendActionBarMessage("§e§l"+choosen.getName()+"§6 aura deux votes contre lui"); player.stopChoosing();
player.sendMessage("§6Tu nuis à la réputation de §7§l"+choosen.getName()+"§6."); player.hideView();
player.stopChoosing(); callback.run();
player.hideView();
callback.run();
}
} }
}); });
} }
@ -87,14 +82,14 @@ public class RCorbeau extends Role{
for(LGPlayer lgp : getGame().getAlive()) for(LGPlayer lgp : getGame().getAlive())
if(lgp.getCache().getBoolean("corbeau_selected")) { if(lgp.getCache().getBoolean("corbeau_selected")) {
lgp.getCache().remove("corbeau_selected"); lgp.getCache().remove("corbeau_selected");
LGPlayer lg = lgp;
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg); MainLg plugin = getGame().getPlugin();
getGame().getVote().vote(new LGPlayer("§a§lLe corbeau"), lg);//fix getGame().getVote().vote(new LGPlayer(plugin, "§a§lLe corbeau"), lgp);
getGame().broadcastMessage("§7§l"+lg.getName()+"§6 a reçu la visite du "+getName()+"§6."); 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()); }.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.MainLg;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -85,34 +84,31 @@ public class RCupidon extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null) {
public void callback(LGPlayer choosen) { if(player.getCache().has("cupidon_first")) {
if(choosen != null) { LGPlayer first = player.getCache().remove("cupidon_first");
if(player.getCache().has("cupidon_first")) { if(first == choosen) {
LGPlayer first = player.getCache().remove("cupidon_first"); int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId();
if(first == choosen) { WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
int entityId = Integer.MAX_VALUE-choosen.getPlayer().getEntityId(); destroy.setEntityIds(new int[] {entityId});
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); destroy.sendPacket(player.getPlayer());
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
} else {
// sendHead(player, choosen);
int entityId = Integer.MAX_VALUE-first.getPlayer().getEntityId();
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
destroy.setEntityIds(new int[] {entityId});
destroy.sendPacket(player.getPlayer());
setInLove(first, choosen);
player.sendMessage("§7§l"+first.getName()+"§9 et §7§l"+choosen.getName()+"§9 sont désormais follement amoureux.");
player.stopChoosing();
player.hideView();
callback.run();
}
} else { } else {
sendHead(player, choosen); // sendHead(player, choosen);
player.getCache().set("cupidon_first", 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(); player2.updatePrefix();
} }
WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), final WrappedDataWatcherObject invisible = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)); final WrappedDataWatcherObject noGravity = new WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class));
protected void sendHead(LGPlayer to, LGPlayer ofWho) { protected void sendHead(LGPlayer to, LGPlayer ofWho) {
int entityId = Integer.MAX_VALUE-ofWho.getPlayer().getEntityId(); int entityId = Integer.MAX_VALUE-ofWho.getPlayer().getEntityId();
WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving(); WrapperPlayServerSpawnEntityLiving spawn = new WrapperPlayServerSpawnEntityLiving();
@ -207,7 +203,7 @@ public class RCupidon extends Role{
public void onGameEnd(LGGameEndEvent e) { public void onGameEnd(LGGameEndEvent e) {
if(e.getGame() == getGame()) { if(e.getGame() == getGame()) {
WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
ArrayList<Integer> ids = new ArrayList<Integer>(); ArrayList<Integer> ids = new ArrayList<>();
for(LGPlayer lgp : getGame().getInGame()) for(LGPlayer lgp : getGame().getInGame())
ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId()); ids.add(Integer.MAX_VALUE-lgp.getPlayer().getEntityId());
int[] intList = new int[ids.size()]; int[] intList = new int[ids.size()];
@ -237,7 +233,7 @@ public class RCupidon extends Role{
@EventHandler @EventHandler
public void onEndCheck(LGEndCheckEvent e) { public void onEndCheck(LGEndCheckEvent e) {
if(e.getGame() == getGame()) { if(e.getGame() == getGame()) {
ArrayList<LGPlayer> winners = new ArrayList<LGPlayer>(); ArrayList<LGPlayer> winners = new ArrayList<>();
for(LGPlayer lgp : getGame().getAlive()) for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleWinType() != RoleWinType.NONE) if(lgp.getRoleWinType() != RoleWinType.NONE)
winners.add(lgp); winners.add(lgp);
@ -253,7 +249,7 @@ public class RCupidon extends Role{
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onChat(AsyncPlayerChatEvent e) { public void onChat(AsyncPlayerChatEvent e) {
LGPlayer player = LGPlayer.thePlayer(e.getPlayer()); LGPlayer player = LGPlayer.thePlayer(getGame().getPlugin(), e.getPlayer());
if(player.getGame() == getGame()) { if(player.getGame() == getGame()) {
if(e.getMessage().startsWith("!")) { if(e.getMessage().startsWith("!")) {
if(player.getCache().has("inlove")){ if(player.getCache().has("inlove")){

View file

@ -1,39 +1,7 @@
package fr.leomelki.loupgarou.roles; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; 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 class RDetective extends Role{
public RDetective(LGGame game) { public RDetective(LGGame game) {
@ -80,32 +48,29 @@ public class RDetective extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null) {
public void callback(LGPlayer choosen) { if(choosen == player) {
if(choosen != null) { player.sendMessage("§cVous ne pouvez pas vous sélectionner !");
if(choosen == player) { return;
player.sendMessage("§cVous ne pouvez pas vous sélectionner !"); }
return; if(player.getCache().has("detective_first")) {
} LGPlayer first = player.getCache().remove("detective_first");
if(player.getCache().has("detective_first")) { if(first == choosen) {
LGPlayer first = player.getCache().remove("detective_first"); player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !");
if(first == choosen) {
player.sendMessage("§cVous ne pouvez pas comparer §7§l"+first.getName()+"§c avec lui même !");
} else {
if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType())
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 sont §adu même camp.");
else
player.sendMessage("§7§l"+first.getName()+"§6 et §7§l"+choosen.getName()+"§6 ne sont §cpas du même camp.");
player.stopChoosing();
player.hideView();
callback.run();
}
} else { } else {
player.getCache().set("detective_first", choosen); if((first.getRoleType() == RoleType.NEUTRAL || choosen.getRoleType() == RoleType.NEUTRAL) ? first.getRole().getClass() == choosen.getRole().getClass() : first.getRoleType() == choosen.getRoleType())
player.sendMessage("§9Choisis un joueur avec qui tu souhaites comparer le rôle de §7§l"+choosen.getName()); 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -35,7 +36,7 @@ public class RDictateur extends Role{
items[3] = new ItemStack(Material.IRON_NUGGET); items[3] = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = items[3].getItemMeta(); ItemMeta meta = items[3].getItemMeta();
meta.setDisplayName("§7§lNe rien faire"); 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[3].setItemMeta(meta);
items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER); items[5] = new ItemStack(Material./*DIAMOND_SWORD*/GUNPOWDER);
meta = items[5].getItemMeta(); meta = items[5].getItemMeta();
@ -122,7 +123,7 @@ public class RDictateur extends Role{
public void onInventoryClick(InventoryClickEvent e) { public void onInventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem(); ItemStack item = e.getCurrentItem();
Player player = (Player)e.getWhoClicked(); 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(lgp.getRole() != this || item == null || item.getItemMeta() == null)return;
@ -148,7 +149,7 @@ public class RDictateur extends Role{
@EventHandler @EventHandler
public void onClick(PlayerInteractEvent e) { public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer(); 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) { if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
getGame().cancelWait(); getGame().cancelWait();
player.stopChoosing(); player.stopChoosing();
@ -162,7 +163,7 @@ public class RDictateur extends Role{
@EventHandler @EventHandler
public void onQuitInventory(InventoryCloseEvent e) { public void onQuitInventory(InventoryCloseEvent e) {
if(e.getInventory() instanceof CraftInventoryCustom) { 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) { if(player.getRole() == this && inMenu) {
new BukkitRunnable() { new BukkitRunnable() {
@ -218,9 +219,7 @@ public class RDictateur extends Role{
lgp.getPlayer().getInventory().setItem(8, null); lgp.getPlayer().getInventory().setItem(8, null);
lgp.getPlayer().updateInventory(); lgp.getPlayer().updateInventory();
this.run(); this.run();
}, (player, secondsLeft)->{ }, (player, secondsLeft)-> lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)");
return lgp == player ? "§9§lC'est à ton tour !" : "§6Le Dictateur choisit sa victime (§e"+secondsLeft+" s§6)";
});
lgp.choose((choosen)->{ lgp.choose((choosen)->{
if(choosen != null) { if(choosen != null) {
getGame().cancelWait(); getGame().cancelWait();

View file

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

View file

@ -1,13 +1,13 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Comparator;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import fr.leomelki.loupgarou.classes.LGCustomItems; import fr.leomelki.loupgarou.classes.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import java.util.Comparator;
public class REnfantSauvageLG extends Role{ public class REnfantSauvageLG extends Role{
public REnfantSauvageLG(LGGame game) { public REnfantSauvageLG(LGGame game) {
super(game); super(game);
@ -71,12 +71,7 @@ public class REnfantSauvageLG extends Role{
if(lgRole == null) { if(lgRole == null) {
getGame().getRoles().add(lgRole = new RLoupGarou(getGame())); getGame().getRoles().add(lgRole = new RLoupGarou(getGame()));
getGame().getRoles().sort(new Comparator<Role>() { getGame().getRoles().sort(Comparator.comparingInt(Role::getTurnOrder));
@Override
public int compare(Role role1, Role role2) {
return role1.getTurnOrder()-role2.getTurnOrder();
}
});
} }
lgRole.join(player, false); 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent; import fr.leomelki.loupgarou.events.LGNightPlayerPreKilledEvent;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGPreDayStartEvent; import fr.leomelki.loupgarou.events.LGPreDayStartEvent;
@ -59,30 +58,27 @@ public class RGarde extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null) {
public void callback(LGPlayer choosen) { LGPlayer lastProtected = player.getCache().get("garde_lastProtected");
if(choosen != null) { if(choosen == lastProtected) {
LGPlayer lastProtected = player.getCache().get("garde_lastProtected"); if(lastProtected == player)
if(choosen == lastProtected) { player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière.");
if(lastProtected == player) else
player.sendMessage("§4§oTu t'es déjà protégé la nuit dernière."); player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière.");
else } else {
player.sendMessage("§4§oTu as déjà protégé §7§l§o"+lastProtected.getName()+"§4§o la nuit dernière."); if(choosen == player) {
} else { player.sendMessage("§6Tu décides de te protéger toi-même cette nuit.");
if(choosen == player) { player.sendActionBarMessage("§9Tu seras protégé.");
player.sendMessage("§6Tu décides de te protéger toi-même cette nuit."); } else {
player.sendActionBarMessage("§9Tu seras protégé."); player.sendMessage("§6Tu vas protéger §7§l"+choosen.getName()+"§6 cette nuit.");
} else { player.sendActionBarMessage("§7§l"+choosen.getName()+"§9 sera protégé.");
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();
} }
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; 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.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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; 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;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
@ -79,17 +67,14 @@ public class RGrandMechantLoup extends Role{
this.callback = callback; this.callback = callback;
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null && choosen != player) {
public void callback(LGPlayer choosen) { player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit");
if(choosen != null && choosen != player) { player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 va mourir cette nuit"); getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU);
player.sendMessage("§6Tu as choisi de manger §7§l"+choosen.getName()+"§6."); player.stopChoosing();
getGame().kill(choosen, getGame().getDeaths().containsKey(Reason.LOUP_GAROU) ? Reason.GM_LOUP_GAROU : Reason.LOUP_GAROU); player.hideView();
player.stopChoosing(); callback.run();
player.hideView();
callback.run();
}
} }
}); });
} }

View file

@ -71,9 +71,7 @@ public class RLoupGarou extends Role{
return 30; return 30;
} }
@Getter private final LGChat chat = new LGChat((sender, message) -> { @Getter private final LGChat chat = new LGChat((sender, message) -> "§c"+sender.getName()+" §6» §f"+message);
return "§c"+sender.getName()+" §6» §f"+message;
});
boolean showSkins = false; boolean showSkins = false;
LGVote vote; LGVote vote;
@ -86,9 +84,7 @@ public class RLoupGarou extends Role{
} }
public void onNightTurn(Runnable callback) { public void onNightTurn(Runnable callback) {
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> { 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");
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";
});
for(LGPlayer lgp : getGame().getAlive()) for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.LOUP_GAROU) if(lgp.getRoleType() == RoleType.LOUP_GAROU)
lgp.showView(); lgp.showView();
@ -124,7 +120,7 @@ public class RLoupGarou extends Role{
equal = true; equal = true;
if(equal) { if(equal) {
choosen = null; choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>(); ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet()) for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.LOUP_GAROU) if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.LOUP_GAROU)
choosable.add(entry.getKey()); choosable.add(entry.getKey());

View file

@ -1,6 +1,6 @@
package fr.leomelki.loupgarou.roles; package fr.leomelki.loupgarou.roles;
import java.util.Arrays; import java.util.Collections;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
import fr.leomelki.loupgarou.classes.LGWinType; import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.events.LGEndCheckEvent; import fr.leomelki.loupgarou.events.LGEndCheckEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent;
@ -24,7 +23,7 @@ public class RLoupGarouBlanc extends Role{
skip = new ItemStack(Material.IRON_NUGGET); skip = new ItemStack(Material.IRON_NUGGET);
ItemMeta meta = skip.getItemMeta(); ItemMeta meta = skip.getItemMeta();
meta.setDisplayName("§7§lNe rien faire"); meta.setDisplayName("§7§lNe rien faire");
meta.setLore(Arrays.asList("§8Passez votre tour")); meta.setLore(Collections.singletonList("§8Passez votre tour"));
skip.setItemMeta(meta); skip.setItemMeta(meta);
} }
@ -93,30 +92,27 @@ public class RLoupGarouBlanc extends Role{
RLoupGarou lg = lg_; RLoupGarou lg = lg_;
player.showView(); player.showView();
player.getPlayer().getInventory().setItem(8, skip); player.getPlayer().getInventory().setItem(8, skip);
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null && choosen != player) {
public void callback(LGPlayer choosen) { if(!lg.getPlayers().contains(choosen)) {
if(choosen != null && choosen != player) { player.sendMessage("§7§l"+choosen.getName()+"§4 n'est pas un Loup-Garou.");
if(!lg.getPlayers().contains(choosen)) { return;
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.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 @EventHandler
public void onClick(PlayerInteractEvent e) { public void onClick(PlayerInteractEvent e) {
Player p = e.getPlayer(); 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) { if(e.getItem() != null && e.getItem().getType() == Material.IRON_NUGGET && player.getRole() == this) {
player.stopChoosing(); player.stopChoosing();
p.getInventory().setItem(8, null); p.getInventory().setItem(8, null);

View file

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

View file

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

View file

@ -50,7 +50,7 @@ public class RPetiteFille extends Role{
return -1; 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 @EventHandler
public void onChangeRole(LGRoleTurnEndEvent e) { public void onChangeRole(LGRoleTurnEndEvent e) {
@ -61,9 +61,7 @@ public class RPetiteFille extends Role{
RLoupGarou lgRole = (RLoupGarou)role; RLoupGarou lgRole = (RLoupGarou)role;
for(LGPlayer player : getPlayers()) for(LGPlayer player : getPlayers())
if(!player.getCache().getBoolean("infected") && player.isRoleActive()) if(!player.getCache().getBoolean("infected") && player.isRoleActive())
player.joinChat(lgRole.getChat(), (sender, message)->{ player.joinChat(lgRole.getChat(), (sender, message)-> "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message, true);
return "§c"+customNames.get(lgRole.getPlayers().indexOf(sender))+" §6» §f"+message;
}, true);
break; break;
} }
if(e.getPreviousRole() instanceof RLoupGarou) if(e.getPreviousRole() instanceof RLoupGarou)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,11 +7,8 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; 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.LGCustomItems;
import fr.leomelki.loupgarou.classes.LGCustomSkin;
import fr.leomelki.loupgarou.classes.LGGame; import fr.leomelki.loupgarou.classes.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGVote; import fr.leomelki.loupgarou.classes.LGVote;
@ -19,12 +16,9 @@ import fr.leomelki.loupgarou.classes.LGWinType;
import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints; import fr.leomelki.loupgarou.classes.LGCustomItems.LGCustomItemsConstraints;
import fr.leomelki.loupgarou.classes.chat.LGChat; import fr.leomelki.loupgarou.classes.chat.LGChat;
import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent; import fr.leomelki.loupgarou.events.LGCustomItemChangeEvent;
import fr.leomelki.loupgarou.events.LGDayEndEvent;
import fr.leomelki.loupgarou.events.LGGameEndEvent; import fr.leomelki.loupgarou.events.LGGameEndEvent;
import fr.leomelki.loupgarou.events.LGNightEndEvent; import fr.leomelki.loupgarou.events.LGNightEndEvent;
import fr.leomelki.loupgarou.events.LGNightStart;
import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason; import fr.leomelki.loupgarou.events.LGPlayerKilledEvent.Reason;
import fr.leomelki.loupgarou.events.LGSkinLoadEvent;
import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent; import fr.leomelki.loupgarou.events.LGUpdatePrefixEvent;
import fr.leomelki.loupgarou.events.LGVampiredEvent; import fr.leomelki.loupgarou.events.LGVampiredEvent;
import lombok.Getter; import lombok.Getter;
@ -82,9 +76,7 @@ public class RVampire extends Role{
return nextCanInfect < getGame().getNight() && super.hasPlayersLeft(); return nextCanInfect < getGame().getNight() && super.hasPlayersLeft();
} }
@Getter private final LGChat chat = new LGChat((sender, message) -> { @Getter private final LGChat chat = new LGChat((sender, message) -> "§5"+sender.getName()+" §6» §f"+message);
return "§5"+sender.getName()+" §6» §f"+message;
});
int nextCanInfect = 0; int nextCanInfect = 0;
LGVote vote; LGVote vote;
@Override @Override
@ -95,9 +87,7 @@ public class RVampire extends Role{
} }
public void onNightTurn(Runnable callback) { public void onNightTurn(Runnable callback) {
vote = new LGVote(getTimeout(), getTimeout()/3, getGame(), false, false, (player, secondsLeft)-> { 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");
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";
});
for(LGPlayer lgp : getGame().getAlive()) for(LGPlayer lgp : getGame().getAlive())
if(lgp.getRoleType() == RoleType.VAMPIRE) if(lgp.getRoleType() == RoleType.VAMPIRE)
lgp.showView(); lgp.showView();
@ -132,7 +122,7 @@ public class RVampire extends Role{
equal = true; equal = true;
if(equal) { if(equal) {
choosen = null; choosen = null;
ArrayList<LGPlayer> choosable = new ArrayList<LGPlayer>(); ArrayList<LGPlayer> choosable = new ArrayList<>();
for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet()) for(Entry<LGPlayer, List<LGPlayer>> entry : vote.getVotes().entrySet())
if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.VAMPIRE) if(entry.getValue().size() == max && entry.getKey().getRoleType() != RoleType.VAMPIRE)
choosable.add(entry.getKey()); 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.LGGame;
import fr.leomelki.loupgarou.classes.LGPlayer; import fr.leomelki.loupgarou.classes.LGPlayer;
import fr.leomelki.loupgarou.classes.LGPlayer.LGChooseCallback;
public class RVoyante extends Role{ public class RVoyante extends Role{
public RVoyante(LGGame game) { public RVoyante(LGGame game) {
@ -50,17 +49,14 @@ public class RVoyante extends Role{
protected void onNightTurn(LGPlayer player, Runnable callback) { protected void onNightTurn(LGPlayer player, Runnable callback) {
player.showView(); player.showView();
player.choose(new LGChooseCallback() { player.choose(choosen -> {
@Override if(choosen != null && choosen != player) {
public void callback(LGPlayer choosen) { //player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20);
if(choosen != null && choosen != player) { player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName());
//player.sendTitle("§6Vous avez regardé un rôle", "§e§l"+choosen.getName()+"§6§l est §e§l"+choosen.getRole().getName(), 5*20); player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6.");
player.sendActionBarMessage("§e§l"+choosen.getName()+"§6 est §e§l"+choosen.getRole().getName()); player.stopChoosing();
player.sendMessage("§6Tu découvres que §7§l"+choosen.getName()+"§6 est "+choosen.getRole().getName()+"§6."); player.hideView();
player.stopChoosing(); callback.run();
player.hideView();
callback.run();
}
} }
}); });
} }

View file

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

View file

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

View file

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

View file

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