L'historique des calculs d'un joueur est maintenant stocké dans la classe OnlinePlayer
This commit is contained in:
parent
a4a138b9dc
commit
fc64edebe6
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<jardesc>
|
||||
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.1.jar"/>
|
||||
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.2.jar"/>
|
||||
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: PandacraftUtils
|
||||
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
|
||||
version: 3.1
|
||||
version: 3.2
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<Player, List<HistoryElement>> history = new HashMap<Player, List<HistoryElement>>();
|
||||
|
||||
|
||||
|
||||
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<HistoryElement> 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);
|
||||
|
||||
@ -95,25 +86,7 @@ public class CalculatorManager implements Listener {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
history.put(event.getPlayer(), new ArrayList<HistoryElement>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
history.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class HistoryElement
|
||||
public class HistoryElement
|
||||
{
|
||||
public String expression;
|
||||
public String value;
|
||||
|
@ -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<CalculatorManager.HistoryElement> Calculator_history = new ArrayList<CalculatorManager.HistoryElement>();
|
||||
|
||||
public void addToCalculatorHistory(CalculatorManager.HistoryElement el) {
|
||||
Calculator_history.add(el);
|
||||
if (Calculator_history.size() > 5)
|
||||
Calculator_history.remove(0);
|
||||
}
|
||||
|
||||
public List<CalculatorManager.HistoryElement> getCalculator_history() {
|
||||
return Collections.unmodifiableList(Calculator_history);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user