Cleanup backpack callback code
This commit is contained in:
parent
222e122eda
commit
b238a17467
|
@ -21,5 +21,5 @@ public interface Callback<T>
|
|||
{
|
||||
void onResult(T done);
|
||||
|
||||
void onFail();
|
||||
default void onFail() { /* In most cases this can be ignored since it will not happen with most db queries used */ }
|
||||
}
|
|
@ -114,17 +114,10 @@ public class RestoreCommand extends MinepacksCommand
|
|||
messageNoUserFound.send(sender);
|
||||
return;
|
||||
}
|
||||
getMinepacksPlugin().getBackpack(target, new Callback<Backpack>() {
|
||||
@Override
|
||||
public void onResult(Backpack backpack)
|
||||
{
|
||||
backpack.getInventory().setContents(items);
|
||||
backpack.setChanged();
|
||||
messageRestored.send(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {}
|
||||
getMinepacksPlugin().getBackpack(target, backpack -> {
|
||||
backpack.getInventory().setContents(items);
|
||||
backpack.setChanged();
|
||||
messageRestored.send(sender);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
|
|
@ -44,24 +44,16 @@ public class SortCommand extends MinepacksCommand
|
|||
public void execute(final @NotNull CommandSender commandSender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args)
|
||||
{
|
||||
final Player player = (Player) commandSender;
|
||||
getMinepacksPlugin().getBackpack(player, new Callback<Backpack>()
|
||||
{
|
||||
@Override
|
||||
public void onResult(Backpack backpack)
|
||||
getMinepacksPlugin().getBackpack(player, backpack -> {
|
||||
InventoryCompressor compressor = new InventoryCompressor(backpack.getInventory().getContents());
|
||||
if(!compressor.sort().isEmpty())
|
||||
{
|
||||
InventoryCompressor compressor = new InventoryCompressor(backpack.getInventory().getContents());
|
||||
if(!compressor.sort().isEmpty())
|
||||
{
|
||||
plugin.getLogger().warning("Failed to sort backpack!"); //this should not happen
|
||||
return;
|
||||
}
|
||||
backpack.getInventory().setContents(compressor.getTargetStacks());
|
||||
backpack.setChanged();
|
||||
messageSorted.send(player);
|
||||
plugin.getLogger().warning("Failed to sort backpack!"); //this should not happen
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {} // This should not happen
|
||||
backpack.getInventory().setContents(compressor.getTargetStacks());
|
||||
backpack.setChanged();
|
||||
messageSorted.send(player);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -91,16 +91,7 @@ public class CooldownManager extends BukkitRunnable implements Listener
|
|||
{
|
||||
final UUID uuid = event.getPlayer().getUniqueId();
|
||||
cooldowns.put(uuid, System.currentTimeMillis() + cooldown); // Temporary cooldown till the data is loaded from the database
|
||||
plugin.getDatabase().getCooldown(event.getPlayer(), new Callback<Long>() {
|
||||
@Override
|
||||
public void onResult(Long dbCooldownTime)
|
||||
{
|
||||
cooldowns.put(uuid, dbCooldownTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {}
|
||||
});
|
||||
plugin.getDatabase().getCooldown(event.getPlayer(), dbCooldownTime -> cooldowns.put(uuid, dbCooldownTime));
|
||||
}
|
||||
else if(addOnJoin)
|
||||
{
|
||||
|
|
|
@ -48,21 +48,13 @@ public class DropOnDeath extends MinepacksListener
|
|||
if (!player.hasPermission(Permissions.KEEP_ON_DEATH))
|
||||
{
|
||||
final Location location = player.getLocation();
|
||||
plugin.getBackpack(player, new Callback<Backpack>()
|
||||
{
|
||||
@Override
|
||||
public void onResult(Backpack backpack)
|
||||
plugin.getBackpack(player, backpack -> {
|
||||
BackpackDropOnDeathEvent event1 = new BackpackDropOnDeathEvent(player, backpack);
|
||||
plugin.getServer().getPluginManager().callEvent(event1);
|
||||
if(!event1.isCancelled())
|
||||
{
|
||||
BackpackDropOnDeathEvent event = new BackpackDropOnDeathEvent(player, backpack);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled())
|
||||
{
|
||||
backpack.drop(location);
|
||||
}
|
||||
backpack.drop(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,17 +306,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin, IPlugin
|
|||
@Override
|
||||
public void openBackpack(@NotNull Player opener, @NotNull OfflinePlayer owner, boolean editable, @Nullable String title)
|
||||
{
|
||||
database.getBackpack(owner, new Callback<Backpack>()
|
||||
{
|
||||
@Override
|
||||
public void onResult(Backpack backpack)
|
||||
{
|
||||
openBackpack(opener, backpack, editable, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {}
|
||||
});
|
||||
database.getBackpack(owner, backpack -> openBackpack(opener, backpack, editable, title));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue