Added a config option to determine the minimum access level to run Opis at all.

This commit is contained in:
ProfMobius committed 2014-03-23 12:33:46 +01:00
1 parent 7c4568a2eb
commit bf136555af
3 files changed
+22 -1

No files matched your search

@@ -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));
+5 -1
View File
@@ -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);
@@ -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);
}
}