parent
71f8b0eaf4
commit
8f734eb1d1
23 changed files with 525 additions and 212 deletions
@ -0,0 +1,81 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.genericMenus; |
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem; |
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; |
||||||
|
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; |
||||||
|
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; |
||||||
|
import com.github.stefvanschie.inventoryframework.pane.component.PagingButtons; |
||||||
|
import com.github.stefvanschie.inventoryframework.pane.util.Slot; |
||||||
|
import com.j256.ormlite.stmt.QueryBuilder; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import xyz.soukup.ecoCraftCore.gui.GuiItemBuilder; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.PermissionGroup; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Region; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.RegionMember; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Consumer; |
||||||
|
|
||||||
|
public class GroupSelector { |
||||||
|
public static ChestGui selectGroup(Player viewer, Region region, Consumer<Player> selectAction){ |
||||||
|
ChestGui chestGui = new ChestGui(3, LangManager.getLegacyString("gui.player-selector.title")); |
||||||
|
PaginatedPane pane = new PaginatedPane(0,0, 9, 2); |
||||||
|
List<GuiItem> guiItems = new ArrayList<>(); |
||||||
|
|
||||||
|
chestGui.setOnGlobalClick(event -> event.setCancelled(true)); |
||||||
|
|
||||||
|
RegionMember regionMember = region.getRegionMember(viewer); |
||||||
|
|
||||||
|
if (regionMember == null){ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
QueryBuilder<PermissionGroup, Integer> queryBuilder = PermissionGroup.getDao().queryBuilder(); |
||||||
|
|
||||||
|
try { |
||||||
|
queryBuilder |
||||||
|
.where() |
||||||
|
.eq("region_id", region.getId()) |
||||||
|
.and() |
||||||
|
.lt("weight", regionMember.getPermissionGroup().getWeight()); |
||||||
|
List<PermissionGroup> groups = queryBuilder.query(); |
||||||
|
|
||||||
|
for (PermissionGroup group : groups){ |
||||||
|
GuiItem guiItem = new GuiItemBuilder(group.getIcon(), |
||||||
|
group.getName(), |
||||||
|
group.getDescription(), |
||||||
|
(event -> selectAction.accept(viewer))).build(); |
||||||
|
} |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
|
||||||
|
pane.populateWithGuiItems(guiItems); |
||||||
|
PagingButtons pagingButtons = new PagingButtons(Slot.fromXY(0, 2),9, pane); |
||||||
|
|
||||||
|
chestGui.addPane(pane); |
||||||
|
|
||||||
|
|
||||||
|
return chestGui; |
||||||
|
} |
||||||
|
|
||||||
|
public static ChestGui selectGroup(Player viewer, Region region, Consumer<Player> selectAction, Consumer<Player> backAction){ |
||||||
|
ChestGui chestGui = selectGroup(viewer, region, selectAction); |
||||||
|
OutlinePane pane = new OutlinePane(4,2, 1, 1); |
||||||
|
GuiItem backButton = new GuiItemBuilder(Material.REDSTONE, |
||||||
|
"gui.player-selector.back-button.name", |
||||||
|
"gui.player-selector.back-button.lore", |
||||||
|
(event -> backAction.accept(viewer))) |
||||||
|
.build(); |
||||||
|
|
||||||
|
pane.addItem(backButton); |
||||||
|
chestGui.addPane(pane); |
||||||
|
|
||||||
|
return chestGui; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,4 +1,36 @@ |
|||||||
package xyz.soukup.ecoCraftCore.genericMenus; |
package xyz.soukup.ecoCraftCore.genericMenus; |
||||||
|
|
||||||
|
import io.papermc.paper.dialog.Dialog; |
||||||
|
import io.papermc.paper.registry.data.dialog.ActionButton; |
||||||
|
import io.papermc.paper.registry.data.dialog.DialogBase; |
||||||
|
import io.papermc.paper.registry.data.dialog.action.DialogAction; |
||||||
|
import io.papermc.paper.registry.data.dialog.input.DialogInput; |
||||||
|
import io.papermc.paper.registry.data.dialog.type.DialogType; |
||||||
|
import net.kyori.adventure.text.event.ClickCallback; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Consumer; |
||||||
|
|
||||||
|
|
||||||
public class TextInput { |
public class TextInput { |
||||||
|
public static Dialog textInput(Player viewer, String titleKey, String fieldDesctriptionKey, String initial , Consumer<String> action){ |
||||||
|
DialogAction dialogAction = DialogAction.customClick(((response, audience) -> action.accept(response.getText("input"))), ClickCallback.Options.builder().build())); |
||||||
|
|
||||||
|
return Dialog.create(builder -> builder.empty() |
||||||
|
.base(DialogBase.builder(LangManager.get(titleKey)) |
||||||
|
.inputs(List.of(DialogInput.text("input", LangManager.get(fieldDesctriptionKey)) |
||||||
|
.initial(initial) |
||||||
|
.maxLength(256) |
||||||
|
.build())) |
||||||
|
.build()) |
||||||
|
.type(DialogType.confirmation( |
||||||
|
ActionButton.builder(LangManager.get("gui.text-input.confirm")) |
||||||
|
.action(dialogAction) |
||||||
|
.build(), |
||||||
|
ActionButton.builder(LangManager.get("gui.text-input.cancel")) |
||||||
|
.build() |
||||||
|
))); |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
@ -1,46 +1,185 @@ |
|||||||
package xyz.soukup.ecoCraftCore.regions; |
package xyz.soukup.ecoCraftCore.regions; |
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem; |
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; |
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; |
||||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; |
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; |
||||||
|
import com.github.stefvanschie.inventoryframework.pane.component.ToggleButton; |
||||||
|
import io.papermc.paper.dialog.Dialog; |
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.World; |
||||||
|
import org.bukkit.entity.Player; |
||||||
import org.bukkit.event.inventory.InventoryClickEvent; |
import org.bukkit.event.inventory.InventoryClickEvent; |
||||||
import xyz.soukup.ecoCraftCore.messages.Messages; |
import xyz.soukup.ecoCraftCore.genericMenus.PlayerSelector; |
||||||
|
import xyz.soukup.ecoCraftCore.genericMenus.TextInput; |
||||||
|
import xyz.soukup.ecoCraftCore.gui.GuiItemBuilder; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Island; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Permission; |
||||||
import xyz.soukup.ecoCraftCore.objects.Region; |
import xyz.soukup.ecoCraftCore.objects.Region; |
||||||
import xyz.soukup.ecoCraftCore.objects.RegionMember; |
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
public class RegionMenu { |
public class RegionMenu { |
||||||
public static ChestGui regionGui(RegionMember regionMember, Region region){ |
public static ChestGui regionGui(Player player, Region region){ |
||||||
|
|
||||||
return buildGui(regionMember, region); |
return buildGui(player, region); |
||||||
} |
} |
||||||
|
|
||||||
private static ChestGui buildGui(RegionMember regionMember, Region region){ |
private static ChestGui buildGui(Player player, Region region){ |
||||||
String title; |
String title; |
||||||
int regionLevel = region.getLevel(); |
int regionLevel = region.getLevel(); |
||||||
|
|
||||||
if (regionLevel == -1){ |
if (regionLevel == -1){ |
||||||
title = Messages.getAsString("gui.region.title-island"); |
title = LangManager.getLegacyString("gui.region.title-island"); |
||||||
} else { |
} else { |
||||||
title = Messages.getAsString("gui.region.title"); |
title = LangManager.getLegacyString("gui.region.title"); |
||||||
} |
} |
||||||
|
|
||||||
ChestGui gui = new ChestGui(2, title); |
ChestGui gui = new ChestGui(2, title); |
||||||
OutlinePane outlinePane = new OutlinePane(0, 0, 9, 2); |
OutlinePane outlinePane = new OutlinePane(0, 0, 9, 2); |
||||||
|
|
||||||
addIslandSettings(outlinePane, regionMember, region); |
addIslandSettings(outlinePane, player, region); |
||||||
|
addMemberManagement(outlinePane, player, region); |
||||||
|
|
||||||
|
|
||||||
|
gui.addPane(outlinePane); |
||||||
return gui; |
return gui; |
||||||
} |
} |
||||||
|
|
||||||
private static void addIslandSettings(OutlinePane outlinePane, RegionMember regionMember, Region region) { |
private static void addMemberManagement(OutlinePane pane, Player player, Region region){ |
||||||
|
if (!region.hasPermission(player, Permission.MANAGE_MEMBERS)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
GuiItem addMemberButton = new GuiItemBuilder(Material.PLAYER_HEAD, |
||||||
|
"gui.region.add-member.name", |
||||||
|
"gui.region.add-member.description", |
||||||
|
(event -> addMemberSelectPlayer(player, region))) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
private static void addMemberSelectPlayer(Player player, Region region) { |
||||||
|
World world = Bukkit.getWorld(region.getIsland()); |
||||||
|
|
||||||
|
if (world == null){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
List<Player> players = world.getPlayers(); |
||||||
|
List<Player> candidates = new ArrayList<>(); |
||||||
|
|
||||||
|
for(Player candidate : players){ |
||||||
|
if (region.getRegionMember(candidate) != null){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
candidates.add(candidate); |
||||||
|
} |
||||||
|
|
||||||
|
ChestGui playerSelectGui = PlayerSelector.selectPlayer(player, |
||||||
|
candidates, |
||||||
|
(( selectedPlayer) -> addMemberSelectGroup(player, region, selectedPlayer)), |
||||||
|
(event -> regionGui(player, region).show(player))); |
||||||
|
|
||||||
|
playerSelectGui.show(player); |
||||||
} |
} |
||||||
|
|
||||||
private static void setIslandDescription(InventoryClickEvent event, Region region, RegionMember regionMember) { |
private static void addMemberSelectGroup(Player player, Region region, Player selectedPlayer){ |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
private static void setIslandName(InventoryClickEvent inventoryClickEvent, Region region, RegionMember regionMember) { |
private static void addIslandSettings(OutlinePane pane, Player player, Region region) { |
||||||
|
if (region.getLevel() != -1){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (!region.hasPermission(player, Permission.MANAGE_INFO)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
Island island = Island.findByUuid(region.getIsland()); |
||||||
|
|
||||||
|
if (island == null){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
ToggleButton toggleButton = new ToggleButton(1,1); |
||||||
|
|
||||||
|
Dialog islandTitleDialog = TextInput.textInput(player, |
||||||
|
"gui.region.name-island.name", |
||||||
|
"gui.region.name-island.input", |
||||||
|
island.getDisplayName(), |
||||||
|
(s -> setIslandName(player, island, s))); |
||||||
|
Dialog islandDescriptionDialog = TextInput.textInput(player, |
||||||
|
"gui.region.description-island.name", |
||||||
|
"gui.region.description-island.input", |
||||||
|
island.getDescritpion(), |
||||||
|
(s -> setIslandDescription(player, island, s))); |
||||||
|
|
||||||
|
GuiItem visibilityToggle = new GuiItemBuilder(Material.ENDER_EYE, |
||||||
|
"gui.region.visibility-island.name", |
||||||
|
"gui.region.visibility-island.description", |
||||||
|
(event -> toggleIslandPublic(player, island, event)), |
||||||
|
island.getPublic() |
||||||
|
).build(); |
||||||
|
|
||||||
|
GuiItem titleButton = new GuiItemBuilder( |
||||||
|
Material.DARK_OAK_SIGN, |
||||||
|
"gui.region.name-island.name", |
||||||
|
"gui.region.name-island.description", |
||||||
|
(event -> player.showDialog(islandTitleDialog)) |
||||||
|
).build(); |
||||||
|
|
||||||
|
GuiItem descriptionButton = new GuiItemBuilder( |
||||||
|
Material.ACACIA_SIGN, |
||||||
|
"gui.region.description-island.name", |
||||||
|
"gui.region.description-island.description", |
||||||
|
(event -> player.showDialog(islandDescriptionDialog)) |
||||||
|
).build(); |
||||||
|
|
||||||
|
pane.addItem(visibilityToggle); |
||||||
|
pane.addItem(titleButton); |
||||||
|
pane.addItem(descriptionButton); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void toggleIslandPublic(Player player, Island island, InventoryClickEvent event){ |
||||||
|
island.setPublic(!island.getPublic()); |
||||||
|
island.save(); |
||||||
|
|
||||||
|
ChestGui chestGui = (ChestGui) ChestGui.getGui(event.getInventory()); |
||||||
|
|
||||||
|
if (chestGui == null){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
OutlinePane pane = new OutlinePane(event.getSlot(), 1); |
||||||
|
|
||||||
|
GuiItem visibilityToggle = new GuiItemBuilder(Material.ENDER_EYE, |
||||||
|
"gui.region.visibility-island.name", |
||||||
|
"gui.region.visibility-island.description", |
||||||
|
(clickEvent -> toggleIslandPublic(player, island, event)), |
||||||
|
island.getPublic() |
||||||
|
).build(); |
||||||
|
|
||||||
|
pane.addItem(visibilityToggle); |
||||||
|
chestGui.addPane(pane); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void setIslandDescription(Player player, Island island, String description) { |
||||||
|
island.setDescritpion(description); |
||||||
|
island.save(); |
||||||
|
LangManager.send(player, "island.changed.description"); |
||||||
|
} |
||||||
|
|
||||||
|
private static void setIslandName(Player player, Island island, String name) { |
||||||
|
island.setDisplayName(name); |
||||||
|
island.save(); |
||||||
|
LangManager.send(player, "island.changed.name"); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue