commit 3ad5610dbf364812bd500401bc0f4eb4d939ac4c Author: BlueFox Date: Sun May 19 10:56:00 2024 +0200 Initialized git repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4788b4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +target/ + +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next + +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cda3f23 --- /dev/null +++ b/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + de.privacynerd + Positions + 1.1.2 + jar + + Positions + + + 1.8 + UTF-8 + + + + + + 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 + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + 1.20.4-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/de/privacynerd/positions/Positions.java b/src/main/java/de/privacynerd/positions/Positions.java new file mode 100644 index 0000000..4856603 --- /dev/null +++ b/src/main/java/de/privacynerd/positions/Positions.java @@ -0,0 +1,150 @@ +package de.privacynerd.positions; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +class PositionCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + YamlConfiguration positions = new YamlConfiguration(); + Player player = (Player) sender; + try { + positions.load("positions.yaml"); + } catch (IOException e) { + try { + new File("positions.yaml").createNewFile(); + player.sendMessage(Positions.PREFIX + ChatColor.RED + "An internal error occurred. Please try to execute the command again."); + return true; + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } catch (InvalidConfigurationException e) { + new File("positions.yaml").delete(); + try { + new File("positions.yaml").createNewFile(); + + player.sendMessage(Positions.PREFIX + ChatColor.RED + "An internal error occurred. Please try to execute the command again."); + return true; + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + List positionList = (List) positions.getList("positions"); + if(positionList == null) { + List list = new ArrayList<>(); + positions.set("positions", list); + try {positions.save("positions.yaml");} catch (IOException e) {e.printStackTrace();} // save the configuration + positionList = (List) positions.getList("positions"); + } + + if(args.length == 0) {player.sendMessage(Positions.PREFIX + ChatColor.RED + "You have to specify at least one argument"); return true;} + + if(args[0].equalsIgnoreCase("list")) { + if(positionList.isEmpty()) { + player.sendMessage(Positions.PREFIX + ChatColor.GOLD + "You haven't set any positions to display here!"); + } else { + player.sendMessage(Positions.PREFIX + ChatColor.GREEN + "Available positions:"); + for(String name : positionList) { + Location pos = positions.getLocation(name); + int x = pos.getBlockX(); + int y = pos.getBlockY(); + int z = pos.getBlockZ(); + player.sendMessage(ChatColor.GOLD + name + ": " + ChatColor.RED + x + ChatColor.DARK_GREEN + " " + y + ChatColor.BLUE + " " + z); + } + player.sendMessage(Positions.PREFIX + ChatColor.ITALIC + "Type \"/pos del>\" to delete them."); + } + return true; + } + /*if(args[0].equalsIgnoreCase("show")) { + ArmorStand armorStand = player.getWorld().spawn(player.getLocation(), ArmorStand.class); + armorStand.setVisible(false); + armorStand.setCustomName(ChatColor.GOLD + "POSITION"); + armorStand.setCustomNameVisible(true); + } + if(args[0].equalsIgnoreCase("hide")) { + + }*/ + + //if(!args[0].equalsIgnoreCase("list") && !args[0].equalsIgnoreCase("show") && !args[0].equalsIgnoreCase("hide")) { + if(!args[0].equalsIgnoreCase("list")) { // only save a new position when it's not named list (cause that's another action) + if(positionList.contains(args[0])) { // does the position already exist? + if(args[0].equalsIgnoreCase("positions")) { + player.sendMessage(Positions.PREFIX + ChatColor.RED + "You can't set (or get) the position \"positions\""); + return true; + } else if(args.length==2 && args[1].startsWith("del")) { + positionList.remove(args[0]); + positions.set("positions", positionList); + try {positions.save("positions.yaml");} catch (IOException e) {e.printStackTrace();} // save the configuration + player.sendMessage(Positions.PREFIX + ChatColor.GREEN + "Successfully deleted the position \"" + ChatColor.BLUE + args[0] + ChatColor.GREEN + "\"!"); + return true; + } else { + Location pos = positions.getLocation(args[0]); + int x = pos.getBlockX(); + int y = pos.getBlockY(); + int z = pos.getBlockZ(); + player.sendMessage(Positions.PREFIX + ChatColor.AQUA + "Position \"" + ChatColor.BLUE + args[0] + ChatColor.AQUA + "\": " + ChatColor.RED + x + ChatColor.GREEN + " " + y + ChatColor.BLUE + " " + z); + return true; + } + } else { + if(args[0].equalsIgnoreCase("positions")) { + player.sendMessage(Positions.PREFIX + ChatColor.RED + "You can't set (or get) the position \"positions\""); + return true; + } else { + Location playerPos = player.getLocation(); + positionList.add(args[0]); + positions.set(args[0], playerPos); + positions.set("positions", positionList); + try {positions.save("positions.yaml");} catch (IOException e) {e.printStackTrace();} // save the configuration + player.sendMessage(Positions.PREFIX + ChatColor.GREEN + "Position \"" + ChatColor.BLUE + args[0] + ChatColor.GREEN + "\" has been saved."); + return true; + } + } + } + return true; + } +} + +public final class Positions extends JavaPlugin { + public static String PREFIX = ChatColor.BLUE + "[" + ChatColor.LIGHT_PURPLE + "Positions" + ChatColor.BLUE + "] " + ChatColor.WHITE; + public static Positions INSTANCE; + public Positions() { + INSTANCE = this; + } + + public void log(String msg) { + Bukkit.getConsoleSender().sendMessage(PREFIX + msg); + } + + public void chat(String msg) { + Bukkit.getConsoleSender().sendMessage(PREFIX + msg); + } + + @Override + public void onEnable() { + // Plugin startup logic + log(ChatColor.GREEN + "Plugin has been enabled"); + + Bukkit.getPluginCommand("position").setExecutor(new PositionCommand()); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + log(ChatColor.RED + "Plugin has been disabled"); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..935379f --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: Positions +version: '${project.version}' +main: de.privacynerd.positions.Positions +api-version: '1.20' +description: Plugin which provides the command "pos". See "/help pos"! + +commands: + position: + description: With this command you gain the ability to save your position and get to it later. + usage: /position del; /position ; /position list; + aliases: ["pos"] \ No newline at end of file