Search in sources :

Example 1 with SkillType

use of com.gmail.nossr50.datatypes.skills.SkillType in project GDHooks by bloodmc.

the class McMMOProvider method onPlayerSkillEvent.

public boolean onPlayerSkillEvent(McMMOPlayerSkillEvent event, Object target, Set<Context> contexts) {
    final Player player = event.getPlayer();
    final World world = player.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return true;
    }
    final Location location = player.getLocation();
    final PlayerData playerData = GriefDefender.getCore().getPlayerData(world.getUID(), player.getUniqueId());
    final Claim claim = GriefDefender.getCore().getClaimAt(location);
    final String skillType = event.getSkill().name().toLowerCase().replace(" ", "_");
    contexts.add(new Context("mcmmo:skill_level", String.valueOf(event.getSkillLevel())));
    contexts.add(new Context("mcmmo:skill_type", skillType));
    final Tristate result = GriefDefender.getPermissionManager().getActiveFlagPermissionValue(event, location, claim, playerData.getUser(), SKILL_USE, player, target, contexts, null, true);
    if (result == Tristate.FALSE) {
        return false;
    }
    return true;
}
Also used : Context(com.griefdefender.api.permission.Context) Player(org.bukkit.entity.Player) McMMOPlayer(com.gmail.nossr50.datatypes.player.McMMOPlayer) Tristate(com.griefdefender.api.Tristate) World(org.bukkit.World) PlayerData(com.griefdefender.api.data.PlayerData) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location)

Example 2 with SkillType

use of com.gmail.nossr50.datatypes.skills.SkillType in project GDHooks by bloodmc.

the class McMMOProvider method onPlayerXpGain.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerXpGain(McMMOPlayerXpGainEvent event) {
    final String skillType = event.getSkill().name().toLowerCase().replace(" ", "_");
    final String reason = event.getXpGainReason().name().toLowerCase();
    final Player player = event.getPlayer();
    final World world = player.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return;
    }
    final Set<Context> contexts = new HashSet<>();
    contexts.add(new Context("mcmmo:skill_level", String.valueOf(event.getSkillLevel())));
    contexts.add(new Context("mcmmo:skill_type", skillType));
    contexts.add(new Context("mcmmo:reason", reason));
    final Location location = player.getLocation();
    final PlayerData playerData = GriefDefender.getCore().getPlayerData(world.getUID(), player.getUniqueId());
    final Claim claim = GriefDefender.getCore().getClaimAt(location);
    final Double xpGained = GriefDefender.getPermissionManager().getActiveOptionValue(TypeToken.get(Double.class), MCMMO_XP_GAIN_MODIFIER, playerData.getUser(), claim, contexts);
    if (xpGained != null && xpGained != 1.0) {
        event.setRawXpGained(event.getRawXpGained() * xpGained.floatValue());
    }
}
Also used : Context(com.griefdefender.api.permission.Context) Player(org.bukkit.entity.Player) McMMOPlayer(com.gmail.nossr50.datatypes.player.McMMOPlayer) World(org.bukkit.World) PlayerData(com.griefdefender.api.data.PlayerData) Claim(com.griefdefender.api.claim.Claim) HashSet(java.util.HashSet) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with SkillType

use of com.gmail.nossr50.datatypes.skills.SkillType in project GDHooks by bloodmc.

the class McMMOProvider method onPlayerDisarmEvent.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerDisarmEvent(McMMOPlayerDisarmEvent event) {
    final Player player = event.getPlayer();
    final World world = player.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return;
    }
    final Player targetPlayer = event.getDefender();
    final Location location = targetPlayer.getLocation();
    final PlayerData playerData = GriefDefender.getCore().getPlayerData(world.getUID(), player.getUniqueId());
    final Claim claim = GriefDefender.getCore().getClaimAt(location);
    final String skillType = event.getSkill().name().toLowerCase().replace(" ", "_");
    final Set<Context> contexts = new HashSet<>();
    contexts.add(new Context("mcmmo:skill_level", String.valueOf(event.getSkillLevel())));
    contexts.add(new Context("mcmmo:skill_type", skillType));
    final Tristate result = GriefDefender.getPermissionManager().getActiveFlagPermissionValue(event, location, claim, playerData.getUser(), PLAYER_DISARM, player, targetPlayer, contexts, null, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
Also used : Context(com.griefdefender.api.permission.Context) Player(org.bukkit.entity.Player) McMMOPlayer(com.gmail.nossr50.datatypes.player.McMMOPlayer) Tristate(com.griefdefender.api.Tristate) World(org.bukkit.World) PlayerData(com.griefdefender.api.data.PlayerData) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) HashSet(java.util.HashSet) EventHandler(org.bukkit.event.EventHandler)

