Amélioration de la clarté du code & suppression de debugs

- Amélioration de la clarté du code
- Suppression de debugs inutiles
This commit is contained in:
leomelki 2020-03-18 13:12:18 +01:00
parent d318f13ea4
commit 16ae73421c
5 changed files with 46 additions and 128 deletions

View file

@ -90,7 +90,6 @@ public class MainLg extends JavaPlugin{
@Override @Override
public void onEnable() { public void onEnable() {
// Audio4WebPlugin.getMain().unRegisterPackets();
instance = this; instance = this;
loadRoles(); loadRoles();
if(!new File(getDataFolder(), "config.yml").exists()) {//Créer la config if(!new File(getDataFolder(), "config.yml").exists()) {//Créer la config
@ -115,12 +114,10 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
// if (event.getPacketType() == PacketType.Play.Server.UPDATE_TIME) {
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket()); WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket());
LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer()); LGPlayer lgp = LGPlayer.thePlayer(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,7 +134,6 @@ 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) {
// if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(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<PlayerInfoData>();
@ -165,19 +161,16 @@ public class MainLg extends JavaPlugin{
datas.add(data); datas.add(data);
} }
info.setData(datas); info.setData(datas);
// }
} }
}); });
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) {
// if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(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);
} }
// }
} }
}); });
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) { protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) {
@ -202,14 +195,12 @@ 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) {
// if (event.getPacketType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer()); LGPlayer player = LGPlayer.thePlayer(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())
equip.setItem(new ItemStack(Material.AIR)); equip.setItem(new ItemStack(Material.AIR));
} }
// }
} }
}); });

View file

