/
NMSAlgorithmsImpl.java
131 lines (110 loc) · 4.55 KB
/
NMSAlgorithmsImpl.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
package com.bgsoftware.superiorskyblock.nms.v1_12_R1;
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.v1_12_R1.algorithms.GlowEnchantment;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.Item;
import net.minecraft.server.v1_12_R1.MinecraftKey;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.World;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionEffect;
public class NMSAlgorithmsImpl implements NMSAlgorithms {
private final SuperiorSkyblockPlugin plugin;
public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}
@Override
public void registerCommand(BukkitCommand command) {
((CraftServer) plugin.getServer()).getCommandMap().register("superiorskyblock2", command);
}
@Override
public String parseSignLine(String original) {
return IChatBaseComponent.ChatSerializer.a(CraftChatMessage.fromString(original)[0]);
}
@Override
public int getCombinedId(Location location) {
World world = ((CraftWorld) location.getWorld()).getHandle();
IBlockData blockData = world.getType(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
return Block.getCombinedId(blockData);
}
@Override
public int getCombinedId(Material material, byte data) {
//noinspection deprecation
return material.getId() + (data << 12);
}
@Override
public int compareMaterials(Material o1, Material o2) {
return Integer.compare(o1.ordinal(), o2.ordinal());
}
@Override
public Key getBlockKey(int combinedId) {
//noinspection deprecation
Material material = Material.getMaterial(combinedId & 4095);
byte data = (byte) (combinedId >> 12 & 15);
return KeyImpl.of(material, data);
}
@Override
public Key getMinecartBlock(Minecart minecart) {
MaterialData materialData = minecart.getDisplayBlock();
//noinspection deprecation
return KeyImpl.of(materialData.getItemType(), materialData.getData());
}
@Override
public Key getFallingBlockType(FallingBlock fallingBlock) {
//noinspection deprecation
return KeyImpl.of(fallingBlock.getMaterial(), fallingBlock.getBlockData());
}
@Override
public void setCustomModel(ItemMeta itemMeta, int customModel) {
// Doesn't exist
}
@Override
public void addPotion(PotionMeta potionMeta, PotionEffect potionEffect) {
if (!potionMeta.hasCustomEffects())
potionMeta.setColor(potionEffect.getType().getColor());
potionMeta.addCustomEffect(potionEffect, true);
}
@Override
public String getMinecraftKey(org.bukkit.inventory.ItemStack itemStack) {
MinecraftKey minecraftKey = Item.REGISTRY.b(CraftItemStack.asNMSCopy(itemStack).getItem());
return minecraftKey == null ? "minecraft:air" : minecraftKey.toString();
}
@Override
public Enchantment getGlowEnchant() {
return GlowEnchantment.createEnchantment();
}
@Override
public int getMaxWorldSize() {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
return server.getPropertyManager().getInt("max-world-size", 29999984);
}
@Override
public double getCurrentTps() {
return Bukkit.getTPS()[0];
}
@Override
public Object createMenuInventoryHolder(InventoryType inventoryType, InventoryHolder defaultHolder, String title) {
return defaultHolder;
}
}