added bedrock displayname prefix
This commit is contained in:
parent
9004609c1b
commit
696c4bc260
src/main/java/eu/mhsl/craftattack/spawn
appliances
afkTag
displayName
outlawed
sleepTag
yearRank
util/text
@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AfkTag extends Appliance implements DisplayName.DisplayNamed {
|
||||
public class AfkTag extends Appliance implements DisplayName.Prefixed {
|
||||
private final HashMap<UUID, Long> afkTimings = new HashMap<>();
|
||||
private static final int updateIntervalSeconds = 30;
|
||||
private static final int afkWhenMillis = 3 * 60 * 1000;
|
||||
|
@ -8,9 +8,13 @@ import eu.mhsl.craftattack.spawn.appliances.afkTag.AfkTag;
|
||||
import eu.mhsl.craftattack.spawn.appliances.outlawed.Outlawed;
|
||||
import eu.mhsl.craftattack.spawn.appliances.sleepTag.SleepTag;
|
||||
import eu.mhsl.craftattack.spawn.appliances.yearRank.YearRank;
|
||||
import eu.mhsl.craftattack.spawn.util.server.Floodgate;
|
||||
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -22,7 +26,7 @@ import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DisplayName extends Appliance {
|
||||
public interface DisplayNamed {
|
||||
public interface Prefixed {
|
||||
@Nullable Component getNamePrefix(Player player);
|
||||
}
|
||||
|
||||
@ -39,10 +43,22 @@ public class DisplayName extends Appliance {
|
||||
prefixes.forEach(supplier -> {
|
||||
Component prefix = supplier.get();
|
||||
if(prefix == null) return;
|
||||
playerName.append(prefix).append(
|
||||
Component.text(" ").hoverEvent(Component.empty().asHoverEvent()));
|
||||
playerName
|
||||
.append(prefix)
|
||||
.append(ComponentUtil.clearedSpace());
|
||||
});
|
||||
|
||||
if(Floodgate.isBedrock(player)) {
|
||||
playerName
|
||||
.append(
|
||||
Component.text("\uD83C\uDFAE", NamedTextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.showText(Component.text(
|
||||
String.format("%s spielt die Minecraft: Bedrock Edition", player.getName())
|
||||
)))
|
||||
)
|
||||
.append(ComponentUtil.clearedSpace());
|
||||
}
|
||||
|
||||
playerName.append(Component.text(player.getName(), playerColor));
|
||||
|
||||
setGlobal(player, playerName.build());
|
||||
@ -54,12 +70,10 @@ public class DisplayName extends Appliance {
|
||||
player.displayName(component);
|
||||
player.playerListName(component);
|
||||
} catch(Exception e) {
|
||||
//TODO this throws often exceptions, but still works, don't know why
|
||||
Main.instance().getLogger().log(Level.SEVERE, e, e::getMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<Listener> listeners() {
|
||||
|
@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Outlawed extends Appliance implements DisplayName.DisplayNamed {
|
||||
public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
||||
public final int timeoutInMs = 1000 * 60 * 60 * 6;
|
||||
private final Map<UUID, Long> timeouts = new HashMap<>();
|
||||
|
||||
|
@ -17,7 +17,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SleepTag extends Appliance implements DisplayName.DisplayNamed {
|
||||
public class SleepTag extends Appliance implements DisplayName.Prefixed {
|
||||
private final Set<Player> sleepingPlayers = new HashSet<>();
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class YearRank extends Appliance implements DisplayName.DisplayNamed {
|
||||
public class YearRank extends Appliance implements DisplayName.Prefixed {
|
||||
record CraftAttackYear(String name) {}
|
||||
private final Map<UUID, List<CraftAttackYear>> rankMap = new HashMap<>();
|
||||
|
||||
|
@ -22,6 +22,10 @@ public class ComponentUtil {
|
||||
return Component.text("Bitte warte einen Augenblick...", NamedTextColor.GRAY);
|
||||
}
|
||||
|
||||
public static Component clearedSpace() {
|
||||
return Component.text(" ").hoverEvent(Component.empty().asHoverEvent());
|
||||
}
|
||||
|
||||
public static TextComponent appendWithNewline(Component a, Component b) {
|
||||
return Component.text().append(a.appendNewline().append(b)).build();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user