Search in sources :

Example 6 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project PyrCore by PYRRH4.

the class PlayerData method restore.

// ------------------------------------------------------------
// Restore the data
// ------------------------------------------------------------
public static void restore(final Player player) {
    if (Core.instance().getPlayerDataInstance().lastInventory.containsKey(player.getUniqueId())) {
        player.getInventory().setContents(Core.instance().getPlayerDataInstance().lastInventory.get(player.getUniqueId()));
    }
    if (Core.instance().getPlayerDataInstance().lastArmor.containsKey(player.getUniqueId())) {
        player.getInventory().setArmorContents(Core.instance().getPlayerDataInstance().lastArmor.get(player.getUniqueId()));
    }
    player.updateInventory();
    if (Core.instance().getPlayerDataInstance().lastScoreboard.containsKey(player.getUniqueId())) {
        Scoreboard scoreboard = Core.instance().getPlayerDataInstance().lastScoreboard.get(player.getUniqueId());
        if (scoreboard == null) {
            scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
        }
        player.setScoreboard(Core.instance().getPlayerDataInstance().lastScoreboard.get(player.getUniqueId()));
    } else {
        player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
    }
    // PotionEffects
    Utils.resetEffects(player);
    if (Core.instance().getPlayerDataInstance().lastPotionEffects.containsKey(player.getUniqueId())) {
        for (PotionEffect effect : Core.instance().getPlayerDataInstance().lastPotionEffects.get(player.getUniqueId())) player.addPotionEffect(effect);
    }
    // Other
    Utils.resetWalkSpeed(player);
    Utils.resetGameMode(player);
    Utils.showToAll(player);
    if (Core.instance().getPlayerDataInstance().allowFly.containsKey(player.getUniqueId())) {
        Utils.allowFly(player, Core.instance().getPlayerDataInstance().allowFly.get(player.getUniqueId()));
    }
    if (Core.instance().getPlayerDataInstance().gamemodes.containsKey(player.getUniqueId())) {
        player.setGameMode(Core.instance().getPlayerDataInstance().gamemodes.get(player.getUniqueId()));
    }
    Core.instance().getPlayerDataInstance().lastInventory.remove(player.getUniqueId());
    Core.instance().getPlayerDataInstance().lastArmor.remove(player.getUniqueId());
    Core.instance().getPlayerDataInstance().lastScoreboard.remove(player.getUniqueId());
    Core.instance().getPlayerDataInstance().lastPotionEffects.remove(player.getUniqueId());
    Core.instance().getPlayerDataInstance().allowFly.remove(player.getUniqueId());
    Core.instance().getPlayerDataInstance().gamemodes.remove(player.getUniqueId());
}
Also used : Scoreboard(org.bukkit.scoreboard.Scoreboard) PotionEffect(org.bukkit.potion.PotionEffect)

Example 7 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project MagicPlugin by elBukkit.

the class ScoreboardTeamProvider method isFriendly.

