Skip to content

Commit

Permalink
Permission d'interagir avec les entites sur une île
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Jan 29, 2024
1 parent 990ee40 commit bb23cef
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum PermissionsIsland implements Permissions {
INTERACT_ENTITIES(2_048),
KILL_UNKNOWN_ENTITY(4_096),
KILL_NPC(8_192),
INTERACT(16_384)
;

private final long permissionValue;
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/main/java/fr/euphyllia/skyllia/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.euphyllia.skyllia.listeners.bukkitevents.BlockEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.PortailAlternativeFoliaEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.entity.DamageEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.player.InteractEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.player.InventoryEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.player.JoinEvent;
import fr.euphyllia.skyllia.listeners.bukkitevents.player.PlayerEvent;
Expand Down Expand Up @@ -112,6 +113,7 @@ private void loadListener() {
pluginManager.registerEvents(new InventoryEvent(this.interneAPI), this);
pluginManager.registerEvents(new PlayerEvent(this.interneAPI), this);
pluginManager.registerEvents(new DamageEvent(this.interneAPI), this);
pluginManager.registerEvents(new InteractEvent(this.interneAPI), this);
if (this.interneAPI.isFolia()) {
pluginManager.registerEvents(new PortailAlternativeFoliaEvent(this.interneAPI), this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.euphyllia.skyllia.listeners.bukkitevents.player;

import fr.euphyllia.skyllia.api.InterneAPI;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsIsland;
import fr.euphyllia.skyllia.listeners.ListenersUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class InteractEvent implements Listener {
private final InterneAPI api;
private final Logger logger = LogManager.getLogger(InteractEvent.class);

public InteractEvent(InterneAPI interneAPI) {
this.api = interneAPI;
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteractEvent(final PlayerInteractEvent event) {
if (event.useInteractedBlock().equals(Event.Result.DENY)) return;
if (event.useItemInHand().equals(Event.Result.DENY)) return;

Player player = event.getPlayer();
if (player.hasPermission("skyllia.interact.bypass")) {
return;
}
ListenersUtils.checkPermission(player.getChunk(), player, PermissionsIsland.INTERACT, event);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteractEntitiesEvent(final PlayerInteractEntityEvent event) {
if (event.isCancelled()) return;

Player player = event.getPlayer();
if (player.hasPermission("skyllia.interact_entity.bypass")) {
return;
}
ListenersUtils.checkPermission(event.getRightClicked().getChunk(), player, PermissionsIsland.INTERACT_ENTITIES, event);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteractEntitiesEvent(final PlayerInteractAtEntityEvent event) {
if (event.isCancelled()) return;

Player player = event.getPlayer();
if (player.hasPermission("skyllia.interact_entity.bypass")) {
return;
}
ListenersUtils.checkPermission(event.getRightClicked().getChunk(), player, PermissionsIsland.INTERACT_ENTITIES, event);
}

}

0 comments on commit bb23cef

Please sign in to comment.