Search in sources :

Example 11 with Permission

use of org.bukkit.permissions.Permission in project BKCommonLib by bergerhealer.

the class PluginBase method loadPermission.

/**
 * Loads a single permission using the configuration node, default and
 * description
 *
 * @param node to use for the permission path, default and description
 * @param def value to use if the node is unusable
 * @param description to use if the node is unusable
 * @return Permission that was loaded
 */
public final Permission loadPermission(ConfigurationNode node, PermissionDefault def, String description) {
    Permission permission = getPermission(node.getPath());
    permission.setDefault(node.get("default", def));
    permission.setDescription(node.get("description", description));
    return permission;
}
Also used : Permission(org.bukkit.permissions.Permission)

Example 12 with Permission

use of org.bukkit.permissions.Permission in project MyPet by xXKeyleXx.

the class MyPetPlugin method onEnable.

public void onEnable() {
    this.isReady = false;
    Updater updater = new Updater("MyPet");
    updater.update();
    if (compatUtil.getInternalVersion() == null || !MyPetVersion.isValidBukkitPacket(compatUtil.getInternalVersion())) {
        getLogger().warning(ChatColor.RED + "This version of MyPet is not compatible with \"" + compatUtil.getInternalVersion() + "\". Is MyPet up to date?");
        updater.waitForDownload();
        setEnabled(false);
        return;
    }
    serviceManager.activate(Load.State.OnEnable);
    pluginHookManager.enableHooks();
    serviceManager.activate(Load.State.AfterHooks);
    entityRegistry.registerEntityTypes();
    if (getLogger() instanceof MyPetLogger) {
        ((MyPetLogger) getLogger()).updateDebugLoggerLogLevel();
    }
    compatManager.enable();
    getLogger().info("Compat mode for " + compatUtil.getInternalVersion() + " loaded.");
    // register event listener
    PlayerListener playerListener = new PlayerListener();
    getServer().getPluginManager().registerEvents(playerListener, this);
    VehicleListener vehicleListener = new VehicleListener();
    getServer().getPluginManager().registerEvents(vehicleListener, this);
    EntityListener entityListener = new EntityListener();
    getServer().getPluginManager().registerEvents(entityListener, this);
    LevelUpListener levelupListener = new LevelUpListener();
    getServer().getPluginManager().registerEvents(levelupListener, this);
    WorldListener worldListener = new WorldListener();
    getServer().getPluginManager().registerEvents(worldListener, this);
    // register commands
    getCommand("petname").setExecutor(new CommandName());
    getCommand("petcall").setExecutor(new CommandCall());
    getCommand("petsendaway").setExecutor(new CommandSendAway());
    getCommand("petstop").setExecutor(new CommandStop());
    getCommand("petrelease").setExecutor(new CommandRelease());
    getCommand("mypet").setExecutor(new CommandHelp());
    getCommand("petinventory").setExecutor(new CommandInventory());
    getCommand("petpickup").setExecutor(new CommandPickup());
    getCommand("petbehavior").setExecutor(new CommandBehavior());
    getCommand("petinfo").setExecutor(new CommandInfo());
    getCommand("mypetadmin").setExecutor(new CommandAdmin());
    getCommand("petskill").setExecutor(new CommandSkill());
    getCommand("petskilltree").setExecutor(new CommandShowSkillTree());
    getCommand("petchooseskilltree").setExecutor(new CommandChooseSkilltree());
    getCommand("petbeacon").setExecutor(new CommandBeacon());
    getCommand("petrespawn").setExecutor(new CommandRespawn());
    getCommand("pettype").setExecutor(new CommandPetType());
    getCommand("petsettings").setExecutor(new CommandSettings());
    getCommand("petswitch").setExecutor(new CommandSwitch());
    getCommand("petstore").setExecutor(new CommandStore());
    getCommand("petlist").setExecutor(new CommandList());
    // register skills
    registerSkillsInfo();
    registerSkills();
    // create folders
    File skilltreeFolder = new File(getDataFolder().getPath(), "skilltrees");
    getDataFolder().mkdirs();
    boolean createDefaultSkilltree = skilltreeFolder.mkdirs();
    new File(getDataFolder(), "locale").mkdirs();
    new File(getDataFolder(), "logs").mkdirs();
    if (createDefaultSkilltree) {
        platformHelper.copyResource(this, "skilltrees/default.st", new File(skilltreeFolder, "default.st"));
        getLogger().info("Default skilltree file created (default.st).");
    }
    // load skilltrees
    List<String> petTypes = new LinkedList<>();
    petTypes.add("default");
    for (MyPetType type : MyPetType.all()) {
        petTypes.add(type.name());
    }
    SkillTreeMobType.clearMobTypes();
    SkillTreeLoaderNBT.getSkilltreeLoader().loadSkillTrees(getDataFolder().getPath() + File.separator + "skilltrees", petTypes);
    Set<String> skilltreeNames = new LinkedHashSet<>();
    for (MyPetType mobType : MyPetType.values()) {
        SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(mobType);
        SkillTreeLoader.addDefault(skillTreeMobType);
        SkillTreeLoader.manageInheritance(skillTreeMobType);
        skilltreeNames.addAll(skillTreeMobType.getSkillTreeNames());
    }
    // register skilltree permissions
    for (String skilltreeName : skilltreeNames) {
        try {
            Bukkit.getPluginManager().addPermission(new Permission("MyPet.skilltree." + skilltreeName));
        } catch (Exception ignored) {
        }
    }
    for (int i = 0; i <= Configuration.Misc.MAX_STORED_PET_COUNT; i++) {
        try {
            Bukkit.getPluginManager().addPermission(new Permission("MyPet.petstorage.limit." + i));
        } catch (Exception ignored) {
        }
    }
    File translationReadme = new File(getDataFolder(), "locale" + File.separator + "readme.txt");
    if (!translationReadme.exists()) {
        platformHelper.copyResource(this, "locale-readme.txt", translationReadme);
    }
    Translation.init();
    for (Team team : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) {
        if (team.getName().startsWith("MyPet-")) {
            team.unregister();
        }
    }
    // init repository
    repo = new SqLiteRepository();
    try {
        repo.init();
    } catch (RepositoryInitException ignored) {
        setEnabled(false);
        return;
    }
    File nbtFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets");
    if (nbtFile.exists()) {
        Converter.convert();
    }
    if (repo instanceof Scheduler) {
        Timer.addTask((Scheduler) repo);
    }
    // load worldgroups
    loadGroups(new File(getDataFolder().getPath(), "worldgroups.yml"));
    Timer.startTimer();
    // init Metrics
    Metrics metrics = new Metrics(this);
    metrics.addCustomChart(new Metrics.SingleLineChart("active_pets", () -> myPetManager.countActiveMyPets()));
    metrics.addCustomChart(new Metrics.SimplePie("build", MyPetVersion::getBuild));
    metrics.addCustomChart(new Metrics.SimplePie("update_mode", () -> {
        String mode = "Disabled";
        if (Configuration.Update.CHECK) {
            mode = "Check";
            if (Configuration.Update.DOWNLOAD) {
                mode += " & Download";
            }
        }
        return mode;
    }));
    updater.waitForDownload();
    getLogger().info("version " + MyPetVersion.getVersion() + "-b" + MyPetVersion.getBuild() + ChatColor.GREEN + " ENABLED");
    this.isReady = true;
    serviceManager.activate(Load.State.OnReady);
    // load pets for online players
    new BukkitRunnable() {

        @Override
        public void run() {
            for (final Player player : getServer().getOnlinePlayers()) {
                repo.getMyPetPlayer(player, new RepositoryCallback<MyPetPlayer>() {

                    @Override
                    public void callback(final MyPetPlayer p) {
                        if (p != null) {
                            final MyPetPlayerImpl onlinePlayer = (MyPetPlayerImpl) p;
                            onlinePlayer.setLastKnownName(player.getName());
                            if (!player.getUniqueId().equals(onlinePlayer.getOfflineUUID())) {
                                if (onlinePlayer.getMojangUUID() == null) {
                                    onlinePlayer.setMojangUUID(player.getUniqueId());
                                }
                                onlinePlayer.setOnlineMode(true);
                            }
                            playerManager.setOnline(onlinePlayer);
                            final WorldGroup joinGroup = WorldGroup.getGroupByWorld(player.getWorld().getName());
                            if (onlinePlayer.hasMyPet()) {
                                MyPet myPet = onlinePlayer.getMyPet();
                                if (!myPet.getWorldGroup().equals(joinGroup.getName())) {
                                    myPetManager.deactivateMyPet(onlinePlayer, true);
                                }
                            }
                            if (joinGroup != null && !onlinePlayer.hasMyPet() && onlinePlayer.hasMyPetInWorldGroup(joinGroup.getName())) {
                                final UUID petUUID = onlinePlayer.getMyPetForWorldGroup(joinGroup.getName());
                                MyPetApi.getRepository().getMyPet(petUUID, new RepositoryCallback<StoredMyPet>() {

                                    @Override
                                    public void callback(StoredMyPet storedMyPet) {
                                        myPetManager.activateMyPet(storedMyPet);
                                        if (onlinePlayer.hasMyPet()) {
                                            final MyPet myPet = onlinePlayer.getMyPet();
                                            final MyPetPlayer myPetPlayer = myPet.getOwner();
                                            if (myPet.wantsToRespawn()) {
                                                if (myPetPlayer.hasMyPet()) {
                                                    MyPet runMyPet = myPetPlayer.getMyPet();
                                                    switch(runMyPet.createEntity()) {
                                                        case Canceled:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPet.getOwner()), runMyPet.getPetName()));
                                                            break;
                                                        case NoSpace:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPet.getOwner()), runMyPet.getPetName()));
                                                            break;
                                                        case NotAllowed:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPet.getOwner()), myPet.getPetName()));
                                                            break;
                                                        case Dead:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", myPet.getOwner()), myPet.getPetName(), myPet.getRespawnTime()));
                                                            break;
                                                        case Flying:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPet.getOwner()), myPet.getPetName()));
                                                            break;
                                                        case Success:
                                                            runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", myPet.getOwner()), runMyPet.getPetName()));
                                                            break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                });
                            }
                            onlinePlayer.checkForDonation();
                        }
                    }
                });
            }
        }
    }.runTaskLater(this, 0);
}
Also used : MyPetPlayerImpl(de.Keyle.MyPet.util.player.MyPetPlayerImpl) Metrics(org.bstats.bukkit.Metrics) Updater(de.Keyle.MyPet.util.Updater) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) Permission(org.bukkit.permissions.Permission) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPetLogger(de.Keyle.MyPet.util.logger.MyPetLogger) SqLiteRepository(de.Keyle.MyPet.repository.types.SqLiteRepository) File(java.io.File) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Team(org.bukkit.scoreboard.Team) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 13 with Permission

