2019-03-03 22:33:44 +01:00
|
|
|
package com.songoda.ultimatemoderation.gui;
|
|
|
|
|
|
|
|
import com.songoda.ultimatemoderation.UltimateModeration;
|
|
|
|
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
2019-03-08 02:39:49 +01:00
|
|
|
import com.songoda.ultimatemoderation.punish.Punishment;
|
2019-03-03 22:33:44 +01:00
|
|
|
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
|
|
|
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
2019-03-08 02:39:49 +01:00
|
|
|
import com.songoda.ultimatemoderation.tickets.TicketResponse;
|
2019-03-03 22:33:44 +01:00
|
|
|
import com.songoda.ultimatemoderation.utils.Methods;
|
|
|
|
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
2019-03-05 06:06:02 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2019-03-03 22:33:44 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2019-03-08 02:39:49 +01:00
|
|
|
import org.omg.PortableInterceptor.ACTIVE;
|
2019-03-03 22:33:44 +01:00
|
|
|
|
2019-03-08 02:39:49 +01:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
2019-03-03 22:33:44 +01:00
|
|
|
|
|
|
|
public class GUIPunishments extends AbstractGUI {
|
|
|
|
|
|
|
|
private final UltimateModeration plugin;
|
2019-03-05 06:06:02 +01:00
|
|
|
private final OfflinePlayer toModerate;
|
2019-03-03 22:33:44 +01:00
|
|
|
|
|
|
|
private Activity currentActivity = Activity.BOTH;
|
|
|
|
private PunishmentType punishmentType = PunishmentType.ALL;
|
|
|
|
|
2019-03-08 02:39:49 +01:00
|
|
|
private int page = 0;
|
|
|
|
|
2019-03-05 06:06:02 +01:00
|
|
|
public GUIPunishments(UltimateModeration plugin, OfflinePlayer toModerate, Player player) {
|
2019-03-03 22:33:44 +01:00
|
|
|
super(player);
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.toModerate = toModerate;
|
|
|
|
|
|
|
|
init(plugin.getLocale().getMessage("gui.punishments.title", toModerate.getName()), 54);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void constructGUI() {
|
|
|
|
inventory.clear();
|
|
|
|
resetClickables();
|
|
|
|
registerClickables();
|
|
|
|
|
|
|
|
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(toModerate);
|
|
|
|
|
2019-03-08 02:39:49 +01:00
|
|
|
List<PunishmentHolder> punishments = new ArrayList<>();
|
2019-03-03 22:33:44 +01:00
|
|
|
|
|
|
|
if (currentActivity == Activity.ACTIVE || currentActivity == Activity.BOTH) {
|
|
|
|
for (AppliedPunishment punishment : playerPunishData.getActivePunishments()) {
|
|
|
|
if (punishmentType != PunishmentType.ALL) {
|
|
|
|
if (punishment.getPunishmentType() != punishmentType)
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-08 02:39:49 +01:00
|
|
|
punishments.add(new PunishmentHolder(Activity.ACTIVE, punishment));
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentActivity == Activity.EXPIRED || currentActivity == Activity.BOTH) {
|
|
|
|
for (AppliedPunishment punishment : playerPunishData.getExpiredPunishments()) {
|
|
|
|
if (punishmentType != PunishmentType.ALL) {
|
|
|
|
if (punishment.getPunishmentType() != punishmentType)
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-08 02:39:49 +01:00
|
|
|
punishments.add(new PunishmentHolder(Activity.EXPIRED, punishment));
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 02:39:49 +01:00
|
|
|
int numNotes = punishments.size();
|
2019-03-09 04:28:32 +01:00
|
|
|
int maxPage = (int) Math.floor(numNotes / 36.0);
|
2019-03-08 02:39:49 +01:00
|
|
|
|
|
|
|
punishments = punishments.stream().skip(page * 36).limit(36)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (page != 0) {
|
|
|
|
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous"));
|
|
|
|
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
|
|
|
|
page --;
|
|
|
|
constructGUI();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page != maxPage) {
|
2019-03-08 02:58:23 +01:00
|
|
|
createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next"));
|
|
|
|
registerClickable(6, ((player1, inventory1, cursor, slot, type) -> {
|
2019-03-08 02:39:49 +01:00
|
|
|
page ++;
|
|
|
|
constructGUI();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
|
|
|
|
|
|
|
createButton(3, Material.APPLE, Methods.formatText("&6" + currentActivity.getTranslation()));
|
|
|
|
createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name()));
|
|
|
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1");
|
|
|
|
|
2019-03-03 22:33:44 +01:00
|
|
|
int currentSlot = 18;
|
2019-03-08 02:39:49 +01:00
|
|
|
for (PunishmentHolder punishmentHolder : punishments) {
|
2019-03-09 04:28:32 +01:00
|
|
|
AppliedPunishment appliedPunishment = punishmentHolder.getAppliedPunishment();
|
2019-03-08 02:39:49 +01:00
|
|
|
Activity activity = punishmentHolder.getActivity();
|
2019-03-03 22:33:44 +01:00
|
|
|
|
|
|
|
ArrayList<String> lore = new ArrayList<>();
|
|
|
|
lore.add("");
|
|
|
|
lore.add(plugin.getLocale().getMessage("gui.punishments.reason"));
|
|
|
|
lore.add("&7" + appliedPunishment.getReason());
|
|
|
|
if (appliedPunishment.getPunishmentType() != PunishmentType.KICK) {
|
|
|
|
lore.add("");
|
|
|
|
lore.add(plugin.getLocale().getMessage("gui.punishments.duration"));
|
|
|
|
lore.add("&7" + Methods.makeReadable(appliedPunishment.getDuration()));
|
|
|
|
lore.add("");
|
|
|
|
lore.add(plugin.getLocale().getMessage("gui.punishments.punisher"));
|
|
|
|
lore.add("&7" + (appliedPunishment.getPunisher() == null ? "Console" : Bukkit.getOfflinePlayer(appliedPunishment.getPunisher()).getName()));
|
|
|
|
if (activity == Activity.ACTIVE) {
|
|
|
|
lore.add("");
|
|
|
|
lore.add(plugin.getLocale().getMessage("gui.punishments.remaining"));
|
|
|
|
lore.add("&7" + Methods.makeReadable(appliedPunishment.getTimeRemaining()));
|
|
|
|
lore.add("");
|
|
|
|
lore.add(plugin.getLocale().getMessage("gui.punishments.click"));
|
|
|
|
|
|
|
|
registerClickable(currentSlot, ((player1, inventory1, cursor, slot, type) -> {
|
|
|
|
appliedPunishment.expire();
|
|
|
|
constructGUI();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lore.add("");
|
|
|
|
createButton(currentSlot, Material.MAP,
|
|
|
|
"&6&l" + appliedPunishment.getPunishmentType().getTranslation() + " - &7&l" + activity.getTranslation(), lore);
|
|
|
|
|
|
|
|
currentSlot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void registerClickables() {
|
|
|
|
registerClickable(8, ((player1, inventory1, cursor, slot, type) ->
|
|
|
|
new GUIPlayer(plugin, toModerate, player)));
|
|
|
|
|
|
|
|
registerClickable(3, ((player1, inventory1, cursor, slot, type) -> {
|
|
|
|
this.currentActivity = currentActivity.next();
|
2019-03-08 02:39:49 +01:00
|
|
|
this.page = 0;
|
2019-03-03 22:33:44 +01:00
|
|
|
constructGUI();
|
|
|
|
}));
|
|
|
|
|
|
|
|
registerClickable(4, ((player1, inventory1, cursor, slot, type) -> {
|
|
|
|
this.punishmentType = punishmentType.nextFilter();
|
2019-03-08 02:39:49 +01:00
|
|
|
this.page = 0;
|
2019-03-03 22:33:44 +01:00
|
|
|
constructGUI();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void registerOnCloses() {
|
|
|
|
}
|
|
|
|
|
2019-03-08 02:39:49 +01:00
|
|
|
private class PunishmentHolder {
|
|
|
|
|
|
|
|
private final Activity activity;
|
|
|
|
private final AppliedPunishment appliedPunishment;
|
|
|
|
|
|
|
|
public PunishmentHolder(Activity activity, AppliedPunishment appliedPunishment) {
|
|
|
|
this.activity = activity;
|
|
|
|
this.appliedPunishment = appliedPunishment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Activity getActivity() {
|
|
|
|
return activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AppliedPunishment getAppliedPunishment() {
|
|
|
|
return appliedPunishment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:33:44 +01:00
|
|
|
private enum Activity {
|
|
|
|
|
|
|
|
BOTH, ACTIVE, EXPIRED;
|
|
|
|
|
|
|
|
private static Activity[] vals = values();
|
|
|
|
|
|
|
|
public Activity next() {
|
|
|
|
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTranslation() {
|
|
|
|
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishments.activity." + this.name().toLowerCase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|