From fc64edebe67f2779877374224ce541612e415b26 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 25 Jan 2015 01:21:13 -0500 Subject: [PATCH] =?UTF-8?q?L'historique=20des=20calculs=20d'un=20joueur=20?= =?UTF-8?q?est=20maintenant=20stock=C3=A9=20dans=20la=20classe=20OnlinePla?= =?UTF-8?q?yer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 2 +- .../commands/CommandAdmin.java | 2 +- .../modules/CalculatorManager.java | 47 ++++--------------- .../pandacraftutils/players/OnlinePlayer.java | 16 +++++++ 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/make_jar.jardesc b/make_jar.jardesc index 90a0308..dc3f8c1 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 0eb82db..6c54d1c 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 3.1 +version: 3.2 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java index 2a17e79..414a7ca 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java @@ -24,7 +24,7 @@ public class CommandAdmin extends AbstractCommandExecutor { return true; } if (args[0].equalsIgnoreCase("version")) { - sender.sendMessage(ChatColor.GREEN+plugin.getName()+" v"+plugin.getDescription().getVersion()); + sender.sendMessage(ChatColor.GREEN+plugin.getDescription().getFullName()); return true; } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java index 4ae8a5c..f727838 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java @@ -1,37 +1,27 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.modules; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; import net.mc_pandacraft.java.util.JArithmeticInterpreter; import net.mc_pandacraft.java.util.StringUtil; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; public class CalculatorManager implements Listener { private PandacraftUtils plugin = PandacraftUtils.getInstance(); - private Map> history = new HashMap>(); - public CalculatorManager() { plugin.getServer().getPluginManager().registerEvents(this, plugin); - - // analyse des joueurs déjà en ligne (/reload) - for (Player p : plugin.getServer().getOnlinePlayers()) - onPlayerJoin(new PlayerJoinEvent(p, "")); // simule l'évènement d'arrivé d'un joueur, pour le rajouter } @@ -44,16 +34,19 @@ public class CalculatorManager implements Listener { if (!message.startsWith("=")) return; + OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer()); + List history = op.getCalculator_history(); + if (message.length() == 1) { // affichage de l'historique event.getPlayer().sendMessage(ChatColor.GRAY+"Historique d'utilisation de la calculatrice"); - int i = history.get(event.getPlayer()).size(); - for(HistoryElement el : history.get(event.getPlayer())) + int i = history.size(); + for(HistoryElement el : history) { event.getPlayer().sendMessage(ChatColor.GRAY+"res"+i+ChatColor.RESET+" : "+ChatColor.GRAY+el.expression+ChatColor.RESET+"="+ChatColor.GRAY+el.value); i--; } - if (history.get(event.getPlayer()).size() == 0) + if (history.size() == 0) { event.getPlayer().sendMessage(ChatColor.RED+"Utilisez le symbole "+ChatColor.GRAY+"="+ChatColor.RED+" dans le chat pour faire un calcul mathématique"); } @@ -73,9 +66,7 @@ public class CalculatorManager implements Listener { calcul.value = StringUtil.formatDouble(JArithmeticInterpreter.getResultFromExpression(message, expression)); calcul.expression = expression.toString(); - history.get(event.getPlayer()).add(calcul); - if (history.get(event.getPlayer()).size() > 5) - history.get(event.getPlayer()).remove(0); + op.addToCalculatorHistory(calcul); event.getPlayer().sendMessage(ChatColor.GRAY+calcul.expression+ChatColor.RESET+"="+ChatColor.GRAY+calcul.value); @@ -94,26 +85,8 @@ public class CalculatorManager implements Listener { } - - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - history.put(event.getPlayer(), new ArrayList()); - } - - - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) - { - history.remove(event.getPlayer()); - } - - - - private class HistoryElement + public class HistoryElement { public String expression; public String value; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java index 96f5d73..6e7ca55 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -1,12 +1,15 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.players; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Random; import java.util.Set; import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.CalculatorManager; import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface; import org.bukkit.Bukkit; @@ -199,7 +202,20 @@ public class OnlinePlayer { + /* + * Historique de calcul + */ + private ArrayList Calculator_history = new ArrayList(); + public void addToCalculatorHistory(CalculatorManager.HistoryElement el) { + Calculator_history.add(el); + if (Calculator_history.size() > 5) + Calculator_history.remove(0); + } + + public List getCalculator_history() { + return Collections.unmodifiableList(Calculator_history); + }