Java Code Examples for org.bukkit.entity.Player#getScoreboard()

The following examples show how to use org.bukkit.entity.Player#getScoreboard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerData.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public PlayerData(final Player p) {
  	if (SkyWarsReloaded.getCfg().debugEnabled()) {
      	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Creating " + p.getName() + "'s Datafile");
  	}
  	this.beingRestored = false;
      this.uuid = p.getUniqueId();
      this.sb = p.getScoreboard();
      this.health = p.getHealth();
      this.food = p.getFoodLevel();
      this.sat = p.getSaturation();
if (!SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
	xp = p.getExp();
}
      inv = Bukkit.createInventory(null, InventoryType.PLAYER, p.getName());
      inv.setContents(p.getInventory().getContents());
  	if (SkyWarsReloaded.getCfg().debugEnabled()) {
  		Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + p.getName() + "'s Datafile has been created");
  	}
  }
 
Example 2
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles cleaning push protection on player quit
 * @param player
 */
private void removePush(Player player)
{
    try {
        scoreboard = player.getScoreboard();
        if(scoreboard !=null)
        {
            //Player Remove
            Team pTeam = scoreboard.getTeam(NO_PUSH_TEAM_NAME);
            if (pTeam != null) {
                pTeam.removeEntry(player.getName());
            }
        }
    } catch (Exception e) {
        plugin.getLogger().severe("Error trying to remove player from push scoreboard");
        plugin.getLogger().severe(player.getName() + " : " + e.getMessage());
        e.printStackTrace();
    }
}
 
Example 3
Source File: AssembleBoard.java    From Assemble with GNU General Public License v3.0 5 votes vote down vote up
public Scoreboard getScoreboard() {
	Player player = Bukkit.getPlayer(getUuid());
	if (getAssemble().isHook() || player.getScoreboard() != Bukkit.getScoreboardManager().getMainScoreboard()) {
		return player.getScoreboard();
	} else {
		return Bukkit.getScoreboardManager().getNewScoreboard();
	}
}
 
Example 4
Source File: TagUtils.java    From TabooLib with MIT License 5 votes vote down vote up
public static Scoreboard getScoreboardComputeIfAbsent(Player player) {
    Scoreboard scoreboard = player.getScoreboard();
    if (scoreboard == null) {
        player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
    }
    return player.getScoreboard();
}
 
Example 5
Source File: BPlayerBoard.java    From Netherboard with Apache License 2.0 5 votes vote down vote up
public BPlayerBoard(Player player, Scoreboard scoreboard, String name) {
    this.player = player;
    this.scoreboard = scoreboard;

    if(this.scoreboard == null) {
        Scoreboard sb = player.getScoreboard();

        if(sb == null || sb == Bukkit.getScoreboardManager().getMainScoreboard())
            sb = Bukkit.getScoreboardManager().getNewScoreboard();

        this.scoreboard = sb;
    }

    this.name = name;

    String subName = player.getName().length() <= 14
            ? player.getName()
            : player.getName().substring(0, 14);

    this.objective = this.scoreboard.getObjective("sb" + subName);
    this.buffer = this.scoreboard.getObjective("bf" + subName);

    if(this.objective == null)
        this.objective = this.scoreboard.registerNewObjective("sb" + subName, "dummy");
    if(this.buffer == null)
        this.buffer = this.scoreboard.registerNewObjective("bf" + subName, "dummy");

    this.objective.setDisplayName(name);
    sendObjective(this.objective, ObjectiveMode.CREATE);
    sendObjectiveDisplay(this.objective);

    this.buffer.setDisplayName(name);
    sendObjective(this.buffer, ObjectiveMode.CREATE);

    this.player.setScoreboard(this.scoreboard);
}
 
