mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Add ability to resolve unsafe positions by UUID where the identifier would otherwise be unsafe (#356)
This commit is contained in:
1 parent
4bd0244891
commit
3c18214016
26 files changed
+188
-60
No files matched your search
@@ -29,6 +29,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class Home extends SavedPosition {
|
||||
|
||||
public static final String IDENTIFIER_DELIMITER = ".";
|
||||
private final User owner;
|
||||
private boolean isPublic;
|
||||
|
||||
@@ -74,4 +75,17 @@ public class Home extends SavedPosition {
|
||||
public void setPublic(boolean aPublic) {
|
||||
isPublic = aPublic;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getSafeIdentifier() {
|
||||
return getOwner().getUsername() + IDENTIFIER_DELIMITER + super.getSafeIdentifier();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return getOwner().getUsername() + IDENTIFIER_DELIMITER + super.getIdentifier();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -79,10 +80,26 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier for this position. This is the name, unless the name contains
|
||||
* characters that are not allowed in a command argument, in which case it is the UUID.
|
||||
*
|
||||
* @return The identifier for this position
|
||||
*/
|
||||
@NotNull
|
||||
public String getSafeIdentifier() {
|
||||
return Locales.escapeText(getName()).equals(getName()) ? getName() : getUuid().toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
// Compare based on names for alphabetical sorting
|
||||
@Override
|
||||
public int compareTo(@NotNull SavedPosition o) {
|
||||
return this.getMeta().getName().compareTo(o.getMeta().getName());
|
||||
return this.getName().compareTo(o.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user