1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Invert if statement

This commit is contained in:
Senne 2022-01-01 22:48:16 +01:00
parent 4792124224
commit ef8e84a350
No known key found for this signature in database
GPG Key ID: EA68733326BBA376

View File

@ -45,34 +45,36 @@ public class MiddleClickListener implements Listener {
// get the block the player is looking at for later // get the block the player is looking at for later
Block b = player.getTargetBlockExact(5); Block b = player.getTargetBlockExact(5);
if (isActualMiddleClick(e, b)) { if (!isActualMiddleClick(e, b)) {
// find the actual slimefun item the user is looking at return;
String id = BlockStorage.checkID(b); }
SlimefunItem sfItem = SlimefunItem.getById(id);
// vanilla block -> ignore // find the actual slimefun item the user is looking at
if (sfItem == null) { String id = BlockStorage.checkID(b);
SlimefunItem sfItem = SlimefunItem.getById(id);
// vanilla block -> ignore
if (sfItem == null) {
return;
}
/*
* Before giving the item to the user, check if you can swap
* to the item instead (user already has item in hotbar).
* This is sometimes bypassed by the client itself (not fixable though).
*/
for (int i = 0; i < 9; i++) {
SlimefunItem hotbarItem = SlimefunItem.getByItem(player.getInventory().getItem(i));
if (hotbarItem != null && hotbarItem.getId() == sfItem.getId()) {
player.getInventory().setHeldItemSlot(i);
// Has to be cancelled in order for it to work properly.
e.setCancelled(true);
return; return;
} }
/*
* Before giving the item to the user, check if you can swap
* to the item instead (user already has item in hotbar).
* This is sometimes bypassed by the client itself (not fixable though).
*/
for (int i = 0; i < 9; i++) {
SlimefunItem hotbarItem = SlimefunItem.getByItem(player.getInventory().getItem(i));
if (hotbarItem != null && hotbarItem.getId() == sfItem.getId()) {
player.getInventory().setHeldItemSlot(i);
// Has to be cancelled in order for it to work properly.
e.setCancelled(true);
return;
}
}
// Give the item, doing it like this will not alter any other cases.
e.setCursor(sfItem.getItem().clone());
} }
// Give the item, doing it like this will not alter any other cases.
e.setCursor(sfItem.getItem().clone());
} }
} }