Don't get cosmetic data if cosmetics have been disabled

This commit is contained in:
Sam 2017-09-10 23:57:43 +01:00 committed by cnr
parent 52adaf45a2
commit 61541c130f
3 changed files with 15 additions and 0 deletions

View File

@ -1114,6 +1114,8 @@ public class GadgetManager extends MiniPlugin
public void disableAll() public void disableAll()
{ {
_userGadgetPersistence.setEnabled(false);
for (GadgetType gadgetType : _gadgets.keySet()) for (GadgetType gadgetType : _gadgets.keySet())
{ {
for (Gadget gadget : _gadgets.get(gadgetType)) for (Gadget gadget : _gadgets.get(gadgetType))

View File

@ -16,15 +16,27 @@ public class UserGadgetPersistence
private final GadgetManager _manager; private final GadgetManager _manager;
private final PlayerKeyValueRepository<String> _repository; private final PlayerKeyValueRepository<String> _repository;
private boolean _enabled;
public UserGadgetPersistence(GadgetManager manager) public UserGadgetPersistence(GadgetManager manager)
{ {
_manager = manager; _manager = manager;
_repository = new PlayerKeyValueRepository<>("gadgets", String.class); _repository = new PlayerKeyValueRepository<>("gadgets", String.class);
_enabled = true;
}
public void setEnabled(boolean enabled)
{
_enabled = enabled;
} }
public void load(Player player) public void load(Player player)
{ {
if (!_enabled)
{
return;
}
_repository.getAll(player.getUniqueId()).thenCompose(BukkitFuture.accept(values -> _repository.getAll(player.getUniqueId()).thenCompose(BukkitFuture.accept(values ->
{ {
if (player.isOnline()) if (player.isOnline())

View File

@ -123,6 +123,7 @@ public abstract class WinEffectGadget extends Gadget
_allPlayers.clear(); _allPlayers.clear();
_allPlayers = null; _allPlayers = null;
// Loads gadgets back when players are teleported to the arcade hub, after the win effect // Loads gadgets back when players are teleported to the arcade hub, after the win effect
Manager.getUserGadgetPersistence().setEnabled(true);
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
Manager.getUserGadgetPersistence().load(player); Manager.getUserGadgetPersistence().load(player);