Compare commits
No commits in common. "master" and "plot_rtp" have entirely different histories.
|
|
@ -57,7 +57,6 @@ 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);
|
||||
|
|
|
|||
|
|
@ -95,21 +95,6 @@ public class Config extends AbstractConfig {
|
|||
}
|
||||
}
|
||||
|
||||
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.";
|
||||
|
||||
|
|
|
|||
|
|
@ -197,20 +197,6 @@ public class Messages extends AbstractConfig {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RANDOM_PLOT {
|
||||
private static final String prefix = "random-plot.";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
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().key().asMinimalString());
|
||||
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.HAPPY_VILLAGER, 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,10 +2,6 @@ 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