mirror of
https://github.com/FirephoenixX02/RapidReport.git
synced 2026-05-09 17:52:36 +02:00
Add ClickListener + edit gui screen
This commit is contained in:
parent
3cd7ff8e8e
commit
1bad1bd6f3
7 changed files with 193 additions and 38 deletions
|
|
@ -14,6 +14,7 @@ import me.firephoenix.rapidreport.commands.CloseReportCommand;
|
|||
import me.firephoenix.rapidreport.commands.ListReportsCommand;
|
||||
import me.firephoenix.rapidreport.commands.ReportCommand;
|
||||
import me.firephoenix.rapidreport.commands.ReportGUICommand;
|
||||
import me.firephoenix.rapidreport.ui.UIManager;
|
||||
import me.firephoenix.rapidreport.utils.DataBaseManager;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
|
@ -46,6 +47,8 @@ public class RapidReport {
|
|||
public DataBaseManager dataBaseManager;
|
||||
@Getter
|
||||
public String chatPrefix = "<gray>[<red>RapidReport<gray>] ";
|
||||
@Getter
|
||||
public UIManager uiManager;
|
||||
|
||||
@Inject
|
||||
public RapidReport(ProxyServer proxyServer, Logger logger, @DataDirectory final Path folder) {
|
||||
|
|
@ -66,6 +69,8 @@ public class RapidReport {
|
|||
|
||||
dataBaseManager.initDB();
|
||||
|
||||
uiManager = new UIManager();
|
||||
|
||||
commandManager.register(commandManager.metaBuilder("report").plugin(this).build(), new ReportCommand());
|
||||
commandManager.register(commandManager.metaBuilder("reports").plugin(this).build(), new ListReportsCommand());
|
||||
commandManager.register(commandManager.metaBuilder("closereport").plugin(this).build(), new CloseReportCommand());
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@ import com.velocitypowered.api.proxy.Player;
|
|||
import dev.simplix.protocolize.api.ClickType;
|
||||
import dev.simplix.protocolize.api.Protocolize;
|
||||
import dev.simplix.protocolize.api.chat.ChatElement;
|
||||
import dev.simplix.protocolize.api.inventory.Inventory;
|
||||
import dev.simplix.protocolize.api.item.BaseItemStack;
|
||||
import dev.simplix.protocolize.api.item.ItemStack;
|
||||
import dev.simplix.protocolize.api.player.ProtocolizePlayer;
|
||||
import dev.simplix.protocolize.data.ItemType;
|
||||
import dev.simplix.protocolize.data.inventory.InventoryType;
|
||||
import me.firephoenix.rapidreport.RapidReport;
|
||||
import me.firephoenix.rapidreport.ui.CustomInventory;
|
||||
import me.firephoenix.rapidreport.ui.UIManager;
|
||||
import me.firephoenix.rapidreport.utils.Report;
|
||||
import me.firephoenix.rapidreport.ui.UIComponent;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -47,50 +48,16 @@ public class ReportGUICommand implements SimpleCommand {
|
|||
while (result.next()) {
|
||||
reports.add(new Report(result.getString("reporterName"), result.getString("reportedName"),
|
||||
UUID.fromString(result.getString("reportedUUID")), result.getString("reason"),
|
||||
result.getString("status")));
|
||||
result.getString("status"), result.getInt("id")));
|
||||
}
|
||||
result.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Inventory inventory = new Inventory(InventoryType.GENERIC_9X6);
|
||||
inventory.title(ChatElement.ofLegacyText("§cReports"));
|
||||
|
||||
//Top Row of Glass
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
// Populate the inventory with reports once they are fetched
|
||||
int slot = 10;
|
||||
for (Report report : reports) {
|
||||
if (slot > 43) break;
|
||||
List<ChatElement<?>> lore = new ArrayList<>();
|
||||
lore.add(ChatElement.ofLegacyText("§cReported by: §7" + report.reporterPlayerName));
|
||||
lore.add(ChatElement.ofLegacyText("§cReason: §7" + report.reason));
|
||||
lore.add(ChatElement.ofLegacyText("§cStatus: §7" + report.status));
|
||||
|
||||
ItemStack reportItem = new ItemStack(ItemType.PAPER);
|
||||
|
||||
reportItem.displayName(ChatElement.ofLegacyText("§c" + report.reportedPlayerName));
|
||||
reportItem.lore(lore);
|
||||
|
||||
|
||||
|
||||
inventory.item(slot, reportItem);
|
||||
slot++;
|
||||
}
|
||||
|
||||
// Bottom Row of Glass
|
||||
for (int i = 45; i < 54; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
// Open the inventory for the player
|
||||
ProtocolizePlayer protocolizePlayer = Protocolize.playerProvider().player(((Player) commandSource).getUniqueId());
|
||||
protocolizePlayer.openInventory(inventory);
|
||||
protocolizePlayer.openInventory(RapidReport.INSTANCE.getUiManager().createReportListGUI(reports, protocolizePlayer));
|
||||
}).exceptionally(ex -> {
|
||||
commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "<red>Error fetching reports.");
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package me.firephoenix.rapidreport.ui;
|
||||
|
||||
import dev.simplix.protocolize.api.inventory.Inventory;
|
||||
import dev.simplix.protocolize.data.inventory.InventoryType;
|
||||
import lombok.Getter;
|
||||
import me.firephoenix.rapidreport.RapidReport;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2024, All Rights Reserved.
|
||||
*/
|
||||
public class CustomInventory extends Inventory {
|
||||
@Getter
|
||||
public HashMap<Integer, UIComponent> slotToComponentMap = new HashMap<>();
|
||||
|
||||
public CustomInventory(InventoryType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public void item(int slot, UIComponent uiComponent) {
|
||||
slotToComponentMap.put(slot, uiComponent);
|
||||
item(slot, uiComponent.getItemStack());
|
||||
}
|
||||
}
|
||||
37
src/main/java/me/firephoenix/rapidreport/ui/UIComponent.java
Normal file
37
src/main/java/me/firephoenix/rapidreport/ui/UIComponent.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package me.firephoenix.rapidreport.ui;
|
||||
|
||||
import dev.simplix.protocolize.api.item.ItemStack;
|
||||
import dev.simplix.protocolize.api.player.ProtocolizePlayer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.firephoenix.rapidreport.RapidReport;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2024, All Rights Reserved.
|
||||
*/
|
||||
public class UIComponent {
|
||||
@Getter
|
||||
private ItemStack itemStack;
|
||||
@Setter
|
||||
private Runnable clickListener;
|
||||
|
||||
public UIComponent(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
public UIComponent(ItemStack itemStack, Runnable clickListener) {
|
||||
this.itemStack = itemStack;
|
||||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
public void runClickListener(ProtocolizePlayer protocolizePlayer) {
|
||||
if (!hasPermission(protocolizePlayer)) return;
|
||||
clickListener.run();
|
||||
}
|
||||
|
||||
public boolean hasPermission(ProtocolizePlayer protocolizePlayer) {
|
||||
if (RapidReport.INSTANCE.getProxy().getPlayer(protocolizePlayer.uniqueId()).isEmpty()) return false;
|
||||
return RapidReport.INSTANCE.getProxy().getPlayer(protocolizePlayer.uniqueId()).get().hasPermission("rapidreport.gui");
|
||||
}
|
||||
}
|
||||
106
src/main/java/me/firephoenix/rapidreport/ui/UIManager.java
Normal file
106
src/main/java/me/firephoenix/rapidreport/ui/UIManager.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package me.firephoenix.rapidreport.ui;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import dev.simplix.protocolize.api.ClickType;
|
||||
import dev.simplix.protocolize.api.chat.ChatElement;
|
||||
import dev.simplix.protocolize.api.item.ItemStack;
|
||||
import dev.simplix.protocolize.api.player.ProtocolizePlayer;
|
||||
import dev.simplix.protocolize.data.ItemType;
|
||||
import dev.simplix.protocolize.data.inventory.InventoryType;
|
||||
import me.firephoenix.rapidreport.RapidReport;
|
||||
import me.firephoenix.rapidreport.utils.Report;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2024, All Rights Reserved.
|
||||
*/
|
||||
public class UIManager {
|
||||
|
||||
public CustomInventory createReportListGUI(ArrayList<Report> reports, ProtocolizePlayer protocolizePlayer) {
|
||||
CustomInventory inventory = new CustomInventory(InventoryType.GENERIC_9X6);
|
||||
inventory.title(ChatElement.ofLegacyText("§cReports"));
|
||||
|
||||
//Top Row of Glass
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
// Populate the inventory with reports once they are fetched
|
||||
int slot = 10;
|
||||
for (Report report : reports) {
|
||||
if (slot > 43) break;
|
||||
List<ChatElement<?>> lore = new ArrayList<>();
|
||||
lore.add(ChatElement.ofLegacyText("§cReported by: §7" + report.reporterPlayerName));
|
||||
lore.add(ChatElement.ofLegacyText("§cReason: §7" + report.reason));
|
||||
lore.add(ChatElement.ofLegacyText("§cStatus: §7" + report.status));
|
||||
|
||||
ItemStack reportItemStack = new ItemStack(ItemType.PAPER);
|
||||
|
||||
reportItemStack.displayName(ChatElement.ofLegacyText("§c" + report.reportedPlayerName));
|
||||
reportItemStack.lore(lore);
|
||||
|
||||
UIComponent reportComponent = new UIComponent(reportItemStack);
|
||||
|
||||
reportComponent.setClickListener(() -> {
|
||||
protocolizePlayer.openInventory(createReportEditGUI(report, protocolizePlayer));
|
||||
});
|
||||
|
||||
inventory.item(slot, reportComponent);
|
||||
slot++;
|
||||
}
|
||||
|
||||
// Bottom Row of Glass
|
||||
for (int i = 45; i < 54; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
inventory.onClick(click -> {
|
||||
if (click.clickType() != ClickType.LEFT_CLICK) return;
|
||||
if (inventory.getSlotToComponentMap().containsKey(click.slot())) {
|
||||
inventory.getSlotToComponentMap().get(click.slot()).runClickListener(click.player());
|
||||
}
|
||||
});
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public CustomInventory createReportEditGUI(Report report, ProtocolizePlayer protocolizePlayer) {
|
||||
CustomInventory inventory = new CustomInventory(InventoryType.GENERIC_9X5);
|
||||
inventory.title(ChatElement.ofLegacyText("§cEdit-Report"));
|
||||
|
||||
//Top Row of Glass
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
ItemStack closeItemStack = new ItemStack(ItemType.BARRIER);
|
||||
|
||||
closeItemStack.displayName(ChatElement.ofLegacyText("§c" + "Close Report"));
|
||||
|
||||
UIComponent closeComponent = new UIComponent(closeItemStack);
|
||||
|
||||
closeComponent.setClickListener(() -> {
|
||||
RapidReport.INSTANCE.getDataBaseManager().closeReport(report);
|
||||
protocolizePlayer.closeInventory();
|
||||
});
|
||||
|
||||
inventory.item(20, closeComponent);
|
||||
|
||||
|
||||
// Bottom Row of Glass
|
||||
for (int i = 36; i < 45; i++) {
|
||||
inventory.item(i, new ItemStack(ItemType.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
inventory.onClick(click -> {
|
||||
if (click.clickType() != ClickType.LEFT_CLICK) return;
|
||||
if (inventory.getSlotToComponentMap().containsKey(click.slot())) {
|
||||
inventory.getSlotToComponentMap().get(click.slot()).runClickListener(click.player());
|
||||
}
|
||||
});
|
||||
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,6 +93,10 @@ public class DataBaseManager {
|
|||
runStatementAsync("INSERT INTO rapid_report_reports (reporterName, reportedName, reportedUUID, reason, status) VALUES ('" + report.reporterPlayerName + "', '" + report.reportedPlayerName + "', '" + report.reportedPlayerUUID.toString() + "', '" + report.reason + "', '" + report.status + "')");
|
||||
}
|
||||
|
||||
public void closeReport(Report report) {
|
||||
runStatementAsync("UPDATE rapid_report_reports SET status = 'resolved' WHERE id = " + report.databaseID + " AND status = 'unresolved'");
|
||||
}
|
||||
|
||||
public void initDB() {
|
||||
// first lets read our setup file.
|
||||
// This file contains statements to create our inital tables.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public class Report {
|
|||
public final UUID reportedPlayerUUID;
|
||||
public final String reason;
|
||||
public final String status;
|
||||
public int databaseID = 0;
|
||||
|
||||
public Report(final String reporterPlayerName, final String reportedPlayerName, final UUID reportedPlayerUUID, final String reason, final String status) {
|
||||
this.reporterPlayerName = reporterPlayerName;
|
||||
|
|
@ -23,4 +24,13 @@ public class Report {
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
public Report(final String reporterPlayerName, final String reportedPlayerName, final UUID reportedPlayerUUID, final String reason, final String status, final int databaseID) {
|
||||
this.reporterPlayerName = reporterPlayerName;
|
||||
this.reportedPlayerName = reportedPlayerName;
|
||||
this.reportedPlayerUUID = reportedPlayerUUID;
|
||||
this.reason = reason;
|
||||
this.status = status;
|
||||
this.databaseID = databaseID;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue