mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-12-28 11:59:21 +01:00
Complete bukkit plugin implementation
This commit is contained in:
parent
3daab62714
commit
0bb50f8044
@ -17,6 +17,7 @@ public BukkitCommandSource(CommandSender delegate) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(Text text) {
|
public void sendMessage(Text text) {
|
||||||
|
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance(), () -> {
|
||||||
if (delegate instanceof Player) {
|
if (delegate instanceof Player) {
|
||||||
Player player = (Player) delegate;
|
Player player = (Player) delegate;
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ public void sendMessage(Text text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delegate.sendMessage(text.toFormattingCodedString('§'));
|
delegate.sendMessage(text.toFormattingCodedString('§'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,209 @@
|
|||||||
package de.bluecolored.bluemap.bukkit;
|
package de.bluecolored.bluemap.bukkit;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.flowpowered.math.vector.Vector3i;
|
||||||
|
|
||||||
import de.bluecolored.bluemap.common.plugin.Commands;
|
import de.bluecolored.bluemap.common.plugin.Commands;
|
||||||
|
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
|
||||||
|
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||||
|
import de.bluecolored.bluemap.common.plugin.text.TextColor;
|
||||||
|
|
||||||
public class BukkitCommands implements CommandExecutor {
|
public class BukkitCommands implements CommandExecutor {
|
||||||
|
|
||||||
private Commands commands;
|
private Commands bluemapCommands;
|
||||||
|
|
||||||
|
private Collection<Command> commands;
|
||||||
|
|
||||||
public BukkitCommands(Commands commands) {
|
public BukkitCommands(Commands commands) {
|
||||||
this.commands = commands;
|
this.bluemapCommands = commands;
|
||||||
|
this.commands = new ArrayList<>();
|
||||||
|
initCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initCommands() {
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
commands.executeRootCommand(new BukkitCommandSource(sender));
|
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.status") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 0) return false;
|
||||||
|
|
||||||
|
bluemapCommands.executeRootCommand(source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.reload", "reload") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 0) return false;
|
||||||
|
|
||||||
|
bluemapCommands.executeReloadCommand(source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.pause", "pause") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 0) return false;
|
||||||
|
|
||||||
|
bluemapCommands.executePauseCommand(source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.resume", "resume") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 0) return false;
|
||||||
|
|
||||||
|
bluemapCommands.executeResumeCommand(source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.rendertask.create.world", "render") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length > 1) return false;
|
||||||
|
|
||||||
|
World world;
|
||||||
|
if (args.length == 1) {
|
||||||
|
world = Bukkit.getWorld(args[0]);
|
||||||
|
if (world == null) {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "There is no world named '" + args[0] + "'!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
world = player.getWorld();
|
||||||
|
} else {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "Since you are not a player, you have to specify a world!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bluemapCommands.executeRenderWorldCommand(source, world.getUID());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.rendertask.prioritize", "render", "prioritize") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 1) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(args[0]);
|
||||||
|
bluemapCommands.executePrioritizeRenderTaskCommand(source, uuid);
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "'" + args[0] + "' is not a valid UUID!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.rendertask.remove", "render", "remove") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (args.length != 1) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(args[0]);
|
||||||
|
bluemapCommands.executeRemoveRenderTaskCommand(source, uuid);
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "'" + args[0] + "' is not a valid UUID!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(new Command("bluemap.debug", "debug") {
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, CommandSource source, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "You have to be a player to use this command!"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
UUID world = player.getWorld().getUID();
|
||||||
|
Vector3i pos = new Vector3i(
|
||||||
|
player.getLocation().getBlockX(),
|
||||||
|
player.getLocation().getBlockY(),
|
||||||
|
player.getLocation().getBlockZ()
|
||||||
|
);
|
||||||
|
|
||||||
|
bluemapCommands.executeDebugCommand(source, world, pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String label, String[] args) {
|
||||||
|
int max = -1;
|
||||||
|
Command maxCommand = null;
|
||||||
|
for (Command command : commands) {
|
||||||
|
int matchSize = command.matches(args);
|
||||||
|
if (matchSize > max) {
|
||||||
|
maxCommand = command;
|
||||||
|
max = matchSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxCommand == null) return false;
|
||||||
|
|
||||||
|
BukkitCommandSource source = new BukkitCommandSource(sender);
|
||||||
|
|
||||||
|
if (!maxCommand.checkPermission(sender)) {
|
||||||
|
source.sendMessage(Text.of(TextColor.RED, "You don't have permission to use this command!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxCommand.execute(sender, source, Arrays.copyOfRange(args, max, args.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
private abstract class Command {
|
||||||
|
|
||||||
|
private String[] command;
|
||||||
|
private String permission;
|
||||||
|
|
||||||
|
public Command(String permission, String... command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean execute(CommandSender sender, CommandSource source, String[] args);
|
||||||
|
|
||||||
|
public int matches(String[] args) {
|
||||||
|
if (args.length < command.length) return -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < command.length; i++) {
|
||||||
|
if (!args[i].equalsIgnoreCase(command[i])) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return command.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkPermission(CommandSender sender) {
|
||||||
|
if (sender.isOp()) return true;
|
||||||
|
return sender.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,12 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.bstats.bukkit.MetricsLite;
|
import org.bstats.bukkit.MetricsLite;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -15,6 +19,8 @@
|
|||||||
|
|
||||||
public class BukkitPlugin extends JavaPlugin implements ServerInterface {
|
public class BukkitPlugin extends JavaPlugin implements ServerInterface {
|
||||||
|
|
||||||
|
private static BukkitPlugin instance;
|
||||||
|
|
||||||
private Plugin bluemap;
|
private Plugin bluemap;
|
||||||
private EventForwarder eventForwarder;
|
private EventForwarder eventForwarder;
|
||||||
private BukkitCommands commands;
|
private BukkitCommands commands;
|
||||||
@ -25,6 +31,8 @@ public BukkitPlugin() {
|
|||||||
this.eventForwarder = new EventForwarder();
|
this.eventForwarder = new EventForwarder();
|
||||||
this.bluemap = new Plugin("bukkit", this);
|
this.bluemap = new Plugin("bukkit", this);
|
||||||
this.commands = new BukkitCommands(bluemap.getCommands());
|
this.commands = new BukkitCommands(bluemap.getCommands());
|
||||||
|
|
||||||
|
BukkitPlugin.instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,9 +72,30 @@ public void unregisterAllListeners() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUIDForWorld(File worldFolder) throws IOException {
|
public UUID getUUIDForWorld(File worldFolder) throws IOException {
|
||||||
worldFolder = worldFolder.getCanonicalFile();
|
final File normalizedWorldFolder = worldFolder.getCanonicalFile();
|
||||||
|
|
||||||
|
Future<UUID> futureUUID;
|
||||||
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
|
futureUUID = Bukkit.getScheduler().callSyncMethod(BukkitPlugin.getInstance(), () -> getUUIDForWorldSync(normalizedWorldFolder));
|
||||||
|
} else {
|
||||||
|
futureUUID = CompletableFuture.completedFuture(getUUIDForWorldSync(normalizedWorldFolder));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return futureUUID.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
if (e.getCause() instanceof IOException) {
|
||||||
|
throw (IOException) e.getCause();
|
||||||
|
} else {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID getUUIDForWorldSync (File worldFolder) throws IOException {
|
||||||
for (World world : getServer().getWorlds()) {
|
for (World world : getServer().getWorlds()) {
|
||||||
Logger.global.logInfo("Found world-folder: " + world.getWorldFolder().getCanonicalPath());
|
|
||||||
if (worldFolder.equals(world.getWorldFolder().getCanonicalFile())) return world.getUID();
|
if (worldFolder.equals(world.getWorldFolder().getCanonicalFile())) return world.getUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,4 +111,8 @@ public Plugin getBlueMap() {
|
|||||||
return bluemap;
|
return bluemap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BukkitPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,46 @@
|
|||||||
name: BlueMap
|
name: BlueMap
|
||||||
|
description: "A 3d-map of your Minecraft worlds view-able in your browser using three.js (WebGL)"
|
||||||
main: de.bluecolored.bluemap.bukkit.BukkitPlugin
|
main: de.bluecolored.bluemap.bukkit.BukkitPlugin
|
||||||
version: 0.2.1
|
version: 0.2.1
|
||||||
author: Blue (TBlueF / Lukas Rieger)
|
author: "Blue (TBlueF / Lukas Rieger)"
|
||||||
authors: [Blue (TBlueF / Lukas Rieger)]
|
authors: [Blue (TBlueF / Lukas Rieger)]
|
||||||
website: "https://github.com/BlueMap-Minecraft"
|
website: "https://github.com/BlueMap-Minecraft"
|
||||||
commands:
|
commands:
|
||||||
bluemap:
|
bluemap:
|
||||||
|
description: Root command for all bluemap commands
|
||||||
|
permission: bluemap
|
||||||
|
usage: |
|
||||||
|
/<command>
|
||||||
|
/<command> reload
|
||||||
|
/<command> pause
|
||||||
|
/<command> resume
|
||||||
|
/<command> render [world]
|
||||||
|
/<command> debug
|
||||||
|
permissions:
|
||||||
|
bluemap.*:
|
||||||
|
children:
|
||||||
|
bluemap.status: true
|
||||||
|
bluemap.reload: true
|
||||||
|
bluemap.pause: true
|
||||||
|
bluemap.resume: true
|
||||||
|
bluemap.rendertask.create.world: true
|
||||||
|
bluemap.rendertask.prioritize: true
|
||||||
|
bluemap.rendertask.remove: true
|
||||||
|
bluemap.debug: true
|
||||||
|
default: op
|
||||||
|
bluemap.status:
|
||||||
|
default: op
|
||||||
|
bluemap.reload:
|
||||||
|
default: op
|
||||||
|
bluemap.pause:
|
||||||
|
default: op
|
||||||
|
bluemap.resume:
|
||||||
|
default: op
|
||||||
|
bluemap.rendertask.create.world:
|
||||||
|
default: op
|
||||||
|
bluemap.rendertask.prioritize:
|
||||||
|
default: op
|
||||||
|
bluemap.rendertask.remove:
|
||||||
|
default: op
|
||||||
|
bluemap.debug:
|
||||||
|
default: op
|
Loading…
Reference in New Issue
Block a user