Example 4 with SkillType

use of com.gmail.nossr50.datatypes.skills.SkillType in project Depenizen by DenizenScript.

the class McMMOCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ElementTag state = scriptEntry.getElement("state");
    ElementTag type = scriptEntry.getElement("type");
    ElementTag quantity = scriptEntry.getElement("quantity");
    ElementTag party = scriptEntry.getElement("party");
    ElementTag skill = scriptEntry.getElement("skill");
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, type, state, quantity, party, skill);
    }
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            {
                if (quantity.asDouble() >= 0 && skill != null && player != null) {
                    switch(Type.valueOf(type.asString().toUpperCase())) {
                        case LEVELS:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.addLevel(player.getPlayerEntity(), skill.asString(), quantity.asInt());
                                } else {
                                    ExperienceAPI.addLevelOffline(player.getName(), skill.asString(), quantity.asInt());
                                }
                                break;
                            }
                        case XP:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.addRawXP(player.getPlayerEntity(), skill.asString(), quantity.asFloat());
                                } else {
                                    ExperienceAPI.addRawXPOffline(player.getName(), skill.asString(), quantity.asFloat());
                                }
                            }
                    }
                } else if (party != null && PartyManager.getParty(party.asString()) != null) {
                    PartyAPI.addToParty(player.getPlayerEntity(), party.asString());
                }
                break;
            }
        case REMOVE:
            {
                if (quantity.asDouble() >= 0 && skill != null && player != null) {
                    switch(Type.valueOf(type.asString().toUpperCase())) {
                        case LEVELS:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.setLevel(player.getPlayerEntity(), skill.asString(), ExperienceAPI.getLevel(player.getPlayerEntity(), skill.asString()) - quantity.asInt());
                                } else {
                                    ExperienceAPI.setLevelOffline(player.getName(), skill.asString(), ExperienceAPI.getLevelOffline(player.getName(), skill.asString()) - quantity.asInt());
                                }
                                break;
                            }
                        case XP:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.removeXP(player.getPlayerEntity(), skill.asString(), quantity.asInt());
                                } else {
                                    ExperienceAPI.removeXPOffline(player.getName(), skill.asString(), quantity.asInt());
                                }
                                break;
                            }
                    }
                } else if (player != null && player.isOnline() && party != null && PartyManager.getParty(party.asString()) != null) {
                    if (PartyAPI.getPartyLeader(party.asString()).equals(player.getName())) {
                        PartyManager.disbandParty(PartyManager.getParty(party.asString()));
                    } else {
                        PartyAPI.removeFromParty(player.getPlayerEntity());
                    }
                } else if (player != null) {
                    mcMMO.getDatabaseManager().removeUser(player.getName(), player.getUUID());
                }
                break;
            }
        case SET:
            {
                if (quantity.asDouble() >= 0 && skill != null && player != null) {
                    switch(Type.valueOf(type.asString().toUpperCase())) {
                        case LEVELS:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.setLevel(player.getPlayerEntity(), skill.asString(), quantity.asInt());
                                } else {
                                    ExperienceAPI.setLevelOffline(player.getName(), skill.asString(), quantity.asInt());
                                }
                                break;
                            }
                        case XP:
                            {
                                if (player.isOnline()) {
                                    ExperienceAPI.setXP(player.getPlayerEntity(), skill.asString(), quantity.asInt());
                                } else {
                                    ExperienceAPI.setXPOffline(player.getName(), skill.asString(), quantity.asInt());
                                }
                                break;
                            }
                    }
                } else {
                    switch(Type.valueOf(type.asString().toUpperCase())) {
                        case LEADER:
                            {
                                if (party != null && PartyManager.getParty(party.asString()) != null) {
                                    PartyAPI.setPartyLeader(party.asString(), player.getName());
                                }
                                break;
                            }
                        case XPRATE:
                            {
                                if (quantity.asInt() > 0) {
                                    ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(quantity.asInt());
                                }
                                break;
                            }
                        case HARDCORE:
                            {
                                if (skill == null) {
                                    return;
                                }
                                PrimarySkillType skillType = PrimarySkillType.getSkill(skill.asString());
                                boolean isEnabled = mcMMO.p.getGeneralConfig().getHardcoreStatLossEnabled(skillType);
                                switch(State.valueOf(state.asString().toUpperCase())) {
                                    case TOGGLE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreStatLossEnabled(skillType, !isEnabled);
                                            break;
                                        }
                                    case TRUE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreStatLossEnabled(skillType, true);
                                            break;
                                        }
                                    case FALSE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreStatLossEnabled(skillType, false);
                                            break;
                                        }
                                }
                                break;
                            }
                        case VAMPIRISM:
                            {
                                if (skill == null) {
                                    return;
                                }
                                PrimarySkillType skillType = PrimarySkillType.getSkill(skill.asString());
                                boolean isEnabled = mcMMO.p.getGeneralConfig().getHardcoreVampirismEnabled(skillType);
                                switch(State.valueOf(state.asString().toUpperCase())) {
                                    case TOGGLE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreVampirismEnabled(skillType, !isEnabled);
                                            break;
                                        }
                                    case TRUE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreVampirismEnabled(skillType, true);
                                            break;
                                        }
                                    case FALSE:
                                        {
                                            mcMMO.p.getGeneralConfig().setHardcoreVampirismEnabled(skillType, false);
                                            break;
                                        }
                                }
                                break;
                            }
                    }
                }
                break;
            }
    }
}
Also used : PrimarySkillType(com.gmail.nossr50.datatypes.skills.PrimarySkillType) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 5 with SkillType

