Add HistoryCommand, and working history button in /p

This commit is contained in:
Spencer 2018-01-03 18:14:02 -05:00 committed by Alexander Meech
parent c85b92f52b
commit 27453af867
4 changed files with 193 additions and 4 deletions

View File

@ -0,0 +1,83 @@
package mineplex.core.punish.Command;
import java.util.concurrent.atomic.AtomicReference;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.punish.Punish;
import mineplex.core.punish.UI.PunishShop;
import mineplex.core.punish.UI.history.PunishHistoryPage;
public class HistoryCommand extends CommandBase<Punish>
{
private PunishShop _punishShop;
public HistoryCommand(Punish plugin)
{
super(plugin, Punish.Perm.PUNISHMENT_HISTORY_COMMAND, "history", "phistory", "ph");
_punishShop = new PunishShop(plugin);
}
@Override
public void Execute(Player caller, String[] args)
{
Player target;
if (args.length < 1 || !Plugin.GetClients().Get(caller).hasPermission(Punish.Perm.PUNISHMENT_COMMAND))
{
target = caller;
}
else
{
target = Bukkit.getPlayerExact(args[0]);
}
if (target != null)
{
Plugin.GetRepository().LoadPunishClient(caller.getName(), clientToken ->
{
Plugin.LoadClient(clientToken);
_punishShop.openPageForPlayer(caller, new PunishHistoryPage(Plugin, _punishShop, caller, target.getName(), false, null, null));
});
return;
}
AtomicReference<String> playerName = new AtomicReference<>(args[0]);
Plugin.GetRepository().MatchPlayerName(matches ->
{
boolean matchedExact = false;
for (String match : matches)
{
if (match.equalsIgnoreCase(playerName.get()))
{
matchedExact = true;
}
}
if (matchedExact)
{
matches.removeIf(s -> !s.equalsIgnoreCase(playerName.get()));
}
UtilPlayer.searchOffline(matches, t ->
{
if (t == null)
{
return;
}
Plugin.GetRepository().LoadPunishClient(t, clientToken ->
{
Plugin.LoadClient(clientToken);
_punishShop.openPageForPlayer(caller, new PunishHistoryPage(Plugin, _punishShop, caller, playerName.get(), false, null, null));
});
}, caller, playerName.get(), true);
}, playerName.get());
}
}

View File

@ -14,7 +14,7 @@ import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.punish.Punish;
import mineplex.core.punish.UI.PunishPage;
import mineplex.core.punish.UI.staff.PunishStaffPage;
import mineplex.core.punish.UI.PunishShop;
public class PunishCommand extends CommandBase<Punish>
@ -76,7 +76,7 @@ public class PunishCommand extends CommandBase<Punish>
Plugin.GetRepository().LoadPunishClient(originalName.get(), clientToken ->
{
Plugin.LoadClient(clientToken);
_punishShop.openPageForPlayer(caller, new PunishPage(Plugin, _punishShop, caller, originalName.get(), finalReason, wasDisguised.get(), originalName.get(), disguisedName.get()));
_punishShop.openPageForPlayer(caller, new PunishStaffPage(Plugin, _punishShop, caller, originalName.get(), finalReason, wasDisguised.get(), originalName.get(), disguisedName.get()));
});
return;
@ -118,7 +118,7 @@ public class PunishCommand extends CommandBase<Punish>
Plugin.GetRepository().LoadPunishClient(t, clientToken ->
{
Plugin.LoadClient(clientToken);
_punishShop.openPageForPlayer(caller, new PunishPage(Plugin, _punishShop, caller, t, finalReason, false, null, null));
_punishShop.openPageForPlayer(caller, new PunishStaffPage(Plugin, _punishShop, caller, t, finalReason, false, null, null));
});
}, caller, finalPlayerName, true);
}, playerName);

View File

@ -35,6 +35,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.punish.Command.HistoryCommand;
import mineplex.core.punish.Command.PunishCommand;
import mineplex.core.punish.Command.RulesCommand;
import mineplex.core.punish.Tokens.PunishClientToken;
@ -56,7 +57,8 @@ public class Punish extends MiniPlugin
RULES_COMMAND,
REPORT_BAN_ACCESS,
BYPASS_REMOVE_CONFIRMATION,
PUNISHMENT_REAPPLY
PUNISHMENT_REAPPLY,
PUNISHMENT_HISTORY_COMMAND
}
private Map<String, PunishClient> _punishClients;
@ -99,6 +101,8 @@ public class Punish extends MiniPlugin
PermissionGroup.FN.setPermission(Perm.BYPASS_REMOVE_CONFIRMATION, true, true);
PermissionGroup.ADMIN.setPermission(Perm.BYPASS_REMOVE_CONFIRMATION, true, true);
PermissionGroup.PLAYER.setPermission(Perm.PUNISHMENT_HISTORY_COMMAND, true, true);
}
public ClansBanManager getClansPunish()
@ -115,6 +119,7 @@ public class Punish extends MiniPlugin
public void addCommands()
{
addCommand(new PunishCommand(this));
addCommand(new HistoryCommand(this));
addCommand(new RulesCommand(this));
}

View File

@ -0,0 +1,101 @@
package mineplex.core.punish.UI.history;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.C;
import mineplex.core.punish.Punish;
import mineplex.core.punish.Punishment;
import mineplex.core.punish.UI.PunishPage;
import mineplex.core.punish.UI.PunishShop;
import mineplex.core.punish.UI.staff.PunishStaffPage;
import mineplex.core.shop.item.ShopItem;
public class PunishHistoryPage extends PunishPage
{
private static final int ELEMENTS_PER_PAGE = 28;
private int _page;
private boolean _inStaffGui;
private PunishStaffPage _previousPage;
public PunishHistoryPage(Punish punish, PunishShop shop, Player player, String target, boolean inStaffGui, String reason, PunishStaffPage previousPage)
{
super(punish, shop, "History - " + target, player, target, reason);
_inStaffGui = inStaffGui;
_previousPage = previousPage;
buildPage();
}
private void buildBackButton()
{
if (!_inStaffGui || _previousPage == null)
{
return;
}
ItemStack icon = new ItemStack(Material.BED);
ItemMeta meta = icon.getItemMeta();
meta.setDisplayName(C.cGreenB + "Go Back");
meta.setLore(Arrays.asList(new String[0]));
icon.setItemMeta(meta);
addButton(4, icon, (p, c) -> getShop().openPageForPlayer(getPlayer(), _previousPage));
}
@Override
protected void buildPage()
{
List<Punishment> punishments = _pastPunishments;
if (punishments == null)
{
return;
}
int slot = 10;
int startIndex = _page * ELEMENTS_PER_PAGE;
int endIndex = startIndex + ELEMENTS_PER_PAGE;
punishments = punishments.subList(startIndex, Math.min(endIndex, punishments.size()));
for (Punishment punishment : punishments)
{
addHistoryItem(slot, punishment);
if (++slot % 9 == 8)
{
slot += 2;
}
}
if (_page != 0)
{
addButton(45, new ShopItem(Material.ARROW, C.cGreen + "Previous Page", new String[0], 1, false), (player, clickType) ->
{
_page--;
refresh();
});
}
if (endIndex <= _pastPunishments.size())
{
addButton(53, new ShopItem(Material.ARROW, C.cGreen + "Next Page", new String[0], 1, false), (player, clickType) ->
{
_page++;
refresh();
});
}
buildBackButton();
}
}