Complete rewrite of Admin & Party chat code

There are some API breaks as a result of these rewrites, I tried to keep it minimal, but I'm sure some plugins will need to update.
This commit is contained in:
nossr50
2020-10-26 16:31:02 -07:00
parent cf6a2e9e97
commit 749c83ac59
44 changed files with 1419 additions and 713 deletions

View File

@ -0,0 +1,52 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.Config;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class AdminAuthor implements Author {
private final @NotNull Player player;
private @Nullable String overrideName;
public AdminAuthor(@NotNull Player player) {
this.player = player;
}
@Override
public @NotNull String getAuthoredName() {
if(overrideName != null) {
return overrideName;
} else {
if(Config.getInstance().getAdminDisplayNames()) {
return player.getDisplayName();
} else {
return player.getName();
}
}
}
@Override
public void setName(@NotNull String newName) {
overrideName = newName;
}
@Override
public boolean isConsole() {
return false;
}
@Override
public boolean isPlayer() {
return true;
}
@Override
public @NonNull UUID uuid() {
return player.getUniqueId();
}
}

View File

@ -0,0 +1,32 @@
package com.gmail.nossr50.chat.author;
import net.kyori.adventure.identity.Identity;
import org.jetbrains.annotations.NotNull;
public interface Author extends Identity {
/**
* The name of this author
* @return the name of this author
*/
@NotNull String getAuthoredName();
/**
* Set the name of this author
* @param newName value of the new name
*/
void setName(@NotNull String newName);
/**
* Whether or not this author is a {@link org.bukkit.command.ConsoleCommandSender}
*
* @return true if this author is the console
*/
boolean isConsole();
/**
* Whether or not this author is a {@link org.bukkit.entity.Player}
* @return true if this author is a player
*/
boolean isPlayer();
}

View File

@ -0,0 +1,41 @@
package com.gmail.nossr50.chat.author;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class ConsoleAuthor implements Author {
private final UUID uuid;
private @NotNull String name;
public ConsoleAuthor(@NotNull String name) {
this.name = name;
this.uuid = new UUID(0, 0);
}
@Override
public @NotNull String getAuthoredName() {
return name;
}
@Override
public void setName(@NotNull String newName) {
this.name = newName;
}
@Override
public boolean isConsole() {
return true;
}
@Override
public boolean isPlayer() {
return false;
}
@Override
public @NonNull UUID uuid() {
return uuid;
}
}

View File

@ -0,0 +1,52 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.Config;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class PartyAuthor implements Author {
private final @NotNull Player player;
private @Nullable String overrideName;
public PartyAuthor(@NotNull Player player) {
this.player = player;
}
@Override
public @NotNull String getAuthoredName() {
if(overrideName != null) {
return overrideName;
} else {
if(Config.getInstance().getPartyDisplayNames()) {
return player.getDisplayName();
} else {
return player.getName();
}
}
}
@Override
public void setName(@NotNull String newName) {
overrideName = newName;
}
@Override
public boolean isConsole() {
return false;
}
@Override
public boolean isPlayer() {
return true;
}
@Override
public @NonNull UUID uuid() {
return player.getUniqueId();
}
}