use of org.bukkit.permissions.Permission in project MyPet by xXKeyleXx.

the class CommandOptionReload method onCommandOption.

@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
    int oldMaxPetCount = Configuration.Misc.MAX_STORED_PET_COUNT;
    ConfigurationLoader.loadConfiguration();
    ConfigurationLoader.loadCompatConfiguration();
    if (MyPetApi.getLogger() instanceof MyPetLogger) {
        ((MyPetLogger) MyPetApi.getLogger()).updateDebugLoggerLogLevel();
    }
    Translation.init();
    if (Configuration.Misc.MAX_STORED_PET_COUNT > oldMaxPetCount) {
        for (int i = oldMaxPetCount + 1; i <= Configuration.Misc.MAX_STORED_PET_COUNT; i++) {
            try {
                Bukkit.getPluginManager().addPermission(new Permission("MyPet.petstorage.limit." + i));
            } catch (Exception ignored) {
            }
        }
    } else if (oldMaxPetCount > Configuration.Misc.MAX_STORED_PET_COUNT) {
        for (int i = oldMaxPetCount; i > Configuration.Misc.MAX_STORED_PET_COUNT; i--) {
            try {
                Bukkit.getPluginManager().removePermission("MyPet.petstorage.limit." + i);
            } catch (Exception ignored) {
            }
        }
    }
    sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] config loaded!");
    return true;
}
Also used : Permission(org.bukkit.permissions.Permission) MyPetLogger(de.Keyle.MyPet.util.logger.MyPetLogger)

