mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-30 04:34:43 +02:00
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:
52
src/main/java/com/gmail/nossr50/chat/author/AdminAuthor.java
Normal file
52
src/main/java/com/gmail/nossr50/chat/author/AdminAuthor.java
Normal 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();
|
||||
}
|
||||
}
|
32
src/main/java/com/gmail/nossr50/chat/author/Author.java
Normal file
32
src/main/java/com/gmail/nossr50/chat/author/Author.java
Normal 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();
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
52
src/main/java/com/gmail/nossr50/chat/author/PartyAuthor.java
Normal file
52
src/main/java/com/gmail/nossr50/chat/author/PartyAuthor.java
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user