commit 0582879bf57b98e40d5f6587d845e26b01882c0a Author: Mazey-Jessica Emily Twilight Date: Thu Jan 2 15:54:53 2025 +0000 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..039a9d1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..34e8362 --- /dev/null +++ b/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + com.example + jailplugin + 1.0-SNAPSHOT + + + 17 + UTF-8 + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + io.papermc.paper + paper-api + 1.21.4-R0.1-SNAPSHOT + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/src/main/java/com/example/JailPlugin.java b/src/main/java/com/example/JailPlugin.java new file mode 100644 index 0000000..fea3e83 --- /dev/null +++ b/src/main/java/com/example/JailPlugin.java @@ -0,0 +1,238 @@ +package com.example.jailplugin; + +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.ChatColor; + +public class JailPlugin extends JavaPlugin { + private Location jailLocation; + private Location unjailLocation; + + @Override + public void onEnable() { + saveDefaultConfig(); + loadLocations(); + getLogger().info("JailPlugin has been enabled!"); + } + + @Override + public void onDisable() { + saveLocations(); + getLogger().info("JailPlugin has been disabled!"); + } + + private void loadLocations() { + if (getConfig().contains("jail")) { + World world = getServer().getWorld(getConfig().getString("jail.world")); + double x = getConfig().getDouble("jail.x"); + double y = getConfig().getDouble("jail.y"); + double z = getConfig().getDouble("jail.z"); + float yaw = (float) getConfig().getDouble("jail.yaw"); + float pitch = (float) getConfig().getDouble("jail.pitch"); + jailLocation = new Location(world, x, y, z, yaw, pitch); + } + + if (getConfig().contains("unjail")) { + World world = getServer().getWorld(getConfig().getString("unjail.world")); + double x = getConfig().getDouble("unjail.x"); + double y = getConfig().getDouble("unjail.y"); + double z = getConfig().getDouble("unjail.z"); + float yaw = (float) getConfig().getDouble("unjail.yaw"); + float pitch = (float) getConfig().getDouble("unjail.pitch"); + unjailLocation = new Location(world, x, y, z, yaw, pitch); + } + } + + private void saveLocations() { + if (jailLocation != null) { + getConfig().set("jail.world", jailLocation.getWorld().getName()); + getConfig().set("jail.x", jailLocation.getX()); + getConfig().set("jail.y", jailLocation.getY()); + getConfig().set("jail.z", jailLocation.getZ()); + getConfig().set("jail.yaw", jailLocation.getYaw()); + getConfig().set("jail.pitch", jailLocation.getPitch()); + } + + if (unjailLocation != null) { + getConfig().set("unjail.world", unjailLocation.getWorld().getName()); + getConfig().set("unjail.x", unjailLocation.getX()); + getConfig().set("unjail.y", unjailLocation.getY()); + getConfig().set("unjail.z", unjailLocation.getZ()); + getConfig().set("unjail.yaw", unjailLocation.getYaw()); + getConfig().set("unjail.pitch", unjailLocation.getPitch()); + } + + saveConfig(); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + switch (cmd.getName().toLowerCase()) { + case "setjail": + return handleSetJail(sender, args); + case "setunjail": + return handleSetUnjail(sender, args); + case "jail": + return handleJail(sender, args); + case "unjail": + return handleUnjail(sender, args); + case "jailreload": + return handleReload(sender); + case "jailhelp": + return handleHelp(sender); + default: + return false; + } + } + + private boolean handleSetJail(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command can only be used by players!"); + return true; + } + + Player player = (Player) sender; + if (!player.hasPermission("jailplugin.setjail")) { + player.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); + return true; + } + + if (args.length == 3) { + try { + double x = Double.parseDouble(args[0]); + double y = Double.parseDouble(args[1]); + double z = Double.parseDouble(args[2]); + jailLocation = new Location(player.getWorld(), x, y, z); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "Invalid coordinates! Use: /setjail "); + return true; + } + } else if (args.length == 0) { + jailLocation = player.getLocation(); + } else { + player.sendMessage(ChatColor.RED + "Usage: /setjail or /setjail "); + return true; + } + + saveLocations(); + player.sendMessage(ChatColor.GREEN + "Jail location has been set!"); + return true; + } + + private boolean handleSetUnjail(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command can only be used by players!"); + return true; + } + + Player player = (Player) sender; + if (!player.hasPermission("jailplugin.setunjail")) { + player.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); + return true; + } + + if (args.length == 3) { + try { + double x = Double.parseDouble(args[0]); + double y = Double.parseDouble(args[1]); + double z = Double.parseDouble(args[2]); + unjailLocation = new Location(player.getWorld(), x, y, z); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "Invalid coordinates! Use: /setunjail "); + return true; + } + } else if (args.length == 0) { + unjailLocation = player.getLocation(); + } else { + player.sendMessage(ChatColor.RED + "Usage: /setunjail or /setunjail "); + return true; + } + + saveLocations(); + player.sendMessage(ChatColor.GREEN + "Unjail location has been set!"); + return true; + } + + private boolean handleJail(CommandSender sender, String[] args) { + if (!sender.hasPermission("jailplugin.jail")) { + sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); + return true; + } + + if (jailLocation == null) { + sender.sendMessage(ChatColor.RED + "Jail location has not been set! Use /setjail first."); + return true; + } + + if (args.length != 1) { + sender.sendMessage(ChatColor.RED + "Usage: /jail "); + return true; + } + + Player target = getServer().getPlayer(args[0]); + if (target == null) { + sender.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } + + target.teleport(jailLocation); + target.sendMessage(ChatColor.RED + "You have been jailed!"); + sender.sendMessage(ChatColor.GREEN + "Player " + target.getName() + " has been jailed!"); + return true; + } + + private boolean handleUnjail(CommandSender sender, String[] args) { + if (!sender.hasPermission("jailplugin.unjail")) { + sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); + return true; + } + + if (unjailLocation == null) { + sender.sendMessage(ChatColor.RED + "Unjail location has not been set! Use /setunjail first."); + return true; + } + + if (args.length != 1) { + sender.sendMessage(ChatColor.RED + "Usage: /unjail "); + return true; + } + + Player target = getServer().getPlayer(args[0]); + if (target == null) { + sender.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } + + target.teleport(unjailLocation); + target.sendMessage(ChatColor.GREEN + "You have been released from jail!"); + sender.sendMessage(ChatColor.GREEN + "Player " + target.getName() + " has been released from jail!"); + return true; + } + + private boolean handleReload(CommandSender sender) { + if (!sender.hasPermission("jailplugin.reload")) { + sender.sendMessage(ChatColor.RED + "You don't have permission to reload the configuration!"); + return true; + } + + reloadConfig(); + loadLocations(); + sender.sendMessage(ChatColor.GREEN + "JailPlugin configuration reloaded!"); + return true; + } + + private boolean handleHelp(CommandSender sender) { + sender.sendMessage(ChatColor.YELLOW + "JailPlugin Commands:"); + sender.sendMessage(ChatColor.GREEN + "/setjail [x y z]" + ChatColor.WHITE + " - Set the jail location."); + sender.sendMessage(ChatColor.GREEN + "/setunjail [x y z]" + ChatColor.WHITE + " - Set the unjail location."); + sender.sendMessage(ChatColor.GREEN + "/jail " + ChatColor.WHITE + " - Jail a player."); + sender.sendMessage(ChatColor.GREEN + "/unjail " + ChatColor.WHITE + " - Unjail a player."); + sender.sendMessage(ChatColor.GREEN + "/jailreload" + ChatColor.WHITE + " - Reload the plugin configuration."); + sender.sendMessage(ChatColor.GREEN + "/jailhelp" + ChatColor.WHITE + " - Show this help message."); + return true; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..9e0fdf8 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,15 @@ +jail: + world: world + x: 0.0 + y: 64.0 + z: 0.0 + yaw: 0.0 + pitch: 0.0 + +unjail: + world: world + x: 0.0 + y: 64.0 + z: 0.0 + yaw: 0.0 + pitch: 0.0 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..d4f7256 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,45 @@ +name: JailPlugin +version: '1.0' +main: com.example.jailplugin.JailPlugin +api-version: '1.21' +commands: + setjail: + description: Set the jail location + usage: / [x y z] + permission: jailplugin.setjail + setunjail: + description: Set the unjail location + usage: / [x y z] + permission: jailplugin.setunjail + jail: + description: Teleport a player to jail + usage: / + permission: jailplugin.jail + unjail: + description: Release a player from jail + usage: / + permission: jailplugin.unjail + jailreload: + description: Reload the JailPlugin configuration + usage: / + permission: jailplugin.reload + jailhelp: + description: Display help for JailPlugin commands + usage: / + +permissions: + jailplugin.setjail: + description: Allows setting the jail location + default: op + jailplugin.setunjail: + description: Allows setting the unjail location + default: op + jailplugin.jail: + description: Allows jailing other players + default: op + jailplugin.unjail: + description: Allows releasing players from jail + default: op + jailplugin.reload: + description: Allows reloading the plugin configuration + default: op