use of com.gmail.nossr50.datatypes.skills.SkillType in project TriggerReactor by wysohn.

the class McMmoSupport method removeXp.

/**
 * remove 'xp' from target player's 'skillType'
 *
 * @param player
 * @param skillType
 * @param xp
 */
public void removeXp(Player player, String skillType, int xp) {
    McMMOPlayer mmoPlayer = (McMMOPlayer) player(player.getName());
    if (mmoPlayer == null)
        throw new RuntimeException("Could not find MCMMO info for player " + player.getName());
    SkillType type = SkillType.valueOf(skillType);
    mmoPlayer.removeXp(type, xp);
}
Also used : McMMOPlayer(com.gmail.nossr50.datatypes.player.McMMOPlayer) SkillType(com.gmail.nossr50.datatypes.skills.SkillType)

Aggregations

McMMOPlayer (com.gmail.nossr50.datatypes.player.McMMOPlayer)12 SkillType (com.gmail.nossr50.datatypes.skills.SkillType)7 Player (org.bukkit.entity.Player)5 Claim (com.griefdefender.api.claim.Claim)4 PlayerData (com.griefdefender.api.data.PlayerData)4 Context (com.griefdefender.api.permission.Context)4 Location (org.bukkit.Location)4 World (org.bukkit.World)4 PrimarySkillType (com.gmail.nossr50.datatypes.skills.PrimarySkillType)3 Tristate (com.griefdefender.api.Tristate)3 HashSet (java.util.HashSet)3 EventHandler (org.bukkit.event.EventHandler)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 McMMOPlayerAbilityData (com.griefdefender.hooks.provider.mcmmo.McMMOPlayerAbilityData)1 BankerService (gg.projecteden.nexus.models.banker.BankerService)1 McMMOPrestige (gg.projecteden.nexus.models.mcmmo.McMMOPrestige)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 McRPGPlayer (us.eunoians.mcrpg.players.McRPGPlayer)1 Parser (us.eunoians.mcrpg.util.Parser)1