Skip to content

Commit 25b9d27

Browse files
committed
First attempt to handle ground riptide
Also fix an error with old versions
1 parent 3198615 commit 25b9d27

File tree

9 files changed

+167
-48
lines changed

9 files changed

+167
-48
lines changed

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
4848
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo;
4949
import fr.neatmonster.nocheatplus.checks.moving.velocity.VelocityFlags;
50+
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
5051
import fr.neatmonster.nocheatplus.compat.Bridge1_13;
5152
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
5253
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
@@ -181,8 +182,7 @@ public CombinedData getNewInstance(PlayerFactoryArgument arg) {
181182
public void onReleasingTrident(Player player, Vector vel) {
182183
final IPlayerData pData = DataManager.getPlayerData(player);
183184
final MovingData data = pData.getGenericInstance(MovingData.class);
184-
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
185-
thisMove.tridentRelease = true;
185+
data.setTridentReleaseEvent(AlmostBoolean.MAYBE);
186186
}
187187

188188
/**

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/FastClick.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.bukkit.Material;
2121
import org.bukkit.entity.Player;
22+
import org.bukkit.event.inventory.InventoryClickEvent;
2223
import org.bukkit.event.inventory.InventoryType;
2324
import org.bukkit.inventory.InventoryView;
2425
import org.bukkit.inventory.ItemStack;
@@ -69,7 +70,7 @@ public FastClick() {
6970
* @return true, if successful
7071
*/
7172
public boolean check(final Player player, final long now,
72-
final InventoryView view, final int slot, final ItemStack cursor,
73+
final InventoryClickEvent event, final int slot, final ItemStack cursor,
7374
final ItemStack clicked, final boolean isShiftClick,
7475
final String inventoryAction, final InventoryData data, final InventoryConfig cc,
7576
final IPlayerData pData) {
@@ -91,11 +92,11 @@ public boolean check(final Player player, final long now,
9192
}
9293

9394
if (inventoryAction != null) {
94-
amount = getAmountWithAction(view, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, inventoryAction, data, cc);
95+
amount = getAmountWithAction(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, inventoryAction, data, cc);
9596
}
9697
else if (cursor != null) {
9798
// Detect shift-click features indirectly.
98-
amount = detectTweaks1_5(view, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
99+
amount = detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
99100
}
100101
else amount = 1f;
101102

@@ -190,7 +191,7 @@ public boolean checkContainerInteraction(final Player player, final InventoryDat
190191
* @param data
191192
* @param cc
192193
*/
193-
private float detectTweaks1_5(final InventoryView view, final int slot, final ItemStack clicked,
194+
private float detectTweaks1_5(final InventoryClickEvent event, final int slot, final ItemStack clicked,
194195
final Material clickedMat, final Material cursorMat,
195196
final int cursorAmount, final boolean isShiftClick,
196197
final InventoryData data, final InventoryConfig cc) {
@@ -203,13 +204,13 @@ private float detectTweaks1_5(final InventoryView view, final int slot, final It
203204
else if (clickedMat == Material.AIR || clickedMat == cursorMat
204205
|| isShiftClick && clickedMat == data.fastClickLastClicked ) {
205206
return Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit)
206-
/ (float) (isShiftClick && clickedMat != Material.AIR ? (1.0 + Math.max(cursorAmount, InventoryUtil.getStackCount(view, clicked))) : cursorAmount) * 0.75f;
207+
/ (float) (isShiftClick && clickedMat != Material.AIR ? (1.0 + Math.max(cursorAmount, InventoryUtil.getStackCount(event, clicked))) : cursorAmount) * 0.75f;
207208
}
208209
return 1f;
209210
}
210211

211212

212-
private float getAmountWithAction(final InventoryView view, final int slot, final ItemStack clicked,
213+
private float getAmountWithAction(final InventoryClickEvent event, final int slot, final ItemStack clicked,
213214
final Material clickedMat, final Material cursorMat,
214215
final int cursorAmount, final boolean isShiftClick,
215216
final String inventoryAction,
@@ -219,7 +220,7 @@ private float getAmountWithAction(final InventoryView view, final int slot, fina
219220
if (inventoryAction.equals("DROP_ONE_SLOT")
220221
&& slot == data.fastClickLastSlot
221222
&& clickedMat == data.fastClickLastClicked
222-
&& view.getType() == InventoryType.CRAFTING
223+
&& event.getInventory().getType() == InventoryType.CRAFTING
223224
// && InventoryUtil.couldHaveInventoryOpen(player)
224225
// TODO: Distinguish if the inventory is really open.
225226
) {
@@ -228,14 +229,14 @@ private float getAmountWithAction(final InventoryView view, final int slot, fina
228229

229230
// Collect to cursor.
230231
if (inventoryAction.equals("COLLECT_TO_CURSOR")) {
231-
final int stackCount = InventoryUtil.getStackCount(view, clicked);
232+
final int stackCount = InventoryUtil.getStackCount(event, clicked);
232233
return stackCount <= 0 ? 1f : Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) / stackCount * 0.75f;
233234
}
234235

235236
// Shift click features.
236237
if ((inventoryAction.equals("MOVE_TO_OTHER_INVENTORY")) && cursorMat != Material.AIR) {
237238
// Let the legacy method do the side condition checks and counting for now.
238-
return detectTweaks1_5(view, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
239+
return detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
239240
}
240241
return 1f;
241242
}

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.bukkit.event.player.PlayerRespawnEvent;
5050
import org.bukkit.event.player.PlayerTeleportEvent;
5151
import org.bukkit.inventory.Inventory;
52-
import org.bukkit.inventory.InventoryView;
5352
import org.bukkit.inventory.ItemStack;
5453
import org.bukkit.inventory.meta.BookMeta;
5554

@@ -227,7 +226,7 @@ public void onInventoryClick(final InventoryClickEvent event) {
227226
// We still want to know if the player clicked in the inventory (even if cancelled) for the inventory-open estimate above.
228227
return;
229228
}
230-
if (slot == InventoryView.OUTSIDE || slot < 0) {
229+
if (slot == -999 || slot < 0) {
231230
// Set and return, not interested in these clicks.
232231
data.lastClickTime = now;
233232
return;
@@ -238,11 +237,11 @@ public void onInventoryClick(final InventoryClickEvent event) {
238237
boolean cancel = false;
239238
// Fast inventory manipulation check.
240239
if (fastClick.isEnabled(player, pData)) {
241-
if (!((event.getView().getType().equals(InventoryType.CREATIVE) || player.getGameMode() == GameMode.CREATIVE) && cc.fastClickSpareCreative)) {
240+
if (!((event.getInventory().getType().equals(InventoryType.CREATIVE) || player.getGameMode() == GameMode.CREATIVE) && cc.fastClickSpareCreative)) {
242241
boolean check = true;
243242
try {
244243
// Exempted inventories are not checked.
245-
check = !cc.inventoryExemptions.contains(ChatColor.stripColor(event.getView().getTitle()));
244+
check = !cc.inventoryExemptions.contains(ChatColor.stripColor(BridgeBukkitAPI.getInventoryTitle(event)));
246245
}
247246
catch (IllegalStateException e) {
248247
// Uhm... Can this ISE be fixed?
@@ -257,7 +256,7 @@ public void onInventoryClick(final InventoryClickEvent event) {
257256
keepCancel = true;
258257
}
259258
// Then check for too fast inventory clicking
260-
if (!cancel && fastClick.check(player, now, event.getView(), slot, cursor, clicked, event.isShiftClick(), inventoryAction, data, cc, pData)) {
259+
if (!cancel && fastClick.check(player, now, event, slot, cursor, clicked, event.isShiftClick(), inventoryAction, data, cc, pData)) {
261260
cancel = true;
262261
}
263262
}
@@ -676,14 +675,14 @@ private void outputDebugInventoryClick(final Player player, final int slot, fina
676675

677676
// Inventory view.
678677
builder.append(" , View: ");
679-
final InventoryView view = event.getView();
680-
builder.append(view.getClass().getName());
678+
//final InventoryView view = BridgeBukkitAPI.getInventoryView(event);
679+
//builder.append(view.getClass().getName());
681680

682681
// Bottom inventory.
683-
addInventory(view.getBottomInventory(), view, " , Bottom: ", builder);
682+
addInventory(BridgeBukkitAPI.getBottomInventory(event), BridgeBukkitAPI.getInventoryTitle(event), " , Bottom: ", builder);
684683

685684
// Top inventory.
686-
addInventory(view.getBottomInventory(), view, " , Top: ", builder);
685+
addInventory(BridgeBukkitAPI.getTopInventory(event), BridgeBukkitAPI.getInventoryTitle(event), " , Top: ", builder);
687686

688687
if (action != null) {
689688
builder.append(" , Action: ");
@@ -698,13 +697,12 @@ private void outputDebugInventoryClick(final Player player, final int slot, fina
698697
debug(player, builder.toString());
699698
}
700699

701-
private void addInventory(final Inventory inventory, final InventoryView view, final String prefix, final StringBuilder builder) {
700+
private void addInventory(final Inventory inventory, final String name, final String prefix, final StringBuilder builder) {
702701
builder.append(prefix);
703702
if (inventory == null) {
704703
builder.append("(none)");
705704
}
706705
else {
707-
String name = view.getTitle();
708706
builder.append(name);
709707
builder.append("/");
710708
builder.append(inventory.getClass().getName());

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public VehicleMoveData call() throws Exception {
216216
public int fireworksBoostTickNeedCheck = 0;
217217
/** Expire at this tick. */
218218
public int fireworksBoostTickExpire = 0;
219+
private AlmostBoolean tridentRelease = AlmostBoolean.NO;
219220

220221
// *----------Data of the MorePackets check----------*
221222
/** Packet frequency count. */
@@ -829,6 +830,21 @@ private void removeAllPlayerSpeedModifiers() {
829830
fireworksBoostDuration = 0;
830831
fireworksBoostTickExpire = 0;
831832
}
833+
/**
834+
* Set when PlayerRiptideEvent called
835+
*/
836+
public void setTridentReleaseEvent(AlmostBoolean isReleased) {
837+
tridentRelease = isReleased;
838+
}
839+
840+
/**
841+
* Set when pass to PlayerMoveData, also reset state
842+
*/
843+
public AlmostBoolean consumeTridentReleaseEvent() {
844+
final AlmostBoolean result = tridentRelease;
845+
tridentRelease = AlmostBoolean.NO;
846+
return result;
847+
}
832848

833849

834850

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ private boolean checkPlayerMove(final Player player, final Location from, final
11911191
thisMove.multiMoveCount = multiMoveCount;
11921192
thisMove.setBackYDistance = pTo.getY() - data.getSetBackY();
11931193
thisMove.isGliding = Bridge1_9.isGliding(player);
1194+
thisMove.tridentRelease = data.consumeTridentReleaseEvent();
11941195

11951196
////////////////////////////
11961197
// Potion effect "Jump". //

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/model/PlayerMoveData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class PlayerMoveData extends MoveData {
4747
public double submergedWaterHeight;
4848

4949
/** Sets whether the player has just released a trident with riptide. Set on {@link org.bukkit.event.player.PlayerRiptideEvent}. */
50-
public boolean tridentRelease;
50+
public AlmostBoolean tridentRelease;
5151

5252
/**
5353
* The distance covered by a move from the setback point to the to.getY() point.
@@ -230,6 +230,7 @@ protected void resetBase() {
230230
negligibleHorizontalCollision = false;
231231
collidesHorizontally = false;
232232
hasImpulse = AlmostBoolean.NO;
233+
tridentRelease = AlmostBoolean.NO;
233234
// Super class last, because it'll set valid to true in the end.
234235
super.resetBase();
235236
}

0 commit comments

Comments
 (0)