From 001ccc3ea1fd2a692e3b8584876546575b59af5e Mon Sep 17 00:00:00 2001 From: Jamie Brassel Date: Fri, 29 Jan 2021 01:13:39 -0500 Subject: [PATCH] Add restrictions to non-op players --- build.gradle | 2 +- src/main/java/cmsc389e/circuitry/Circuitry.java | 1 + .../java/cmsc389e/circuitry/client/EventHandler.java | 12 +++++------- .../cmsc389e/circuitry/common/block/NodeBlock.java | 2 +- .../circuitry/common/command/SetCommand.java | 2 +- .../circuitry/common/command/TestCommand.java | 3 ++- update.json | 5 +++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 7524b78..0772c3b 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'net.minecraftforge.gradle' archivesBaseName = 'circuitry' group = 'cmsc389e.' + archivesBaseName -version = '1.15.2-2.0.0.0' +version = '1.15.2-2.0.1.0' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' diff --git a/src/main/java/cmsc389e/circuitry/Circuitry.java b/src/main/java/cmsc389e/circuitry/Circuitry.java index 91c0123..336926f 100644 --- a/src/main/java/cmsc389e/circuitry/Circuitry.java +++ b/src/main/java/cmsc389e/circuitry/Circuitry.java @@ -81,6 +81,7 @@ public static void onDedicatedServerSetup(FMLDedicatedServerSetupEvent event) { serverProperties.put("generate-structures", falseValue); serverProperties.put("level-type", WorldType.FLAT.getName()); serverProperties.put("spawn-animals", falseValue); + serverProperties.put("spawn-protection", Integer.toString(Integer.MAX_VALUE)); } properties.save(Paths.get("server.properties")); } diff --git a/src/main/java/cmsc389e/circuitry/client/EventHandler.java b/src/main/java/cmsc389e/circuitry/client/EventHandler.java index 1d872c8..da75da1 100644 --- a/src/main/java/cmsc389e/circuitry/client/EventHandler.java +++ b/src/main/java/cmsc389e/circuitry/client/EventHandler.java @@ -53,6 +53,7 @@ @EventBusSubscriber(Dist.CLIENT) public class EventHandler { + private static final Minecraft MINECRAFT = Minecraft.getInstance(); private static final Field WORLD_SEED = ObfuscationReflectionHelper.findField(CreateWorldScreen.class, "field_146329_I"); // worldSeed @@ -65,11 +66,9 @@ private static AlertScreen alert(String msg1, String msg2, String msg3, String b } @SubscribeEvent - @SuppressWarnings("resource") public static void onDrawHighlightBlock(DrawHighlightEvent.HighlightBlock event) { - Minecraft minecraft = Minecraft.getInstance(); - NodeTileEntity entity = NodeTileEntity.get(minecraft.world, event.getTarget().getPos()); - minecraft.ingameGUI.setOverlayMessage(entity == null ? "" : entity.tag, false); + NodeTileEntity entity = NodeTileEntity.get(MINECRAFT.world, event.getTarget().getPos()); + MINECRAFT.ingameGUI.setOverlayMessage(entity == null ? "" : entity.tag, false); } @SubscribeEvent @@ -110,7 +109,6 @@ public static void onGuiOpenEvent(GuiOpenEvent event) throws IllegalAccessExcept } @SubscribeEvent - @SuppressWarnings("resource") public static void onTickClient(TickEvent.ClientTickEvent event) { if (event.phase == Phase.END) { BlockPos pos = null; @@ -118,9 +116,9 @@ public static void onTickClient(TickEvent.ClientTickEvent event) { int pressTime = 0; while (key.binding.isPressed()) pressTime++; - if (pressTime > 0) { + if (pressTime > 0 && MINECRAFT.player.hasPermissionLevel(4)) { if (pos == null) { - RayTraceResult result = Minecraft.getInstance().objectMouseOver; + RayTraceResult result = MINECRAFT.objectMouseOver; if (result != null && result.getType() == Type.BLOCK) pos = ((BlockRayTraceResult) result).getPos(); } diff --git a/src/main/java/cmsc389e/circuitry/common/block/NodeBlock.java b/src/main/java/cmsc389e/circuitry/common/block/NodeBlock.java index 32c0491..9fa1500 100644 --- a/src/main/java/cmsc389e/circuitry/common/block/NodeBlock.java +++ b/src/main/java/cmsc389e/circuitry/common/block/NodeBlock.java @@ -58,7 +58,7 @@ public boolean hasTileEntity(BlockState state) { @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { - if (!worldIn.isRemote) + if (!worldIn.isRemote && player.hasPermissionLevel(4)) ((NodeTileEntity) worldIn.getTileEntity(pos)).changeIndex(1); return ActionResultType.SUCCESS; } diff --git a/src/main/java/cmsc389e/circuitry/common/command/SetCommand.java b/src/main/java/cmsc389e/circuitry/common/command/SetCommand.java index b37404c..2354c54 100644 --- a/src/main/java/cmsc389e/circuitry/common/command/SetCommand.java +++ b/src/main/java/cmsc389e/circuitry/common/command/SetCommand.java @@ -39,7 +39,7 @@ public static void register(CommandDispatcher dispatcher) { String powered = "Powered"; String tag = "Tag"; - dispatcher.register(Commands.literal("set") + dispatcher.register(Commands.literal("set").requires(context -> context.hasPermissionLevel(4)) .then(Commands.argument(powered, BoolArgumentType.bool()) .executes(context -> execute(context, BoolArgumentType.getBool(context, powered), null)) .then(Commands.argument(tag, StringArgumentType.word()) diff --git a/src/main/java/cmsc389e/circuitry/common/command/TestCommand.java b/src/main/java/cmsc389e/circuitry/common/command/TestCommand.java index 8171dde..2f9be4b 100644 --- a/src/main/java/cmsc389e/circuitry/common/command/TestCommand.java +++ b/src/main/java/cmsc389e/circuitry/common/command/TestCommand.java @@ -98,7 +98,8 @@ public static void register(CommandDispatcher dispatcher) { .executes(context -> submit(context, StringArgumentType.getString(context, loginName), StringArgumentType.getString(context, password))))); - dispatcher.register(Commands.literal("test").then(load).then(start).then(stop).then(submit)); + dispatcher.register(Commands.literal("test").requires(context -> context.hasPermissionLevel(4)).then(load) + .then(start).then(stop).then(submit)); } private static int start(CommandContext context, int delay) { diff --git a/update.json b/update.json index eeca7d6..ca88776 100644 --- a/update.json +++ b/update.json @@ -1,6 +1,7 @@ { "homepage": "https://github.com/CMSC-389E/mod-and-testing-framework/releases", "1.15.2": { + "1.15.2-2.0.1.0": "-Restrict modifying the world, node information, and using commands to players with op permission.", "1.15.2-2.0.0.0": "-Fix /submit.\n-Update semester information and links.\n-Disable other dimensions.\n-Sync node tags server to client.\n-Add toggle node and decrease tag keys.\n-Add default server settings.\n-Add mod description.\n-Force configuration file reload on world load.\n-Improve performance.", "1.15.2-1.0.0.0": "-Add checks for problems loading test files.\n-Set default world settings.\n-Fix testing delay.\n-Fix stop command.\n-Add testing summary.\n-Fix version information.", "1.15.2-0.0.1.1": "Fix Apache HttpClient Mime embedding", @@ -16,8 +17,8 @@ "1.12.2-0.0.1.0-beta3": "-Implement commands.\n-Fix minor bugs." }, "promos": { - "1.15.2-latest": "1.15.2-2.0.0.0", - "1.15.2-recommended": "1.15.2-2.0.0.0", + "1.15.2-latest": "1.15.2-2.0.1.0", + "1.15.2-recommended": "1.15.2-2.0.1.0", "1.12.2-latest": "1.12.2-1.0.1.0", "1.12.2-recommended": "1.12.2-1.0.1.0"