Skip to content

Commit

Permalink
Fixed the ability to take books out of lecterns on other islands (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Apr 5, 2023
1 parent 836677d commit c255b7c
Show file tree
Hide file tree
Showing 5 changed files with 2,319 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class IslandPrivileges {
public static final IslandPrivilege PICKUP_DROPS = register("PICKUP_DROPS");
@Nullable
public static final IslandPrivilege PICKUP_FISH = register("PICKUP_FISH", !ServerVersion.isLegacy());
@Nullable
public static final IslandPrivilege PICKUP_LECTERN_BOOK = register("PICKUP_LECTERN_BOOK", ServerVersion.isAtLeast(ServerVersion.v1_14));
public static final IslandPrivilege PROMOTE_MEMBERS = register("PROMOTE_MEMBERS");
public static final IslandPrivilege RANKUP = register("RANKUP");
public static final IslandPrivilege RATINGS_SHOW = register("RATINGS_SHOW");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
Expand Down Expand Up @@ -100,6 +101,7 @@ public ProtectionListener(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
this.registerPlayerArrowPickupListener();
this.registerPlayerAttemptPickupItemListener();
this.registerPlayerTakeLecternBookListener();
}

public enum Flag {
Expand Down Expand Up @@ -693,6 +695,14 @@ private void registerPlayerAttemptPickupItemListener() {
}
}

private void registerPlayerTakeLecternBookListener() {
try {
Class.forName("org.bukkit.event.player.PlayerTakeLecternBookEvent");
Bukkit.getPluginManager().registerEvents(new PlayerTakeLecternBookListener(), plugin);
} catch (Exception ignored) {
}
}

private class PaperAttemptPickupListener implements Listener {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
Expand All @@ -713,6 +723,20 @@ public void onPlayerArrowPickup(PlayerPickupArrowEvent e) {

}

private class PlayerTakeLecternBookListener implements Listener {

@EventHandler
public void onPlayerTakeLecternBook(PlayerTakeLecternBookEvent e) {
Location blockLocation = e.getLectern().getLocation();
SuperiorPlayer superiorPlayer = plugin.getPlayers().getSuperiorPlayer(e.getPlayer());
Island island = plugin.getGrid().getIslandAt(blockLocation);
if (preventInteraction(island, blockLocation, superiorPlayer, IslandPrivileges.PICKUP_LECTERN_BOOK,
Flag.SEND_MESSAGES, Flag.PREVENT_OUTSIDE_ISLANDS))
e.setCancelled(true);
}

}

@Nullable
private static EntityType getSafeEntityType(String entityType) {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ island-roles:
- MONSTER_DAMAGE
- NAME_ENTITY
- PAINTING
- PICKUP_AXOLOTL
- PICKUP_DROPS
- PICKUP_FISH
- PICKUP_LECTERN_BOOK
- SIGN_INTERACT
- TURTLE_EGG_TRAMPING
- USE
Expand Down

0 comments on commit c255b7c

Please sign in to comment.