Skip to content

Commit

Permalink
Finish up most important things
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Aug 31, 2022
1 parent 3c58c88 commit cd78d7f
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 25 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.technicjelle</groupId>
<artifactId>bluemap-playercontrol</artifactId>
<version>0.0.1</version>
<version>1.0.0-BETA</version>
<packaging>jar</packaging>

<name>BlueMapPlayerControl</name>
Expand Down Expand Up @@ -83,7 +83,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -31,7 +26,6 @@ public void onEnable() {

@Override
public void onDisable() {
// Plugin shutdown logic
getLogger().info("BlueMapPlayerControl disabled");
}
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return null;
List<String> 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");
}
}
38 changes: 35 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
usage: /<command> [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

0 comments on commit cd78d7f

Please sign in to comment.