Upload files to "src/main/java/com/wulliestudio/playerutils"

This commit is contained in:
2025-11-30 06:37:01 +00:00
commit 5a80f4dcea
5 changed files with 505 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
package com.wulliestudio.playerutils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
public class KillCommand implements CommandExecutor, Listener{
private final JavaPlugin plugin;
public KillCommand(JavaPlugin plugin){
this.plugin = plugin;
}
// register commands
public void registerCommands(){
PluginCommand cmd = plugin.getCommand("kill");
if(cmd == null){
plugin.getLogger().severe("hey dumbass update plugin.yml");
return;
}
cmd.setExecutor(this);
cmd.setTabCompleter((sender, command, lable, args) -> List.of());
plugin.getServer()
.getPluginManager()
.registerEvents(this, plugin);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(!(sender instanceof Player player)){
sender.sendMessage("this command cant be used like that");
return true;
}
player.setMetadata("suicide", new FixedMetadataValue(plugin, true));
player.setHealth(0);
return true;
}
@EventHandler
public void onDeath(PlayerDeathEvent event){
Player p = event.getEntity();
if(p.hasMetadata("suicide")){
event.setDeathMessage(p.getName() + " pussed out like a BITCH");
p.removeMetadata("suicide", plugin);
}
}
}

View File

@@ -0,0 +1,195 @@
package com.wulliestudio.playerutils;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class NameColorManager {
private final JavaPlugin plugin;
private File colorFile;
private FileConfiguration colorConfig;
private File playerColorFile;
private FileConfiguration playerColorConfig;
public NameColorManager(JavaPlugin plugin) {
this.plugin = plugin;
loadColors();
loadPlayerColors();
}
// ---------------------------------------
// Load colors.yml
// ---------------------------------------
private void loadColors() {
colorFile = new File(plugin.getDataFolder(), "colors.yml");
if (!colorFile.exists()) {
plugin.saveResource("colors.yml", false);
}
colorConfig = YamlConfiguration.loadConfiguration(colorFile);
if (colorConfig.getConfigurationSection("colors") == null) {
colorConfig.createSection("colors");
try {
colorConfig.save(colorFile);
} catch (IOException ignored) {}
}
}
public Map<String, Object> getColorMap() {
ConfigurationSection sec = colorConfig.getConfigurationSection("colors");
if (sec == null) return Collections.emptyMap();
return sec.getValues(false);
}
public String getColorValue(String name) {
if (name == null) return null;
return colorConfig.getString("colors." + name.toLowerCase());
}
// ---------------------------------------
// Load / Save playercolors.yml
// ---------------------------------------
private void loadPlayerColors() {
playerColorFile = new File(plugin.getDataFolder(), "playercolors.yml");
if (!playerColorFile.exists()) {
try {
if (!playerColorFile.getParentFile().exists()) playerColorFile.getParentFile().mkdirs();
playerColorFile.createNewFile();
} catch (IOException e) {
plugin.getLogger().severe("Could not create playercolors.yml!");
}
}
playerColorConfig = YamlConfiguration.loadConfiguration(playerColorFile);
if (playerColorConfig.getConfigurationSection("players") == null) {
playerColorConfig.createSection("players");
savePlayerColors();
}
}
public void savePlayerColors() {
try {
playerColorConfig.save(playerColorFile);
} catch (IOException e) {
plugin.getLogger().severe("Failed to save playercolors.yml!");
}
}
// ---------------------------------------
// Utility: Convert "#RRGGBB" → §x§R§R§G§G§B§B
// ---------------------------------------
private String hexToMCColor(String hex) {
if (hex == null || !hex.startsWith("#") || hex.length() != 7)
return null;
StringBuilder out = new StringBuilder("§x");
char[] chars = hex.substring(1).toCharArray();
for (char c : chars) {
out.append('§').append(Character.toUpperCase(c));
}
return out.toString();
}
// ---------------------------------------
// Apply player color
// ---------------------------------------
public void setPlayerColor(Player p, String colorKey) {
playerColorConfig.set("players." + p.getUniqueId(), colorKey.toLowerCase());
savePlayerColors();
applyColorByKey(p, colorKey.toLowerCase());
}
public void applyColorByKey(Player p, String colorKey) {
String value = getColorValue(colorKey);
if (value == null) return;
applyColorFromValue(p, value);
}
public void applyColorFromValue(Player p, String value) {
String prefix;
if (value.startsWith("#")) {
String conv = hexToMCColor(value);
if (conv == null) return;
prefix = conv;
} else {
prefix = value;
}
String formatted = prefix + p.getName() + "§r";
p.setDisplayName(formatted);
p.setPlayerListName(formatted);
}
public void loadPlayerColor(Player p) {
String key = playerColorConfig.getString("players." + p.getUniqueId());
if (key != null) {
applyColorByKey(p, key.toLowerCase());
}
}
// ---------------------------------------
// Commands
// ---------------------------------------
public void registerCommands() {
PluginCommand cmd = plugin.getCommand("nc");
if (cmd == null) {
plugin.getLogger().severe("Command /nc missing from plugin.yml!");
return;
}
cmd.setExecutor((sender, command, label, args) -> {
if (!(sender instanceof Player player))
return true;
if (args.length != 1) {
player.sendMessage("§cUsage: /nc <color>");
return true;
}
String key = args[0].toLowerCase();
String value = getColorValue(key);
if (value == null) {
player.sendMessage("§cInvalid color! Available colors:");
for (String c : getColorMap().keySet())
player.sendMessage(" §4- §f" + c);
return true;
}
setPlayerColor(player, key);
player.sendMessage("§6Your name color is now set to: " + key);
return true;
});
cmd.setTabCompleter((sender, command, label, args) -> {
if (args.length == 1)
return getColorMap().keySet().stream().collect(Collectors.toList());
return List.of();
});
}
}

