mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-04 15:41:31 +00:00
113 lines
6.1 KiB
Diff
113 lines
6.1 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/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index 6626a175376df9b549ed7eaf13d0ed21d4fc8153..1379333fcb04451a1f1000dc18c7dae224a8d33c 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -429,6 +429,10 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
public boolean isRealPlayer; // Paper
|
|
public @Nullable com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
|
|
public @Nullable 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;
|
|
@@ -747,6 +751,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
}
|
|
// CraftBukkit end
|
|
this.tickClientLoadTimeout();
|
|
+ this.resetOperationCountPerTick(); // Leaves - player operation limiter
|
|
this.gameMode.tick();
|
|
this.wardenSpawnTracker.tick();
|
|
if (this.invulnerableTime > 0) {
|
|
@@ -2970,4 +2975,31 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
return (org.bukkit.craftbukkit.entity.CraftPlayer) super.getBukkitEntity();
|
|
}
|
|
// CraftBukkit end
|
|
+
|
|
+ // 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
|
|
}
|
|
diff --git a/net/minecraft/server/level/ServerPlayerGameMode.java b/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
index 6734756d7a51e635a50a47577f9e6b6f8111db51..5d4eb61af0b0f39a5d4c37f4a303fa24b3a2936d 100644
|
|
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -300,6 +300,19 @@ public class ServerPlayerGameMode {
|
|
}
|
|
|
|
public void destroyAndAck(BlockPos pos, int sequence, String message) {
|
|
+ // Leaves start - player operation limiter
|
|
+ if (org.leavesmc.leaves.LeavesConfig.modify.playerOperationLimiter) {
|
|
+ if (message.equals("insta mine")) {
|
|
+ player.addInstaBreakCountPerTick();
|
|
+ if (!player.allowOperation()) {
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new org.leavesmc.leaves.event.player.PlayerOperationLimitEvent(player.getBukkitEntity(), org.leavesmc.leaves.event.player.PlayerOperationLimitEvent.Operation.MINE, org.bukkit.craftbukkit.block.CraftBlock.at(level, pos)));
|
|
+ this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos)));
|
|
+ this.debugLogging(pos, false, sequence, message);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - player operation limiter
|
|
if (this.destroyBlock(pos)) {
|
|
this.debugLogging(pos, true, sequence, message);
|
|
} else {
|
|
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
|
index de3bf6e1a6c5a2bf13f25af386fab5b5c9831248..0f12afbea724eefeaebf0b05474a64ec96759d62 100644
|
|
--- a/net/minecraft/world/item/BlockItem.java
|
|
+++ b/net/minecraft/world/item/BlockItem.java
|
|
@@ -65,6 +65,21 @@ public class BlockItem extends Item {
|
|
final org.bukkit.block.BlockState oldBukkitState = bukkitState != null ? bukkitState : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockPlaceContext.getLevel(), blockPlaceContext.getClickedPos()); // Paper - Reset placed block on exception
|
|
// CraftBukkit end
|
|
|
|
+ // Leaves start - player operation limiter
|
|
+ if (org.leavesmc.leaves.LeavesConfig.modify.playerOperationLimiter && !context.getLevel().isClientSide()) {
|
|
+ ServerPlayer player = (ServerPlayer) context.getPlayer();
|
|
+ if (player != null && placementState != null) {
|
|
+ player.addPlaceBlockCountPerTick();
|
|
+ if (!player.allowOperation()) {
|
|
+ if (bukkitState != null) {
|
|
+ context.getLevel().getCraftServer().getPluginManager().callEvent(new org.leavesmc.leaves.event.player.PlayerOperationLimitEvent(player.getBukkitEntity(), org.leavesmc.leaves.event.player.PlayerOperationLimitEvent.Operation.PLACE, bukkitState.getBlock()));
|
|
+ }
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - player operation limiter
|
|
+
|
|
if (placementState == null) {
|
|
return InteractionResult.FAIL;
|
|
} else if (!this.placeBlock(blockPlaceContext, placementState)) {
|