use of com.denizenscript.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditor method setPlayerSkinBlob.
// <--[language]
// @name Player Entity Skins (Skin Blobs)
// @group Minecraft Logic
// @description
// Player entities (that is, both real players and player-type NPCs), in addition to Player_Head items,
// use something called a "skin blob" to determine what skin to show.
// A skin blob consists of an identifier (usually the player's UUID, sometimes the name), a "texture", and a "signature".
//
// The "texture" portion, despite the name, does not contain actual texture data - it contains a Base64 encoding of a JSON section that contains outlinks to real skin data.
// That might be a bit confusing, so here's an example:
//
// The raw "texture" data for "mcmonkey4eva"'s skin is:
// eyJ0aW1lc3RhbXAiOjE1NjU1NjUyNDA4NTMsInByb2ZpbGVJZCI6IjQ2MGU5NmI5N2EwZTQxNmRiMmMzNDUwODE2NGI4YjFiIiwicHJvZmlsZU5hbWUiOiJtY21vbmtleTRldmEiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dH
// VyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2ZkMzRiM2UyN2EzZmU1MzgyN2IzN2FkNTk1NmFjY2EwOGYyODYzYzY5MjZjYzk3MTE2ZGRhMzM0ODY5N2E1YTkifX19
//
// This is base64 encoding, which is just a way of controlling the format of binary data. When passed through a Base64 decoder, that says:
// {"timestamp":1565565240853,"profileId":"460e96b97a0e416db2c34508164b8b1b","profileName":"mcmonkey4eva","signatureRequired":true,
// "textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/fd34b3e27a3fe53827b37ad5956acca08f2863c6926cc97116dda3348697a5a9"}}}
//
// As you can see, it contains: the timestamp of when the skin was added, the UUID and name, and a link to the actual skin file on Mojang's servers.
//
// The "signature" portion is a digitally encrypted signature that is used to verify a skin really was generated by Mojang.
// It is also represented as Base64, but cannot be decoded to anything readable.
// The "signature" is required for Player entity skins, but can generally be left off from Player_Head items (meaning, you can generate your own Player_Head items by base64 encoding your own JSON).
//
// The website <@link url https://mineskin.org/> can be used to generate full texture+signature data from any skin file
// (it does this by automatically uploading the skin image to Mojang's servers for processing and signing, using a donated Minecraft account).
//
// In terms of general actual usage, skin blobs are generally meant to be read from tags and applied with mechanisms, never directly written out or read by a human, due to their complexity.
//
// A skin_blob always represents a single actual skin, as opposed to a player name/uuid, where the account owner might choose to change their skin.
//
// It should be noted that any time a skin is applied to a Player, NPC, Or Player_Head item using just a name or UUID, the server must contact Mojang's servers to requst the skin blob for that given name/uuid.
// With a skin blob, however, the server does not need to make any remote calls, and can apply the skin directly (However note that the client will still download the image from Mojang's servers).
// -->
public void setPlayerSkinBlob(Player player, String blob) {
NetworkInterceptHelper.enable();
PlayerProfile profile = getFakeProfile(player, true);
String[] split = blob.split(";");
profile.setTexture(split[0]);
profile.setTextureSignature(split.length > 1 ? split[1] : null);
updatePlayer(player, true);
}
use of com.denizenscript.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditor method setPlayerName.
public void setPlayerName(Player player, String name) {
NetworkInterceptHelper.enable();
PlayerProfile profile = getFakeProfile(player, true);
profile.setName(name);
updatePlayer(player, false);
}
use of com.denizenscript.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class LocationTag method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("block_facing") && mechanism.requireObject(LocationTag.class)) {
LocationTag faceVec = mechanism.valueAsType(LocationTag.class);
Block block = getBlock();
MaterialTag material = new MaterialTag(block);
if (!MaterialDirectional.describes(material)) {
mechanism.echoError("LocationTag.block_facing mechanism failed: block is not directional.");
return;
}
MaterialDirectional.getFrom(material).setFacing(Utilities.faceFor(faceVec.toVector()));
block.setBlockData(material.getModernData());
}
// -->
if (mechanism.matches("block_type") && mechanism.requireObject(MaterialTag.class)) {
MaterialTag mat = mechanism.valueAsType(MaterialTag.class);
getBlock().setBlockData(mat.getModernData(), false);
}
// -->
if (mechanism.matches("biome") && mechanism.requireObject(BiomeTag.class)) {
mechanism.valueAsType(BiomeTag.class).getBiome().setTo(getBlock());
}
// -->
if (mechanism.matches("spawner_custom_rules") && mechanism.requireObject(MapTag.class) && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
MapTag map = mechanism.valueAsType(MapTag.class);
ObjectTag skyMin = map.getObject("sky_min"), skyMax = map.getObject("sky_max"), blockMin = map.getObject("block_min"), blockMax = map.getObject("block_max");
if (skyMin == null || skyMax == null || blockMin == null || blockMax == null) {
mechanism.echoError("Invalid spawner_custom_rules input, missing map keys.");
return;
}
NMSHandler.getBlockHelper().setSpawnerCustomRules(spawner, Integer.parseInt(skyMin.toString()), Integer.parseInt(skyMax.toString()), Integer.parseInt(blockMin.toString()), Integer.parseInt(blockMax.toString()));
spawner.update();
}
// -->
if (mechanism.matches("spawner_type") && mechanism.requireObject(EntityTag.class) && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
NMSHandler.getBlockHelper().setSpawnerSpawnedType(spawner, mechanism.valueAsType(EntityTag.class));
spawner.update();
}
// -->
if (mechanism.matches("spawner_delay_data") && getBlockState() instanceof CreatureSpawner) {
ListTag list = mechanism.valueAsType(ListTag.class);
if (list.size() < 3) {
return;
}
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setDelay(Integer.parseInt(list.get(0)));
int minDelay = Integer.parseInt(list.get(1));
int maxDelay = Integer.parseInt(list.get(2));
// or new min would be higher than the current max
if (minDelay > spawner.getMaxSpawnDelay()) {
spawner.setMaxSpawnDelay(maxDelay);
spawner.setMinSpawnDelay(minDelay);
} else {
spawner.setMinSpawnDelay(minDelay);
spawner.setMaxSpawnDelay(maxDelay);
}
spawner.update();
}
// -->
if (mechanism.matches("spawner_max_nearby_entities") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setMaxNearbyEntities(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_player_range") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setRequiredPlayerRange(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_range") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setSpawnRange(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_count") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setSpawnCount(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("lock") && getBlockState() instanceof Lockable) {
BlockState state = getBlockState();
((Lockable) state).setLock(mechanism.hasValue() ? mechanism.getValue().asString() : null);
state.update();
}
// -->
if (mechanism.matches("sign_contents") && getBlockState() instanceof Sign) {
Sign state = (Sign) getBlockState();
for (int i = 0; i < 4; i++) {
AdvancedTextImpl.instance.setSignLine(state, i, "");
}
ListTag list = mechanism.valueAsType(ListTag.class);
CoreUtilities.fixNewLinesToListSeparation(list);
if (list.size() > 4) {
Debug.echoError("Sign can only hold four lines!");
} else {
for (int i = 0; i < list.size(); i++) {
AdvancedTextImpl.instance.setSignLine(state, i, list.get(i));
}
}
state.update();
}
// -->
if (mechanism.matches("skull_skin")) {
final BlockState blockState = getBlockState();
Material material = getBlock().getType();
if (blockState instanceof Skull) {
ListTag list = mechanism.valueAsType(ListTag.class);
String idString = list.get(0);
String texture = null;
if (list.size() > 1) {
texture = list.get(1);
}
PlayerProfile profile;
if (idString.contains("-")) {
UUID uuid = UUID.fromString(idString);
String name = null;
if (list.size() > 2) {
name = list.get(2);
}
profile = new PlayerProfile(name, uuid, texture);
} else {
profile = new PlayerProfile(idString, null, texture);
}
profile = NMSHandler.getInstance().fillPlayerProfile(profile);
if (texture != null) {
// Ensure we didn't get overwritten
profile.setTexture(texture);
}
NMSHandler.getBlockHelper().setPlayerProfile((Skull) blockState, profile);
} else {
Debug.echoError("Unable to set skull_skin on block of type " + material.name() + " with state " + blockState.getClass().getCanonicalName());
}
}
// -->
if (mechanism.matches("hive_max_bees") && mechanism.requireInteger()) {
Beehive hive = (Beehive) getBlockState();
hive.setMaxEntities(mechanism.getValue().asInt());
hive.update();
}
// -->
if (mechanism.matches("release_bees")) {
Beehive hive = (Beehive) getBlockState();
hive.releaseEntities();
hive.update();
}
// -->
if (mechanism.matches("add_bee") && mechanism.requireObject(EntityTag.class)) {
Beehive hive = (Beehive) getBlockState();
hive.addEntity((Bee) mechanism.valueAsType(EntityTag.class).getBukkitEntity());
hive.update();
}
// -->
if (mechanism.matches("command_block_name")) {
if (getBlock().getState() instanceof CommandBlock) {
CommandBlock block = ((CommandBlock) getBlockState());
block.setName(mechanism.getValue().asString());
block.update();
}
}
// -->
if (mechanism.matches("command_block")) {
if (getBlock().getState() instanceof CommandBlock) {
CommandBlock block = ((CommandBlock) getBlockState());
block.setCommand(mechanism.getValue().asString());
block.update();
}
}
// -->
if (mechanism.matches("custom_name")) {
if (getBlockState() instanceof Nameable) {
String title = null;
if (mechanism.hasValue()) {
title = mechanism.getValue().asString();
}
BlockState state = getBlockState();
((Nameable) state).setCustomName(title);
state.update(true);
}
}
// -->
if (mechanism.matches("brewing_time")) {
if (getBlockState() instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) getBlockState();
stand.setBrewingTime(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
stand.update();
}
}
// -->
if (mechanism.matches("brewing_fuel_level")) {
if (getBlockState() instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) getBlockState();
stand.setFuelLevel(mechanism.getValue().asInt());
stand.update();
}
}
// -->
if (mechanism.matches("furnace_burn_duration") && mechanism.requireObject(DurationTag.class)) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setBurnTime((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_burn_time")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setBurnTime((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("furnace_cook_duration")) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTime((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_cook_time")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTime((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("furnace_cook_duration_total")) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTimeTotal((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_cook_time_total")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTimeTotal((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("patterns")) {
List<org.bukkit.block.banner.Pattern> patterns = new ArrayList<>();
ListTag list = mechanism.valueAsType(ListTag.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) {
Debug.echoError("Could not apply pattern to banner: " + string);
}
}
Banner banner = (Banner) getBlockState();
banner.setPatterns(patterns);
banner.update();
}
// -->
if (mechanism.matches("head_rotation") && mechanism.requireInteger()) {
Skull sk = (Skull) getBlockState();
sk.setRotation(getSkullBlockFace(mechanism.getValue().asInt() - 1));
sk.update();
}
// -->
if (mechanism.matches("generate_tree") && mechanism.requireEnum(TreeType.class)) {
boolean generated = getWorld().generateTree(this, TreeType.valueOf(mechanism.getValue().asString().toUpperCase()));
if (!generated) {
Debug.echoError("Could not generate tree at " + identifySimple() + ". Make sure this location can naturally generate a tree!");
}
}
// -->
if (mechanism.matches("beacon_primary_effect")) {
Beacon beacon = (Beacon) getBlockState();
beacon.setPrimaryEffect(PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase()));
beacon.update();
}
// -->
if (mechanism.matches("beacon_secondary_effect")) {
Beacon beacon = (Beacon) getBlockState();
beacon.setSecondaryEffect(PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase()));
beacon.update();
}
// -->
if (mechanism.matches("activate")) {
BlockState state = getBlockState();
if (state instanceof Dispenser) {
((Dispenser) state).dispense();
} else if (state instanceof Dropper) {
((Dropper) state).drop();
} else {
Debug.echoError("'activate' mechanism does not work for blocks of type: " + state.getType().name());
}
}
// -->
if (mechanism.matches("lectern_page") && mechanism.requireInteger()) {
BlockState state = getBlockState();
if (state instanceof Lectern) {
((Lectern) state).setPage(mechanism.getValue().asInt());
state.update();
} else {
Debug.echoError("'lectern_page' mechanism can only be called on a lectern block.");
}
}
// -->
if (mechanism.matches("clear_loot_table")) {
BlockState state = getBlockState();
if (state instanceof Lootable) {
((Lootable) state).setLootTable(null);
state.update();
} else {
Debug.echoError("'clear_loot_table' mechanism can only be called on a lootable block (like a chest).");
}
}
// -->
if (mechanism.matches("jukebox_record")) {
BlockState state = getBlockState();
if (state instanceof Jukebox) {
if (mechanism.hasValue() && mechanism.requireObject(ItemTag.class)) {
((Jukebox) state).setRecord(mechanism.valueAsType(ItemTag.class).getItemStack());
} else {
NMSHandler.getBlockHelper().makeBlockStateRaw(state);
((Jukebox) state).setRecord(null);
}
state.update();
} else {
Debug.echoError("'jukebox_record' mechanism can only be called on a jukebox block.");
}
}
// -->
if (mechanism.matches("jukebox_play") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (state instanceof Jukebox) {
if (mechanism.getValue().asBoolean()) {
Material mat = ((Jukebox) state).getRecord().getType();
if (mat == Material.AIR) {
Debug.echoError("'jukebox_play' cannot play nothing.");
return;
}
((Jukebox) state).setPlaying(mat);
} else {
((Jukebox) state).stopPlaying();
}
state.update();
} else {
Debug.echoError("'jukebox_play' mechanism can only be called on a jukebox block.");
}
}
// -->
if (mechanism.matches("age") && mechanism.requireObject(DurationTag.class)) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setAge(mechanism.valueAsType(DurationTag.class).getTicks());
state.update();
} else {
Debug.echoError("'age' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("is_exact_teleport") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setExactTeleport(mechanism.getValue().asBoolean());
state.update();
} else {
Debug.echoError("'is_exact_teleport' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("exit_location") && mechanism.requireObject(LocationTag.class)) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setExitLocation(mechanism.valueAsType(LocationTag.class));
state.update();
} else {
Debug.echoError("'exit_location' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("vanilla_tick")) {
NMSHandler.getBlockHelper().doRandomTick(this);
}
// -->
if (mechanism.matches("apply_bonemeal") && mechanism.requireEnum(BlockFace.class)) {
getBlock().applyBoneMeal(BlockFace.valueOf(mechanism.getValue().asString().toUpperCase()));
}
// -->
if (mechanism.matches("campfire_items") && mechanism.requireObject(ListTag.class)) {
BlockState state = getBlockState();
if (!(state instanceof Campfire)) {
Debug.echoError("'campfire_items' mechanism can only be called on campfire blocks.");
} else {
Campfire fire = (Campfire) state;
List<ItemTag> list = mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context);
for (int i = 0; i < list.size(); i++) {
if (i >= fire.getSize()) {
Debug.echoError("Cannot add item for index " + (i + 1) + " as the campfire can only hold " + fire.getSize() + " items.");
break;
}
fire.setItem(i, list.get(i).getItemStack());
}
fire.update();
}
}
// -->
if (mechanism.matches("ring_bell")) {
BlockState state = getBlockState();
if (!(state instanceof Bell)) {
Debug.echoError("'ring_bell' mechanism can only be called on Bell blocks.");
} else {
NMSHandler.getBlockHelper().ringBell((Bell) state);
}
}
// -->
if (mechanism.matches("sign_glowing") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (!(state instanceof Sign)) {
Debug.echoError("'sign_glowing' mechanism can only be called on Sign blocks.");
} else {
Sign sign = (Sign) state;
sign.setGlowingText(mechanism.getValue().asBoolean());
sign.update();
}
}
// -->
if (mechanism.matches("sign_glow_color") && mechanism.requireEnum(DyeColor.class)) {
BlockState state = getBlockState();
if (!(state instanceof Sign)) {
Debug.echoError("'sign_glow_color' mechanism can only be called on Sign blocks.");
} else {
Sign sign = (Sign) state;
sign.setColor(mechanism.getValue().asEnum(DyeColor.class));
sign.update();
}
}
CoreUtilities.autoPropertyMechanism(this, mechanism);
}
use of com.denizenscript.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class ItemSkullskin method getPropertyString.
@Override
public String getPropertyString() {
PlayerProfile playerProfile = NMSHandler.getItemHelper().getSkullSkin(item.getItemStack());
if (playerProfile != null) {
String name = playerProfile.getName();
UUID uuid = playerProfile.getUniqueId();
return (uuid != null ? uuid : name) + (playerProfile.hasTexture() ? "|" + playerProfile.getTexture() + (uuid != null && name != null ? "|" + name : "") : "");
}
return null;
}
use of com.denizenscript.denizen.nms.util.PlayerProfile in project Denizen-For-Bukkit by DenizenScript.
the class ItemSkullskin method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("skull_skin")) {
ListTag list = mechanism.valueAsType(ListTag.class);
String idString = list.get(0);
String texture = null;
if (list.size() > 1) {
texture = list.get(1);
}
PlayerProfile profile;
if (CoreUtilities.contains(idString, '-')) {
UUID uuid = UUID.fromString(idString);
String name = null;
if (list.size() > 2) {
name = list.get(2);
}
profile = new PlayerProfile(name, uuid, texture);
} else {
profile = new PlayerProfile(idString, null, texture);
}
profile = NMSHandler.getInstance().fillPlayerProfile(profile);
if (texture != null) {
// Ensure we didn't get overwritten
profile.setTexture(texture);
}
if (profile.getTexture() == null) {
// Can't set a skull skin to nothing.
return;
}
item.setItemStack(NMSHandler.getItemHelper().setSkullSkin(item.getItemStack(), profile));
}
}
Aggregations