Skip to content

Commit

Permalink
feat(members): Try to support members ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Dec 29, 2024
1 parent b533899 commit 8c0b377
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.artformgames.plugin.residencelist.ui;

import cc.carm.lib.configuration.core.Configuration;
import cc.carm.lib.easyplugin.gui.GUI;
import cc.carm.lib.easyplugin.gui.GUIItem;
import cc.carm.lib.easyplugin.gui.GUIType;
import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI;
Expand Down Expand Up @@ -137,10 +138,11 @@ public void loadResidences() {
display.stream().filter(r -> {
ResidenceData d = Main.getInstance().getResidenceManager().getResidence(r);
return d.isPublicDisplayed() || (d.isOwner(getViewer()));
}).forEach(residence -> addItem(generateIcon(data, residence)));
}).forEach(residence -> addItem(generateIcon(getViewer(), this, owner, data, residence)));
}

protected GUIItem generateIcon(UserListData userData, ClaimedResidence residence) {
protected static GUIItem generateIcon(Player viewer, GUI previous, String filterOwner,
UserListData userData, ClaimedResidence residence) {
ResidenceData data = Main.getInstance().getResidenceManager().getResidence(residence);
PreparedItem icon = PluginConfig.ICON.INFO.prepare(
data.getDisplayName(), data.getOwner(),
Expand Down Expand Up @@ -175,13 +177,13 @@ public void onClick(Player clicker, ClickType type) {
PluginMessages.PIN.SOUND.playTo(clicker);
PluginMessages.PIN.MESSAGE.send(clicker, data.getDisplayName());
}
open(getViewer(), owner);
open(viewer, filterOwner);
} else if (type.isLeftClick()) { // View information
PluginConfig.GUI.CLICK_SOUND.playTo(getViewer());
PluginConfig.GUI.CLICK_SOUND.playTo(viewer);
if (data.isOwner(clicker)) {
ResidenceManageUI.open(getViewer(), data, ResidenceListUI.this);
ResidenceManageUI.open(viewer, data, previous);
} else {
ResidenceInfoUI.open(getViewer(), data, ResidenceListUI.this);
ResidenceInfoUI.open(viewer, data, previous);
}
} else if (type.isRightClick()) { // Teleport to residence (If allowed)
if (!data.canTeleport(viewer)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.artformgames.plugin.residencelist.ui;

import cc.carm.lib.configuration.core.Configuration;
import cc.carm.lib.easyplugin.gui.GUI;
import cc.carm.lib.easyplugin.gui.GUIItem;
import cc.carm.lib.easyplugin.gui.GUIType;
import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem;
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
import com.artformgames.plugin.residencelist.Main;
import com.artformgames.plugin.residencelist.ResidenceListAPI;
import com.artformgames.plugin.residencelist.api.residence.ResidenceData;
import com.artformgames.plugin.residencelist.api.residence.ResidenceRate;
import com.artformgames.plugin.residencelist.api.user.UserListData;
import com.artformgames.plugin.residencelist.conf.PluginConfig;
import com.artformgames.plugin.residencelist.conf.PluginMessages;
import com.artformgames.plugin.residencelist.listener.EditHandler;
import com.artformgames.plugin.residencelist.utils.GUIUtils;
import com.artformgames.plugin.residencelist.utils.ResidenceUtils;
import com.bekvon.bukkit.residence.containers.ResidencePlayer;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class ResidenceMembersUI extends AutoPagedGUI {

public static void open(@NotNull Player player, @NotNull ResidenceData data, @Nullable GUI previousGUI) {
new ResidenceMembersUI(player, data, previousGUI).openGUI(player);
}

protected @NotNull Player viewer;
protected @NotNull ResidenceData data;
protected @Nullable GUI previousGUI;

public ResidenceMembersUI(@NotNull Player viewer, @NotNull ResidenceData data, @Nullable GUI previousGUI) {
super(GUIType.SIX_BY_NINE, Objects.requireNonNull(CONFIG.TITLE.parse(viewer, data.getDisplayName())), 28, 52);
this.viewer = viewer;
this.data = data;
this.previousGUI = previousGUI;

setPreviousPageSlot(36);
setNextPageSlot(44);
setPreviousPageUI(PluginConfig.ICON.PAGE.PREVIOUS_PAGE.get(viewer));
setNextPageUI(PluginConfig.ICON.PAGE.NEXT_PAGE.get(viewer));
setNoPreviousPageUI(PluginConfig.ICON.PAGE.NO_PREVIOUS_PAGE.get(viewer));
setNoNextPageUI(PluginConfig.ICON.PAGE.NO_NEXT_PAGE.get(viewer));
setEmptyItem(PluginConfig.ICON.EMPTY.get(viewer));

initItems();
loadIcon();
loadMembers();
}

public @NotNull Player getViewer() {
return viewer;
}

public UserListData getPlayerData() {
return Main.getInstance().getUserManager().get(getViewer());
}

public @NotNull ResidenceData getData() {
return data;
}

public void initItems() {

if (this.previousGUI != null) {
setItem(0, new GUIItem(CONFIG.ITEMS.BACK.get(viewer)) {
@Override
public void onClick(Player player, ClickType clickType) {
PluginConfig.GUI.CLICK_SOUND.playTo(player);
previousGUI.openGUI(player);
}
});
}

Location teleportLocation = getData().getTeleportLocation(getViewer());
if (teleportLocation != null && getData().canTeleport(getViewer())) {
setItem(13, new GUIItem(CONFIG.ITEMS.TELEPORT_TO.prepare(
getData().getResidence().getMainArea().getWorldName(),
teleportLocation.getBlockX(),
teleportLocation.getBlockY(),
teleportLocation.getBlockZ()
).get(getViewer())) {
@Override
public void onClick(Player clicker, ClickType type) {
data.getResidence().tpToResidence(clicker, clicker, clicker.hasPermission("residence.admin"));
PluginMessages.TELEPORT.SOUND.playTo(clicker);
}
});
} else {
setItem(13, new GUIItem(CONFIG.ITEMS.TELEPORT_DISABLED.prepare().get(getViewer())));
}

if (ResidenceUtils.isServerLand(getData().getResidence())) {
setItem(14, new GUIItem(CONFIG.ITEMS.SERVER.prepare().get(getViewer())));
} else {
setItem(14, new GUIItem(CONFIG.ITEMS.OWNER.prepare(getData().getOwner())
.setSkullOwner(getData().getResidence().getOwnerUUID())
.get(getViewer())) {
@Override
public void onClick(Player clicker, ClickType type) {
ResidenceListUI.open(getViewer(), getData().getOwner());
PluginConfig.GUI.CLICK_SOUND.playTo(getViewer());
}
});
}

ResidenceRate rated = getData().getRates().get(getViewer().getUniqueId());
ItemStack rateIcon;
if (rated == null) {
rateIcon = CONFIG.ITEMS.RATE.get(getViewer());
} else {
rateIcon = CONFIG.ITEMS.RATED.prepare(ResidenceListAPI.format(rated.time()))
.insertLore("comment", GUIUtils.sortContent(rated.content()))
.get(getViewer());
}
setItem(15, new GUIItem(rateIcon) {
@Override
public void onClick(Player clicker, ClickType type) {
if (!(type.isLeftClick() || type.isRightClick())) return;
clicker.closeInventory();
boolean recommend = type.isLeftClick();
PluginMessages.COMMENT.NOTIFY.send(clicker, getData().getDisplayName());
PluginMessages.COMMENT.ASK_SOUND.playTo(clicker);
EditHandler.start(clicker, (player, content) -> {
getData().modify(d -> d.addRate(content, recommend, getViewer().getUniqueId()));
open(player, getData(), previousGUI);
if (recommend) {
PluginMessages.COMMENT.YES_SOUND.playTo(player);
} else {
PluginMessages.COMMENT.NO_SOUND.playTo(player);
}
});
}
});
}

public void loadMembers() {
if (getData().getRates().isEmpty()) {
setItem(40, new GUIItem(CONFIG.ITEMS.EMPTY.get(getViewer())));
return;
}

ClaimedResidence residence = getData().getResidence();
for (ResidencePlayer trustedPlayer : residence.getTrustedPlayers()) {
trustedPlayer.getPlayer();
}

}

public void loadIcon() {
setItem(11, generateIcon(getPlayerData(), getData().getResidence()));
}

public interface CONFIG extends Configuration {

ConfiguredMessage<String> TITLE = ConfiguredMessage.asString()
.defaults("&a&lMembers &7#&f%(name)")
.params("name").build();

}
}

0 comments on commit 8c0b377

Please sign in to comment.