Example 14 with Permission

use of org.bukkit.permissions.Permission in project Jobs by GamingMesh.

the class PermissionHandler method recalculatePermissions.

public void recalculatePermissions(JobsPlayer jPlayer) {
    Player player = plugin.getServer().getPlayer(jPlayer.getPlayerUUID());
    if (player == null)
        return;
    boolean changed = false;
    // remove old permissions
    String permName = "jobs.players." + player.getName();
    Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
    if (permission != null) {
        plugin.getServer().getPluginManager().removePermission(permission);
        changed = true;
    }
    // Permissions should only apply if we have permission to use jobs in this world
    if (hasWorldPermission(player, player.getWorld().getName())) {
        List<JobProgression> progression = jPlayer.getJobProgression();
        // calculate new permissions
        HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
        if (progression.size() == 0) {
            Job job = Jobs.getNoneJob();
            if (job != null) {
                for (JobPermission perm : job.getPermissions()) {
                    if (perm.getLevelRequirement() <= 0) {
                        if (perm.getValue()) {
                            permissions.put(perm.getNode(), true);
                        } else {
                            /*
                                 * If the key exists, don't put a false node in
                                 * This is in case we already have a true node there
                                 */
                            if (!permissions.containsKey(perm.getNode())) {
                                permissions.put(perm.getNode(), false);
                            }
                        }
                    }
                }
            }
        } else {
            for (JobProgression prog : progression) {
                for (JobPermission perm : prog.getJob().getPermissions()) {
                    if (prog.getLevel() >= perm.getLevelRequirement()) {
                        /*
                             * If the key exists, don't put a false node in
                             * This is in case we already have a true node there
                             */
                        if (perm.getValue()) {
                            permissions.put(perm.getNode(), true);
                        } else {
                            if (!permissions.containsKey(perm.getNode())) {
                                permissions.put(perm.getNode(), false);
                            }
                        }
                    }
                }
            }
        }
        // add new permissions (if applicable)
        if (permissions.size() > 0) {
            plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
            changed = true;
        }
    }
    // If the permissions changed, recalculate them
    if (!changed)
        return;
    // find old attachment
    PermissionAttachment attachment = null;
    for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
        if (pai.getAttachment() != null && pai.getAttachment().getPlugin() instanceof JobsPlugin) {
            attachment = pai.getAttachment();
        }
    }
    // create if attachment doesn't exist
    if (attachment == null) {
        attachment = player.addAttachment(plugin);
        attachment.setPermission(permName, true);
    }
    // recalculate!
    player.recalculatePermissions();
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) HashMap(java.util.HashMap) JobPermission(com.gamingmesh.jobs.container.JobPermission) JobProgression(com.gamingmesh.jobs.container.JobProgression) Permission(org.bukkit.permissions.Permission) JobPermission(com.gamingmesh.jobs.container.JobPermission) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) Job(com.gamingmesh.jobs.container.Job) PermissionAttachment(org.bukkit.permissions.PermissionAttachment)

