From 911abcbd156abb7be2c307f81962c2c8f5bc07ed Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 8 Jun 2023 19:21:14 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 38 +++++++++++++ .idea/.gitignore | 3 ++ .idea/encodings.xml | 7 +++ .idea/misc.xml | 19 +++++++ .idea/vcs.xml | 6 +++ pom.xml | 30 +++++++++++ .../nCoords/commands/CoordsCommand.java | 54 +++++++++++++++++++ src/main/java/io/natfan/nCoords/nCoords.java | 20 +++++++ src/main/resources/plugin.yml | 8 +++ 9 files changed, 185 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/io/natfan/nCoords/commands/CoordsCommand.java create mode 100644 src/main/java/io/natfan/nCoords/nCoords.java create mode 100644 src/main/resources/plugin.yml 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/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..6e62f9d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..495019f --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + io.natfan + nCoords + 1.0-SNAPSHOT + + + 18 + 18 + UTF-8 + + + + org.spigotmc + spigot-api + 1.19.4-R0.1-SNAPSHOT + + + org.jetbrains + annotations + RELEASE + compile + + + + \ No newline at end of file diff --git a/src/main/java/io/natfan/nCoords/commands/CoordsCommand.java b/src/main/java/io/natfan/nCoords/commands/CoordsCommand.java new file mode 100644 index 0000000..654392c --- /dev/null +++ b/src/main/java/io/natfan/nCoords/commands/CoordsCommand.java @@ -0,0 +1,54 @@ +package io.natfan.nCoords.commands; + +import io.natfan.nCoords.nCoords; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class CoordsCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (sender instanceof ConsoleCommandSender && args.length == 0) { + sender.sendMessage(nCoords.NewErrorMessage("Console doesn't have any coordinates! Try specifying a user.")); + return true; + } + + Player player; + boolean isSelf = true; + if (args.length == 0) player = (Player) sender; + else { + isSelf = false; + player = Bukkit.getPlayer(args[0]); + } + + if (player == null) { + sender.sendMessage(nCoords.NewErrorMessage("%s does not exist".formatted(args[0]))); + return true; + } + boolean hasPermission = sender.isOp() || sender.hasPermission("ncoords.other"); + if (!isSelf && !hasPermission) { + sender.sendMessage(nCoords.NewErrorMessage("You do not have permission to perform this command.")); + return true; + } + Location location = player.getLocation(); + World world = location.getWorld(); + if (world == null) return true; + boolean isNotMainWorld = !world.isNatural(); + + String message = "X: %d, Y: %d, Z: %d".formatted(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + if (isNotMainWorld) message += " (%s)".formatted(location.getWorld().getName()); + + if (isSelf) sender.sendMessage(ChatColor.GREEN + "Sending your coordinates..."); + else sender.sendMessage(ChatColor.GREEN + "Sending " + ChatColor.DARK_GREEN + player.getName() + ChatColor.GREEN + "'s coordinates..."); + + player.chat(message); + return true; + } +} diff --git a/src/main/java/io/natfan/nCoords/nCoords.java b/src/main/java/io/natfan/nCoords/nCoords.java new file mode 100644 index 0000000..3844d2d --- /dev/null +++ b/src/main/java/io/natfan/nCoords/nCoords.java @@ -0,0 +1,20 @@ +package io.natfan.nCoords; + +import io.natfan.nCoords.commands.CoordsCommand; +import org.bukkit.ChatColor; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Objects; + +public class nCoords extends JavaPlugin { + @Override + public void onEnable() { + Objects.requireNonNull(this.getCommand("coords")).setExecutor(new CoordsCommand()); + } + + public void onDisable() {} + + public static String NewErrorMessage(String message) { + return ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + message; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..b62e222 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: 'nCoords' +version: '1.0.0-SNAPSHOT' +main: io.natfan.nCoords.nCoords +api-version: '1.18' +commands: + coords: + description: Prints your current coordinates in chat. + usage: / \ No newline at end of file