[Experimental] Update inventory after FastConsume violations.

This might be used for other inventory violations too (subject to
testing).
This commit is contained in:
asofold 2013-05-26 21:01:39 +02:00
parent 7e1347a78b
commit 3b22ca2e6a
4 changed files with 104 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.TickTask;
/**
@ -46,6 +47,7 @@ public class FastConsume extends Check implements Listener{
final InventoryData data = InventoryData.getData(player);
if (check(player, event.getItem(), data)){
event.setCancelled(true);
DataManager.getPlayerData(player.getName(), true).task.updateInventory();
}
data.instantEatInteract = 0;
data.instantEatFood = null;

View File

@ -62,6 +62,13 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
protected static DataManager instance = null;
//////////////////
// Not static.
//////////////////
/** PlayerData storage. */
protected final Map<String, PlayerData> playerData = new LinkedHashMap<String, PlayerData>(100);
/*
*
*/
@ -137,6 +144,7 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
factory.removeData(playerName);
}
clearComponentData(CheckType.ALL, playerName);
playerData.remove(playerName.toLowerCase()); // TODO
}
if (deleteData || deleteHistory) removeExecutionHistory(CheckType.ALL, playerName);
if (deleteHistory) ViolationHistory.removeHistory(playerName);
@ -263,6 +271,9 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
}
}
ViolationHistory.clear(checkType);
if (checkType == CheckType.ALL){
instance.playerData.clear(); // TODO
}
}
/**
@ -289,6 +300,10 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
if (otherFactory.removeData(playerName) != null) had = true;
}
if (checkType == CheckType.ALL){
instance.playerData.remove(playerName.toLowerCase());
}
return had;
}
@ -459,4 +474,24 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
}
}
/**
*
* @param playerName
* @param create
* @return
*/
public static PlayerData getPlayerData(final String playerName, final boolean create){
final String lcName = playerName.toLowerCase(); // TODO: Store by both lower case and exact case (also store the Player reference).
final PlayerData data = instance.playerData.get(lcName);
if (data != null) return data;
else if (!create){
return null;
}
else{
final PlayerData newData = new PlayerData(lcName);
instance.playerData.put(lcName, newData);
return newData;
}
}
}

View File

@ -12,16 +12,33 @@ import fr.neatmonster.nocheatplus.components.IData;
* <br>Might contain...
* <li>References of configs.</li>
* <li>Exemption entries.</li>
* <li>Player references<li>
* <hr>
* Main reasons are...
* <li>Faster cross-check data access both for check and data management.</li>
* <li>Have the data in one place, easy to control and manage.</li>
* <li>Easier transition towards non-static access, if it should ever happen.</li>
* <hr>
* (not complete)
* (not complete)<br>
* Might contain individual settings such as debug flags, exemption, notification settings, task references.
* @author mc_dev
*
*/
public class PlayerData implements IData {
public final PlayerTask task;
/** Lower case name of the player. */
final String lcName;
/**
*
* @param playerName Accurate case not (yet) demanded.
*/
public PlayerData(final String playerName){
this.lcName = playerName.toLowerCase();
this.task = new PlayerTask(this.lcName);
}
}

View File

@ -0,0 +1,49 @@
package fr.neatmonster.nocheatplus.players;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener;
/**
* Player specific task.
* @author mc_dev
*
*/
public class PlayerTask extends OnDemandTickListener {
public final String lcName;
protected boolean updateInventory = false;
/**
*
* @param name Not demanded to be case sensitive.
*/
public PlayerTask(final String name){
this.lcName = name.toLowerCase();
}
@SuppressWarnings("deprecation")
@Override
public boolean delegateTick(final int tick, final long timeLast) {
final Player player = DataManager.getPlayer(lcName);
if (player != null){
if (player.isOnline()){
if (updateInventory){
player.updateInventory();
updateInventory = false;
}
}
}
return false;
}
public void updateInventory(){
// TODO: Might not allow registering every tick.
updateInventory = true;
register();
}
// TODO: updateHunger
}