mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +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 a86d63ffc53d1af12f55be9592b0259667d5c367..f74eaf852ed5d111dd318bce5290a6c319d22c40 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -393,6 +393,10 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
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;
|
|
@@ -798,6 +802,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) {
|
|
@@ -3084,4 +3089,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 623c069f1fe079e020c6391a3db1a3d95cd3dbf5..d2b2290c73826278a89eb02ab81ee503ee41a4a2 100644
|
|
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -303,6 +303,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 e619a872d51bf0be64ff594c916c89a5bbf1d3fc..1f4a3d2610abfa2ea2b1d5feba9606b806d6d416 100644
|
|
--- a/net/minecraft/world/item/BlockItem.java
|
|
+++ b/net/minecraft/world/item/BlockItem.java
|
|
@@ -72,6 +72,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)) {
|