Skip to content

Commit

Permalink
Add restrictions to non-op players
Browse files Browse the repository at this point in the history
  • Loading branch information
MaidThatPrograms committed Jan 29, 2021
1 parent d0efab0 commit 001ccc3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 1 addition & 0 deletions src/main/java/cmsc389e/circuitry/Circuitry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/cmsc389e/circuitry/client/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -110,17 +109,16 @@ 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;
for (Key key : Key.values()) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void register(CommandDispatcher<CommandSource> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public static void register(CommandDispatcher<CommandSource> 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<CommandSource> context, int delay) {
Expand Down
5 changes: 3 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit 001ccc3

Please sign in to comment.