From bf136555af71ffdf10c848b1f5c06a5015dcf3b3 Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Sun, 23 Mar 2014 12:33:46 +0100 Subject: [PATCH] Added a config option to determine the minimum access level to run Opis at all. --- mcp/mobius/opis/commands/client/CommandOpis.java | 12 ++++++++++++ mcp/mobius/opis/modOpis.java | 6 +++++- mcp/mobius/opis/network/enums/DataReq.java | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mcp/mobius/opis/commands/client/CommandOpis.java b/mcp/mobius/opis/commands/client/CommandOpis.java index a0d5a77..63f0ce6 100644 --- a/mcp/mobius/opis/commands/client/CommandOpis.java +++ b/mcp/mobius/opis/commands/client/CommandOpis.java @@ -8,11 +8,13 @@ import mcp.mobius.opis.events.PlayerTracker; import mcp.mobius.opis.network.DataReqHandler; import mcp.mobius.opis.network.OpisPacketHandler; import mcp.mobius.opis.network.enums.ClientCommand; +import mcp.mobius.opis.network.enums.DataReq; import mcp.mobius.opis.network.server.Packet_ClientCommand; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatMessageComponent; public class CommandOpis extends CommandBase { @@ -28,6 +30,16 @@ public class CommandOpis extends CommandBase { @Override public void processCommand(ICommandSender icommandsender, String[] astring) { + if (!(icommandsender instanceof Player)){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("You are not a normal client and can't open the Swing interface.")); + return; + } + + if (!DataReq.COMMAND_OPEN_SWING.canPlayerUseCommand((Player)icommandsender)){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("Your access level prevents you from doing that.")); + return; + } + PlayerTracker.instance().playersSwing.add((Player)icommandsender); PlayerTracker.instance().playersOpis.add((Player)icommandsender); ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ClientCommand.create(ClientCommand.SHOW_SWING)); diff --git a/mcp/mobius/opis/modOpis.java b/mcp/mobius/opis/modOpis.java index 288e6d3..4c46156 100644 --- a/mcp/mobius/opis/modOpis.java +++ b/mcp/mobius/opis/modOpis.java @@ -92,6 +92,7 @@ public class modOpis { public static String commentTables = "Minimum access level to be able to view tables in /opis command. Valid values : NONE, PRIVILEGED, ADMIN"; public static String commentOverlays = "Minimum access level to be able to show overlays in MapWriter. Valid values : NONE, PRIVILEGED, ADMIN"; + public static String commentOpis = "Minimum access level to be open Opis interface. Valid values : NONE, PRIVILEGED, ADMIN"; public static String commentPrivileged = "List of players with PRIVILEGED access level."; @EventHandler @@ -107,11 +108,14 @@ public class modOpis { String[] users = config.get("ACCESS_RIGHTS", "privileged", new String[]{}, commentPrivileged).getStringList(); AccessLevel minTables = AccessLevel.PRIVILEGED; AccessLevel minOverlays = AccessLevel.PRIVILEGED; - try{ minTables = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "tables", "NONE", commentTables).getString()); } catch (IllegalArgumentException e){} + AccessLevel openOpis = AccessLevel.PRIVILEGED; + try{ openOpis = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "opis", "NONE", commentTables).getString()); } catch (IllegalArgumentException e){} + try{ minTables = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "tables", "NONE", commentTables).getString()); } catch (IllegalArgumentException e){} try{ minOverlays = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "overlays", "NONE", commentOverlays).getString()); } catch (IllegalArgumentException e){} DataReq.setTablesMinimumLevel(minTables); DataReq.setOverlaysMinimumLevel(minOverlays); + DataReq.setOpisMinimumLevel(openOpis); for (String s : users) PlayerTracker.instance().addPrivilegedPlayer(s,false); diff --git a/mcp/mobius/opis/network/enums/DataReq.java b/mcp/mobius/opis/network/enums/DataReq.java index 69f71ee..c9671bf 100644 --- a/mcp/mobius/opis/network/enums/DataReq.java +++ b/mcp/mobius/opis/network/enums/DataReq.java @@ -48,6 +48,7 @@ public enum DataReq { COMMAND_FILTERING_FALSE, COMMAND_UNREGISTER, COMMAND_UNREGISTER_SWING, + COMMAND_OPEN_SWING, OVERLAY_CHUNK_ENTITIES, OVERLAY_CHUNK_TIMING; @@ -95,4 +96,8 @@ public enum DataReq { DataReq.LIST_CHUNK_LOADED.setAccessLevel(level); DataReq.LIST_CHUNK_TICKETS.setAccessLevel(level); } + + public static void setOpisMinimumLevel(AccessLevel level){ + DataReq.COMMAND_OPEN_SWING.setAccessLevel(level); + } }