Example 15 with Permission

use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.

the class CommandPermissions method registerOp.

private static Permission registerOp(Permission parent) {
    Permission op = DefaultPermissions.registerPermission(PREFIX + "op", "Allows the user to change operators", PermissionDefault.OP, parent);
    DefaultPermissions.registerPermission(PREFIX + "op.give", "Allows the user to give a player operator status", op);
    DefaultPermissions.registerPermission(PREFIX + "op.take", "Allows the user to take a players operator status", op);
    op.recalculatePermissibles();
    return op;
}
Also used : Permission(org.bukkit.permissions.Permission)

Aggregations

Permission (org.bukkit.permissions.Permission)23 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)2 MyPetLogger (de.Keyle.MyPet.util.logger.MyPetLogger)2 Player (org.bukkit.entity.Player)2 ConfigurationNode (com.bergerkiller.bukkit.common.config.ConfigurationNode)1 IPermissionDefault (com.bergerkiller.bukkit.common.permissions.IPermissionDefault)1 Job (com.gamingmesh.jobs.container.Job)1 JobPermission (com.gamingmesh.jobs.container.JobPermission)1 JobProgression (com.gamingmesh.jobs.container.JobProgression)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1 MyPet (de.Keyle.MyPet.api.entity.MyPet)1 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)1 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)1 SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)1 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)1 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)1 Updater (de.Keyle.MyPet.util.Updater)1 MyPetPlayerImpl (de.Keyle.MyPet.util.player.MyPetPlayerImpl)1 File (java.io.File)1 HashMap (java.util.HashMap)1