Skip to content

Commit

Permalink
Add dPlayer mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Oct 20, 2013
1 parent 540aab1 commit eb3efac
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -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());


Expand Down
105 changes: 100 additions & 5 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -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 {


/////////////////////
Expand Down Expand Up @@ -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
// <player.xp.level>
// -->
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);

}
}

0 comments on commit eb3efac

Please sign in to comment.