Fixed damage and portal settings

This commit is contained in:
Fabrizio La Rosa 2020-06-17 20:33:01 +02:00
parent b1528c30a2
commit 6f2adfad70
5 changed files with 56 additions and 31 deletions

View File

@ -109,7 +109,7 @@ public class Entity implements Listener {
// Check permissions.
skyblock.getPermissionManager()
.processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation()));
.processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation()), true);
} else { // Make it work with all the entities, not just TNT
org.bukkit.entity.Entity entity = event.getEntity();

View File

@ -81,9 +81,10 @@ public class Portal implements Listener {
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
PlayerEnterPortalEvent playerEnterPortalEvent = new PlayerEnterPortalEvent(player, player.getLocation()); // TODO Why?? - Fabrimat
// Check permissions.
if (!skyblock.getPermissionManager().processPermission(new PlayerEnterPortalEvent(player, player.getLocation()),
player, island))
if (!skyblock.getPermissionManager().processPermission(playerEnterPortalEvent,
player, island) || playerEnterPortalEvent.isCancelled())
return;
IslandEnvironment spawnEnvironment;

View File

@ -146,6 +146,10 @@ public class PermissionManager {
}
public boolean processPermission(Cancellable cancellable, Player player, Island island) {
return processPermission(cancellable, player, island, false);
}
public boolean processPermission(Cancellable cancellable, Player player, Island island, boolean reversePermission) {
if (island == null) return true;
for (HandlerWrapper wrapper : registeredHandlers) {
@ -157,7 +161,7 @@ public class PermissionManager {
BasicPermission permission = wrapper.getPermission();
if (hasPermission(player, island, permission))
if (hasPermission(player, island, permission, reversePermission))
continue;
try {
@ -169,20 +173,28 @@ public class PermissionManager {
return true;
}
public boolean hasPermission(Player player, Island island, BasicPermission permission) {
public boolean hasPermission(Player player, Island island, BasicPermission permission, boolean reversePermission){
if (player == null)
return island.hasPermission(IslandRole.Owner, permission);
if (player.hasPermission("fabledskyblock.bypass." + permission.getName().toLowerCase()))
return true;
return !reversePermission;
if (island.hasPermission(island.getRole(player), permission))
return true;
switch(island.getRole(player)){
case Owner:
case Operator:
case Member:
return island.hasPermission(IslandRole.Member, permission);
case Coop:
return island.hasPermission(IslandRole.Coop, permission);
case Visitor:
return island.hasPermission(IslandRole.Visitor, permission);
}
return false;
}
if (island.isCoopPlayer(player.getUniqueId()) && island.hasPermission(IslandRole.Coop, permission))
return true;
return island.hasPermission(IslandRole.Visitor, permission);
public boolean hasPermission(Player player, Island island, BasicPermission permission) {
return this.hasPermission(player, island, permission, false);
}
public boolean hasPermission(Location location, String permission, IslandRole islandRole) {

View File

@ -7,6 +7,7 @@ import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionType;
import com.songoda.skyblock.utils.version.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -52,10 +53,10 @@ public class DamagePermission extends ListeningPermission {
FileManager.Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Settings.Damage.Enable"))
event.setCancelled(true);
else if (!configLoad.getBoolean("Island.Damage.Enable"))
if (configLoad.getBoolean("Island.Settings.Damage.Enable", false)
|| !configLoad.getBoolean("Island.Damage.Enable", false)) {
event.setCancelled(true);
}
}
@PermissionHandler
@ -66,10 +67,9 @@ public class DamagePermission extends ListeningPermission {
FileManager.Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Settings.Damage.Enable")) {
event.setCancelled(true);
} else if (!configLoad.getBoolean("Island.Damage.Enable")) {
if (configLoad.getBoolean("Island.Settings.Damage.Enable", false)
|| !configLoad.getBoolean("Island.Damage.Enable", false)) {
event.setCancelled(true);
}
}

View File

@ -3,12 +3,15 @@ package com.songoda.skyblock.permission.permissions.listening;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.*;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionType;
import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent;
import com.songoda.skyblock.utils.world.LocationUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@ -26,18 +29,11 @@ public class PortalPermission extends ListeningPermission {
@PermissionHandler
public void onPortalEnter(PlayerEnterPortalEvent event) {
Player player = (Player) event.getEntity();
if(event.getEntity() instanceof Player){
Player player = (Player) event.getEntity();
cancelAndMessage(event, player, plugin, messageManager);
}
@PermissionHandler
public void onMove(PlayerMoveEvent event) {
CompatibleMaterial toMaterial = CompatibleMaterial.getMaterial(event.getTo().getBlock().getType());
if (toMaterial == CompatibleMaterial.NETHER_BRICK || toMaterial == CompatibleMaterial.END_PORTAL) {
event.setTo(LocationUtil.getRandomLocation(event.getFrom().getWorld(), 5000, 5000, true, true));
cancelAndMessage(event, event.getPlayer(), plugin, messageManager);
cancelAndMessage(event, player, plugin, messageManager);
player.teleport(getToLocation(event.getLocation(), player));
}
}
@ -47,8 +43,24 @@ public class PortalPermission extends ListeningPermission {
|| event.getCause() == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL
|| event.getCause() == PlayerTeleportEvent.TeleportCause.END_PORTAL
|| ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) &&
event.getCause() == PlayerTeleportEvent.TeleportCause.END_GATEWAY)
event.getCause() == PlayerTeleportEvent.TeleportCause.END_GATEWAY){
event.getPlayer().teleport(getToLocation(event.getFrom(), event.getPlayer()));
cancelAndMessage(event, event.getPlayer(), plugin, messageManager);
}
}
private Location getToLocation(Location from, Player player) {
IslandManager islandManager = plugin.getIslandManager();
Island island = islandManager.getIslandAtLocation(from);
Location to = island.getLocation(IslandWorld.Normal, IslandEnvironment.Main);
if(island.hasRole(IslandRole.Visitor, player.getUniqueId())){
to = LocationUtil.getSafeLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
if(to == null){
to = LocationUtil.getSpawnLocation();
}
}
return to;
}
}