diff --git a/skyblock.iml b/skyblock.iml index 97e93273..ae1ab2d0 100644 --- a/skyblock.iml +++ b/skyblock.iml @@ -28,6 +28,6 @@ - + \ No newline at end of file diff --git a/src/main/java/com/songoda/skyblock/SkyBlock.java b/src/main/java/com/songoda/skyblock/SkyBlock.java index fc81f45d..06d0f7fb 100644 --- a/src/main/java/com/songoda/skyblock/SkyBlock.java +++ b/src/main/java/com/songoda/skyblock/SkyBlock.java @@ -4,6 +4,7 @@ import com.songoda.core.SongodaCore; import com.songoda.core.SongodaPlugin; import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.configuration.Config; +import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; import com.songoda.skyblock.api.SkyBlockAPI; import com.songoda.skyblock.ban.BanManager; @@ -15,6 +16,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.confirmation.ConfirmationTask; import com.songoda.skyblock.cooldown.CooldownManager; import com.songoda.skyblock.generator.GeneratorManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.tasks.HologramTask; import com.songoda.skyblock.invite.InviteManager; import com.songoda.skyblock.island.IslandManager; @@ -44,7 +46,6 @@ import com.songoda.skyblock.world.WorldManager; import com.songoda.skyblock.world.generator.VoidGenerator; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.event.HandlerList; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.PluginManager; @@ -82,6 +83,9 @@ public class SkyBlock extends SongodaPlugin { private LocalizationManager localizationManager; private RewardManager rewardManager; private FabledChallenge fabledChallenge; + private PermissionManager permissionManager; + + private final GuiManager guiManager = new GuiManager(this); public static SkyBlock getInstance() { return INSTANCE; @@ -103,6 +107,7 @@ public class SkyBlock extends SongodaPlugin { // Load Holograms com.songoda.core.hooks.HologramManager.load(this); + permissionManager = new PermissionManager(this); fileManager = new FileManager(this); localizationManager = new LocalizationManager(); worldManager = new WorldManager(this); @@ -357,4 +362,12 @@ public class SkyBlock extends SongodaPlugin { public FabledChallenge getFabledChallenge() { return fabledChallenge; } + + public PermissionManager getPermissionManager() { + return permissionManager; + } + + public GuiManager getGuiManager() { + return guiManager; + } } diff --git a/src/main/java/com/songoda/skyblock/api/island/Island.java b/src/main/java/com/songoda/skyblock/api/island/Island.java index 07c2741a..ee95ae3d 100644 --- a/src/main/java/com/songoda/skyblock/api/island/Island.java +++ b/src/main/java/com/songoda/skyblock/api/island/Island.java @@ -6,6 +6,7 @@ import com.songoda.skyblock.api.ban.Ban; import com.songoda.skyblock.api.utils.APIUtil; import com.songoda.skyblock.api.visit.Visit; import com.songoda.skyblock.island.IslandCoop; +import com.songoda.skyblock.island.IslandPermission; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.WeatherType; @@ -360,29 +361,12 @@ public class Island { return this.handle.isUpgrade(APIUtil.toImplementation(upgrade)); } - /** - * @return Setting of an IslandRole for the Island - */ - public IslandSetting getSetting(IslandRole role, String setting) { - Preconditions.checkArgument(role != null, "Cannot get setting to null role"); - Preconditions.checkArgument(setting != null, "Cannot get setting for null setting"); - - return new IslandSetting(this.handle.getSetting(APIUtil.toImplementation(role), setting)); - } - /** * @return A List of Settings of an IslandRole for the Island */ - public List getSettings(IslandRole role) { + public List getSettings(IslandRole role) { Preconditions.checkArgument(role != null, "Cannot get settings to null role"); - List settings = new ArrayList<>(); - - for (com.songoda.skyblock.island.IslandSetting settingList : this.handle - .getSettings(APIUtil.toImplementation(role))) { - settings.add(new IslandSetting(settingList)); - } - - return settings; + return this.handle.getSettings(APIUtil.toImplementation(role)); } /** diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandManager.java b/src/main/java/com/songoda/skyblock/api/island/IslandManager.java index e3cf6978..6e20c504 100644 --- a/src/main/java/com/songoda/skyblock/api/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/api/island/IslandManager.java @@ -1,8 +1,11 @@ package com.songoda.skyblock.api.island; import com.google.common.base.Preconditions; +import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.api.structure.Structure; import com.songoda.skyblock.api.utils.APIUtil; +import com.songoda.skyblock.island.IslandPermission; +import com.songoda.skyblock.permission.PermissionManager; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -15,9 +18,11 @@ import java.util.UUID; public class IslandManager { private final com.songoda.skyblock.island.IslandManager islandManager; + private final PermissionManager permissionManager; public IslandManager(com.songoda.skyblock.island.IslandManager islandManager) { this.islandManager = islandManager; + this.permissionManager = SkyBlock.getInstance().getPermissionManager(); } /** @@ -75,41 +80,6 @@ public class IslandManager { this.islandManager.closeIsland(island.getIsland()); } - /** - * Checks if a player has permission at an Island for a Setting - * - * @return true of conditions met, false otherwise - */ - public boolean hasPermission(Player player, String setting) { - Preconditions.checkArgument(player != null, "Cannot check permission to null player"); - - return this.islandManager.hasPermission(player, setting); - } - - /** - * Checks if a player has permission at a location of an Island for a Setting - * - * @return true of conditions met, false otherwise - */ - public boolean hasPermission(Player player, Location location, String setting) { - Preconditions.checkArgument(player != null, "Cannot check permission to null player"); - Preconditions.checkArgument(location != null, "Cannot check permission to null location"); - - return this.islandManager.hasPermission(player, location, setting); - } - - /** - * Checks the permission of a Setting for a Role at a Location - * - * @return true of conditions met, false otherwise - */ - public boolean hasSetting(Location location, IslandRole role, String setting) { - Preconditions.checkArgument(location != null, "Cannot check setting to null location"); - Preconditions.checkArgument(role != null, "Cannot check setting to null role"); - - return this.islandManager.hasSetting(location, APIUtil.toImplementation(role), setting); - } - /** * @return A Set of Members of an Island that are online */ diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandSetting.java b/src/main/java/com/songoda/skyblock/api/island/IslandSetting.java deleted file mode 100644 index 192e1e11..00000000 --- a/src/main/java/com/songoda/skyblock/api/island/IslandSetting.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.songoda.skyblock.api.island; - -public class IslandSetting { - - private final com.songoda.skyblock.island.IslandSetting handle; - - public IslandSetting(com.songoda.skyblock.island.IslandSetting handle) { - this.handle = handle; - } - - /** - * @return The name of the Setting - */ - public String getName() { - return this.handle.getName(); - } - - /** - * @return The status condition of the Setting - */ - public boolean getStatus() { - return this.handle.getStatus(); - } - - /** - * @param status condition for the Setting - */ - public void setStatus(boolean status) { - this.handle.setStatus(status); - } -} diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/BanCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/BanCommand.java index 9c9c09e0..0ff09f8e 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/BanCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/BanCommand.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.UUID; import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.skyblock.permission.PermissionManager; import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -27,6 +28,7 @@ public class BanCommand extends SubCommand { public void onCommandByPlayer(Player player, String[] args) { Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> { MessageManager messageManager = skyblock.getMessageManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); IslandManager islandManager = skyblock.getIslandManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -42,7 +44,7 @@ public class BanCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Visitor.Banning")) { if (island.hasRole(IslandRole.Owner, player.getUniqueId()) - || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && island.getSetting(IslandRole.Operator, "Ban").getStatus())) { + || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && permissionManager.hasPermission(island, "Ban", IslandRole.Operator))) { Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); UUID targetPlayerUUID = null; diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/BansCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/BansCommand.java index ff0ad368..b76fb8e7 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/BansCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/BansCommand.java @@ -30,7 +30,7 @@ public class BansCommand extends SubCommand { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bans.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Unban").getStatus()) + && skyblock.getPermissionManager().hasPermission(island, "Unban", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { if (island.getBan().getBans().size() == 0) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bans.Bans.Message")); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/BiomeCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/BiomeCommand.java index 92a41901..ca7003c6 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/BiomeCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/BiomeCommand.java @@ -32,7 +32,7 @@ public class BiomeCommand extends SubCommand { messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Biome").getStatus()) + && skyblock.getPermissionManager().hasPermission(island,"Biome", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { Biome.getInstance().open(player); soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/BorderCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/BorderCommand.java index d48604bf..a1453cff 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/BorderCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/BorderCommand.java @@ -9,6 +9,7 @@ import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.menus.Border; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -22,6 +23,7 @@ public class BorderCommand extends SubCommand { public void onCommandByPlayer(Player player, String[] args) { MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -34,7 +36,7 @@ public class BorderCommand extends SubCommand { messageManager.sendMessage(player, configLoad.getString("Command.Island.Border.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Border").getStatus()) + && permissionManager.hasPermission(island, "Border", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.WorldBorder.Enable")) { diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java index 32cd2509..117e1bd8 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java @@ -32,7 +32,7 @@ public class CloseCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Visitor").getStatus())) { + && skyblock.getPermissionManager().hasPermission(island,"Visitor", IslandRole.Operator))) { if (island.isOpen()) { islandManager.closeIsland(island); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java index 1c66fbc6..a93e36dc 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.menus.Coop; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.player.OfflinePlayer; import com.songoda.skyblock.utils.world.LocationUtil; @@ -27,6 +28,7 @@ public class CoopCommand extends SubCommand { public void onCommandByPlayer(Player player, String[] args) { MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -44,7 +46,7 @@ public class CoopCommand extends SubCommand { .getBoolean("Island.Coop.Enable")) { if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus())) { + && permissionManager.hasPermission(island, "CoopPlayers", IslandRole.Operator))) { if (args.length == 1 || args.length == 2) { Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/InviteCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/InviteCommand.java index 676ef69e..d175c111 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/InviteCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/InviteCommand.java @@ -46,7 +46,7 @@ public class InviteCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Invite").getStatus())) { + && skyblock.getPermissionManager().hasPermission(island, "Invite", IslandRole.Operator))) { Config mainConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); if ((island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java index 1aa58b71..11794bf7 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java @@ -38,7 +38,7 @@ public class KickAllCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Kick").getStatus())) { + && skyblock.getPermissionManager().hasPermission(island, "Kick", IslandRole.Operator))) { if (island.isOpen()) { Set islandVisitors = islandManager.getVisitorsAtIsland(island); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java index 0850d2d1..a4563ebb 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.UUID; import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.skyblock.permission.PermissionManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; @@ -40,6 +41,7 @@ public class KickCommand extends SubCommand { IslandManager islandManager = skyblock.getIslandManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); PlayerData playerData = playerDataManager.getPlayerData(player); @@ -52,7 +54,7 @@ public class KickCommand extends SubCommand { messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) - || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && island.getSetting(IslandRole.Operator, "Kick").getStatus())) { + || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && permissionManager.hasPermission(island, "Kick", IslandRole.Operator))) { UUID targetPlayerUUID = null; String targetPlayerName = null; diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java index 1c2c3c93..9e7fef50 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java @@ -7,6 +7,7 @@ import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -21,6 +22,7 @@ public class OpenCommand extends SubCommand { MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); SoundManager soundManager = skyblock.getSoundManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -32,7 +34,7 @@ public class OpenCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Visitor").getStatus())) { + && permissionManager.hasPermission(island, "Visitor", IslandRole.Operator))) { if (island.isOpen()) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Open.Already.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java index defb3d0d..3cf701fa 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java @@ -32,7 +32,7 @@ public class PublicCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Visitor").getStatus())) { + && skyblock.getPermissionManager().hasPermission(island, "Visitor", IslandRole.Operator))) { if (island.isOpen()) { islandManager.closeIsland(island); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/SetSpawnCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/SetSpawnCommand.java index 43bd2a5c..e4a55b9e 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/SetSpawnCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/SetSpawnCommand.java @@ -51,7 +51,8 @@ public class SetSpawnCommand extends SubCommand { if (island.hasRole(IslandRole.Operator, player.getUniqueId()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && (island.getSetting(IslandRole.Operator, environment.name() + "Spawn").getStatus())) + && (skyblock.getPermissionManager().hasPermission(island, + environment.name() + "Spawn", IslandRole.Operator))) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { if (islandManager.isPlayerAtIsland(island, player)) { IslandWorld world = skyblock.getWorldManager().getIslandWorld(player.getWorld()); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/SettingsCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/SettingsCommand.java index 0b310616..16f98a9f 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/SettingsCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/SettingsCommand.java @@ -3,11 +3,15 @@ package com.songoda.skyblock.command.commands.island; import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.command.SubCommand; import com.songoda.skyblock.config.FileManager.Config; +import com.songoda.skyblock.gui.GuiPermissions; +import com.songoda.skyblock.gui.GuiPermissionsSelector; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.menus.Settings; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -22,6 +26,7 @@ public class SettingsCommand extends SubCommand { MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); SoundManager soundManager = skyblock.getSoundManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -34,16 +39,15 @@ public class SettingsCommand extends SubCommand { } else if (island.hasRole(IslandRole.Operator, player.getUniqueId()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && (island.getSetting(IslandRole.Operator, "Visitor").getStatus() - || island.getSetting(IslandRole.Operator, "Member").getStatus())) + && (permissionManager.hasPermission(island, "Visitor", IslandRole.Operator) + || permissionManager.hasPermission(island, "Member", IslandRole.Operator))) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { - Settings.getInstance().open(player, - Settings.Type.Categories, null, null); + skyblock.getGuiManager().showGUI(player, new GuiPermissionsSelector(skyblock, island, null)); soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F); - } else { + } else{ messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Default.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); } } else { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Role.Message")); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/UnbanCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/UnbanCommand.java index 9489d6ad..bbbc76f1 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/UnbanCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/UnbanCommand.java @@ -41,7 +41,7 @@ public class UnbanCommand extends SubCommand { .getBoolean("Island.Visitor.Banning")) { if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Unban").getStatus())) { + && skyblock.getPermissionManager().hasPermission(island,"Unban", IslandRole.Operator))) { Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); UUID targetPlayerUUID = null; diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/WeatherCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/WeatherCommand.java index 77a2a283..0b5bd056 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/WeatherCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/WeatherCommand.java @@ -31,7 +31,7 @@ public class WeatherCommand extends SubCommand { messageManager.sendMessage(player, configLoad.getString("Command.Island.Weather.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Weather").getStatus()) + && skyblock.getPermissionManager().hasPermission(island, "Weather", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { Weather.getInstance().open(player); soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java b/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java new file mode 100644 index 00000000..5262fc9c --- /dev/null +++ b/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java @@ -0,0 +1,163 @@ +package com.songoda.skyblock.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.utils.TextUtils; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandPermission; +import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionManager; +import com.songoda.skyblock.permission.PermissionType; +import com.songoda.skyblock.visit.Visit; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class GuiPermissions extends Gui { + + private SkyBlock plugin; + private final PermissionManager permissionManager; + private final IslandRole role; + private final Island island; + private final FileConfiguration configLoad; + private final FileManager.Config config; + private final Gui returnGui; + + public GuiPermissions(SkyBlock plugin, Island island, IslandRole role, Gui returnGui) { + super(6, returnGui); + this.plugin = plugin; + this.permissionManager = plugin.getPermissionManager(); + this.role = role; + this.island = island; + this.returnGui = returnGui; + this.configLoad = plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration(); + this.config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")); + setTitle(TextUtils.formatText(configLoad.getString("Menu.Settings." + role.name() + ".Title"))); + setDefaultItem(null); + paint(); + } + + public void paint() { + if (inventory != null) + inventory.clear(); + setActionForRange(0, 0, 5, 9, null); + + setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> { + CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player); + guiManager.showGUI(event.player, returnGui); + }); + + if (role == IslandRole.Visitor) { + if (config.getFileConfiguration().getBoolean("Island.Visitor.Welcome.Enable")) + setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.MAP, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Welcome.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Visitor.Item.Welcome.Lore"))), + (event) -> { + guiManager.showGUI(event.player, new WelcomeEditor(plugin, this, island)); + }); + + if (config.getFileConfiguration().getBoolean("Island.Visitor.Signature.Enable")) { + setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Signature.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Visitor.Item.Signature.Lore"))), + (event) -> { + guiManager.showGUI(event.player, new SignatureEditor(plugin, this, island)); + }); + } + + Visit visit = island.getVisit(); + List welcomeLore = TextUtils.formatText(configLoad.getStringList( + island.isOpen() + ? "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Closed.Lore" + : "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Open.Lore")); + + List welcomeFinal = new ArrayList<>(); + + for (String line : welcomeLore) { + welcomeFinal.add(line.replace("%visits", String.valueOf(visit.getVisitors().size())) + .replace("%votes", String.valueOf(visit.getVoters().size())) + .replace("%visitors", String.valueOf(plugin.getIslandManager().getVisitorsAtIsland(island).size()))); + } + + setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname")), + welcomeFinal), + (event -> { + if (island.isOpen()) { + plugin.getIslandManager().closeIsland(island); + CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.play(event.player); + } else { + island.setOpen(true); + CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.play(event.player); + } + paint(); + })); + } + + setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> { + CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player); + guiManager.showGUI(event.player, returnGui); + }); + + List permissions = permissionManager.getPermissions().stream() + .filter(p -> p.getType() == getType(role)) + .collect(Collectors.toList()); + double itemCount = permissions.size(); + this.pages = (int) Math.max(1, Math.ceil(itemCount / 36)); + + if (page != 1) + setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Back"), + (event) -> { + page--; + paint(); + }); + + if (page != pages) + setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next"), + (event) -> { + page++; + paint(); + }); + + for (int i = 9; i < 45; i++) { + int current = ((page - 1) * 36) - 9; + if (current + i >= permissions.size()) { + setItem(i, null); + continue; + } + BasicPermission permission = permissions.get(current + i); + if (permission == null) continue; + + setButton(i, permission.getItem(island, role), (event) -> { + IslandPermission islandPermission = island.getPermission(role, permission); + islandPermission.setStatus(!islandPermission.getStatus()); + paint(); + }); + } + } + + public PermissionType getType(IslandRole role) { + switch (role) { + default: + case Visitor: + case Member: + case Coop: + return PermissionType.GENERIC; + case Operator: + return PermissionType.OPERATOR; + case Owner: + return PermissionType.ISLAND; + } + } +} diff --git a/src/main/java/com/songoda/skyblock/gui/GuiPermissionsSelector.java b/src/main/java/com/songoda/skyblock/gui/GuiPermissionsSelector.java new file mode 100644 index 00000000..f7ecb428 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/gui/GuiPermissionsSelector.java @@ -0,0 +1,64 @@ +package com.songoda.skyblock.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.utils.TextUtils; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandRole; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; + +public class GuiPermissionsSelector extends Gui { + + public GuiPermissionsSelector(SkyBlock plugin, Island island, Gui returnGui) { + super(1, returnGui); + setDefaultItem(null); + + FileConfiguration configLoad = plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration(); + + setTitle(ChatColor.translateAlternateColorCodes('&', + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Title")))); + + setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SIGN, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Visitor.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Visitor.Lore"))), (event) -> + guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Visitor, this))); + + setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Member.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Member.Lore"))), (event) -> + guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Member, this))); + + setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Operator.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Operator.Lore"))), (event) -> + guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Operator, this))); + + boolean isCoop = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Coop.Enable"); + + setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> { + CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player); + guiManager.showGUI(event.player, returnGui); + }); + + if (isCoop) + setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.NAME_TAG, + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Coop.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Coop.Lore"))), (event) -> + guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Coop, this))); + + setButton(isCoop ? 7 : 8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SAPLING.getItem(), + TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Owner.Displayname")), + TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Owner.Lore"))), (event) -> + guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Owner, this))); + + } +} diff --git a/src/main/java/com/songoda/skyblock/gui/SignatureEditor.java b/src/main/java/com/songoda/skyblock/gui/SignatureEditor.java new file mode 100644 index 00000000..b80c2a1a --- /dev/null +++ b/src/main/java/com/songoda/skyblock/gui/SignatureEditor.java @@ -0,0 +1,86 @@ +package com.songoda.skyblock.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.core.gui.AnvilGui; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.utils.TextUtils; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandMessage; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class SignatureEditor extends Gui { + + private final SkyBlock plugin; + private final FileConfiguration configLoad; + private final Gui returnGui; + private final Island island; + private final FileManager.Config mainConfig; + + public SignatureEditor(SkyBlock plugin, Gui returnGui, Island island) { + super(1); + this.plugin = plugin; + this.returnGui = returnGui; + this.island = island; + this.configLoad = plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration(); + this.mainConfig = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")); + setDefaultItem(null); + setTitle(TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Title"))); + paint(); + } + + public void paint() { + List signatureMessage = island.getMessage(IslandMessage.Signature); + setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Return.Displayname"))), + (event) -> guiManager.showGUI(event.player, returnGui)); + setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Return.Displayname"))), + (event) -> guiManager.showGUI(event.player, returnGui)); + + setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Line.Add.Displayname")), + TextUtils.formatText(configLoad.getStringList( + signatureMessage.size() == mainConfig.getFileConfiguration().getInt("Island.Visitor.Signature.Lines") + ? "Menu.Settings.Visitor.Panel.Signature.Item.Line.Add.Limit.Lore" + : "Menu.Settings.Visitor.Panel.Signature.Item.Line.Add.More.Lore"))), + (event -> { + AnvilGui gui = new AnvilGui(event.player, this); + gui.setAction((e -> { + signatureMessage.add(gui.getInputText().trim()); + island.setMessage(IslandMessage.Signature, e.player.getName(), signatureMessage); + CompatibleSound.BLOCK_NOTE_BLOCK_PLING.play(e.player); + e.player.closeInventory(); + paint(); + })); + gui.setTitle(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Line.Add.Word.Enter")); + guiManager.showGUI(event.player, gui); + })); + + List itemLore = new ArrayList<>(); + itemLore.add(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Message.Word.Empty")); + setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SIGN, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Message.Displayname")), + TextUtils.formatText(signatureMessage.size() == 0 ? itemLore : signatureMessage))); + + setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Signature.Item.Line.Remove.Displayname")), + TextUtils.formatText(configLoad.getStringList( + signatureMessage.size() == 0 + ? "Menu.Settings.Visitor.Panel.Signature.Item.Line.Remove.None.Lore" + : "Menu.Settings.Visitor.Panel.Signature.Item.Line.Remove.Lines.Lore"))), + (event -> { + signatureMessage.remove(signatureMessage.size() - 1); + island.setMessage(IslandMessage.Signature, event.player.getName(), signatureMessage); + paint(); + })); + } +} diff --git a/src/main/java/com/songoda/skyblock/gui/WelcomeEditor.java b/src/main/java/com/songoda/skyblock/gui/WelcomeEditor.java new file mode 100644 index 00000000..8e05e4a7 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/gui/WelcomeEditor.java @@ -0,0 +1,137 @@ +package com.songoda.skyblock.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.core.gui.AnvilGui; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.utils.TextUtils; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.island.IslandMessage; +import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.message.MessageManager; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class WelcomeEditor extends Gui { + + private final SkyBlock plugin; + private final FileConfiguration configLoad; + private final Gui returnGui; + private final Island island; + private final FileManager.Config mainConfig; + private final MessageManager messageManager; + private final IslandManager islandManager; + + public WelcomeEditor(SkyBlock plugin, Gui returnGui, Island island) { + super(1); + this.plugin = plugin; + this.returnGui = returnGui; + this.island = island; + this.configLoad = plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration(); + this.mainConfig = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")); + this.messageManager = plugin.getMessageManager(); + this.islandManager = plugin.getIslandManager(); + setDefaultItem(null); + setTitle(TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Title"))); + paint(); + } + + public void paint() { + List welcomeMessage = island.getMessage(IslandMessage.Welcome); + setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Return.Displayname"))), + (event) -> guiManager.showGUI(event.player, returnGui)); + setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Return.Displayname"))), + (event) -> guiManager.showGUI(event.player, returnGui)); + + setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Line.Add.Displayname")), + TextUtils.formatText(configLoad.getStringList( + welcomeMessage.size() == mainConfig.getFileConfiguration().getInt("Island.Visitor.Welcome.Lines") + ? "Menu.Settings.Visitor.Panel.Welcome.Item.Line.Add.Limit.Lore" + : "Menu.Settings.Visitor.Panel.Welcome.Item.Line.Add.More.Lore"))), + (event -> { + AnvilGui gui = new AnvilGui(event.player, this); + gui.setAction((e -> { + if (!hasPermission(e.player)) + return; + if (island.getMessage(IslandMessage.Signature) + .size() > mainConfig.getFileConfiguration().getInt( + "Island.Visitor.Signature.Lines") + || gui.getInputText().length() > mainConfig.getFileConfiguration() + .getInt("Island.Visitor.Signature.Length")) { + CompatibleSound.BLOCK_ANVIL_LAND.play(e.player); + } else { + welcomeMessage.add(gui.getInputText().trim()); + island.setMessage(IslandMessage.Welcome, e.player.getName(), welcomeMessage); + CompatibleSound.BLOCK_NOTE_BLOCK_PLING.play(e.player); + } + e.player.closeInventory(); + paint(); + })); + gui.setTitle(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Line.Add.Word.Enter")); + guiManager.showGUI(event.player, gui); + })); + + List itemLore = new ArrayList<>(); + itemLore.add(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Message.Word.Empty")); + setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SIGN, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Message.Displayname")), + TextUtils.formatText(welcomeMessage.size() == 0 ? itemLore : welcomeMessage))); + + setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, + TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Panel.Welcome.Item.Line.Remove.Displayname")), + TextUtils.formatText(configLoad.getStringList( + welcomeMessage.size() == 0 + ? "Menu.Settings.Visitor.Panel.Welcome.Item.Line.Remove.None.Lore" + : "Menu.Settings.Visitor.Panel.Welcome.Item.Line.Remove.Lines.Lore"))), + (event -> { + welcomeMessage.remove(welcomeMessage.size() - 1); + island.setMessage(IslandMessage.Welcome, event.player.getName(), welcomeMessage); + paint(); + })); + } + + private boolean hasPermission(Player player) { + Island island1 = islandManager.getIsland(player); + + if (island1 == null) { + messageManager.sendMessage(player, + configLoad.getString( + "Command.Island.Settings.Owner.Message")); + CompatibleSound.BLOCK_ANVIL_LAND.play(player); + player.closeInventory(); + return false; + } else if (!(island1.hasRole(IslandRole.Operator, + player.getUniqueId()) + || island1.hasRole(IslandRole.Owner, + player.getUniqueId()))) { + messageManager.sendMessage(player, configLoad + .getString("Command.Island.Role.Message")); + CompatibleSound.BLOCK_ANVIL_LAND.play(player); + player.closeInventory(); + return false; + } else if (!plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), + "config.yml")) + .getFileConfiguration().getBoolean( + "Island.Visitor.Signature.Enable")) { + messageManager.sendMessage(player, + configLoad.getString( + "Island.Settings.Visitor.Signature.Disabled.Message")); + CompatibleSound.BLOCK_ANVIL_LAND.play(player); + return false; + } + return true; + } +} diff --git a/src/main/java/com/songoda/skyblock/island/Island.java b/src/main/java/com/songoda/skyblock/island/Island.java index 4b5f2c8c..5faf476c 100644 --- a/src/main/java/com/songoda/skyblock/island/Island.java +++ b/src/main/java/com/songoda/skyblock/island/Island.java @@ -9,6 +9,8 @@ import com.songoda.skyblock.ban.Ban; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.upgrade.Upgrade; @@ -36,7 +38,7 @@ public class Island { private final SkyBlock skyblock; private final com.songoda.skyblock.api.island.Island apiWrapper; - private Map> islandSettings = new HashMap<>(); + private Map> islandPermissions = new HashMap<>(); private List islandLocations = new ArrayList<>(); private Map coopPlayers = new HashMap<>(); @@ -50,6 +52,7 @@ public class Island { this.skyblock = SkyBlock.getInstance(); FileManager fileManager = skyblock.getFileManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); this.islandUUID = UUID.randomUUID(); this.ownerUUID = player.getUniqueId(); @@ -159,18 +162,22 @@ public class Island { } for (IslandRole roleList : IslandRole.getRoles()) { - List settings = new ArrayList<>(); + List permissions = new ArrayList<>(); - for (String settingList : defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false)) { - if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration().getString("Settings." + roleList.name() + "." + settingList) == null) { - settings.add( - new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList))); + for (BasicPermission permission : skyblock.getPermissionManager().getPermissions()) { + + if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration() + .getString("Settings." + roleList.name() + "." + permission.getName()) == null) { + permissions.add( + new IslandPermission(permission, defaultSettingsConfig.getFileConfiguration() + .getBoolean("Settings." + roleList.name() + "." + permission.getName(), true))); } else { - settings.add(new IslandSetting(settingList, settingsDataConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList))); + permissions.add(new IslandPermission(permission, settingsDataConfig.getFileConfiguration() + .getBoolean("Settings." + roleList.name() + "." + permission.getName(), true))); } } - islandSettings.put(roleList, settings); + islandPermissions.put(roleList, permissions); } } else { FileConfiguration configLoad = config.getFileConfiguration(); @@ -186,15 +193,15 @@ public class Island { configLoad.set("Ownership.Original", ownerUUID.toString()); for (IslandRole roleList : IslandRole.getRoles()) { + List allPermissions = skyblock.getPermissionManager().getPermissions(); + List permissions = new ArrayList<>(allPermissions.size()); - Set keys = defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false); - List settings = new ArrayList<>(keys.size()); - - for (String settingList : keys) { - settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList))); + for (BasicPermission permission : allPermissions) { + permissions.add( + new IslandPermission(permission, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + permission, true))); } - islandSettings.put(roleList, settings); + islandPermissions.put(roleList, permissions); } save(); @@ -649,26 +656,34 @@ public class Island { .getFileConfiguration().getBoolean("Upgrade." + type.name()); } - public IslandSetting getSetting(IslandRole role, String setting) { - if (islandSettings.containsKey(role)) { - for (IslandSetting settingList : islandSettings.get(role)) { - if (settingList.getName().equalsIgnoreCase(setting)) { - return settingList; - } + public boolean hasPermission(IslandRole role, BasicPermission permission) { + if (islandPermissions.containsKey(role)) { + for (IslandPermission islandPermission : islandPermissions.get(role)) { + if (islandPermission.getPermission() == permission) + return islandPermission.getStatus(); } } - return new IslandSetting(setting, true); //TODO: Default setting value + return true; //TODO: Default setting value } - public List getSettings(IslandRole role) { - if (islandSettings.containsKey(role)) { - return islandSettings.get(role); + public IslandPermission getPermission(IslandRole role, BasicPermission permission) { + if (islandPermissions.containsKey(role)) { + for (IslandPermission islandPermission : islandPermissions.get(role)) { + if (islandPermission.getPermission() == permission) + return islandPermission; + } } return null; } + public List getSettings(IslandRole role) { + if (islandPermissions.containsKey(role)) + return Collections.unmodifiableList(islandPermissions.get(role)); + return Collections.emptyList(); + } + public double getBankBalance() { return skyblock.getFileManager().getConfig( new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) @@ -809,9 +824,9 @@ public class Island { .getConfig(new File(skyblock.getDataFolder().toString() + "/setting-data", ownerUUID.toString() + ".yml")); FileConfiguration configLoad = config.getFileConfiguration(); - for (Entry> entry : islandSettings.entrySet()) { - for (IslandSetting setting : entry.getValue()) { - configLoad.set("Settings." + entry.getKey() + "." + setting.getName(), setting.getStatus()); + for (Entry> entry : islandPermissions.entrySet()) { + for (IslandPermission permission : entry.getValue()) { + configLoad.set("Settings." + entry.getKey() + "." + permission.getPermission().getName(), permission.getStatus()); } } @@ -879,4 +894,5 @@ public class Island { public com.songoda.skyblock.api.island.Island getAPIWrapper() { return apiWrapper; } + } diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index 77efb555..730f66c8 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -3,7 +3,6 @@ package com.songoda.skyblock.island; import com.google.common.base.Preconditions; import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleSound; -import com.songoda.core.utils.PlayerUtils; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.api.event.island.*; import com.songoda.skyblock.ban.BanManager; @@ -1184,32 +1183,6 @@ public class IslandManager { return islandStorage.containsKey(uuid); } - public boolean hasPermission(Player player, String setting) { - return hasPermission(player, player.getLocation(), setting); - } - - public boolean hasPermission(Player player, org.bukkit.Location location, String setting) { - Island island = getIslandAtLocation(location); - - if (island == null) return true; - - if (player.hasPermission("fabledskyblock.bypass." + setting.toLowerCase())) return true; - - if (island.getSetting(island.getRole(player), setting).getStatus()) return true; - - if (island.isCoopPlayer(player.getUniqueId()) && island.getSetting(IslandRole.Coop, setting).getStatus()) - return true; - - return island.getSetting(IslandRole.Visitor, setting).getStatus(); - } - - public boolean hasSetting(org.bukkit.Location location, IslandRole role, String setting) { - Island island = getIslandAtLocation(location); - if (island == null) return false; - - return island.getSetting(role, setting).getStatus(); - } - public void removeSpawnProtection(org.bukkit.Location location) { Block block = location.getBlock(); @@ -1386,7 +1359,7 @@ public class IslandManager { Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - boolean coopPlayers = island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus(); + boolean coopPlayers = island.hasPermission(IslandRole.Operator, skyblock.getPermissionManager().getPermission("CoopPlayers")); for (Player all : Bukkit.getOnlinePlayers()) { if (uuid != null && all.getUniqueId().equals(uuid)) { @@ -1433,7 +1406,7 @@ public class IslandManager { settings.put("Damage", true); for (String settingList : settings.keySet()) { - if (configLoad.getBoolean("Island.Settings." + settingList + ".Enable") && island.getSetting(IslandRole.Owner, settingList).getStatus() == settings.get(settingList)) { + if (configLoad.getBoolean("Island.Settings." + settingList + ".Enable") && island.hasPermission(IslandRole.Owner, skyblock.getPermissionManager().getPermission(settingList)) == settings.get(settingList)) { safeLevel++; } } diff --git a/src/main/java/com/songoda/skyblock/island/IslandPermission.java b/src/main/java/com/songoda/skyblock/island/IslandPermission.java new file mode 100644 index 00000000..6eb14aaf --- /dev/null +++ b/src/main/java/com/songoda/skyblock/island/IslandPermission.java @@ -0,0 +1,26 @@ +package com.songoda.skyblock.island; + +import com.songoda.skyblock.permission.BasicPermission; + +public class IslandPermission { + + private final BasicPermission permission; + private boolean status; + + public IslandPermission(BasicPermission permission, boolean status) { + this.permission = permission; + this.status = status; + } + + public BasicPermission getPermission() { + return permission; + } + + public boolean getStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } +} diff --git a/src/main/java/com/songoda/skyblock/island/IslandSetting.java b/src/main/java/com/songoda/skyblock/island/IslandSetting.java deleted file mode 100644 index 38b63337..00000000 --- a/src/main/java/com/songoda/skyblock/island/IslandSetting.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.songoda.skyblock.island; - -public class IslandSetting { - - private String name; - private boolean status; - - public IslandSetting(String name, boolean status) { - this.name = name; - this.status = status; - } - - public String getName() { - return this.name; - } - - public boolean getStatus() { - return this.status; - } - - public void setStatus(boolean status) { - this.status = status; - } -} diff --git a/src/main/java/com/songoda/skyblock/listeners/Block.java b/src/main/java/com/songoda/skyblock/listeners/Block.java index c911cc1c..01601b6b 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Block.java +++ b/src/main/java/com/songoda/skyblock/listeners/Block.java @@ -10,6 +10,8 @@ import com.songoda.skyblock.generator.GeneratorManager; import com.songoda.skyblock.island.*; import com.songoda.skyblock.levelling.rework.IslandLevelManager; import com.songoda.skyblock.limit.impl.BlockLimitation; +import com.songoda.skyblock.permission.PermissionManager; +import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; import com.songoda.skyblock.stackable.Stackable; import com.songoda.skyblock.stackable.StackableManager; import com.songoda.skyblock.utils.NumberUtil; @@ -66,10 +68,8 @@ public class Block implements Listener { return; } - if (!islandManager.hasPermission(player, blockLocation, "Destroy")) { - event.setCancelled(true); - skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) { return; } @@ -203,12 +203,10 @@ public class Block implements Listener { return; } - if (!islandManager.hasPermission(player, blockLoc, "Place")) { - event.setCancelled(true); - skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(new PlayerEnterPortalEvent(player, player.getLocation()), + player, island)) return; - } Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -569,7 +567,10 @@ public class Block implements Listener { if (!worldManager.isIslandWorld(block.getWorld())) return; IslandManager islandManager = skyblock.getIslandManager(); - if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "FireSpread")) event.setCancelled(true); + PermissionManager permissionManager = skyblock.getPermissionManager(); + if (!permissionManager.hasPermission( + islandManager.getIslandAtLocation(block.getLocation()),"FireSpread", IslandRole.Owner)) + event.setCancelled(true); } @EventHandler diff --git a/src/main/java/com/songoda/skyblock/listeners/Bucket.java b/src/main/java/com/songoda/skyblock/listeners/Bucket.java index d930a978..1c1af994 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Bucket.java +++ b/src/main/java/com/songoda/skyblock/listeners/Bucket.java @@ -30,19 +30,17 @@ public class Bucket implements Listener { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getBlockClicked(); + IslandManager islandManager = skyblock.getIslandManager(); + CompatibleMaterial clickedBlock = CompatibleMaterial.getBlockMaterial(event.getBlockClicked().getType()); if (clickedBlock == CompatibleMaterial.WATER || clickedBlock == CompatibleMaterial.LAVA) { if (skyblock.getWorldManager().isIslandWorld(block.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, block.getLocation(), "Bucket")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + Island island = islandManager.getIslandAtLocation(block.getLocation()); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; } } } @@ -52,24 +50,21 @@ public class Bucket implements Listener { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getBlockClicked().getRelative(event.getBlockFace()); - if (skyblock.getWorldManager().isIslandWorld(block.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, block.getLocation(), "Bucket")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - WorldManager worldManager = skyblock.getWorldManager(); IslandManager islandManager = skyblock.getIslandManager(); + if (skyblock.getWorldManager().isIslandWorld(block.getWorld())) { + Island island = islandManager.getIslandAtLocation(block.getLocation()); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; + } + if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) return; Island island = islandManager.getIslandAtLocation(block.getLocation()); + if (island == null) return; diff --git a/src/main/java/com/songoda/skyblock/listeners/Death.java b/src/main/java/com/songoda/skyblock/listeners/Death.java index be72e160..178c0b4b 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Death.java +++ b/src/main/java/com/songoda/skyblock/listeners/Death.java @@ -31,8 +31,8 @@ public class Death implements Listener { boolean keepInventory = false; if (configLoad.getBoolean("Island.Settings.KeepItemsOnDeath.Enable")) { - if (skyblock.getIslandManager().hasSetting(player.getLocation(), IslandRole.Owner, - "KeepItemsOnDeath")) { + if (skyblock.getPermissionManager().hasPermission(player.getLocation(),"KeepItemsOnDeath", + IslandRole.Owner)) { keepInventory = true; } } else keepInventory = configLoad.getBoolean("Island.KeepItemsOnDeath.Enable"); diff --git a/src/main/java/com/songoda/skyblock/listeners/Entity.java b/src/main/java/com/songoda/skyblock/listeners/Entity.java index 7e2dff23..3e34e9e4 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Entity.java +++ b/src/main/java/com/songoda/skyblock/listeners/Entity.java @@ -1,25 +1,19 @@ package com.songoda.skyblock.listeners; import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.*; import com.songoda.skyblock.limit.impl.EntityLimitaton; -import com.songoda.skyblock.message.MessageManager; -import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.stackable.StackableManager; import com.songoda.skyblock.upgrade.Upgrade; import com.songoda.skyblock.utils.version.NMSUtil; import com.songoda.skyblock.utils.world.LocationUtil; -import com.songoda.skyblock.utils.world.entity.EntityUtil; import com.songoda.skyblock.world.WorldManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Projectile; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -29,10 +23,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerShearEntityEvent; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; @@ -61,46 +53,16 @@ public class Entity implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); if (!(event.getEntity() instanceof Player)) { return; } Player player = (Player) event.getEntity(); - FileManager fileManager = skyblock.getFileManager(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - event.getCause(); - if (event.getCause() == DamageCause.VOID) { - return; - } else if (event.getCause() == DamageCause.ENTITY_ATTACK) { - EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event; - - if (entityDamageByEntityEvent.getDamager() != null && entityDamageByEntityEvent.getDamager() instanceof Player) { - return; - } - } else { - if (NMSUtil.getVersionNumber() > 11) { - if (event.getCause() == DamageCause.valueOf("ENTITY_SWEEP_ATTACK")) { - EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event; - - if (entityDamageByEntityEvent.getDamager() != null && entityDamageByEntityEvent.getDamager() instanceof Player) { - return; - } - } - } - } - - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - if (configLoad.getBoolean("Island.Settings.Damage.Enable")) { - if (!skyblock.getIslandManager().hasSetting(player.getLocation(), IslandRole.Owner, "Damage")) { - event.setCancelled(true); - } - } else if (!configLoad.getBoolean("Island.Damage.Enable")) { - event.setCancelled(true); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation())); } // Fix a bug in minecraft where arrows with flame still apply fire ticks even if @@ -113,129 +75,40 @@ public class Entity implements Listener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); - SoundManager soundManager = skyblock.getSoundManager(); - FileManager fileManager = skyblock.getFileManager(); if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); org.bukkit.entity.Entity entity = event.getEntity(); if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - if (entity instanceof Player) { - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - if (configLoad.getBoolean("Island.Settings.PvP.Enable")) { - if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "PvP")) { - event.setCancelled(true); - } - } else if (!configLoad.getBoolean("Island.PvP.Enable")) { - event.setCancelled(true); - } - } else if (entity instanceof ArmorStand) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Destroy")) { - event.setCancelled(true); - - messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } else { - // Check if it's a monster and player has the permission to damage the entity - // If - // If it's not a monster or the player has the permission - if (EntityUtil.isMonster(entity.getType()) && islandManager.hasPermission(player, entity.getLocation(), "MonsterHurting")) { - // Player has permission to damage the entity - return; - } - // Either the entity is not a monster or the player doesn't have permission so whe check if he has permission to damage mobs - if (!islandManager.hasPermission(player, entity.getLocation(), "MobHurting")) { - event.setCancelled(true); - - messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } + // Check permissions. + skyblock.getPermissionManager() + .processPermission(event, player, islandManager.getIslandAtLocation(entity.getLocation())); } return; } - if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) { - Player player = (Player) ((Projectile) event.getDamager()).getShooter(); - org.bukkit.entity.Entity entity = event.getEntity(); - - if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - if (event.getEntity() instanceof Player) { - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - if (entity.getType() == EntityType.ITEM_FRAME && !islandManager.hasPermission(player, entity.getLocation(), "HangingDestroy")) { - event.setCancelled(true); - return; - } - - if (configLoad.getBoolean("Island.Settings.PvP.Enable")) { - if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "PvP")) { - event.setCancelled(true); - } - } else if (!configLoad.getBoolean("Island.PvP.Enable")) { - event.setCancelled(true); - } - } else { - // Check if it's a monster and player has the permission to damage the entity - // If - // If it's not a monster or the player has the permission - if (EntityUtil.isMonster(entity.getType()) && islandManager.hasPermission(player, entity.getLocation(), "MonsterHurting")) { - // Player has permission to damage the entity - return; - } - // Either the entity is not a monster or the player doesn't have permission so whe check if he has permission to damage mobs - if (!islandManager.hasPermission(player, entity.getLocation(), "MobHurting")) { - event.setCancelled(true); - - messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - } - } else if (event.getEntity() instanceof Player) { + if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + // Check permissions. + skyblock.getPermissionManager() + .processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation())); - if (configLoad.getBoolean("Island.Settings.Damage.Enable")) { - if (!islandManager.hasSetting(player.getLocation(), IslandRole.Owner, "Damage") || (event.getDamager() instanceof TNTPrimed - && !islandManager.hasSetting(player.getLocation(), IslandRole.Owner, "Explosions"))) { - event.setCancelled(true); - } - } else if (!configLoad.getBoolean("Island.Damage.Enable")) { - event.setCancelled(true); - } - } } else if (event.getDamager() instanceof TNTPrimed) { org.bukkit.entity.Entity entity = event.getEntity(); - if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "Explosions")) { - event.setCancelled(true); - } - } + // Check permissions. + skyblock.getPermissionManager() + .processPermission(event, islandManager.getIslandAtLocation(entity.getLocation())); } // Fix a bug in minecraft where arrows with flame still apply fire ticks even if // the shot entity isn't damaged - if (event.isCancelled() && event.getEntity() != null && event.getDamager() instanceof Arrow + if (event.isCancelled() && event.getDamager() instanceof Arrow && ((Arrow) event.getDamager()).getShooter() instanceof Player) { Arrow arrow = (Arrow) event.getDamager(); if (arrow.getFireTicks() != 0) { @@ -254,19 +127,16 @@ public class Entity implements Listener { Player player = event.getPlayer(); if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, event.getEntity().getLocation(), "Shearing")) { - event.setCancelled(true); + IslandManager islandManager = skyblock.getIslandManager(); + Island island = islandManager.getIslandAtLocation(event.getEntity().getLocation()); - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, island); } } /** - * Checks that an entity is not targeting another entity on different islands. + * Checks that an entity is not targeting another entity on different islands.x * * @author LimeGlass */ @@ -300,13 +170,13 @@ public class Entity implements Listener { @EventHandler public void onStackableInteract(PlayerArmorStandManipulateEvent event) { Player player = event.getPlayer(); - if (!skyblock.getIslandManager().hasPermission(player, event.getRightClicked().getLocation(), "ArmorStandUse")) { - event.setCancelled(true); + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getRightClicked().getLocation()))) + return; if (NMSUtil.getVersionNumber() != 8) return; @@ -325,116 +195,53 @@ public class Entity implements Listener { @EventHandler public void onHangingPlace(HangingPlaceEvent event) { Player player = event.getPlayer(); + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, event.getEntity().getLocation(), "EntityPlacement")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getEntity().getLocation())); } @EventHandler public void onHangingBreak(HangingBreakEvent event) { Hanging hanging = event.getEntity(); + if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - if (event.getCause() != RemoveCause.EXPLOSION) { - return; - } - - if (skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) { - if (!skyblock.getIslandManager().hasSetting(hanging.getLocation(), IslandRole.Owner, "Explosions")) { - event.setCancelled(true); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, null, + islandManager.getIslandAtLocation(hanging.getLocation())); } @EventHandler public void onHangingBreak(HangingBreakByEntityEvent event) { Hanging hanging = event.getEntity(); - if (!(event.getRemover() instanceof Player)) { + if (!(event.getRemover() instanceof Player)) return; - } - Player player = (Player) event.getRemover(); + if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - if (skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, hanging.getLocation(), "HangingDestroy")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - } - - @EventHandler - public void onHangingInteract(PlayerInteractEntityEvent event) { - if (!(event.getRightClicked() instanceof Hanging)) { - return; - } - - Player player = event.getPlayer(); - Hanging hanging = (Hanging) event.getRightClicked(); - - if (skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, hanging.getLocation(), "HangingDestroy")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - } - - @EventHandler - public void onHangingRemoveItem(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player && event.getEntity() instanceof Hanging)) { - return; - } - - Player player = (Player) event.getDamager(); - Hanging hanging = (Hanging) event.getEntity(); - - if (skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, hanging.getLocation(), "HangingDestroy")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, (Player) event.getRemover(), + islandManager.getIslandAtLocation(hanging.getLocation())); } @EventHandler public void onEntityTaming(EntityTameEvent event) { - if (!(event.getOwner() instanceof Player)) { + if (!(event.getOwner() instanceof Player)) return; - } - Player player = (Player) event.getOwner(); + LivingEntity entity = event.getEntity(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, event.getEntity().getLocation(), "MobTaming")) { - event.setCancelled(true); + if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() - .getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, (Player) event.getOwner(), + islandManager.getIslandAtLocation(entity.getLocation())); } @EventHandler @@ -504,10 +311,8 @@ public class Entity implements Listener { event.setCancelled(true); return; } - - if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "MobGriefing")) { - event.setCancelled(true); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, null, island); if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Block.Level.Enable")) @@ -555,9 +360,10 @@ public class Entity implements Listener { IslandManager islandManager = skyblock.getIslandManager(); if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "Explosions")) { + // Check permissions. + if (!skyblock.getPermissionManager().hasPermission(null, + islandManager.getIslandAtLocation(entity.getLocation()), "Explosions")) event.setCancelled(true); - } if (!event.isCancelled()) { Island island = islandManager.getIslandAtLocation(entity.getLocation()); @@ -668,22 +474,16 @@ public class Entity implements Listener { @EventHandler public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) { - if (!(event.getTarget() instanceof Player)) { + if (!(event.getTarget() instanceof Player)) return; - } - - if (!(event.getEntity() instanceof ExperienceOrb)) { - return; - } Player player = (Player) event.getTarget(); + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) return; + IslandManager islandManager = skyblock.getIslandManager(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, "ExperienceOrbPickup")) { - event.setTarget(null); - event.setCancelled(true); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getEntity().getLocation())); } private static final Set CHECKED_REASONS; @@ -724,7 +524,6 @@ public class Entity implements Listener { event.setCancelled(true); return; } - } SpawnReason spawnReason = event.getSpawnReason(); @@ -732,7 +531,7 @@ public class Entity implements Listener { if (!CHECKED_REASONS.contains(spawnReason)) return; if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld())) return; - if (skyblock.getIslandManager().hasSetting(entityLocation, IslandRole.Owner, "NaturalMobSpawning")) return; + if (skyblock.getPermissionManager().hasPermission(null, island, "NaturalMobSpawning")) return; if (spawnReason != SpawnReason.JOCKEY && spawnReason != SpawnReason.MOUNT) { entity.remove(); // Older versions ignore the event being cancelled, so this fixes that issue. return; diff --git a/src/main/java/com/songoda/skyblock/listeners/Food.java b/src/main/java/com/songoda/skyblock/listeners/Food.java index 4ac1d836..b4821104 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Food.java +++ b/src/main/java/com/songoda/skyblock/listeners/Food.java @@ -1,14 +1,11 @@ package com.songoda.skyblock.listeners; import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.island.IslandRole; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.FoodLevelChangeEvent; -import java.io.File; - public class Food implements Listener { private final SkyBlock skyblock; @@ -22,11 +19,8 @@ public class Food implements Listener { Player player = (Player) event.getEntity(); if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) - .getFileConfiguration().getBoolean("Island.Settings.Hunger.Enable") - && !skyblock.getIslandManager().hasSetting(player.getLocation(), IslandRole.Owner, "Hunger")) { - event.setCancelled(true); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, player.getLocation()); } } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Grow.java b/src/main/java/com/songoda/skyblock/listeners/Grow.java index b48068c3..5e684435 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Grow.java +++ b/src/main/java/com/songoda/skyblock/listeners/Grow.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.PermissionManager; import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.event.EventHandler; @@ -182,8 +183,8 @@ public class Grow implements Listener { org.bukkit.block.Block block = event.getBlock(); if (!skyblock.getWorldManager().isIslandWorld(block.getWorld())) return; - IslandManager islandManager = skyblock.getIslandManager(); - if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "FireSpread")) event.setCancelled(true); + PermissionManager permissionManager = skyblock.getPermissionManager(); + if (!permissionManager.hasPermission(block.getLocation(), "FireSpread", IslandRole.Owner)) event.setCancelled(true); } @EventHandler @@ -191,8 +192,8 @@ public class Grow implements Listener { org.bukkit.block.Block block = event.getBlock(); if (!skyblock.getWorldManager().isIslandWorld(block.getWorld())) return; - IslandManager islandManager = skyblock.getIslandManager(); - if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "LeafDecay")) event.setCancelled(true); + PermissionManager permissionManager = skyblock.getPermissionManager(); + if (!permissionManager.hasPermission(block.getLocation(), "LeafDecay", IslandRole.Owner)) event.setCancelled(true); } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Interact.java b/src/main/java/com/songoda/skyblock/listeners/Interact.java index ef6034eb..49a14c00 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Interact.java +++ b/src/main/java/com/songoda/skyblock/listeners/Interact.java @@ -18,20 +18,13 @@ import com.songoda.skyblock.stackable.Stackable; import com.songoda.skyblock.stackable.StackableManager; import com.songoda.skyblock.utils.NumberUtil; import com.songoda.skyblock.utils.structure.StructureUtil; -import com.songoda.skyblock.utils.version.NMSUtil; import com.songoda.skyblock.world.WorldManager; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.block.Beacon; -import org.bukkit.block.CreatureSpawner; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Horse; import org.bukkit.entity.Player; -import org.bukkit.entity.minecart.StorageMinecart; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -41,7 +34,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; @@ -66,9 +58,7 @@ public class Interact implements Listener { return; } - MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); - SoundManager soundManager = skyblock.getSoundManager(); StackableManager stackableManager = skyblock.getStackableManager(); IslandLevelManager levellingManager = skyblock.getLevellingManager(); @@ -78,64 +68,12 @@ public class Interact implements Listener { return; } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { - if (CompatibleMaterial.getMaterial(block.getType()) == CompatibleMaterial.DRAGON_EGG) { - if (!islandManager.hasPermission(player, block.getLocation(), "DragonEggUse")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (block.getState() instanceof Beacon) { // ChunkCollectors support - if (!islandManager.hasPermission(player, block.getLocation(), "Beacon")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (block.getState() instanceof InventoryHolder || block.getState() instanceof CreatureSpawner) { // EpicHoppers/EpicSpawners support - if (!islandManager.hasPermission(player, block.getLocation(), "Storage")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (CompatibleMaterial.getMaterial(block.getType()) == CompatibleMaterial.CAULDRON) { // WildStacker stackables - if (!islandManager.hasPermission(player, block.getLocation(), "Place") || !islandManager.hasPermission(player, block.getLocation(), "Destroy")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - } - - if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) { - if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.EGG) { - if (!skyblock.getIslandManager().hasPermission(player, "Projectile")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - } - CompatibleMaterial material = block == null ? null : CompatibleMaterial.getMaterial(block.getType()); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { final CompatibleMaterial blockType = CompatibleMaterial.getBlockMaterial(event.getClickedBlock().getType()); final CompatibleMaterial heldType; @@ -147,8 +85,8 @@ public class Interact implements Listener { heldType = CompatibleMaterial.AIR; } - if (stackableManager != null && stackableManager.isStackableMaterial(heldType) && blockType == heldType && !player.isSneaking() && islandManager - .hasPermission(player, block.getLocation(), "Place") + if (stackableManager != null && stackableManager.isStackableMaterial(heldType) && blockType == heldType + && !player.isSneaking() && skyblock.getPermissionManager().hasPermission(player, island, "Place") && (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Stackable.RequirePermission") || player.hasPermission("fabledskyblock.stackable"))) { @@ -248,215 +186,13 @@ public class Interact implements Listener { return; } - if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BONE_MEAL && !islandManager.hasPermission(player, block.getLocation(), "Place")) { - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - event.setCancelled(true); - return; - } - - if (material == CompatibleMaterial.SWEET_BERRY_BUSH) { - if (!islandManager.hasPermission(player, block.getLocation(), "Destroy")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.ANVIL) { - if (!islandManager.hasPermission(player, block.getLocation(), "Anvil")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.WHITE_BED || material == CompatibleMaterial.ORANGE_BED - || material == CompatibleMaterial.MAGENTA_BED || material == CompatibleMaterial.LIGHT_BLUE_BED - || material == CompatibleMaterial.YELLOW_BED || material == CompatibleMaterial.LIME_BED - || material == CompatibleMaterial.PINK_BED || material == CompatibleMaterial.GRAY_BED - || material == CompatibleMaterial.LIGHT_GRAY_BED || material == CompatibleMaterial.CYAN_BED - || material == CompatibleMaterial.CYAN_BED || material == CompatibleMaterial.PURPLE_BED - || material == CompatibleMaterial.BLUE_BED || material == CompatibleMaterial.BROWN_BED - || material == CompatibleMaterial.GREEN_BED || material == CompatibleMaterial.RED_BED - || material == CompatibleMaterial.BLACK_BED - ) { - if (!islandManager.hasPermission(player, block.getLocation(), "Bed")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.BREWING_STAND) { - if (!islandManager.hasPermission(player, block.getLocation(), "Brewing")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.CHEST || material == CompatibleMaterial.TRAPPED_CHEST - || (NMSUtil.getVersionNumber() > 9 && (material == CompatibleMaterial.SHULKER_BOX - || material == CompatibleMaterial.BLACK_SHULKER_BOX || material == CompatibleMaterial.BLUE_SHULKER_BOX - || material == CompatibleMaterial.BROWN_SHULKER_BOX || material == CompatibleMaterial.CYAN_SHULKER_BOX - || material == CompatibleMaterial.GRAY_SHULKER_BOX || material == CompatibleMaterial.GREEN_SHULKER_BOX - || material == CompatibleMaterial.LIGHT_BLUE_SHULKER_BOX || material == CompatibleMaterial.LIGHT_GRAY_SHULKER_BOX - || material == CompatibleMaterial.LIME_SHULKER_BOX || material == CompatibleMaterial.MAGENTA_SHULKER_BOX - || material == CompatibleMaterial.ORANGE_SHULKER_BOX || material == CompatibleMaterial.PINK_SHULKER_BOX - || material == CompatibleMaterial.PURPLE_SHULKER_BOX || material == CompatibleMaterial.RED_SHULKER_BOX - || material == CompatibleMaterial.WHITE_SHULKER_BOX || material == CompatibleMaterial.YELLOW_SHULKER_BOX))) { - if (!islandManager.hasPermission(player, block.getLocation(), "Storage")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.CRAFTING_TABLE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Workbench")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.BIRCH_DOOR || material == CompatibleMaterial.ACACIA_DOOR - || material == CompatibleMaterial.DARK_OAK_DOOR || material == CompatibleMaterial.JUNGLE_DOOR - || material == CompatibleMaterial.SPRUCE_DOOR || material == CompatibleMaterial.OAK_DOOR) { - if (!islandManager.hasPermission(player, block.getLocation(), "Door")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.ENCHANTING_TABLE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Enchant")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.FURNACE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Furnace")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.STONE_BUTTON || material == CompatibleMaterial.OAK_BUTTON || material == CompatibleMaterial.SPRUCE_BUTTON - || material == CompatibleMaterial.BIRCH_BUTTON || material == CompatibleMaterial.JUNGLE_BUTTON || material == CompatibleMaterial.ACACIA_BUTTON - || material == CompatibleMaterial.DARK_OAK_BUTTON || material == CompatibleMaterial.LEVER) { - if (!islandManager.hasPermission(player, block.getLocation(), "LeverButton")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.JUKEBOX) { - if (!islandManager.hasPermission(player, block.getLocation(), "Jukebox")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.OAK_TRAPDOOR || material == CompatibleMaterial.SPRUCE_TRAPDOOR - || material == CompatibleMaterial.BIRCH_TRAPDOOR || material == CompatibleMaterial.JUNGLE_TRAPDOOR - || material == CompatibleMaterial.ACACIA_TRAPDOOR || material == CompatibleMaterial.DARK_OAK_TRAPDOOR - || material == CompatibleMaterial.NOTE_BLOCK || material == CompatibleMaterial.HOPPER - || material == CompatibleMaterial.COMPARATOR || material == CompatibleMaterial.REPEATER) { - if (material == CompatibleMaterial.HOPPER && !islandManager.hasPermission(player, block.getLocation(), "Hopper")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - if (!islandManager.hasPermission(player, block.getLocation(), "Redstone")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.OAK_FENCE_GATE || material == CompatibleMaterial.ACACIA_FENCE_GATE || material == CompatibleMaterial.BIRCH_FENCE_GATE - || material == CompatibleMaterial.DARK_OAK_FENCE_GATE || material == CompatibleMaterial.JUNGLE_FENCE_GATE || material == CompatibleMaterial.SPRUCE_FENCE_GATE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Gate")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if ((material == CompatibleMaterial.DROPPER || (material == CompatibleMaterial.DISPENSER))) { - if (!islandManager.hasPermission(player, block.getLocation(), "DropperDispenser")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.TNT) { - if (!islandManager.hasPermission(player, block.getLocation(), "Destroy")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (material == CompatibleMaterial.CAKE) { - if (player.getFoodLevel() < 20 && !islandManager.hasPermission(player, block.getLocation(), "Cake")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (player.getGameMode() == GameMode.SURVIVAL + if (player.getGameMode() == GameMode.SURVIVAL && material == CompatibleMaterial.OBSIDIAN && event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BUCKET) { - if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Block.Obsidian.Enable") - && islandManager.hasPermission(player, block.getLocation(), "Bucket")) { + if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Block.Obsidian.Enable")) { CompatibleSound.BLOCK_FIRE_EXTINGUISH.play(block.getWorld(), block.getLocation(), 1.0F, 1.0F); block.setType(CompatibleMaterial.AIR.getBlockMaterial()); @@ -470,8 +206,8 @@ public class Interact implements Listener { return; } } else if (material == CompatibleMaterial.END_PORTAL_FRAME) { - if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Block.EndFrame.Enable") - && islandManager.hasPermission(player, block.getLocation(), "Destroy")) { + if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Block.EndFrame.Enable")) { if (Bukkit.getPluginManager().isPluginEnabled("EpicAnchors")) { if (com.songoda.epicanchors.EpicAnchors.getInstance().getAnchorManager().getAnchor(block.getLocation()) != null) { @@ -532,94 +268,6 @@ public class Interact implements Listener { } } } - - if ((event.getItem() != null) && (CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR) && !event.isCancelled()) { - if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BUCKET - || CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.WATER_BUCKET - || CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.LAVA_BUCKET) { - if (!islandManager.hasPermission(player, block.getLocation(), "Bucket")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - player.updateInventory(); - } - } else if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.GLASS_BOTTLE) { - if (material == CompatibleMaterial.WATER || material == CompatibleMaterial.CAULDRON) { - if (!islandManager.hasPermission(player, block.getLocation(), "WaterCollection")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - player.updateInventory(); - } - } - } else if (event.getItem().getType().name().contains("SPAWN_EGG") || event.getItem().getType().name().equals("MONSTER_EGG")) { - if (!islandManager.hasPermission(player, block.getLocation(), "SpawnEgg")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - player.updateInventory(); - } - } else if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.ARMOR_STAND || event.getItem().getType().name().contains("BOAT") || event.getItem().getType().name().contains("MINECART")) { - if (!islandManager.hasPermission(player, block.getLocation(), "EntityPlacement")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - player.updateInventory(); - } - } - } - } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - // Note: Cast is necessary as it is ambiguous without it in 1.8 - if (CompatibleMaterial.getMaterial(player.getTargetBlock(null, 5).getType()) == CompatibleMaterial.FIRE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Fire")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - } else if (event.getAction() == Action.PHYSICAL) { - if (material == CompatibleMaterial.TURTLE_EGG) { - event.setCancelled(true); - } else if (material == CompatibleMaterial.FARMLAND) { - if (!islandManager.hasPermission(player, block.getLocation(), "Crop")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } else if (material == CompatibleMaterial.STONE_PRESSURE_PLATE || material == CompatibleMaterial.OAK_PRESSURE_PLATE - || material == CompatibleMaterial.SPRUCE_PRESSURE_PLATE || material == CompatibleMaterial.BIRCH_PRESSURE_PLATE - || material == CompatibleMaterial.JUNGLE_PRESSURE_PLATE || material == CompatibleMaterial.ACACIA_PRESSURE_PLATE - || material == CompatibleMaterial.DARK_OAK_PRESSURE_PLATE - || material == CompatibleMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE - || material == CompatibleMaterial.HEAVY_WEIGHTED_PRESSURE_PLATE) { - if (!islandManager.hasPermission(player, block.getLocation(), "PressurePlate")) { - event.setCancelled(true); - } - } else if (material == CompatibleMaterial.TRIPWIRE) { - if (!islandManager.hasPermission(player, block.getLocation(), "Redstone")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } } } @@ -693,219 +341,15 @@ public class Interact implements Listener { Player player = event.getPlayer(); org.bukkit.entity.Entity entity = event.getRightClicked(); - ItemStack is = player.getItemInHand(); - - MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); - SoundManager soundManager = skyblock.getSoundManager(); - if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - if ((is != null) && (CompatibleMaterial.getMaterial(is) != CompatibleMaterial.AIR)) { - if (CompatibleMaterial.getMaterial(is) == CompatibleMaterial.LEAD) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Leash")) { - event.setCancelled(true); + if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld())) return; - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + Island island = islandManager.getIslandAtLocation(entity.getLocation()); - return; - } - } - } - - if (entity.getType() == EntityType.HORSE || entity.getType() == EntityType.PIG) { - if (entity.getType() == EntityType.HORSE) { - Horse horse = (Horse) event.getRightClicked(); - - if (horse.getInventory().getSaddle() != null && player.isSneaking()) { - if (!islandManager.hasPermission(player, horse.getLocation(), "HorseInventory")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else { - if (!islandManager.hasPermission(player, horse.getLocation(), "MobRiding")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - } else if (entity.getType() == EntityType.PIG) { - if (!islandManager.hasPermission(player, entity.getLocation(), "MobRiding")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - } else if (entity.getType().equals(EntityType.SHEEP)) { - if (!islandManager.hasPermission(player, entity.getLocation(), "EntityPlacement")) { - event.setCancelled(true); - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } else if (entity.getType().equals(EntityType.ITEM_FRAME)) { - if (!skyblock.getIslandManager().hasPermission(player, entity.getLocation(), "Storage")) { - event.setCancelled(true); - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } else if (entity.getType() == EntityType.COW || entity.getType() == EntityType.MUSHROOM_COW) { - if (CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BUCKET) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Milking")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - } else if (entity.getType() == EntityType.VILLAGER) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Trading")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (entity instanceof StorageMinecart) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Storage")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (entity.getType() == EntityType.MINECART || entity.getType() == EntityType.BOAT) { - if (!islandManager.hasPermission(player, entity.getLocation(), "MinecartBoat")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } else if (entity.getType() == EntityType.MINECART_HOPPER) { - if (!islandManager.hasPermission(player, entity.getLocation(), "Hopper")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - - return; - } - } - - if (entity.getType() == EntityType.HORSE) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_APPLE - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_CARROT - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SUGAR - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.APPLE - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.HAY_BLOCK)) { - return; - } - } else if (entity.getType() == EntityType.SHEEP || entity.getType() == EntityType.COW || entity.getType() == EntityType.MUSHROOM_COW) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT)) { - return; - } - } else if (entity.getType() == EntityType.PIG) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CARROT || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.POTATO)) { - return; - } - } else if (entity.getType() == EntityType.CHICKEN) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT_SEEDS - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PUMPKIN_SEEDS || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.MELON_SEEDS)) { - if (NMSUtil.getVersionNumber() > 8) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BEETROOT_SEEDS)) { - return; - } - } else { - return; - } - } - } else if (entity.getType() == EntityType.WOLF) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BONE - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PORKCHOP - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BEEF - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CHICKEN - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.RABBIT - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.MUTTON - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.ROTTEN_FLESH - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_PORKCHOP - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_BEEF - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_CHICKEN - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_RABBIT - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_MUTTON)) { - return; - } - } else if (entity.getType() == EntityType.OCELOT) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COD - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SALMON - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.TROPICAL_FISH - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PUFFERFISH)) { - return; - } - } else if (entity.getType() == EntityType.RABBIT) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.DANDELION - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CARROTS - || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_CARROT)) { - return; - } - } else { - int NMSVersion = NMSUtil.getVersionNumber(); - - if (NMSVersion > 10) { - if (entity.getType() == EntityType.LLAMA) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.HAY_BLOCK)) { - return; - } - } else if (NMSVersion > 12) { - if (entity.getType() == EntityType.TURTLE) { - if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SEAGRASS)) { - return; - } - } else { - return; - } - } else { - return; - } - } else { - return; - } - } - - if (!islandManager.hasPermission(player, entity.getLocation(), "AnimalBreeding")) { - event.setCancelled(true); - - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; } @EventHandler @@ -914,15 +358,17 @@ public class Interact implements Listener { return; } + IslandManager islandManager = skyblock.getIslandManager(); + Player player = (Player) event.getAttacker(); - if (!skyblock.getIslandManager().hasPermission(player, event.getVehicle().getLocation(), "MobHurting")) { - event.setCancelled(true); + if (!skyblock.getWorldManager().isIslandWorld(event.getVehicle().getWorld())) return; - skyblock.getMessageManager() - .sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + Island island = islandManager.getIslandAtLocation(event.getVehicle().getLocation()); + + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; } @EventHandler @@ -931,15 +377,17 @@ public class Interact implements Listener { return; } + IslandManager islandManager = skyblock.getIslandManager(); + Player player = (Player) event.getAttacker(); - if (!skyblock.getIslandManager().hasPermission(player, event.getVehicle().getLocation(), "MobHurting")) { - event.setCancelled(true); + if (!skyblock.getWorldManager().isIslandWorld(event.getVehicle().getWorld())) return; - skyblock.getMessageManager() - .sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + Island island = islandManager.getIslandAtLocation(event.getVehicle().getLocation()); + + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(event, player, island)) + return; } @EventHandler(ignoreCancelled = true) @@ -948,25 +396,4 @@ public class Interact implements Listener { event.setCancelled(true); } } - - @EventHandler - public void onPlayerInteractAtEntity(PlayerInteractEntityEvent event) { - Player player = event.getPlayer(); - org.bukkit.entity.Entity entity = event.getRightClicked(); - - if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { - return; - } - - if (entity instanceof ArmorStand) { - if (!skyblock.getIslandManager().hasPermission(player, entity.getLocation(), "ArmorStandUse")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } - - } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Inventory.java b/src/main/java/com/songoda/skyblock/listeners/Inventory.java index 037214f3..f97eb152 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Inventory.java +++ b/src/main/java/com/songoda/skyblock/listeners/Inventory.java @@ -1,14 +1,10 @@ package com.songoda.skyblock.listeners; -import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.SkyBlock; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.inventory.HorseInventory; - -import java.io.File; public class Inventory implements Listener { @@ -22,19 +18,10 @@ public class Inventory implements Listener { public void onInventoryOpen(InventoryOpenEvent event) { Player player = (Player) event.getPlayer(); - if (!(event.getInventory() instanceof HorseInventory)) { - return; - } - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, "HorseInventory")) { - event.setCancelled(true); - - skyblock.getMessageManager().sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - skyblock.getSoundManager().playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + skyblock.getIslandManager().getIsland(player)); } } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Item.java b/src/main/java/com/songoda/skyblock/listeners/Item.java index 3e115d59..00917de8 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Item.java +++ b/src/main/java/com/songoda/skyblock/listeners/Item.java @@ -1,6 +1,8 @@ package com.songoda.skyblock.listeners; import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -18,23 +20,25 @@ public class Item implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); Player player = event.getPlayer(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, "ItemDrop")) { - event.setCancelled(true); - } - } + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) return; + + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getItemDrop().getLocation())); } @EventHandler public void onPlayerPickupItem(PlayerPickupItemEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); Player player = event.getPlayer(); - if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) { - if (!skyblock.getIslandManager().hasPermission(player, "ItemPickup")) { - event.setCancelled(true); - } - } + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) return; + + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getItem().getLocation())); } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Move.java b/src/main/java/com/songoda/skyblock/listeners/Move.java index 05957bad..55cf5071 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Move.java +++ b/src/main/java/com/songoda/skyblock/listeners/Move.java @@ -6,6 +6,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -49,6 +50,7 @@ public class Move implements Listener { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); WorldManager worldManager = skyblock.getWorldManager(); FileManager fileManager = skyblock.getFileManager(); @@ -105,7 +107,7 @@ public class Move implements Listener { boolean keepItemsOnDeath; if (configLoad.getBoolean("Island.Settings.KeepItemsOnDeath.Enable")) { - keepItemsOnDeath = island.getSetting(IslandRole.Owner, "KeepItemsOnDeath").getStatus(); + keepItemsOnDeath = permissionManager.hasPermission(island,"KeepItemsOnDeath", IslandRole.Owner); } else { keepItemsOnDeath = configLoad.getBoolean("Island.KeepItemsOnDeath.Enable"); } diff --git a/src/main/java/com/songoda/skyblock/listeners/Portal.java b/src/main/java/com/songoda/skyblock/listeners/Portal.java index 8c94659d..03c79bd1 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Portal.java +++ b/src/main/java/com/songoda/skyblock/listeners/Portal.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.island.IslandEnvironment; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.world.WorldManager; @@ -43,10 +44,7 @@ public class Portal implements Listener { org.bukkit.block.Block from = event.getFrom().getBlock(); org.bukkit.block.Block to = event.getTo().getBlock(); - MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); - FileManager fileManager = skyblock.getFileManager(); - SoundManager soundManager = skyblock.getSoundManager(); if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) return; @@ -54,15 +52,9 @@ public class Portal implements Listener { if (island == null) return; - CompatibleMaterial toMaterial = CompatibleMaterial.getMaterial(to.getType()); - - if( (toMaterial == CompatibleMaterial.NETHER_BRICK || toMaterial == CompatibleMaterial.END_PORTAL) - && !islandManager.hasPermission(player, player.getLocation(), "Portal")) { - event.setTo(LocationUtil.getRandomLocation(event.getFrom().getWorld(), 5000, 5000, true, true)); - messageManager.sendMessage(player, - fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } + // Check permissions. + skyblock.getPermissionManager().processPermission(event, player, + islandManager.getIslandAtLocation(event.getTo())); } @EventHandler(priority = EventPriority.LOW) @@ -87,24 +79,22 @@ public class Portal implements Listener { Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - if (!islandManager.hasPermission(player, player.getLocation(), "Portal")) { - messageManager.sendMessage(player, - fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(new PlayerEnterPortalEvent(player, player.getLocation()), + player, island)) return; - } IslandEnvironment spawnEnvironment; switch (island.getRole(player)) { - case Operator: - case Owner: - case Member: - case Coop: - spawnEnvironment = IslandEnvironment.Main; - break; + case Operator: + case Owner: + case Member: + case Coop: + spawnEnvironment = IslandEnvironment.Main; + break; - default: - spawnEnvironment = IslandEnvironment.Visitor; + default: + spawnEnvironment = IslandEnvironment.Visitor; } Tick tick; @@ -133,37 +123,39 @@ public class Portal implements Listener { IslandWorld fromWorld = worldManager.getIslandWorld(player.getWorld()); IslandWorld toWorld = IslandWorld.Normal; - if (CompatibleMaterial.getMaterial(block.getType()).equals(CompatibleMaterial.NETHER_PORTAL)) toWorld = fromWorld.equals(IslandWorld.Normal) ? IslandWorld.Nether : IslandWorld.Normal; - else if (CompatibleMaterial.getMaterial(block.getType()).equals(CompatibleMaterial.END_PORTAL)) toWorld = fromWorld.equals(IslandWorld.Normal) ? IslandWorld.End : IslandWorld.Normal; + if (CompatibleMaterial.getMaterial(block.getType()).equals(CompatibleMaterial.NETHER_PORTAL)) + toWorld = fromWorld.equals(IslandWorld.Normal) ? IslandWorld.Nether : IslandWorld.Normal; + else if (CompatibleMaterial.getMaterial(block.getType()).equals(CompatibleMaterial.END_PORTAL)) + toWorld = fromWorld.equals(IslandWorld.Normal) ? IslandWorld.End : IslandWorld.Normal; switch (toWorld) { - case Nether: - if (configLoad.getBoolean("Island.World.Nether.Enable") && island.isRegionUnlocked(player, "Nether")) { + case Nether: + if (configLoad.getBoolean("Island.World.Nether.Enable") && island.isRegionUnlocked(player, "Nether")) { + IslandWorld toWorldF = toWorld; + Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> player.teleport(island.getLocation(toWorldF, spawnEnvironment)), 1L); + soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); + player.setFallDistance(0.0F); + tick.setTick(1); + } + break; + + case End: + if (configLoad.getBoolean("Island.World.End.Enable") && island.isRegionUnlocked(player, "End")) { + IslandWorld toWorldF = toWorld; + Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> player.teleport(island.getLocation(toWorldF, spawnEnvironment)), 1L); + soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); + player.setFallDistance(0.0F); + tick.setTick(1); + } + break; + + default: IslandWorld toWorldF = toWorld; Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> player.teleport(island.getLocation(toWorldF, spawnEnvironment)), 1L); soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); player.setFallDistance(0.0F); tick.setTick(1); - } - break; - - case End: - if (configLoad.getBoolean("Island.World.End.Enable") && island.isRegionUnlocked(player, "End")) { - IslandWorld toWorldF = toWorld; - Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> player.teleport(island.getLocation(toWorldF, spawnEnvironment)), 1L); - soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); - player.setFallDistance(0.0F); - tick.setTick(1); - } - break; - - default: - IslandWorld toWorldF = toWorld; - Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> player.teleport(island.getLocation(toWorldF, spawnEnvironment)), 1L); - soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); - player.setFallDistance(0.0F); - tick.setTick(1); - break; + break; } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Projectile.java b/src/main/java/com/songoda/skyblock/listeners/Projectile.java index dc869b0b..e3bbdeae 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Projectile.java +++ b/src/main/java/com/songoda/skyblock/listeners/Projectile.java @@ -1,58 +1,38 @@ package com.songoda.skyblock.listeners; -import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; -import org.bukkit.entity.FishHook; +import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.projectiles.ProjectileSource; -import java.io.File; - public class Projectile implements Listener { - private final SkyBlock skyblock; + private final SkyBlock skyblock; - public Projectile(SkyBlock skyblock) { - this.skyblock = skyblock; - } + public Projectile(SkyBlock skyblock) { + this.skyblock = skyblock; + } - @EventHandler - public void onProjectileLaunch(ProjectileLaunchEvent event) { - org.bukkit.entity.Projectile projectile = event.getEntity(); - ProjectileSource shooter = projectile.getShooter(); - if (!(shooter instanceof Player)) - return; + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent event) { + org.bukkit.entity.Projectile projectile = event.getEntity(); + ProjectileSource shooter = projectile.getShooter(); + if (!(shooter instanceof Player)) + return; - MessageManager messageManager = skyblock.getMessageManager(); - SoundManager soundManager = skyblock.getSoundManager(); - Player player = (Player) shooter; + Player player = (Player) shooter; - if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) - return; + if (!skyblock.getWorldManager().isIslandWorld(player.getWorld())) + return; - if (projectile instanceof FishHook) { - if (!skyblock.getIslandManager().hasPermission(player, "Fishing")) { - event.setCancelled(true); - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - return; - } - - if (!skyblock.getIslandManager().hasPermission(player, "Projectile")) { - event.setCancelled(true); - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - } + // Check permissions. + skyblock.getPermissionManager().processPermission(new ProjectileLaunchByPlayerEvent(event.getEntity()), player, player.getLocation()); + } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Teleport.java b/src/main/java/com/songoda/skyblock/listeners/Teleport.java index f2841f4d..62b733ef 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Teleport.java +++ b/src/main/java/com/songoda/skyblock/listeners/Teleport.java @@ -11,10 +11,10 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; -import com.songoda.skyblock.utils.version.NMSUtil; import com.songoda.skyblock.visit.Visit; import com.songoda.skyblock.world.WorldManager; import org.bukkit.Bukkit; @@ -27,7 +27,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import java.io.File; import java.util.UUID; @@ -58,31 +57,13 @@ public class Teleport implements Listener { islandManager.loadPlayer(player); if (worldManager.isIslandWorld(player.getWorld())) { - boolean isCause = false; - if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.NETHER_PORTAL || event.getCause() == TeleportCause.END_PORTAL) { - isCause = true; - } else { - if (NMSUtil.getVersionNumber() > 9) { - if (event.getCause() == TeleportCause.END_GATEWAY) { - isCause = true; - } - } - } - - if (isCause && !islandManager.hasPermission(player, "Portal")) { - event.setCancelled(true); - - messageManager.sendMessage(player, configLoad.getString("Island.Settings.Permission.Message")); - soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); + com.songoda.skyblock.island.Island island = islandManager.getIslandAtLocation(event.getTo()); + // Check permissions. + if (!skyblock.getPermissionManager().processPermission(new PlayerEnterPortalEvent(player, player.getLocation()), + player, island)) return; - } - - if (isCause && event.getCause() != TeleportCause.ENDER_PEARL) { - event.setCancelled(true); - return; - } } if (playerDataManager.hasPlayerData(player)) { diff --git a/src/main/java/com/songoda/skyblock/menus/Bans.java b/src/main/java/com/songoda/skyblock/menus/Bans.java index ff504f79..03df6a45 100644 --- a/src/main/java/com/songoda/skyblock/menus/Bans.java +++ b/src/main/java/com/songoda/skyblock/menus/Bans.java @@ -140,7 +140,7 @@ public class Bans { Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> open(player), 1L); } else { if ((island1.hasRole(IslandRole.Operator, player.getUniqueId()) - && island1.getSetting(IslandRole.Operator, "Unban").getStatus()) + && skyblock.getPermissionManager().hasPermission(island1,"Unban", IslandRole.Operator)) || island1.hasRole(IslandRole.Owner, player.getUniqueId())) { String playerName = ChatColor.stripColor(is.getItemMeta().getDisplayName()); Bukkit.getServer().dispatchCommand(player, "island unban " + playerName); diff --git a/src/main/java/com/songoda/skyblock/menus/Biome.java b/src/main/java/com/songoda/skyblock/menus/Biome.java index bea1f59a..47a0c4a1 100644 --- a/src/main/java/com/songoda/skyblock/menus/Biome.java +++ b/src/main/java/com/songoda/skyblock/menus/Biome.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.cooldown.CooldownPlayer; import com.songoda.skyblock.cooldown.CooldownType; import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -47,6 +48,7 @@ public class Biome { CooldownManager cooldownManager = skyblock.getCooldownManager(); MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); BiomeManager biomeManager = skyblock.getBiomeManager(); SoundManager soundManager = skyblock.getSoundManager(); @@ -64,7 +66,7 @@ public class Biome { return; } else if (!((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Biome").getStatus()) + && permissionManager.hasPermission(island, "Biome", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId()))) { messageManager.sendMessage(player, langConfig.getString("Command.Island.Biome.Permission.Message")); diff --git a/src/main/java/com/songoda/skyblock/menus/Border.java b/src/main/java/com/songoda/skyblock/menus/Border.java index eaa65790..dc72f77d 100644 --- a/src/main/java/com/songoda/skyblock/menus/Border.java +++ b/src/main/java/com/songoda/skyblock/menus/Border.java @@ -55,7 +55,7 @@ public class Border { return; } else if (!((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Border").getStatus()) + && skyblock.getPermissionManager().hasPermission(island,"Border", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId()))) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Border.Permission.Message")); diff --git a/src/main/java/com/songoda/skyblock/menus/Coop.java b/src/main/java/com/songoda/skyblock/menus/Coop.java index b701bbbf..488818a1 100644 --- a/src/main/java/com/songoda/skyblock/menus/Coop.java +++ b/src/main/java/com/songoda/skyblock/menus/Coop.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.island.IslandCoop; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -49,6 +50,7 @@ public class Coop { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -161,7 +163,7 @@ public class Coop { Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> open(player), 1L); } else { if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus()) + && permissionManager.hasPermission(island, "CoopPlayers", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { String playerName = ChatColor.stripColor(is.getItemMeta().getDisplayName()); diff --git a/src/main/java/com/songoda/skyblock/menus/Members.java b/src/main/java/com/songoda/skyblock/menus/Members.java index 4982a45d..db6de9e4 100644 --- a/src/main/java/com/songoda/skyblock/menus/Members.java +++ b/src/main/java/com/songoda/skyblock/menus/Members.java @@ -7,6 +7,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -48,6 +49,7 @@ public class Members { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -179,7 +181,7 @@ public class Members { return; } } else if (island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Kick").getStatus()) { + && permissionManager.hasPermission(island, "Kick", IslandRole.Operator)) { Bukkit.getServer().dispatchCommand(player, "island kick " + playerName); Bukkit.getServer().getScheduler().runTaskLater(skyblock, @@ -312,7 +314,7 @@ public class Members { if (island.hasRole(IslandRole.Owner, player.getUniqueId())) { operatorActions = new boolean[]{true, true}; } else if (island.hasRole(IslandRole.Operator, player.getUniqueId())) { - if (island.getSetting(IslandRole.Operator, "Kick").getStatus()) { + if (permissionManager.hasPermission(island, "Kick", IslandRole.Operator)) { operatorActions = new boolean[]{false, true}; } } diff --git a/src/main/java/com/songoda/skyblock/menus/Settings.java b/src/main/java/com/songoda/skyblock/menus/Settings.java index a1028a3b..79772e7a 100644 --- a/src/main/java/com/songoda/skyblock/menus/Settings.java +++ b/src/main/java/com/songoda/skyblock/menus/Settings.java @@ -7,6 +7,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -46,6 +47,7 @@ public class Settings { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -65,6 +67,7 @@ public class Settings { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); + soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); return; } else if (!(island13.hasRole(IslandRole.Operator, player.getUniqueId()) @@ -96,7 +99,7 @@ public class Settings { } if (island13.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island13.getSetting(IslandRole.Operator, "Coop").getStatus()) { + && !permissionManager.hasPermission(island13, "Coop", IslandRole.Operator)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Access.Message")); soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); @@ -114,7 +117,7 @@ public class Settings { .equals(ChatColor.translateAlternateColorCodes('&', configLoad .getString("Menu.Settings.Categories.Item.Visitor.Displayname"))))) { if (island13.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island13.getSetting(IslandRole.Operator, "Visitor").getStatus()) { + && !permissionManager.hasPermission(island13, "Visitor", IslandRole.Operator)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Access.Message")); soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); @@ -133,7 +136,7 @@ public class Settings { .equals(ChatColor.translateAlternateColorCodes('&', configLoad .getString("Menu.Settings.Categories.Item.Member.Displayname"))))) { if (island13.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island13.getSetting(IslandRole.Operator, "Member").getStatus()) { + && !permissionManager.hasPermission(island13, "Member", IslandRole.Operator)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Access.Message")); soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); @@ -169,7 +172,7 @@ public class Settings { .equals(ChatColor.translateAlternateColorCodes('&', configLoad .getString("Menu.Settings.Categories.Item.Owner.Displayname"))))) { if (island13.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island13.getSetting(IslandRole.Operator, "Island").getStatus()) { + && !permissionManager.hasPermission(island13,"Island", IslandRole.Operator)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Access.Message")); soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); @@ -241,7 +244,7 @@ public class Settings { return; } else if (island14.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island14.getSetting(IslandRole.Operator, role.name()).getStatus()) { + && !permissionManager.hasPermission(island14, role.name(), IslandRole.Operator)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Settings.Permission.Access.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); @@ -295,11 +298,11 @@ public class Settings { } else if (is.hasItemMeta()) { String roleName = getRoleName(role); - for (IslandSetting settingList : island14.getSettings(role)) { + for (IslandPermission settingList : island14.getSettings(role)) { if (is.getItemMeta().getDisplayName() .equals(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Settings." + roleName + ".Item.Setting." - + settingList.getName() + ".Displayname")))) { + + settingList.getPermission().getName() + ".Displayname")))) { if (!hasPermission(island14, player, role)) { messageManager.sendMessage(player, configLoad .getString("Command.Island.Settings.Permission.Change.Message")); @@ -308,19 +311,17 @@ public class Settings { return; } - if (settingList != null) { - if (settingList.getStatus()) { - settingList.setStatus(false); - } else { - settingList.setStatus(true); - } + if (settingList.getStatus()) { + settingList.setStatus(false); + } else { + settingList.setStatus(true); + } - if (settingList.getName().equals("KeepItemsOnDeath") - || settingList.getName().equals("PvP") - || settingList.getName().equals("Damage")) { - island14.getVisit() - .setSafeLevel(islandManager.getIslandSafeLevel(island14)); - } + if (settingList.getPermission().getName().equals("KeepItemsOnDeath") + || settingList.getPermission().getName().equals("PvP") + || settingList.getPermission().getName().equals("Damage")) { + island14.getVisit() + .setSafeLevel(islandManager.getIslandSafeLevel(island14)); } break; @@ -1515,6 +1516,7 @@ public class Settings { private ItemStack createItem(Island island, IslandRole role, String setting, ItemStack is) { SkyBlock skyblock = SkyBlock.getInstance(); + PermissionManager permissionManager = skyblock.getPermissionManager(); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -1532,7 +1534,7 @@ public class Settings { im.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Settings." + roleName + ".Item.Setting." + setting + ".Displayname"))); - if (island.getSetting(role, setting).getStatus()) { + if (island.hasPermission(role, permissionManager.getPermission(setting))) { for (String itemLoreList : configLoad .getStringList("Menu.Settings." + roleName + ".Item.Setting.Status.Enabled.Lore")) { itemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList)); @@ -1560,6 +1562,7 @@ public class Settings { } private boolean hasPermission(Island island, Player player, IslandRole role) { + PermissionManager permissionManager = SkyBlock.getInstance().getPermissionManager(); if (role == IslandRole.Visitor || role == IslandRole.Member || role == IslandRole.Coop || role == IslandRole.Owner) { String roleName = role.name(); @@ -1569,7 +1572,7 @@ public class Settings { } return !island.hasRole(IslandRole.Operator, player.getUniqueId()) - || island.getSetting(IslandRole.Operator, roleName).getStatus(); + || permissionManager.hasPermission(island, roleName, IslandRole.Operator); } else if (role == IslandRole.Operator) { return island.hasRole(IslandRole.Owner, player.getUniqueId()); } diff --git a/src/main/java/com/songoda/skyblock/menus/Visitors.java b/src/main/java/com/songoda/skyblock/menus/Visitors.java index a7ff825d..e7187130 100644 --- a/src/main/java/com/songoda/skyblock/menus/Visitors.java +++ b/src/main/java/com/songoda/skyblock/menus/Visitors.java @@ -7,6 +7,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -43,6 +44,7 @@ public class Visitors { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -106,8 +108,8 @@ public class Visitors { } else { boolean isOperator = island.hasRole(IslandRole.Operator, player.getUniqueId()), isOwner = island.hasRole(IslandRole.Owner, player.getUniqueId()), - canKick = island.getSetting(IslandRole.Operator, "Kick").getStatus(), - canBan = island.getSetting(IslandRole.Operator, "Ban").getStatus(), + canKick = permissionManager.hasPermission(island, "Kick", IslandRole.Operator), + canBan = permissionManager.hasPermission(island, "Ban", IslandRole.Operator), banningEnabled = fileManager .getConfig(new File(skyblock.getDataFolder(), "config.yml")) .getFileConfiguration().getBoolean("Island.Visitor.Banning"); @@ -206,8 +208,8 @@ public class Visitors { } else { boolean isOperator = island.hasRole(IslandRole.Operator, player.getUniqueId()), isOwner = island.hasRole(IslandRole.Owner, player.getUniqueId()), - canKick = island.getSetting(IslandRole.Operator, "Kick").getStatus(), - canBan = island.getSetting(IslandRole.Operator, "Ban").getStatus(), + canKick = skyblock.getPermissionManager().hasPermission(island, "Kick", IslandRole.Operator), + canBan = skyblock.getPermissionManager().hasPermission(island, "Ban", IslandRole.Operator), banningEnabled = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) .getFileConfiguration().getBoolean("Island.Visitor.Banning"); int index = playerMenuPage * 36 - 36, diff --git a/src/main/java/com/songoda/skyblock/menus/Weather.java b/src/main/java/com/songoda/skyblock/menus/Weather.java index 296f3726..47b560b8 100644 --- a/src/main/java/com/songoda/skyblock/menus/Weather.java +++ b/src/main/java/com/songoda/skyblock/menus/Weather.java @@ -9,6 +9,7 @@ import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -43,6 +44,7 @@ public class Weather { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); + PermissionManager permissionManager = skyblock.getPermissionManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); @@ -62,7 +64,7 @@ public class Weather { return; } else if (!((island.hasRole(IslandRole.Operator, player.getUniqueId()) - && island.getSetting(IslandRole.Operator, "Biome").getStatus()) + && permissionManager.hasPermission(island, "Biome", IslandRole.Operator)) || island.hasRole(IslandRole.Owner, player.getUniqueId()))) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Weather.Permission.Message")); diff --git a/src/main/java/com/songoda/skyblock/permission/BasicPermission.java b/src/main/java/com/songoda/skyblock/permission/BasicPermission.java new file mode 100644 index 00000000..2644a769 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/BasicPermission.java @@ -0,0 +1,83 @@ +package com.songoda.skyblock.permission; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.utils.TextUtils; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandRole; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public abstract class BasicPermission { + + private final String name; + private final CompatibleMaterial icon; + private final PermissionType type; + + protected BasicPermission(String name, CompatibleMaterial icon, PermissionType type) { + this.name = name; + this.icon = icon; + this.type = type; + } + + public ItemStack getItem(Island island, IslandRole role) { + ItemStack is = icon.getItem(); + FileManager.Config config = SkyBlock.getInstance().getFileManager() + .getConfig(new File(SkyBlock.getInstance().getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + List itemLore = new ArrayList<>(); + + ItemMeta im = is.getItemMeta(); + + String roleName = role.name(); + + if (role == IslandRole.Visitor + || role == IslandRole.Member + || role == IslandRole.Coop) + roleName = "Default"; + + String nameFinal = configLoad.getString("Menu.Settings." + roleName + ".Item.Setting." + name + ".Displayname"); + + im.setDisplayName(TextUtils.formatText(nameFinal == null ? name : nameFinal)); + + for (String itemLoreList : configLoad + .getStringList("Menu.Settings." + roleName + ".Item.Setting.Status." + + (island.hasPermission(role, this) ? "Enabled" : "Disabled") + ".Lore")) + itemLore.add(TextUtils.formatText(itemLoreList)); + + im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + im.setLore(itemLore); + is.setItemMeta(im); + + return is; + } + + /** + * Use this to check additional perms. + * + * @return + */ + public boolean extraCheck() { + return true; + } + + public String getName() { + return name; + } + + public CompatibleMaterial getIcon() { + return icon; + } + + public PermissionType getType() { + return type; + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/HandlerWrapper.java b/src/main/java/com/songoda/skyblock/permission/HandlerWrapper.java new file mode 100644 index 00000000..f724718b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/HandlerWrapper.java @@ -0,0 +1,22 @@ +package com.songoda.skyblock.permission; + +import java.lang.reflect.Method; + +public class HandlerWrapper { + + private final BasicPermission permission; + private final Method handler; + + public HandlerWrapper(BasicPermission permission, Method handler) { + this.permission = permission; + this.handler = handler; + } + + public BasicPermission getPermission() { + return permission; + } + + public Method getHandler() { + return handler; + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java b/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java new file mode 100644 index 00000000..361633d2 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java @@ -0,0 +1,93 @@ +package com.songoda.skyblock.permission; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; +import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.player.*; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; + +import java.io.File; + +public abstract class ListeningPermission extends BasicPermission { + + protected ListeningPermission(String name, CompatibleMaterial icon, PermissionType type) { + super(name, icon, type); + } + + public void onInteract(PlayerInteractEvent event) {} + + public void onInteractEntity(PlayerInteractEntityEvent event) {} + + public void onShear(PlayerShearEntityEvent event) {} + + public void onBreak(BlockBreakEvent event) {} + + public void onPlace(BlockPlaceEvent event) {} + + public void onVehicleDamage(VehicleDamageEvent event) {} + + public void onVehicleDestroy(VehicleDestroyEvent event) {} + + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {} + + public void onEntityDamage(EntityDamageEvent event) {} + + public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) {} + + public void onHangingPlace(HangingPlaceEvent event) {} + + public void onHangingBreak(HangingBreakEvent event) {} + + public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {} + + public void onEntityTame(EntityTameEvent event) {} + + public void onTargetEntity(EntityTargetLivingEntityEvent event) {} + + public void onBucketEmpty(PlayerBucketEmptyEvent event) {} + + public void onBucketFill(PlayerBucketFillEvent event) {} + + public void onInventoryOpen(InventoryOpenEvent event) {} + + public void onFoodLevelChange(FoodLevelChangeEvent event) {} + + public void onPortalEnter(PlayerEnterPortalEvent event) {} + + public void onPickupItem(PlayerPickupItemEvent event) {} + + public void onDropItem(PlayerDropItemEvent event) {} + + public void onMove(PlayerMoveEvent event) {} + + public void onTeleport(PlayerTeleportEvent event) {} + + public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) {} + + protected void noPermsMessage(Player player, SkyBlock plugin, MessageManager messageManager) { + messageManager.sendMessage(player, + plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.Settings.Permission.Message")); + CompatibleSound.ENTITY_VILLAGER_NO.play(player); + } + + protected void cancelAndMessage(Cancellable cancellable, Player player, + SkyBlock plugin, MessageManager messageManager) { + cancellable.setCancelled(true); + noPermsMessage(player, plugin, messageManager); + + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/PermissionHandler.java b/src/main/java/com/songoda/skyblock/permission/PermissionHandler.java new file mode 100644 index 00000000..7f9df51b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/PermissionHandler.java @@ -0,0 +1,14 @@ +package com.songoda.skyblock.permission; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface PermissionHandler { + + PermissionPriority priority() default PermissionPriority.NORMAL; + +} diff --git a/src/main/java/com/songoda/skyblock/permission/PermissionManager.java b/src/main/java/com/songoda/skyblock/permission/PermissionManager.java new file mode 100644 index 00000000..736d04a9 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/PermissionManager.java @@ -0,0 +1,216 @@ +package com.songoda.skyblock.permission; + +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.permission.event.Stoppable; +import com.songoda.skyblock.permission.permissions.basic.*; +import com.songoda.skyblock.permission.permissions.listening.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.util.stream.Collectors; + +public class PermissionManager { + + private final SkyBlock plugin; + + private final List registeredPermissions = new ArrayList<>(); + private List registeredHandlers = new LinkedList<>(); + + public PermissionManager(SkyBlock plugin) { + this.plugin = plugin; + + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { + // Load default permissions. + registerPermissions( + //Listening + new StoragePermission(plugin), + new DragonEggUsePermission(plugin), + new BeaconPermission(plugin), + new ProjectilePermission(plugin), + new DestroyPermission(plugin), + new AnvilPermission(plugin), + new BedPermission(plugin), + new BrewingPermission(plugin), + new WorkbenchPermission(plugin), + new DoorPermission(plugin), + new EnchantPermission(plugin), + new FurnacePermission(plugin), + new LeverButtonPermission(plugin), + new JukeboxPermission(plugin), + new HopperPermission(plugin), + new NoteblockPermission(plugin), + new RedstonePermission(plugin), + new GatePermission(plugin), + new DropperDispenserPermission(plugin), + new BucketPermission(plugin), + new WaterCollectionPermission(plugin), + new SpawnEggPermission(plugin), + new EntityPlacementPermission(plugin), + new FirePermission(plugin), + new TramplePermission(plugin), + new PressurePlatePermission(plugin), + new CakePermission(plugin), + new PlacePermission(plugin), + new LeashPermission(plugin), + new AnimalBreedingPermission(plugin), + new MinecartPermission(plugin), + new BoatPermission(plugin), + new TradingPermission(plugin), + new MilkingPermission(plugin), + new ShearingPermission(plugin), + new MobRidingPermission(plugin), + new HorseInventoryPermission(plugin), + new MobHurtingPermission(plugin), + new ArmorStandUsePermission(plugin), + new MonsterHurtingPermission(plugin), + new PvpPermission(plugin), + new HangingDestroyPermission(plugin), + new DamagePermission(plugin), + new ExplosionsPermission(), + new MobTamingPermission(plugin), + new MobGriefingPermission(plugin), + new ExperienceOrbPickupPermission(plugin), + new NaturalMobSpawningPermission(), + new HungerPermission(plugin), + new PortalPermission(plugin), + new ItemPickupPermission(), + new ItemDropPermission(), + new FishingPermission(plugin), + + // Basic + new MemberPermission(), + new VisitorPermission(), + new KickPermission(), + new BiomePermission(), + new KeepItemsOnDeathPermission(), + new UnbanPermission(), + new BanPermission(), + new BorderPermission(), + new FireSpreadPermission(), + new CoopPlayersPermission(), + new IslandPermission(), + new LeafDecayPermission(), + new WeatherPermission(), + new MainSpawnPermission(), + new VisitorSpawnPermission()); + + registeredHandlers = registeredHandlers.stream().sorted(Comparator.comparingInt(h -> { + final PermissionHandler permissionHandler = h.getHandler().getAnnotation(PermissionHandler.class); + return permissionHandler.priority().ordinal(); + })).collect(Collectors.toList()); + }, 20L); + } + + public boolean registerPermission(BasicPermission permission) { + registeredPermissions.add(permission); + Set methods; + try { + Method[] publicMethods = permission.getClass().getMethods(); + methods = new HashSet<>(publicMethods.length, Float.MAX_VALUE); + methods.addAll(Arrays.asList(publicMethods)); + Collections.addAll(methods, permission.getClass().getDeclaredMethods()); + } catch (NoClassDefFoundError e) { + return false; + } + for (Method method : methods) { + final PermissionHandler permissionHandler = method.getAnnotation(PermissionHandler.class); + if (permissionHandler == null) continue; + registeredHandlers.add(new HandlerWrapper(permission, method)); + } + return true; + } + + public boolean registerPermissions(BasicPermission... permissions) { + for (BasicPermission permission : permissions) + if (!registerPermission(permission)) + return false; + return true; + } + + public boolean processPermission(Cancellable cancellable, Island island) { + return processPermission(cancellable, null, island); + } + + public boolean processPermission(Cancellable cancellable, Player player, Location location) { + return processPermission(cancellable, player, plugin.getIslandManager().getIslandAtLocation(location)); + } + + public boolean processPermission(Cancellable cancellable, Player player, Island island) { + if (island == null) return true; + + for (HandlerWrapper wrapper : registeredHandlers) { + Method handler = wrapper.getHandler(); + if (handler.getParameterTypes()[0] != cancellable.getClass()) continue; + + if (cancellable.isCancelled()) return false; + if (cancellable instanceof Stoppable && ((Stoppable) cancellable).isStopped()) return true; + + BasicPermission permission = wrapper.getPermission(); + + if (permission.extraCheck() && hasPermission(player, island, permission)) + continue; + + try { + handler.invoke(permission, cancellable); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + return true; + } + + public boolean hasPermission(Player player, Island island, BasicPermission permission) { + if (player == null) + return island.hasPermission(IslandRole.Owner, permission); + + if (player.hasPermission("fabledskyblock.bypass." + permission.getName().toLowerCase())) + return true; + + if (island.hasPermission(island.getRole(player), permission)) + return true; + + if (island.isCoopPlayer(player.getUniqueId()) && island.hasPermission(IslandRole.Coop, permission)) + return true; + + return island.hasPermission(IslandRole.Visitor, permission); + } + + public boolean hasPermission(Location location, String permission, IslandRole islandRole) { + if (location == null) + return false; + return plugin.getIslandManager().getIslandAtLocation(location) + .hasPermission(islandRole, getPermission(permission)); + } + + public boolean hasPermission(Island island, String permission, IslandRole islandRole) { + return island.hasPermission(islandRole, getPermission(permission)); + } + + public boolean hasPermission(Player player, Island island, String permission) { + return hasPermission(player, island, getPermission(permission)); + } + + public BasicPermission getPermission(String permissionName) { + return registeredPermissions.stream() + .filter(p -> p.getName().equalsIgnoreCase(permissionName)) + .findFirst().orElse(null); + } + + public List getPermissions() { + return new ArrayList<>(registeredPermissions); + } + + public List getListeningPermissions() { + return registeredPermissions.stream() + .filter(p -> p instanceof ListeningPermission) + .map(p -> (ListeningPermission) p) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/PermissionPriority.java b/src/main/java/com/songoda/skyblock/permission/PermissionPriority.java new file mode 100644 index 00000000..de3b0dcb --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/PermissionPriority.java @@ -0,0 +1,7 @@ +package com.songoda.skyblock.permission; + +public enum PermissionPriority { + + FIRST, NORMAL, LAST + +} diff --git a/src/main/java/com/songoda/skyblock/permission/PermissionType.java b/src/main/java/com/songoda/skyblock/permission/PermissionType.java new file mode 100644 index 00000000..b82bf6df --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/PermissionType.java @@ -0,0 +1,7 @@ +package com.songoda.skyblock.permission; + +public enum PermissionType { + + GENERIC, OPERATOR, ISLAND + +} diff --git a/src/main/java/com/songoda/skyblock/permission/event/Stoppable.java b/src/main/java/com/songoda/skyblock/permission/event/Stoppable.java new file mode 100644 index 00000000..fa123463 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/event/Stoppable.java @@ -0,0 +1,8 @@ +package com.songoda.skyblock.permission.event; + +public interface Stoppable { + + boolean isStopped(); + + void setStopped(boolean stopped); +} \ No newline at end of file diff --git a/src/main/java/com/songoda/skyblock/permission/event/events/PlayerEnterPortalEvent.java b/src/main/java/com/songoda/skyblock/permission/event/events/PlayerEnterPortalEvent.java new file mode 100644 index 00000000..657b02c4 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/event/events/PlayerEnterPortalEvent.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.event.events; + +import com.songoda.skyblock.permission.event.Stoppable; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.entity.EntityPortalEnterEvent; + +public class PlayerEnterPortalEvent extends EntityPortalEnterEvent implements Cancellable, Stoppable { + + private boolean isCancelled = false; + private boolean isStopped = false; + + public PlayerEnterPortalEvent(Player player, Location location) { + super(player, location); + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } + + @Override + public boolean isStopped() { + return isStopped; + } + + @Override + public void setStopped(boolean stopped) { + isStopped = stopped; + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java b/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java new file mode 100644 index 00000000..fda7715c --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.event.events; + +import com.songoda.skyblock.permission.event.Stoppable; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.entity.ProjectileLaunchEvent; + +public class ProjectileLaunchByPlayerEvent extends ProjectileLaunchEvent implements Cancellable, Stoppable { + + private boolean isCancelled = false; + private boolean isStopped = false; + + public ProjectileLaunchByPlayerEvent(Entity what) { + super(what); + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } + + @Override + public boolean isStopped() { + return isStopped; + } + + @Override + public void setStopped(boolean stopped) { + isStopped = stopped; + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/BanPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BanPermission.java new file mode 100644 index 00000000..67bc555b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BanPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class BanPermission extends BasicPermission { + + public BanPermission() { + super("Ban", CompatibleMaterial.IRON_AXE, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/BiomePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BiomePermission.java new file mode 100644 index 00000000..4f6ef59d --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BiomePermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class BiomePermission extends BasicPermission { + + public BiomePermission() { + super("Biome", CompatibleMaterial.MAP, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/BorderPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BorderPermission.java new file mode 100644 index 00000000..4c0a80a1 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/BorderPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class BorderPermission extends BasicPermission { + + public BorderPermission() { + super("Border", CompatibleMaterial.BEACON, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/CoopPlayersPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/CoopPlayersPermission.java new file mode 100644 index 00000000..536e7399 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/CoopPlayersPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class CoopPlayersPermission extends BasicPermission { + + public CoopPlayersPermission() { + super("CoopPlayers", CompatibleMaterial.BOOK, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/FireSpreadPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/FireSpreadPermission.java new file mode 100644 index 00000000..8a6de856 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/FireSpreadPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class FireSpreadPermission extends BasicPermission { + + public FireSpreadPermission() { + super("FireSpread", CompatibleMaterial.FLINT_AND_STEEL, PermissionType.ISLAND); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/IslandPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/IslandPermission.java new file mode 100644 index 00000000..0a916216 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/IslandPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class IslandPermission extends BasicPermission { + + public IslandPermission() { + super("Island", CompatibleMaterial.OAK_SAPLING, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/KeepItemsOnDeathPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/KeepItemsOnDeathPermission.java new file mode 100644 index 00000000..5cb8e3d7 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/KeepItemsOnDeathPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class KeepItemsOnDeathPermission extends BasicPermission { + + public KeepItemsOnDeathPermission() { + super("KeepItemsOnDeath", CompatibleMaterial.ITEM_FRAME, PermissionType.ISLAND); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/KickPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/KickPermission.java new file mode 100644 index 00000000..b9ff1544 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/KickPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class KickPermission extends BasicPermission { + + public KickPermission() { + super("Visitor", CompatibleMaterial.IRON_DOOR, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/LeafDecayPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/LeafDecayPermission.java new file mode 100644 index 00000000..2b0075cc --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/LeafDecayPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class LeafDecayPermission extends BasicPermission { + + public LeafDecayPermission() { + super("LeafDecay", CompatibleMaterial.OAK_LEAVES, PermissionType.ISLAND); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/MainSpawnPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/MainSpawnPermission.java new file mode 100644 index 00000000..3ec00821 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/MainSpawnPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class MainSpawnPermission extends BasicPermission { + + public MainSpawnPermission() { + super("MainSpawn", CompatibleMaterial.EMERALD, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/MemberPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/MemberPermission.java new file mode 100644 index 00000000..a88800c4 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/MemberPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class MemberPermission extends BasicPermission { + + public MemberPermission() { + super("Member", CompatibleMaterial.PAINTING, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/NaturalMobSpawningPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/NaturalMobSpawningPermission.java new file mode 100644 index 00000000..faca2f8b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/NaturalMobSpawningPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class NaturalMobSpawningPermission extends BasicPermission { + + public NaturalMobSpawningPermission() { + super("NaturalMobSpawning", CompatibleMaterial.PIG_SPAWN_EGG, PermissionType.ISLAND); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/UnbanPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/UnbanPermission.java new file mode 100644 index 00000000..f9fce026 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/UnbanPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class UnbanPermission extends BasicPermission { + + public UnbanPermission() { + super("Unban", CompatibleMaterial.RED_DYE, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorPermission.java new file mode 100644 index 00000000..f79c768f --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class VisitorPermission extends BasicPermission { + + public VisitorPermission() { + super("Visitor", CompatibleMaterial.OAK_SIGN, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorSpawnPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorSpawnPermission.java new file mode 100644 index 00000000..d52cf97b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/VisitorSpawnPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class VisitorSpawnPermission extends BasicPermission { + + public VisitorSpawnPermission() { + super("VisitorSpawn", CompatibleMaterial.NETHER_STAR, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/basic/WeatherPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/basic/WeatherPermission.java new file mode 100644 index 00000000..9aadb322 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/basic/WeatherPermission.java @@ -0,0 +1,13 @@ +package com.songoda.skyblock.permission.permissions.basic; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.BasicPermission; +import com.songoda.skyblock.permission.PermissionType; + +public class WeatherPermission extends BasicPermission { + + public WeatherPermission() { + super("Weather", CompatibleMaterial.CLOCK, PermissionType.OPERATOR); + } + +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnimalBreedingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnimalBreedingPermission.java new file mode 100644 index 00000000..ca613e64 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnimalBreedingPermission.java @@ -0,0 +1,115 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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.utils.version.NMSUtil; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; + +public class AnimalBreedingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public AnimalBreedingPermission(SkyBlock plugin) { + super("AnimalBreeding", CompatibleMaterial.WHEAT, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + ItemStack is = player.getItemInHand(); + Entity entity = event.getRightClicked(); + + if (entity.getType() == EntityType.HORSE) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_APPLE + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_CARROT + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SUGAR + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.APPLE + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.HAY_BLOCK)) { + return; + } + } else if (entity.getType() == EntityType.SHEEP || entity.getType() == EntityType.COW || entity.getType() == EntityType.MUSHROOM_COW) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT)) { + return; + } + } else if (entity.getType() == EntityType.PIG) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CARROT || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.POTATO)) { + return; + } + } else if (entity.getType() == EntityType.CHICKEN) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.WHEAT_SEEDS + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PUMPKIN_SEEDS || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.MELON_SEEDS)) { + if (NMSUtil.getVersionNumber() > 8) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BEETROOT_SEEDS)) { + return; + } + } else { + return; + } + } + } else if (entity.getType() == EntityType.WOLF) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BONE + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PORKCHOP + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.BEEF + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CHICKEN + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.RABBIT + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.MUTTON + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.ROTTEN_FLESH + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_PORKCHOP + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_BEEF + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_CHICKEN + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_RABBIT + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COOKED_MUTTON)) { + return; + } + } else if (entity.getType() == EntityType.OCELOT) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.COD + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SALMON + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.TROPICAL_FISH + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.PUFFERFISH)) { + return; + } + } else if (entity.getType() == EntityType.RABBIT) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.DANDELION + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.CARROTS + || CompatibleMaterial.getMaterial(is) == CompatibleMaterial.GOLDEN_CARROT)) { + return; + } + } else { + int NMSVersion = NMSUtil.getVersionNumber(); + + if (NMSVersion > 10) { + if (entity.getType() == EntityType.LLAMA) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.HAY_BLOCK)) { + return; + } + } else if (NMSVersion > 12) { + if (entity.getType() == EntityType.TURTLE) { + if (!(CompatibleMaterial.getMaterial(is) == CompatibleMaterial.SEAGRASS)) { + return; + } + } else { + return; + } + } else { + return; + } + } else { + return; + } + } + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnvilPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnvilPermission.java new file mode 100644 index 00000000..5a3dc544 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/AnvilPermission.java @@ -0,0 +1,36 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class AnvilPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public AnvilPermission(SkyBlock plugin) { + super("Anvil", CompatibleMaterial.ANVIL, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.ANVIL) + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ArmorStandUsePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ArmorStandUsePermission.java new file mode 100644 index 00000000..ac79a6b3 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ArmorStandUsePermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class ArmorStandUsePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public ArmorStandUsePermission(SkyBlock plugin) { + super("ArmorStandUse", CompatibleMaterial.ARMOR_STAND, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + + if (event.getRightClicked() instanceof ArmorStand) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) { + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/BeaconPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BeaconPermission.java new file mode 100644 index 00000000..7553cf8c --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BeaconPermission.java @@ -0,0 +1,39 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Beacon; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class BeaconPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public BeaconPermission(SkyBlock plugin) { + super("Beacon", CompatibleMaterial.BEACON, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (block.getState() instanceof Beacon) // ChunkCollectors support + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/BedPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BedPermission.java new file mode 100644 index 00000000..f5987184 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BedPermission.java @@ -0,0 +1,44 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class BedPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public BedPermission(SkyBlock plugin) { + super("Bed", CompatibleMaterial.RED_BED, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.WHITE_BED || material == CompatibleMaterial.ORANGE_BED + || material == CompatibleMaterial.MAGENTA_BED || material == CompatibleMaterial.LIGHT_BLUE_BED + || material == CompatibleMaterial.YELLOW_BED || material == CompatibleMaterial.LIME_BED + || material == CompatibleMaterial.PINK_BED || material == CompatibleMaterial.GRAY_BED + || material == CompatibleMaterial.LIGHT_GRAY_BED || material == CompatibleMaterial.CYAN_BED + || material == CompatibleMaterial.PURPLE_BED || material == CompatibleMaterial.BLUE_BED + || material == CompatibleMaterial.BROWN_BED || material == CompatibleMaterial.GREEN_BED + || material == CompatibleMaterial.RED_BED || material == CompatibleMaterial.BLACK_BED) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/BoatPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BoatPermission.java new file mode 100644 index 00000000..c0b3cb21 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BoatPermission.java @@ -0,0 +1,34 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class BoatPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public BoatPermission(SkyBlock plugin) { + super("Boat", CompatibleMaterial.OAK_BOAT, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + + if (event.getRightClicked().getType() == EntityType.BOAT) + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/BrewingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BrewingPermission.java new file mode 100644 index 00000000..936957e9 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BrewingPermission.java @@ -0,0 +1,51 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class BrewingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public BrewingPermission(SkyBlock plugin) { + super("Brewing", CompatibleMaterial.BREWING_STAND, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.BREWING_STAND) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Player player = (Player)event.getDamager(); + Entity entity = event.getEntity(); + + if (!(entity instanceof Monster)) return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/BucketPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BucketPermission.java new file mode 100644 index 00000000..aff2c6d6 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/BucketPermission.java @@ -0,0 +1,56 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class BucketPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public BucketPermission(SkyBlock plugin) { + super("Bucket", CompatibleMaterial.BUCKET, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (player.getGameMode() == GameMode.SURVIVAL + && CompatibleMaterial.getMaterial(event.getClickedBlock()) == CompatibleMaterial.OBSIDIAN + && event.getItem() != null + && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR + && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BUCKET) + cancelAndMessage(event, player, plugin, messageManager); + } else if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR) { + if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BUCKET + || CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.WATER_BUCKET + || CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.LAVA_BUCKET) { + cancelAndMessage(event, player, plugin, messageManager); + player.updateInventory(); + } + } + } + + @PermissionHandler + public void onBucketFill(PlayerBucketFillEvent event) { + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } + + @PermissionHandler + public void onBucketEmpty(PlayerBucketEmptyEvent event) { + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/CakePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/CakePermission.java new file mode 100644 index 00000000..dfdeb421 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/CakePermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class CakePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public CakePermission(SkyBlock plugin) { + super("Cake", CompatibleMaterial.CAKE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.CAKE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/DamagePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DamagePermission.java new file mode 100644 index 00000000..9673cd72 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DamagePermission.java @@ -0,0 +1,76 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +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.configuration.file.FileConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; + +import java.io.File; + +public class DamagePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final FileManager fileManager; + + public DamagePermission(SkyBlock plugin) { + super("Damage", CompatibleMaterial.RED_DYE, PermissionType.GENERIC); + this.plugin = plugin; + this.fileManager = plugin.getFileManager(); + } + + @PermissionHandler + public void onEntityDamage(EntityDamageEvent event) { + if (event.getCause() == EntityDamageEvent.DamageCause.VOID) { + return; + } else if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { + EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event; + + if (entityDamageByEntityEvent.getDamager() instanceof Player) { + return; + } + } else { + if (NMSUtil.getVersionNumber() > 11) { + if (event.getCause() == EntityDamageEvent.DamageCause.valueOf("ENTITY_SWEEP_ATTACK")) { + EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event; + + if (entityDamageByEntityEvent.getDamager() instanceof Player) { + return; + } + } + } + } + + 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")) + event.setCancelled(true); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + + if (entity.getType() != EntityType.PLAYER) return; + + 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")) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/DestroyPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DestroyPermission.java new file mode 100644 index 00000000..0afe4742 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DestroyPermission.java @@ -0,0 +1,57 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class DestroyPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public DestroyPermission(SkyBlock plugin) { + super("Destroy", CompatibleMaterial.DIAMOND_PICKAXE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.SWEET_BERRY_BUSH || material == CompatibleMaterial.TNT + || material == CompatibleMaterial.END_PORTAL_FRAME) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Player player = (Player)event.getDamager(); + Entity entity = event.getEntity(); + + if (entity.getType() != EntityType.ARMOR_STAND) return; + + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onBlockBreak(BlockBreakEvent event) { + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/DoorPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DoorPermission.java new file mode 100644 index 00000000..53543b04 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DoorPermission.java @@ -0,0 +1,40 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class DoorPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public DoorPermission(SkyBlock plugin) { + super("Door", CompatibleMaterial.OAK_DOOR, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.BIRCH_DOOR || material == CompatibleMaterial.ACACIA_DOOR + || material == CompatibleMaterial.DARK_OAK_DOOR || material == CompatibleMaterial.JUNGLE_DOOR + || material == CompatibleMaterial.SPRUCE_DOOR || material == CompatibleMaterial.OAK_DOOR) + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/DragonEggUsePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DragonEggUsePermission.java new file mode 100644 index 00000000..6a0d8f7a --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DragonEggUsePermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class DragonEggUsePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public DragonEggUsePermission(SkyBlock plugin) { + super("DragonEggUse", CompatibleMaterial.DRAGON_EGG, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block.getType()) == CompatibleMaterial.DRAGON_EGG) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/DropperDispenserPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DropperDispenserPermission.java new file mode 100644 index 00000000..b282d768 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/DropperDispenserPermission.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class DropperDispenserPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public DropperDispenserPermission(SkyBlock plugin) { + super("DropperDispenser", CompatibleMaterial.DROPPER, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (material == CompatibleMaterial.DROPPER || material == CompatibleMaterial.DISPENSER) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/EnchantPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/EnchantPermission.java new file mode 100644 index 00000000..1f3a3328 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/EnchantPermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class EnchantPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public EnchantPermission(SkyBlock plugin) { + super("Enchant", CompatibleMaterial.ENCHANTING_TABLE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.ENCHANTING_TABLE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/EntityPlacementPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/EntityPlacementPermission.java new file mode 100644 index 00000000..fd82e8e9 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/EntityPlacementPermission.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEvent; + +public class EntityPlacementPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public EntityPlacementPermission(SkyBlock plugin) { + super("EntityPlacement", CompatibleMaterial.SHEEP_SPAWN_EGG, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + Player player = event.getPlayer(); + if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR) { + if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.ARMOR_STAND + || event.getItem().getType().name().contains("BOAT") + || event.getItem().getType().name().contains("MINECART")) { + cancelAndMessage(event, player, plugin, messageManager); + player.updateInventory(); + } + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExperienceOrbPickupPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExperienceOrbPickupPermission.java new file mode 100644 index 00000000..9f2df3e6 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExperienceOrbPickupPermission.java @@ -0,0 +1,34 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.ExperienceOrb; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; + +public class ExperienceOrbPickupPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public ExperienceOrbPickupPermission(SkyBlock plugin) { + super("ExperienceOrbPickup", CompatibleMaterial.EXPERIENCE_BOTTLE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onTargetEntity(EntityTargetLivingEntityEvent event) { + Player player = (Player) event.getTarget(); + + if (!(event.getEntity() instanceof ExperienceOrb)) + return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExplosionsPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExplosionsPermission.java new file mode 100644 index 00000000..5753bdfa --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ExplosionsPermission.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; + +public class ExplosionsPermission extends ListeningPermission { + + public ExplosionsPermission() { + super("Explosions", CompatibleMaterial.GUNPOWDER, PermissionType.GENERIC); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + + if (event.getDamager() instanceof TNTPrimed) + event.setCancelled(true); + if (entity.getType() == EntityType.PLAYER + && event.getDamager() instanceof TNTPrimed) + event.setCancelled(true); + } + + @PermissionHandler + public void onHangingBreak(HangingBreakEvent event) { + if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) + return; + + event.setCancelled(true); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/FirePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FirePermission.java new file mode 100644 index 00000000..b4151498 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FirePermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class FirePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public FirePermission(SkyBlock plugin) { + super("Fire", CompatibleMaterial.FLINT_AND_STEEL, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(player.getTargetBlock(null, 5)) == CompatibleMaterial.FIRE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java new file mode 100644 index 00000000..a3f8b54b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java @@ -0,0 +1,35 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionPriority; +import com.songoda.skyblock.permission.PermissionType; +import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.ProjectileLaunchEvent; + +public class FishingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public FishingPermission(SkyBlock plugin) { + super("Fishing", CompatibleMaterial.FISHING_ROD, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler(priority = PermissionPriority.LAST) + public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) { + org.bukkit.entity.Projectile projectile = event.getEntity(); + Player shooter = (Player) projectile.getShooter(); + if (projectile instanceof FishHook) { + cancelAndMessage(event, shooter, plugin, messageManager); + event.setStopped(true); + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/FurnacePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FurnacePermission.java new file mode 100644 index 00000000..07c21595 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FurnacePermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class FurnacePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public FurnacePermission(SkyBlock plugin) { + super("Furnace", CompatibleMaterial.FURNACE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.FURNACE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/GatePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/GatePermission.java new file mode 100644 index 00000000..c201432b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/GatePermission.java @@ -0,0 +1,39 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class GatePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public GatePermission(SkyBlock plugin) { + super("Gate", CompatibleMaterial.OAK_FENCE_GATE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (material == CompatibleMaterial.OAK_FENCE_GATE || material == CompatibleMaterial.ACACIA_FENCE_GATE + || material == CompatibleMaterial.BIRCH_FENCE_GATE || material == CompatibleMaterial.DARK_OAK_FENCE_GATE + || material == CompatibleMaterial.JUNGLE_FENCE_GATE || material == CompatibleMaterial.SPRUCE_FENCE_GATE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/HangingDestroyPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HangingDestroyPermission.java new file mode 100644 index 00000000..fee55ad7 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HangingDestroyPermission.java @@ -0,0 +1,58 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class HangingDestroyPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public HangingDestroyPermission(SkyBlock plugin) { + super("HangingDestroy", CompatibleMaterial.ITEM_FRAME, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + + if (entity instanceof Hanging) { + + Player player; + if (event.getDamager() instanceof Player) + player = (Player)event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + cancelAndMessage(event, player, plugin, messageManager); + + } + } + + @PermissionHandler + public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { + if (!(event.getRemover() instanceof Player)) + return; + + cancelAndMessage(event, (Player) event.getRemover(), plugin, messageManager); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + if (!(event.getRightClicked() instanceof Hanging)) + return; + + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/HopperPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HopperPermission.java new file mode 100644 index 00000000..f2445f4d --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HopperPermission.java @@ -0,0 +1,50 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class HopperPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public HopperPermission(SkyBlock plugin) { + super("Hopper", CompatibleMaterial.HOPPER, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.HOPPER) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + + if (event.getRightClicked().getType() == EntityType.MINECART_HOPPER) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/HorseInventoryPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HorseInventoryPermission.java new file mode 100644 index 00000000..d027f149 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HorseInventoryPermission.java @@ -0,0 +1,48 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.HorseInventory; + +public class HorseInventoryPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public HorseInventoryPermission(SkyBlock plugin) { + super("HorseInventory", CompatibleMaterial.DIAMOND_HORSE_ARMOR, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + if (entity.getType() == EntityType.HORSE) { + Horse horse = (Horse) event.getRightClicked(); + if (horse.getInventory().getSaddle() != null && player.isSneaking()) + cancelAndMessage(event, player, plugin, messageManager); + } + } + + @PermissionHandler + public void onInventoryOpen(InventoryOpenEvent event) { + if (!(event.getInventory() instanceof HorseInventory)) + return; + + cancelAndMessage(event, (Player) event.getPlayer(), plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/HungerPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HungerPermission.java new file mode 100644 index 00000000..fde5cc42 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/HungerPermission.java @@ -0,0 +1,34 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.event.entity.FoodLevelChangeEvent; + +import java.io.File; + +public class HungerPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public HungerPermission(SkyBlock plugin) { + super("Hunger", CompatibleMaterial.COOKED_BEEF, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @Override + public boolean extraCheck() { + return plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Settings.Hunger.Enable"); + } + + @PermissionHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + event.setCancelled(true); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemDropPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemDropPermission.java new file mode 100644 index 00000000..f7904f06 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemDropPermission.java @@ -0,0 +1,19 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.event.player.PlayerDropItemEvent; + +public class ItemDropPermission extends ListeningPermission { + + public ItemDropPermission() { + super("ItemDrop", CompatibleMaterial.PUMPKIN_SEEDS, PermissionType.GENERIC); + } + + @PermissionHandler + public void ondropItem(PlayerDropItemEvent event) { + event.setCancelled(true); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemPickupPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemPickupPermission.java new file mode 100644 index 00000000..58fef4b4 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ItemPickupPermission.java @@ -0,0 +1,20 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; + +public class ItemPickupPermission extends ListeningPermission { + + public ItemPickupPermission() { + super("ItemPickup", CompatibleMaterial.MELON_SEEDS, PermissionType.GENERIC); + } + + @PermissionHandler + public void onPickupItem(PlayerPickupItemEvent event) { + event.setCancelled(true); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/JukeboxPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/JukeboxPermission.java new file mode 100644 index 00000000..249dc2b5 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/JukeboxPermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class JukeboxPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public JukeboxPermission(SkyBlock plugin) { + super("Jukebox", CompatibleMaterial.JUKEBOX, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.JUKEBOX) + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeashPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeashPermission.java new file mode 100644 index 00000000..024c875d --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeashPermission.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; + +public class LeashPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public LeashPermission(SkyBlock plugin) { + super("Leash", CompatibleMaterial.LEAD, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + ItemStack is = player.getItemInHand(); + + if (CompatibleMaterial.getMaterial(is) != CompatibleMaterial.AIR) { + if (CompatibleMaterial.getMaterial(is) == CompatibleMaterial.LEAD) + cancelAndMessage(event, player, plugin, messageManager); + } + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeverButtonPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeverButtonPermission.java new file mode 100644 index 00000000..56b61fba --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/LeverButtonPermission.java @@ -0,0 +1,40 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class LeverButtonPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public LeverButtonPermission(SkyBlock plugin) { + super("LeverButton", CompatibleMaterial.LEVER, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.STONE_BUTTON || material == CompatibleMaterial.OAK_BUTTON + || material == CompatibleMaterial.SPRUCE_BUTTON || material == CompatibleMaterial.BIRCH_BUTTON + || material == CompatibleMaterial.JUNGLE_BUTTON || material == CompatibleMaterial.ACACIA_BUTTON + || material == CompatibleMaterial.DARK_OAK_BUTTON || material == CompatibleMaterial.LEVER) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MilkingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MilkingPermission.java new file mode 100644 index 00000000..528a83d4 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MilkingPermission.java @@ -0,0 +1,43 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class MilkingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MilkingPermission(SkyBlock plugin) { + super("Milking", CompatibleMaterial.MILK_BUCKET, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + if (entity.getType() == EntityType.COW) { + if (CompatibleMaterial.getMaterial(player.getItemInHand()) == CompatibleMaterial.BUCKET) + cancelAndMessage(event, player, plugin, messageManager); + } else if (entity.getType() == EntityType.MUSHROOM_COW) { + if (CompatibleMaterial.getMaterial(player.getItemInHand()) == CompatibleMaterial.BUCKET + || CompatibleMaterial.getMaterial(player.getItemInHand()) == CompatibleMaterial.BOWL) + cancelAndMessage(event, player, plugin, messageManager); + + } + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MinecartPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MinecartPermission.java new file mode 100644 index 00000000..6f90d95a --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MinecartPermission.java @@ -0,0 +1,34 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class MinecartPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MinecartPermission(SkyBlock plugin) { + super("Minecart", CompatibleMaterial.MINECART, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + + if (event.getRightClicked().getType() == EntityType.MINECART) + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobGriefingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobGriefingPermission.java new file mode 100644 index 00000000..d411e012 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobGriefingPermission.java @@ -0,0 +1,58 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; + +public class MobGriefingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MobGriefingPermission(SkyBlock plugin) { + super("MobGriefing", CompatibleMaterial.IRON_SHOVEL, PermissionType.ISLAND); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onVehicleDamage(VehicleDamageEvent event) { + + + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onVehicleDestroy(VehicleDestroyEvent event) { + + + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + EntityType type = event.getEntityType(); + + if (type == EntityType.ARMOR_STAND || type == EntityType.PLAYER || entity instanceof Monster) return; + + Player player; + if (event.getDamager() instanceof Player) + player = (Player)event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobHurtingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobHurtingPermission.java new file mode 100644 index 00000000..36a51d46 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobHurtingPermission.java @@ -0,0 +1,58 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; + +public class MobHurtingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MobHurtingPermission(SkyBlock plugin) { + super("MobHurting", CompatibleMaterial.WOODEN_SWORD, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onVehicleDamage(VehicleDamageEvent event) { + + + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onVehicleDestroy(VehicleDestroyEvent event) { + + + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + EntityType type = event.getEntityType(); + + if (type == EntityType.ARMOR_STAND || type == EntityType.PLAYER || entity instanceof Monster) return; + + Player player; + if (event.getDamager() instanceof Player) + player = (Player)event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobRidingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobRidingPermission.java new file mode 100644 index 00000000..75671896 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobRidingPermission.java @@ -0,0 +1,44 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class MobRidingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MobRidingPermission(SkyBlock plugin) { + super("MobRiding", CompatibleMaterial.SADDLE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + if (entity.getType() == EntityType.HORSE || entity.getType() == EntityType.PIG) { + if (entity.getType() == EntityType.HORSE) { + Horse horse = (Horse) event.getRightClicked(); + if (horse.getInventory().getSaddle() == null) + cancelAndMessage(event, player, plugin, messageManager); + } else if (entity.getType() == EntityType.PIG) { + cancelAndMessage(event, player, plugin, messageManager); + } + } + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobTamingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobTamingPermission.java new file mode 100644 index 00000000..1a04e224 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MobTamingPermission.java @@ -0,0 +1,54 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; + +public class MobTamingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MobTamingPermission(SkyBlock plugin) { + super("MobTaming", CompatibleMaterial.POPPY, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onVehicleDamage(VehicleDamageEvent event) { + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onVehicleDestroy(VehicleDestroyEvent event) { + Player player = (Player) event.getAttacker(); + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + EntityType type = event.getEntityType(); + + if (type == EntityType.ARMOR_STAND || type == EntityType.PLAYER || entity instanceof Monster) return; + + Player player; + if (event.getDamager() instanceof Player) + player = (Player)event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/MonsterHurtingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MonsterHurtingPermission.java new file mode 100644 index 00000000..8d2558ef --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/MonsterHurtingPermission.java @@ -0,0 +1,39 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionPriority; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class MonsterHurtingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public MonsterHurtingPermission(SkyBlock plugin) { + super("MonsterHurting", CompatibleMaterial.BONE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler(priority = PermissionPriority.FIRST) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Player player; + if (event.getDamager() instanceof Player) + player = (Player)event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + Entity entity = event.getEntity(); + + if (entity.getType() == EntityType.ARMOR_STAND || !(entity instanceof Monster)) return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/NoteblockPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/NoteblockPermission.java new file mode 100644 index 00000000..c9016d9f --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/NoteblockPermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class NoteblockPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public NoteblockPermission(SkyBlock plugin) { + super("Noteblock", CompatibleMaterial.NOTE_BLOCK, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.NOTE_BLOCK) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/PlacePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PlacePermission.java new file mode 100644 index 00000000..c09643e1 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PlacePermission.java @@ -0,0 +1,40 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class PlacePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public PlacePermission(SkyBlock plugin) { + super("Place", CompatibleMaterial.DIRT, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + + if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.BONE_MEAL) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onPlace(BlockPlaceEvent event) { + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/PortalPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PortalPermission.java new file mode 100644 index 00000000..ad7fb013 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PortalPermission.java @@ -0,0 +1,62 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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.version.NMSUtil; +import com.songoda.skyblock.utils.world.LocationUtil; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class PortalPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public PortalPermission(SkyBlock plugin) { + super("Portal", CompatibleMaterial.ENDER_PEARL, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onPortalEnter(PlayerEnterPortalEvent event) { + 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); + } + } + + @PermissionHandler + public void onTeleport(PlayerTeleportEvent event) { + boolean isCause = false; + + if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL || event.getCause() == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL || event.getCause() == PlayerTeleportEvent.TeleportCause.END_PORTAL) { + isCause = true; + } else { + if (NMSUtil.getVersionNumber() > 9) { + if (event.getCause() == PlayerTeleportEvent.TeleportCause.END_GATEWAY) { + isCause = true; + } + } + } + + if (isCause) + cancelAndMessage(event, event.getPlayer(), plugin, messageManager); + } +} + diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/PressurePlatePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PressurePlatePermission.java new file mode 100644 index 00000000..81a664a3 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PressurePlatePermission.java @@ -0,0 +1,41 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class PressurePlatePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public PressurePlatePermission(SkyBlock plugin) { + super("PressurePlate", CompatibleMaterial.OAK_PRESSURE_PLATE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.PHYSICAL) + return; + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (material == CompatibleMaterial.STONE_PRESSURE_PLATE || material == CompatibleMaterial.OAK_PRESSURE_PLATE + || material == CompatibleMaterial.SPRUCE_PRESSURE_PLATE || material == CompatibleMaterial.BIRCH_PRESSURE_PLATE + || material == CompatibleMaterial.JUNGLE_PRESSURE_PLATE || material == CompatibleMaterial.ACACIA_PRESSURE_PLATE + || material == CompatibleMaterial.DARK_OAK_PRESSURE_PLATE || material == CompatibleMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE + || material == CompatibleMaterial.HEAVY_WEIGHTED_PRESSURE_PLATE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java new file mode 100644 index 00000000..873f0cbc --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java @@ -0,0 +1,40 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionPriority; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class ProjectilePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public ProjectilePermission(SkyBlock plugin) { + super("Projectile", CompatibleMaterial.ARROW, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) + return; + + Player player = event.getPlayer(); + if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.EGG) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler(priority = PermissionPriority.LAST) + public void onProjectileLaunch(ProjectileLaunchEvent event) { + event.setCancelled(true); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/PvpPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PvpPermission.java new file mode 100644 index 00000000..ce5ecaaa --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/PvpPermission.java @@ -0,0 +1,53 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +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 org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +import java.io.File; + +public class PvpPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + private final FileManager fileManager; + + public PvpPermission(SkyBlock plugin) { + super("PvP", CompatibleMaterial.DIAMOND_SWORD, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + this.fileManager = plugin.getFileManager(); + } + + @PermissionHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + + Player player; + if (event.getDamager() instanceof Player) + player = (Player) event.getDamager(); + else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) + player = (Player) ((Projectile) event.getDamager()).getShooter(); + else return; + + FileManager.Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Settings.PvP.Enable")) { + event.setCancelled(true); + } else if (!configLoad.getBoolean("Island.PvP.Enable")) { + event.setCancelled(true); + } + + if (entity.getType() == EntityType.ARMOR_STAND || !(entity instanceof Monster)) return; + + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/RedstonePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/RedstonePermission.java new file mode 100644 index 00000000..418187a1 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/RedstonePermission.java @@ -0,0 +1,39 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class RedstonePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public RedstonePermission(SkyBlock plugin) { + super("Redstone", CompatibleMaterial.REDSTONE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (material == CompatibleMaterial.COMPARATOR || material == CompatibleMaterial.REPEATER) + cancelAndMessage(event, player, plugin, messageManager); + } else if (event.getAction() == Action.PHYSICAL) { + if (material == CompatibleMaterial.TRIPWIRE) + cancelAndMessage(event, player, plugin, messageManager); + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ShearingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ShearingPermission.java new file mode 100644 index 00000000..9167448f --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ShearingPermission.java @@ -0,0 +1,28 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerShearEntityEvent; + +public class ShearingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public ShearingPermission(SkyBlock plugin) { + super("Shearing", CompatibleMaterial.SHEARS, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onShear(PlayerShearEntityEvent event) { + Player player = event.getPlayer(); + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/SpawnEggPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/SpawnEggPermission.java new file mode 100644 index 00000000..cbac7254 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/SpawnEggPermission.java @@ -0,0 +1,35 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEvent; + +public class SpawnEggPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public SpawnEggPermission(SkyBlock plugin) { + super("SpawnEgg", CompatibleMaterial.EGG, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + Player player = event.getPlayer(); + if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR) { + if (event.getItem().getType().name().contains("SPAWN_EGG") || event.getItem().getType().name().equals("MONSTER_EGG")) { + cancelAndMessage(event, player, plugin, messageManager); + player.updateInventory(); + } + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/StoragePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/StoragePermission.java new file mode 100644 index 00000000..089e2129 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/StoragePermission.java @@ -0,0 +1,62 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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.utils.version.NMSUtil; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.minecart.StorageMinecart; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class StoragePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public StoragePermission(SkyBlock plugin) { + super("Storage", CompatibleMaterial.CHEST, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + Player player = event.getPlayer(); + + if (material == CompatibleMaterial.CHEST || material == CompatibleMaterial.TRAPPED_CHEST + || (NMSUtil.getVersionNumber() > 9 && (material == CompatibleMaterial.SHULKER_BOX + || material == CompatibleMaterial.BLACK_SHULKER_BOX || material == CompatibleMaterial.BLUE_SHULKER_BOX + || material == CompatibleMaterial.BROWN_SHULKER_BOX || material == CompatibleMaterial.CYAN_SHULKER_BOX + || material == CompatibleMaterial.GRAY_SHULKER_BOX || material == CompatibleMaterial.GREEN_SHULKER_BOX + || material == CompatibleMaterial.LIGHT_BLUE_SHULKER_BOX || material == CompatibleMaterial.LIGHT_GRAY_SHULKER_BOX + || material == CompatibleMaterial.LIME_SHULKER_BOX || material == CompatibleMaterial.MAGENTA_SHULKER_BOX + || material == CompatibleMaterial.ORANGE_SHULKER_BOX || material == CompatibleMaterial.PINK_SHULKER_BOX + || material == CompatibleMaterial.PURPLE_SHULKER_BOX || material == CompatibleMaterial.RED_SHULKER_BOX + || material == CompatibleMaterial.WHITE_SHULKER_BOX || material == CompatibleMaterial.YELLOW_SHULKER_BOX))) + cancelAndMessage(event, player, plugin, messageManager); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + + if (event.getRightClicked().getType() == EntityType.ITEM_FRAME + || event.getRightClicked() instanceof StorageMinecart) + cancelAndMessage(event, player, plugin, messageManager); + + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/TradingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TradingPermission.java new file mode 100644 index 00000000..49e72cce --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TradingPermission.java @@ -0,0 +1,36 @@ +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.message.MessageManager; +import com.songoda.skyblock.permission.ListeningPermission; +import com.songoda.skyblock.permission.PermissionHandler; +import com.songoda.skyblock.permission.PermissionType; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class TradingPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public TradingPermission(SkyBlock plugin) { + super("Trading", CompatibleMaterial.EMERALD, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + + + Player player = event.getPlayer(); + + if (event.getRightClicked().getType() == EntityType.VILLAGER + || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) + && event.getRightClicked().getType() == EntityType.WANDERING_TRADER) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/TramplePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TramplePermission.java new file mode 100644 index 00000000..0d2ffd30 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TramplePermission.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class TramplePermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public TramplePermission(SkyBlock plugin) { + super("Trample", CompatibleMaterial.WHEAT_SEEDS, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.PHYSICAL) + return; + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (material == CompatibleMaterial.TURTLE_EGG || material == CompatibleMaterial.FARMLAND) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/TrapdoorPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TrapdoorPermission.java new file mode 100644 index 00000000..a05c4f27 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/TrapdoorPermission.java @@ -0,0 +1,39 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class TrapdoorPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public TrapdoorPermission(SkyBlock plugin) { + super("Trapdoor", CompatibleMaterial.OAK_TRAPDOOR, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + + if (material == CompatibleMaterial.OAK_TRAPDOOR || material == CompatibleMaterial.SPRUCE_TRAPDOOR + || material == CompatibleMaterial.BIRCH_TRAPDOOR || material == CompatibleMaterial.JUNGLE_TRAPDOOR + || material == CompatibleMaterial.ACACIA_TRAPDOOR || material == CompatibleMaterial.DARK_OAK_TRAPDOOR) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/WaterCollectionPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/WaterCollectionPermission.java new file mode 100644 index 00000000..8f52a38b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/WaterCollectionPermission.java @@ -0,0 +1,38 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEvent; + +public class WaterCollectionPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public WaterCollectionPermission(SkyBlock plugin) { + super("WaterCollection", CompatibleMaterial.POTION, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + + + Player player = event.getPlayer(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); + if (event.getItem() != null && CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.AIR) { + if (CompatibleMaterial.getMaterial(event.getItem()) == CompatibleMaterial.GLASS_BOTTLE) { + if (material == CompatibleMaterial.WATER || material == CompatibleMaterial.CAULDRON) { + cancelAndMessage(event, player, plugin, messageManager); + player.updateInventory(); + } + } + } + } +} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/WorkbenchPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/WorkbenchPermission.java new file mode 100644 index 00000000..fb976239 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/WorkbenchPermission.java @@ -0,0 +1,36 @@ +package com.songoda.skyblock.permission.permissions.listening; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +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 org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class WorkbenchPermission extends ListeningPermission { + + private final SkyBlock plugin; + private final MessageManager messageManager; + + public WorkbenchPermission(SkyBlock plugin) { + super("Workbench", CompatibleMaterial.CRAFTING_TABLE, PermissionType.GENERIC); + this.plugin = plugin; + this.messageManager = plugin.getMessageManager(); + } + + @PermissionHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (CompatibleMaterial.getMaterial(block) == CompatibleMaterial.CRAFTING_TABLE) + cancelAndMessage(event, player, plugin, messageManager); + } +} diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index d575a604..63e4ccbd 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -12,7 +12,7 @@ Settings: WaterCollection: false Storage: false Workbench: false - Crop: false + Trample: false Door: false Gate: false Projectile: false @@ -40,11 +40,14 @@ Settings: HangingDestroy: false Cake: false DragonEggUse: false - MinecartBoat: false + Minecart: false + Boat: false Portal: false Hopper: false EntityPlacement: false ExperienceOrbPickup: false + Trapdoor: false + Noteblock: false Member: Destroy: true Place: true @@ -58,7 +61,7 @@ Settings: WaterCollection: true Storage: true Workbench: true - Crop: true + Trample: true Door: true Gate: true Projectile: true @@ -83,7 +86,8 @@ Settings: Fishing: true DropperDispenser: true SpawnEgg: true - MinecartBoat: true + Minecart: true + Boat: true HangingDestroy: true Cake: true DragonEggUse: true @@ -91,6 +95,8 @@ Settings: Hopper: true EntityPlacement: true ExperienceOrbPickup: true + Trapdoor: true + Noteblock: true Operator: Invite: true Kick: true