Hooked in statchangeevent

This commit is contained in:
Chiss 2014-08-08 13:53:58 +10:00
parent 1a33dbb5ee
commit 8f72ba4ab7
4 changed files with 22 additions and 11 deletions

View File

@ -14,6 +14,8 @@ public class AchievementManager extends MiniPlugin
{
private StatsManager _statsManager;
private boolean debug = true;
public AchievementManager(StatsManager statsManager)
{
super("Achievement Manager", statsManager.GetPlugin());
@ -33,6 +35,9 @@ public class AchievementManager extends MiniPlugin
for (String stat : type.getStats())
{
exp += _statsManager.Get(playerName).getStat(stat);
if (debug)
System.out.println(type.getName() + " Value [" + stat + "] is [" + _statsManager.Get(playerName).getStat(stat) + "]");
}
return type.getLevelData(exp);
@ -51,6 +56,10 @@ public class AchievementManager extends MiniPlugin
{
if (stat.equalsIgnoreCase(event.getStatName()))
{
if (debug)
System.out.println(player.getName() + " - " + type.getName() +
" [" + type.getLevelData(event.getValueAfter()).getLevel() + " & " + type.getLevelData(event.getValueBefore()).getLevel() + "]");
if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel())
{
UtilPlayer.message(player, F.main("Achievement",

View File

@ -8,14 +8,18 @@ public class PlayerStats
{
private NautHashMap<String, Integer> _statHash = new NautHashMap<String, Integer>();
public void addStat(String statName, int value)
public int addStat(String statName, int value)
{
if (!_statHash.containsKey(statName))
{
_statHash.put(statName, 0);
}
_statHash.put(statName, _statHash.get(statName) + value);
int current = _statHash.get(statName);
_statHash.put(statName, current + value);
return current+value;
}
public int getStat(String statName)

View File

@ -10,6 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.event.StatChangeEvent;
public class StatsManager extends MiniClientPlugin<PlayerStats>
{
@ -48,7 +50,10 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
public void incrementStat(Player player, final String statName, int value)
{
Get(player).addStat(statName, Get(player).getStat(statName) + value);
int newValue = Get(player).addStat(statName, Get(player).getStat(statName) + value);
//Event
UtilServer.getServer().getPluginManager().callEvent(new StatChangeEvent(player.getName(), statName, newValue - value, newValue));
String uuidString = player.getUniqueId().toString();

View File

@ -10,15 +10,13 @@ public class StatChangeEvent extends Event
private static final HandlerList handlers = new HandlerList();
private String _player;
private String _table;
private String _statName;
private int _valueBefore;
private int _valueAfter;
public StatChangeEvent(String player, String table, String statName, int valueBefore, int valueAfter)
public StatChangeEvent(String player, String statName, int valueBefore, int valueAfter)
{
_player = player;
_table = table;
_statName = statName;
_valueBefore = valueBefore;
_valueAfter = valueAfter;
@ -39,11 +37,6 @@ public class StatChangeEvent extends Event
return _player;
}
public String getTable()
{
return _table;
}
public String getStatName()
{
return _statName;