use of net.aufdemrand.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class dLocation method adjust.
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
// -->
if (mechanism.matches("block_type") && mechanism.requireObject(dMaterial.class)) {
dMaterial mat = value.asType(dMaterial.class);
byte data = mat.hasData() ? mat.getData() : 0;
getBlock().setTypeIdAndData(mat.getMaterial().getId(), data, false);
}
// -->
if (mechanism.matches("biome") && mechanism.requireObject(dBiome.class)) {
value.asType(dBiome.class).getBiome().changeBlockBiome(this);
}
// -->
if (mechanism.matches("spawner_type") && mechanism.requireObject(dEntity.class) && getBlock().getState() instanceof CreatureSpawner) {
((CreatureSpawner) getBlock().getState()).setSpawnedType(value.asType(dEntity.class).getBukkitEntityType());
}
// -->
if (mechanism.matches("sign_contents") && getBlock().getState() instanceof Sign) {
Sign state = (Sign) getBlock().getState();
for (int i = 0; i < 4; i++) {
state.setLine(i, "");
}
dList list = value.asType(dList.class);
if (list.size() > 4) {
dB.echoError("Sign can only hold four lines!");
} else {
for (int i = 0; i < list.size(); i++) {
state.setLine(i, EscapeTags.unEscape(list.get(i)));
}
}
state.update();
}
// -->
if (mechanism.matches("skull_skin")) {
final BlockState blockState = getBlock().getState();
if (blockState instanceof Skull) {
dList list = mechanism.getValue().asType(dList.class);
String idString = list.get(0);
PlayerProfile profile;
if (idString.contains("-")) {
UUID uuid = UUID.fromString(idString);
profile = new PlayerProfile(null, uuid, null);
} else {
profile = new PlayerProfile(idString, null, null);
}
profile = NMSHandler.getInstance().fillPlayerProfile(profile);
NMSHandler.getInstance().getBlockHelper().setPlayerProfile((Skull) blockState, profile);
}
}
// -->
if (mechanism.matches("command_block_name")) {
if (getBlock().getType() == Material.COMMAND) {
CommandBlock block = ((CommandBlock) getBlock().getState());
block.setName(value.asString());
block.update();
}
}
// -->
if (mechanism.matches("command_block")) {
if (getBlock().getType() == Material.COMMAND) {
CommandBlock block = ((CommandBlock) getBlock().getState());
block.setCommand(value.asString());
block.update();
}
}
// -->
if (mechanism.matches("furnace_burn_time")) {
Material material = getBlock().getType();
if (material == Material.FURNACE || material == Material.BURNING_FURNACE) {
Furnace furnace = (Furnace) getBlock().getState();
furnace.setBurnTime((short) value.asInt());
}
}
// -->
if (mechanism.matches("furnace_cook_time")) {
Material material = getBlock().getType();
if (material == Material.FURNACE || material == Material.BURNING_FURNACE) {
Furnace furnace = (Furnace) getBlock().getState();
furnace.setCookTime((short) value.asInt());
}
}
// -->
if (mechanism.matches("base_color")) {
Banner banner = (Banner) getBlock().getState();
banner.setBaseColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
banner.update();
}
// -->
if (mechanism.matches("patterns")) {
List<org.bukkit.block.banner.Pattern> patterns = new ArrayList<org.bukkit.block.banner.Pattern>();
dList list = mechanism.getValue().asType(dList.class);
List<String> split;
for (String string : list) {
try {
split = CoreUtilities.split(string, '/', 2);
patterns.add(new org.bukkit.block.banner.Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
} catch (Exception e) {
dB.echoError("Could not apply pattern to banner: " + string);
}
}
Banner banner = (Banner) getBlock().getState();
banner.setPatterns(patterns);
banner.update();
}
// -->
if (mechanism.matches("head_rotation") && mechanism.requireInteger()) {
((Skull) getBlock().getState()).setRotation(getSkullBlockFace(value.asInt() - 1));
}
// -->
if (mechanism.matches("data") && mechanism.hasValue()) {
getBlock().setData((byte) value.asInt());
}
if (!mechanism.fulfilled()) {
mechanism.reportInvalid();
}
}
use of net.aufdemrand.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelper_v1_11_R1 method getPlayerProfile.
@Override
public PlayerProfile getPlayerProfile(Skull skull) {
GameProfile profile = ((CraftSkull) skull).getTileEntity().getGameProfile();
if (profile == null) {
return null;
}
String name = profile.getName();
UUID id = profile.getId();
com.mojang.authlib.properties.Property property = Iterables.getFirst(profile.getProperties().get("textures"), null);
return new PlayerProfile(name, id, property != null ? property.getValue() : null);
}
use of net.aufdemrand.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class CustomEntityHelper_v1_11_R1 method spawnFakePlayer.
@Override
public FakePlayer spawnFakePlayer(Location location, String name, String skin) throws IllegalArgumentException {
String fullName = name;
String prefix = null;
String suffix = null;
if (name == null) {
return null;
} else if (fullName.length() > 16) {
prefix = fullName.substring(0, 16);
if (fullName.length() > 30) {
int len = 30;
name = fullName.substring(16, 30);
if (name.matches(".*[^A-Za-z0-9_].*")) {
if (fullName.length() >= 32) {
len = 32;
name = fullName.substring(16, 32);
} else if (fullName.length() == 31) {
len = 31;
name = fullName.substring(16, 31);
}
} else if (name.length() > 46) {
throw new IllegalArgumentException("You must specify a name with no more than 46 characters for FAKE_PLAYER entities!");
} else {
name = ChatColor.RESET + name;
}
suffix = fullName.substring(len);
} else {
name = fullName.substring(16);
if (!name.matches(".*[^A-Za-z0-9_].*")) {
name = ChatColor.RESET + name;
}
if (name.length() > 16) {
suffix = name.substring(16);
name = name.substring(0, 16);
}
}
}
if (skin != null && skin.length() > 16) {
throw new IllegalArgumentException("You must specify a name with no more than 16 characters for FAKE_PLAYER entity skins!");
}
CraftWorld world = (CraftWorld) location.getWorld();
WorldServer worldServer = world.getHandle();
PlayerProfile playerProfile = new PlayerProfile(name, null);
if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
playerProfile = NMSHandler.getInstance().fillPlayerProfile(playerProfile);
}
if (skin != null) {
PlayerProfile skinProfile = new PlayerProfile(skin, null);
skinProfile = NMSHandler.getInstance().fillPlayerProfile(skinProfile);
playerProfile.setTexture(skinProfile.getTexture());
playerProfile.setTextureSignature(skinProfile.getTextureSignature());
}
UUID uuid = UUID.randomUUID();
if (uuid.version() == 4) {
long msb = uuid.getMostSignificantBits();
msb &= ~0x0000000000004000L;
msb |= 0x0000000000002000L;
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
playerProfile.setUniqueId(uuid);
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
final EntityFakePlayer_v1_11_R1 fakePlayer = new EntityFakePlayer_v1_11_R1(worldServer.getMinecraftServer(), worldServer, gameProfile, new PlayerInteractManager(worldServer));
fakePlayer.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
CraftFakePlayer_v1_11_R1 craftFakePlayer = fakePlayer.getBukkitEntity();
craftFakePlayer.fullName = fullName;
if (prefix != null) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
String hash = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = teamName.getBytes("UTF-8");
md.update(bytes, 0, bytes.length);
hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
} catch (Exception e) {
e.printStackTrace();
}
if (hash != null) {
Team team = scoreboard.getTeam(hash);
if (team == null) {
team = scoreboard.registerNewTeam(hash);
team.setPrefix(prefix);
if (suffix != null) {
team.setSuffix(suffix);
}
}
team.addPlayer(craftFakePlayer);
}
}
return craftFakePlayer;
}
use of net.aufdemrand.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class Handler_v1_8_R3 method fillPlayerProfile.
@Override
public PlayerProfile fillPlayerProfile(PlayerProfile playerProfile) {
try {
if (playerProfile != null) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
gameProfile.getProperties().get("textures").clear();
if (playerProfile.getTextureSignature() != null) {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
} else {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
}
MinecraftServer minecraftServer = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile gameProfile1 = null;
if (gameProfile.getId() != null) {
gameProfile1 = minecraftServer.getUserCache().a(gameProfile.getId());
}
if (gameProfile1 == null && gameProfile.getName() != null) {
gameProfile1 = minecraftServer.getUserCache().getProfile(gameProfile.getName());
}
if (gameProfile1 == null) {
gameProfile1 = gameProfile;
}
if (playerProfile.hasTexture()) {
gameProfile1.getProperties().get("textures").clear();
if (playerProfile.getTextureSignature() != null) {
gameProfile1.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
} else {
gameProfile1.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
}
}
if (Iterables.getFirst(gameProfile1.getProperties().get("textures"), null) == null) {
gameProfile1 = minecraftServer.aD().fillProfileProperties(gameProfile1, true);
}
Property property = Iterables.getFirst(gameProfile1.getProperties().get("textures"), null);
return new PlayerProfile(gameProfile1.getName(), gameProfile1.getId(), property != null ? property.getValue() : null, property != null ? property.getSignature() : null);
}
} catch (Exception e) {
if (dB.verbose) {
dB.echoError(e);
}
}
return null;
}
use of net.aufdemrand.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class CustomEntityHelper_v1_8_R3 method spawnFakePlayer.
@Override
public FakePlayer spawnFakePlayer(Location location, String name, String skin) throws IllegalArgumentException {
String fullName = name;
String prefix = null;
String suffix = null;
if (name == null) {
return null;
} else if (fullName.length() > 16) {
prefix = fullName.substring(0, 16);
if (fullName.length() > 30) {
int len = 30;
name = fullName.substring(16, 30);
if (name.matches(".*[^A-Za-z0-9_].*")) {
if (fullName.length() >= 32) {
len = 32;
name = fullName.substring(16, 32);
} else if (fullName.length() == 31) {
len = 31;
name = fullName.substring(16, 31);
}
} else if (name.length() > 46) {
throw new IllegalArgumentException("You must specify a name with no more than 46 characters for FAKE_PLAYER entities!");
} else {
name = ChatColor.RESET + name;
}
suffix = fullName.substring(len);
} else {
name = fullName.substring(16);
if (!name.matches(".*[^A-Za-z0-9_].*")) {
name = ChatColor.RESET + name;
}
if (name.length() > 16) {
suffix = name.substring(16);
name = name.substring(0, 16);
}
}
}
if (skin != null && skin.length() > 16) {
throw new IllegalArgumentException("You must specify a name with no more than 16 characters for FAKE_PLAYER entity skins!");
}
CraftWorld world = (CraftWorld) location.getWorld();
WorldServer worldServer = world.getHandle();
PlayerProfile playerProfile = new PlayerProfile(name, null);
if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
playerProfile = NMSHandler.getInstance().fillPlayerProfile(playerProfile);
}
if (skin != null) {
PlayerProfile skinProfile = new PlayerProfile(skin, null);
skinProfile = NMSHandler.getInstance().fillPlayerProfile(skinProfile);
playerProfile.setTexture(skinProfile.getTexture());
playerProfile.setTextureSignature(skinProfile.getTextureSignature());
}
UUID uuid = UUID.randomUUID();
if (uuid.version() == 4) {
long msb = uuid.getMostSignificantBits();
msb &= ~0x0000000000004000L;
msb |= 0x0000000000002000L;
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
playerProfile.setUniqueId(uuid);
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
final EntityFakePlayer_v1_8_R3 fakePlayer = new EntityFakePlayer_v1_8_R3(worldServer.getMinecraftServer(), worldServer, gameProfile, new PlayerInteractManager(worldServer));
fakePlayer.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
CraftFakePlayer_v1_8_R3 craftFakePlayer = fakePlayer.getBukkitEntity();
craftFakePlayer.fullName = fullName;
if (prefix != null) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
String hash = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = teamName.getBytes("UTF-8");
md.update(bytes, 0, bytes.length);
hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
} catch (Exception e) {
e.printStackTrace();
}
if (hash != null) {
Team team = scoreboard.getTeam(hash);
if (team == null) {
team = scoreboard.registerNewTeam(hash);
team.setPrefix(prefix);
if (suffix != null) {
team.setSuffix(suffix);
}
}
team.addPlayer(craftFakePlayer);
}
}
return craftFakePlayer;
}
Aggregations