Skip to content

Commit 38e2775

Browse files
committed
Quick fix for issue where people who had homes with capital letters were unable to delete them
1 parent 470623b commit 38e2775

File tree

6 files changed

+50
-17
lines changed

6 files changed

+50
-17
lines changed

src/main/java/simplexity/simplehomes/commands/CommandUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class CommandUtils {
2222

2323
public static Home getHomeFromList(List<Home> homes, String homeName) {
2424
for (Home home : homes) {
25-
if (home.name().equalsIgnoreCase(homeName)) {
25+
if (home.name().equals(homeName)) {
2626
return home;
2727
}
2828
}
@@ -41,7 +41,6 @@ public static int maxHomesPermission(Player player) {
4141
int maxHomes = 0;
4242
for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
4343
String permission = pai.getPermission();
44-
if (!pai.getValue()) continue; //if the permission is set false, skip it
4544
if (!pai.getValue() || !permission.startsWith(COUNT_BASE))
4645
continue; // if the permission is set false, if it isn't ours, skip it
4746
permission = permission.replace(COUNT_BASE, ""); //

src/main/java/simplexity/simplehomes/commands/DeleteHome.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
3636
Placeholder.parsed("command", "/delhome"));
3737
return false;
3838
}
39-
String homeName = args[0].toLowerCase();
39+
String homeName = args[0];
4040
Home homeRequested = CommandUtils.getHomeFromList(playerHomesList, homeName);
41+
if (homeRequested == null) {
42+
player.sendRichMessage(
43+
LocaleHandler.getInstance().getHomeNotFound(),
44+
Placeholder.parsed("name", homeName));
45+
}
4146
if (!shouldDelete(homeRequested, player, homeName)) return false;
4247
//Need to parse the message before deleting the home otherwise there's no home to send into the method. At least that's what happened originally.
4348
//Probably had to do with how I was originally putting it in but whatever, I'm doing it here now.
44-
Component parsedHomeDeleteMessage = LocaleHandler.getInstance().locationResolver(homeRequested,
49+
Component parsedHomeDeleteMessage = LocaleHandler.getInstance().homeComponent(homeRequested,
4550
LocaleHandler.getInstance().getHomeDeleted());
4651
Cache.getInstance().removeHomeByName(player.getUniqueId(), homeName);
4752
player.sendMessage(parsedHomeDeleteMessage);

src/main/java/simplexity/simplehomes/commands/HomeList.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import net.kyori.adventure.text.Component;
44
import net.kyori.adventure.text.minimessage.MiniMessage;
55
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
6+
import org.bukkit.Location;
67
import org.bukkit.command.Command;
78
import org.bukkit.command.CommandExecutor;
89
import org.bukkit.command.CommandSender;
910
import org.bukkit.entity.Player;
1011
import org.jetbrains.annotations.NotNull;
1112
import simplexity.simplehomes.Home;
1213
import simplexity.simplehomes.SimpleHomes;
14+
import simplexity.simplehomes.configs.ConfigHandler;
1315
import simplexity.simplehomes.configs.LocaleHandler;
1416
import simplexity.simplehomes.saving.Cache;
1517

@@ -33,12 +35,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
3335
Placeholder.parsed("command", "/homelist"));
3436
return false;
3537
}
36-
Component listMessage = createHomesListMessage(playerHomes);
38+
Home bedHome = null;
39+
Location potentialBedLocation = player.getPotentialBedLocation();
40+
if (potentialBedLocation != null) {
41+
bedHome = new Home(ConfigHandler.getInstance().getBedHomesName(), potentialBedLocation);
42+
}
43+
Component listMessage = createHomesListMessage(playerHomes, bedHome);
3744
player.sendMessage(listMessage);
3845
return true;
3946
}
4047

