mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
234 lines
11 KiB
Diff
234 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Sat, 24 Jul 2021 00:07:31 -0500
|
|
Subject: [PATCH] Purpur: Add compass command
|
|
|
|
Original license: MIT
|
|
Original project: https://github.com/PurpurMC/Purpur
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
|
index 0e8700ccc884957f08fa382723a3784d94da0f0e..66242833210ae89cbca7448cd4e7cf1fa774bcf0 100644
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
|
@@ -215,6 +215,7 @@ public class Commands {
|
|
StopCommand.register(this.dispatcher);
|
|
WhitelistCommand.register(this.dispatcher);
|
|
org.dreeam.leaf.commands.TPSBarCommand.register(this.dispatcher); // Purpur
|
|
+ org.dreeam.leaf.commands.CompassCommand.register(this.dispatcher); // Purpur
|
|
}
|
|
|
|
if (environment.includeIntegrated) {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 39a0bd651736c80cc558775d94794ee020c574a8..09667820e41ef9c4e3aef9e2c8d18eb6aa0bdc1e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -270,6 +270,7 @@ public class ServerPlayer extends Player {
|
|
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
|
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - there are a lot of changes to do if we change all methods leading to the event
|
|
private boolean tpsBar = false; // Purpur
|
|
+ private boolean compassBar = false; // Purpur
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
|
|
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
|
|
@@ -509,6 +510,7 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
if (nbt.contains("Purpur.TPSBar")) { this.tpsBar = nbt.getBoolean("Purpur.TPSBar"); } // Purpur
|
|
+ if (nbt.contains("Purpur.CompassBar")) { this.compassBar = nbt.getBoolean("Purpur.CompassBar"); } // Purpur
|
|
}
|
|
|
|
@Override
|
|
@@ -576,6 +578,7 @@ public class ServerPlayer extends Player {
|
|
this.getBukkitEntity().setExtraData(nbt); // CraftBukkit
|
|
|
|
nbt.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur
|
|
+ nbt.putBoolean("Purpur.CompassBar", this.compassBar); // Purpur
|
|
}
|
|
|
|
// CraftBukkit start - World fallback code, either respawn location or global spawn
|
|
@@ -2563,5 +2566,13 @@ public class ServerPlayer extends Player {
|
|
public void tpsBar(boolean tpsBar) {
|
|
this.tpsBar = tpsBar;
|
|
}
|
|
+
|
|
+ public boolean compassBar() {
|
|
+ return this.compassBar;
|
|
+ }
|
|
+
|
|
+ public void compassBar(boolean compassBar) {
|
|
+ this.compassBar = compassBar;
|
|
+ }
|
|
// Purpur end
|
|
}
|
|
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
index f8b3f9cca444ef457118edc57b3ff08b1ed1ac40..02272d03d84d1c5c9133d30eb1de58715130d259 100644
|
|
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
@@ -166,6 +166,11 @@ public class LeafConfig {
|
|
public static String commandTPSBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
|
|
public static String commandTPSBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
|
|
public static int commandTPSBarTickInterval = 20;
|
|
+ public static String commandCompassBarTitle = "S \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 SW \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 W \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 NW \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 N \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 NE \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 E \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 SE \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 S \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 SW \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 W \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 NW \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 N \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 NE \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 E \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 SE \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 \u25C8 \u00B7 ";
|
|
+ public static BossBar.Overlay commandCompassBarProgressOverlay = BossBar.Overlay.PROGRESS;
|
|
+ public static BossBar.Color commandCompassBarProgressColor = BossBar.Color.BLUE;
|
|
+ public static float commandCompassBarProgressPercent = 1.0F;
|
|
+ public static int commandCompassBarTickInterval = 5;
|
|
|
|
private static void commandSettings() {
|
|
commandTPSBarOutput = getString("command.messages.tpsbar-command-output", commandTPSBarOutput);
|
|
@@ -179,5 +184,16 @@ public class LeafConfig {
|
|
commandTPSBarTextColorMedium = getString("command.tpsbar.text-color.medium", commandTPSBarTextColorMedium);
|
|
commandTPSBarTextColorLow = getString("command.tpsbar.text-color.low", commandTPSBarTextColorLow);
|
|
commandTPSBarTickInterval = getInt("command.tpsbar.tick-interval", commandTPSBarTickInterval);
|
|
+
|
|
+ commandCompassBarTitle = getString("command.compass.title", commandCompassBarTitle);
|
|
+ commandCompassBarProgressOverlay = BossBar.Overlay.valueOf(getString("command.compass.overlay", commandCompassBarProgressOverlay.name()));
|
|
+ commandCompassBarProgressColor = BossBar.Color.valueOf(getString("command.compass.progress-color", commandCompassBarProgressColor.name()));
|
|
+ commandCompassBarProgressPercent = (float) getDouble("command.compass.percent", commandCompassBarProgressPercent);
|
|
+ commandCompassBarTickInterval = getInt("command.compass.tick-interval", commandCompassBarTickInterval);
|
|
+ }
|
|
+
|
|
+ public static boolean compassItemShowsBossBar = false;
|
|
+ private static void gameplayMechanicSettings() {
|
|
+ compassItemShowsBossBar = getBoolean("gameplay-mechanics.item.compass.holding-shows-bossbar", compassItemShowsBossBar);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/dreeam/leaf/commands/CompassCommand.java b/src/main/java/org/dreeam/leaf/commands/CompassCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a3c85794307e906c4343d490e0e10daaab0efb38
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/commands/CompassCommand.java
|
|
@@ -0,0 +1,27 @@
|
|
+package org.dreeam.leaf.commands;
|
|
+
|
|
+import com.mojang.brigadier.CommandDispatcher;
|
|
+import net.minecraft.commands.CommandSourceStack;
|
|
+import net.minecraft.commands.Commands;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import org.dreeam.leaf.tasks.CompassTask;
|
|
+
|
|
+public class CompassCommand {
|
|
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
+ dispatcher.register(Commands.literal("compass")
|
|
+ .requires(listener -> listener.hasPermission(2))
|
|
+ .executes(context -> {
|
|
+ ServerPlayer player = context.getSource().getPlayerOrException();
|
|
+ CompassTask task = CompassTask.instance();
|
|
+ if (player.compassBar()) {
|
|
+ task.removePlayer(player.getBukkitEntity());
|
|
+ player.compassBar(false);
|
|
+ } else {
|
|
+ task.addPlayer(player.getBukkitEntity());
|
|
+ player.compassBar(true);
|
|
+ }
|
|
+ return 1;
|
|
+ })
|
|
+ ).setPermission("bukkit.command.compass");
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/dreeam/leaf/tasks/BossBarTask.java b/src/main/java/org/dreeam/leaf/tasks/BossBarTask.java
|
|
index ae629c689779339589de3ec28fb6a79bf54da583..7dacf4f21d082dd9a19db6e5122d06b5bda8fc95 100644
|
|
--- a/src/main/java/org/dreeam/leaf/tasks/BossBarTask.java
|
|
+++ b/src/main/java/org/dreeam/leaf/tasks/BossBarTask.java
|
|
@@ -90,10 +90,12 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|
|
|
public static void startAll() {
|
|
TPSBarTask.instance().start();
|
|
+ CompassTask.instance().start();
|
|
}
|
|
|
|
public static void stopAll() {
|
|
TPSBarTask.instance().stop();
|
|
+ CompassTask.instance().stop();
|
|
}
|
|
|
|
public static void addToAll(ServerPlayer player) {
|
|
@@ -101,9 +103,13 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|
if (player.tpsBar()) {
|
|
TPSBarTask.instance().addPlayer(bukkit);
|
|
}
|
|
+ if (player.compassBar()) {
|
|
+ CompassTask.instance().addPlayer(bukkit);
|
|
+ }
|
|
}
|
|
|
|
public static void removeFromAll(Player player) {
|
|
TPSBarTask.instance().removePlayer(player);
|
|
+ CompassTask.instance().removePlayer(player);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/dreeam/leaf/tasks/CompassTask.java b/src/main/java/org/dreeam/leaf/tasks/CompassTask.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..3ecd9bb435e5066176da88f7d50d4920cee017e5
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/tasks/CompassTask.java
|
|
@@ -0,0 +1,68 @@
|
|
+package org.dreeam.leaf.tasks;
|
|
+
|
|
+import net.kyori.adventure.bossbar.BossBar;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.world.item.Items;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.dreeam.leaf.LeafConfig;
|
|
+
|
|
+public class CompassTask extends BossBarTask {
|
|
+ private static CompassTask instance;
|
|
+
|
|
+ private int tick = 0;
|
|
+
|
|
+ public static CompassTask instance() {
|
|
+ if (instance == null) {
|
|
+ instance = new CompassTask();
|
|
+ }
|
|
+ return instance;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ if (++tick < LeafConfig.commandCompassBarTickInterval) {
|
|
+ return;
|
|
+ }
|
|
+ tick = 0;
|
|
+
|
|
+ MinecraftServer.getServer().getAllLevels().forEach((level) -> {
|
|
+ if (LeafConfig.compassItemShowsBossBar) {
|
|
+ level.players().forEach(player -> {
|
|
+ if (!player.compassBar()) {
|
|
+ if (player.getMainHandItem().getItem() != Items.COMPASS && player.getOffhandItem().getItem() != Items.COMPASS) {
|
|
+ removePlayer(player.getBukkitEntity());
|
|
+ } else if (!hasPlayer(player.getUUID())) {
|
|
+ addPlayer(player.getBukkitEntity());
|
|
+ }
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+ });
|
|
+
|
|
+ super.run();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ BossBar createBossBar() {
|
|
+ return BossBar.bossBar(Component.text(""), LeafConfig.commandCompassBarProgressPercent, LeafConfig.commandCompassBarProgressColor, LeafConfig.commandCompassBarProgressOverlay);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ void updateBossBar(BossBar bossbar, Player player) {
|
|
+ float yaw = player.getLocation().getYaw();
|
|
+ int length = LeafConfig.commandCompassBarTitle.length();
|
|
+ int pos = (int) ((normalize(yaw) * (length / 720F)) + (length / 2F));
|
|
+ bossbar.name(Component.text(LeafConfig.commandCompassBarTitle.substring(pos - 25, pos + 25)));
|
|
+ }
|
|
+
|
|
+ private float normalize(float yaw) {
|
|
+ while (yaw < -180.0F) {
|
|
+ yaw += 360.0F;
|
|
+ }
|
|
+ while (yaw > 180.0F) {
|
|
+ yaw -= 360.0F;
|
|
+ }
|
|
+ return yaw;
|
|
+ }
|
|
+}
|