Skip to content

Commit

Permalink
Updated accessor methods to use UUIDs
Browse files Browse the repository at this point in the history
Updated the ChestShopSign's accessor methods in RemoveAccessor.java and AddAccessor.java to use UUIDs instead of player names for better tracking and handling of user identities. The changes include the addition of UUID import, new error messages in Configuration/Messages.java, and modification in getAccessors method in ChestShopSign.java.
  • Loading branch information
Feli499 committed Dec 29, 2023
1 parent d9b70bd commit 203fef8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/Acrobot/ChestShop/Commands/AddAccessor.java
Expand Up @@ -2,7 +2,8 @@

import static com.Acrobot.ChestShop.Permission.ADMIN;

import org.bukkit.Bukkit;
import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
Expand All @@ -14,6 +15,7 @@
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;

/**
* @author Acrobot
Expand Down Expand Up @@ -53,12 +55,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

String playerName = args[0];
Player newAccessor = Bukkit.getPlayer(playerName);
UUID newAccessor = NameManager.getUUIDFor(playerName);
if (newAccessor == null) {
sender.sendMessage(Messages.prefix(Messages.UNKNOWN_PLAYER));
return true;
}

if (ChestShopSign.isAccessor(newAccessor, sign)) {
sender.sendMessage(Messages.prefix(Messages.ACCESSOR_ALREADY_ADDED));
return true;
}

ChestShopSign.addAccessor(newAccessor, sign);
sender.sendMessage(Messages.prefix(Messages.NEW_ACCESSOR_ADDED));
return true;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/Acrobot/ChestShop/Commands/RemoveAccessor.java
Expand Up @@ -2,7 +2,8 @@

import static com.Acrobot.ChestShop.Permission.ADMIN;

import org.bukkit.Bukkit;
import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
Expand All @@ -14,6 +15,7 @@
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;

/**
* @author Acrobot
Expand Down Expand Up @@ -53,12 +55,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

String playerName = args[0];
Player accessorToRemove = Bukkit.getPlayer(playerName);
UUID accessorToRemove = NameManager.getUUIDFor(playerName);
if (accessorToRemove == null) {
sender.sendMessage(Messages.prefix(Messages.UNKNOWN_PLAYER));
return true;
}

if (!ChestShopSign.isAccessor(accessorToRemove, sign)) {
sender.sendMessage(Messages.prefix(Messages.ACCESSOR_NOT_ADDED));
return true;
}

ChestShopSign.removeAccessor(accessorToRemove, sign);
sender.sendMessage(Messages.prefix(Messages.ACCESSOR_REMOVED));
return true;
Expand Down
Expand Up @@ -90,7 +90,9 @@ public class Messages {
@PrecededBySpace
public static final String UNKNOWN_PLAYER = "Player not found.";
public static final String NEW_ACCESSOR_ADDED = "New accessor added.";
public static final String ACCESSOR_REMOVED = "New accessor removed.";
public static final String ACCESSOR_ALREADY_ADDED = "Accessor already added.";
public static final String ACCESSOR_REMOVED = "Accessor removed.";
public static final String ACCESSOR_NOT_ADDED = "Player isn't a accessor.";

public static String prefix(String message) {
return PREFIX + message;
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java
Expand Up @@ -168,15 +168,20 @@ public static Collection<String> getAccessors(Sign sign) {
return new HashSet<>(Arrays.asList(split));
}

public static void addAccessor(OfflinePlayer player, Sign sign) {
public static void addAccessor(UUID player, Sign sign) {
Collection<String> accessors = getAccessors(sign);
accessors.add(player.getUniqueId().toString());
accessors.add(player.toString());
saveAccessors(accessors, sign);
}

public static void removeAccessor(OfflinePlayer player, Sign sign) {
public static boolean isAccessor(UUID player, Sign sign) {
Collection<String> accessors = getAccessors(sign);
accessors.remove(player.getUniqueId().toString());
return accessors.contains(player.toString());
}

public static void removeAccessor(UUID player, Sign sign) {
Collection<String> accessors = getAccessors(sign);
accessors.remove(player.toString());
saveAccessors(accessors, sign);
}

Expand Down

0 comments on commit 203fef8

Please sign in to comment.