41-
private Component createHomesListMessage(List<Home> homesList) {
48+
private Component createHomesListMessage(List<Home> homesList, Home bedHome) {
4249
Component messageToSend = miniMessage.deserialize(LocaleHandler.getInstance().getListHeader());
4350
if (homesList.isEmpty()) {
4451
messageToSend = messageToSend
@@ -49,7 +56,12 @@ private Component createHomesListMessage(List<Home> homesList) {
4956
for (Home home : homesList) {
5057
messageToSend = messageToSend
5158
.appendNewline()
52-
.append(LocaleHandler.getInstance().locationResolver(home, LocaleHandler.getInstance().getListItem()));
59+
.append(LocaleHandler.getInstance().homeComponent(home, LocaleHandler.getInstance().getListItem()));
60+
}
61+
if (bedHome != null) {
62+
messageToSend = messageToSend
63+
.appendNewline()
64+
.append(LocaleHandler.getInstance().bedHomeComponent(bedHome, LocaleHandler.getInstance().getListItem()));
5365
}
5466
return messageToSend;
5567
}

src/main/java/simplexity/simplehomes/configs/LocaleHandler.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.configuration.InvalidConfigurationException;
77
import org.bukkit.configuration.file.FileConfiguration;
88
import org.bukkit.configuration.file.YamlConfiguration;
9+
import org.jetbrains.annotations.NotNull;
910
import simplexity.simplehomes.Home;
1011
import simplexity.simplehomes.SimpleHomes;
1112

@@ -24,7 +25,7 @@ public class LocaleHandler {
2425
//---------
2526
private String mustBePlayer, provideHomeName, homeAlreadyExists, homeNotFound, nullHome, cannotSetMoreHomes,
2627
cannotUseCommand, errorHasOccurred, noPermission;
27-
private String insertName, insertWorld, insertXLoc, insertYLoc, insertZLoc, insertOverride;
28+
private String insertName, insertWorld, insertXLoc, insertYLoc, insertZLoc, insertOverride, insertBedName;
2829
private String homeSet, homeDeleted, homeTeleported, pluginReloaded, listHeader, listItem, listNoHomes;
2930
private String blacklistedWarning, voidWarning, fireWarning, blocksWarning, lavaWarning, waterWarning;
3031
private String unsupportedDestructive, importHelp, importNotEnoughArgs, onlyConsole, cannotConfirm, timedOut, noValidPlugin,
@@ -63,6 +64,7 @@ public void loadLocale() {
6364
errorHasOccurred = localeConfig.getString("errors.error-has-occurred", "<red>An error has occurred while running this command. Please contact the server staff to let them know (-SimpleHomes Plugin)</red>");
6465
noPermission = localeConfig.getString("errors.no-permission", "<red>You do not have permission to use <value></red>");
6566
insertName = localeConfig.getString("inserts.name", "<yellow><name></yellow>");
67+
insertBedName = localeConfig.getString("inserts.bed-name", "<dark_gray><name></dark_gray>");
6668
insertWorld = localeConfig.getString("inserts.world", "<yellow><world></yellow>");
6769
insertXLoc = localeConfig.getString("inserts.x-loc", "<yellow><x-loc>x</yellow>,");
6870
insertYLoc = localeConfig.getString("inserts.y-loc", "<yellow><y-loc>y</yellow>,");
@@ -173,10 +175,7 @@ public String getListItem() {
173175
return listItem;
174176
}
175177

176-
public Component locationResolver(Home home, String message) {
177-
if (home == null) {
178-
return null;
179-
}
178+
public Component homeComponent(@NotNull Home home, String message) {
180179
Component nameComponent = miniMessage.deserialize(insertName,
181180
Placeholder.unparsed("name", home.name()));
182181
Component worldComponent = miniMessage.deserialize(insertWorld,
@@ -195,6 +194,25 @@ public Component locationResolver(Home home, String message) {
195194
Placeholder.component("z-loc", zComponent));
196195
}
197196

197+
public Component bedHomeComponent(@NotNull Home home, String message) {
198+
Component nameComponent = miniMessage.deserialize(insertBedName,
199+
Placeholder.unparsed("name", ConfigHandler.getInstance().getBedHomesName()));
200+
Component worldComponent = miniMessage.deserialize(insertWorld,
201+
Placeholder.unparsed("world", home.location().getWorld().getName()));
202+
Component xComponent = miniMessage.deserialize(insertXLoc,
203+
Placeholder.unparsed("x-loc", String.valueOf(home.location().getBlockX())));
204+
Component yComponent = miniMessage.deserialize(insertYLoc,
205+
Placeholder.unparsed("y-loc", String.valueOf(home.location().getBlockY())));
206+
Component zComponent = miniMessage.deserialize(insertZLoc,
207+
Placeholder.unparsed("z-loc", String.valueOf(home.location().getBlockZ())));
208+
return miniMessage.deserialize(message,
209+
Placeholder.component("name", nameComponent),
210+
Placeholder.component("world", worldComponent),
211+
Placeholder.component("x-loc", xComponent),
212+
Placeholder.component("y-loc", yComponent),
213+
Placeholder.component("z-loc", zComponent));
214+
}
215+
198216
public String getListNoHomes() {
199217
return listNoHomes;
200218
}
@@ -296,4 +314,7 @@ public String getNoPermission() {
296314
return noPermission;
297315
}
298316

317+
public String getInsertBedName() {
318+
return insertBedName;
319+
}
299320
}

src/main/java/simplexity/simplehomes/saving/Cache.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public static Cache getInstance() {
2424
private final HashMap<UUID, List<Home>> cachedHomes = new HashMap<>();
2525

2626
public List<Home> getPlayerHomes(UUID playerUuid) {
27-
// Get cached homes if they're already cached, and returned
2827
if (cachedHomes.containsKey(playerUuid)) return cachedHomes.get(playerUuid);
29-
// Otherwise, query the database, and cache the results, or create a blank array list and add it if there is no
30-
// results. Return the newly cached data.
3128
List<Home> savedHomes = SQLHandler.getInstance().getHomes(playerUuid);
3229
if (savedHomes == null || savedHomes.isEmpty()) savedHomes = new ArrayList<>();
3330
cachedHomes.put(playerUuid, savedHomes);
@@ -62,7 +59,7 @@ public void removePlayerFromCache(UUID playerUuid) {
6259
@SuppressWarnings("JavaExistingMethodCanBeUsed")
6360
private Home getHomeFromList(List<Home> homes, String homeName) {
6461
for (Home home : homes) {
65-
if (home.name().equalsIgnoreCase(homeName)) {
62+
if (home.name().equals(homeName)) {
6663
return home;
6764
}
6865
}

src/main/java/simplexity/simplehomes/saving/SQLHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public List<Home> getHomes(UUID uuid) {
9191
}
9292

9393
public void deleteHome(UUID uuid, String homeName) {
94-
// Prepare the SQL statement to check if the home exists
9594
String checkIfExistsQuery = "SELECT * FROM homes WHERE player_uuid = ? AND home_name = ?";
9695
try (PreparedStatement homeExists = getConnection().prepareStatement(checkIfExistsQuery)) {
9796
homeExists.setString(1, uuid.toString());

0 commit comments

Comments
 (0)