Skip to content

Commit

Permalink
Update ChestShopSign validation method
Browse files Browse the repository at this point in the history
The validation method "isValid" in the ChestShopSign class has been replaced with "isLegacyValid". Changes were made across multiple files where this method is used. Additionally, import sections were tidied in several classes, grouping related imports together.
  • Loading branch information
Feli499 committed Dec 31, 2023
1 parent 2a0dbea commit 65cb039
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 227 deletions.
Expand Up @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isValid(signBlock)) {
if (signBlock == null || !ChestShopSign.isLegacyValid(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Expand Down
Expand Up @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isValid(signBlock)) {
if (signBlock == null || !ChestShopSign.isLegacyValid(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/Acrobot/ChestShop/Commands/SetAmount.java
@@ -1,11 +1,7 @@
package com.Acrobot.ChestShop.Commands;

import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import static com.Acrobot.ChestShop.Permission.ADMIN;

import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
Expand All @@ -15,6 +11,11 @@
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.util.RayTraceResult;

import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;

public class SetAmount implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Expand All @@ -33,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isValid(signBlock)) {
if (signBlock == null || !ChestShopSign.isLegacyValid(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/Acrobot/ChestShop/Commands/SetItem.java
@@ -1,10 +1,7 @@
package com.Acrobot.ChestShop.Commands;

import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import static com.Acrobot.ChestShop.Permission.ADMIN;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;

import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
Expand All @@ -14,6 +11,11 @@
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.util.RayTraceResult;

import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;

public class SetItem implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Expand All @@ -32,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isValid(signBlock)) {
if (signBlock == null || !ChestShopSign.isLegacyValid(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/Acrobot/ChestShop/Commands/SetPrice.java
@@ -1,11 +1,7 @@
package com.Acrobot.ChestShop.Commands;

import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import static com.Acrobot.ChestShop.Permission.ADMIN;

import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
Expand All @@ -15,6 +11,11 @@
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.util.RayTraceResult;

import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;

public class SetPrice implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Expand All @@ -33,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isValid(signBlock)) {
if (signBlock == null || !ChestShopSign.isLegacyValid(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ public static void onChestPlace(BlockPlaceEvent event) {
public static void onPlaceAgainstSign(BlockPlaceEvent event) {
Block against = event.getBlockAgainst();

if (!ChestShopSign.isValid(against)) {
if (!ChestShopSign.isLegacyValid(against)) {
return;
}

Expand Down
Expand Up @@ -52,7 +52,7 @@ public static void onSign(BlockPhysicsEvent event) {
Sign sign = (Sign) block.getState();
Block attachedBlock = BlockUtil.getAttachedBlock(sign);

if (attachedBlock.getType() == Material.AIR && ChestShopSign.isValid(sign)) {
if (attachedBlock.getType() == Material.AIR && ChestShopSign.isLegacyValid(sign)) {
if (!block.hasMetadata(METADATA_NAME)) {
return;
}
Expand All @@ -70,7 +70,7 @@ public static void onSignBreak(BlockBreakEvent event) {

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public static void onBrokenSign(BlockBreakEvent event) {
if (ChestShopSign.isValid(event.getBlock())) {
if (ChestShopSign.isLegacyValid(event.getBlock())) {
sendShopDestroyedEvent((Sign) event.getBlock().getState(), event.getPlayer());
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public static boolean canBlockBeBroken(Block block, Player breaker) {

for (Sign sign : attachedSigns) {

if (!canBeBroken || !ChestShopSign.isValid(sign)) {
if (!canBeBroken || !ChestShopSign.isLegacyValid(sign)) {
continue;
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ public class SignCreate implements Listener {
public static void onSignChange(SignChangeEvent event) {
Block signBlock = event.getBlock();
if (event.getSide() == Side.BACK) {
if (ChestShopSign.isValid(signBlock)) {
if (ChestShopSign.isLegacyValid(signBlock)) {
event.setCancelled(true);
}
return;
Expand Down
Expand Up @@ -84,7 +84,7 @@ public static void onInteract(PlayerInteractEvent event) {

Sign sign = (Sign) block.getState();

if (!ChestShopSign.isValid(sign)) {
if (!ChestShopSign.isLegacyValid(sign)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java
Expand Up @@ -41,7 +41,7 @@ public static boolean canAccess(Player player, Block block) {
if (isSign(block)) {
Sign sign = (Sign) block.getState();

if (!ChestShopSign.isValid(sign)) {
if (!ChestShopSign.isLegacyValid(sign)) {
return true;
}

Expand Down
100 changes: 100 additions & 0 deletions src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java
@@ -0,0 +1,100 @@
package com.Acrobot.ChestShop.Signs;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;

public class ChestShopMetaData implements ConfigurationSerializable {

private UUID owner;
private Set<UUID> accessors;

private int quantity;

private double buyPrice;

private double sellPrice;

private ItemStack itemStack;

public ChestShopMetaData(UUID owner, int quantity, double sellPrice, double buyPrice, ItemStack itemStack) {
this(owner, quantity, sellPrice, buyPrice, itemStack, new HashSet<>());
}

private ChestShopMetaData(UUID owner, int quantity, double sellPrice, double buyPrice, ItemStack itemStack, Set<UUID> accessors) {
this.owner = owner;
this.quantity = quantity;
this.sellPrice = sellPrice;
this.buyPrice = buyPrice;
this.itemStack = itemStack;
this.accessors = accessors;
}

public HashSet<UUID> getAccessors() {
return new HashSet<>(accessors);
}

public void addAccessor(UUID uuid) {
accessors.add(uuid);
}

public void removeAccessor(UUID uuid) {
accessors.remove(uuid);
}

public boolean isAccessor(UUID uuid) {
return accessors.contains(uuid);
}

public UUID getOwner() {
return owner;
}

public boolean isOwner(UUID uuid) {
return owner.equals(uuid);
}

public int getQuantity() {
return quantity;
}

public double getBuyPrice() {
return buyPrice;
}

public double getSellPrice() {
return sellPrice;
}

public ItemStack getItemStack() {
return itemStack;
}

@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("owner", owner);
data.put("accessors", accessors);
data.put("amount", quantity);
data.put("buyPrice", buyPrice);
data.put("sellPrice", sellPrice);
data.put("itemStack", itemStack.serialize());
return data;
}

public static ChestShopMetaData deserialize(Map<String, Object> map) {

UUID owner = (UUID) map.get("owner");
int amount = (int) map.get("amount");
double sellPrice = (double) map.get("sellPrice");
double buyPrice = (double) map.get("buyPrice");
ItemStack itemStack = (ItemStack) map.get("itemStack");
Set<UUID> accessors = new HashSet<>((HashSet<UUID>) map.get("accessors"));
return new ChestShopMetaData(owner, amount, sellPrice, buyPrice, itemStack, accessors);
}
}

0 comments on commit 65cb039

Please sign in to comment.