mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
113 lines
6.2 KiB
Diff
113 lines
6.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Sun, 11 Dec 2022 18:43:35 +0800
|
|
Subject: [PATCH] Player operation limiter
|
|
|
|
This patch is Powered by plusls-carpet-addition(https://github.com/plusls/plusls-carpet-addition)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 9f32ed6b7f7c3dc0175cadf811956991b136be23..eee83b3e9bc409c987bf85970f9c2add052cbeb0 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -301,6 +301,10 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
|
|
public @Nullable String clientBrandName = null; // Paper - Brand support
|
|
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
|
|
+ // Leaves start - player operation limiter
|
|
+ private int instaBreakCountPerTick = 0;
|
|
+ private int placeBlockCountPerTick = 0;
|
|
+ // Leaves end - player operation limiter
|
|
|
|
// Paper start - rewrite chunk system
|
|
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
|
|
@@ -764,6 +768,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
this.joining = false;
|
|
}
|
|
// CraftBukkit end
|
|
+ this.resetOperationCountPerTick(); // Leaves - player operation limiter
|
|
this.gameMode.tick();
|
|
this.wardenSpawnTracker.tick();
|
|
--this.spawnInvulnerableTime;
|
|
@@ -2954,5 +2959,32 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
public CraftPlayer getBukkitEntity() {
|
|
return (CraftPlayer) super.getBukkitEntity();
|
|
}
|
|
+
|
|
+ // Leaves start - player operation limiter
|
|
+ private void resetOperationCountPerTick() {
|
|
+ instaBreakCountPerTick = 0;
|
|
+ placeBlockCountPerTick = 0;
|
|
+ }
|
|
+
|
|
+ public int getInstaBreakCountPerTick() {
|
|
+ return instaBreakCountPerTick;
|
|
+ }
|
|
+
|
|
+ public int getPlaceBlockCountPerTick() {
|
|
+ return placeBlockCountPerTick;
|
|
+ }
|
|
+
|
|
+ public void addInstaBreakCountPerTick() {
|
|
+ ++instaBreakCountPerTick;
|
|
+ }
|
|
+
|
|
+ public void addPlaceBlockCountPerTick() {
|
|
+ ++placeBlockCountPerTick;
|
|
+ }
|
|
+
|
|
+ public boolean allowOperation() {
|
|
+ return (instaBreakCountPerTick == 0 || placeBlockCountPerTick == 0) && (instaBreakCountPerTick <= 1 && placeBlockCountPerTick <= 2);
|
|
+ }
|
|
+ // Leaves end - player operation limiter
|
|
// CraftBukkit end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
index cc01ead133cc6859ca5d7a1d0ac3c12955e590da..dea6b2cb7df6a9bb23cc56b0f97eaad9209c6527 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -339,6 +339,19 @@ public class ServerPlayerGameMode {
|
|
}
|
|
|
|
public void destroyAndAck(BlockPos pos, int sequence, String reason) {
|
|
+ // Leaves start - player operation limiter
|
|
+ if (org.leavesmc.leaves.LeavesConfig.playerOperationLimiter) {
|
|
+ if (reason.equals("insta mine")) {
|
|
+ player.addInstaBreakCountPerTick();
|
|
+ if (!player.allowOperation()) {
|
|
+ MinecraftServer.getServer().server.getPluginManager().callEvent(new org.leavesmc.leaves.event.player.PlayerOperationLimitEvent(player.getBukkitEntity(), org.leavesmc.leaves.event.player.PlayerOperationLimitEvent.Operation.MINE, CraftBlock.at(level, pos)));
|
|
+ this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos)));
|
|
+ this.debugLogging(pos, false, sequence, reason);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - player operation limiter
|
|
if (this.destroyBlock(pos)) {
|
|
this.debugLogging(pos, true, sequence, reason);
|
|
} else {
|
|
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
index 29f38a0a87cb7e27ac18c09dd59e774cfd874592..2759a9eeef85b323b7e1ea78090f4f9d637c938a 100644
|
|
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
@@ -80,6 +80,20 @@ public class BlockItem extends Item {
|
|
final org.bukkit.block.BlockState oldBlockstate = blockstate != null ? blockstate : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos()); // Paper - Reset placed block on exception
|
|
// CraftBukkit end
|
|
|
|
+ // Leaves start - player operation limiter
|
|
+ if (org.leavesmc.leaves.LeavesConfig.playerOperationLimiter && !context.getLevel().isClientSide()) {
|
|
+ ServerPlayer player = (ServerPlayer) context.getPlayer();
|
|
+ if (player != null && iblockdata != null) {
|
|
+ player.addPlaceBlockCountPerTick();
|
|
+ if (!player.allowOperation()) {
|
|
+ if (blockstate != null) {
|
|
+ MinecraftServer.getServer().server.getPluginManager().callEvent(new org.leavesmc.leaves.event.player.PlayerOperationLimitEvent(player.getBukkitEntity(), org.leavesmc.leaves.event.player.PlayerOperationLimitEvent.Operation.PLACE, blockstate.getBlock()));
|
|
+ }
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - player operation limiter
|
|
if (iblockdata == null) {
|
|
return InteractionResult.FAIL;
|
|
} else if (!this.placeBlock(blockactioncontext1, iblockdata)) {
|