@Override
public boolean isFriendly(Entity attacker, Entity entity) {
    if (attacker instanceof Player && entity instanceof Player) {
        Player player1 = (Player) attacker;
        Player player2 = (Player) entity;
        Scoreboard scoreboard1 = player1.getScoreboard();
        Scoreboard scoreboard2 = player2.getScoreboard();
        if (scoreboard1 != null && scoreboard2 != null) {
            Team team1 = scoreboard1.getEntryTeam(player1.getName());
            Team team2 = scoreboard2.getEntryTeam(player2.getName());
            if (team1 != null && team2 != null && team1.equals(team2)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) Scoreboard(org.bukkit.scoreboard.Scoreboard) Team(org.bukkit.scoreboard.Team)

Example 8 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project MassiveCore by MassiveCraft.

the class BoardUtil method setObjectiveEntries.

public static boolean setObjectiveEntries(Objective objective, Map<String, Integer> entries) {
    if (entries == null)
        return false;
    boolean ret = false;
    // Add or Update
    for (Entry<String, Integer> entry : entries.entrySet()) {
        String key = entry.getKey();
        Integer value = entry.getValue();
        ret |= setObjectiveValue(objective, key, value);
    }
    // Remove
    Scoreboard board = objective.getScoreboard();
    for (String key : board.getEntries()) {
        if (entries.containsKey(key))
            continue;
        if (getObjectiveValue(objective, key) == 0)
            continue;
        board.resetScores(key);
    }
    return ret;
}
Also used : Scoreboard(org.bukkit.scoreboard.Scoreboard)

Example 9 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project MassiveCore by MassiveCraft.

the class BoardUtil method clean.

// -------------------------------------------- //
// CLEAN
// -------------------------------------------- //
public static void clean(Player player) {
    // Delete scores for temporary objectives.
    for (Objective objective : getTemporaryObjectives()) {
        setObjectiveValue(objective, player, 0);
    }
    // Delete player team if temporary and sole player.
    for (Scoreboard board : getBoards()) {
        Team team = getKeyTeam(board, player);
        if (isTeamPersistent(team))
            continue;
        if (getTeamMembers(team).size() > 1)
            continue;
        deleteTeam(team);
    }
}
Also used : Objective(org.bukkit.scoreboard.Objective) Scoreboard(org.bukkit.scoreboard.Scoreboard) Team(org.bukkit.scoreboard.Team)

Example 10 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project Citizens2 by CitizensDev.

the class HumanController method createEntity.

@Override
protected Entity createEntity(final Location at, final NPC npc) {
    final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
    String coloredName = Colorizer.parseColors(npc.getFullName());
    String name = coloredName, prefix = null, suffix = null;
    if (coloredName.length() > 16) {
        prefix = coloredName.substring(0, 16);
        if (coloredName.length() > 30) {
            int len = 30;
            name = coloredName.substring(16, 30);
            if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
                if (coloredName.length() >= 32) {
                    len = 32;
                    name = coloredName.substring(16, 32);
                } else if (coloredName.length() == 31) {
                    len = 31;
                    name = coloredName.substring(16, 31);
                }
            } else {
                name = ChatColor.RESET + name;
            }
            suffix = coloredName.substring(len);
        } else {
            name = coloredName.substring(16);
            if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
                name = ChatColor.RESET + name;
            }
            if (name.length() > 16) {
                suffix = name.substring(16);
                name = name.substring(0, 16);
            }
        }
        coloredName = coloredName.substring(0, 16);
    }
    final String prefixCapture = prefix, suffixCapture = suffix;
    UUID uuid = npc.getUniqueId();
    if (uuid.version() == 4) {
        // clear version
        long msb = uuid.getMostSignificantBits();
        msb &= ~0x0000000000004000L;
        msb |= 0x0000000000002000L;
        uuid = new UUID(msb, uuid.getLeastSignificantBits());
    }
    final GameProfile profile = new GameProfile(uuid, name);
    final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, new PlayerInteractManager(nmsWorld), npc);
    Skin skin = handle.getSkinTracker().getSkin();
    if (skin != null) {
        skin.apply(handle);
    }
    Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {

        @Override
        public void run() {
            if (getBukkitEntity() == null || !getBukkitEntity().isValid())
                return;
            boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
            NMS.addOrRemoveFromPlayerList(getBukkitEntity(), npc.data().get("removefromplayerlist", removeFromPlayerList));
            if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
                Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
                String teamName = profile.getId().toString().substring(0, 16);
                Team team = scoreboard.getTeam(teamName);
                if (team == null) {
                    team = scoreboard.registerNewTeam(teamName);
                    if (prefixCapture != null) {
                        team.setPrefix(prefixCapture);
                    }
                    if (suffixCapture != null) {
                        team.setSuffix(suffixCapture);
                    }
                }
                team.addPlayer(handle.getBukkitEntity());
                handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
            }
        }
    }, 20);
    handle.getBukkitEntity().setSleepingIgnored(true);
    return handle.getBukkitEntity();
}
Also used : WorldServer(net.minecraft.server.v1_11_R1.WorldServer) GameProfile(com.mojang.authlib.GameProfile) Scoreboard(org.bukkit.scoreboard.Scoreboard) PlayerInteractManager(net.minecraft.server.v1_11_R1.PlayerInteractManager) Skin(net.citizensnpcs.npc.skin.Skin) Team(org.bukkit.scoreboard.Team) UUID(java.util.UUID) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Aggregations

Scoreboard (org.bukkit.scoreboard.Scoreboard)39 Team (org.bukkit.scoreboard.Team)24 GameProfile (com.mojang.authlib.GameProfile)11 UUID (java.util.UUID)11 Objective (org.bukkit.scoreboard.Objective)11 Property (com.mojang.authlib.properties.Property)7 BigInteger (java.math.BigInteger)7 MessageDigest (java.security.MessageDigest)7 Player (org.bukkit.entity.Player)7 PlayerProfile (net.aufdemrand.denizen.nms.util.PlayerProfile)4 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)3 File (java.io.File)3 Skin (net.citizensnpcs.npc.skin.Skin)3 User (net.dzikoysk.funnyguilds.basic.User)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 EntityType (org.bukkit.entity.EntityType)3 PotionEffectType (org.bukkit.potion.PotionEffectType)3 PotionType (org.bukkit.potion.PotionType)3 Score (org.bukkit.scoreboard.Score)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2