use of org.bukkit.OfflinePlayer in project Prism-Bukkit by prism.
the class EntityAction method setEntity.
/**
*
* @param entity
* @param dyeUsed
*/
public void setEntity(Entity entity, String dyeUsed) {
// Build an object for the specific details of this action
actionData = new EntityActionData();
if (entity != null && entity.getType() != null && entity.getType().name() != null) {
this.actionData.entity_name = entity.getType().name().toLowerCase();
this.world_name = entity.getWorld().getName();
this.x = entity.getLocation().getBlockX();
this.y = entity.getLocation().getBlockY();
this.z = entity.getLocation().getBlockZ();
// Get custom name
if (entity instanceof LivingEntity) {
this.actionData.custom_name = ((LivingEntity) entity).getCustomName();
}
// Get animal age
if (entity instanceof Ageable && !(entity instanceof Monster)) {
final Ageable a = (Ageable) entity;
this.actionData.isAdult = a.isAdult();
} else {
this.actionData.isAdult = true;
}
// Get current sheep color
if (entity instanceof Sheep) {
final Sheep sheep = ((Sheep) entity);
this.actionData.color = sheep.getColor().name().toLowerCase();
}
// Get color it will become
if (dyeUsed != null) {
this.actionData.newColor = dyeUsed;
}
// Get villager type
if (entity instanceof Villager) {
final Villager v = (Villager) entity;
if (v.getProfession() != null) {
this.actionData.profession = v.getProfession().toString().toLowerCase();
}
}
// Wolf details
if (entity instanceof Wolf) {
final Wolf wolf = (Wolf) entity;
// Owner
if (wolf.isTamed()) {
if (wolf.getOwner() instanceof Player) {
this.actionData.taming_owner = wolf.getOwner().getName();
}
if (wolf.getOwner() instanceof OfflinePlayer) {
this.actionData.taming_owner = wolf.getOwner().getName();
}
}
// Collar color
this.actionData.color = wolf.getCollarColor().name().toLowerCase();
// Sitting
if (wolf.isSitting()) {
this.actionData.sitting = true;
}
}
// Ocelot details
if (entity instanceof Ocelot) {
final Ocelot ocelot = (Ocelot) entity;
// Owner
if (ocelot.isTamed()) {
if (ocelot.getOwner() instanceof Player) {
this.actionData.taming_owner = ocelot.getOwner().getName();
}
if (ocelot.getOwner() instanceof OfflinePlayer) {
this.actionData.taming_owner = ocelot.getOwner().getName();
}
}
// Cat type
this.actionData.var = ocelot.getCatType().toString().toLowerCase();
// Sitting
if (ocelot.isSitting()) {
this.actionData.sitting = true;
}
}
// Horse details
if (entity instanceof Horse) {
final Horse h = (Horse) entity;
this.actionData.var = h.getVariant().toString();
this.actionData.hColor = h.getColor().toString();
this.actionData.style = h.getStyle().toString();
this.actionData.chest = h.isCarryingChest();
this.actionData.dom = h.getDomestication();
this.actionData.maxDom = h.getMaxDomestication();
this.actionData.jump = h.getJumpStrength();
this.actionData.maxHealth = h.getMaxHealth();
final HorseInventory hi = h.getInventory();
if (hi.getSaddle() != null) {
this.actionData.saddle = "" + hi.getSaddle().getTypeId();
}
if (hi.getArmor() != null) {
this.actionData.armor = "" + hi.getArmor().getTypeId();
}
// Owner
if (h.isTamed()) {
if (h.getOwner() instanceof Player) {
this.actionData.taming_owner = h.getOwner().getName();
}
if (h.getOwner() instanceof OfflinePlayer) {
this.actionData.taming_owner = h.getOwner().getName();
}
}
}
}
}
use of org.bukkit.OfflinePlayer in project Denizen-For-Bukkit by DenizenScript.
the class ScoreboardHelper method _recallScoreboards.
/*
* Called on server startup or /denizen reload saves
*/
public static void _recallScoreboards() {
// Clear every existing ingame scoreboard
for (Map.Entry<String, Scoreboard> entry : scoreboardMap.entrySet()) {
clearScoreboard(entry.getValue());
}
Scoreboard emptyBoard = createScoreboard();
// Clear every viewer's set scoreboard
for (Map.Entry<String, String> entry : viewerMap.entrySet()) {
OfflinePlayer player = ScoreboardCommand.getOfflinePlayer(entry.getKey());
if (player.isOnline()) {
player.getPlayer().setScoreboard(emptyBoard);
}
}
// Delete the contents of the scoreboardMap and viewerMap
scoreboardMap.clear();
viewerMap.clear();
ConfigurationSection rootSection = DenizenAPI.getCurrentInstance().getScoreboards().getConfigurationSection("Scoreboards");
// Go no further if we have no scoreboards saved
if (rootSection == null) {
return;
}
Scoreboard board = null;
// Iterate through scoreboards
for (String id : rootSection.getKeys(false)) {
// Create a scoreboard with this id
board = createScoreboard(id);
// Get the list of viewers
List<String> viewerList = rootSection.getStringList(id + ".Viewers");
// and make them see this scoreboard if they are online
for (String viewer : viewerList) {
if (dPlayer.matches(viewer)) {
dPlayer player = dPlayer.valueOf(viewer);
viewerMap.put(player.getName(), id);
if (player.isOnline()) {
player.getPlayerEntity().setScoreboard(board);
}
}
}
ConfigurationSection objSection = rootSection.getConfigurationSection(id + ".Objectives");
// Go no further if we have no objectives saved
if (objSection == null) {
return;
}
// Iterate through objectives
for (String obj : objSection.getKeys(false)) {
// Get display slot and criteria for this objective
String displaySlot = objSection.getString(obj + ".Display slot");
String criteria = objSection.getString(obj + ".Criteria");
// Use default criteria if necessary
if (criteria == null) {
criteria = "dummy";
}
// Use default display slot if necessary
if (displaySlot == null) {
displaySlot = "NONE";
}
// Register the objective and set it up
Objective o = board.registerNewObjective(obj, criteria);
o.setDisplayName(obj);
// Only set display slot if it's valid
if (aH.Argument.valueOf(displaySlot).matchesEnum(DisplaySlot.values())) {
o.setDisplaySlot(DisplaySlot.valueOf(displaySlot.toUpperCase()));
}
ConfigurationSection scoreSection = objSection.getConfigurationSection(obj + ".Scores");
if (scoreSection != null) {
// Iterate through scores and add them to this objective
for (String scoreName : scoreSection.getKeys(false)) {
int scoreInt = scoreSection.getInt(scoreName);
addScore(o, ScoreboardCommand.getOfflinePlayer(scoreName), scoreInt);
}
}
}
}
}
use of org.bukkit.OfflinePlayer in project Bukkit by Bukkit.
the class DeopCommand method execute.
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender))
return true;
if (args.length != 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
player.setOp(false);
if (player instanceof Player) {
((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
}
Command.broadcastCommandMessage(sender, "De-opped " + args[0]);
return true;
}
use of org.bukkit.OfflinePlayer in project Denizen-For-Bukkit by DenizenScript.
the class GroupCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
dWorld world = (dWorld) scriptEntry.getObject("world");
Element group = scriptEntry.getElement("group");
// Report to dB
dB.report(scriptEntry, getName(), action.debug() + (world != null ? world.debug() : "") + group.debug());
World bukkitWorld = null;
if (world != null) {
bukkitWorld = world.getWorld();
}
OfflinePlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer();
boolean inGroup = Depends.permissions.playerInGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
switch(Action.valueOf(action.asString().toUpperCase())) {
case ADD:
if (inGroup) {
dB.echoDebug(scriptEntry, "Player " + player.getName() + " is already in group " + group);
} else {
Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
}
return;
case REMOVE:
if (!inGroup) {
dB.echoDebug(scriptEntry, "Player " + player.getName() + " is not in group " + group);
} else {
Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
}
return;
case SET:
for (String grp : Depends.permissions.getPlayerGroups((bukkitWorld == null ? null : bukkitWorld.getName()), player)) {
Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, grp);
}
Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
}
}
use of org.bukkit.OfflinePlayer in project Jobs by GamingMesh.
the class JobsCommands method demote.
@JobCommand
public boolean demote(CommandSender sender, String[] args) {
if (args.length < 3) {
sendUsage(sender, "demote");
return true;
}
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
return true;
}
try {
// check if player already has the job
if (jPlayer.isInJob(job)) {
Integer levelsLost = Integer.parseInt(args[2]);
Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
if (player != null) {
String message = Language.getMessage("command.demote.output.target");
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
message = message.replace("%levelslost%", Integer.valueOf(levelsLost).toString());
player.sendMessage(message);
}
sender.sendMessage(Language.getMessage("command.admin.success"));
}
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
}
return true;
}
Aggregations