Show villager workstation feature
This commit is contained in:
parent
18de5cebd6
commit
0a2e5865bf
|
|
@ -2,17 +2,20 @@ package com.alttd.playerutils;
|
|||
|
||||
import com.alttd.playerutils.commands.PlayerUtilsCommand;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.GhastSpeed;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.RandomPlotPort;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.RotateBlock;
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.config.KeyStorage;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.event_listeners.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
public final class PlayerUtils extends JavaPlugin {
|
||||
|
||||
private PlayerUtilsCommand playerUtilsCommand;
|
||||
|
|
@ -20,8 +23,8 @@ public final class PlayerUtils extends JavaPlugin {
|
|||
@Override
|
||||
public void onEnable() {
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
reloadConfigs();
|
||||
registerEvents();
|
||||
registerSchedulers();
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +35,11 @@ public final class PlayerUtils extends JavaPlugin {
|
|||
|
||||
private void registerCommands() {
|
||||
playerUtilsCommand = new PlayerUtilsCommand(this);
|
||||
if (getServer().getPluginManager().isPluginEnabled("PlotSquared")) {
|
||||
playerUtilsCommand.addSubCommand(new RandomPlotPort(this));
|
||||
} else {
|
||||
log.warn("PlotSquared not found — rpp subcommand will not be registered.");
|
||||
}
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
|
|
@ -44,6 +52,7 @@ public final class PlayerUtils extends JavaPlugin {
|
|||
pluginManager.registerEvents(new PlayerJoin(this), this);
|
||||
pluginManager.registerEvents(new BookWriteEvent(), this);
|
||||
pluginManager.registerEvents(new BookByteLimitListener(), this);
|
||||
pluginManager.registerEvents(new VillagerWorkstationEvent(this), this);
|
||||
|
||||
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent();
|
||||
pluginManager.registerEvents(rotateBlockEvent, this);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j public class Config extends AbstractConfig{
|
||||
|
|
@ -92,4 +93,86 @@ import java.util.Set;
|
|||
WAYPOINT_TRANSMIT_RANGE = config.getDouble(prefix, "waypoint_transmit_range", WAYPOINT_TRANSMIT_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static class VILLAGER_WORKSTATION {
|
||||
private static final String prefix = "villager-workstation.";
|
||||
|
||||
public static int RANGE = 8;
|
||||
public static int CHECK_INTERVAL_TICKS = 5;
|
||||
public static int PARTICLE_RING_COUNT = 8;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
RANGE = config.getInt(prefix, "range", RANGE);
|
||||
CHECK_INTERVAL_TICKS = config.getInt(prefix, "check-interval-ticks", CHECK_INTERVAL_TICKS);
|
||||
PARTICLE_RING_COUNT = config.getInt(prefix, "particle-ring-count", PARTICLE_RING_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RANDOM_PLOT {
|
||||
private static final String prefix = "random-plot.";
|
||||
|
||||
// Command
|
||||
public static String PORT_COMMAND = "rpp";
|
||||
public static List<String> ALLOWED_WORLDS = List.of("plotworld");
|
||||
|
||||
// Permissions
|
||||
public static boolean USE_LUCKPERMS = true;
|
||||
public static String LUCKPERMS_GROUP = "default";
|
||||
public static boolean USE_VAULT = false;
|
||||
public static String VAULT_GROUP = "member";
|
||||
public static String FALLBACK_PERM = "randomplot.use";
|
||||
|
||||
// Countdown
|
||||
public static int COUNTDOWN_SECONDS = 3;
|
||||
public static HashMap<Integer, String> COUNTDOWN_TITLES = new HashMap<>();
|
||||
public static String COUNTDOWN_SUBTITLE = "<gray>Preparing teleportation</gray>";
|
||||
|
||||
// Messages
|
||||
public static String MSG_TELEPORT_START = "<green>Starting teleport countdown...</green>";
|
||||
public static String MSG_TELEPORT_SUCCESS = "<gold>You have arrived at a random plot!</gold>";
|
||||
public static String MSG_TELEPORT_CANCELLED = "<red>Teleport cancelled! You moved.</red>";
|
||||
public static String MSG_NO_PLOTS_FOUND = "<red>No plots found in this world.</red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
PORT_COMMAND = config.getString(prefix, "port-command", PORT_COMMAND);
|
||||
ALLOWED_WORLDS = config.getStringList(prefix, "allowed-worlds", ALLOWED_WORLDS);
|
||||
|
||||
USE_LUCKPERMS = config.getBoolean(prefix + "permissions.", "use-luckperms", USE_LUCKPERMS);
|
||||
LUCKPERMS_GROUP = config.getString(prefix + "permissions.", "luckperms-group", LUCKPERMS_GROUP);
|
||||
USE_VAULT = config.getBoolean(prefix + "permissions.", "use-vault", USE_VAULT);
|
||||
VAULT_GROUP = config.getString(prefix + "permissions.", "vault-group", VAULT_GROUP);
|
||||
FALLBACK_PERM = config.getString(prefix + "permissions.", "fallback-perm", FALLBACK_PERM);
|
||||
|
||||
COUNTDOWN_SECONDS = config.getInt(prefix + "countdown.", "seconds", COUNTDOWN_SECONDS);
|
||||
COUNTDOWN_SUBTITLE = config.getString(prefix + "countdown.", "subtitle", COUNTDOWN_SUBTITLE);
|
||||
|
||||
// Countdown titles — integer keys map to display strings
|
||||
COUNTDOWN_TITLES.clear();
|
||||
ConfigurationSection titlesSection =
|
||||
config.getConfigurationSection("random-plot.countdown.titles");
|
||||
if (titlesSection != null) {
|
||||
for (String key : titlesSection.getKeys(false)) {
|
||||
try {
|
||||
COUNTDOWN_TITLES.put(Integer.parseInt(key),
|
||||
titlesSection.getString(key, key));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
} else {
|
||||
// Write defaults on first run
|
||||
config.yaml.addDefault("random-plot.countdown.titles.3", "<#08FBFF>3");
|
||||
config.yaml.addDefault("random-plot.countdown.titles.2", "<#08FBFF>2");
|
||||
config.yaml.addDefault("random-plot.countdown.titles.1", "<#08FBFF>1");
|
||||
COUNTDOWN_TITLES.put(3, "<#08FBFF>3");
|
||||
COUNTDOWN_TITLES.put(2, "<#08FBFF>2");
|
||||
COUNTDOWN_TITLES.put(1, "<#08FBFF>1");
|
||||
}
|
||||
|
||||
MSG_TELEPORT_START = config.getString(prefix + "messages.", "teleport-start", MSG_TELEPORT_START);
|
||||
MSG_TELEPORT_SUCCESS = config.getString(prefix + "messages.", "teleport-success", MSG_TELEPORT_SUCCESS);
|
||||
MSG_TELEPORT_CANCELLED = config.getString(prefix + "messages.", "teleport-cancelled", MSG_TELEPORT_CANCELLED);
|
||||
MSG_NO_PLOTS_FOUND = config.getString(prefix + "messages.", "no-plots-found", MSG_NO_PLOTS_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String KEY = "<green>Receive a key that you are owed: <gold>/pu key</gold></green>";
|
||||
public static String GHAST_SPEED = "<green>Set the speed of a ghast: <gold>/pu ghastspeed <speed></gold></green>";
|
||||
public static String RECOUNT_ARMOR_STANDS = "<green>Recount armor stands in current chunk: <gold>/pu recount</gold></green>";
|
||||
public static String RPP = "<green>Teleport to a random plot: <gold>/pu rpp</gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -47,6 +48,7 @@ public class Messages extends AbstractConfig {
|
|||
ROTATE_BLOCK = config.getString(prefix, "rotate-block", ROTATE_BLOCK);
|
||||
GHAST_SPEED = config.getString(prefix, "ghast-speed", GHAST_SPEED);
|
||||
RECOUNT_ARMOR_STANDS = config.getString(prefix, "recount-armor-stands", RECOUNT_ARMOR_STANDS);
|
||||
RPP = config.getString(prefix, "rpp", RPP);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,6 +187,19 @@ public class Messages extends AbstractConfig {
|
|||
|
||||
}
|
||||
|
||||
public static class RANDOM_PLOT_PORT {
|
||||
private static final String prefix = "pu-command.rpp.";
|
||||
|
||||
public static String NOT_ALLOWED_WORLD = "<red>You must be in an allowed world to use this command.</red>";
|
||||
public static String PLOTSQUARED_UNAVAILABLE = "<red>PlotSquared is not available on this server.</red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NOT_ALLOWED_WORLD = config.getString(prefix, "not-allowed-world", NOT_ALLOWED_WORLD);
|
||||
PLOTSQUARED_UNAVAILABLE = config.getString(prefix, "plotsquared-unavailable", PLOTSQUARED_UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RECOUNT_ARMOR_STANDS {
|
||||
private static final String prefix = "recount-armor-stands.";
|
||||
|
||||
|
|
@ -197,4 +212,17 @@ public class Messages extends AbstractConfig {
|
|||
SUCCESS = config.getString(prefix, "success", SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
public static class VILLAGER_WORKSTATION {
|
||||
private static final String prefix = "villager-workstation.";
|
||||
|
||||
public static String WORKSTATION = "<gold>Villager (<profession>): <yellow><workstation></yellow></gold>";
|
||||
public static String NO_WORKSTATION = "<gold>Villager (<profession>): <gray>No workstation</gray></gold>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
WORKSTATION = config.getString(prefix, "workstation", WORKSTATION);
|
||||
NO_WORKSTATION = config.getString(prefix, "no-workstation", NO_WORKSTATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.memory.MemoryKey;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@Slf4j
|
||||
public class VillagerWorkstationEvent implements Listener {
|
||||
|
||||
public VillagerWorkstationEvent(JavaPlugin plugin) {
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::checkPlayersLookingAtVillagers,
|
||||
0L, Config.VILLAGER_WORKSTATION.CHECK_INTERVAL_TICKS);
|
||||
}
|
||||
|
||||
private void checkPlayersLookingAtVillagers() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.getInventory().getItemInMainHand().getType().equals(Material.AIR)) {
|
||||
continue;
|
||||
}
|
||||
Entity target = player.getTargetEntity(Config.VILLAGER_WORKSTATION.RANGE);
|
||||
if (!(target instanceof Villager villager)) {
|
||||
continue;
|
||||
}
|
||||
showWorkstation(player, villager);
|
||||
}
|
||||
}
|
||||
|
||||
private void showWorkstation(Player player, Villager villager) {
|
||||
String professionName = formatName(villager.getProfession().name());
|
||||
Location jobSite = villager.getMemory(MemoryKey.JOB_SITE);
|
||||
|
||||
if (jobSite == null) {
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize(
|
||||
Messages.VILLAGER_WORKSTATION.NO_WORKSTATION
|
||||
.replace("<profession>", professionName)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the actual block type at the linked location so it reflects reality
|
||||
String blockName = formatName(jobSite.getBlock().getType().name());
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize(
|
||||
Messages.VILLAGER_WORKSTATION.WORKSTATION
|
||||
.replace("<profession>", professionName)
|
||||
.replace("<workstation>", blockName)));
|
||||
|
||||
spawnWorkstationParticles(player, jobSite.getBlock().getLocation());
|
||||
}
|
||||
|
||||
private void spawnWorkstationParticles(Player player, Location blockLoc) {
|
||||
World world = blockLoc.getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double cx = blockLoc.getX() + 0.5;
|
||||
double cy = blockLoc.getY() + 1.1;
|
||||
double cz = blockLoc.getZ() + 0.5;
|
||||
int count = Config.VILLAGER_WORKSTATION.PARTICLE_RING_COUNT;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
double angle = (2 * Math.PI * i) / count;
|
||||
double x = cx + 0.5 * Math.cos(angle);
|
||||
double z = cz + 0.5 * Math.sin(angle);
|
||||
player.spawnParticle(Particle.VILLAGER_HAPPY, x, cy, z, 1, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatName(String enumName) {
|
||||
String lower = enumName.replace("_", " ").toLowerCase();
|
||||
return Character.toUpperCase(lower.charAt(0)) + lower.substring(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,10 @@ name: PlayerUtils
|
|||
version: '${version}'
|
||||
main: com.alttd.playerutils.PlayerUtils
|
||||
api-version: '1.20'
|
||||
softdepend:
|
||||
- PlotSquared
|
||||
- LuckPerms
|
||||
- Vault
|
||||
commands:
|
||||
playerutils:
|
||||
description: Base command for player utils
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user