@ -205,14 +205,8 @@ public class LGGame implements Listener{
lgp.joinChat(dayChat); lgp.joinChat(dayChat);
/* WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
team.setMode(1);
team.setName("you_are");
team.sendPacket(lgp.getPlayer());*/
lgp.setGame(this); lgp.setGame(this);
inGame.add(lgp); inGame.add(lgp);
System.out.println("add > "+inGame);
lgp.setScoreboard(null); lgp.setScoreboard(null);
@ -228,7 +222,7 @@ public class LGGame implements Listener{
} }
lgp.getPlayer().setGameMode(GameMode.ADVENTURE); lgp.getPlayer().setGameMode(GameMode.ADVENTURE);
//broadcastMessage("§7Le joueur §8"+lgp.getName()+"§7 a rejoint la partie §9(§8"+inGame.size()+"§7/§8"+maxPlayers+"§9)"); broadcastMessage("§7Le joueur §8"+lgp.getName()+"§7 a rejoint la partie §9(§8"+inGame.size()+"§7/§8"+maxPlayers+"§9)");
//Reset scoreboard //Reset scoreboard
WrapperPlayServerScoreboardObjective obj = new WrapperPlayServerScoreboardObjective(); WrapperPlayServerScoreboardObjective obj = new WrapperPlayServerScoreboardObjective();
@ -341,6 +335,7 @@ public class LGGame implements Listener{
}.runTaskTimer(MainLg.getInstance(), 0, 4); }.runTaskTimer(MainLg.getInstance(), 0, 4);
} }
private void _start() { private void _start() {
broadcastMessage("§8Plugin développé par §e§lleomelki§8.\n§8Projet organisé par §e§lShytoos§8.\n");
broadcastMessage("§8§oDébut de la partie..."); broadcastMessage("§8§oDébut de la partie...");
//Give roles... //Give roles...
ArrayList<LGPlayer> toGive = (ArrayList<LGPlayer>) inGame.clone(); ArrayList<LGPlayer> toGive = (ArrayList<LGPlayer>) inGame.clone();
@ -380,10 +375,6 @@ public class LGGame implements Listener{
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<IndexedRole>(roles_.values());
for(IndexedRole role : roles) {
System.out.println(role.getRole().getName()+" -> "+role.getNumber());
}
System.out.println(roles);
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));
@ -541,14 +532,6 @@ public class LGGame implements Listener{
Bukkit.getPluginManager().callEvent(new LGPlayerGotKilledEvent(this, killed, reason, !checkEndGame(false) && endGame)); Bukkit.getPluginManager().callEvent(new LGPlayerGotKilledEvent(this, killed, reason, !checkEndGame(false) && endGame));
/*PlayerInventory inv = killed.getPlayer().getInventory();
ItemStack is = new ItemStack(Material.CYAN_DYE);
ItemMeta meta = is.getItemMeta();
meta.setDisplayName("§a");
is.setItemMeta(meta);
for(int i = 0;i<9;i++)
inv.setItem(i, is);
killed.getPlayer().updateInventory();*/
VariousUtils.setWarning(killed.getPlayer(), true); VariousUtils.setWarning(killed.getPlayer(), true);
killed.getPlayer().getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN)); killed.getPlayer().getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN));
@ -600,7 +583,6 @@ public class LGGame implements Listener{
broadcastMessage(winType.getMessage()); broadcastMessage(winType.getMessage());
for(LGPlayer lgp : getInGame()) { for(LGPlayer lgp : getInGame()) {
System.out.println(lgp.getName()+" (spec)");
lgp.leaveChat(); lgp.leaveChat();
lgp.joinChat(spectatorChat); lgp.joinChat(spectatorChat);
@ -618,11 +600,8 @@ public class LGGame implements Listener{
Player p = lgp.getPlayer(); Player p = lgp.getPlayer();
/* p.getInventory().clear();
p.updateInventory();*/
lgp.showView(); lgp.showView();
p.removePotionEffect(PotionEffectType.JUMP); p.removePotionEffect(PotionEffectType.JUMP);
// p.removePotionEffect(PotionEffectType.INVISIBILITY);
p.setWalkSpeed(0.2f); p.setWalkSpeed(0.2f);
} }
@ -635,6 +614,7 @@ public class LGGame implements Listener{
team.sendPacket(lgp.getPlayer()); team.sendPacket(lgp.getPlayer());
LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame()); LGPlayer.thePlayer(lgp.getPlayer()).join(MainLg.getInstance().getCurrentGame());
} }
//A remettre pour activer le démarrage automatique
/* wait(30, ()->{ /* wait(30, ()->{
for(LGPlayer lgp : getInGame()) for(LGPlayer lgp : getInGame())
if(lgp.getPlayer().isOnline()) { if(lgp.getPlayer().isOnline()) {
@ -671,8 +651,6 @@ public class LGGame implements Listener{
int died = 0; int died = 0;
boolean endGame = false; boolean endGame = false;
//Play rooster crowing sound !
//p.playAudio("https://leomelki.fr/a4w/gamemode/loupgarou/Rooster-crowing-sound.mp3", 0.3);
for(Entry<Reason, LGPlayer> entry : deaths.entrySet()) { for(Entry<Reason, LGPlayer> entry : deaths.entrySet()) {
if(entry.getKey() == Reason.DONT_DIE) if(entry.getKey() == Reason.DONT_DIE)
@ -723,10 +701,9 @@ public class LGGame implements Listener{
} }
} }
public void startDay() { public void startDay() {
for(LGPlayer player : getInGame()) { for(LGPlayer player : getInGame())
player.joinChat(dayChat, player.isDead()); player.joinChat(dayChat, player.isDead());
System.out.println(player.getName()+" > "+player.isDead()+" (startDay)");
}
LGDayStartEvent dayStart = new LGDayStartEvent(this); LGDayStartEvent dayStart = new LGDayStartEvent(this);
Bukkit.getPluginManager().callEvent(dayStart); Bukkit.getPluginManager().callEvent(dayStart);
if(dayStart.isCancelled()) if(dayStart.isCancelled())
@ -818,9 +795,6 @@ public class LGGame implements Listener{
setMayor(vote.getChoosen()); setMayor(vote.getChoosen());
broadcastMessage("§7§l"+mayor.getName()+"§6 devient le §5§lCapitaine §6du village."); broadcastMessage("§7§l"+mayor.getName()+"§6 devient le §5§lCapitaine §6du village.");
/*LGGame.this.wait(5, this::peopleVote, (player, secondsLeft)->{
return "§6Le peuple va voter dans §e"+secondsLeft+" seconde"+(secondsLeft > 1 ? "s" : "");
});*/
peopleVote(); peopleVote();
}); });
} }

View file