Example 6
Source File: ScoreBoardManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private void enableScoreboard(Player player) {
    if(isDisabledGlobally()) return;
    if(isDisabled(player)) return;
    
    UUID uuid = player.getUniqueId();
    if(shouldSavePrevious() && !this.previousScoreboardMap.containsKey(uuid)) {
        Scoreboard previousScoreboard = player.getScoreboard();
        Objective objective = previousScoreboard.getObjective("combatlogx");
        if(objective == null) this.previousScoreboardMap.put(uuid, previousScoreboard);
    }
    
    CustomScoreBoard customScoreBoard = this.customScoreBoardMap.getOrDefault(uuid, new CustomScoreBoard(this.expansion, player));
    this.customScoreBoardMap.put(uuid, customScoreBoard);
    customScoreBoard.enableScoreboard();
}
 
Example 7
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles push protection
 * @param player
 */
public void setPush(Player player) {
    scoreboard = player.getScoreboard();
    if (scoreboard == null) {
        //plugin.getLogger().info("1.9 " +"DEBUG: initializing scoreboard");
        scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    }
    if (Settings.allowPushing) {
        if (scoreboard.getTeam(NO_PUSH_TEAM_NAME) != null) {
            //plugin.getLogger().info("1.9 " +"DEBUG: unregistering the team");
            scoreboard.getTeam(NO_PUSH_TEAM_NAME).unregister();
        }
        return;
    }
    // Try and get what team the player is on right now
    Team pushTeam = scoreboard.getEntryTeam(player.getName());
    if (pushTeam == null) {
        // It doesn't exist yet, so make it
        pushTeam = scoreboard.getTeam(NO_PUSH_TEAM_NAME);
        if (pushTeam == null) {
            pushTeam = scoreboard.registerNewTeam(NO_PUSH_TEAM_NAME);
        }
        // Add the player to the team
        pushTeam.addEntry(player.getName()); 
    }
    if (pushTeam.getName().equals(NO_PUSH_TEAM_NAME)) {
        //plugin.getLogger().info("1.9 " +"DEBUG: pushing not allowed");
        pushTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);               
    } else {
        //plugin.getLogger().info("1.9 " +"DEBUG: player is already in another team");
    }
}
 
Example 8
Source File: ScoreComponent.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getValue(String locale) {
	String value = forcedvalue;
	if (value == null) {
		Player player = Bukkit.getPlayerExact(playername);
		if (player != null) {
			Scoreboard board = player.getScoreboard();
			Objective objective = board.getObjective(objectivename);
			if (objective != null) {
				value = String.valueOf(objective.getScore(playername).getScore());
			}
		}
	}
	return value != null ? value : "";
}
 
Example 9
Source File: CloudServer.java    From CloudNet with Apache License 2.0 4 votes vote down vote up
private void initScoreboard(Player all) {
    if (all.getScoreboard() == null) {
        all.setScoreboard(all.getServer().getScoreboardManager().getNewScoreboard());
    }
}
 
Example 10
Source File: Scoreboards.java    From TabooLib with MIT License 4 votes vote down vote up
public static Scoreboard display(Player p, String... elements) {
    elements = fixLines(elements);
    try {
        if (p.getScoreboard() == null || p.getScoreboard() == Bukkit.getScoreboardManager().getMainScoreboard() || p.getScoreboard().getObjectives().size() != 1) {
            p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
        }
        if (p.getScoreboard().getObjective(p.getUniqueId().toString().substring(0, 16)) == null) {
            p.getScoreboard().registerNewObjective(p.getUniqueId().toString().substring(0, 16), "dummy");
            p.getScoreboard().getObjective(p.getUniqueId().toString().substring(0, 16)).setDisplaySlot(DisplaySlot.SIDEBAR);
        }
        p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).setDisplayName(elements[0]);
        for (int i = 1; i < elements.length; i++) {
            if (elements[i] != null) {
                if (p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).getScore() != 16 - i) {
                    p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).setScore(16 - i);
                    for (String string : p.getScoreboard().getEntries()) {
                        if (p.getScoreboard().getObjective(p.getUniqueId().toString().substring(0, 16)).getScore(string).getScore() == 16 - i) {
                            if (!string.equals(elements[i])) {
                                p.getScoreboard().resetScores(string);
                            }
                        }
                    }
                }
            }
        }
        for (String entry : p.getScoreboard().getEntries()) {
            boolean toErase = true;
            for (String element : elements) {
                if (element != null && element.equals(entry) && p.getScoreboard().getObjective(p.getUniqueId().toString().substring(0, 16)).getScore(entry).getScore() == 16 - Arrays.asList(elements).indexOf(element)) {
                    toErase = false;
                    break;
                }
            }
            if (toErase) {
                p.getScoreboard().resetScores(entry);
            }
        }
        return p.getScoreboard();
    } catch (Exception e) {
        return null;
    }
}
 
