Update local cache of inventory and if fail, revert change.

Removed full lock on login.

Removed Thanskgiving benefit.
This commit is contained in:
Jonathan Williams 2014-11-22 17:52:22 -08:00
parent 695ed95b5d
commit 37b5e495b8
3 changed files with 31 additions and 19 deletions

View File

@ -239,7 +239,6 @@ public class CoreClientManager extends MiniPlugin
Gson gson = new Gson();
final RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid);
clientInformationEvent.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
@ -248,7 +247,6 @@ public class CoreClientManager extends MiniPlugin
_repository.login(uuid.toString(), client.GetPlayerName());
Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent);
clientInformationEvent.decreaseProcessingCount();
}
});

View File

@ -11,6 +11,7 @@ import mineplex.core.benefit.benefits.Thanksgiving2014;
import mineplex.core.common.util.Callback;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
@ -28,31 +29,39 @@ public class RankBenefitsGiver9000 extends MiniClientPlugin<PlayerBenefit>
_repository = new RankBenefitsGiver9000Repository(plugin);
_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
//_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)
public void giveBenefit(final PlayerJoinEvent event)
{
for (final BenefitBase benefit : _benefits)
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
if (!Get(event.getPlayer()).Benefits.contains(benefit.getName()))
public void run()
{
benefit.recordBenefit(event.getPlayer(), new Callback<Boolean>()
if (Get(event.getPlayer()).Loaded)
{
public void run(Boolean success)
for (final BenefitBase benefit : _benefits)
{
if (success)
if (!Get(event.getPlayer()).Benefits.contains(benefit.getName()))
{
benefit.rewardPlayer(event.getPlayer());
benefit.recordBenefit(event.getPlayer(), new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
benefit.rewardPlayer(event.getPlayer());
}
else
System.out.println("Benefit reward failed for " + event.getPlayer().getName());
}
});
}
else
System.out.println("Benefit reward failed for " + event.getPlayer().getName());
}
});
}
}
}
}, 100L);
}
@Override
@ -73,6 +82,7 @@ public class RankBenefitsGiver9000 extends MiniClientPlugin<PlayerBenefit>
for (String benefit : _repository.retrievePlayerBenefits(event.getUniqueId().toString()))
{
Get(event.getPlayerName()).Benefits.add(benefit);
Get(event.getPlayerName()).Loaded = true;
}
event.decreaseProcessingCount();

View File

@ -69,6 +69,11 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
public void addItemToInventory(final Player player, String category, final String item, final int count)
{
if (_items.containsKey(item))
{
Get(player).addItem(new ClientItem(_items.get(item), count));
}
addItemToInventory(null, player, category, item, count);
}
@ -78,16 +83,15 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
{
public void run(Boolean success)
{
if (success)
if (!success)
{
System.out.println("Add item to Inventory FAILED for " + player.getName());
if (_items.containsKey(item))
{
Get(player).addItem(new ClientItem(_items.get(item), count));
Get(player).addItem(new ClientItem(_items.get(item), -count));
}
System.out.println("Add item to Inventory succeeded.");
}
else
System.out.println("Add item to Inventory FAILED for " + player.getName());
if (callback != null)
callback.run(success);