@ -103,7 +103,6 @@ public class LGPlayer {
titlePacket.setStay(stay); titlePacket.setStay(stay);
titlePacket.setFadeOut(10); titlePacket.setFadeOut(10);
titlePacket.sendPacket(player); titlePacket.sendPacket(player);
//player.sendTitle(title, subTitle);
titlePacket = new WrapperPlayServerTitle(); titlePacket = new WrapperPlayServerTitle();
titlePacket.setAction(TitleAction.TITLE); titlePacket.setAction(TitleAction.TITLE);
@ -185,14 +184,6 @@ public class LGPlayer {
if(getGame() != null && !isDead() && player != null) { if(getGame() != null && !isDead() && player != null) {
List<String> meList = Arrays.asList(getName()); List<String> meList = Arrays.asList(getName());
for(LGPlayer lgp : getGame().getInGame()) { for(LGPlayer lgp : getGame().getInGame()) {
/* WrapperPlayServerScoreboardTeam team = new WrapperPlayServerScoreboardTeam();
LGUpdatePrefixEvent event = new LGUpdatePrefixEvent(getGame(), this, lgp, "");
Bukkit.getPluginManager().callEvent(event);
team.setPrefix(WrappedChatComponent.fromText(event.getPrefix()));
team.setMode(2);
team.setName(getName());
team.setPlayers(meList);
team.sendPacket(lgp.getPlayer());*/
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(); WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>(); ArrayList<PlayerInfoData> infos = new ArrayList<PlayerInfoData>();
info.setAction(PlayerInfoAction.ADD_PLAYER); info.setAction(PlayerInfoAction.ADD_PLAYER);
@ -313,13 +304,10 @@ public class LGPlayer {
if(lgp != this && lgp.getPlayer() != null) if(lgp != this && lgp.getPlayer() != null)
lgp.getPlayer().hidePlayer(getPlayer()); lgp.getPlayer().hidePlayer(getPlayer());
muted = true; muted = true;
/* for(Player player : Bukkit.getOnlinePlayers())
Audio4WebPlugin.getMain().mute(getPlayer(), player);//On mute le joueur pour tout le monnde*/
} }
public void resetMuted() { public void resetMuted() {
muted = false; muted = false;
} }
//@Getter private ArrayList<LGPlayer> sendTo = new ArrayList<LGPlayer>();
@Getter private LGChat chat; @Getter private LGChat chat;
@ -351,50 +339,17 @@ public class LGPlayer {
public void onChat(String message) { public void onChat(String message) {
if(chat != null) { if(chat != null) {
chat.sendMessage(this, message); chat.sendMessage(this, message);
/* if(getGame().isStarted()) {
if(isDead()) {
for(LGPlayer lgp : getGame().getInGame())
if(lgp.isDead() || sendTo.contains(lgp))
lgp.sendMessage("§8Spectateur §o§l"+getName()+" > §7§o"+message);
}else if(sendTo.size() != 0) {
for(LGPlayer lgp : getSendTo())
lgp.sendMessage("§6§o§l"+getName()+" > §e§o"+message);
sendMessage("§6§o§l"+getName()+" > §e§o"+message);
}
} else
getGame().broadcastMessage("§8§l"+getName()+" > §7"+message);*/
} }
} }
/*public void mute(LGPlayer toMute) {
toMute.getSendTo().remove(this);
// Audio4WebPlugin.getMain().mute(toMute.getPlayer(), getPlayer());
}*/
/*public void unMute(LGPlayer toUnMute) {
toUnMute.getSendTo().add(this);
// Audio4WebPlugin.getMain().unMute(toUnMute.getPlayer(), getPlayer());
}*/
public void playAudio(LGSound sound, double volume) { public void playAudio(LGSound sound, double volume) {
if(player != null) if(player != null)
getPlayer().playSound(getPlayer().getLocation(), sound.getSound(), (float)volume, 1); getPlayer().playSound(getPlayer().getLocation(), sound.getSound(), (float)volume, 1);
/* try {
System.out.println("send "+url+" to "+getName()+" at "+volume);
Audio4WebPlugin.getMain().askPlay(getPlayer(), url, volume);
} catch (IOException e) {
e.printStackTrace();
}*/
} }
public void stopAudio(LGSound sound) { public void stopAudio(LGSound sound) {
if(player != null) if(player != null)
getPlayer().stopSound(sound.getSound()); getPlayer().stopSound(sound.getSound());
/* try {
System.out.println("send "+url+" to "+getName()+" at "+volume);
Audio4WebPlugin.getMain().askPlay(getPlayer(), url, volume);
} catch (IOException e) {
e.printStackTrace();
}*/
} }
long lastChoose; long lastChoose;

View file

@ -103,7 +103,6 @@ public class LGVote {
} }
private void end() { private void end() {
ended = true; ended = true;
System.out.println("end "+votes+" this");
for(LGPlayer lgp : viewers) for(LGPlayer lgp : viewers)
showVoting(lgp, null); showVoting(lgp, null);
for(LGPlayer lgp : votes.keySet()) for(LGPlayer lgp : votes.keySet())
@ -204,7 +203,6 @@ public class LGVote {
game.cancelWait(); game.cancelWait();
callback.run(); callback.run();
} }
System.out.println("total end "+votes+" - "+this);
} }
public LGChooseCallback getChooseCallback(LGPlayer who) { public LGChooseCallback getChooseCallback(LGPlayer who) {

View file

@ -1,5 +1,5 @@
name: LoupGarou name: LoupGarou
version: 0.0.2 version: 1.0.0
description: Permet de jouer au jeu du loup garou description: Permet de jouer au jeu du loup garou
main: fr.leomelki.loupgarou.MainLg main: fr.leomelki.loupgarou.MainLg
depend: [ProtocolLib] depend: [ProtocolLib]