Example 11
Source File: Scoreboards.java    From TabooLib with MIT License 4 votes vote down vote up
public static boolean display(Collection<Player> players, org.bukkit.scoreboard.Scoreboard board, String... elements) {
    try {
        String objName = "COLLAB-SB-WINTER";
        if (board == null) {
            board = Bukkit.getScoreboardManager().getNewScoreboard();
        }
        elements = fixLines(elements);
        for (Player player : players) {
            if (player.getScoreboard() != board) {
                player.setScoreboard(board);
            }
        }
        if (board.getObjective(objName) == null) {
            board.registerNewObjective(objName, "dummy");
            board.getObjective(objName).setDisplaySlot(DisplaySlot.SIDEBAR);
        }
        board.getObjective(DisplaySlot.SIDEBAR).setDisplayName(elements[0]);
        for (int i = 1; i < elements.length; i++) {
            if (elements[i] != null && board.getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).getScore() != 16 - i) {
                board.getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).setScore(16 - i);
                for (String string : board.getEntries()) {
                    if (board.getObjective(objName).getScore(string).getScore() == 16 - i) {
                        if (!string.equals(elements[i])) {
                            board.resetScores(string);
                        }
                    }
                }
            }
        }
        for (String entry : board.getEntries()) {
            boolean toErase = true;
            for (String element : elements) {
                if (element != null && element.equals(entry) && board.getObjective(objName).getScore(entry).getScore() == 16 - Arrays.asList(elements).indexOf(element)) {
                    toErase = false;
                    break;
                }
            }
            if (toErase) {
                board.resetScores(entry);
            }
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 12
Source File: LoginListener.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
	Player player = event.getPlayer();

	//adding player
	plugin.getPlayerManager().addIfNotExists(player);

	final NovaPlayer nPlayer = PlayerManager.getPlayer(player);

	//Send version message if there's an update
	if(VersionUtils.isUpdateAvailable() && Permission.NOVAGUILDS_ADMIN_UPDATEAVAILABLE.has(player)) {
		Message.CHAT_UPDATE.send(player);
	}

	//Schedule region check
	NovaGuilds.runTask(new Runnable() {
		@Override
		public void run() {
			plugin.getRegionManager().checkAtRegionChange(nPlayer);
		}
	});

	if(nPlayer.hasGuild()) {
		for(Player onlinePlayer : CompatibilityUtils.getOnlinePlayers()) {
			NovaPlayer onlineNPlayer = PlayerManager.getPlayer(onlinePlayer);

			if(onlineNPlayer.equals(nPlayer) || !onlineNPlayer.isAtRegion() || !onlineNPlayer.getAtRegion().getGuild().equals(nPlayer.getGuild())) {
				continue;
			}

			plugin.getRegionManager().checkRaidInit(onlineNPlayer);
		}

		//Show bank hologram
		nPlayer.getGuild().showVaultHologram(player);
	}

	//TabAPI
	if(Config.TAGAPI_ENABLED.getBoolean()) {
		if(player.getScoreboard() == null
				|| player.getScoreboard() == Bukkit.getScoreboardManager().getMainScoreboard()) {
			player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
		}

		TagUtils.refresh();
	}

	//PacketExtension
	if(plugin.getPacketExtension() != null) {
		plugin.getPacketExtension().registerPlayer(player);
	}

	//Tab
	if(Config.TABLIST_ENABLED.getBoolean()) {
		nPlayer.setTabList(plugin.createTabList(nPlayer));
		TabUtils.refresh(nPlayer);
	}

	//Guild inactive time
	if(nPlayer.hasGuild()) {
		nPlayer.getGuild().updateInactiveTime();
	}

	BossBarUtils.removeBar(player);
}
 
