Skip to content

Commit

Permalink
serverDataSyncer permission check will pass if carpet-tis-addition's …
Browse files Browse the repository at this point in the history
…`debugNbtQueryNoPermission` rule is enable
  • Loading branch information
Fallen-Breath committed Mar 17, 2024
1 parent afd108c commit 9e8d269
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import me.fallenbreath.tweakermore.TweakerMoreMod;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.mixins.tweaks.mod_tweaks.serverDataSyncer.DoubleInventoryAccessor;
import me.fallenbreath.tweakermore.util.compat.carpettisaddition.CarpetTISAdditionAccess;
import me.fallenbreath.tweakermore.util.event.TweakerMoreEvents;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -81,7 +82,11 @@ public DataQueryHandlerPro getQueryHandler()
public static boolean hasEnoughPermission()
{
MinecraftClient mc = MinecraftClient.getInstance();
return mc.player != null && mc.player.allowsPermissionLevel(2);
if (mc.player != null && mc.player.allowsPermissionLevel(2))
{
return true;
}
return CarpetTISAdditionAccess.getBooleanRule("debugNbtQueryNoPermission").orElse(false);
}

public void resetSyncLimiter()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.util.compat.carpettisaddition;

import me.fallenbreath.tweakermore.util.ReflectionUtil;

import java.util.Optional;

public class CarpetTISAdditionAccess
{
public static Optional<Boolean> getBooleanRule(String ruleName)
{
return ReflectionUtil.getClass("carpettisaddition.CarpetTISAdditionSettings")
.map(clazz -> ReflectionUtil.getStaticField(clazz, ruleName))
.map(vw -> vw.isPresent() ? vw.get() : null)
.map(value -> value instanceof Boolean ? (Boolean)value : null);
}
}

0 comments on commit 9e8d269

Please sign in to comment.