View File

@@ -0,0 +1,67 @@
package com.wulliestudio.playerutils;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class PluginMain extends JavaPlugin {
private TeleportManager tpManager;
private NameColorManager nameColorManager;
private KillCommand killCommand;
private HomeSystem homeSystem;
private RTPCommand rtpCommand;
private HelpCommand helpCommand;
@Override
public void onEnable() {
saveDefaultConfig();
getLogger().info("PlayerUtils enabled");
// register tp
tpManager = new TeleportManager(this);
tpManager.registerCommands();
// register name colors
nameColorManager = new NameColorManager(this);
nameColorManager.registerCommands();
// registar kill command
killCommand = new KillCommand(this);
killCommand.registerCommands();
// register home system
homeSystem = new HomeSystem(this);
homeSystem.registerCommands();
// register rtp
rtpCommand = new RTPCommand(this);
rtpCommand.registerCommands();
// register help
helpCommand = new HelpCommand(this);
helpCommand.registerCommands();
getServer().getPluginManager().registerEvents(new org.bukkit.event.Listener() {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
nameColorManager.loadPlayerColor(event.getPlayer());
}
}, this);
}
@Override
public void onDisable() {
nameColorManager.savePlayerColors();
getLogger().info("PlayerUtils disabled");
}
public TeleportManager getTpManager() {
return tpManager;
}
}

View File

@@ -0,0 +1,65 @@
package com.wulliestudio.playerutils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.command.PluginCommand;
import java.util.concurrent.ThreadLocalRandom;
public class RTPCommand implements CommandExecutor{
private final PluginMain plugin;
public RTPCommand(PluginMain plugin){
this.plugin = plugin;
}
public void registerCommands(){
PluginCommand cmd = plugin.getCommand("rtp");
if(cmd == null){
plugin.getLogger().severe("hey dumbass update plugin.yml");
return;
}
cmd.setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(!(sender instanceof Player p)) {
sender.sendMessage("How in the name of all that holy did you do that");
return true;
}
World world = p.getWorld();
int centerX = 0;
int centerZ = 0;
int radius = 500;
int x = ThreadLocalRandom.current().nextInt(centerX - radius, centerX + radius);
int z = ThreadLocalRandom.current().nextInt(centerZ - radius, centerZ + radius);
world.getChunkAtAsync(x >> 4, z >> 4).thenAccept(chunk -> {
int y = world.getHighestBlockYAt(x, z);
Location loc = new Location(world, x + 0.5, y + 1.0, z + 0.5);
p.getScheduler().run(plugin, task -> {
p.teleportAsync(loc);
p.sendMessage("§6Teleported to a random location!");
}, null);
});
p.sendMessage("§bSearching for a safe random location...");
return true;
}
}

View File

@@ -0,0 +1,103 @@
package com.wulliestudio.playerutils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.UUID;
public class TeleportManager {
private final JavaPlugin plugin;
private final HashMap<UUID, UUID> teleportRequests = new HashMap<>();
public TeleportManager(JavaPlugin plugin){
this.plugin = plugin;
}
public void registerCommands(){
// /tpa
plugin.getCommand("tpa").setExecutor((sender, command, label, args) -> {
if(!(sender instanceof Player player)) return true;
if(args.length != 1){
player.sendMessage("§cUsage: /tpa <player>");
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if(target == null){
player.sendMessage("§cPlayer not found!");
return true;
}
teleportRequests.put(target.getUniqueId(), player.getUniqueId());
target.sendMessage("§4" + player.getName() + " §6wants to teleport to you. Type §4/tpaccept §6or §4/tpdeny§6.");
player.sendMessage("§4Request sent to §6" + target.getName());
return true;
});
// /tpaccept
plugin.getCommand("tpaccept").setExecutor((sender, command, label, args) -> {
if(!(sender instanceof Player target)) return true;
UUID requesterId = teleportRequests.remove(target.getUniqueId());
if(requesterId == null){
target.sendMessage("§cNo pending teleport requests!");
return true;
}
Player requester = Bukkit.getPlayer(requesterId);
if(requester == null){
target.sendMessage("§cRequester is no longer online!");
return true;
}
startTeleport(requester, target);
return true;
});
// /tpdeny
plugin.getCommand("tpdeny").setExecutor((sender, command, label, args) -> {
if(!(sender instanceof Player target)) return true;
UUID requesterId = teleportRequests.remove(target.getUniqueId());
if (requesterId == null) {
target.sendMessage("§cNo pending teleport requests!");
return true;
}
target.sendMessage("§cTeleport request denied.");
Player requester = Bukkit.getPlayer(requesterId);
if(requester != null) requester.sendMessage("§cYour teleport request was denied.");
return true;
});
}
// Teleport logic
private void startTeleport(Player requester, Player target) {
requester.sendMessage("§6Teleporting to §4" + target.getName() + " §6in 3 seconds...");
requester.setInvisible(true);
requester.getScheduler().runDelayed(plugin, (ignored) -> {
if(!requester.isOnline() || !target.isOnline()) return;
target.getScheduler().execute(plugin, () -> {
requester.teleportAsync(target.getLocation()).thenRun(() -> {
requester.setInvisible(false);
requester.sendMessage("§4Teleported to §6" + target.getName() + "§4!");
});
}, null, 1L);
}, null, 60L); // 3 seconds (20 ticks × 3)
}
}