From cd78d7fa14926a760abebb898e737e6211c1d5f1 Mon Sep 17 00:00:00 2001
From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com>
Date: Wed, 31 Aug 2022 18:41:40 +0200
Subject: [PATCH] Finish up most important things
---
README.md | 16 ++--
pom.xml | 4 +-
.../BlueMapPlayerControl.java | 10 +--
.../bluemapplayercontrol/commands/BMPC.java | 84 ++++++++++++++++++-
src/main/resources/plugin.yml | 38 ++++++++-
5 files changed, 127 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
index 3176efc..41c1638 100644
--- a/README.md
+++ b/README.md
@@ -3,12 +3,12 @@
Simple [Paper](https://papermc.io/) plugin that allows you to show/hide players on [BlueMap](https://github.com/BlueMap-Minecraft/BlueMap/)
## Commands
-| Command | Usage | Permission |
-|-----------------------|------------------------------------------------|----------------------|
-| `/bmpc` | Allows a player to toggle their own visibility | `bmpc.self.toggle` |
-| `/bmpc hide` | Hides a player's own visibility | `bmpc.self.hide` |
-| `/bmpc show` | Shows a player's own visibility | `bmpc.self.show` |
-| `/bmpc [player]` | Toggles the visibility of any player | `bmpc.others.toggle` |
-| `/bmpc hide [player]` | Hides any player's visibility | `bmpc.others.hide` |
-| `/bmpc show [player]` | Shows any player's visibility | `bmpc.others.show` |
+| Command | Usage | Permission |
+|-----------------------|------------------------------------------------|---------------------------|
+| 🚧 `/bmpc` | Allows a player to toggle their own visibility | `bmpc.self.toggle` |
+| `/bmpc show` | Shows a player's own visibility | `bmpc.self.show` |
+| `/bmpc hide` | Hides a player's own visibility | `bmpc.self.hide` |
+| 🚧 `/bmpc [player]` | Toggles the visibility of any player | `bmpc.others.toggle` (OP) |
+| `/bmpc show [player]` | Shows any player's visibility | `bmpc.others.show` (OP) |
+| `/bmpc hide [player]` | Hides any player's visibility | `bmpc.others.hide` (OP) |
diff --git a/pom.xml b/pom.xml
index d83806d..aca6edd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.technicjelle
bluemap-playercontrol
- 0.0.1
+ 1.0.0-BETA
jar
BlueMapPlayerControl
@@ -83,7 +83,7 @@
org.jetbrains
annotations
- 22.0.0
+ 23.0.0
compile
diff --git a/src/main/java/com/technicjelle/bluemapplayercontrol/BlueMapPlayerControl.java b/src/main/java/com/technicjelle/bluemapplayercontrol/BlueMapPlayerControl.java
index acde95f..c74d125 100644
--- a/src/main/java/com/technicjelle/bluemapplayercontrol/BlueMapPlayerControl.java
+++ b/src/main/java/com/technicjelle/bluemapplayercontrol/BlueMapPlayerControl.java
@@ -1,25 +1,20 @@
package com.technicjelle.bluemapplayercontrol;
import com.technicjelle.bluemapplayercontrol.commands.BMPC;
-import de.bluecolored.bluemap.api.BlueMapAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
@SuppressWarnings("unused")
public final class BlueMapPlayerControl extends JavaPlugin {
+ BMPC executor;
@Override
public void onEnable() {
- // Plugin startup logic
getLogger().info("BlueMapPlayerControl enabled");
- BlueMapAPI.onEnable(blueMapAPI -> {
- getLogger().info("BlueMapAPI enabled");
- getLogger().info("BlueMapAPI version: " + blueMapAPI.getAPIVersion());
- });
PluginCommand bmpc = Bukkit.getPluginCommand("bmpc");
- BMPC executor = new BMPC();
+ executor = new BMPC();
if(bmpc != null) {
bmpc.setExecutor(executor);
bmpc.setTabCompleter(executor);
@@ -31,7 +26,6 @@ public void onEnable() {
@Override
public void onDisable() {
- // Plugin shutdown logic
getLogger().info("BlueMapPlayerControl disabled");
}
}
diff --git a/src/main/java/com/technicjelle/bluemapplayercontrol/commands/BMPC.java b/src/main/java/com/technicjelle/bluemapplayercontrol/commands/BMPC.java
index 9f4c0fc..79de827 100644
--- a/src/main/java/com/technicjelle/bluemapplayercontrol/commands/BMPC.java
+++ b/src/main/java/com/technicjelle/bluemapplayercontrol/commands/BMPC.java
@@ -1,13 +1,15 @@
package com.technicjelle.bluemapplayercontrol.commands;
import de.bluecolored.bluemap.api.BlueMapAPI;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
-import java.util.List;
+import java.util.*;
public class BMPC implements CommandExecutor, TabCompleter {
@@ -19,15 +21,89 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (BlueMapAPI.getInstance().isPresent()) {
BlueMapAPI api = BlueMapAPI.getInstance().get();
- api.getWebApp().setPlayerVisibility(sender.getServer().getPlayerUniqueId(sender.getName()), false);
- return true;
+ // === SELF ===
+ if(sender instanceof Player) { // only players can self
+ UUID senderUUID = sender.getServer().getPlayerUniqueId(sender.getName());
+ if (args.length == 0) {
+ //TODO: Toggle self
+ sender.sendMessage(ChatColor.YELLOW + "This command is not yet implemented. Please specify show/hide");
+ return true;
+ }
+ if (args.length == 1) {
+ if (args[0].equalsIgnoreCase("show")) {
+ api.getWebApp().setPlayerVisibility(senderUUID, true);
+ sender.sendMessage("You are now visible on the map");
+ return true;
+ } else if (args[0].equalsIgnoreCase("hide")) {
+ api.getWebApp().setPlayerVisibility(senderUUID, false);
+ sender.sendMessage("You are now invisible on the map");
+ return true;
+ }
+ }
+ }
+
+ // === OTHER ===
+ Player targetPlayer = sender.getServer().getPlayer(args[args.length - 1]); //if the last argument is a player name
+ if (targetPlayer == null) {
+ if(othersAllowed(sender)) {
+ sender.sendMessage(ChatColor.YELLOW + "Player not found");
+ } else {
+ noPermissionWarning(sender);
+ }
+ return true;
+ } else {
+ if(othersAllowed(sender)) {
+ UUID targetUUID = targetPlayer.getUniqueId();
+ if (args.length == 1) {
+ //TODO: Toggle other
+ sender.sendMessage(ChatColor.YELLOW + "This command is not yet implemented. Please specify show/hide");
+ return true;
+ } else if (args[0].equalsIgnoreCase("show")) {
+ api.getWebApp().setPlayerVisibility(targetUUID, true);
+ sender.sendMessage(targetPlayer.getDisplayName() + " is now visible on the map");
+ return true;
+ } else if (args[0].equalsIgnoreCase("hide")) {
+ api.getWebApp().setPlayerVisibility(targetUUID, false);
+ sender.sendMessage(targetPlayer.getDisplayName() + " is now invisible on the map");
+ return true;
+ }
+ } else {
+ noPermissionWarning(sender);
+ return true;
+ }
+ }
}
+
return false;
}
+ private void noPermissionWarning(CommandSender sender) {
+ sender.sendMessage(ChatColor.RED + "You are don't have permission to change the visibility of others");
+ }
@Override
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
- return null;
+ List completions = new ArrayList<>();
+ if (args.length == 1) {
+ completions.add("show");
+ completions.add("hide");
+ }
+ if (othersAllowed(sender)) {
+ if (sender.getServer().getPlayer(args[0]) == null
+ || args[0].equalsIgnoreCase("show")
+ || args[0].equalsIgnoreCase("hide")
+ || args[0].isBlank()) {
+ if(args.length <= 2) {
+ for (Player player : sender.getServer().getOnlinePlayers()) {
+ completions.add(player.getName());
+ }
+ }
+ }
+ }
+ return completions;
+ }
+
+ private boolean othersAllowed(CommandSender sender) {
+ return sender.isOp() || sender.hasPermission("bmpc.other");
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index a126376..26bd5e8 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -7,8 +7,40 @@ depend:
author: TechnicJelle
description: Adds player hiding functionality to BlueMap
website: https://github.com/TechnicJelle/BlueMapPlayerControl
+
commands:
bmpc:
- usage: /bmpc
- description: Toggles your own visibility on BlueMap
- permission: bmpc.self.toggle
\ No newline at end of file
+ usage: / [hide | show] [player]
+ description: Toggles visibility on BlueMap
+ permission: bmpc
+
+permissions:
+ bmpc:
+ default: true
+ bmpc.*:
+ default: op
+ children:
+ bmpc.self:
+ default: true
+ children:
+ bmpc.self.toggle: true
+ bmpc.self.show: true
+ bmpc.self.hide: true
+ bmpc.others:
+ default: op
+ children:
+ bmpc.others.toggle: true
+ bmpc.others.show: true
+ bmpc.others.hide: true
+ bmpc.self.toggle:
+ default: true
+ bmpc.self.show:
+ default: true
+ bmpc.self.hide:
+ default: true
+ bmpc.others.toggle:
+ default: op
+ bmpc.others.show:
+ default: op
+ bmpc.others.hide:
+ default: op
\ No newline at end of file