From eb3efac2d45dfdd4fa806208013be74eb3517179 Mon Sep 17 00:00:00 2001 From: Jeremy Schroeder Date: Sat, 19 Oct 2013 20:17:26 -0400 Subject: [PATCH] Add dPlayer mechanisms --- .../aufdemrand/denizen/objects/dEntity.java | 12 +- .../aufdemrand/denizen/objects/dPlayer.java | 105 +++++++++++++++++- 2 files changed, 106 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java index f145d3dd16..4022bca6cc 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java @@ -1769,22 +1769,22 @@ public void adjust(Mechanism mechanism, Element value) { return; } - if (mechanism.matches("set_remove_when_far_away")) + if (mechanism.matches("remove_when_far_away")) getLivingEntity().setRemoveWhenFarAway(value.asBoolean()); - if (mechanism.matches("set_custom_name")) + if (mechanism.matches("custom_name")) getLivingEntity().setCustomName(value.asString()); - if (mechanism.matches("set_custom_name_visibility")) + if (mechanism.matches("custom_name_visibility")) getLivingEntity().setCustomNameVisible(value.asBoolean()); - if (mechanism.matches("set_can_pickup_items")) + if (mechanism.matches("can_pickup_items")) getLivingEntity().setCanPickupItems(value.asBoolean()); - if (mechanism.matches("set_leash_holder")) + if (mechanism.matches("leash_holder")) getLivingEntity().setLeashHolder(dEntity.valueOf(value.asString()).getBukkitEntity()); - if (mechanism.matches("set_remaining_air")) + if (mechanism.matches("remaining_air")) getLivingEntity().setRemainingAir(value.asInt()); diff --git a/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java b/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java index f749fb7bd3..7e1f2652bb 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java @@ -12,13 +12,10 @@ import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.entity.Player; -public class dPlayer implements dObject { +public class dPlayer implements dObject, Adjustable { ///////////////////// @@ -968,4 +965,102 @@ else if (getPlayerEntity().getFoodLevel() / maxHunger < 1) return new dEntity(getPlayerEntity()).getAttribute(attribute); } + + @Override + public void adjust(Mechanism mechanism, Element value) { + + + // <--[mechanism] + // @object dPlayer + // @name level + // @input Element(Integer) + // @description + // Sets the level on the player. Does not affect the current progression + // of experience towards next level. + // @tags + // + // --> + if (mechanism.matches("level")) { + getPlayerEntity().setLevel(value.asInt()); + return; + } + + if (mechanism.matches("award_achievement")) { + getPlayerEntity().awardAchievement(Achievement.valueOf(value.asString().toUpperCase())); + return; + } + + if (mechanism.matches("health_scale")) { + getPlayerEntity().setHealthScale(value.asDouble()); + return; + } + + if (mechanism.matches("scale_health")) { + getPlayerEntity().setHealthScaled(value.asBoolean()); + return; + } + + if (mechanism.matches("texture_pack")) { + getPlayerEntity().setTexturePack(value.asString()); + return; + } + + if (mechanism.matches("saturation")) { + getPlayerEntity().setSaturation(value.asFloat()); + return; + } + + if (mechanism.matches("bed_spawn_location")) { + getPlayerEntity().setBedSpawnLocation(dLocation.valueOf(value.asString())); + return; + } + + if (mechanism.matches("fly_speed")) { + getPlayerEntity().setFlySpeed(value.asFloat()); + return; + } + + if (mechanism.matches("weather")) { + getPlayerEntity().setPlayerWeather(WeatherType.valueOf(value.asString().toUpperCase())); + return; + } + + if (mechanism.matches("reset_weather")) { + getPlayerEntity().resetPlayerWeather(); + return; + } + + if (mechanism.matches("player_list_name")) { + getPlayerEntity().setPlayerListName(value.asString()); + return; + } + + if (mechanism.matches("time")) { + getPlayerEntity().setPlayerTime(value.asInt(), true); + return; + } + + if (mechanism.matches("freeze_time")) { + if (value == null) + getPlayerEntity().setPlayerTime(getPlayerEntity().getWorld().getTime(), false); + else + getPlayerEntity().setPlayerTime(value.asInt(), false); + return; + } + + if (mechanism.matches("reset_time")) { + getPlayerEntity().resetPlayerTime(); + return; + } + + if (mechanism.matches("walk_speed")) { + getPlayerEntity().setWalkSpeed(value.asFloat()); + return; + } + + // Pass along to dEntity mechanism handler if not already handled. + Adjustable entity = new dEntity(getPlayerEntity()); + entity.adjust(mechanism, value); + + } }