Compare commits
5 Commits
master
...
region-rew
| Author | SHA1 | Date |
|---|---|---|
|
|
8f734eb1d1 | 5 days ago |
|
|
71f8b0eaf4 | 1 week ago |
|
|
f355dcfa1e | 2 weeks ago |
|
|
e70e526d93 | 3 weeks ago |
|
|
87e7962028 | 3 weeks ago |
47 changed files with 2740 additions and 728 deletions
@ -0,0 +1,19 @@ |
|||||||
|
Copyright (c) 2025-2026 Jakub Soukup, Erik Radovan and contributors |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
||||||
|
of the Software, but NOT including the right to run, execute or use the |
||||||
|
Software or any executable binaries built from the source code. |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all |
||||||
|
copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
SOFTWARE |
||||||
@ -1,89 +0,0 @@ |
|||||||
package xyz.soukup.ecoCraftCore.database; |
|
||||||
|
|
||||||
import com.j256.ormlite.dao.Dao; |
|
||||||
import xyz.soukup.ecoCraftCore.database.objects.*; |
|
||||||
import xyz.soukup.ecoCraftCore.database.objects.VirtualChest; |
|
||||||
|
|
||||||
public class DaoRegistry { |
|
||||||
private static Dao<Shop, Integer> shopDao; |
|
||||||
private static Dao<Transaction, Integer> transactionDao; |
|
||||||
private static Dao<VirtualChest, Integer> virtualChestDao; |
|
||||||
private static Dao<Account, Integer> accountDao; |
|
||||||
private static Dao<Island, Integer> islandDao; |
|
||||||
private static Dao<TeleportRequest, Integer> teleportRequestsDao; |
|
||||||
private static Dao<ActiveServer, Integer> activeServerDao; |
|
||||||
private static Dao<Region, Integer> regionDao; |
|
||||||
private static Dao<RegionMember, Integer> regionMemberDao; |
|
||||||
|
|
||||||
public static Dao<RegionMember, Integer> getRegionMemberDao() { |
|
||||||
return regionMemberDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setRegionMemberDao(Dao<RegionMember, Integer> regionMemberDao) { |
|
||||||
DaoRegistry.regionMemberDao = regionMemberDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<Region, Integer> getRegionDao() { |
|
||||||
return regionDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setRegionDao(Dao<Region, Integer> regionDao) { |
|
||||||
DaoRegistry.regionDao = regionDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<TeleportRequest, Integer> getTeleportRequestsDao() { |
|
||||||
return teleportRequestsDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setTeleportRequestsDao(Dao<TeleportRequest, Integer> teleportRequestsDao) { |
|
||||||
DaoRegistry.teleportRequestsDao = teleportRequestsDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<ActiveServer, Integer> getActiveServerDao() { |
|
||||||
return activeServerDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setActiveServerDao(Dao<ActiveServer, Integer> activeServerDao) { |
|
||||||
DaoRegistry.activeServerDao = activeServerDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<Shop, Integer> getShopDao() { |
|
||||||
return shopDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setShopDao(Dao<Shop, Integer> shopDao) { |
|
||||||
DaoRegistry.shopDao = shopDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<Transaction, Integer> getTransactionDao() { |
|
||||||
return transactionDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setTransactionDao(Dao<Transaction, Integer> transactionDao) { |
|
||||||
DaoRegistry.transactionDao = transactionDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<VirtualChest, Integer> getVirtualChestDao() { |
|
||||||
return virtualChestDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setVirtualChestDao(Dao<VirtualChest, Integer> virtualChestDao) { |
|
||||||
DaoRegistry.virtualChestDao = virtualChestDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<Account, Integer> getAccountDao() { |
|
||||||
return accountDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setAccountDao(Dao<Account, Integer> accountDao) { |
|
||||||
DaoRegistry.accountDao = accountDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static Dao<Island, Integer> getIslandDao() { |
|
||||||
return islandDao; |
|
||||||
} |
|
||||||
|
|
||||||
public static void setIslandDaoo(Dao<Island, Integer> islandDao) { |
|
||||||
DaoRegistry.islandDao = islandDao; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,213 +0,0 @@ |
|||||||
package xyz.soukup.ecoCraftCore.database.objects; |
|
||||||
|
|
||||||
import com.j256.ormlite.dao.ForeignCollection; |
|
||||||
import com.j256.ormlite.field.DatabaseField; |
|
||||||
import com.j256.ormlite.field.ForeignCollectionField; |
|
||||||
import com.j256.ormlite.table.DatabaseTable; |
|
||||||
import xyz.soukup.ecoCraftCore.database.DaoRegistry; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
@DatabaseTable(tableName = "regions") |
|
||||||
public class Region { |
|
||||||
|
|
||||||
public static final HashMap<String, List<Region>> cache = new HashMap<>(); |
|
||||||
|
|
||||||
@DatabaseField(generatedId = true) |
|
||||||
private int id; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private String island; |
|
||||||
|
|
||||||
@DatabaseField(columnName = "region_type", canBeNull = false) |
|
||||||
private int regionType; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int x1; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int y1; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int z1; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int x2; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int y2; |
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false) |
|
||||||
private int z2; |
|
||||||
|
|
||||||
@ForeignCollectionField(eager = true) |
|
||||||
private ForeignCollection<RegionMember> regionMembers; |
|
||||||
|
|
||||||
@DatabaseField() |
|
||||||
private Integer value; |
|
||||||
|
|
||||||
public Region() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public Region(String island, int regionType, int x1, int y1, int z1, int x2, int y2, int z2) { |
|
||||||
this.island = island; |
|
||||||
this.regionType = regionType; |
|
||||||
this.x1 = Math.min(x1, x2); |
|
||||||
this.y1 = Math.min(y1, y2); |
|
||||||
this.x2 = Math.max(x1, x2); |
|
||||||
this.y2 = Math.max(y1, y2); |
|
||||||
this.z1 = Math.min(z1, z2); |
|
||||||
this.z2 = Math.max(z1, z2); |
|
||||||
|
|
||||||
} |
|
||||||
public int getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public int getRegionType() { |
|
||||||
return regionType; |
|
||||||
} |
|
||||||
|
|
||||||
public int getX1() { |
|
||||||
return x1; |
|
||||||
} |
|
||||||
|
|
||||||
public int getZ1() { |
|
||||||
return z1; |
|
||||||
} |
|
||||||
|
|
||||||
public int getZ2() { |
|
||||||
return z2; |
|
||||||
} |
|
||||||
|
|
||||||
public int getY1() { |
|
||||||
return y1; |
|
||||||
} |
|
||||||
|
|
||||||
public int getX2() { |
|
||||||
return x2; |
|
||||||
} |
|
||||||
|
|
||||||
public int getY2() { |
|
||||||
return y2; |
|
||||||
} |
|
||||||
|
|
||||||
public ForeignCollection<RegionMember> getRegionMembers() { |
|
||||||
return regionMembers; |
|
||||||
} |
|
||||||
|
|
||||||
public Integer getValue() { |
|
||||||
return value; |
|
||||||
} |
|
||||||
|
|
||||||
public String getIsland() { |
|
||||||
return island; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setRegionType(int regionType) { |
|
||||||
this.regionType = regionType; |
|
||||||
} |
|
||||||
|
|
||||||
public void setValue(Integer value) { |
|
||||||
this.value = value; |
|
||||||
} |
|
||||||
|
|
||||||
public void save(){ |
|
||||||
try { |
|
||||||
|
|
||||||
DaoRegistry.getRegionDao().createOrUpdate(this); |
|
||||||
List<Region> regions = cache.get(island); |
|
||||||
|
|
||||||
if (regions == null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
regions.removeIf(region -> region.getId() == this.id); |
|
||||||
regions.add(this); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void addRegionMember(String memberType, String member, String membershipType){ |
|
||||||
RegionMember regionMember = new RegionMember(this, memberType, member, membershipType); |
|
||||||
regionMember.save(); |
|
||||||
|
|
||||||
Region updatedRegion = Region.findById(this.id); |
|
||||||
List<Region> regions = cache.get(island); |
|
||||||
|
|
||||||
if (regions == null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
regions.removeIf(region -> region.getId() == this.id); |
|
||||||
regions.add(updatedRegion); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public boolean isInside(int x, int y, int z) { |
|
||||||
return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; |
|
||||||
} |
|
||||||
|
|
||||||
public static Region findById(int id) { |
|
||||||
try { |
|
||||||
return DaoRegistry.getRegionDao().queryForId(id); |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void cacheRegions(String island) { |
|
||||||
try { |
|
||||||
List<Region> regions = DaoRegistry.getRegionDao().queryBuilder() |
|
||||||
.where() |
|
||||||
.eq("island", island) |
|
||||||
.query(); |
|
||||||
cache.put(island, regions); |
|
||||||
} catch (Exception e) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static Region findRegion(int x, int y, int z, String island) { |
|
||||||
|
|
||||||
Region region = null; |
|
||||||
int highestType = -1; |
|
||||||
|
|
||||||
if (!cache.containsKey(island)) { |
|
||||||
cacheRegions(island); |
|
||||||
} |
|
||||||
|
|
||||||
for (Region cachedRegion : cache.get(island)) { |
|
||||||
if (!cachedRegion.isInside(x, y, z)) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
if (highestType >= cachedRegion.getRegionType()){ |
|
||||||
continue; |
|
||||||
} |
|
||||||
region = cachedRegion; |
|
||||||
} |
|
||||||
|
|
||||||
return region; |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public void changeBoundaries(int x1, int y1, int z1, int x2, int y2, int z2){ |
|
||||||
this.x1 = Math.min(x1, x2); |
|
||||||
this.y1 = Math.min(y1, y2); |
|
||||||
this.x2 = Math.max(x1, x2); |
|
||||||
this.y2 = Math.max(y1, y2); |
|
||||||
this.z1 = Math.min(z1, z2); |
|
||||||
this.z2 = Math.max(z1, z2); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@ -1,65 +0,0 @@ |
|||||||
package xyz.soukup.ecoCraftCore.database.objects; |
|
||||||
|
|
||||||
import com.j256.ormlite.field.DatabaseField; |
|
||||||
import com.j256.ormlite.table.DatabaseTable; |
|
||||||
import xyz.soukup.ecoCraftCore.database.DaoRegistry; |
|
||||||
|
|
||||||
import java.sql.SQLException; |
|
||||||
|
|
||||||
@DatabaseTable(tableName = "region_members") |
|
||||||
public class RegionMember { |
|
||||||
|
|
||||||
@DatabaseField(generatedId = true) |
|
||||||
private int id; |
|
||||||
|
|
||||||
@DatabaseField(foreign = true, foreignAutoRefresh = true) |
|
||||||
private Region region; |
|
||||||
|
|
||||||
@DatabaseField(columnName = "member_type", canBeNull = false) |
|
||||||
private String membertype; |
|
||||||
|
|
||||||
@DatabaseField(columnName = "member_name", canBeNull = false) |
|
||||||
private String memberName; |
|
||||||
|
|
||||||
@DatabaseField(columnName = "membership_type", canBeNull = false) |
|
||||||
private String membershipType; |
|
||||||
|
|
||||||
public RegionMember(){ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public RegionMember(Region region, String membertype, String memberName, String membershipType){ |
|
||||||
this.region = region; |
|
||||||
this.membertype = membertype; |
|
||||||
this.memberName = memberName; |
|
||||||
this.membershipType = membershipType; |
|
||||||
} |
|
||||||
|
|
||||||
public Region getRegion() { |
|
||||||
return region; |
|
||||||
} |
|
||||||
|
|
||||||
public String getMembertype() { |
|
||||||
return membertype; |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() { |
|
||||||
return memberName; |
|
||||||
} |
|
||||||
|
|
||||||
public String getMembershipType() { |
|
||||||
return membershipType; |
|
||||||
} |
|
||||||
|
|
||||||
public void setMembershipType(String membershipType) { |
|
||||||
this.membershipType = membershipType; |
|
||||||
} |
|
||||||
|
|
||||||
public void save(){ |
|
||||||
try { |
|
||||||
DaoRegistry.getRegionMemberDao().createOrUpdate(this); |
|
||||||
} catch (SQLException e) { |
|
||||||
throw new RuntimeException(e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
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 net.kyori.adventure.text.Component; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.inventory.meta.SkullMeta; |
||||||
|
import xyz.soukup.ecoCraftCore.gui.GuiItemBuilder; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.Replace; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Consumer; |
||||||
|
|
||||||
|
public class PlayerSelector { |
||||||
|
public static ChestGui selectPlayer(Player viewer, List<Player> players, 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)); |
||||||
|
|
||||||
|
for (Player player : players){ |
||||||
|
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD); |
||||||
|
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); |
||||||
|
Component name = LangManager.get("gui.player-selector.name-format", new Replace("name", player.displayName())); |
||||||
|
|
||||||
|
skullMeta.setOwningPlayer(player); |
||||||
|
skullMeta.displayName(name); |
||||||
|
itemStack.setItemMeta(skullMeta); |
||||||
|
|
||||||
|
GuiItem guiItem = new GuiItem(itemStack); |
||||||
|
guiItem.setAction(event -> selectAction.accept(viewer)); |
||||||
|
guiItems.add(guiItem); |
||||||
|
} |
||||||
|
|
||||||
|
pane.populateWithGuiItems(guiItems); |
||||||
|
PagingButtons pagingButtons = new PagingButtons(Slot.fromXY(0, 2),9, pane); |
||||||
|
|
||||||
|
chestGui.addPane(pane); |
||||||
|
|
||||||
|
|
||||||
|
return chestGui; |
||||||
|
} |
||||||
|
|
||||||
|
public static ChestGui selectPlayer(Player viewer, List<Player> players, Consumer<Player> selectAction, Consumer<Player> backAction){ |
||||||
|
ChestGui chestGui = selectPlayer(viewer, players, 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; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
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 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,4 +0,0 @@ |
|||||||
package xyz.soukup.ecoCraftCore.islands; |
|
||||||
|
|
||||||
public class UnloadIsland { |
|
||||||
} |
|
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.messages; |
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component; |
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||||
|
|
||||||
|
public class Replace { |
||||||
|
private final String key; |
||||||
|
private final String value; |
||||||
|
|
||||||
|
public Replace(String key, Component value){ |
||||||
|
this.key = key; |
||||||
|
this.value = MiniMessage.miniMessage().serialize(value); |
||||||
|
} |
||||||
|
|
||||||
|
public Replace(String key, String value) { |
||||||
|
this.key = key; |
||||||
|
this.value = value; |
||||||
|
} |
||||||
|
|
||||||
|
public String process(String input) { |
||||||
|
return input.replace("<" + key + ">", value); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,43 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.objects; |
||||||
|
|
||||||
|
public enum Permission { |
||||||
|
PLACE(0), |
||||||
|
BREAK(1), |
||||||
|
INTERACT(2), |
||||||
|
ENTITY_INTERACT(3), |
||||||
|
OPEN_CHESTS(4), |
||||||
|
ENTER(5), |
||||||
|
EXIT(6), |
||||||
|
MANAGE_MEMBERS(7), |
||||||
|
MANAGE_GROUPS(8), |
||||||
|
MANAGE_REGIONS(9), |
||||||
|
TRANSFER_OWNERSHIP(10), |
||||||
|
USE_HOPPER(11), |
||||||
|
HARVEST(12), |
||||||
|
PLANT(13), |
||||||
|
PICKUP_ITEMS(14), |
||||||
|
DROP_ITEMS(15), |
||||||
|
REDSTONE_INTERACT(16), |
||||||
|
SIT(17), |
||||||
|
SHOP_INTERACT(18), |
||||||
|
HARM_ENTITIES(19), |
||||||
|
HARM_PLAYERS(20), |
||||||
|
VEHICLE_RIDE(21), |
||||||
|
VEHICLE_PLACE(22), |
||||||
|
VEHICLE_BREAK(23), |
||||||
|
VEHICLE_INTERACT(24), |
||||||
|
BUCKET_USE(25), |
||||||
|
MANAGE_INFO(26); |
||||||
|
|
||||||
|
|
||||||
|
private final int mask; |
||||||
|
|
||||||
|
Permission(int position) { |
||||||
|
this.mask = 1 << position; |
||||||
|
} |
||||||
|
|
||||||
|
public int getMask() { |
||||||
|
return mask; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,228 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.objects; |
||||||
|
|
||||||
|
import com.j256.ormlite.dao.Dao; |
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "permission_groups") |
||||||
|
public class PermissionGroup { |
||||||
|
|
||||||
|
public static Dao<PermissionGroup, Integer> dao; |
||||||
|
|
||||||
|
public static void setDao(Dao<PermissionGroup, Integer> dao) { |
||||||
|
PermissionGroup.dao = dao; |
||||||
|
} |
||||||
|
|
||||||
|
public static Dao<PermissionGroup, Integer> getDao() { |
||||||
|
return dao; |
||||||
|
} |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(foreign = true, foreignAutoRefresh = true, uniqueCombo = true) |
||||||
|
private Region region; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, uniqueCombo = true) |
||||||
|
private String name; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, columnName = "display_name") |
||||||
|
private String displayName; |
||||||
|
|
||||||
|
@DatabaseField() |
||||||
|
private String description; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private Material icon; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, defaultValue = "0") |
||||||
|
private int weight; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, defaultValue = "true") |
||||||
|
private Boolean editable; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, defaultValue = "true") |
||||||
|
private Boolean deletable; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, defaultValue = "0", columnName = "permissions_number") |
||||||
|
private int permissionsNumber; |
||||||
|
|
||||||
|
public PermissionGroup(){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup(int permissionsNumber){ |
||||||
|
this.permissionsNumber = permissionsNumber; |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup(Region region, String name, String displayName, String description, Material icon){ |
||||||
|
this.region = region; |
||||||
|
this.name = name; |
||||||
|
this.displayName = displayName; |
||||||
|
this.description = description; |
||||||
|
this.icon = icon; |
||||||
|
this.editable = true; |
||||||
|
this.deletable = true; |
||||||
|
this.permissionsNumber = 0; |
||||||
|
this.weight = 0; |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup(Region region, String name, String displayName, String description, Material icon, Boolean editable, Boolean deletable, int weight,int permissions){ |
||||||
|
this.region = region; |
||||||
|
this.name = name; |
||||||
|
this.displayName = displayName; |
||||||
|
this.description = description; |
||||||
|
this.icon = icon; |
||||||
|
this.editable = editable; |
||||||
|
this.deletable = deletable; |
||||||
|
this.permissionsNumber = permissions; |
||||||
|
this.weight = weight; |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup(Region region, String name, String displayName, String description, Material icon, Boolean editable, Boolean deletable, int weight, Permission... permissions) { |
||||||
|
this.region = region; |
||||||
|
this.name = name; |
||||||
|
this.displayName = displayName; |
||||||
|
this.description = description; |
||||||
|
this.icon = icon; |
||||||
|
this.editable = editable; |
||||||
|
this.deletable = deletable; |
||||||
|
this.permissionsNumber = 0; |
||||||
|
this.weight = 0; |
||||||
|
for (Permission permission : permissions) { |
||||||
|
this.permissionsNumber |= permission.getMask(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup copyTo(Region region) { |
||||||
|
return new PermissionGroup( |
||||||
|
region, |
||||||
|
this.name, |
||||||
|
this.displayName, |
||||||
|
this.description, |
||||||
|
this.icon, |
||||||
|
this.editable, |
||||||
|
this.deletable, |
||||||
|
this.weight, |
||||||
|
this.permissionsNumber |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasPermission(Permission permission) { |
||||||
|
return (this.permissionsNumber & permission.getMask()) != 0; |
||||||
|
} |
||||||
|
|
||||||
|
public void addPermission(Permission... permissions) { |
||||||
|
for (Permission permission : permissions){ |
||||||
|
this.permissionsNumber |= permission.getMask(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void removePermission(Permission permission) { |
||||||
|
this.permissionsNumber &= ~permission.getMask(); |
||||||
|
} |
||||||
|
|
||||||
|
public int getPermissionsNumber() { |
||||||
|
return permissionsNumber; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDisplayName() { |
||||||
|
return displayName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDisplayName(String displayName) { |
||||||
|
this.displayName = displayName; |
||||||
|
} |
||||||
|
|
||||||
|
public Material getIcon() { |
||||||
|
return icon; |
||||||
|
} |
||||||
|
|
||||||
|
public void setIcon(Material icon) { |
||||||
|
this.icon = icon; |
||||||
|
} |
||||||
|
|
||||||
|
public int getWeight() { |
||||||
|
return weight; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWeight(int weight) { |
||||||
|
this.weight = weight; |
||||||
|
} |
||||||
|
|
||||||
|
public static Status changeGroupDisplayNameSafely(int id, String groupName, String displayName, Player senderPlayer){ |
||||||
|
Region region = Region.findById(id); |
||||||
|
|
||||||
|
if (region == null){ |
||||||
|
return Status.NOT_EXIST; |
||||||
|
} |
||||||
|
|
||||||
|
PermissionGroup permissionGroup = region.getPermissionGroup(groupName); |
||||||
|
|
||||||
|
if (permissionGroup == null){ |
||||||
|
return Status.NOT_EXIST_GROUP; |
||||||
|
} |
||||||
|
|
||||||
|
PermissionGroup senderGroup = region.getRegionMember(senderPlayer).getPermissionGroup(); |
||||||
|
|
||||||
|
if (!(region.hasPermission(senderPlayer, Permission.MANAGE_GROUPS) && senderGroup.getWeight() > permissionGroup.getWeight())){ |
||||||
|
return Status.NO_PERMISSION; |
||||||
|
} |
||||||
|
|
||||||
|
permissionGroup.setDisplayName(displayName); |
||||||
|
permissionGroup.save(); |
||||||
|
|
||||||
|
return Status.OK; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDescription(String description) { |
||||||
|
this.description = description; |
||||||
|
} |
||||||
|
|
||||||
|
public void save(){ |
||||||
|
try { |
||||||
|
getDao().createOrUpdate(this); |
||||||
|
region.dropCache(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static PermissionGroup getPermissionGroup(Region region, String name){ |
||||||
|
try { |
||||||
|
return getDao().queryBuilder().where().eq("region_id", region.getId()).and().eq("name", name).queryForFirst(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getDescription() { |
||||||
|
return description; |
||||||
|
} |
||||||
|
|
||||||
|
public void delete() { |
||||||
|
Dao<RegionMember, Integer> memberDao = RegionMember.getDao(); |
||||||
|
try { |
||||||
|
memberDao.delete(memberDao.queryBuilder().where().eq("permission_group", this.id).query()); |
||||||
|
getDao().delete(this); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
|
||||||
|
region.dropCache(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,469 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.objects; |
||||||
|
|
||||||
|
import com.j256.ormlite.dao.Dao; |
||||||
|
import com.j256.ormlite.dao.ForeignCollection; |
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.field.ForeignCollectionField; |
||||||
|
import com.j256.ormlite.stmt.DeleteBuilder; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
import org.bukkit.Location; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "regions") |
||||||
|
public class Region { |
||||||
|
|
||||||
|
public static Dao<Region, Integer> dao; |
||||||
|
|
||||||
|
public static void setDao(Dao<Region, Integer> dao) { |
||||||
|
Region.dao = dao; |
||||||
|
} |
||||||
|
|
||||||
|
public static Dao<Region, Integer> getDao() { |
||||||
|
return dao; |
||||||
|
} |
||||||
|
|
||||||
|
public static final HashMap<String, List<Region>> cache = new HashMap<>(); |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String island; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "region_level", canBeNull = false) |
||||||
|
private int regionLevel; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int x1; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int y1; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int z1; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int x2; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int y2; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int z2; |
||||||
|
|
||||||
|
@ForeignCollectionField(eager = true) |
||||||
|
private ForeignCollection<RegionMember> regionMembers; |
||||||
|
|
||||||
|
@DatabaseField() |
||||||
|
private Integer value; |
||||||
|
|
||||||
|
public Region() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Region(String island, int regionLevel, int x1, int y1, int z1, int x2, int y2, int z2) { |
||||||
|
this.island = island; |
||||||
|
this.regionLevel = regionLevel; |
||||||
|
this.x1 = Math.min(x1, x2); |
||||||
|
this.y1 = Math.min(y1, y2); |
||||||
|
this.x2 = Math.max(x1, x2); |
||||||
|
this.y2 = Math.max(y1, y2); |
||||||
|
this.z1 = Math.min(z1, z2); |
||||||
|
this.z2 = Math.max(z1, z2); |
||||||
|
|
||||||
|
save(); |
||||||
|
createDefaultGroupsAndReturnOwner(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup getPermissionGroup(String name){ |
||||||
|
return PermissionGroup.getPermissionGroup(this, name); |
||||||
|
} |
||||||
|
|
||||||
|
public Region(Region parentRegion, int x1, int y1, int z1, int x2, int y2, int z2) { |
||||||
|
this.island = parentRegion.getIsland(); |
||||||
|
this.regionLevel = parentRegion.getLevel() + 1; |
||||||
|
this.x1 = Math.min(x1, x2); |
||||||
|
this.y1 = Math.min(y1, y2); |
||||||
|
this.x2 = Math.max(x1, x2); |
||||||
|
this.y2 = Math.max(y1, y2); |
||||||
|
this.z1 = Math.min(z1, z2); |
||||||
|
this.z2 = Math.max(z1, z2); |
||||||
|
|
||||||
|
save(); |
||||||
|
|
||||||
|
copyDataFrom(parentRegion); |
||||||
|
} |
||||||
|
|
||||||
|
private void copyDataFrom(Region source) { |
||||||
|
try { |
||||||
|
Map<String, PermissionGroup> groupMapping = new HashMap<>(); |
||||||
|
|
||||||
|
List<PermissionGroup> sourceGroups = PermissionGroup.getDao().queryBuilder() |
||||||
|
.where().eq("region_id", source.getId()).query(); |
||||||
|
|
||||||
|
for (PermissionGroup sourceGroup : sourceGroups) { |
||||||
|
PermissionGroup clonedGroup = sourceGroup.copyTo(this); |
||||||
|
clonedGroup.save(); |
||||||
|
groupMapping.put(clonedGroup.getName(), clonedGroup); |
||||||
|
} |
||||||
|
|
||||||
|
for (RegionMember sourceMember : source.getRegionMembers()) { |
||||||
|
PermissionGroup targetGroup = groupMapping.get(sourceMember.getPermissionGroup().getName()); |
||||||
|
|
||||||
|
if (targetGroup != null) { |
||||||
|
addRegionMember(sourceMember.getMemberType(), sourceMember.getName(), targetGroup); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Region(String island, int regionType, int x1, int y1, int z1, int x2, int y2, int z2, Player owner) { |
||||||
|
this.island = island; |
||||||
|
this.regionLevel = regionType; |
||||||
|
this.x1 = Math.min(x1, x2); |
||||||
|
this.y1 = Math.min(y1, y2); |
||||||
|
this.x2 = Math.max(x1, x2); |
||||||
|
this.y2 = Math.max(y1, y2); |
||||||
|
this.z1 = Math.min(z1, z2); |
||||||
|
this.z2 = Math.max(z1, z2); |
||||||
|
|
||||||
|
this.save(); |
||||||
|
|
||||||
|
PermissionGroup ownerGroup = this.createDefaultGroupsAndReturnOwner(); |
||||||
|
addRegionMember("player", owner.getName(), ownerGroup); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public int getLevel() { |
||||||
|
return regionLevel; |
||||||
|
} |
||||||
|
|
||||||
|
public int getX1() { |
||||||
|
return x1; |
||||||
|
} |
||||||
|
|
||||||
|
public int getZ1() { |
||||||
|
return z1; |
||||||
|
} |
||||||
|
|
||||||
|
public int getZ2() { |
||||||
|
return z2; |
||||||
|
} |
||||||
|
|
||||||
|
public int getY1() { |
||||||
|
return y1; |
||||||
|
} |
||||||
|
|
||||||
|
public int getX2() { |
||||||
|
return x2; |
||||||
|
} |
||||||
|
|
||||||
|
public int getY2() { |
||||||
|
return y2; |
||||||
|
} |
||||||
|
|
||||||
|
public ForeignCollection<RegionMember> getRegionMembers() { |
||||||
|
return regionMembers; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getValue() { |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIsland() { |
||||||
|
return island; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setRegionLevel(int regionLevel) { |
||||||
|
this.regionLevel = regionLevel; |
||||||
|
} |
||||||
|
|
||||||
|
public void setValue(Integer value) { |
||||||
|
this.value = value; |
||||||
|
} |
||||||
|
|
||||||
|
public void save(){ |
||||||
|
try { |
||||||
|
|
||||||
|
getDao().createOrUpdate(this); |
||||||
|
List<Region> regions = cache.get(island); |
||||||
|
|
||||||
|
if (regions == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
regions.removeIf(region -> region.getId() == this.id); |
||||||
|
regions.add(this); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void dropCache(){ |
||||||
|
cache.remove(island); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void addRegionMember(Player player, PermissionGroup group){ |
||||||
|
addRegionMember("player", player.getName(), group); |
||||||
|
} |
||||||
|
|
||||||
|
public void addRegionMember(String memberType, String member, PermissionGroup permissionGroup){ |
||||||
|
RegionMember regionMember = new RegionMember(this, memberType, member, permissionGroup); |
||||||
|
regionMember.save(); |
||||||
|
|
||||||
|
List<Region> regions = cache.get(island); |
||||||
|
|
||||||
|
if (regions == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
regions.removeIf(region -> region.getId() == this.id); |
||||||
|
regions.add(this); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void removeRegionMember(Player player){ |
||||||
|
removeRegionMember("player", player.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
public void removeRegionMember(String memberType, String member){ |
||||||
|
try { |
||||||
|
DeleteBuilder<RegionMember, Integer> deletion = RegionMember.getDao().deleteBuilder(); |
||||||
|
deletion.where().eq("region_id", this.id).and().eq("member_type", memberType).and().eq("member_name", member); |
||||||
|
deletion.delete(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
dropCache(); |
||||||
|
} |
||||||
|
|
||||||
|
public RegionMember getRegionMember(Player player){ |
||||||
|
return getRegionMember("player", player.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasPermission(Player player, Permission permission){ |
||||||
|
RegionMember regionMember = getRegionMember(player); |
||||||
|
PermissionGroup permissionGroup; |
||||||
|
|
||||||
|
if (regionMember == null) { |
||||||
|
permissionGroup = getPermissionGroup("default"); |
||||||
|
}else { |
||||||
|
permissionGroup = regionMember.getPermissionGroup(); |
||||||
|
} |
||||||
|
|
||||||
|
return permissionGroup.hasPermission(permission); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasPermission(String memberType, String memberName, Permission permission){ |
||||||
|
RegionMember regionMember = getRegionMember(memberType, memberName); |
||||||
|
PermissionGroup permissionGroup; |
||||||
|
|
||||||
|
if (regionMember == null) { |
||||||
|
permissionGroup = getPermissionGroup("default"); |
||||||
|
}else { |
||||||
|
permissionGroup = regionMember.getPermissionGroup(); |
||||||
|
} |
||||||
|
|
||||||
|
return permissionGroup.hasPermission(permission); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Region> getOverlappingRegions(Location loc1, Location loc2) { |
||||||
|
if (loc1.getWorld() != loc2.getWorld()){ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String island = loc1.getWorld().getName(); |
||||||
|
|
||||||
|
List<Region> overlapping = new java.util.ArrayList<>(); |
||||||
|
|
||||||
|
if (!cache.containsKey(island)) { |
||||||
|
cacheRegions(island); |
||||||
|
} |
||||||
|
|
||||||
|
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX()); |
||||||
|
int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()); |
||||||
|
int minY = Math.min(loc1.getBlockY(), loc2.getBlockY()); |
||||||
|
int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()); |
||||||
|
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); |
||||||
|
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); |
||||||
|
|
||||||
|
for (Region region : cache.get(island)) { |
||||||
|
if ((region.getX1() <= maxX |
||||||
|
&& region.getX2() >= minX) && (region.getY1() <= maxY |
||||||
|
&& region.getY2() >= minY) && (region.getZ1() <= maxZ |
||||||
|
&& region.getZ2() >= minZ)) { |
||||||
|
overlapping.add(region); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return overlapping; |
||||||
|
} |
||||||
|
|
||||||
|
public static Region getHighestLevelRegion(Location loc1, Location loc2) { |
||||||
|
List<Region> regions = getOverlappingRegions(loc1, loc2); |
||||||
|
|
||||||
|
if (regions.isEmpty()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
return regions.stream().max(Comparator.comparingInt(Region::getLevel)).orElse(null); |
||||||
|
} |
||||||
|
|
||||||
|
public RegionMember getRegionMember(String type, String name){ |
||||||
|
return this.regionMembers.stream().filter(regionMember -> regionMember.getMemberType().equals(type) && regionMember.getName().equals(name)).findFirst().orElse(null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isInside(int x, int y, int z) { |
||||||
|
return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean envelops(Location loc1, Location loc2) { |
||||||
|
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX()); |
||||||
|
int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()); |
||||||
|
int minY = Math.min(loc1.getBlockY(), loc2.getBlockY()); |
||||||
|
int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()); |
||||||
|
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); |
||||||
|
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); |
||||||
|
|
||||||
|
return this.x1 <= minX && this.x2 >= maxX && |
||||||
|
this.y1 <= minY && this.y2 >= maxY && |
||||||
|
this.z1 <= minZ && this.z2 >= maxZ; |
||||||
|
} |
||||||
|
|
||||||
|
public static Region findById(int id) { |
||||||
|
try { |
||||||
|
return getDao().queryForId(id); |
||||||
|
} catch (Exception e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void cacheRegions(String island) { |
||||||
|
try { |
||||||
|
List<Region> regions = getDao().queryBuilder() |
||||||
|
.where() |
||||||
|
.eq("island", island) |
||||||
|
.query(); |
||||||
|
cache.put(island, regions); |
||||||
|
} catch (Exception e) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static Region findRegion(Location location){ |
||||||
|
return findRegion(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld().getName()); |
||||||
|
} |
||||||
|
|
||||||
|
public static Region findRegion(int x, int y, int z, String island) { |
||||||
|
|
||||||
|
Region region = null; |
||||||
|
int highestType = -2; |
||||||
|
|
||||||
|
if (!cache.containsKey(island)) { |
||||||
|
cacheRegions(island); |
||||||
|
} |
||||||
|
|
||||||
|
for (Region cachedRegion : cache.get(island)) { |
||||||
|
if (!cachedRegion.isInside(x, y, z)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (highestType >= cachedRegion.getLevel()){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
region = cachedRegion; |
||||||
|
} |
||||||
|
|
||||||
|
return region; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void changeBoundaries(int x1, int y1, int z1, int x2, int y2, int z2){ |
||||||
|
this.x1 = Math.min(x1, x2); |
||||||
|
this.y1 = Math.min(y1, y2); |
||||||
|
this.x2 = Math.max(x1, x2); |
||||||
|
this.y2 = Math.max(y1, y2); |
||||||
|
this.z1 = Math.min(z1, z2); |
||||||
|
this.z2 = Math.max(z1, z2); |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup createDefaultGroupsAndReturnOwner(){ |
||||||
|
String ownerDisplayName = LangManager.getString("region.permission-groups.owner.name"); |
||||||
|
String ownerDescription = LangManager.getString("region.permission-groups.owner.description"); |
||||||
|
PermissionGroup owner = new PermissionGroup(this, "owner", ownerDisplayName, ownerDescription, Material.RED_CONCRETE, false, false, 101, 2147483647); |
||||||
|
owner.save(); |
||||||
|
|
||||||
|
String adminDisplayName = LangManager.getString("region.permission-groups.admin.name"); |
||||||
|
String adminDescription = LangManager.getString("region.permission-groups.admin.description"); |
||||||
|
PermissionGroup admin = new PermissionGroup(this, "admin", adminDisplayName, adminDescription, Material.YELLOW_CONCRETE, true, true, 90, 2147482623); |
||||||
|
admin.save(); |
||||||
|
|
||||||
|
String memberDisplayName = LangManager.getString("region.permission-groups.member.name"); |
||||||
|
String memberDescription = LangManager.getString("region.permission-groups.member.description"); |
||||||
|
PermissionGroup member = new PermissionGroup(this, "member", memberDisplayName, memberDescription, Material.GREEN_CONCRETE, true, true, 10, 2095231); |
||||||
|
member.save(); |
||||||
|
|
||||||
|
String defaultDisplayName = LangManager.getString("region.permission-groups.default"); |
||||||
|
String defaultDescription = LangManager.getString("region.permission-groups.default.description"); |
||||||
|
PermissionGroup defaultGroup = new PermissionGroup(this, "default", defaultDisplayName, defaultDescription, Material.GRAY_CONCRETE, true, false, 0,96); |
||||||
|
defaultGroup.save(); |
||||||
|
|
||||||
|
return owner; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void delete() { |
||||||
|
try { |
||||||
|
getDao().delete(this); |
||||||
|
cache.get(this.island).remove(this); |
||||||
|
Dao<PermissionGroup, Integer> permissionGroupDao = PermissionGroup.getDao(); |
||||||
|
Dao<RegionMember, Integer> regionMemberDao = RegionMember.getDao(); |
||||||
|
|
||||||
|
DeleteBuilder<PermissionGroup, Integer> groupDeleteBuilder = permissionGroupDao.deleteBuilder(); |
||||||
|
groupDeleteBuilder.where().eq("region_id", this.id); |
||||||
|
groupDeleteBuilder.delete(); |
||||||
|
|
||||||
|
DeleteBuilder<RegionMember, Integer> memberDeleteBuilder= regionMemberDao.deleteBuilder(); |
||||||
|
memberDeleteBuilder.where().eq("region_id", this.id); |
||||||
|
memberDeleteBuilder.delete(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void addPermissionGroup(String name, int weight, Material icon, String displayName, String description, int permissionsNumber) { |
||||||
|
PermissionGroup group = new PermissionGroup(this, name, displayName, description, icon, true, true, weight, permissionsNumber); |
||||||
|
group.save(); |
||||||
|
} |
||||||
|
|
||||||
|
public void transferOwnership(Player oldOwner, Player newOwner) { |
||||||
|
removeRegionMember(oldOwner); |
||||||
|
addRegionMember(newOwner, this.getPermissionGroup("owner")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,90 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.objects; |
||||||
|
|
||||||
|
import com.j256.ormlite.dao.Dao; |
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "region_members") |
||||||
|
public class RegionMember { |
||||||
|
|
||||||
|
public static Dao<RegionMember, Integer> dao; |
||||||
|
|
||||||
|
public static void setDao(Dao<RegionMember, Integer> dao) { |
||||||
|
RegionMember.dao = dao; |
||||||
|
} |
||||||
|
|
||||||
|
public static Dao<RegionMember, Integer> getDao() { |
||||||
|
return dao; |
||||||
|
} |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(foreign = true, foreignAutoRefresh = true) |
||||||
|
private Region region; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "member_type", canBeNull = false) |
||||||
|
private String memberType; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "member_name", canBeNull = false) |
||||||
|
private String memberName; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "permission_group", foreign = true, foreignAutoRefresh = true,canBeNull = false) |
||||||
|
private PermissionGroup permissionGroup; |
||||||
|
|
||||||
|
public RegionMember(){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public RegionMember(Region region, String membertype, String memberName, PermissionGroup permissionGroup){ |
||||||
|
this.region = region; |
||||||
|
this.memberType = membertype; |
||||||
|
this.memberName = memberName; |
||||||
|
this.permissionGroup = permissionGroup; |
||||||
|
} |
||||||
|
|
||||||
|
public Region getRegion() { |
||||||
|
return region; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMemberType() { |
||||||
|
return memberType; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return memberName; |
||||||
|
} |
||||||
|
|
||||||
|
public PermissionGroup getPermissionGroup() { |
||||||
|
return permissionGroup; |
||||||
|
} |
||||||
|
|
||||||
|
public void setPermissionGroup(PermissionGroup permissionGroup) { |
||||||
|
this.permissionGroup = permissionGroup; |
||||||
|
save(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasPermission(Permission permission){ |
||||||
|
return getPermissionGroup().hasPermission(permission); |
||||||
|
} |
||||||
|
|
||||||
|
public void save(){ |
||||||
|
try { |
||||||
|
getDao().createOrUpdate(this); |
||||||
|
region.dropCache(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void delete(){ |
||||||
|
try { |
||||||
|
getDao().delete(this); |
||||||
|
region.dropCache(); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.objects; |
||||||
|
|
||||||
|
public enum Status { |
||||||
|
OK, |
||||||
|
INVALID_SELECTION, |
||||||
|
NO_PERMISSION, |
||||||
|
NO_SELECTION, |
||||||
|
REGION_NOT_ENVELOPS, |
||||||
|
NOT_EXIST, |
||||||
|
PLAYER_NOT_ON_ISLAND, |
||||||
|
NOT_EXIST_GROUP, |
||||||
|
NOT_EXIST_PERMISSION, |
||||||
|
ALREADY_MEMBER, |
||||||
|
NOT_MEMBER, ALREADY_EXISTS, |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,448 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.regions; |
||||||
|
|
||||||
|
import com.j256.ormlite.stmt.QueryBuilder; |
||||||
|
import com.mojang.brigadier.arguments.IntegerArgumentType; |
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType; |
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder; |
||||||
|
import com.mojang.brigadier.context.CommandContext; |
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException; |
||||||
|
import com.mojang.brigadier.suggestion.Suggestions; |
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder; |
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack; |
||||||
|
import io.papermc.paper.command.brigadier.Commands; |
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes; |
||||||
|
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.LangManager; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.Replace; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Permission; |
||||||
|
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.List; |
||||||
|
import java.util.concurrent.CompletableFuture; |
||||||
|
|
||||||
|
public class RegionCommand { |
||||||
|
|
||||||
|
public static LiteralArgumentBuilder<CommandSourceStack> command(){ |
||||||
|
LiteralArgumentBuilder<CommandSourceStack> confirm = Commands.literal("confirm"); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, PlayerSelectorArgumentResolver> playerArgument = Commands.argument("player", ArgumentTypes.player()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> memberArgument = Commands.argument("member", StringArgumentType.word()).suggests(RegionCommand::memberSuggestions); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> groupArgument = Commands.argument("group", StringArgumentType.word()).suggests(RegionCommand::memberGroupSuggestions); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> nameArgument = Commands.argument("name", StringArgumentType.word()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, Integer> weightArgument = Commands.argument("weight", IntegerArgumentType.integer()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, ItemStack> iconArgument = Commands.argument("icon", ArgumentTypes.itemStack()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> displayNameArgument = Commands.argument("display-name", StringArgumentType.string()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> descriptionArgument = Commands.argument("description", StringArgumentType.greedyString()); |
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> permissionArgument = Commands.argument("permission", StringArgumentType.word()).suggests(RegionCommand::permissionSuggestions); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> create = Commands.literal("create") |
||||||
|
.executes(RegionCommand::create); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> delete = Commands.literal("delete") |
||||||
|
.executes(RegionCommand::delete) |
||||||
|
.then(confirm.executes(RegionCommand::delete)); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> addMember = Commands.literal("add") |
||||||
|
.then(playerArgument.then(groupArgument.executes(RegionCommand::addMember))); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> removeMember = Commands.literal("remove") |
||||||
|
.then(memberArgument.executes(RegionCommand::removeMember)); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> member = Commands.literal("member") |
||||||
|
.then(addMember) |
||||||
|
.then(removeMember); |
||||||
|
|
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> groupCreate = Commands.literal("create") |
||||||
|
.then(nameArgument |
||||||
|
.then(weightArgument |
||||||
|
.then(iconArgument |
||||||
|
.then(displayNameArgument |
||||||
|
.then(descriptionArgument |
||||||
|
.executes(RegionCommand::createGroup)))))); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> groupRemove = Commands.literal("remove") |
||||||
|
.executes(RegionCommand::removeGroup); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> addPermission = Commands.literal("add-permission") |
||||||
|
.then(permissionArgument.executes(RegionCommand::addPermission)); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> removePermission = Commands.literal("remove-permission") |
||||||
|
.then(permissionArgument.executes(RegionCommand::removePermission)); |
||||||
|
|
||||||
|
Commands.literal("transfer-ownership").then(playerArgument |
||||||
|
.executes(RegionCommand::transferOwnership) |
||||||
|
.then(confirm.executes(RegionCommand::transferOwnership))); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> changeIcon = Commands.literal("change-icon") |
||||||
|
.then(iconArgument.executes(RegionCommand::changeIcon)); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> changeDisplayName = Commands.literal("change-display-name") |
||||||
|
.then(displayNameArgument.executes(RegionCommand::changeDisplayName)); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> changeDescription = Commands.literal("change-description") |
||||||
|
.then(descriptionArgument.executes(RegionCommand::changeDescription)); |
||||||
|
|
||||||
|
RequiredArgumentBuilder<CommandSourceStack, String> groupEdit = nameArgument.suggests(RegionCommand::memberGroupSuggestions) |
||||||
|
.then(groupRemove) |
||||||
|
.then(addPermission) |
||||||
|
.then(removePermission) |
||||||
|
.then(changeIcon) |
||||||
|
.then(changeDisplayName) |
||||||
|
.then(changeDescription); |
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> group = Commands.literal("group") |
||||||
|
.then(groupCreate) |
||||||
|
.then(groupEdit); |
||||||
|
|
||||||
|
|
||||||
|
RequiredArgumentBuilder<CommandSourceStack, Integer> regionEdits = Commands.argument("id", IntegerArgumentType.integer(1, 2147483647)) |
||||||
|
.suggests(RegionCommand::regionIdSuggestions) |
||||||
|
.then(delete) |
||||||
|
.then(member) |
||||||
|
.then(group); |
||||||
|
|
||||||
|
return Commands.literal("region") |
||||||
|
.requires(c -> c.getSender() instanceof Player) |
||||||
|
.then(regionEdits) |
||||||
|
.then(create); |
||||||
|
} |
||||||
|
|
||||||
|
private static int changeIcon(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
ItemStack itemStack = context.getArgument("icon", ItemStack.class); |
||||||
|
|
||||||
|
switch (RegionManager.changeGroupIconSafely(id, name, itemStack, player)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.icon-changed"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int changeDescription(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
String description = context.getArgument("description", String.class); |
||||||
|
|
||||||
|
switch (RegionManager.changeGroupDescriptionSafely(id, name, description, player)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.description-changed"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int changeDisplayName(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
String displayName = context.getArgument("display-name", String.class); |
||||||
|
|
||||||
|
switch (RegionManager.changeGroupDisplayNameSafely(id, name, displayName, player)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.display-name-changed"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int transferOwnership(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
|
||||||
|
PlayerSelectorArgumentResolver newOwnerResolver = context.getArgument("new-owner", PlayerSelectorArgumentResolver.class); |
||||||
|
Player newOwner; |
||||||
|
try { |
||||||
|
newOwner = newOwnerResolver.resolve(context.getSource()).getFirst(); |
||||||
|
} catch (CommandSyntaxException e) { |
||||||
|
LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
if (!context.getInput().endsWith("confirm")){ |
||||||
|
LangManager.send(player, "region.command.confirm-warning.transfer-ownership", |
||||||
|
new Replace("id", String.valueOf(id)), |
||||||
|
new Replace("name", newOwner.getName())); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
switch (RegionManager.transferOwnershipSafely(id, player, newOwner)){ |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case OK -> LangManager.send(player, "region.command.transferred-ownership"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int removePermission(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
String permission = context.getArgument("permission", String.class); |
||||||
|
|
||||||
|
switch (RegionManager.removeGroupPermissionSafely(player, id, name, permission)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NOT_EXIST_PERMISSION -> LangManager.send(player, "region.command.error.not-exist-permission"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.removed-permission"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int addPermission(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
String permission = context.getArgument("permission", String.class); |
||||||
|
|
||||||
|
switch (RegionManager.addGroupPermissionSafely(player, id, name, permission)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NOT_EXIST_PERMISSION -> LangManager.send(player, "region.command.error.not-exist-permission"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.added-permission"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int removeGroup(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
|
||||||
|
switch (RegionManager.removeRegionGroupSafely(id, player, name)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(player, "region.command.error.not-exist-group"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case OK -> LangManager.send(player, "region.command.deleted-group"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int createGroup(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String name = context.getArgument("name", String.class); |
||||||
|
int weight = context.getArgument("weight", Integer.class); |
||||||
|
ItemStack icon = context.getArgument("icon", ItemStack.class); |
||||||
|
String displayName = context.getArgument("display-name", String.class); |
||||||
|
String description = context.getArgument("description", String.class); |
||||||
|
|
||||||
|
|
||||||
|
switch (RegionManager.addRegionGroupSafely(id, player, name, weight, icon, displayName, description)){ |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case ALREADY_EXISTS -> LangManager.send(player, "region.command.error.already-exist"); |
||||||
|
case OK -> LangManager.send(player, "region.command.created-group"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static CompletableFuture<Suggestions> permissionSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder){ |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
|
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
Region region = Region.findById(id); |
||||||
|
|
||||||
|
if (region == null){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
String remaining = builder.getRemaining().toUpperCase(); |
||||||
|
|
||||||
|
for (Permission permission : Permission.values()){ |
||||||
|
if (permission.name().contains(remaining) && region.hasPermission(player, permission)){ |
||||||
|
|
||||||
|
builder.suggest(permission.name()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
private static CompletableFuture<Suggestions> regionIdSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
Region region = Region.findRegion(player.getLocation()); |
||||||
|
|
||||||
|
if (region != null){ |
||||||
|
builder.suggest(region.getId()); |
||||||
|
} |
||||||
|
|
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
private static CompletableFuture<Suggestions> memberGroupSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder){ |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
Region region = Region.findById(id); |
||||||
|
|
||||||
|
if (region == null){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
if (!region.hasPermission(player, Permission.MANAGE_MEMBERS)){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
RegionMember regionMember = region.getRegionMember(player); |
||||||
|
|
||||||
|
if (regionMember == null){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
PermissionGroup senderGroup = regionMember.getPermissionGroup(); |
||||||
|
|
||||||
|
if (senderGroup == null){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
QueryBuilder<PermissionGroup, Integer> queryBuilder = PermissionGroup.getDao().queryBuilder(); |
||||||
|
String remaining = builder.getRemaining().toUpperCase(); |
||||||
|
|
||||||
|
try { |
||||||
|
queryBuilder.selectColumns("name"); |
||||||
|
queryBuilder.where().eq("region_id", id).and().lt("weight", senderGroup.getWeight()); |
||||||
|
List<PermissionGroup> permissionGroups = queryBuilder.query(); |
||||||
|
for (PermissionGroup permissionGroup : permissionGroups){ |
||||||
|
if (permissionGroup.getName().contains(remaining)){ |
||||||
|
builder.suggest(permissionGroup.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static CompletableFuture<Suggestions> memberSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder){ |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
Region region = Region.findById(id); |
||||||
|
|
||||||
|
if (region == null){ |
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
QueryBuilder<RegionMember, Integer> queryBuilder = RegionMember.getDao().queryBuilder(); |
||||||
|
String remaining = builder.getRemaining().toUpperCase(); |
||||||
|
|
||||||
|
try { |
||||||
|
queryBuilder.selectColumns("member_name"); |
||||||
|
queryBuilder.where().eq("region_id", id); |
||||||
|
List<RegionMember> regionMembers = queryBuilder.query(); |
||||||
|
for (RegionMember member : regionMembers){ |
||||||
|
if (member.getName().toUpperCase().contains(remaining)){ |
||||||
|
builder.suggest(member.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
return builder.buildFuture(); |
||||||
|
} |
||||||
|
|
||||||
|
private static int removeMember(CommandContext<CommandSourceStack> context) { |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
Player senderPlayer = (Player) context.getSource().getSender(); |
||||||
|
String memberToRemove = context.getArgument("member", String.class); |
||||||
|
|
||||||
|
|
||||||
|
switch (RegionManager.removeMemberSafely(id, memberToRemove, senderPlayer)){ |
||||||
|
case OK -> LangManager.send(senderPlayer, "region.command.removed-member"); |
||||||
|
case NOT_EXIST -> LangManager.send(senderPlayer, "region.command.error.not-exist"); |
||||||
|
case NO_PERMISSION -> LangManager.send(senderPlayer, "region.command.error.no-permission"); |
||||||
|
case NOT_MEMBER -> LangManager.send(senderPlayer, "region.command.error.not-member"); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static int addMember(CommandContext<CommandSourceStack> context){ |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
String groupName = context.getArgument("group", String.class); |
||||||
|
Player senderPlayer = (Player) context.getSource().getSender(); |
||||||
|
PlayerSelectorArgumentResolver playerSelectorArgumentResolver = context.getArgument("player", PlayerSelectorArgumentResolver.class); |
||||||
|
try { |
||||||
|
Player playerToAdd = playerSelectorArgumentResolver.resolve(context.getSource()).getFirst(); |
||||||
|
|
||||||
|
switch (RegionManager.addMemberSafely(id, playerToAdd, senderPlayer, groupName)){ |
||||||
|
case OK -> LangManager.send(senderPlayer, "region.command.added-member"); |
||||||
|
case NOT_EXIST -> LangManager.send(senderPlayer, "region.command.error.not-exist"); |
||||||
|
case NO_PERMISSION -> LangManager.send(senderPlayer, "region.command.error.no-permission"); |
||||||
|
case NOT_EXIST_GROUP -> LangManager.send(senderPlayer, "region.command.error.not-exist-group"); |
||||||
|
case PLAYER_NOT_ON_ISLAND -> LangManager.send(senderPlayer, "region.command.error.player-not-on-island"); |
||||||
|
case ALREADY_MEMBER -> LangManager.send(senderPlayer, "region.command.error.already-member"); |
||||||
|
} |
||||||
|
} catch (CommandSyntaxException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int delete(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
int id = context.getArgument("id", Integer.class); |
||||||
|
|
||||||
|
if (!context.getInput().endsWith("confirm")){ |
||||||
|
LangManager.send(player, "region.command.confirm-warning.delete", new Replace("id", String.valueOf(id))); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
switch (RegionManager.deleteRegionSafely(id, player)){ |
||||||
|
case OK -> LangManager.send(player, "region.command.deleted"); |
||||||
|
case NOT_EXIST -> LangManager.send(player, "region.command.error.not-exist"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static int create(CommandContext<CommandSourceStack> context) { |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
|
||||||
|
switch (RegionManager.createRegionSafely(player)){ |
||||||
|
case OK -> LangManager.send(player, "region.command.created"); |
||||||
|
case NO_SELECTION -> LangManager.send(player, "region.command.error.no-selection"); |
||||||
|
case NO_PERMISSION -> LangManager.send(player, "region.command.error.no-permission"); |
||||||
|
case INVALID_SELECTION -> LangManager.send(player, "region.command.error.invalid-selection"); |
||||||
|
case REGION_NOT_ENVELOPS -> LangManager.send(player, "region.command.error.region-not-envelops"); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,185 @@ |
|||||||
|
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.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 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 java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class RegionMenu { |
||||||
|
public static ChestGui regionGui(Player player, Region region){ |
||||||
|
|
||||||
|
return buildGui(player, region); |
||||||
|
} |
||||||
|
|
||||||
|
private static ChestGui buildGui(Player player, Region region){ |
||||||
|
String title; |
||||||
|
int regionLevel = region.getLevel(); |
||||||
|
|
||||||
|
if (regionLevel == -1){ |
||||||
|
title = LangManager.getLegacyString("gui.region.title-island"); |
||||||
|
} else { |
||||||
|
title = LangManager.getLegacyString("gui.region.title"); |
||||||
|
} |
||||||
|
|
||||||
|
ChestGui gui = new ChestGui(2, title); |
||||||
|
OutlinePane outlinePane = new OutlinePane(0, 0, 9, 2); |
||||||
|
|
||||||
|
addIslandSettings(outlinePane, player, region); |
||||||
|
addMemberManagement(outlinePane, player, region); |
||||||
|
|
||||||
|
|
||||||
|
gui.addPane(outlinePane); |
||||||
|
return gui; |
||||||
|
} |
||||||
|
|
||||||
|
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 addMemberSelectGroup(Player player, Region region, Player selectedPlayer){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
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