mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 01:17:42 +01:00
Add compass command
This commit is contained in:
committed by
granny
parent
a771a5beb7
commit
a5c728eafe
@@ -243,6 +243,11 @@ public class PurpurConfig {
|
||||
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;
|
||||
public static boolean commandGamemodeRequiresPermission = false;
|
||||
public static boolean hideHiddenPlayersFromEntitySelector = false;
|
||||
public static String uptimeFormat = "<days><hours><minutes><seconds>";
|
||||
@@ -265,6 +270,13 @@ public class PurpurConfig {
|
||||
commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium);
|
||||
commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow);
|
||||
commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval);
|
||||
|
||||
commandCompassBarTitle = getString("settings.command.compass.title", commandCompassBarTitle);
|
||||
commandCompassBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.compass.overlay", commandCompassBarProgressOverlay.name()));
|
||||
commandCompassBarProgressColor = BossBar.Color.valueOf(getString("settings.command.compass.progress-color", commandCompassBarProgressColor.name()));
|
||||
commandCompassBarProgressPercent = (float) getDouble("settings.command.compass.percent", commandCompassBarProgressPercent);
|
||||
commandCompassBarTickInterval = getInt("settings.command.compass.tick-interval", commandCompassBarTickInterval);
|
||||
|
||||
commandGamemodeRequiresPermission = getBoolean("settings.command.gamemode.requires-specific-permission", commandGamemodeRequiresPermission);
|
||||
hideHiddenPlayersFromEntitySelector = getBoolean("settings.command.hide-hidden-players-from-entity-selector", hideHiddenPlayersFromEntitySelector);
|
||||
uptimeFormat = getString("settings.command.uptime.format", uptimeFormat);
|
||||
|
||||
@@ -215,6 +215,7 @@ public class PurpurWorldConfig {
|
||||
public float enderPearlEndermiteChance = 0.05F;
|
||||
public int glowBerriesEatGlowDuration = 0;
|
||||
public boolean shulkerBoxItemDropContentsWhenDestroyed = true;
|
||||
public boolean compassItemShowsBossBar = false;
|
||||
private void itemSettings() {
|
||||
itemImmuneToCactus.clear();
|
||||
getList("gameplay-mechanics.item.immune.cactus", new ArrayList<>()).forEach(key -> {
|
||||
@@ -263,6 +264,7 @@ public class PurpurWorldConfig {
|
||||
enderPearlEndermiteChance = (float) getDouble("gameplay-mechanics.item.ender-pearl.endermite-spawn-chance", enderPearlEndermiteChance);
|
||||
glowBerriesEatGlowDuration = getInt("gameplay-mechanics.item.glow_berries.eat-glow-duration", glowBerriesEatGlowDuration);
|
||||
shulkerBoxItemDropContentsWhenDestroyed = getBoolean("gameplay-mechanics.item.shulker_box.drop-contents-when-destroyed", shulkerBoxItemDropContentsWhenDestroyed);
|
||||
compassItemShowsBossBar = getBoolean("gameplay-mechanics.item.compass.holding-shows-bossbar", compassItemShowsBossBar);
|
||||
}
|
||||
|
||||
public double minecartMaxSpeed = 0.4D;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.purpurmc.purpur.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.purpurmc.purpur.task.CompassTask;
|
||||
|
||||
public class CompassCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("compass")
|
||||
.requires(listener -> listener.hasPermission(2, "bukkit.command.compass"))
|
||||
.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;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.purpurmc.purpur.task;
|
||||
|
||||
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.purpurmc.purpur.PurpurConfig;
|
||||
|
||||
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 < PurpurConfig.commandCompassBarTickInterval) {
|
||||
return;
|
||||
}
|
||||
tick = 0;
|
||||
|
||||
MinecraftServer.getServer().getAllLevels().forEach((level) -> {
|
||||
if (level.purpurConfig.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(""), PurpurConfig.commandCompassBarProgressPercent, PurpurConfig.commandCompassBarProgressColor, PurpurConfig.commandCompassBarProgressOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
void updateBossBar(BossBar bossbar, Player player) {
|
||||
float yaw = player.getLocation().getYaw();
|
||||
int length = PurpurConfig.commandCompassBarTitle.length();
|
||||
int pos = (int) ((normalize(yaw) * (length / 720F)) + (length / 2F));
|
||||
bossbar.name(Component.text(PurpurConfig.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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user