Skip to content

Commit

Permalink
Prevent egg hatching in claims without container permission (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
YanisBft committed Jan 13, 2021
1 parent e95b798 commit 5a70d69
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
Expand Down Expand Up @@ -1335,6 +1336,39 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
}
}

//when a player throws an egg
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerThrowEgg(PlayerEggThrowEvent event)
{
Player player = event.getPlayer();
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
Claim claim = this.dataStore.getClaimAt(event.getEgg().getLocation(), false, playerData.lastClaim);

//allow throw egg if player is in ignore claims mode
if (playerData.ignoreClaims) return;

if (claim != null && claim.allowContainers(player) != null)
{
String message = this.instance.dataStore.getMessage(Messages.NoContainersPermission, claim.getOwnerName());

if (player.hasPermission("griefprevention.ignoreclaims"))
{
message += " " + instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
}

GriefPrevention.sendMessage(player, TextMode.Err, message);

//cancel the event by preventing hatching
event.setHatching(false);

//only give the egg back if player is in survival or adventure
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
{
player.getInventory().addItem(event.getEgg().getItem());
}
}
}

//when a player reels in his fishing rod
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerFish(PlayerFishEvent event)
Expand Down

0 comments on commit 5a70d69

Please sign in to comment.