mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Get 1.13.2 command handling working
This commit is contained in:
parent
80f8aca6f7
commit
0cb59d23a4
@ -103,13 +103,14 @@ public class DynmapMod
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onServerStarting(FMLServerStartingEvent event) {
|
public void onServerStarting(FMLServerStartingEvent event) {
|
||||||
server = event.getServer();
|
server = event.getServer();
|
||||||
}
|
if(plugin == null)
|
||||||
|
plugin = proxy.startServer(server);
|
||||||
|
plugin.onStarting(event.getCommandDispatcher());
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onServerStarted(FMLServerStartedEvent event) {
|
public void onServerStarted(FMLServerStartedEvent event) {
|
||||||
DynmapCommonAPIListener.register(new APICallback());
|
DynmapCommonAPIListener.register(new APICallback());
|
||||||
if(plugin == null)
|
|
||||||
plugin = proxy.startServer(server);
|
|
||||||
plugin.serverStarted();
|
plugin.serverStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ import net.minecraft.block.state.IBlockState;
|
|||||||
import net.minecraft.command.CommandException;
|
import net.minecraft.command.CommandException;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.command.ICommandSource;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
@ -120,7 +119,11 @@ import com.google.gson.GsonBuilder;
|
|||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
|
||||||
import net.minecraft.state.IProperty;
|
import net.minecraft.state.IProperty;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
@ -448,24 +451,20 @@ public class DynmapPlugin
|
|||||||
return (server.isSinglePlayer() && player.equalsIgnoreCase(server.getServerOwner()));
|
return (server.isSinglePlayer() && player.equalsIgnoreCase(server.getServerOwner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPerm(ICommandSource sender, String permission) {
|
private boolean hasPerm(EntityPlayer psender, String permission) {
|
||||||
PermissionsHandler ph = PermissionsHandler.getHandler();
|
PermissionsHandler ph = PermissionsHandler.getHandler();
|
||||||
if(ph != null) {
|
if((psender != null) && ph.hasPermission(psender.getEntity().getName().getString(), permission)) {
|
||||||
if((sender instanceof EntityPlayer) && ph.hasPermission(((EntityPlayer)sender).getEntity().getName().getString(), permission)) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return permissions.has(sender, permission);
|
return permissions.has(psender, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPermNode(ICommandSource sender, String permission) {
|
private boolean hasPermNode(EntityPlayer psender, String permission) {
|
||||||
PermissionsHandler ph = PermissionsHandler.getHandler();
|
PermissionsHandler ph = PermissionsHandler.getHandler();
|
||||||
if(ph != null) {
|
if((psender != null) && ph.hasPermissionNode(psender.getEntity().getName().getString(), permission)) {
|
||||||
if((sender instanceof EntityPlayer) && ph.hasPermissionNode(((EntityPlayer)sender).getEntity().getName().getString(), permission)) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return permissions.hasPermissionNode(sender, permission);
|
return permissions.hasPermissionNode(psender, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
private Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||||
@ -1309,13 +1308,13 @@ public class DynmapPlugin
|
|||||||
/* Handler for generic console command sender */
|
/* Handler for generic console command sender */
|
||||||
public class ForgeCommandSender implements DynmapCommandSender
|
public class ForgeCommandSender implements DynmapCommandSender
|
||||||
{
|
{
|
||||||
private ICommandSource sender;
|
private CommandSource sender;
|
||||||
|
|
||||||
protected ForgeCommandSender() {
|
protected ForgeCommandSender() {
|
||||||
sender = null;
|
sender = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForgeCommandSender(ICommandSource send)
|
public ForgeCommandSender(CommandSource send)
|
||||||
{
|
{
|
||||||
sender = send;
|
sender = send;
|
||||||
}
|
}
|
||||||
@ -1331,7 +1330,7 @@ public class DynmapPlugin
|
|||||||
{
|
{
|
||||||
if(sender != null) {
|
if(sender != null) {
|
||||||
ITextComponent ichatcomponent = new TextComponentString(msg);
|
ITextComponent ichatcomponent = new TextComponentString(msg);
|
||||||
sender.sendMessage(ichatcomponent);
|
sender.sendFeedback(ichatcomponent, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1435,6 +1434,31 @@ public class DynmapPlugin
|
|||||||
DynmapCommonAPIListener.apiInitialized(core);
|
DynmapCommonAPIListener.apiInitialized(core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int test(CommandSource source) throws CommandSyntaxException
|
||||||
|
{
|
||||||
|
System.out.println(source.toString());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DynmapCommand dynmapCmd;
|
||||||
|
private DmapCommand dmapCmd;
|
||||||
|
private DmarkerCommand dmarkerCmd;
|
||||||
|
private DynmapExpCommand dynmapexpCmd;
|
||||||
|
|
||||||
|
public void onStarting(CommandDispatcher<CommandSource> cd) {
|
||||||
|
/* Register command hander */
|
||||||
|
dynmapCmd = new DynmapCommand(this);
|
||||||
|
dmapCmd = new DmapCommand(this);
|
||||||
|
dmarkerCmd = new DmarkerCommand(this);
|
||||||
|
dynmapexpCmd = new DynmapExpCommand(this);
|
||||||
|
dynmapCmd.register(cd);
|
||||||
|
dmapCmd.register(cd);
|
||||||
|
dmarkerCmd.register(cd);
|
||||||
|
dynmapexpCmd.register(cd);
|
||||||
|
|
||||||
|
Log.info("Register commands");
|
||||||
|
}
|
||||||
|
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
initializeBlockStates();
|
initializeBlockStates();
|
||||||
/* Enable core */
|
/* Enable core */
|
||||||
@ -1487,14 +1511,6 @@ public class DynmapPlugin
|
|||||||
/* Register our update trigger events */
|
/* Register our update trigger events */
|
||||||
registerEvents();
|
registerEvents();
|
||||||
Log.info("Register events");
|
Log.info("Register events");
|
||||||
/* Register command hander */
|
|
||||||
Commands cm = server.getCommandManager();
|
|
||||||
cm.getDispatcher().register(new DynmapCommand(this));
|
|
||||||
cm.getDispatcher().register(new DmapCommand(this));
|
|
||||||
cm.getDispatcher().register(new DmarkerCommand(this));
|
|
||||||
cm.getDispatcher().register(new DynmapExpCommand(this));
|
|
||||||
|
|
||||||
Log.info("Register commands");
|
|
||||||
|
|
||||||
/* Submit metrics to mcstats.org */
|
/* Submit metrics to mcstats.org */
|
||||||
initMetrics();
|
initMetrics();
|
||||||
@ -1531,13 +1547,19 @@ public class DynmapPlugin
|
|||||||
Log.info("Disabled");
|
Log.info("Disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCommand(ICommandSource sender, String cmd, String[] args)
|
void onCommand(CommandSource sender, String cmd, String[] args)
|
||||||
{
|
{
|
||||||
DynmapCommandSender dsender;
|
DynmapCommandSender dsender;
|
||||||
|
EntityPlayer psender;
|
||||||
|
try {
|
||||||
|
psender = sender.asPlayer();
|
||||||
|
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException x) {
|
||||||
|
psender = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (sender instanceof EntityPlayer)
|
if (psender != null)
|
||||||
{
|
{
|
||||||
dsender = getOrAddPlayer((EntityPlayer)sender);
|
dsender = new ForgePlayer(psender);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2017,29 +2039,39 @@ public class DynmapPlugin
|
|||||||
core.serverStarted();
|
core.serverStarted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public MinecraftServer getMCServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynmapCommandHandler extends LiteralArgumentBuilder<CommandSource>
|
class DynmapCommandHandler
|
||||||
{
|
{
|
||||||
private String cmd;
|
private String cmd;
|
||||||
private DynmapPlugin plugin;
|
private DynmapPlugin plugin;
|
||||||
|
|
||||||
public DynmapCommandHandler(String cmd, DynmapPlugin p)
|
public DynmapCommandHandler(String cmd, DynmapPlugin p)
|
||||||
{
|
{
|
||||||
super(cmd);
|
|
||||||
this.cmd = cmd;
|
this.cmd = cmd;
|
||||||
this.plugin = p;
|
this.plugin = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
public void register(CommandDispatcher<CommandSource> cd) {
|
||||||
public void execute(MinecraftServer server, ICommandSource sender,
|
cd.register(Commands.literal(cmd).
|
||||||
String[] args) throws CommandException {
|
then(RequiredArgumentBuilder.<CommandSource, String> argument("args", StringArgumentType.greedyString()).
|
||||||
Log.info("execute " + cmd + " args=" + args.toString());
|
executes((ctx) -> this.execute(plugin.getMCServer(), ctx.getSource(), ctx.getInput()))).
|
||||||
plugin.onCommand(sender, cmd, args);
|
executes((ctx) -> this.execute(plugin.getMCServer(), ctx.getSource(), ctx.getInput())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
public String getUsage(ICommandSource arg0) {
|
public int execute(MinecraftServer server, CommandSource sender,
|
||||||
|
String cmdline) throws CommandException {
|
||||||
|
String[] args = cmdline.split("\\s+");
|
||||||
|
plugin.onCommand(sender, cmd, Arrays.copyOfRange(args, 1, args.length));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
public String getUsage(CommandSource arg0) {
|
||||||
return "Run /" + cmd + " help for details on using command";
|
return "Run /" + cmd + " help for details on using command";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.command.ICommandSource;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
import org.dynmap.ConfigurationNode;
|
import org.dynmap.ConfigurationNode;
|
||||||
@ -85,17 +84,17 @@ public class FilePermissions implements PermissionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean has(ICommandSource sender, String permission) {
|
public boolean has(EntityPlayer psender, String permission) {
|
||||||
if(sender instanceof EntityPlayer) {
|
if(psender != null) {
|
||||||
String n = ((EntityPlayer) sender).getName().getString().toLowerCase();
|
String n = psender.getName().getString().toLowerCase();
|
||||||
return hasPerm(n, permission);
|
return hasPerm(n, permission);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermissionNode(ICommandSource sender, String permission) {
|
public boolean hasPermissionNode(EntityPlayer psender, String permission) {
|
||||||
if(sender instanceof EntityPlayer) {
|
if(psender != null) {
|
||||||
String player = ((EntityPlayer) sender).getName().getString().toLowerCase();
|
String player = psender.getName().getString().toLowerCase();
|
||||||
return DynmapPlugin.plugin.isOp(player);
|
return DynmapPlugin.plugin.isOp(player);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,7 +3,6 @@ package org.dynmap.forge_1_13_2.permissions;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.command.ICommandSource;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
import org.dynmap.Log;
|
import org.dynmap.Log;
|
||||||
@ -33,19 +32,19 @@ public class OpPermissions implements PermissionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean has(ICommandSource sender, String permission) {
|
public boolean has(EntityPlayer psender, String permission) {
|
||||||
if(sender instanceof EntityPlayer) {
|
if(psender != null) {
|
||||||
if(usrCommands.contains(permission)) {
|
if(usrCommands.contains(permission)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return DynmapPlugin.plugin.isOp(((EntityPlayer)sender).getEntity().getName().getString());
|
return DynmapPlugin.plugin.isOp(psender.getEntity().getName().getString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermissionNode(ICommandSource sender, String permission) {
|
public boolean hasPermissionNode(EntityPlayer psender, String permission) {
|
||||||
if(sender instanceof EntityPlayer) {
|
if(psender != null) {
|
||||||
return DynmapPlugin.plugin.isOp(((EntityPlayer)sender).getEntity().getName().getString());
|
return DynmapPlugin.plugin.isOp(psender.getEntity().getName().getString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ package org.dynmap.forge_1_13_2.permissions;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.command.ICommandSource;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public interface PermissionProvider {
|
public interface PermissionProvider {
|
||||||
boolean has(ICommandSource sender, String permission);
|
boolean has(EntityPlayer sender, String permission);
|
||||||
boolean hasPermissionNode(ICommandSource sender, String permission);
|
boolean hasPermissionNode(EntityPlayer sender, String permission);
|
||||||
|
|
||||||
Set<String> hasOfflinePermissions(String player, Set<String> perms);
|
Set<String> hasOfflinePermissions(String player, Set<String> perms);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user