Skip to content

Commit

Permalink
fix: move ItemMergeEvent to common PlayerListener, since it is suppor…
Browse files Browse the repository at this point in the history
…ted in 1.8.8 and we do not support earlier 1.8.x versions
  • Loading branch information
Misat11 committed May 6, 2024
1 parent 08cdd06 commit e7197d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;

import java.util.Arrays;
Expand All @@ -47,24 +46,6 @@ public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
}
}

@EventHandler
public void onItemMerge(ItemMergeEvent event) {
// This is already in 1.8.8, but in older 1.8.x versions not (need to check 1.8.8/9 version)
if (event.isCancelled()) {
return;
}

for (String s : Main.getGameNames()) {
Game game = Main.getGame(s);
if (game.getStatus() == GameStatus.RUNNING && game.getOriginalOrInheritedSpawnerDisableMerge()) {
if (GameCreator.isInArea(event.getEntity().getLocation(), game.getPos1(), game.getPos2()) || GameCreator.isInArea(event.getTarget().getLocation(), game.getPos1(), game.getPos2())) {
event.setCancelled(true);
return;
}
}
}
}

@EventHandler
public void onMove(PlayerMoveEvent event) {
if (event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,23 @@ public void onPlaceLiquid(PlayerBucketEmptyEvent event) {
}
}

@EventHandler
public void onItemMerge(ItemMergeEvent event) {
if (event.isCancelled()) {
return;
}

for (String s : Main.getGameNames()) {
Game game = Main.getGame(s);
if (game.getStatus() == GameStatus.RUNNING && game.getOriginalOrInheritedSpawnerDisableMerge()) {
if (GameCreator.isInArea(event.getEntity().getLocation(), game.getPos1(), game.getPos2()) || GameCreator.isInArea(event.getTarget().getLocation(), game.getPos1(), game.getPos2())) {
event.setCancelled(true);
return;
}
}
}
}

/* This event was replaced on 1.12 with newer (event handling is devided between Player112Listener and PlayerBefore112Listener) */
public static void onItemPickup(Player player, Item item, Cancellable cancel) {
if (cancel.isCancelled()) {
Expand Down

0 comments on commit e7197d0

Please sign in to comment.