mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
fix: make User serializable by Gson
This commit is contained in:
5 files changed
+24
-14
No files matched your search
@@ -194,7 +194,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
||||
.teleporter(teleporter)
|
||||
.actions(actions)
|
||||
.target(position)
|
||||
.buildAndComplete(executor.equals(teleporter), teleporter.getUsername());
|
||||
.buildAndComplete(executor.equals(teleporter), teleporter.getName());
|
||||
}
|
||||
|
||||
protected boolean isInvalidOperation(String operation, CommandUser executor) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TpCommand extends Command implements TabCompletable {
|
||||
: target instanceof OnlineUser online ? online.getName() : null;
|
||||
if (executor instanceof OnlineUser online) {
|
||||
if (online.equals(teleporter)) {
|
||||
if (teleporter.getUsername().equalsIgnoreCase(targetName)) {
|
||||
if (teleporter.getName().equalsIgnoreCase(targetName)) {
|
||||
plugin.getLocales().getLocale("error_cannot_teleport_self")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
@@ -118,14 +118,14 @@ public class TpCommand extends Command implements TabCompletable {
|
||||
|
||||
// Display the teleport completion message
|
||||
if (target instanceof Position position) {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete_position", teleporter.getUsername(),
|
||||
plugin.getLocales().getLocale("teleporting_other_complete_position", teleporter.getName(),
|
||||
Integer.toString((int) position.getX()), Integer.toString((int) position.getY()),
|
||||
Integer.toString((int) position.getZ()))
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
teleporter.getUsername(), Objects.requireNonNull(targetName))
|
||||
teleporter.getName(), Objects.requireNonNull(targetName))
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,12 @@ public interface Teleportable {
|
||||
* @return the username string
|
||||
*/
|
||||
@NotNull
|
||||
String getUsername();
|
||||
String getName();
|
||||
|
||||
@NotNull
|
||||
@Deprecated(since = "4.8")
|
||||
default String getUsername() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.william278.huskhomes.teleport;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -56,11 +57,12 @@ public record Username(@NotNull String name) implements Teleportable, Target {
|
||||
/**
|
||||
* Get the username {@link String} being represented by this object.
|
||||
*
|
||||
* @return the username
|
||||
* @return the name
|
||||
* @since 4.8
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public String getUsername() {
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
package net.william278.huskhomes.user;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -30,14 +29,17 @@ import java.util.UUID;
|
||||
* Represents a user who has data saved in the database.
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class User implements Comparable<User> {
|
||||
|
||||
@Expose
|
||||
@NotNull
|
||||
private final UUID uuid;
|
||||
|
||||
private UUID uuid;
|
||||
@Expose
|
||||
@Setter
|
||||
@NotNull
|
||||
private final String name;
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
public static User of(@NotNull UUID uuid, @NotNull String username) {
|
||||
|
||||
Reference in new issue
Block a user