Skip to content

Commit

Permalink
Add 'setAdminshop' and 'setOwner' functions in ChestShopSign class
Browse files Browse the repository at this point in the history
Added 'setAdminshop' and 'setOwner' functions in ChestShopSign.java to handle shop ownership and status updates. These new utilities make it easier to manage shop signs by differentiating between admin and player-owned shops and by permitting the direct assignment of owners.
  • Loading branch information
Feli499 committed Dec 20, 2023
1 parent ce71e71 commit cb363ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
@@ -1,12 +1,5 @@
package com.Acrobot.ChestShop.Listeners.Block;

import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
Expand All @@ -15,6 +8,14 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;

import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;

/**
* @author Acrobot
*/
Expand Down Expand Up @@ -59,5 +60,10 @@ public static void onSignChange(SignChangeEvent event) {
for (byte i = 0; i < 4; ++i) {
signSide.setLine(i, "");
}

boolean isAdminShop = ChestShopSign.isAdminShopNameString(preEvent.getOwnerName());
ChestShopSign.setAdminshop(isAdminShop, sign);
if (!isAdminShop)
ChestShopSign.setOwner(postEvent.getPlayer().getUniqueId(), sign);
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java
Expand Up @@ -60,6 +60,10 @@ public static boolean isAdminShopNameString(String string) {
return string.replace(" ", "").equalsIgnoreCase(Properties.ADMIN_SHOP_NAME.replace(" ", ""));
}

public static void setAdminshop(boolean isAdminshop, Sign sign) {
sign.getPersistentDataContainer().set(ADMINSHOP_NAMESPACED_KEY, PersistentDataType.BOOLEAN, Boolean.valueOf(isAdminshop));
}

public static boolean isAdminShop(Sign sign) {

PersistentDataContainer persistentDataContainer = sign.getPersistentDataContainer();
Expand Down Expand Up @@ -123,7 +127,11 @@ public static boolean isOwner(OfflinePlayer player, Sign sign) {
return playerUUIDAsString.equals(owner);
}

public static String getOwner(Sign sign) {
public static void setOwner(UUID player, Sign sign) {
sign.getPersistentDataContainer().set(OWNER_NAMESPACED_KEY, PersistentDataType.STRING, player.toString());
}

private static String getOwner(Sign sign) {
return sign.getPersistentDataContainer().get(OWNER_NAMESPACED_KEY, PersistentDataType.STRING);
}

Expand Down

0 comments on commit cb363ec

Please sign in to comment.