Skip to content

Commit

Permalink
fix: undo perm check crash
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Aug 25, 2023
1 parent ab8d48b commit 2d1ac2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/github/zly2006/reden/access/PlayerData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.zly2006.reden.carpet.RedenCarpetSettings
import com.github.zly2006.reden.malilib.UNDO_CHEATING_ONLY
import com.github.zly2006.reden.mixinhelper.UpdateMonitorHelper
import com.github.zly2006.reden.utils.isClient
import net.minecraft.client.MinecraftClient
import com.github.zly2006.reden.utils.isSinglePlayerAndCheating
import net.minecraft.command.EntitySelector
import net.minecraft.entity.EntityType
import net.minecraft.entity.TntEntity
Expand All @@ -20,12 +20,12 @@ import java.util.*
class PlayerData(
val player: ServerPlayerEntity,
) {
private infix fun Boolean?.and(other: Boolean?) = this ?: false && other ?: false
val canRecord: Boolean
get() = (!isClient && RedenCarpetSettings.allowedUndoSizeInBytes == 0) ||
(UNDO_CHEATING_ONLY.booleanValue && MinecraftClient.getInstance()?.let {
(it.server?.isSingleplayer and it.player?.hasPermissionLevel(2))
} == true)
get() = if (!isClient) {
RedenCarpetSettings.allowedUndoSizeInBytes != 0
} else if (UNDO_CHEATING_ONLY.booleanValue) {
true
} else isSinglePlayerAndCheating
val undo: MutableList<UndoRecord> = mutableListOf()
val redo: MutableList<RedoRecord> = mutableListOf()
var undoUsedBytes: Int = 0
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/github/zly2006/reden/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.fabricmc.api.EnvType
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.widget.ButtonWidget
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.server.MinecraftServer
Expand Down Expand Up @@ -86,3 +87,10 @@ object ResourceLoader {

fun buttonWidget(x: Int, y: Int, width: Int, height: Int, message: Text, onPress: ButtonWidget.PressAction) =
ButtonWidget(x, y, width, height, message, onPress) { it.get() }

val isSinglePlayerAndCheating: Boolean get() {
infix fun Boolean?.and(other: Boolean?) = this ?: false && other ?: false
return MinecraftClient.getInstance()?.let {
(it.server?.isSingleplayer and it.player?.hasPermissionLevel(2))
} == true
}
1 change: 1 addition & 0 deletions src/main/resources/reden.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ accessible method net/minecraft/world/World getDestructionType (Lnet/minecraft/w
accessible field net/minecraft/world/chunk/Chunk heightmaps Ljava/util/Map;
accessible field net/minecraft/command/EntitySelector PASSTHROUGH_FILTER Lnet/minecraft/util/TypeFilter;
accessible field net/minecraft/server/integrated/IntegratedServer localPlayerUuid Ljava/util/UUID;
accessible field net/minecraft/server/world/ServerWorld syncedBlockEventQueue Lit/unimi/dsi/fastutil/objects/ObjectLinkedOpenHashSet;

0 comments on commit 2d1ac2e

Please sign in to comment.