Completely prevent moving items in inventory (click,drag,offhand swapping) during gameplay to stop a few exploits

This commit is contained in:
selfslaughter 2020-05-18 01:31:19 +10:00
parent b1f2dbf71e
commit 1d44c941a5
3 changed files with 28 additions and 4 deletions

View File

@ -110,6 +110,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(new OnFoodLevelChangeEvent(), this);
getServer().getPluginManager().registerEvents(new OnInventoryClickEvent(), this);
getServer().getPluginManager().registerEvents(new OnInventoryCloseEvent(), this);
getServer().getPluginManager().registerEvents(new OnPlayerSwapHandItemsEvent(), this);
// Removed - This is handled by WorldGuard now.
// getServer().getPluginManager().registerEvents(

View File

@ -25,10 +25,8 @@ public class OnInventoryClickEvent implements Listener {
Player player = (Player) event.getWhoClicked();
for (Arena arena : MemoryStorage.arenaList) {
if (arena.playersInArena.contains(player) && !arena.seekers.contains(player)) {
if (event.getSlot() == 8 || event.getSlot() == 39) {
event.setCancelled(true);
}
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
}
}

View File

@ -0,0 +1,25 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.MemoryStorage;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
public class OnPlayerSwapHandItemsEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) {
// Early exit if no one is in any arena
if (ArenaHandler.noPlayersInArenas()) return;
Player player = event.getPlayer();
for (Arena arena : MemoryStorage.arenaList) {
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
}
}
}
}