Example 13
Source File: TagUtils.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Refreshes tag of a player
 *
 * @param p target player
 */
@SuppressWarnings("deprecation")
public static void refresh(Player p) {
	if(!Config.TAGAPI_ENABLED.getBoolean()) {
		return;
	}

	Scoreboard board = p.getScoreboard();
	for(Player player : CompatibilityUtils.getOnlinePlayers()) {
		NovaPlayer nPlayerLoop = PlayerManager.getPlayer(player);

		String tName = "ng_" + player.getName();
		if(tName.length() > 16) {
			tName = tName.substring(0, 16);
		}

		Team team = board.getTeam(tName);

		if(team == null) {
			team = board.registerNewTeam(tName);
			team.addPlayer(player);
		}

		//Points
		Objective pointsObjective = board.getObjective("points");
		if(Config.POINTSBELOWNAME.getBoolean()) {
			if(pointsObjective == null) {
				pointsObjective = board.registerNewObjective("points", "dummy");
				pointsObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
				pointsObjective.setDisplayName(Message.MISC_POINTSBELOWNAME.get());
			}

			Score score = pointsObjective.getScore(player);
			score.setScore(nPlayerLoop.getPoints());
		}
		else if(pointsObjective != null) {
			pointsObjective.unregister();
		}

		//set tag
		PreparedTag tag = new PreparedTagScoreboardImpl(PlayerManager.getPlayer(player));
		tag.setTagColorFor(PlayerManager.getPlayer(p));
		team.setPrefix(tag.get());
	}
}
 
Example 14
Source File: PlayerStateHolder.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public void apply(Player player, boolean teleport) {
	PlayerInventory playerInv = player.getInventory();
	boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0;
       boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE;

       ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE];
       System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length);

       if (!is1_9 || isSimpleSize) {
           ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE];
           System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length);
           playerInv.setArmorContents(armorContents);
       }
	
	playerInv.setContents(inventoryContents);

	player.setItemOnCursor(null);
	Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor);
	for (ItemStack stack : exceeded.values()) {
           if (stack.getType() == Material.AIR) {
               continue;
           }
           
		player.getWorld().dropItem(player.getLocation(), stack);
	}
	
	player.updateInventory();

       player.setMaxHealth(maxHealth);
	player.setHealth(health);
	player.setFoodLevel(foodLevel);
	player.setLevel(level);
	player.setExp(experience);
	player.setAllowFlight(allowFlight);
	player.setFlying(isFlying);
	
	/* Remove current potion effects */
	Collection<PotionEffect> effects = player.getActivePotionEffects();
	for (PotionEffect effect : effects) {
		player.removePotionEffect(effect.getType());
	}
	player.addPotionEffects(activeEffects);
	
	player.setExhaustion(exhaustion);
	player.setSaturation(saturation);
	player.setFallDistance(fallDistance);
	player.setFireTicks(fireTicks);
	
	if (scoreboard != player.getScoreboard()) {
		Scoreboard showBoard = scoreboard;
		if (scoreboard == null) {
			showBoard = Bukkit.getScoreboardManager().getMainScoreboard();
		}
		
		player.setScoreboard(showBoard);
	}
	
	if (teleport) {
		player.teleport(location);
	}
	
	Location compassTarget = this.compassTarget;
	
	if (compassTarget == null) {
		compassTarget = player.getWorld().getSpawnLocation();
	}
	
	player.setCompassTarget(compassTarget);
	
	for (WeakReference<Player> ref : cantSee) {
		Player cantSeePlayer = ref.get();
		
		if (cantSeePlayer == null) {
			// Player object has been garbage-collected
			continue;
		}
		
		if (!cantSeePlayer.isOnline()) {
			continue;
		}
		
		player.hidePlayer(cantSeePlayer);
	}
	
	player.setGameMode(gamemode);
}