/
BlockHelper_v1_10_R1.java
136 lines (123 loc) · 4.78 KB
/
BlockHelper_v1_10_R1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package net.aufdemrand.denizen.nms.helpers;
import com.google.common.collect.Iterables;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.aufdemrand.denizen.nms.impl.blocks.BlockData_v1_10_R1;
import net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1;
import net.aufdemrand.denizen.nms.interfaces.BlockData;
import net.aufdemrand.denizen.nms.interfaces.BlockHelper;
import net.aufdemrand.denizen.nms.util.PlayerProfile;
import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag;
import net.minecraft.server.v1_10_R1.TileEntity;
import net.minecraft.server.v1_10_R1.TileEntitySkull;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.block.Block;
import org.bukkit.block.FlowerPot;
import org.bukkit.block.Skull;
import org.bukkit.craftbukkit.v1_10_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_10_R1.block.CraftSkull;
import org.bukkit.material.MaterialData;
import java.util.UUID;
public class BlockHelper_v1_10_R1 implements BlockHelper {
@Override
public MaterialData getFlowerpotContents(Block block) {
return ((FlowerPot) block.getState()).getContents();
}
@Override
public void setFlowerpotContents(Block block, MaterialData data) {
FlowerPot flowerPot = (FlowerPot) block.getState();
flowerPot.setContents(data);
flowerPot.update();
}
@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);
}
@Override
public void setPlayerProfile(Skull skull, PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
if (playerProfile.hasTexture()) {
gameProfile.getProperties().put("textures",
new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
}
TileEntitySkull tileEntity = ((CraftSkull) skull).getTileEntity();
tileEntity.setSkullType(SkullType.PLAYER.ordinal());
tileEntity.setGameProfile(gameProfile);
skull.getBlock().getState().update();
}
@Override
public CompoundTag getNbtData(Block block) {
TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
if (tileEntity == null) {
return null;
}
return CompoundTag_v1_10_R1.fromNMSTag(tileEntity.c());
}
@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
if (tileEntity == null) {
return;
}
tileEntity.a(((CompoundTag_v1_10_R1) compoundTag).toNMSTag());
tileEntity.update();
}
@Override
public BlockData getBlockData(short id, byte data) {
return new BlockData_v1_10_R1(id, data);
}
@Override
public BlockData getBlockData(Block block) {
return new BlockData_v1_10_R1(block);
}
@Override
public BlockData getBlockData(String compressedString) {
return BlockData_v1_10_R1.fromCompressedString(compressedString);
}
@Override
public boolean isSafeBlock(Material material) {
// Quick util function to decide whether
// A block is 'safe' (Can be spawned inside of) - air, tallgrass, etc.
// Credit to Mythan for compiling the initial list
switch (material) {
case LEVER:
case WOOD_BUTTON:
case STONE_BUTTON:
case REDSTONE_WIRE:
case SAPLING:
case SIGN_POST:
case WALL_SIGN:
case SNOW:
case TORCH:
case DETECTOR_RAIL:
case ACTIVATOR_RAIL:
case RAILS:
case POWERED_RAIL:
case NETHER_WARTS:
case NETHER_STALK:
case VINE:
case SUGAR_CANE_BLOCK:
case CROPS:
case LONG_GRASS:
case RED_MUSHROOM:
case BROWN_MUSHROOM:
case DEAD_BUSH:
case REDSTONE_TORCH_OFF:
case REDSTONE_TORCH_ON:
case AIR:
case YELLOW_FLOWER:
case RED_ROSE:
return true;
default:
return false;
}
}
}