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
public void onEnable() {
// Audio4WebPlugin.getMain().unRegisterPackets();
instance = this;
loadRoles();
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) {
@Override
public void onPacketSending(PacketEvent event) {
// if (event.getPacketType() == PacketType.Play.Server.UPDATE_TIME) {
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket());
LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer());
if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay())
event.setCancelled(true);
// }
WrapperPlayServerUpdateTime time = new WrapperPlayServerUpdateTime(event.getPacket());
LGPlayer lgp = LGPlayer.thePlayer(event.getPlayer());
if(lgp.getGame() != null && lgp.getGame().getTime() != time.getTimeOfDay())
event.setCancelled(true);
}
}
);
@ -137,47 +134,43 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
// if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket());
ArrayList<PlayerInfoData> datas = new ArrayList<PlayerInfoData>();
for(PlayerInfoData data : info.getData()) {
LGPlayer lgp = LGPlayer.thePlayer(Bukkit.getPlayer(data.getProfile().getUUID()));
if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
WrappedChatComponent displayName = data.getDisplayName();
Bukkit.getPluginManager().callEvent(evt2);
if(evt2.getPrefix().length() > 0) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event.getPacket());
ArrayList<PlayerInfoData> datas = new ArrayList<PlayerInfoData>();
for(PlayerInfoData data : info.getData()) {
LGPlayer lgp = LGPlayer.thePlayer(Bukkit.getPlayer(data.getProfile().getUUID()));
if(player.getGame() != null && player.getGame() == lgp.getGame()) {
LGUpdatePrefixEvent evt2 = new LGUpdatePrefixEvent(player.getGame(), lgp, player, "");
WrappedChatComponent displayName = data.getDisplayName();
Bukkit.getPluginManager().callEvent(evt2);
if(evt2.getPrefix().length() > 0) {
try {
if(displayName != null) {
JSONObject obj = (JSONObject) new JSONParser().parse(displayName.getJson());
displayName = WrappedChatComponent.fromText(evt2.getPrefix()+obj.get("text"));
} else
displayName = WrappedChatComponent.fromText(evt2.getPrefix()+data.getProfile().getName());
} catch (ParseException e) {
e.printStackTrace();
}
if(displayName != null) {
JSONObject obj = (JSONObject) new JSONParser().parse(displayName.getJson());
displayName = WrappedChatComponent.fromText(evt2.getPrefix()+obj.get("text"));
} else
displayName = WrappedChatComponent.fromText(evt2.getPrefix()+data.getProfile().getName());
} catch (ParseException e) {
e.printStackTrace();
}
LGSkinLoadEvent evt = new LGSkinLoadEvent(lgp.getGame(), lgp, player, data.getProfile());
Bukkit.getPluginManager().callEvent(evt);
datas.add(new PlayerInfoData(evt.getProfile(), data.getLatency(), data.getGameMode(), displayName));
}else
datas.add(data);
}
info.setData(datas);
// }
}
LGSkinLoadEvent evt = new LGSkinLoadEvent(lgp.getGame(), lgp, player, data.getProfile());
Bukkit.getPluginManager().callEvent(evt);
datas.add(new PlayerInfoData(evt.getProfile(), data.getLatency(), data.getGameMode(), displayName));
}else
datas.add(data);
}
info.setData(datas);
}
});
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_HEALTH) {
@Override
public void onPacketSending(PacketEvent event) {
// if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
if(player.getGame() != null && player.getGame().isStarted()) {
WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket());
health.setFood(6);
}
// }
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
if(player.getGame() != null && player.getGame().isStarted()) {
WrapperPlayServerUpdateHealth health = new WrapperPlayServerUpdateHealth(event.getPacket());
health.setFood(6);
}
}
});
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SCOREBOARD_TEAM) {
@ -202,14 +195,12 @@ public class MainLg extends JavaPlugin{
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent event) {
// if (event.getPacketType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
if(player.getGame() != null) {
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket());
if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId())
equip.setItem(new ItemStack(Material.AIR));
}
// }
LGPlayer player = LGPlayer.thePlayer(event.getPlayer());
if(player.getGame() != null) {
WrapperPlayServerEntityEquipment equip = new WrapperPlayServerEntityEquipment(event.getPacket());
if(equip.getSlot() == ItemSlot.OFFHAND && equip.getEntityID() != player.getPlayer().getEntityId())
equip.setItem(new ItemStack(Material.AIR));
}
}
});

View file

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

View file

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

View file

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

View file

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