From 00f80502b1de6447d9f0e427d7c6bdbe19c0d50c Mon Sep 17 00:00:00 2001 From: RaynLegends Date: Thu, 13 Jul 2017 00:06:19 +0200 Subject: [PATCH 01/14] Updated to the latest version of Nukkit. Needs testing! Fixes #90, #95, #96 --- .../pokkit/entity/PokkitDamageCause.java | 1 + .../inventory/custom/NukkitCustomInventory.java | 1 - .../nl/rutgerkok/pokkit/item/PokkitItemStack.java | 2 +- .../pokkit/material/PokkitMaterialData.java | 14 ++++++++++++++ .../pokkit/pluginservice/EntityEvents.java | 1 + .../pluginservice/PlayerInteractEvents.java | 13 +++++++------ .../nl/rutgerkok/pokkit/world/PokkitBlock.java | 15 ++++++++------- .../rutgerkok/pokkit/world/PokkitBlockFace.java | 1 + 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitDamageCause.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitDamageCause.java index c325b56..37f1cd6 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitDamageCause.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitDamageCause.java @@ -5,6 +5,7 @@ public final class PokkitDamageCause { public static DamageCause toBukkit(cn.nukkit.event.entity.EntityDamageEvent.DamageCause nukkit) { + // TODO Direct mapping via DamageCause.valueOf? switch (nukkit) { case CONTACT: return DamageCause.CONTACT; diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java index bd62e76..cc2db6a 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java @@ -107,7 +107,6 @@ public void onOpen(Player who) { ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); containerOpenPacket.windowid = (byte) who.getWindowId(this); containerOpenPacket.type = (byte) this.getType().getNetworkType(); - containerOpenPacket.slots = this.getSize(); containerOpenPacket.x = (int) v.x; containerOpenPacket.y = (int) v.y; diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java index e80f068..a021499 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java @@ -63,7 +63,7 @@ public static ItemStack toBukkitCopy(cn.nukkit.item.Item nukkit) { if (nukkit == null) { return null; } - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()); + PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit); Material material = materialData.getBukkitMaterial(); if (material == null) { return null; diff --git a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java b/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java index 332ce75..6da9cdf 100644 --- a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java +++ b/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java @@ -50,9 +50,23 @@ public static PokkitMaterialData fromBukkit(MaterialData materialData) { * The Nukkit damage/block data. * @return The universal material object. */ + @Deprecated public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) { return new PokkitMaterialData(nukkitId, nukkitDamage); } + + /** + * Creates a universal material object from a Nukkit item. + * + * @param nukkitId + * The Nukkit material. + * @param nukkitDamage + * The Nukkit damage/block data. + * @return The universal material object. + */ + public static PokkitMaterialData fromNukkit(cn.nukkit.item.Item item) { + return new PokkitMaterialData(item.getId(), item.getDamage()); + } private final int id; private final int data; diff --git a/src/main/java/nl/rutgerkok/pokkit/pluginservice/EntityEvents.java b/src/main/java/nl/rutgerkok/pokkit/pluginservice/EntityEvents.java index ec6150f..c848a64 100644 --- a/src/main/java/nl/rutgerkok/pokkit/pluginservice/EntityEvents.java +++ b/src/main/java/nl/rutgerkok/pokkit/pluginservice/EntityEvents.java @@ -41,6 +41,7 @@ import cn.nukkit.event.block.ItemFrameDropItemEvent; import cn.nukkit.item.Item; +@SuppressWarnings("deprecation") public final class EntityEvents extends EventTranslator { private static Map getDamageMap(double baseDamage) { diff --git a/src/main/java/nl/rutgerkok/pokkit/pluginservice/PlayerInteractEvents.java b/src/main/java/nl/rutgerkok/pokkit/pluginservice/PlayerInteractEvents.java index 33b2bbb..e4a1bf0 100644 --- a/src/main/java/nl/rutgerkok/pokkit/pluginservice/PlayerInteractEvents.java +++ b/src/main/java/nl/rutgerkok/pokkit/pluginservice/PlayerInteractEvents.java @@ -73,17 +73,18 @@ public void onSignChange(cn.nukkit.event.block.SignChangeEvent event) { // event.setLines(bukkitEvent.getLines()) is unnecessary } - private Action toBukkit(int nukkit) { + private Action toBukkit(cn.nukkit.event.player.PlayerInteractEvent.Action nukkit) { + // TODO Direct mapping via Action.valueOf? switch (nukkit) { - case cn.nukkit.event.player.PlayerInteractEvent.LEFT_CLICK_AIR: + case LEFT_CLICK_AIR: return Action.LEFT_CLICK_AIR; - case cn.nukkit.event.player.PlayerInteractEvent.RIGHT_CLICK_AIR: + case RIGHT_CLICK_AIR: return Action.RIGHT_CLICK_AIR; - case cn.nukkit.event.player.PlayerInteractEvent.LEFT_CLICK_BLOCK: + case LEFT_CLICK_BLOCK: return Action.LEFT_CLICK_BLOCK; - case cn.nukkit.event.player.PlayerInteractEvent.RIGHT_CLICK_BLOCK: + case RIGHT_CLICK_BLOCK: return Action.RIGHT_CLICK_BLOCK; - case cn.nukkit.event.player.PlayerInteractEvent.PHYSICAL: + case PHYSICAL: return Action.PHYSICAL; } throw new RuntimeException("Unknown action: " + nukkit); diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java index 8376533..196e089 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java @@ -27,6 +27,7 @@ import org.bukkit.plugin.Plugin; import cn.nukkit.block.BlockAir; +import cn.nukkit.item.Item; import cn.nukkit.item.ItemBlock; /** @@ -99,7 +100,7 @@ public Chunk getChunk() { @Override public byte getData() { - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()); + PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.toItem()); return (byte) materialData.getBukkitDamage(); } @@ -122,11 +123,11 @@ private Collection getDrops0(cn.nukkit.item.Item item) { item = new ItemBlock(new BlockAir(), 0, 0); } - int[][] drops = nukkit.getDrops(item); + Item[] drops = nukkit.getDrops(item); List result = new ArrayList<>(); - for (int[] drop : drops) { - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(drop[0], drop[1]); - ItemStack stack = new ItemStack(materialData.getBukkitMaterial(), drop[2], materialData.getBukkitDamage()); + for (Item drop : drops) { + PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(drop); + ItemStack stack = new ItemStack(materialData.getBukkitMaterial(), drop.getCount(), materialData.getBukkitDamage()); result.add(stack); } this.drops = result; @@ -222,7 +223,7 @@ public double getTemperature() { @Override public Material getType() { - return PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()).getBukkitMaterial(); + return PokkitMaterialData.fromNukkit(nukkit.toItem()).getBukkitMaterial(); } /** @@ -231,7 +232,7 @@ public Material getType() { * @return The material data. */ public MaterialData getTypeData() { - return PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()).toBukkit(); + return PokkitMaterialData.fromNukkit(nukkit.toItem()).toBukkit(); } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlockFace.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlockFace.java index 7aad81b..e6ebc2e 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlockFace.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlockFace.java @@ -5,6 +5,7 @@ public final class PokkitBlockFace { public static BlockFace toBukkit(cn.nukkit.math.BlockFace nukkit) { + // TODO Direct mapping via BlockFace.valueOf? switch (nukkit) { case DOWN: return BlockFace.DOWN; From 31d9e260ae0f230bbd690e0d92a37859b1ca1d41 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sun, 30 Jul 2017 10:25:50 +0200 Subject: [PATCH 02/14] Update to latest Spigot Guava 21 is no longer included with Pokkit, as Nukkit now also includes it. --- pom.xml | 6 +- .../nl/rutgerkok/pokkit/PokkitUnsafe.java | 12 ++++ .../pokkit/command/PokkitCommandSender.java | 23 +++++++- .../rutgerkok/pokkit/entity/PokkitEntity.java | 10 +++- .../pokkit/entity/PokkitFakeEntity.java | 6 ++ .../pokkit/entity/PokkitHumanEntity.java | 36 +++++++++--- .../pokkit/entity/PokkitItemFrameEntity.java | 6 ++ .../pokkit/entity/PokkitLivingEntity.java | 57 ------------------- .../custom/NukkitCustomInventory.java | 4 +- .../rutgerkok/pokkit/item/PokkitItemMeta.java | 3 +- .../pokkit/material/PokkitMaterialData.java | 20 +++---- .../pokkit/player/PokkitOfflinePlayer.java | 5 -- .../rutgerkok/pokkit/player/PokkitPlayer.java | 21 +++++-- .../pokkit/player/PokkitTeleportCause.java | 5 +- .../rutgerkok/pokkit/plugin/PokkitPlugin.java | 7 --- .../pokkit/scoreboard/PokkitTeam.java | 15 +++++ .../scoreboard/ScoreboardPersister.java | 11 ++++ .../craftbukkit/v1_99_R9/CraftServer.java | 30 ++++++---- 18 files changed, 161 insertions(+), 116 deletions(-) diff --git a/pom.xml b/pom.xml index cc794e4..0170d87 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.spigotmc spigot-api - 1.11.2-R0.1-SNAPSHOT + 1.12-R0.1-SNAPSHOT compile @@ -35,8 +35,8 @@ com.google.guava guava - 17.0 - compile + 21.0 + provided junit diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java b/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java index 6880375..b651133 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java @@ -7,8 +7,10 @@ import org.bukkit.Achievement; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Statistic; import org.bukkit.UnsafeValues; +import org.bukkit.advancement.Advancement; import org.bukkit.inventory.ItemStack; import cn.nukkit.item.Item; @@ -46,6 +48,11 @@ public Statistic getStatisticFromInternalName(String name) { } } + @Override + public Advancement loadAdvancement(NamespacedKey key, String advancementJson) { + throw Pokkit.unsupported(); + } + @Override public ItemStack modifyItemStack(ItemStack stack, String arguments) { // NBT not yet supported @@ -55,6 +62,11 @@ public ItemStack modifyItemStack(ItemStack stack, String arguments) { return stack; } + @Override + public boolean removeAdvancement(NamespacedKey key) { + throw Pokkit.unsupported(); + } + @Override public List tabCompleteInternalMaterialName(String token, List completions) { return completions; diff --git a/src/main/java/nl/rutgerkok/pokkit/command/PokkitCommandSender.java b/src/main/java/nl/rutgerkok/pokkit/command/PokkitCommandSender.java index 8469151..d8146ac 100644 --- a/src/main/java/nl/rutgerkok/pokkit/command/PokkitCommandSender.java +++ b/src/main/java/nl/rutgerkok/pokkit/command/PokkitCommandSender.java @@ -16,7 +16,9 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; -public class PokkitCommandSender implements CommandSender { +import net.md_5.bungee.api.chat.BaseComponent; + +public class PokkitCommandSender extends CommandSender.Spigot implements CommandSender { public static CommandSender toBukkit(cn.nukkit.command.CommandSender nukkit) { // More specialized ones to support instanceof checks @@ -119,6 +121,20 @@ public void removeAttachment(PermissionAttachment attachment) { throw Pokkit.unsupported(); } + @Override + public void sendMessage(BaseComponent component) { + sendMessage(component.toLegacyText()); + } + + @Override + public void sendMessage(BaseComponent... components) { + StringBuilder text = new StringBuilder(); + for (BaseComponent component : components) { + text.append(component.toLegacyText()); + } + sendMessage(text.toString()); + } + @Override public void sendMessage(String message) { nukkit.sendMessage(message); @@ -136,4 +152,9 @@ public void setOp(boolean value) { nukkit.setOp(value); } + @Override + public Spigot spigot() { + return this; + } + } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java index b0bd2c9..326abb6 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java @@ -19,6 +19,7 @@ import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -180,6 +181,11 @@ public List getPassengers() { throw Pokkit.unsupported(); } + @Override + public PistonMoveReaction getPistonMoveReaction() { + return PistonMoveReaction.MOVE; + } + @Override public int getPortalCooldown() { return 80; @@ -500,7 +506,7 @@ public boolean setPassenger(Entity passenger) { @Override public void setPortalCooldown(int cooldown) { - return; // TODO: When portals are properly implemented in Nukkit, change this to use Nukkit's API! + return; // When portals are properly implemented in Nukkit, change this to use Nukkit's API! } @Override @@ -514,7 +520,7 @@ public void setTicksLived(int value) { nukkit.ticksLived = value; } - @Override + @Override public void setVelocity(Vector velocity) { nukkit.setMotion(new Vector3(velocity.getX(), velocity.getY(), velocity.getZ())); } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java index 9b68c8f..dc86c15 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java @@ -16,6 +16,7 @@ import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.Entity; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -161,6 +162,11 @@ public List getPassengers() { return Collections.emptyList(); } + @Override + public PistonMoveReaction getPistonMoveReaction() { + return PistonMoveReaction.MOVE; + } + @Override public int getPortalCooldown() { return 0; diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java index 8633fbe..976344a 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java @@ -8,6 +8,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Villager; import org.bukkit.inventory.Inventory; @@ -43,6 +44,11 @@ public void closeInventory() { throw Pokkit.unsupported(); } + @Override + public int getCooldown(Material material) { + throw Pokkit.unsupported(); + } + @Override public Inventory getEnderChest() { throw Pokkit.unsupported(); @@ -83,11 +89,26 @@ public InventoryView getOpenInventory() { throw Pokkit.unsupported(); } + @Override + public Entity getShoulderEntityLeft() { + return null; // Not implemented in Nukkit + } + + @Override + public Entity getShoulderEntityRight() { + return null; // Not implemented in Nukkit + } + @Override public int getSleepTicks() { throw Pokkit.unsupported(); } + @Override + public boolean hasCooldown(Material material) { + throw Pokkit.unsupported(); + } + @Override public boolean isBlocking() { return false; @@ -133,6 +154,11 @@ public InventoryView openWorkbench(Location location, boolean force) { throw Pokkit.unsupported(); } + @Override + public void setCooldown(Material material, int cooldown) { + throw Pokkit.unsupported(); + } + @Override public void setGameMode(GameMode mode) { throw Pokkit.unsupported(); @@ -149,22 +175,18 @@ public void setItemOnCursor(ItemStack item) { } @Override - public boolean setWindowProperty(Property prop, int value) { + public void setShoulderEntityLeft(Entity entity) { throw Pokkit.unsupported(); } @Override - public int getCooldown(Material material) { + public void setShoulderEntityRight(Entity entity) { throw Pokkit.unsupported(); } @Override - public boolean hasCooldown(Material material) { + public boolean setWindowProperty(Property prop, int value) { throw Pokkit.unsupported(); } - @Override - public void setCooldown(Material material, int cooldown) { - throw Pokkit.unsupported(); - } } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java index 3f0eb2f..b444a4c 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java @@ -5,6 +5,7 @@ import org.bukkit.Rotation; import org.bukkit.block.BlockFace; +import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemFrame; import org.bukkit.inventory.ItemStack; @@ -38,6 +39,11 @@ cn.nukkit.level.Location getNukkitLocation() { return nukkit.getLocation(); } + @Override + public PistonMoveReaction getPistonMoveReaction() { + return PistonMoveReaction.BREAK; + } + @Override public Rotation getRotation() { // TODO: Implement diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java index d38967e..b8c943c 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java @@ -57,50 +57,6 @@ public static cn.nukkit.entity.Entity toNukkit(LivingEntity entity) { this.nukkit = nukkitEntity; } - @Override - public void _INVALID_damage(int arg0) { - cn.nukkit.event.entity.EntityDamageEvent e = new cn.nukkit.event.entity.EntityDamageEvent(nukkit, cn.nukkit.event.entity.EntityDamageEvent.DamageCause.CUSTOM, arg0); - nukkit.attack(e); - } - - @Override - public void _INVALID_damage(int arg0, Entity arg1) { - cn.nukkit.event.entity.EntityDamageByEntityEvent e = new cn.nukkit.event.entity.EntityDamageByEntityEvent(nukkit, PokkitEntity.toNukkit(arg1), cn.nukkit.event.entity.EntityDamageEvent.DamageCause.CUSTOM, arg0); - nukkit.attack(e); - } - - @Override - public int _INVALID_getHealth() { - return (int) nukkit.getHealth(); - } - - @Override - public int _INVALID_getLastDamage() { - throw Pokkit.unsupported(); - - } - - @Override - public int _INVALID_getMaxHealth() { - return nukkit.getMaxHealth(); - } - - @Override - public void _INVALID_setHealth(int arg0) { - nukkit.setHealth(arg0); - } - - @Override - public void _INVALID_setLastDamage(int arg0) { - throw Pokkit.unsupported(); - - } - - @Override - public void _INVALID_setMaxHealth(int arg0) { - nukkit.setMaxHealth(arg0); - } - @Override public boolean addPotionEffect(PotionEffect bukkitEffect) { return addPotionEffect(bukkitEffect, false); @@ -197,19 +153,6 @@ public Entity getLeashHolder() throws IllegalStateException { throw Pokkit.unsupported(); } - @Override - public List getLineOfSight(HashSet bukkitTransparent, int maxDistance) { - cn.nukkit.block.Block[] nukkitBlocks = nukkit.getLineOfSight(maxDistance, 0, - toNukkitBlockIds(bukkitTransparent)); - - List bukkitBlocks = new ArrayList<>(nukkitBlocks.length); - for (cn.nukkit.block.Block nukkitBlock : nukkitBlocks) { - bukkitBlocks.add(PokkitBlock.toBukkit(nukkitBlock)); - } - - return bukkitBlocks; - } - @Override public List getLineOfSight(Set bukkitTransparent, int maxDistance) { cn.nukkit.block.Block[] nukkitBlocks = nukkit.getLineOfSight(maxDistance, 0, diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java index cc2db6a..c90555e 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java @@ -5,8 +5,6 @@ import java.util.HashMap; import java.util.Objects; -import com.google.common.base.Throwables; - import cn.nukkit.Player; import cn.nukkit.inventory.BaseInventory; import cn.nukkit.inventory.InventoryType; @@ -98,7 +96,7 @@ public void onOpen(Player who) { try { blockEntityDataPacket.namedTag = NBTIO.write(getSpawnCompound(v), ByteOrder.LITTLE_ENDIAN); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } who.dataPacket(blockEntityDataPacket); diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java index 8635055..34c4c9b 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java @@ -17,7 +17,6 @@ import org.bukkit.inventory.meta.ItemMeta; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import cn.nukkit.nbt.tag.CompoundTag; @@ -85,7 +84,7 @@ public ItemMeta clone() { meta.tag = this.tag.copy(); return meta; } catch (CloneNotSupportedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java b/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java index 6da9cdf..a8cb177 100644 --- a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java +++ b/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java @@ -42,21 +42,18 @@ public static PokkitMaterialData fromBukkit(MaterialData materialData) { } /** - * Creates a universal material object from a Nukkit material. + * Creates a universal material object from a Nukkit item. * - * @param nukkitId - * The Nukkit material. - * @param nukkitDamage - * The Nukkit damage/block data. + * @param item + * The Nukkit item. * @return The universal material object. */ - @Deprecated - public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) { - return new PokkitMaterialData(nukkitId, nukkitDamage); + public static PokkitMaterialData fromNukkit(cn.nukkit.item.Item item) { + return new PokkitMaterialData(item.getId(), item.getDamage()); } /** - * Creates a universal material object from a Nukkit item. + * Creates a universal material object from a Nukkit material. * * @param nukkitId * The Nukkit material. @@ -64,8 +61,9 @@ public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) { * The Nukkit damage/block data. * @return The universal material object. */ - public static PokkitMaterialData fromNukkit(cn.nukkit.item.Item item) { - return new PokkitMaterialData(item.getId(), item.getDamage()); + @Deprecated + public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) { + return new PokkitMaterialData(nukkitId, nukkitDamage); } private final int id; diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitOfflinePlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitOfflinePlayer.java index dc2f17a..ab3cd66 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitOfflinePlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitOfflinePlayer.java @@ -124,11 +124,6 @@ public Map serialize() { return ImmutableMap.of("name", getName()); } - @Override - public void setBanned(boolean banned) { - getNukkit().setBanned(banned); - } - @Override public void setOp(boolean value) { getNukkit().setOp(value); diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java index 93361a1..fb49a96 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java @@ -41,6 +41,8 @@ import org.bukkit.SoundCategory; import org.bukkit.Statistic; import org.bukkit.WeatherType; +import org.bukkit.advancement.Advancement; +import org.bukkit.advancement.AdvancementProgress; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.configuration.serialization.DelegateDeserialization; @@ -345,6 +347,11 @@ public InetSocketAddress getAddress() { return address; } + @Override + public AdvancementProgress getAdvancementProgress(Advancement advancement) { + throw Pokkit.unsupported(); + } + @Override public boolean getAllowFlight() { return nukkit.getAdventureSettings().canFly(); @@ -489,6 +496,12 @@ public Set getListeningPluginChannels() { } + @Override + public String getLocale() { + // Not implemented in Nukkit + return "en_US"; + } + @Override public List getMetadata(String metadataKey) { return getMetadataStore().getMetadata(this, metadataKey); @@ -616,7 +629,8 @@ public void giveExpLevels(int levels) { @Override public boolean hasAchievement(@SuppressWarnings("deprecation") org.bukkit.Achievement achievement) { - return true; // TODO: When achievements are properly implemented in Nukkit, change this to use Nukkit's API! + return true; // When achievements are properly implemented in Nukkit, + // change this to use Nukkit's API! } @Override @@ -1028,11 +1042,6 @@ public void setAllowFlight(boolean value) { nukkit.getAdventureSettings().setCanFly(value); } - @Override - public void setBanned(boolean value) { - nukkit.setBanned(value); - } - @Override public void setBedSpawnLocation(Location arg0) { throw Pokkit.unsupported(); diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitTeleportCause.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitTeleportCause.java index 02a185f..a5995da 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitTeleportCause.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitTeleportCause.java @@ -11,12 +11,15 @@ public final class PokkitTeleportCause { /** * Converts a Bukkit teleport cause to a Nukkit cause. * + * @param cause + * The Bukkit cause. + * * @return The Nukkit cause. */ public static TeleportCause toNukkit(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { switch (cause) { case COMMAND: - return TeleportCause.COMMAND; + return TeleportCause.COMMAND; case ENDER_PEARL: return TeleportCause.ENDER_PEARL; case NETHER_PORTAL: diff --git a/src/main/java/nl/rutgerkok/pokkit/plugin/PokkitPlugin.java b/src/main/java/nl/rutgerkok/pokkit/plugin/PokkitPlugin.java index bbbb602..842c76e 100644 --- a/src/main/java/nl/rutgerkok/pokkit/plugin/PokkitPlugin.java +++ b/src/main/java/nl/rutgerkok/pokkit/plugin/PokkitPlugin.java @@ -20,8 +20,6 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import com.avaje.ebean.EbeanServer; - import cn.nukkit.Server; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; @@ -55,11 +53,6 @@ public FileConfiguration getConfig() { throw Pokkit.unsupported(); } - @Override - public EbeanServer getDatabase() { - throw Pokkit.unsupported(); - } - @Override public File getDataFolder() { return nukkit.getDataFolder(); diff --git a/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitTeam.java b/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitTeam.java index 5bf19fb..82b6730 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitTeam.java +++ b/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitTeam.java @@ -10,6 +10,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Scoreboard; @@ -27,6 +28,7 @@ final class PokkitTeam implements Team { private String suffix = ""; private boolean allowFriendyFire; private boolean canSeeFriendlyInvisibles; + private ChatColor color = ChatColor.RESET; PokkitTeam(String name, PokkitScoreboard scoreboard) { this.name = Objects.requireNonNull(name); @@ -67,6 +69,12 @@ private PokkitScoreboard checkScoreboard() throws IllegalStateException { return scoreboard; } + @Override + public ChatColor getColor() throws IllegalStateException { + checkScoreboard(); + return color; + } + @Override public String getDisplayName() throws IllegalStateException { checkScoreboard(); @@ -179,6 +187,13 @@ public void setCanSeeFriendlyInvisibles(boolean enabled) throws IllegalStateExce this.canSeeFriendlyInvisibles = enabled; } + @Override + public void setColor(ChatColor color) { + Validate.notNull(color, "color"); + checkScoreboard(); + this.color = color; + } + @Override public void setDisplayName(String displayName) throws IllegalStateException, IllegalArgumentException { Validate.notNull(displayName, "displayName"); diff --git a/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java b/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java index d6803cb..5fee06d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java +++ b/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.scoreboard.DisplaySlot; @@ -92,6 +93,7 @@ private void loadTeam(ConfigurationSection config, Team team) { team.setOption(Option.DEATH_MESSAGE_VISIBILITY, toOptionStatus(config.getString("death_messages", ""))); team.setOption(Option.NAME_TAG_VISIBILITY, toOptionStatus(config.getString("name_tags", ""))); team.setAllowFriendlyFire(config.getBoolean("friendly_fire")); + team.setColor(toChatColor(config.getString("color", ""))); List members = config.getStringList("members"); if (members != null) { @@ -142,6 +144,15 @@ private void saveTeam(ConfigurationSection config, Team team) { config.set("name_tags", team.getOption(Option.NAME_TAG_VISIBILITY).name().toLowerCase()); config.set("friendly_fire", team.allowFriendlyFire()); config.set("members", new ArrayList<>(team.getEntries())); + config.set("color", team.getColor().name()); + } + + private ChatColor toChatColor(String string) { + try { + return ChatColor.valueOf(string.toUpperCase()); + } catch (IllegalArgumentException e) { + return ChatColor.RESET; + } } private OptionStatus toOptionStatus(String string) { diff --git a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java index bf080b3..e35f613 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java @@ -40,6 +40,7 @@ import org.bukkit.BanList; import org.bukkit.BanList.Type; import org.bukkit.GameMode; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.UnsafeValues; @@ -47,6 +48,7 @@ import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; +import org.bukkit.advancement.Advancement; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; @@ -78,7 +80,6 @@ import org.bukkit.scoreboard.ScoreboardManager; import org.bukkit.util.CachedServerIcon; -import com.avaje.ebean.config.ServerConfig; import com.google.common.collect.ImmutableMap; import cn.nukkit.level.Level; @@ -136,13 +137,14 @@ public CraftServer(cn.nukkit.Server nukkitServer, Logger logger, File pluginFold } @Override - public Player[] _INVALID_getOnlinePlayers() { - return nukkit.getOnlinePlayers().values().stream().map(PokkitPlayer::toBukkit).toArray(Player[]::new); + public boolean addRecipe(Recipe arg0) { + throw Pokkit.unsupported(); } @Override - public boolean addRecipe(Recipe arg0) { - throw Pokkit.unsupported(); + public Iterator advancementIterator() { + // Advancements not implemented + return Collections.emptyIterator(); } @Override @@ -180,12 +182,6 @@ public void clearRecipes() { } - @Override - public void configureDbConfig(ServerConfig arg0) { - throw Pokkit.unsupported(); - - } - @Override public BossBar createBossBar(String arg0, BarColor arg1, BarStyle arg2, BarFlag... arg3) { throw Pokkit.unsupported(); @@ -265,6 +261,12 @@ public boolean dispatchCommand(CommandSender sender, String command) throws Comm return nukkit.dispatchCommand(PokkitCommandSender.toNukkit(sender), command); } + @Override + public Advancement getAdvancement(NamespacedKey key) { + // Advancements not implemented + return null; + } + @Override public boolean getAllowEnd() { return false; @@ -694,6 +696,12 @@ public void reload() { nukkit.reload(); } + @Override + public void reloadData() { + // Are there more things we can reload, without reloading all plugins or worlds? + nukkit.reloadWhitelist(); + } + @Override public void reloadWhitelist() { nukkit.reloadWhitelist(); From 4619b1fad982ef260b2ce441a40f375cdc6a3964 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Thu, 4 Jan 2018 21:08:08 +0100 Subject: [PATCH 03/14] Add note about project status --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2992dd9..b8e2ad9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Pokkit [![Build Status](https://circleci.com/gh/rutgerkok/Pokkit.svg?style=shield)](https://circleci.com/gh/rutgerkok/Pokkit/tree/master) +|

Project status

| +|-------------------| +| Currently, Nukkit, on which this project depends, is not actively developed. Pokkit is of course still open for contributions, but I don't really expect any interest. The best option for running Bukkit plugins on Minecraft Pocket Edition (or equivalently, Bedrock Edition) currently seems to be Dragonet DragonProxy. | + The Minecraft multiplayer scene is fragmented. There are many competing server implementations. A popular server is [Spigot](http://www.spigotmc.org/). Spigot is able to load plugins, which can interact with Minecraft through the Spigot Plugin API. For Minecraft Pocket Edition, the mobile version of Minecraft, a server with a plugin API similar to Spigot exists: [Nukkit](https://forums.nukkit.io/). Unfortunately, plugins written for Spigot cannot run on Nukkit. Pokkit is a translation layer that allows plugins written for Spigot to work on Nukkit. However, it is far from perfect. Because of the size of the Spigot API, it is not possible for me to implement all of the Spigot API. From 9b36e971cefe9af725bc81ec52035f5d0a6ac27d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 8 Feb 2018 06:14:56 +1100 Subject: [PATCH 04/14] Update to latest nukkitx (#102) --- pom.xml | 4 +- .../java/nl/rutgerkok/pokkit/PokkitSound.java | 103 +++++++----------- .../pokkit/blockstate/PokkitBlockState.java | 1 - .../pokkit/entity/PokkitFakeEntity.java | 19 +--- .../pokkit/inventory/PokkitInventoryType.java | 2 + .../custom/NukkitCustomInventory.java | 4 +- .../rutgerkok/pokkit/player/PokkitPlayer.java | 22 ++-- .../rutgerkok/pokkit/world/PokkitWorld.java | 72 ++++-------- 8 files changed, 82 insertions(+), 145 deletions(-) diff --git a/pom.xml b/pom.xml index 0170d87..deeb040 100644 --- a/pom.xml +++ b/pom.xml @@ -54,8 +54,8 @@ - nukkit-repo - http://ci.regularbox.com/plugin/repository/everything/ + potestas-repo + https://repo.potestas.xyz/main/ spigot-repo diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java index 030ba2f..ca66b38 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java @@ -1,28 +1,9 @@ package nl.rutgerkok.pokkit; +import cn.nukkit.math.Vector3; import org.bukkit.Location; import org.bukkit.Sound; -import cn.nukkit.level.sound.AnvilBreakSound; -import cn.nukkit.level.sound.AnvilFallSound; -import cn.nukkit.level.sound.AnvilUseSound; -import cn.nukkit.level.sound.ClickSound; -import cn.nukkit.level.sound.DoorBumpSound; -import cn.nukkit.level.sound.DoorCrashSound; -import cn.nukkit.level.sound.DoorSound; -import cn.nukkit.level.sound.EndermanTeleportSound; -import cn.nukkit.level.sound.ExperienceOrbSound; -import cn.nukkit.level.sound.LevelEventSound; -import cn.nukkit.level.sound.GhastShootSound; -import cn.nukkit.level.sound.GhastSound; -import cn.nukkit.level.sound.LaunchSound; -import cn.nukkit.level.sound.LeverSound; -import cn.nukkit.level.sound.NoteBoxSound; -import cn.nukkit.level.sound.PopSound; -import cn.nukkit.level.sound.TNTPrimeSound; -import cn.nukkit.math.Vector3; -import cn.nukkit.network.protocol.LevelEventPacket; - /** * Sound conversion. Many sounds from PC cannot be played in PE, as far as I * know. @@ -30,28 +11,28 @@ */ public final class PokkitSound { - public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound sound, float pitch) { + public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, float pitch) { Vector3 vector = new Vector3(location.getX(), location.getY(), location.getZ()); switch (sound) { case AMBIENT_CAVE: break; case BLOCK_ANVIL_BREAK: - return new AnvilBreakSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_ANVIL_BREAK; case BLOCK_ANVIL_DESTROY: break; case BLOCK_ANVIL_FALL: - return new AnvilFallSound(vector, pitch); + break; case BLOCK_ANVIL_HIT: break; case BLOCK_ANVIL_LAND: - break; + return cn.nukkit.level.Sound.RANDOM_ANVIL_LAND; case BLOCK_ANVIL_PLACE: break; case BLOCK_ANVIL_STEP: break; case BLOCK_ANVIL_USE: - return new AnvilUseSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_ANVIL_USE; case BLOCK_BREWING_STAND_BREW: break; case BLOCK_CHEST_CLOSE: @@ -155,7 +136,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case BLOCK_LAVA_POP: break; case BLOCK_LEVER_CLICK: - return new LeverSound(vector, pitch > 0.6); + break; case BLOCK_METAL_BREAK: break; case BLOCK_METAL_FALL: @@ -171,17 +152,17 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case BLOCK_METAL_STEP: break; case BLOCK_NOTE_BASEDRUM: - return new NoteBoxSound(vector, NoteBoxSound.INSTRUMENT_BASS_DRUM, (int) (pitch * 16)); + return cn.nukkit.level.Sound.NOTE_BASSATTACK; case BLOCK_NOTE_BASS: - return new NoteBoxSound(vector, NoteBoxSound.INSTRUMENT_BASS, (int) (pitch * 16)); + return cn.nukkit.level.Sound.NOTE_BASS; case BLOCK_NOTE_HARP: - break; + return cn.nukkit.level.Sound.NOTE_HARP; case BLOCK_NOTE_HAT: - return new NoteBoxSound(vector, NoteBoxSound.INSTRUMENT_CLICK, (int) (pitch * 16)); + return cn.nukkit.level.Sound.NOTE_HAT; case BLOCK_NOTE_PLING: - return new NoteBoxSound(vector, NoteBoxSound.INSTRUMENT_PIANO, (int) (pitch * 16)); + return cn.nukkit.level.Sound.NOTE_PLING; case BLOCK_NOTE_SNARE: - return new NoteBoxSound(vector, NoteBoxSound.INSTRUMENT_TABOUR, (int) (pitch * 16)); + return cn.nukkit.level.Sound.NOTE_SNARE; case BLOCK_PISTON_CONTRACT: break; case BLOCK_PISTON_EXTEND: @@ -255,15 +236,15 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case BLOCK_WATER_AMBIENT: break; case BLOCK_WOODEN_DOOR_CLOSE: - break; + return cn.nukkit.level.Sound.RANDOM_DOOR_CLOSE; case BLOCK_WOODEN_DOOR_OPEN: - return new DoorSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_DOOR_OPEN; case BLOCK_WOODEN_TRAPDOOR_CLOSE: - break; + return cn.nukkit.level.Sound.RANDOM_DOOR_CLOSE; case BLOCK_WOODEN_TRAPDOOR_OPEN: - break; + return cn.nukkit.level.Sound.RANDOM_DOOR_OPEN; case BLOCK_WOOD_BREAK: - break; + return cn.nukkit.level.Sound.HIT_WOOD; case BLOCK_WOOD_BUTTON_CLICK_OFF: break; case BLOCK_WOOD_BUTTON_CLICK_ON: @@ -295,7 +276,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_ARROW_HIT_PLAYER: break; case ENTITY_ARROW_SHOOT: - return new LaunchSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_BOW; case ENTITY_BAT_AMBIENT: break; case ENTITY_BAT_DEATH: @@ -401,17 +382,17 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_ENDEREYE_LAUNCH: break; case ENTITY_ENDERMEN_AMBIENT: - break; + return cn.nukkit.level.Sound.MOB_ENDERMEN_IDLE; case ENTITY_ENDERMEN_DEATH: - break; + return cn.nukkit.level.Sound.MOB_ENDERMEN_DEATH; case ENTITY_ENDERMEN_HURT: - break; + return cn.nukkit.level.Sound.MOB_ENDERMEN_HIT; case ENTITY_ENDERMEN_SCREAM: - break; + return cn.nukkit.level.Sound.MOB_ENDERMEN_SCREAM; case ENTITY_ENDERMEN_STARE: - break; + return cn.nukkit.level.Sound.MOB_ENDERMEN_STARE; case ENTITY_ENDERMEN_TELEPORT: - return new EndermanTeleportSound(vector, pitch); + return cn.nukkit.level.Sound.MOB_ENDERMEN_PORTAL; case ENTITY_ENDERMITE_AMBIENT: break; case ENTITY_ENDERMITE_DEATH: @@ -425,7 +406,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_EXPERIENCE_BOTTLE_THROW: break; case ENTITY_EXPERIENCE_ORB_PICKUP: - return new ExperienceOrbSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_ORB; case ENTITY_FIREWORK_BLAST: break; case ENTITY_FIREWORK_BLAST_FAR: @@ -465,17 +446,17 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_GENERIC_SWIM: break; case ENTITY_GHAST_AMBIENT: - break; + return cn.nukkit.level.Sound.MOB_GHAST_AFFECTIONATE_SCREAM; case ENTITY_GHAST_DEATH: - break; + return cn.nukkit.level.Sound.MOB_GHAST_DEATH; case ENTITY_GHAST_HURT: - break; + return cn.nukkit.level.Sound.MOB_GHAST_MOAN; case ENTITY_GHAST_SCREAM: - return new GhastShootSound(vector, pitch); + return cn.nukkit.level.Sound.MOB_GHAST_SCREAM; case ENTITY_GHAST_SHOOT: - break; + return cn.nukkit.level.Sound.MOB_GHAST_FIREBALL; case ENTITY_GHAST_WARN: - return new GhastSound(vector, pitch); + return cn.nukkit.level.Sound.MOB_GHAST_CHARGE; case ENTITY_GUARDIAN_AMBIENT: break; case ENTITY_GUARDIAN_AMBIENT_LAND: @@ -547,15 +528,15 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_IRONGOLEM_STEP: break; case ENTITY_ITEMFRAME_ADD_ITEM: - return new LevelEventSound(vector, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_ITEM_ADDED, pitch); + return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_ADD_ITEM; case ENTITY_ITEMFRAME_BREAK: - return new LevelEventSound(vector, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_REMOVED, pitch); + return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_BREAK; case ENTITY_ITEMFRAME_PLACE: - return new LevelEventSound(vector, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_PLACED, pitch); + return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_PLACE; case ENTITY_ITEMFRAME_REMOVE_ITEM: - return new LevelEventSound(vector, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_ITEM_REMOVED, pitch); + return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_REMOVE_ITEM; case ENTITY_ITEMFRAME_ROTATE_ITEM: - return new LevelEventSound(vector, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_ITEM_ROTATED, pitch); + return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_ROTATE_ITEM; case ENTITY_ITEM_BREAK: break; case ENTITY_ITEM_PICKUP: @@ -707,7 +688,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_SKELETON_HURT: break; case ENTITY_SKELETON_SHOOT: - return new PopSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_BOW; case ENTITY_SKELETON_STEP: break; case ENTITY_SLIME_ATTACK: @@ -771,7 +752,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_STRAY_STEP: break; case ENTITY_TNT_PRIMED: - return new TNTPrimeSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_FUSE; case ENTITY_VILLAGER_AMBIENT: break; case ENTITY_VILLAGER_DEATH: @@ -835,11 +816,11 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case ENTITY_ZOMBIE_AMBIENT: break; case ENTITY_ZOMBIE_ATTACK_DOOR_WOOD: - return new DoorBumpSound(vector, pitch); + return cn.nukkit.level.Sound.MOB_ZOMBIE_WOOD; case ENTITY_ZOMBIE_ATTACK_IRON_DOOR: break; case ENTITY_ZOMBIE_BREAK_DOOR_WOOD: - return new DoorCrashSound(vector, pitch); + return cn.nukkit.level.Sound.MOB_ZOMBIE_WOODBREAK; case ENTITY_ZOMBIE_DEATH: break; case ENTITY_ZOMBIE_HORSE_AMBIENT: @@ -953,7 +934,7 @@ public static cn.nukkit.level.sound.Sound toNukkit(Location location, Sound soun case RECORD_WARD: break; case UI_BUTTON_CLICK: - return new ClickSound(vector, pitch); + return cn.nukkit.level.Sound.RANDOM_CLICK; case WEATHER_RAIN: break; case WEATHER_RAIN_ABOVE: diff --git a/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java b/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java index e212acb..ef06644 100644 --- a/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java +++ b/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java @@ -272,7 +272,6 @@ public final boolean update(boolean force, boolean applyPhysics) { ((BlockEntitySpawnable) blockEntity).spawnToAll(); if (blockEntity.chunk != null) { blockEntity.chunk.setChanged(); - blockEntity.level.clearChunkCache(blockEntity.chunk.getX(), blockEntity.chunk.getZ()); } return true; diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java index dc86c15..d37dfbd 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java @@ -1,21 +1,12 @@ package nl.rutgerkok.pokkit.entity; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import cn.nukkit.math.SimpleAxisAlignedBB; +import java.util.*; import java.util.stream.Collectors; - import nl.rutgerkok.pokkit.Pokkit; import nl.rutgerkok.pokkit.PokkitLocation; import nl.rutgerkok.pokkit.world.PokkitWorld; - -import org.bukkit.Bukkit; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.Entity; import org.bukkit.event.entity.EntityDamageEvent; @@ -27,8 +18,6 @@ import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; -import cn.nukkit.math.AxisAlignedBB; - abstract class PokkitFakeEntity implements Entity { @Override @@ -143,7 +132,7 @@ public String getName() { @Override public List getNearbyEntities(double x, double y, double z) { cn.nukkit.level.Location location = this.getNukkitLocation(); - cn.nukkit.entity.Entity[] found = location.level.getNearbyEntities(new AxisAlignedBB( + cn.nukkit.entity.Entity[] found = location.level.getNearbyEntities(new SimpleAxisAlignedBB( location.x - x, location.y - y, location.z - z, location.x + x, location.y + y, location.z + z)); diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java index 27ca048..bd296d0 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java @@ -31,6 +31,8 @@ public final class PokkitInventoryType { bukkitToNukkit.put(InventoryType.BEACON, cn.nukkit.inventory.InventoryType.ENCHANT_TABLE); bukkitToNukkit.put(InventoryType.CREATIVE, cn.nukkit.inventory.InventoryType.PLAYER); bukkitToNukkit.put(InventoryType.SHULKER_BOX, cn.nukkit.inventory.InventoryType.CHEST); + + nukkitToBukkit.put(cn.nukkit.inventory.InventoryType.CURSOR, InventoryType.PLAYER); // TODO wrong } /** diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java index c90555e..cfd27d5 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java @@ -56,7 +56,7 @@ private CompoundTag getSpawnCompound(Vector3 position) { public void onClose(Player player) { // Remove the fake chest block ContainerClosePacket closePacket = new ContainerClosePacket(); - closePacket.windowid = (byte) player.getWindowId(this); + closePacket.windowId = (byte) player.getWindowId(this); player.dataPacket(closePacket); Vector3 v = spawnedFakeChestBlocks.get(player.getName().toLowerCase()); @@ -103,7 +103,7 @@ public void onOpen(Player who) { // Open the chest ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); - containerOpenPacket.windowid = (byte) who.getWindowId(this); + containerOpenPacket.windowId = (byte) who.getWindowId(this); containerOpenPacket.type = (byte) this.getType().getNetworkType(); containerOpenPacket.x = (int) v.x; diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java index fb49a96..73c543d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java @@ -1,5 +1,6 @@ package nl.rutgerkok.pokkit.player; +import cn.nukkit.AdventureSettings; import java.net.InetSocketAddress; import java.util.Collection; import java.util.HashSet; @@ -11,11 +12,7 @@ import java.util.UUID; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitGameMode; -import nl.rutgerkok.pokkit.PokkitLocation; -import nl.rutgerkok.pokkit.PokkitSound; -import nl.rutgerkok.pokkit.UniqueIdConversion; +import nl.rutgerkok.pokkit.*; import nl.rutgerkok.pokkit.entity.PokkitHumanEntity; import nl.rutgerkok.pokkit.inventory.PokkitInventory; import nl.rutgerkok.pokkit.inventory.PokkitInventoryView; @@ -278,7 +275,7 @@ public void chat(String message) { @Override public void closeInventory() { - throw Pokkit.unsupported(); + nukkit.removeAllWindows(); } @Override @@ -354,7 +351,7 @@ public AdvancementProgress getAdvancementProgress(Advancement advancement) { @Override public boolean getAllowFlight() { - return nukkit.getAdventureSettings().canFly(); + return nukkit.getAdventureSettings().get(AdventureSettings.Type.ALLOW_FLIGHT); } @Override @@ -722,7 +719,7 @@ public boolean isConversing() { @Override public boolean isFlying() { - return nukkit.getAdventureSettings().canFly() && !nukkit.isOnGround(); + return nukkit.getAdventureSettings().get(AdventureSettings.Type.ALLOW_FLIGHT) && !nukkit.isOnGround(); } @Override @@ -875,11 +872,12 @@ public void playSound(Location location, Sound sound, SoundCategory category, fl return; } - cn.nukkit.level.sound.Sound nukkitSound = PokkitSound.toNukkit(location, sound, pitch); + cn.nukkit.level.Sound nukkitSound = PokkitSound.toNukkit(location, sound, pitch); if (nukkitSound == null) { return; } - nukkit.level.addSound(nukkitSound, nukkit); + Vector3 pos = PokkitVector.toNukkit(location.toVector()); + nukkit.level.addSound(pos, nukkitSound, volume, pitch); } @Override @@ -1039,7 +1037,7 @@ public Map serialize() { @Override public void setAllowFlight(boolean value) { - nukkit.getAdventureSettings().setCanFly(value); + nukkit.getAdventureSettings().set(AdventureSettings.Type.ALLOW_FLIGHT, value); } @Override @@ -1100,7 +1098,7 @@ public void setFireTicks(int fireTicks) { @Override public void setFlying(boolean flying) { - nukkit.getAdventureSettings().setFlying(flying); + nukkit.getAdventureSettings().set(AdventureSettings.Type.FLYING, flying); } diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java index 642d34a..c1dfffe 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java @@ -1,20 +1,21 @@ package nl.rutgerkok.pokkit.world; +import cn.nukkit.entity.weather.EntityLightning; +import cn.nukkit.level.Explosion; +import cn.nukkit.level.Level; +import cn.nukkit.level.Position; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.level.particle.GenericParticle; +import cn.nukkit.math.Vector3; +import cn.nukkit.nbt.tag.CompoundTag; +import cn.nukkit.nbt.tag.DoubleTag; +import cn.nukkit.nbt.tag.FloatTag; +import cn.nukkit.nbt.tag.ListTag; import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.SplittableRandom; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; - -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitLocation; -import nl.rutgerkok.pokkit.PokkitSound; -import nl.rutgerkok.pokkit.UniqueIdConversion; +import nl.rutgerkok.pokkit.*; import nl.rutgerkok.pokkit.entity.PokkitEntity; import nl.rutgerkok.pokkit.entity.PokkitEntityLightningStrike; import nl.rutgerkok.pokkit.entity.PokkitEntityTranslator; @@ -22,33 +23,11 @@ import nl.rutgerkok.pokkit.metadata.WorldMetadataStore; import nl.rutgerkok.pokkit.particle.PokkitParticle; import nl.rutgerkok.pokkit.player.PokkitPlayer; - -import org.bukkit.BlockChangeDelegate; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.ChunkSnapshot; -import org.bukkit.Difficulty; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.Sound; -import org.bukkit.SoundCategory; -import org.bukkit.TreeType; -import org.bukkit.World; -import org.bukkit.WorldBorder; -import org.bukkit.WorldType; +import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_99_R9.CraftServer; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Item; -import org.bukkit.entity.LightningStrike; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.bukkit.inventory.ItemStack; @@ -58,18 +37,6 @@ import org.bukkit.util.Consumer; import org.bukkit.util.Vector; -import cn.nukkit.entity.weather.EntityLightning; -import cn.nukkit.level.Explosion; -import cn.nukkit.level.Level; -import cn.nukkit.level.format.generic.BaseFullChunk; -import cn.nukkit.level.particle.GenericParticle; -import cn.nukkit.level.Position; -import cn.nukkit.math.Vector3; -import cn.nukkit.nbt.tag.CompoundTag; -import cn.nukkit.nbt.tag.DoubleTag; -import cn.nukkit.nbt.tag.FloatTag; -import cn.nukkit.nbt.tag.ListTag; - public final class PokkitWorld implements World { private static final int WORLD_HEIGHT = 256; @@ -373,7 +340,7 @@ public List getLivingEntities() { public Chunk[] getLoadedChunks() { ArrayList loadedChunks = new ArrayList<>(); - for (BaseFullChunk chunk : nukkit.getChunks().values()) { + for (FullChunk chunk : nukkit.getChunks().values()) { if (chunk.isLoaded()) { loadedChunks.add(new PokkitChunk(PokkitWorld.toBukkit(nukkit), chunk.getX(), chunk.getZ())); } @@ -593,11 +560,12 @@ public void playSound(Location location, Sound sound, float volume, float pitch) return; } - cn.nukkit.level.sound.Sound nukkitSound = PokkitSound.toNukkit(location, sound, pitch); + cn.nukkit.level.Sound nukkitSound = PokkitSound.toNukkit(location, sound, pitch); if (nukkitSound == null) { return; } - nukkit.addSound(nukkitSound); + Vector3 pos = PokkitVector.toNukkit(location.toVector()); + nukkit.addSound(pos, nukkitSound, volume, pitch); } @Override From c1375de62a8bd30133ea73c32967f3b09c5b64aa Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sat, 28 Apr 2018 15:40:43 +0200 Subject: [PATCH 05/14] Update to latest NukkitX and Spigot --- pom.xml | 2 +- .../java/nl/rutgerkok/pokkit/PokkitSound.java | 2 - .../pokkit/entity/PokkitLivingEntity.java | 27 ---- .../inventory/PokkitPlayerInventory.java | 2 +- .../custom/NukkitCustomInventory.java | 4 +- .../rutgerkok/pokkit/player/PokkitPlayer.java | 54 ++++++- .../pokkit/pluginservice/InventoryEvents.java | 8 +- .../pokkit/scheduler/PokkitTask.java | 5 + .../rutgerkok/pokkit/world/PokkitBlock.java | 13 +- .../pokkit/world/PokkitChunkSnapshot.java | 68 +++++---- .../rutgerkok/pokkit/world/PokkitWorld.java | 138 ++++++++++++------ 11 files changed, 198 insertions(+), 125 deletions(-) diff --git a/pom.xml b/pom.xml index deeb040..94dec2a 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.spigotmc spigot-api - 1.12-R0.1-SNAPSHOT + 1.12.2-R0.1-SNAPSHOT compile diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java index ca66b38..f39f485 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java @@ -1,6 +1,5 @@ package nl.rutgerkok.pokkit; -import cn.nukkit.math.Vector3; import org.bukkit.Location; import org.bukkit.Sound; @@ -13,7 +12,6 @@ public final class PokkitSound { public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, float pitch) { - Vector3 vector = new Vector3(location.getX(), location.getY(), location.getZ()); switch (sound) { case AMBIENT_CAVE: break; diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java index b8c943c..b7730dd 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java @@ -2,9 +2,7 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import nl.rutgerkok.pokkit.Pokkit; @@ -138,11 +136,6 @@ public double getLastDamage() { return nukkit.getLastDamageCause().getFinalDamage(); } - @Override - public List getLastTwoTargetBlocks(HashSet transparent, int maxDistance) { - throw Pokkit.unsupported(); - } - @Override public List getLastTwoTargetBlocks(Set transparent, int maxDistance) { throw Pokkit.unsupported(); @@ -201,13 +194,6 @@ public boolean getRemoveWhenFarAway() { throw Pokkit.unsupported(); } - @Override - public Block getTargetBlock(HashSet bukkitTransparent, int maxDistance) { - cn.nukkit.block.Block nukkitBlock = nukkit.getTargetBlock(maxDistance, toNukkitBlockIds(bukkitTransparent)); - - return PokkitBlock.toBukkit(nukkitBlock); - } - @Override public Block getTargetBlock(Set bukkitTransparent, int maxDistance) { cn.nukkit.block.Block nukkitBlock = nukkit.getTargetBlock(maxDistance, toNukkitBlockIds(bukkitTransparent)); @@ -344,19 +330,6 @@ public void setRemoveWhenFarAway(boolean remove) { throw Pokkit.unsupported(); } - @SuppressWarnings("deprecation") - private Integer[] toNukkitBlockIds(HashSet bukkitMaterials) { - if (bukkitMaterials == null) { - // Bukkit JavaDocs: "set to null for only air" - return new Integer[cn.nukkit.block.Block.AIR]; - } - return bukkitMaterials.stream() - .map(id -> Material.getMaterial(id)) - .filter(Objects::nonNull) - .map(material -> Integer.valueOf(PokkitMaterialData.fromBukkit(material, 0).getNukkitId())) - .toArray(Integer[]::new); - } - private Integer[] toNukkitBlockIds(Set bukkitMaterials) { if (bukkitMaterials == null) { return new Integer[cn.nukkit.block.Block.AIR]; diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java index 310ce1b..503c5a1 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java @@ -53,7 +53,7 @@ public ItemStack[] getExtraContents() { @Override public int getHeldItemSlot() { - return nukkit().getHeldItemSlot(); + return nukkit().getHeldItemIndex(); } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java index cfd27d5..ccc858d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java @@ -6,6 +6,7 @@ import java.util.Objects; import cn.nukkit.Player; +import cn.nukkit.block.GlobalBlockPalette; import cn.nukkit.inventory.BaseInventory; import cn.nukkit.inventory.InventoryType; import cn.nukkit.item.Item; @@ -82,8 +83,7 @@ public void onOpen(Player who) { updateBlockPacket.x = (int) v.x; updateBlockPacket.y = (int) v.y; updateBlockPacket.z = (int) v.z; - updateBlockPacket.blockId = Item.CHEST; - updateBlockPacket.blockData = 0; + updateBlockPacket.blockRuntimeId = GlobalBlockPalette.getOrCreateRuntimeId(Item.CHEST, 0); updateBlockPacket.flags = UpdateBlockPacket.FLAG_ALL_PRIORITY; who.dataPacket(updateBlockPacket); diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java index 73c543d..858ba7d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java @@ -1,6 +1,5 @@ package nl.rutgerkok.pokkit.player; -import cn.nukkit.AdventureSettings; import java.net.InetSocketAddress; import java.util.Collection; import java.util.HashSet; @@ -12,7 +11,12 @@ import java.util.UUID; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.*; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitGameMode; +import nl.rutgerkok.pokkit.PokkitLocation; +import nl.rutgerkok.pokkit.PokkitSound; +import nl.rutgerkok.pokkit.PokkitVector; +import nl.rutgerkok.pokkit.UniqueIdConversion; import nl.rutgerkok.pokkit.entity.PokkitHumanEntity; import nl.rutgerkok.pokkit.inventory.PokkitInventory; import nl.rutgerkok.pokkit.inventory.PokkitInventoryView; @@ -63,6 +67,8 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.scoreboard.Scoreboard; +import cn.nukkit.AdventureSettings; +import cn.nukkit.block.GlobalBlockPalette; import cn.nukkit.event.player.PlayerChatEvent; import cn.nukkit.level.particle.GenericParticle; import cn.nukkit.math.Vector3; @@ -95,6 +101,15 @@ public static cn.nukkit.Player toNukkit(Player player) { private InetSocketAddress address; public int lastItemSlot = ITEM_SLOT_NOT_INITIALIZED; + /** + * All plugin classes that currently request the player to be hidden. If + * this set is empty, the player can be shown again. + * + * @see #hidePlayer(Plugin, Player) + * @see #showPlayer(Plugin, Player) + */ + private final Set> hidingRequests = new HashSet<>(); + public PokkitPlayer(cn.nukkit.Player player) { super(player); this.nukkit = Objects.requireNonNull(player); @@ -665,9 +680,21 @@ public boolean hasPlayedBefore() { return nukkit.hasPlayedBefore(); } + private void hidePlayer(Class responsible, Player player) { + this.hidingRequests.add(responsible); + nukkit.hidePlayer(PokkitPlayer.toNukkit(player)); + } + @Override + @Deprecated public void hidePlayer(Player player) { - nukkit.hidePlayer(PokkitPlayer.toNukkit(player)); + // No information available on which plugin requested the hide, so just use our own class as a stand-in + hidePlayer(PokkitPlayer.class, player); + } + + @Override + public void hidePlayer(Plugin plugin, Player player) { + hidePlayer(plugin.getClass(), player); } @Override @@ -966,8 +993,7 @@ public void sendBlockChange(Location location, Material material, byte blockData packet.x = x; packet.y = y; packet.z = z; - packet.blockId = nukkitBlockId; - packet.blockData = nukkitBlockData; + packet.blockRuntimeId = GlobalBlockPalette.getOrCreateRuntimeId(nukkitBlockId, nukkitBlockData); packet.flags = flags; nukkit.dataPacket(packet, false); } @@ -1258,9 +1284,23 @@ public void setWhitelisted(boolean value) { nukkit.setWhitelisted(value); } + private void showPlayer(Class clazz, Player player) { + this.hidingRequests.remove(clazz); + if (this.hidingRequests.isEmpty()) { + nukkit.showPlayer(PokkitPlayer.toNukkit(player)); + } + } + + @Override + @Deprecated + public void showPlayer(Player player) { + // No information available on which plugin was responsible, so just use our own class as a stand-in + showPlayer(PokkitPlayer.class, player); + } + @Override - public void showPlayer(Player arg0) { - nukkit.showPlayer(PokkitPlayer.toNukkit(arg0)); + public void showPlayer(Plugin plugin, Player player) { + showPlayer(plugin.getClass(), player); } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/pluginservice/InventoryEvents.java b/src/main/java/nl/rutgerkok/pokkit/pluginservice/InventoryEvents.java index bc3ab8b..5047be1 100644 --- a/src/main/java/nl/rutgerkok/pokkit/pluginservice/InventoryEvents.java +++ b/src/main/java/nl/rutgerkok/pokkit/pluginservice/InventoryEvents.java @@ -124,13 +124,13 @@ public void onItemHeld(cn.nukkit.event.player.PlayerItemHeldEvent event) { PokkitPlayer player = PokkitPlayer.toBukkit(event.getPlayer()); int previousSlot = player.lastItemSlot; if (previousSlot == PokkitPlayer.ITEM_SLOT_NOT_INITIALIZED) { - previousSlot = event.getInventorySlot(); + previousSlot = event.getSlot(); } - player.lastItemSlot = event.getInventorySlot(); + player.lastItemSlot = event.getSlot(); - if (previousSlot != event.getInventorySlot()) { - PlayerItemHeldEvent bukkitEvent = new PlayerItemHeldEvent(player, previousSlot, event.getInventorySlot()); + if (previousSlot != event.getSlot()) { + PlayerItemHeldEvent bukkitEvent = new PlayerItemHeldEvent(player, previousSlot, event.getSlot()); callCancellable(event, bukkitEvent); } } diff --git a/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitTask.java b/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitTask.java index 709d8b8..b4d75fd 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitTask.java +++ b/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitTask.java @@ -32,6 +32,11 @@ public int getTaskId() { return nukkit.getTaskId(); } + @Override + public boolean isCancelled() { + return nukkit.isCancelled(); + } + @Override public boolean isSync() { return !nukkit.isAsynchronous(); diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java index 196e089..dcea108 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java @@ -29,6 +29,7 @@ import cn.nukkit.block.BlockAir; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBlock; +import cn.nukkit.level.biome.EnumBiome; /** * Converts between Nukkit and Bukkit blocks. @@ -147,9 +148,7 @@ public BlockFace getFace(Block block) { @Override public double getHumidity() { - int biomeId = nukkit.getLevel().getBiomeId((int) nukkit.x, (int) nukkit.z); - cn.nukkit.level.generator.biome.Biome biome = cn.nukkit.level.generator.biome.Biome.getBiome(biomeId); - return biome.getRainfall(); + return 0.15; // Seems to be removed from Nukkit } @Override @@ -217,8 +216,12 @@ public BlockState getState() { @Override public double getTemperature() { int biomeId = nukkit.getLevel().getBiomeId((int) nukkit.x, (int) nukkit.z); - cn.nukkit.level.generator.biome.Biome biome = cn.nukkit.level.generator.biome.Biome.getBiome(biomeId); - return biome.getTemperature(); + @SuppressWarnings("deprecation") + cn.nukkit.level.biome.Biome biome = EnumBiome.getBiome(biomeId); + if (biome != null && biome.isFreezing()) { + return 0.1; + } + return 0.6; } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java index 5487af7..2a0c587 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java @@ -1,8 +1,10 @@ package nl.rutgerkok.pokkit.world; import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.material.PokkitMaterialData; import org.bukkit.ChunkSnapshot; +import org.bukkit.Material; import org.bukkit.block.Biome; import cn.nukkit.level.format.generic.BaseFullChunk; @@ -12,9 +14,11 @@ public class PokkitChunkSnapshot implements ChunkSnapshot { private final int z; private final String worldname; // X, Y, Z - private int[][][] blocksIds = new int[16][256][16]; + private Material[][][] blocksIds = new Material[16][256][16]; private int[][][] blocksData = new int[16][256][16]; - + + BaseFullChunk nukkit; + public PokkitChunkSnapshot(final int x, final int z, final String wname, BaseFullChunk baseFullChunk) { this.nukkit = baseFullChunk; this.x = x; @@ -26,48 +30,50 @@ public PokkitChunkSnapshot(final int x, final int z, final String wname, BaseFul for (int blockX = 0; blockX < 16; blockX++) { for (int blockY = 0; blockY < 255; blockY++) { for (int blockZ = 0; blockZ < 16; blockZ++) { - blocksIds[blockX][blockY][blockZ] = baseFullChunk.getBlockId(blockX, blockY, blockZ); - blocksData[blockX][blockY][blockZ] = baseFullChunk.getBlockData(blockX, blockY, blockZ); + @SuppressWarnings("deprecation") + PokkitMaterialData data = PokkitMaterialData.fromNukkit(baseFullChunk.getBlockId(blockX, blockY, blockZ), baseFullChunk.getBlockData(blockX, blockY, blockZ)); + blocksIds[blockX][blockY][blockZ] = data.getBukkitMaterial(); + blocksData[blockX][blockY][blockZ] = data.getBukkitDamage(); } } } } - - BaseFullChunk nukkit; - + @Override - public int getX() { - return x; + public Biome getBiome(int x, int z) { + return Biome.PLAINS; } @Override - public int getZ() { - return z; + public int getBlockData(int x, int y, int z) { + return blocksData[x][y][z]; } @Override - public String getWorldName() { - return worldname; + public int getBlockEmittedLight(int x, int y, int z) { + throw Pokkit.unsupported(); } @Override - public int getBlockTypeId(int x, int y, int z) { - return blocksIds[x][y][z]; + public int getBlockSkyLight(int x, int y, int z) { + return nukkit.getBlockSkyLight(x, y, z); } @Override - public int getBlockData(int x, int y, int z) { - return blocksData[x][y][z]; + public Material getBlockType(int x, int y, int z) { + return blocksIds[x][y][z]; } @Override - public int getBlockSkyLight(int x, int y, int z) { - return nukkit.getBlockSkyLight(x, y, z); + @Deprecated + public int getBlockTypeId(int x, int y, int z) { + return blocksIds[x][y][z].getId(); } @Override - public int getBlockEmittedLight(int x, int y, int z) { + public long getCaptureFullTime() { throw Pokkit.unsupported(); + } @Override @@ -76,26 +82,30 @@ public int getHighestBlockYAt(int x, int z) { } @Override - public Biome getBiome(int x, int z) { - return Biome.PLAINS; + public double getRawBiomeRainfall(int x, int z) { + throw Pokkit.unsupported(); + } @Override public double getRawBiomeTemperature(int x, int z) { throw Pokkit.unsupported(); - + } @Override - public double getRawBiomeRainfall(int x, int z) { - throw Pokkit.unsupported(); - + public String getWorldName() { + return worldname; } @Override - public long getCaptureFullTime() { - throw Pokkit.unsupported(); - + public int getX() { + return x; + } + + @Override + public int getZ() { + return z; } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java index c1dfffe..92a05ff 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java @@ -1,5 +1,50 @@ package nl.rutgerkok.pokkit.world; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.SplittableRandom; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.ChunkSnapshot; +import org.bukkit.Difficulty; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; +import org.bukkit.TreeType; +import org.bukkit.World; +import org.bukkit.WorldBorder; +import org.bukkit.WorldType; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_99_R9.CraftServer; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Item; +import org.bukkit.entity.LightningStrike; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.Plugin; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + import cn.nukkit.entity.weather.EntityLightning; import cn.nukkit.level.Explosion; import cn.nukkit.level.Level; @@ -12,10 +57,12 @@ import cn.nukkit.nbt.tag.DoubleTag; import cn.nukkit.nbt.tag.FloatTag; import cn.nukkit.nbt.tag.ListTag; -import java.io.File; -import java.util.*; -import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.*; + +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitLocation; +import nl.rutgerkok.pokkit.PokkitSound; +import nl.rutgerkok.pokkit.PokkitVector; +import nl.rutgerkok.pokkit.UniqueIdConversion; import nl.rutgerkok.pokkit.entity.PokkitEntity; import nl.rutgerkok.pokkit.entity.PokkitEntityLightningStrike; import nl.rutgerkok.pokkit.entity.PokkitEntityTranslator; @@ -23,19 +70,6 @@ import nl.rutgerkok.pokkit.metadata.WorldMetadataStore; import nl.rutgerkok.pokkit.particle.PokkitParticle; import nl.rutgerkok.pokkit.player.PokkitPlayer; -import org.bukkit.*; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_99_R9.CraftServer; -import org.bukkit.entity.*; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.Consumer; -import org.bukkit.util.Vector; public final class PokkitWorld implements World { @@ -80,6 +114,21 @@ public boolean canGenerateStructures() { return false; } + @Override + public boolean createExplosion(double x, double y, double z, float power) { + return this.createExplosion(null, x, y, z, power, false, true); + } + + @Override + public boolean createExplosion(double x, double y, double z, float power, boolean setFire) { + return this.createExplosion(null, x, y, z, power, setFire, true); + } + + @Override + public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks) { + return this.createExplosion(null, x, y, z, power, setFire, breakBlocks); + } + private boolean createExplosion(Level level, double x, double y, double z, float power, boolean setFire, boolean breakBlocks) { // Base function called by all other createExplosion functions // Nukkit does not yet support setFire @@ -97,21 +146,6 @@ private boolean createExplosion(Level level, double x, double y, double z, float return true; } - @Override - public boolean createExplosion(double x, double y, double z, float power) { - return this.createExplosion(null, x, y, z, power, false, true); - } - - @Override - public boolean createExplosion(double x, double y, double z, float power, boolean setFire) { - return this.createExplosion(null, x, y, z, power, setFire, true); - } - - @Override - public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks) { - return this.createExplosion(null, x, y, z, power, setFire, breakBlocks); - } - @Override public boolean createExplosion(Location loc, float power) { cn.nukkit.level.Location l = PokkitLocation.toNukkit(loc); @@ -127,13 +161,13 @@ public boolean createExplosion(Location loc, float power, boolean setFire) { @Override public Item dropItem(Location location, ItemStack item) { nukkit.dropItem(PokkitLocation.toNukkit(location), PokkitItemStack.toNukkitCopy(item), new Vector3(0, 0, 0)); - return null; // TODO add entity support + return null; // Add entity support } @Override public Item dropItemNaturally(Location location, ItemStack item) { nukkit.dropItem(PokkitLocation.toNukkit(location), PokkitItemStack.toNukkitCopy(item)); - return null; // TODO add entity support + return null; // Add entity support } @Override @@ -143,7 +177,8 @@ public boolean generateTree(Location location, TreeType type) { } @Override - public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { + @Deprecated + public boolean generateTree(Location loc, TreeType type, org.bukkit.BlockChangeDelegate delegate) { throw Pokkit.unsupported(); } @@ -326,13 +361,13 @@ public Set getListeningPluginChannels() { @Override public List getLivingEntities() { List livingEntities = new ArrayList<>(); - + for (cn.nukkit.entity.Entity entity : nukkit.getEntities()) { if (entity instanceof cn.nukkit.entity.EntityLiving) { livingEntities.add((LivingEntity) PokkitEntity.toBukkit(entity)); } } - + return livingEntities; } @@ -535,22 +570,22 @@ public boolean loadChunk(int x, int z, boolean generate) { @Override public void playEffect(Location location, Effect effect, int data) { - return; // TODO: Implement particles + return; // Implement particles } @Override public void playEffect(Location location, Effect effect, int data, int radius) { - return; // TODO: Implement particles + return; // Implement particles } @Override public void playEffect(Location location, Effect effect, T data) { - return; // TODO: Implement particles + return; // Implement particles } @Override public void playEffect(Location location, Effect effect, T data, int radius) { - return; // TODO: Implement particles + return; // Implement particles } @@ -570,8 +605,8 @@ public void playSound(Location location, Sound sound, float volume, float pitch) @Override public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) { - // TODO Auto-generated method stub - + // Ignore the category + playSound(location, sound, volume, pitch); } @Override @@ -589,8 +624,8 @@ public void playSound(Location location, String soundString, float volume, float @Override public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch) { - // TODO Auto-generated method stub - + // Ignore the category + playSound(location, sound, volume, pitch); } @Override @@ -696,6 +731,15 @@ public boolean setSpawnLocation(int x, int y, int z) { return true; } + @Override + public boolean setSpawnLocation(Location location) { + if (!location.getWorld().equals(this)) { + return false; + } + nukkit.setSpawnLocation(PokkitLocation.toNukkit(location)); + return true; + } + @Override public void setStorm(boolean hasStorm) { // Silently unsupported! @@ -951,12 +995,12 @@ public boolean unloadChunk(int x, int z) { @Override public boolean unloadChunk(int x, int z, boolean save) { - return nukkit.unloadChunk(x, z); // TODO: Save + return nukkit.unloadChunk(x, z, true, save); } @Override public boolean unloadChunk(int x, int z, boolean save, boolean safe) { - return nukkit.unloadChunk(x, z, safe); // TODO: Save + return nukkit.unloadChunk(x, z, safe, save); } @Override From e99536bb694db0a469438ff17637b96d86737ea6 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sat, 28 Apr 2018 15:57:34 +0200 Subject: [PATCH 06/14] Map WEARABLE enchantment target BREAKABLE at least includes everything that WEARABLE also includes, I think. --- .../rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java index 82e99d5..72d96c5 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java @@ -25,6 +25,9 @@ public class PokkitEnchantmentTarget { twoWay(EnchantmentType.DIGGER, EnchantmentTarget.TOOL); twoWay(EnchantmentType.FISHING_ROD, EnchantmentTarget.FISHING_ROD); twoWay(EnchantmentType.SWORD, EnchantmentTarget.WEAPON); + + // For WEARABLE, no suitable Nukkit target exists yet + bukkitToNukkit.put(EnchantmentTarget.WEARABLE, EnchantmentType.BREAKABLE); } /** From 395cbff0a962e757daa9c6f772b8f034d8f854e4 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sat, 30 Jun 2018 10:33:51 +0200 Subject: [PATCH 07/14] Remove outdated CircleCi 1 config, add Travis config --- .travis.yml | 5 +++++ circle.yml | 16 ---------------- 2 files changed, 5 insertions(+), 16 deletions(-) create mode 100644 .travis.yml delete mode 100644 circle.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d1a5335 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: java +jdk: + - oraclejdk8 + - oraclejdk9 + - openjdk8 \ No newline at end of file diff --git a/circle.yml b/circle.yml deleted file mode 100644 index b20afaf..0000000 --- a/circle.yml +++ /dev/null @@ -1,16 +0,0 @@ -machine: - java: - version: oraclejdk8 - -checkout: - post: - - git submodule sync - - git submodule update --init - - mvn clean - - mvn package - - cp -R ./target/pokkit*.jar $CIRCLE_ARTIFACTS - -test: - post: - - mkdir -p $CIRCLE_TEST_REPORTS/junit/ - - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; From 9bc378d05e11e48fdc0a03ca14c3bbf4aacdc67d Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sat, 30 Jun 2018 10:42:15 +0200 Subject: [PATCH 08/14] Update for Nukkit SHULKER_BOX support --- .../java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java index bd296d0..e622087 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java @@ -26,11 +26,11 @@ public final class PokkitInventoryType { twoWay(cn.nukkit.inventory.InventoryType.PLAYER, InventoryType.PLAYER); twoWay(cn.nukkit.inventory.InventoryType.WORKBENCH, InventoryType.WORKBENCH); twoWay(cn.nukkit.inventory.InventoryType.ENDER_CHEST, InventoryType.ENDER_CHEST); + twoWay(cn.nukkit.inventory.InventoryType.SHULKER_BOX, InventoryType.SHULKER_BOX); bukkitToNukkit.put(InventoryType.MERCHANT, cn.nukkit.inventory.InventoryType.ANVIL); bukkitToNukkit.put(InventoryType.BEACON, cn.nukkit.inventory.InventoryType.ENCHANT_TABLE); bukkitToNukkit.put(InventoryType.CREATIVE, cn.nukkit.inventory.InventoryType.PLAYER); - bukkitToNukkit.put(InventoryType.SHULKER_BOX, cn.nukkit.inventory.InventoryType.CHEST); nukkitToBukkit.put(cn.nukkit.inventory.InventoryType.CURSOR, InventoryType.PLAYER); // TODO wrong } From bd7a5958d6ccc04564106ed70e2784701f7bbaf1 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sat, 30 Jun 2018 10:46:38 +0200 Subject: [PATCH 09/14] Update build badge and contributors --- README.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b8e2ad9..b824e4a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Pokkit [![Build Status](https://circleci.com/gh/rutgerkok/Pokkit.svg?style=shield)](https://circleci.com/gh/rutgerkok/Pokkit/tree/master) +# Pokkit [![Build Status](https://travis-ci.org/rutgerkok/Pokkit.svg?branch=master)](https://travis-ci.org/rutgerkok/Pokkit) |

Project status

| |-------------------| @@ -47,20 +47,24 @@ Contributions are very much welcomed. If you have any questions, feel free to se Before you start, please read the [contribution guidelines](./CONTRIBUTING.md). I hope to be able to add your name to the list below soon! -### Contributed code since 2017 -* [Ankit](//github.com/AnkitM252) -* [Langsdorf](//github.com/Langsdorf) -* [MrPowerGamerBR](//github.com/MrPowerGamerBR) -* [NycuRO](//github.com/NycuRO) -* [PikyCZ](//github.com/PikyCZ) -* [RaynLegends](//github.com/RaynLegends) -* [Rutger Kok](//github.com/rutgerkok) -* [SuperAlecs](//github.com/SuperAlecs) +### Contributed code since 2018 +* [Jesse Boyd](https://github.com/boy0001) +* [Rutger Kok](https://github.com/rutgerkok) + +### Contributed code in 2017 +* [Ankit](https://github.com/AnkitM252) +* [Langsdorf](https://github.com/Langsdorf) +* [MrPowerGamerBR](https://github.com/MrPowerGamerBR) +* [NycuRO](https://github.com/NycuRO) +* [PikyCZ](https://github.com/PikyCZ) +* [RaynLegends](https://github.com/RaynLegends) +* [Rutger Kok](https://github.com/rutgerkok) +* [SuperAlecs](https://github.com/SuperAlecs) ### Contributed code in 2016 -* [daveboden](//github.com/daveboden) -* [Langsdorf](//github.com/Langsdorf) -* [MrPowerGamerBR](//github.com/MrPowerGamerBR) -* [OliverUv](//github.com/OliverUv) -* [Rutger Kok](//github.com/rutgerkok) -* [ZINGDING](//github.com/ZINGDING) +* [daveboden](https://github.com/daveboden) +* [Langsdorf](https://github.com/Langsdorf) +* [MrPowerGamerBR](https://github.com/MrPowerGamerBR) +* [OliverUv](https://github.com/OliverUv) +* [Rutger Kok](https://github.com/rutgerkok) +* [ZINGDING](https://github.com/ZINGDING) From 529125fab403ccb07383e99de8141392b56160f0 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sun, 26 Aug 2018 13:41:30 +0200 Subject: [PATCH 10/14] Update to Bukkit 1.13.1 --- pom.xml | 2 +- .../java/nl/rutgerkok/pokkit/PokkitSound.java | 754 +++++++++++++----- .../nl/rutgerkok/pokkit/PokkitUnsafe.java | 63 +- .../rutgerkok/pokkit/blockdata/BlockMap.java | 556 +++++++++++++ .../pokkit/blockdata/PokkitBlockData.java | 135 ++++ .../pokkit/blockstate/PlainBlockState.java | 5 +- .../pokkit/blockstate/PokkitBlockState.java | 77 +- .../pokkit/blockstate/SignBlockState.java | 8 +- .../pokkit/enchantment/PokkitEnchantment.java | 22 +- .../enchantment/PokkitEnchantmentImpl.java | 9 +- .../enchantment/PokkitEnchantmentTarget.java | 3 +- .../rutgerkok/pokkit/entity/PokkitEntity.java | 29 +- .../pokkit/entity/PokkitFakeEntity.java | 33 +- .../pokkit/entity/PokkitItemEntity.java | 6 +- .../pokkit/entity/PokkitLivingEntity.java | 31 +- .../inventory/PokkitAbstractInventory.java | 53 +- .../pokkit/inventory/PokkitLiveInventory.java | 26 +- .../inventory/PokkitPlayerInventory.java | 10 +- .../nl/rutgerkok/pokkit/item/ItemMap.java | 453 +++++++++++ .../pokkit/item/PokkitBlockStateMeta.java | 8 +- .../pokkit/item/PokkitItemFactory.java | 91 ++- .../rutgerkok/pokkit/item/PokkitItemMeta.java | 36 +- .../pokkit/item/PokkitItemStack.java | 33 +- .../pokkit/item/PokkitLeatherArmorMeta.java | 24 +- .../pokkit/item/PokkitPotionMeta.java | 8 +- .../pokkit/material/PokkitMaterialData.java | 119 --- .../pokkit/particle/PokkitParticle.java | 114 ++- .../rutgerkok/pokkit/player/PokkitPlayer.java | 102 ++- .../pluginservice/MainScoreboardService.java | 7 +- .../pokkit/potion/PokkitPotionEffect.java | 4 +- .../pokkit/scheduler/PokkitScheduler.java | 11 +- .../pokkit/scoreboard/PokkitScoreboard.java | 10 +- .../scoreboard/ScoreboardPersister.java | 2 +- .../rutgerkok/pokkit/world/PokkitBlock.java | 110 +-- .../pokkit/world/PokkitChunkSnapshot.java | 40 +- .../pokkit/world/PokkitGameRule.java | 42 + .../rutgerkok/pokkit/world/PokkitWorld.java | 133 ++- .../craftbukkit/v1_99_R9/CraftServer.java | 91 ++- .../rutgerkok/pokkit/inventory/ItemTest.java | 5 + .../pokkit/world/PokkitMaterialTest.java | 23 +- 40 files changed, 2411 insertions(+), 877 deletions(-) create mode 100644 src/main/java/nl/rutgerkok/pokkit/blockdata/BlockMap.java create mode 100644 src/main/java/nl/rutgerkok/pokkit/blockdata/PokkitBlockData.java create mode 100644 src/main/java/nl/rutgerkok/pokkit/item/ItemMap.java delete mode 100644 src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java create mode 100644 src/main/java/nl/rutgerkok/pokkit/world/PokkitGameRule.java create mode 100644 src/test/java/nl/rutgerkok/pokkit/inventory/ItemTest.java diff --git a/pom.xml b/pom.xml index 94dec2a..7aea07c 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.spigotmc spigot-api - 1.12.2-R0.1-SNAPSHOT + 1.13.1-R0.1-SNAPSHOT compile diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java index f39f485..ed099c1 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java @@ -43,16 +43,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_CHORUS_FLOWER_GROW: break; - case BLOCK_CLOTH_BREAK: - break; - case BLOCK_CLOTH_FALL: - break; - case BLOCK_CLOTH_HIT: - break; - case BLOCK_CLOTH_PLACE: - break; - case BLOCK_CLOTH_STEP: - break; case BLOCK_COMPARATOR_CLICK: break; case BLOCK_DISPENSER_DISPENSE: @@ -63,10 +53,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_ENCHANTMENT_TABLE_USE: break; - case BLOCK_ENDERCHEST_CLOSE: - break; - case BLOCK_ENDERCHEST_OPEN: - break; case BLOCK_END_GATEWAY_SPAWN: break; case BLOCK_FENCE_GATE_CLOSE: @@ -143,23 +129,19 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_METAL_PLACE: break; - case BLOCK_METAL_PRESSUREPLATE_CLICK_OFF: - break; - case BLOCK_METAL_PRESSUREPLATE_CLICK_ON: - break; case BLOCK_METAL_STEP: break; - case BLOCK_NOTE_BASEDRUM: + case BLOCK_NOTE_BLOCK_BASEDRUM: return cn.nukkit.level.Sound.NOTE_BASSATTACK; - case BLOCK_NOTE_BASS: + case BLOCK_NOTE_BLOCK_BASS: return cn.nukkit.level.Sound.NOTE_BASS; - case BLOCK_NOTE_HARP: + case BLOCK_NOTE_BLOCK_HARP: return cn.nukkit.level.Sound.NOTE_HARP; - case BLOCK_NOTE_HAT: + case BLOCK_NOTE_BLOCK_HAT: return cn.nukkit.level.Sound.NOTE_HAT; - case BLOCK_NOTE_PLING: + case BLOCK_NOTE_BLOCK_PLING: return cn.nukkit.level.Sound.NOTE_PLING; - case BLOCK_NOTE_SNARE: + case BLOCK_NOTE_BLOCK_SNARE: return cn.nukkit.level.Sound.NOTE_SNARE; case BLOCK_PISTON_CONTRACT: break; @@ -183,16 +165,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_SAND_STEP: break; - case BLOCK_SLIME_BREAK: - break; - case BLOCK_SLIME_FALL: - break; - case BLOCK_SLIME_HIT: - break; - case BLOCK_SLIME_PLACE: - break; - case BLOCK_SLIME_STEP: - break; case BLOCK_SNOW_BREAK: break; case BLOCK_SNOW_FALL: @@ -215,10 +187,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_STONE_PLACE: break; - case BLOCK_STONE_PRESSUREPLATE_CLICK_OFF: - break; - case BLOCK_STONE_PRESSUREPLATE_CLICK_ON: - break; case BLOCK_STONE_STEP: break; case BLOCK_TRIPWIRE_ATTACH: @@ -229,8 +197,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case BLOCK_TRIPWIRE_DETACH: break; - case BLOCK_WATERLILY_PLACE: - break; case BLOCK_WATER_AMBIENT: break; case BLOCK_WOODEN_DOOR_CLOSE: @@ -243,32 +209,16 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo return cn.nukkit.level.Sound.RANDOM_DOOR_OPEN; case BLOCK_WOOD_BREAK: return cn.nukkit.level.Sound.HIT_WOOD; - case BLOCK_WOOD_BUTTON_CLICK_OFF: - break; - case BLOCK_WOOD_BUTTON_CLICK_ON: - break; case BLOCK_WOOD_FALL: break; case BLOCK_WOOD_HIT: break; case BLOCK_WOOD_PLACE: break; - case BLOCK_WOOD_PRESSUREPLATE_CLICK_OFF: - break; - case BLOCK_WOOD_PRESSUREPLATE_CLICK_ON: - break; case BLOCK_WOOD_STEP: break; case ENCHANT_THORNS_HIT: break; - case ENTITY_ARMORSTAND_BREAK: - break; - case ENTITY_ARMORSTAND_FALL: - break; - case ENTITY_ARMORSTAND_HIT: - break; - case ENTITY_ARMORSTAND_PLACE: - break; case ENTITY_ARROW_HIT: break; case ENTITY_ARROW_HIT_PLAYER: @@ -283,8 +233,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_BAT_LOOP: break; - // case ENTITY_BAT_TAKEOFF: - // return new BatSound(vector, pitch); case ENTITY_BLAZE_AMBIENT: break; case ENTITY_BLAZE_BURN: @@ -295,10 +243,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_BLAZE_SHOOT: break; - case ENTITY_BOBBER_SPLASH: - break; - case ENTITY_BOBBER_THROW: - break; case ENTITY_CAT_AMBIENT: break; case ENTITY_CAT_DEATH: @@ -363,33 +307,17 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_ELDER_GUARDIAN_HURT_LAND: break; - case ENTITY_ENDERDRAGON_AMBIENT: - break; - case ENTITY_ENDERDRAGON_DEATH: - break; - case ENTITY_ENDERDRAGON_FIREBALL_EXPLODE: - break; - case ENTITY_ENDERDRAGON_FLAP: - break; - case ENTITY_ENDERDRAGON_GROWL: - break; - case ENTITY_ENDERDRAGON_HURT: - break; - case ENTITY_ENDERDRAGON_SHOOT: - break; - case ENTITY_ENDEREYE_LAUNCH: - break; - case ENTITY_ENDERMEN_AMBIENT: + case ENTITY_ENDERMAN_AMBIENT: return cn.nukkit.level.Sound.MOB_ENDERMEN_IDLE; - case ENTITY_ENDERMEN_DEATH: + case ENTITY_ENDERMAN_DEATH: return cn.nukkit.level.Sound.MOB_ENDERMEN_DEATH; - case ENTITY_ENDERMEN_HURT: + case ENTITY_ENDERMAN_HURT: return cn.nukkit.level.Sound.MOB_ENDERMEN_HIT; - case ENTITY_ENDERMEN_SCREAM: + case ENTITY_ENDERMAN_SCREAM: return cn.nukkit.level.Sound.MOB_ENDERMEN_SCREAM; - case ENTITY_ENDERMEN_STARE: + case ENTITY_ENDERMAN_STARE: return cn.nukkit.level.Sound.MOB_ENDERMEN_STARE; - case ENTITY_ENDERMEN_TELEPORT: + case ENTITY_ENDERMAN_TELEPORT: return cn.nukkit.level.Sound.MOB_ENDERMEN_PORTAL; case ENTITY_ENDERMITE_AMBIENT: break; @@ -399,28 +327,10 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_ENDERMITE_STEP: break; - case ENTITY_ENDERPEARL_THROW: - break; case ENTITY_EXPERIENCE_BOTTLE_THROW: break; case ENTITY_EXPERIENCE_ORB_PICKUP: return cn.nukkit.level.Sound.RANDOM_ORB; - case ENTITY_FIREWORK_BLAST: - break; - case ENTITY_FIREWORK_BLAST_FAR: - break; - case ENTITY_FIREWORK_LARGE_BLAST: - break; - case ENTITY_FIREWORK_LARGE_BLAST_FAR: - break; - case ENTITY_FIREWORK_LAUNCH: - break; - case ENTITY_FIREWORK_SHOOT: - break; - case ENTITY_FIREWORK_TWINKLE: - break; - case ENTITY_FIREWORK_TWINKLE_FAR: - break; case ENTITY_GENERIC_BIG_FALL: break; case ENTITY_GENERIC_BURN: @@ -517,46 +427,20 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_HUSK_STEP: break; - case ENTITY_IRONGOLEM_ATTACK: - break; - case ENTITY_IRONGOLEM_DEATH: - break; - case ENTITY_IRONGOLEM_HURT: - break; - case ENTITY_IRONGOLEM_STEP: - break; - case ENTITY_ITEMFRAME_ADD_ITEM: + case ENTITY_ITEM_FRAME_ADD_ITEM: return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_ADD_ITEM; - case ENTITY_ITEMFRAME_BREAK: + case ENTITY_ITEM_FRAME_BREAK: return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_BREAK; - case ENTITY_ITEMFRAME_PLACE: + case ENTITY_ITEM_FRAME_PLACE: return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_PLACE; - case ENTITY_ITEMFRAME_REMOVE_ITEM: + case ENTITY_ITEM_FRAME_REMOVE_ITEM: return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_REMOVE_ITEM; - case ENTITY_ITEMFRAME_ROTATE_ITEM: + case ENTITY_ITEM_FRAME_ROTATE_ITEM: return cn.nukkit.level.Sound.BLOCK_ITEMFRAME_ROTATE_ITEM; case ENTITY_ITEM_BREAK: break; case ENTITY_ITEM_PICKUP: break; - case ENTITY_LEASHKNOT_BREAK: - break; - case ENTITY_LEASHKNOT_PLACE: - break; - case ENTITY_LIGHTNING_IMPACT: - break; - case ENTITY_LIGHTNING_THUNDER: - break; - case ENTITY_LINGERINGPOTION_THROW: - break; - case ENTITY_MAGMACUBE_DEATH: - break; - case ENTITY_MAGMACUBE_HURT: - break; - case ENTITY_MAGMACUBE_JUMP: - break; - case ENTITY_MAGMACUBE_SQUISH: - break; case ENTITY_MINECART_INSIDE: break; case ENTITY_MINECART_RIDING: @@ -615,8 +499,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_POLAR_BEAR_AMBIENT: break; - case ENTITY_POLAR_BEAR_BABY_AMBIENT: - break; case ENTITY_POLAR_BEAR_DEATH: break; case ENTITY_POLAR_BEAR_HURT: @@ -699,30 +581,8 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_SLIME_SQUISH: break; - case ENTITY_SMALL_MAGMACUBE_DEATH: - break; - case ENTITY_SMALL_MAGMACUBE_HURT: - break; - case ENTITY_SMALL_MAGMACUBE_SQUISH: - break; - case ENTITY_SMALL_SLIME_DEATH: - break; - case ENTITY_SMALL_SLIME_HURT: - break; - case ENTITY_SMALL_SLIME_JUMP: - break; - case ENTITY_SMALL_SLIME_SQUISH: - break; case ENTITY_SNOWBALL_THROW: break; - case ENTITY_SNOWMAN_AMBIENT: - break; - case ENTITY_SNOWMAN_DEATH: - break; - case ENTITY_SNOWMAN_HURT: - break; - case ENTITY_SNOWMAN_SHOOT: - break; case ENTITY_SPIDER_AMBIENT: break; case ENTITY_SPIDER_DEATH: @@ -759,8 +619,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_VILLAGER_NO: break; - case ENTITY_VILLAGER_TRADING: - break; case ENTITY_VILLAGER_YES: break; case ENTITY_WITCH_AMBIENT: @@ -813,11 +671,11 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_ZOMBIE_AMBIENT: break; - case ENTITY_ZOMBIE_ATTACK_DOOR_WOOD: - return cn.nukkit.level.Sound.MOB_ZOMBIE_WOOD; case ENTITY_ZOMBIE_ATTACK_IRON_DOOR: break; - case ENTITY_ZOMBIE_BREAK_DOOR_WOOD: + case ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR: + return cn.nukkit.level.Sound.MOB_ZOMBIE_WOOD; + case ENTITY_ZOMBIE_BREAK_WOODEN_DOOR: return cn.nukkit.level.Sound.MOB_ZOMBIE_WOODBREAK; case ENTITY_ZOMBIE_DEATH: break; @@ -829,24 +687,12 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_ZOMBIE_HURT: break; - // case ENTITY_ZOMBIE_INFECT: - // return new ZombieInfectSound(vector, pitch); - case ENTITY_ZOMBIE_PIG_AMBIENT: - break; - case ENTITY_ZOMBIE_PIG_ANGRY: - break; - case ENTITY_ZOMBIE_PIG_DEATH: - break; - case ENTITY_ZOMBIE_PIG_HURT: - break; case ENTITY_ZOMBIE_STEP: break; case ENTITY_ZOMBIE_VILLAGER_AMBIENT: break; case ENTITY_ZOMBIE_VILLAGER_CONVERTED: break; - // case ENTITY_ZOMBIE_VILLAGER_CURE: - // return new ZombieInfectSound(vector, pitch); case ENTITY_ZOMBIE_VILLAGER_DEATH: break; case ENTITY_ZOMBIE_VILLAGER_HURT: @@ -907,29 +753,29 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case MUSIC_NETHER: break; - case RECORD_11: + case MUSIC_DISC_11: break; - case RECORD_13: + case MUSIC_DISC_13: break; - case RECORD_BLOCKS: + case MUSIC_DISC_BLOCKS: break; - case RECORD_CAT: + case MUSIC_DISC_CAT: break; - case RECORD_CHIRP: + case MUSIC_DISC_CHIRP: break; - case RECORD_FAR: + case MUSIC_DISC_FAR: break; - case RECORD_MALL: + case MUSIC_DISC_MALL: break; - case RECORD_MELLOHI: + case MUSIC_DISC_MELLOHI: break; - case RECORD_STAL: + case MUSIC_DISC_STAL: break; - case RECORD_STRAD: + case MUSIC_DISC_STRAD: break; - case RECORD_WAIT: + case MUSIC_DISC_WAIT: break; - case RECORD_WARD: + case MUSIC_DISC_WARD: break; case UI_BUTTON_CLICK: return cn.nukkit.level.Sound.RANDOM_CLICK; @@ -944,22 +790,6 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_ELDER_GUARDIAN_FLOP: break; - case ENTITY_EVOCATION_FANGS_ATTACK: - break; - case ENTITY_EVOCATION_ILLAGER_AMBIENT: - break; - case ENTITY_EVOCATION_ILLAGER_CAST_SPELL: - break; - case ENTITY_EVOCATION_ILLAGER_DEATH: - break; - case ENTITY_EVOCATION_ILLAGER_HURT: - break; - case ENTITY_EVOCATION_ILLAGER_PREPARE_ATTACK: - break; - case ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON: - break; - case ENTITY_EVOCATION_ILLAGER_PREPARE_WOLOLO: - break; case ENTITY_LLAMA_AMBIENT: break; case ENTITY_LLAMA_ANGRY: @@ -988,18 +818,526 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo break; case ENTITY_VEX_HURT: break; - case ENTITY_VINDICATION_ILLAGER_AMBIENT: - break; - case ENTITY_VINDICATION_ILLAGER_DEATH: - break; - case ENTITY_VINDICATION_ILLAGER_HURT: - break; case ITEM_ARMOR_EQUIP_ELYTRA: break; case ITEM_BOTTLE_EMPTY: break; case ITEM_TOTEM_USE: break; + case AMBIENT_UNDERWATER_ENTER: + break; + case AMBIENT_UNDERWATER_EXIT: + break; + case AMBIENT_UNDERWATER_LOOP: + break; + case AMBIENT_UNDERWATER_LOOP_ADDITIONS: + break; + case AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE: + break; + case AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE: + break; + case BLOCK_BEACON_ACTIVATE: + break; + case BLOCK_BEACON_AMBIENT: + break; + case BLOCK_BEACON_DEACTIVATE: + break; + case BLOCK_BEACON_POWER_SELECT: + break; + case BLOCK_BUBBLE_COLUMN_BUBBLE_POP: + break; + case BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT: + break; + case BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE: + break; + case BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT: + break; + case BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE: + break; + case BLOCK_CONDUIT_ACTIVATE: + break; + case BLOCK_CONDUIT_AMBIENT: + break; + case BLOCK_CONDUIT_AMBIENT_SHORT: + break; + case BLOCK_CONDUIT_ATTACK_TARGET: + break; + case BLOCK_CONDUIT_DEACTIVATE: + break; + case BLOCK_CORAL_BLOCK_BREAK: + break; + case BLOCK_CORAL_BLOCK_FALL: + break; + case BLOCK_CORAL_BLOCK_HIT: + break; + case BLOCK_CORAL_BLOCK_PLACE: + break; + case BLOCK_CORAL_BLOCK_STEP: + break; + case BLOCK_ENDER_CHEST_CLOSE: + break; + case BLOCK_ENDER_CHEST_OPEN: + break; + case BLOCK_END_PORTAL_FRAME_FILL: + break; + case BLOCK_END_PORTAL_SPAWN: + break; + case BLOCK_LILY_PAD_PLACE: + break; + case BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF: + break; + case BLOCK_METAL_PRESSURE_PLATE_CLICK_ON: + break; + case BLOCK_NOTE_BLOCK_BELL: + break; + case BLOCK_NOTE_BLOCK_CHIME: + break; + case BLOCK_NOTE_BLOCK_FLUTE: + break; + case BLOCK_NOTE_BLOCK_GUITAR: + break; + case BLOCK_NOTE_BLOCK_XYLOPHONE: + break; + case BLOCK_PUMPKIN_CARVE: + break; + case BLOCK_SLIME_BLOCK_BREAK: + break; + case BLOCK_SLIME_BLOCK_FALL: + break; + case BLOCK_SLIME_BLOCK_HIT: + break; + case BLOCK_SLIME_BLOCK_PLACE: + break; + case BLOCK_SLIME_BLOCK_STEP: + break; + case BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF: + break; + case BLOCK_STONE_PRESSURE_PLATE_CLICK_ON: + break; + case BLOCK_WET_GRASS_BREAK: + break; + case BLOCK_WET_GRASS_FALL: + break; + case BLOCK_WET_GRASS_HIT: + break; + case BLOCK_WET_GRASS_PLACE: + break; + case BLOCK_WET_GRASS_STEP: + break; + case BLOCK_WOODEN_BUTTON_CLICK_OFF: + break; + case BLOCK_WOODEN_BUTTON_CLICK_ON: + break; + case BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF: + break; + case BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON: + break; + case BLOCK_WOOL_BREAK: + break; + case BLOCK_WOOL_FALL: + break; + case BLOCK_WOOL_HIT: + break; + case BLOCK_WOOL_PLACE: + break; + case BLOCK_WOOL_STEP: + break; + case ENTITY_ARMOR_STAND_BREAK: + break; + case ENTITY_ARMOR_STAND_FALL: + break; + case ENTITY_ARMOR_STAND_HIT: + break; + case ENTITY_ARMOR_STAND_PLACE: + break; + case ENTITY_BAT_TAKEOFF: + break; + case ENTITY_BOAT_PADDLE_LAND: + break; + case ENTITY_BOAT_PADDLE_WATER: + break; + case ENTITY_COD_AMBIENT: + break; + case ENTITY_COD_DEATH: + break; + case ENTITY_COD_FLOP: + break; + case ENTITY_COD_HURT: + break; + case ENTITY_DOLPHIN_AMBIENT: + break; + case ENTITY_DOLPHIN_AMBIENT_WATER: + break; + case ENTITY_DOLPHIN_ATTACK: + break; + case ENTITY_DOLPHIN_DEATH: + break; + case ENTITY_DOLPHIN_EAT: + break; + case ENTITY_DOLPHIN_HURT: + break; + case ENTITY_DOLPHIN_JUMP: + break; + case ENTITY_DOLPHIN_PLAY: + break; + case ENTITY_DOLPHIN_SPLASH: + break; + case ENTITY_DOLPHIN_SWIM: + break; + case ENTITY_DRAGON_FIREBALL_EXPLODE: + break; + case ENTITY_DROWNED_AMBIENT: + break; + case ENTITY_DROWNED_AMBIENT_WATER: + break; + case ENTITY_DROWNED_DEATH: + break; + case ENTITY_DROWNED_DEATH_WATER: + break; + case ENTITY_DROWNED_HURT: + break; + case ENTITY_DROWNED_HURT_WATER: + break; + case ENTITY_DROWNED_SHOOT: + break; + case ENTITY_DROWNED_STEP: + break; + case ENTITY_DROWNED_SWIM: + break; + case ENTITY_ENDER_DRAGON_AMBIENT: + break; + case ENTITY_ENDER_DRAGON_DEATH: + break; + case ENTITY_ENDER_DRAGON_FLAP: + break; + case ENTITY_ENDER_DRAGON_GROWL: + break; + case ENTITY_ENDER_DRAGON_HURT: + break; + case ENTITY_ENDER_DRAGON_SHOOT: + break; + case ENTITY_ENDER_EYE_DEATH: + break; + case ENTITY_ENDER_EYE_LAUNCH: + break; + case ENTITY_ENDER_PEARL_THROW: + break; + case ENTITY_EVOKER_AMBIENT: + break; + case ENTITY_EVOKER_CAST_SPELL: + break; + case ENTITY_EVOKER_DEATH: + break; + case ENTITY_EVOKER_FANGS_ATTACK: + break; + case ENTITY_EVOKER_HURT: + break; + case ENTITY_EVOKER_PREPARE_ATTACK: + break; + case ENTITY_EVOKER_PREPARE_SUMMON: + break; + case ENTITY_EVOKER_PREPARE_WOLOLO: + break; + case ENTITY_FIREWORK_ROCKET_BLAST: + break; + case ENTITY_FIREWORK_ROCKET_BLAST_FAR: + break; + case ENTITY_FIREWORK_ROCKET_LARGE_BLAST: + break; + case ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR: + break; + case ENTITY_FIREWORK_ROCKET_LAUNCH: + break; + case ENTITY_FIREWORK_ROCKET_SHOOT: + break; + case ENTITY_FIREWORK_ROCKET_TWINKLE: + break; + case ENTITY_FIREWORK_ROCKET_TWINKLE_FAR: + break; + case ENTITY_FISHING_BOBBER_RETRIEVE: + break; + case ENTITY_FISHING_BOBBER_SPLASH: + break; + case ENTITY_FISHING_BOBBER_THROW: + break; + case ENTITY_FISH_SWIM: + break; + case ENTITY_HUSK_CONVERTED_TO_ZOMBIE: + break; + case ENTITY_ILLUSIONER_AMBIENT: + break; + case ENTITY_ILLUSIONER_CAST_SPELL: + break; + case ENTITY_ILLUSIONER_DEATH: + break; + case ENTITY_ILLUSIONER_HURT: + break; + case ENTITY_ILLUSIONER_MIRROR_MOVE: + break; + case ENTITY_ILLUSIONER_PREPARE_BLINDNESS: + break; + case ENTITY_ILLUSIONER_PREPARE_MIRROR: + break; + case ENTITY_IRON_GOLEM_ATTACK: + break; + case ENTITY_IRON_GOLEM_DEATH: + break; + case ENTITY_IRON_GOLEM_HURT: + break; + case ENTITY_IRON_GOLEM_STEP: + break; + case ENTITY_LEASH_KNOT_BREAK: + break; + case ENTITY_LEASH_KNOT_PLACE: + break; + case ENTITY_LIGHTNING_BOLT_IMPACT: + break; + case ENTITY_LIGHTNING_BOLT_THUNDER: + break; + case ENTITY_LINGERING_POTION_THROW: + break; + case ENTITY_MAGMA_CUBE_DEATH: + break; + case ENTITY_MAGMA_CUBE_DEATH_SMALL: + break; + case ENTITY_MAGMA_CUBE_HURT: + break; + case ENTITY_MAGMA_CUBE_HURT_SMALL: + break; + case ENTITY_MAGMA_CUBE_JUMP: + break; + case ENTITY_MAGMA_CUBE_SQUISH: + break; + case ENTITY_MAGMA_CUBE_SQUISH_SMALL: + break; + case ENTITY_PARROT_AMBIENT: + break; + case ENTITY_PARROT_DEATH: + break; + case ENTITY_PARROT_EAT: + break; + case ENTITY_PARROT_FLY: + break; + case ENTITY_PARROT_HURT: + break; + case ENTITY_PARROT_IMITATE_BLAZE: + break; + case ENTITY_PARROT_IMITATE_CREEPER: + break; + case ENTITY_PARROT_IMITATE_DROWNED: + break; + case ENTITY_PARROT_IMITATE_ELDER_GUARDIAN: + break; + case ENTITY_PARROT_IMITATE_ENDERMAN: + break; + case ENTITY_PARROT_IMITATE_ENDERMITE: + break; + case ENTITY_PARROT_IMITATE_ENDER_DRAGON: + break; + case ENTITY_PARROT_IMITATE_EVOKER: + break; + case ENTITY_PARROT_IMITATE_GHAST: + break; + case ENTITY_PARROT_IMITATE_HUSK: + break; + case ENTITY_PARROT_IMITATE_ILLUSIONER: + break; + case ENTITY_PARROT_IMITATE_MAGMA_CUBE: + break; + case ENTITY_PARROT_IMITATE_PHANTOM: + break; + case ENTITY_PARROT_IMITATE_POLAR_BEAR: + break; + case ENTITY_PARROT_IMITATE_SHULKER: + break; + case ENTITY_PARROT_IMITATE_SILVERFISH: + break; + case ENTITY_PARROT_IMITATE_SKELETON: + break; + case ENTITY_PARROT_IMITATE_SLIME: + break; + case ENTITY_PARROT_IMITATE_SPIDER: + break; + case ENTITY_PARROT_IMITATE_STRAY: + break; + case ENTITY_PARROT_IMITATE_VEX: + break; + case ENTITY_PARROT_IMITATE_VINDICATOR: + break; + case ENTITY_PARROT_IMITATE_WITCH: + break; + case ENTITY_PARROT_IMITATE_WITHER: + break; + case ENTITY_PARROT_IMITATE_WITHER_SKELETON: + break; + case ENTITY_PARROT_IMITATE_WOLF: + break; + case ENTITY_PARROT_IMITATE_ZOMBIE: + break; + case ENTITY_PARROT_IMITATE_ZOMBIE_PIGMAN: + break; + case ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER: + break; + case ENTITY_PARROT_STEP: + break; + case ENTITY_PHANTOM_AMBIENT: + break; + case ENTITY_PHANTOM_BITE: + break; + case ENTITY_PHANTOM_DEATH: + break; + case ENTITY_PHANTOM_FLAP: + break; + case ENTITY_PHANTOM_HURT: + break; + case ENTITY_PHANTOM_SWOOP: + break; + case ENTITY_PLAYER_HURT_DROWN: + break; + case ENTITY_PLAYER_HURT_ON_FIRE: + break; + case ENTITY_PLAYER_SPLASH_HIGH_SPEED: + break; + case ENTITY_POLAR_BEAR_AMBIENT_BABY: + break; + case ENTITY_PUFFER_FISH_AMBIENT: + break; + case ENTITY_PUFFER_FISH_BLOW_OUT: + break; + case ENTITY_PUFFER_FISH_BLOW_UP: + break; + case ENTITY_PUFFER_FISH_DEATH: + break; + case ENTITY_PUFFER_FISH_FLOP: + break; + case ENTITY_PUFFER_FISH_HURT: + break; + case ENTITY_PUFFER_FISH_STING: + break; + case ENTITY_SALMON_AMBIENT: + break; + case ENTITY_SALMON_DEATH: + break; + case ENTITY_SALMON_FLOP: + break; + case ENTITY_SALMON_HURT: + break; + case ENTITY_SKELETON_HORSE_AMBIENT_WATER: + break; + case ENTITY_SKELETON_HORSE_GALLOP_WATER: + break; + case ENTITY_SKELETON_HORSE_JUMP_WATER: + break; + case ENTITY_SKELETON_HORSE_STEP_WATER: + break; + case ENTITY_SKELETON_HORSE_SWIM: + break; + case ENTITY_SLIME_DEATH_SMALL: + break; + case ENTITY_SLIME_HURT_SMALL: + break; + case ENTITY_SLIME_JUMP_SMALL: + break; + case ENTITY_SLIME_SQUISH_SMALL: + break; + case ENTITY_SNOW_GOLEM_AMBIENT: + break; + case ENTITY_SNOW_GOLEM_DEATH: + break; + case ENTITY_SNOW_GOLEM_HURT: + break; + case ENTITY_SNOW_GOLEM_SHOOT: + break; + case ENTITY_SQUID_SQUIRT: + break; + case ENTITY_TROPICAL_FISH_AMBIENT: + break; + case ENTITY_TROPICAL_FISH_DEATH: + break; + case ENTITY_TROPICAL_FISH_FLOP: + break; + case ENTITY_TROPICAL_FISH_HURT: + break; + case ENTITY_TURTLE_AMBIENT_LAND: + break; + case ENTITY_TURTLE_DEATH: + break; + case ENTITY_TURTLE_DEATH_BABY: + break; + case ENTITY_TURTLE_EGG_BREAK: + break; + case ENTITY_TURTLE_EGG_CRACK: + break; + case ENTITY_TURTLE_EGG_HATCH: + break; + case ENTITY_TURTLE_HURT: + break; + case ENTITY_TURTLE_HURT_BABY: + break; + case ENTITY_TURTLE_LAY_EGG: + break; + case ENTITY_TURTLE_SHAMBLE: + break; + case ENTITY_TURTLE_SHAMBLE_BABY: + break; + case ENTITY_TURTLE_SWIM: + break; + case ENTITY_VILLAGER_TRADE: + break; + case ENTITY_VINDICATOR_AMBIENT: + break; + case ENTITY_VINDICATOR_DEATH: + break; + case ENTITY_VINDICATOR_HURT: + break; + case ENTITY_ZOMBIE_CONVERTED_TO_DROWNED: + break; + case ENTITY_ZOMBIE_DESTROY_EGG: + break; + case ENTITY_ZOMBIE_INFECT: + break; + case ENTITY_ZOMBIE_PIGMAN_AMBIENT: + break; + case ENTITY_ZOMBIE_PIGMAN_ANGRY: + break; + case ENTITY_ZOMBIE_PIGMAN_DEATH: + break; + case ENTITY_ZOMBIE_PIGMAN_HURT: + break; + case ENTITY_ZOMBIE_VILLAGER_CURE: + break; + case ITEM_ARMOR_EQUIP_TURTLE: + break; + case ITEM_AXE_STRIP: + break; + case ITEM_BUCKET_EMPTY_FISH: + break; + case ITEM_BUCKET_FILL_FISH: + break; + case ITEM_TRIDENT_HIT: + break; + case ITEM_TRIDENT_HIT_GROUND: + break; + case ITEM_TRIDENT_RETURN: + break; + case ITEM_TRIDENT_RIPTIDE_1: + break; + case ITEM_TRIDENT_RIPTIDE_2: + break; + case ITEM_TRIDENT_RIPTIDE_3: + break; + case ITEM_TRIDENT_THROW: + break; + case ITEM_TRIDENT_THUNDER: + break; + case MUSIC_UNDER_WATER: + break; + case UI_TOAST_CHALLENGE_COMPLETE: + break; + case UI_TOAST_IN: + break; + case UI_TOAST_OUT: + break; default: break; } diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java b/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java index b651133..3291e76 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitUnsafe.java @@ -1,51 +1,48 @@ package nl.rutgerkok.pokkit; -import java.util.List; - -import nl.rutgerkok.pokkit.item.PokkitItemMeta; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; - -import org.bukkit.Achievement; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.Statistic; import org.bukkit.UnsafeValues; import org.bukkit.advancement.Advancement; +import org.bukkit.block.data.BlockData; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; +import org.bukkit.plugin.PluginDescriptionFile; -import cn.nukkit.item.Item; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.item.PokkitItemMeta; @SuppressWarnings("deprecation") public class PokkitUnsafe implements UnsafeValues { @Override - public Achievement getAchievementFromInternalName(String name) { - try { - return Achievement.valueOf(name.toUpperCase().replace("MINECRAFT:", "")); - } catch (IllegalArgumentException e) { - return null; - } + public void checkSupported(PluginDescriptionFile pdf) { + // Empty! } @Override - public Material getMaterialFromInternalName(String name) { - Item item = Item.fromString(name); + public Material fromLegacy(Material material) { + return material; + } - if (item.getId() == Item.AIR && !name.toLowerCase().endsWith("air")) { - // Nukkit returns air in case of failure, correct that - return null; - } + @Override + public BlockData fromLegacy(Material material, byte data) { + return PokkitBlockData.createBlockData(material, data); + } - return PokkitMaterialData.fromNukkit(item.getId(), item.getDamage()).getBukkitMaterial(); + @Override + public Material fromLegacy(MaterialData material) { + return material.getItemType(); } @Override - public Statistic getStatisticFromInternalName(String name) { - try { - return Statistic.valueOf(name.toUpperCase().replace("MINECRAFT:", "")); - } catch (IllegalArgumentException e) { - return null; - } + public Material fromLegacy(MaterialData material, boolean itemPriority) { + return material.getItemType(); + } + + @Override + public int getDataVersion() { + return 1; } @Override @@ -63,18 +60,18 @@ public ItemStack modifyItemStack(ItemStack stack, String arguments) { } @Override - public boolean removeAdvancement(NamespacedKey key) { - throw Pokkit.unsupported(); + public byte[] processClass(PluginDescriptionFile pdf, String path, byte[] clazz) { + return clazz; // Not implemented yet } @Override - public List tabCompleteInternalMaterialName(String token, List completions) { - return completions; + public boolean removeAdvancement(NamespacedKey key) { + throw Pokkit.unsupported(); } @Override - public List tabCompleteInternalStatisticOrAchievementName(String token, List completions) { - return completions; + public Material toLegacy(Material material) { + return material; } } diff --git a/src/main/java/nl/rutgerkok/pokkit/blockdata/BlockMap.java b/src/main/java/nl/rutgerkok/pokkit/blockdata/BlockMap.java new file mode 100644 index 0000000..bc60060 --- /dev/null +++ b/src/main/java/nl/rutgerkok/pokkit/blockdata/BlockMap.java @@ -0,0 +1,556 @@ +package nl.rutgerkok.pokkit.blockdata; + +import org.bukkit.Material; + +import cn.nukkit.block.Block; +import cn.nukkit.block.BlockID; + +/** + * Note: this class does not yet take block data into account. For example, + * Nukkit's WOOL is always converted to Bukkit's WHITE_WOOL. This is something + * that should be corrected in the future. + * + */ +@SuppressWarnings("deprecation") +final class BlockMap { + + private static Material[] nukkitToBukkit = new Material[500]; + private static char[] bukkitToNukkit = new char[Material.values().length]; + + static { + registerTwoWay(BlockID.AIR, Material.AIR); + registerTwoWay(BlockID.STONE, Material.STONE); + registerTwoWay(BlockID.GRASS, Material.GRASS_BLOCK); + registerTwoWay(BlockID.DIRT, Material.DIRT); + registerTwoWay(BlockID.COBBLESTONE, Material.COBBLESTONE); + registerTwoWay(BlockID.PLANK, Material.OAK_PLANKS); + registerTwoWay(BlockID.PLANKS, Material.OAK_PLANKS); + registerTwoWay(BlockID.WOODEN_PLANK, Material.OAK_PLANKS); + registerTwoWay(BlockID.WOODEN_PLANKS, Material.OAK_PLANKS); + registerTwoWay(BlockID.SAPLING, Material.OAK_SAPLING); + registerTwoWay(BlockID.SAPLINGS, Material.OAK_SAPLING); + registerTwoWay(BlockID.BEDROCK, Material.BEDROCK); + registerBukkitToBukkit(BlockID.WATER, Material.WATER); + registerTwoWay(BlockID.STILL_WATER, Material.WATER); + registerBukkitToBukkit(BlockID.LAVA, Material.LAVA); + registerTwoWay(BlockID.STILL_LAVA, Material.LAVA); + registerTwoWay(BlockID.SAND, Material.SAND); + registerTwoWay(BlockID.GRAVEL, Material.GRAVEL); + registerTwoWay(BlockID.GOLD_ORE, Material.GOLD_ORE); + registerTwoWay(BlockID.IRON_ORE, Material.IRON_ORE); + registerTwoWay(BlockID.COAL_ORE, Material.COAL_ORE); + registerTwoWay(BlockID.LOG, Material.OAK_LOG); + registerTwoWay(BlockID.LEAVES, Material.OAK_LEAVES); + registerTwoWay(BlockID.SPONGE, Material.SPONGE); + registerTwoWay(BlockID.GLASS, Material.GLASS); + registerTwoWay(BlockID.LAPIS_ORE, Material.LAPIS_ORE); + registerTwoWay(BlockID.LAPIS_BLOCK, Material.LAPIS_BLOCK); + registerTwoWay(BlockID.DISPENSER, Material.DISPENSER); + registerTwoWay(BlockID.SANDSTONE, Material.SANDSTONE); + registerTwoWay(BlockID.NOTEBLOCK, Material.NOTE_BLOCK); + registerTwoWay(BlockID.BED_BLOCK, Material.RED_BED); + registerTwoWay(BlockID.POWERED_RAIL, Material.POWERED_RAIL); + registerTwoWay(BlockID.DETECTOR_RAIL, Material.DETECTOR_RAIL); + registerTwoWay(BlockID.STICKY_PISTON, Material.STICKY_PISTON); + registerTwoWay(BlockID.COBWEB, Material.COBWEB); + registerTwoWay(BlockID.TALL_GRASS, Material.TALL_GRASS); + registerTwoWay(BlockID.BUSH, Material.FERN); + registerTwoWay(BlockID.DEAD_BUSH, Material.DEAD_BUSH); + registerTwoWay(BlockID.PISTON, Material.PISTON); + registerTwoWay(BlockID.PISTON_HEAD, Material.PISTON_HEAD); + registerTwoWay(BlockID.WOOL, Material.WHITE_WOOL); + registerTwoWay(BlockID.DANDELION, Material.DANDELION); + registerTwoWay(BlockID.POPPY, Material.POPPY); + registerTwoWay(BlockID.BROWN_MUSHROOM, Material.BROWN_MUSHROOM); + registerTwoWay(BlockID.RED_MUSHROOM, Material.RED_MUSHROOM); + registerTwoWay(BlockID.GOLD_BLOCK, Material.GOLD_BLOCK); + registerTwoWay(BlockID.IRON_BLOCK, Material.IRON_BLOCK); + registerTwoWay(BlockID.STONE_SLAB, Material.STONE_SLAB); + registerTwoWay(BlockID.BRICKS, Material.BRICKS); + registerTwoWay(BlockID.TNT, Material.TNT); + registerTwoWay(BlockID.BOOKSHELF, Material.BOOKSHELF); + registerTwoWay(BlockID.MOSS_STONE, Material.MOSSY_COBBLESTONE); + registerTwoWay(BlockID.OBSIDIAN, Material.OBSIDIAN); + registerTwoWay(BlockID.TORCH, Material.TORCH); + registerTwoWay(BlockID.FIRE, Material.FIRE); + registerTwoWay(BlockID.MONSTER_SPAWNER, Material.SPAWNER); + registerTwoWay(BlockID.OAK_WOODEN_STAIRS, Material.OAK_STAIRS); + registerTwoWay(BlockID.CHEST, Material.CHEST); + registerTwoWay(BlockID.REDSTONE_WIRE, Material.REDSTONE_WIRE); + registerTwoWay(BlockID.DIAMOND_ORE, Material.DIAMOND_ORE); + registerTwoWay(BlockID.DIAMOND_BLOCK, Material.DIAMOND_BLOCK); + registerTwoWay(BlockID.CRAFTING_TABLE, Material.CRAFTING_TABLE); + registerTwoWay(BlockID.WHEAT_BLOCK, Material.WHEAT); + registerTwoWay(BlockID.FARMLAND, Material.FARMLAND); + registerTwoWay(BlockID.FURNACE, Material.FURNACE); + registerBukkitToBukkit(BlockID.BURNING_FURNACE, Material.FURNACE); + registerTwoWay(BlockID.SIGN_POST, Material.SIGN); + registerTwoWay(BlockID.DOOR_BLOCK, Material.OAK_DOOR); + registerTwoWay(BlockID.LADDER, Material.LADDER); + registerTwoWay(BlockID.RAIL, Material.RAIL); + registerTwoWay(BlockID.COBBLESTONE_STAIRS, Material.COBBLESTONE_STAIRS); + registerTwoWay(BlockID.WALL_SIGN, Material.WALL_SIGN); + registerTwoWay(BlockID.LEVER, Material.LEVER); + registerTwoWay(BlockID.STONE_PRESSURE_PLATE, Material.STONE_PRESSURE_PLATE); + registerTwoWay(BlockID.IRON_DOOR_BLOCK, Material.IRON_DOOR); + registerTwoWay(BlockID.WOODEN_PRESSURE_PLATE, Material.OAK_PRESSURE_PLATE); + registerTwoWay(BlockID.REDSTONE_ORE, Material.REDSTONE_ORE); + registerBukkitToBukkit(BlockID.GLOWING_REDSTONE_ORE, Material.REDSTONE_ORE); + registerBukkitToBukkit(BlockID.UNLIT_REDSTONE_TORCH, Material.REDSTONE_TORCH); + registerTwoWay(BlockID.REDSTONE_TORCH, Material.REDSTONE_TORCH); + registerTwoWay(BlockID.STONE_BUTTON, Material.STONE_BUTTON); + registerTwoWay(BlockID.SNOW, Material.SNOW); + registerTwoWay(BlockID.ICE, Material.ICE); + registerTwoWay(BlockID.SNOW_BLOCK, Material.SNOW_BLOCK); + registerTwoWay(BlockID.CACTUS, Material.CACTUS); + registerTwoWay(BlockID.CLAY_BLOCK, Material.CLAY); + registerTwoWay(BlockID.SUGARCANE_BLOCK, Material.SUGAR_CANE); + registerTwoWay(BlockID.JUKEBOX, Material.JUKEBOX); + registerTwoWay(BlockID.FENCE, Material.OAK_FENCE); + registerTwoWay(BlockID.PUMPKIN, Material.PUMPKIN); + registerTwoWay(BlockID.NETHERRACK, Material.NETHERRACK); + registerTwoWay(BlockID.SOUL_SAND, Material.SOUL_SAND); + registerTwoWay(BlockID.GLOWSTONE, Material.GLOWSTONE); + registerTwoWay(BlockID.NETHER_PORTAL, Material.NETHER_PORTAL); + registerTwoWay(BlockID.JACK_O_LANTERN, Material.JACK_O_LANTERN); + registerTwoWay(BlockID.CAKE_BLOCK, Material.CAKE); + registerTwoWay(BlockID.UNPOWERED_REPEATER, Material.REPEATER); + registerBukkitToBukkit(BlockID.POWERED_REPEATER, Material.REPEATER); + registerTwoWay(BlockID.INVISIBLE_BEDROCK, Material.BARRIER); + registerTwoWay(BlockID.TRAPDOOR, Material.OAK_TRAPDOOR); + registerTwoWay(BlockID.MONSTER_EGG, Material.INFESTED_STONE); + registerTwoWay(BlockID.STONE_BRICKS, Material.STONE_BRICKS); + registerTwoWay(BlockID.BROWN_MUSHROOM_BLOCK, Material.BROWN_MUSHROOM_BLOCK); + registerTwoWay(BlockID.RED_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK); + registerTwoWay(BlockID.IRON_BARS, Material.IRON_BARS); + registerTwoWay(BlockID.GLASS_PANE, Material.GLASS_PANE); + registerTwoWay(BlockID.MELON_BLOCK, Material.MELON); + registerTwoWay(BlockID.PUMPKIN_STEM, Material.PUMPKIN_STEM); + registerTwoWay(BlockID.MELON_STEM, Material.MELON_STEM); + registerTwoWay(BlockID.VINE, Material.VINE); + registerTwoWay(BlockID.FENCE_GATE_OAK, Material.OAK_FENCE_GATE); + registerTwoWay(BlockID.BRICK_STAIRS, Material.BRICK_STAIRS); + registerTwoWay(BlockID.STONE_BRICK_STAIRS, Material.STONE_BRICK_STAIRS); + registerTwoWay(BlockID.MYCELIUM, Material.MYCELIUM); + registerTwoWay(BlockID.LILY_PAD, Material.LILY_PAD); + registerTwoWay(BlockID.NETHER_BRICKS, Material.NETHER_BRICKS); + registerTwoWay(BlockID.NETHER_BRICK_FENCE, Material.NETHER_BRICK_FENCE); + registerTwoWay(BlockID.NETHER_BRICKS_STAIRS, Material.NETHER_BRICK_STAIRS); + registerTwoWay(BlockID.NETHER_WART_BLOCK, Material.NETHER_WART_BLOCK); + registerTwoWay(BlockID.ENCHANTING_TABLE, Material.ENCHANTING_TABLE); + registerTwoWay(BlockID.BREWING_STAND_BLOCK, Material.BREWING_STAND); + registerTwoWay(BlockID.CAULDRON_BLOCK, Material.CAULDRON); + registerTwoWay(BlockID.END_PORTAL, Material.END_PORTAL); + registerTwoWay(BlockID.END_PORTAL_FRAME, Material.END_PORTAL_FRAME); + registerTwoWay(BlockID.END_STONE, Material.END_STONE); + registerTwoWay(BlockID.DRAGON_EGG, Material.DRAGON_EGG); + registerTwoWay(BlockID.REDSTONE_LAMP, Material.REDSTONE_LAMP); + registerBukkitToBukkit(BlockID.LIT_REDSTONE_LAMP, Material.REDSTONE_LAMP); + registerTwoWay(BlockID.DROPPER, Material.DROPPER); + registerTwoWay(BlockID.ACTIVATOR_RAIL, Material.ACTIVATOR_RAIL); + registerTwoWay(BlockID.COCOA, Material.COCOA); + registerTwoWay(BlockID.SANDSTONE_STAIRS, Material.SANDSTONE_STAIRS); + registerTwoWay(BlockID.EMERALD_ORE, Material.EMERALD_ORE); + registerTwoWay(BlockID.ENDER_CHEST, Material.ENDER_CHEST); + registerTwoWay(BlockID.TRIPWIRE_HOOK, Material.TRIPWIRE_HOOK); + registerTwoWay(BlockID.TRIPWIRE, Material.TRIPWIRE); + registerTwoWay(BlockID.EMERALD_BLOCK, Material.EMERALD_BLOCK); + registerTwoWay(BlockID.SPRUCE_WOOD_STAIRS, Material.SPRUCE_STAIRS); + registerTwoWay(BlockID.BIRCH_WOOD_STAIRS, Material.BIRCH_STAIRS); + registerTwoWay(BlockID.JUNGLE_WOOD_STAIRS, Material.JUNGLE_STAIRS); + registerTwoWay(BlockID.BEACON, Material.BEACON); + registerTwoWay(BlockID.COBBLESTONE_WALL, Material.COBBLESTONE_WALL); + registerTwoWay(BlockID.FLOWER_POT_BLOCK, Material.FLOWER_POT); + registerTwoWay(BlockID.CARROT_BLOCK, Material.CARROTS); + registerTwoWay(BlockID.POTATO_BLOCK, Material.POTATOES); + registerTwoWay(BlockID.WOODEN_BUTTON, Material.OAK_BUTTON); + registerTwoWay(BlockID.SKULL_BLOCK, Material.SKELETON_SKULL); + registerTwoWay(BlockID.ANVIL, Material.ANVIL); + registerTwoWay(BlockID.TRAPPED_CHEST, Material.TRAPPED_CHEST); + registerTwoWay(BlockID.LIGHT_WEIGHTED_PRESSURE_PLATE, Material.LIGHT_WEIGHTED_PRESSURE_PLATE); + registerTwoWay(BlockID.HEAVY_WEIGHTED_PRESSURE_PLATE, Material.HEAVY_WEIGHTED_PRESSURE_PLATE); + registerTwoWay(BlockID.UNPOWERED_COMPARATOR, Material.COMPARATOR); + registerBukkitToBukkit(BlockID.POWERED_COMPARATOR, Material.COMPARATOR); + registerTwoWay(BlockID.DAYLIGHT_DETECTOR, Material.DAYLIGHT_DETECTOR); + registerTwoWay(BlockID.REDSTONE_BLOCK, Material.REDSTONE_BLOCK); + registerTwoWay(BlockID.QUARTZ_ORE, Material.QUARTZ); + registerTwoWay(BlockID.HOPPER_BLOCK, Material.HOPPER); + registerTwoWay(BlockID.QUARTZ_BLOCK, Material.QUARTZ_BLOCK); + registerTwoWay(BlockID.QUARTZ_STAIRS, Material.QUARTZ_STAIRS); + registerBukkitToBukkit(BlockID.DOUBLE_WOOD_SLAB, Material.OAK_SLAB); + registerTwoWay(BlockID.WOOD_SLAB, Material.OAK_SLAB); + registerTwoWay(BlockID.STAINED_TERRACOTTA, Material.WHITE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.STAINED_HARDENED_CLAY, Material.TERRACOTTA); + registerTwoWay(BlockID.STAINED_GLASS_PANE, Material.WHITE_STAINED_GLASS_PANE); + registerTwoWay(BlockID.LEAVES2, Material.ACACIA_LEAVES); + registerTwoWay(BlockID.WOOD2, Material.ACACIA_LOG); + registerTwoWay(BlockID.ACACIA_WOOD_STAIRS, Material.ACACIA_STAIRS); + registerTwoWay(BlockID.DARK_OAK_WOOD_STAIRS, Material.DARK_OAK_STAIRS); + registerTwoWay(BlockID.SLIME_BLOCK, Material.SLIME_BLOCK); + registerTwoWay(BlockID.IRON_TRAPDOOR, Material.IRON_TRAPDOOR); + registerTwoWay(BlockID.PRISMARINE, Material.PRISMARINE); + registerTwoWay(BlockID.SEA_LANTERN, Material.SEA_LANTERN); + registerTwoWay(BlockID.HAY_BALE, Material.HAY_BLOCK); + registerTwoWay(BlockID.CARPET, Material.WHITE_CARPET); + registerTwoWay(BlockID.TERRACOTTA, Material.TERRACOTTA); + registerTwoWay(BlockID.COAL_BLOCK, Material.COAL_BLOCK); + registerTwoWay(BlockID.PACKED_ICE, Material.PACKED_ICE); + registerTwoWay(BlockID.DOUBLE_PLANT, Material.ROSE_BUSH); + registerBukkitToBukkit(BlockID.DAYLIGHT_DETECTOR_INVERTED, Material.DAYLIGHT_DETECTOR); + registerTwoWay(BlockID.RED_SANDSTONE, Material.RED_SANDSTONE); + registerTwoWay(BlockID.RED_SANDSTONE_STAIRS, Material.RED_SANDSTONE_STAIRS); + registerBukkitToBukkit(BlockID.DOUBLE_RED_SANDSTONE_SLAB, Material.RED_SANDSTONE_SLAB); + registerTwoWay(BlockID.RED_SANDSTONE_SLAB, Material.RED_SANDSTONE_SLAB); + registerTwoWay(BlockID.FENCE_GATE_SPRUCE, Material.SPRUCE_FENCE_GATE); + registerTwoWay(BlockID.FENCE_GATE_BIRCH, Material.BIRCH_FENCE_GATE); + registerTwoWay(BlockID.FENCE_GATE_JUNGLE, Material.JUNGLE_FENCE_GATE); + registerTwoWay(BlockID.FENCE_GATE_DARK_OAK, Material.DARK_OAK_FENCE_GATE); + registerTwoWay(BlockID.FENCE_GATE_ACACIA, Material.ACACIA_FENCE_GATE); + registerTwoWay(BlockID.SPRUCE_DOOR_BLOCK, Material.SPRUCE_DOOR); + registerTwoWay(BlockID.BIRCH_DOOR_BLOCK, Material.BIRCH_DOOR); + registerTwoWay(BlockID.JUNGLE_DOOR_BLOCK, Material.JUNGLE_DOOR); + registerTwoWay(BlockID.ACACIA_DOOR_BLOCK, Material.ACACIA_DOOR); + registerTwoWay(BlockID.DARK_OAK_DOOR_BLOCK, Material.DARK_OAK_DOOR); + registerTwoWay(BlockID.GRASS_PATH, Material.GRASS_PATH); + registerTwoWay(BlockID.ITEM_FRAME_BLOCK, Material.ITEM_FRAME); + registerTwoWay(BlockID.CHORUS_FLOWER, Material.CHORUS_FLOWER); + registerTwoWay(BlockID.PURPUR_BLOCK, Material.PURPUR_BLOCK); + registerTwoWay(BlockID.PURPUR_STAIRS, Material.PURPUR_STAIRS); + registerTwoWay(BlockID.UNDYED_SHULKER_BOX, Material.SHULKER_BOX); + registerTwoWay(BlockID.END_BRICKS, Material.END_STONE_BRICKS); + registerTwoWay(BlockID.ICE_FROSTED, Material.FROSTED_ICE); + registerTwoWay(BlockID.END_ROD, Material.END_ROD); + registerTwoWay(BlockID.END_GATEWAY, Material.END_GATEWAY); + registerTwoWay(BlockID.MAGMA, Material.MAGMA_BLOCK); + registerTwoWay(BlockID.BLOCK_NETHER_WART_BLOCK, Material.NETHER_WART_BLOCK); + registerTwoWay(BlockID.RED_NETHER_BRICK, Material.RED_NETHER_BRICKS); + registerTwoWay(BlockID.BONE_BLOCK, Material.BONE_BLOCK); + registerTwoWay(BlockID.SHULKER_BOX, Material.SHULKER_BOX); + registerTwoWay(BlockID.PURPLE_GLAZED_TERRACOTTA, Material.PURPLE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.WHITE_GLAZED_TERRACOTTA, Material.WHITE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.ORANGE_GLAZED_TERRACOTTA, Material.ORANGE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.MAGENTA_GLAZED_TERRACOTTA, Material.MAGENTA_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.LIGHT_BLUE_GLAZED_TERRACOTTA, Material.LIGHT_BLUE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.YELLOW_GLAZED_TERRACOTTA, Material.YELLOW_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.LIME_GLAZED_TERRACOTTA, Material.LIME_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.PINK_GLAZED_TERRACOTTA, Material.PINK_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.GRAY_GLAZED_TERRACOTTA, Material.GRAY_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.SILVER_GLAZED_TERRACOTTA, Material.LIGHT_GRAY_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.CYAN_GLAZED_TERRACOTTA, Material.CYAN_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.BLUE_GLAZED_TERRACOTTA, Material.BLUE_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.BROWN_GLAZED_TERRACOTTA, Material.BROWN_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.GREEN_GLAZED_TERRACOTTA, Material.GREEN_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.RED_GLAZED_TERRACOTTA, Material.RED_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.BLACK_GLAZED_TERRACOTTA, Material.BLACK_GLAZED_TERRACOTTA); + registerTwoWay(BlockID.CONCRETE, Material.WHITE_CONCRETE); + registerTwoWay(BlockID.CONCRETE_POWDER, Material.WHITE_CONCRETE_POWDER); + registerTwoWay(BlockID.CHORUS_PLANT, Material.CHORUS_PLANT); + registerTwoWay(BlockID.STAINED_GLASS, Material.WHITE_STAINED_GLASS); + registerTwoWay(BlockID.PODZOL, Material.PODZOL); + registerTwoWay(BlockID.BEETROOT_BLOCK, Material.BEETROOTS); + registerBukkitToBukkit(BlockID.STONECUTTER, Material.COBBLESTONE); + registerBukkitToBukkit(BlockID.GLOWING_OBSIDIAN, Material.OBSIDIAN); + registerBukkitToBukkit(BlockID.NETHER_REACTOR, Material.RED_NETHER_BRICKS); + registerTwoWay(BlockID.PISTON_EXTENSION, Material.MOVING_PISTON); + registerTwoWay(BlockID.OBSERVER, Material.OBSERVER); + + // Legacy materials + registerBukkitToNukkit(BlockID.AIR, Material.LEGACY_AIR); + registerBukkitToNukkit(BlockID.STONE, Material.LEGACY_STONE); + registerBukkitToNukkit(BlockID.GRASS, Material.LEGACY_GRASS); + registerBukkitToNukkit(BlockID.DIRT, Material.LEGACY_DIRT); + registerBukkitToNukkit(BlockID.COBBLESTONE, Material.LEGACY_COBBLESTONE); + registerBukkitToNukkit(BlockID.WOOD, Material.LEGACY_WOOD); + registerBukkitToNukkit(BlockID.SAPLING, Material.LEGACY_SAPLING); + registerBukkitToNukkit(BlockID.BEDROCK, Material.LEGACY_BEDROCK); + registerBukkitToNukkit(BlockID.WATER, Material.LEGACY_WATER); + registerBukkitToNukkit(BlockID.STILL_WATER, Material.LEGACY_STATIONARY_WATER); + registerBukkitToNukkit(BlockID.LAVA, Material.LEGACY_LAVA); + registerBukkitToNukkit(BlockID.STILL_LAVA, Material.LEGACY_STATIONARY_LAVA); + registerBukkitToNukkit(BlockID.SAND, Material.LEGACY_SAND); + registerBukkitToNukkit(BlockID.GRAVEL, Material.LEGACY_GRAVEL); + registerBukkitToNukkit(BlockID.GOLD_ORE, Material.LEGACY_GOLD_ORE); + registerBukkitToNukkit(BlockID.IRON_ORE, Material.LEGACY_IRON_ORE); + registerBukkitToNukkit(BlockID.COAL_ORE, Material.LEGACY_COAL_ORE); + registerBukkitToNukkit(BlockID.LOG, Material.LEGACY_LOG); + registerBukkitToNukkit(BlockID.LEAVES, Material.LEGACY_LEAVES); + registerBukkitToNukkit(BlockID.SPONGE, Material.LEGACY_SPONGE); + registerBukkitToNukkit(BlockID.GLASS, Material.LEGACY_GLASS); + registerBukkitToNukkit(BlockID.LAPIS_ORE, Material.LEGACY_LAPIS_ORE); + registerBukkitToNukkit(BlockID.LAPIS_BLOCK, Material.LEGACY_LAPIS_BLOCK); + registerBukkitToNukkit(BlockID.DISPENSER, Material.LEGACY_DISPENSER); + registerBukkitToNukkit(BlockID.SANDSTONE, Material.LEGACY_SANDSTONE); + registerBukkitToNukkit(BlockID.NOTEBLOCK, Material.LEGACY_NOTE_BLOCK); + registerBukkitToNukkit(BlockID.BED_BLOCK, Material.LEGACY_BED_BLOCK); + registerBukkitToNukkit(BlockID.POWERED_RAIL, Material.LEGACY_POWERED_RAIL); + registerBukkitToNukkit(BlockID.DETECTOR_RAIL, Material.LEGACY_DETECTOR_RAIL); + registerBukkitToNukkit(BlockID.STICKY_PISTON, Material.LEGACY_PISTON_STICKY_BASE); + registerBukkitToNukkit(BlockID.COBWEB, Material.LEGACY_WEB); + registerBukkitToNukkit(BlockID.TALL_GRASS, Material.LEGACY_LONG_GRASS); + registerBukkitToNukkit(BlockID.DEAD_BUSH, Material.LEGACY_DEAD_BUSH); + registerBukkitToNukkit(BlockID.PISTON, Material.LEGACY_PISTON_BASE); + registerBukkitToNukkit(BlockID.PISTON_EXTENSION, Material.LEGACY_PISTON_EXTENSION); + registerBukkitToNukkit(BlockID.WOOL, Material.LEGACY_WOOL); + registerBukkitToNukkit(BlockID.PISTON_HEAD, Material.LEGACY_PISTON_MOVING_PIECE); + registerBukkitToNukkit(BlockID.FLOWER, Material.LEGACY_YELLOW_FLOWER); + registerBukkitToNukkit(BlockID.RED_FLOWER, Material.LEGACY_RED_ROSE); + registerBukkitToNukkit(BlockID.BROWN_MUSHROOM, Material.LEGACY_BROWN_MUSHROOM); + registerBukkitToNukkit(BlockID.RED_MUSHROOM, Material.LEGACY_RED_MUSHROOM); + registerBukkitToNukkit(BlockID.GOLD_BLOCK, Material.LEGACY_GOLD_BLOCK); + registerBukkitToNukkit(BlockID.IRON_BLOCK, Material.LEGACY_IRON_BLOCK); + registerBukkitToNukkit(BlockID.DOUBLE_STONE_SLAB, Material.LEGACY_DOUBLE_STEP); + registerBukkitToNukkit(BlockID.STONE_SLAB, Material.LEGACY_STEP); + registerBukkitToNukkit(BlockID.BRICKS, Material.LEGACY_BRICK); + registerBukkitToNukkit(BlockID.TNT, Material.LEGACY_TNT); + registerBukkitToNukkit(BlockID.BOOKSHELF, Material.LEGACY_BOOKSHELF); + registerBukkitToNukkit(BlockID.MOSS_STONE, Material.LEGACY_MOSSY_COBBLESTONE); + registerBukkitToNukkit(BlockID.OBSIDIAN, Material.LEGACY_OBSIDIAN); + registerBukkitToNukkit(BlockID.TORCH, Material.LEGACY_TORCH); + registerBukkitToNukkit(BlockID.FIRE, Material.LEGACY_FIRE); + registerBukkitToNukkit(BlockID.MONSTER_SPAWNER, Material.LEGACY_MOB_SPAWNER); + registerBukkitToNukkit(BlockID.WOOD_STAIRS, Material.LEGACY_WOOD_STAIRS); + registerBukkitToNukkit(BlockID.CHEST, Material.LEGACY_CHEST); + registerBukkitToNukkit(BlockID.REDSTONE_WIRE, Material.LEGACY_REDSTONE_WIRE); + registerBukkitToNukkit(BlockID.DIAMOND_ORE, Material.LEGACY_DIAMOND_ORE); + registerBukkitToNukkit(BlockID.DIAMOND_BLOCK, Material.LEGACY_DIAMOND_BLOCK); + registerBukkitToNukkit(BlockID.WORKBENCH, Material.LEGACY_WORKBENCH); + registerBukkitToNukkit(BlockID.WHEAT_BLOCK, Material.LEGACY_CROPS); + registerBukkitToNukkit(BlockID.FARMLAND, Material.LEGACY_SOIL); + registerBukkitToNukkit(BlockID.FURNACE, Material.LEGACY_FURNACE); + registerBukkitToNukkit(BlockID.BURNING_FURNACE, Material.LEGACY_BURNING_FURNACE); + registerBukkitToNukkit(BlockID.SIGN_POST, Material.LEGACY_SIGN_POST); + registerBukkitToNukkit(BlockID.DOOR_BLOCK, Material.LEGACY_WOODEN_DOOR); + registerBukkitToNukkit(BlockID.LADDER, Material.LEGACY_LADDER); + registerBukkitToNukkit(BlockID.RAIL, Material.LEGACY_RAILS); + registerBukkitToNukkit(BlockID.COBBLESTONE_STAIRS, Material.LEGACY_COBBLESTONE_STAIRS); + registerBukkitToNukkit(BlockID.WALL_SIGN, Material.LEGACY_WALL_SIGN); + registerBukkitToNukkit(BlockID.LEVER, Material.LEGACY_LEVER); + registerBukkitToNukkit(BlockID.STONE_PRESSURE_PLATE, Material.LEGACY_STONE_PLATE); + registerBukkitToNukkit(BlockID.IRON_DOOR_BLOCK, Material.LEGACY_IRON_DOOR_BLOCK); + registerBukkitToNukkit(BlockID.WOODEN_PRESSURE_PLATE, Material.LEGACY_WOOD_PLATE); + registerBukkitToNukkit(BlockID.REDSTONE_ORE, Material.LEGACY_REDSTONE_ORE); + registerBukkitToNukkit(BlockID.GLOWING_REDSTONE_ORE, Material.LEGACY_GLOWING_REDSTONE_ORE); + registerBukkitToNukkit(BlockID.UNLIT_REDSTONE_TORCH, Material.LEGACY_REDSTONE_TORCH_OFF); + registerBukkitToNukkit(BlockID.REDSTONE_TORCH, Material.LEGACY_REDSTONE_TORCH_ON); + registerBukkitToNukkit(BlockID.STONE_BUTTON, Material.LEGACY_STONE_BUTTON); + registerBukkitToNukkit(BlockID.SNOW, Material.LEGACY_SNOW); + registerBukkitToNukkit(BlockID.ICE, Material.LEGACY_ICE); + registerBukkitToNukkit(BlockID.SNOW_BLOCK, Material.LEGACY_SNOW_BLOCK); + registerBukkitToNukkit(BlockID.CACTUS, Material.LEGACY_CACTUS); + registerBukkitToNukkit(BlockID.CLAY_BLOCK, Material.LEGACY_CLAY); + registerBukkitToNukkit(BlockID.SUGARCANE_BLOCK, Material.LEGACY_SUGAR_CANE_BLOCK); + registerBukkitToNukkit(BlockID.JUKEBOX, Material.LEGACY_JUKEBOX); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_FENCE); + registerBukkitToNukkit(BlockID.PUMPKIN, Material.LEGACY_PUMPKIN); + registerBukkitToNukkit(BlockID.NETHERRACK, Material.LEGACY_NETHERRACK); + registerBukkitToNukkit(BlockID.SOUL_SAND, Material.LEGACY_SOUL_SAND); + registerBukkitToNukkit(BlockID.GLOWSTONE, Material.LEGACY_GLOWSTONE); + registerBukkitToNukkit(BlockID.NETHER_PORTAL, Material.LEGACY_PORTAL); + registerBukkitToNukkit(BlockID.JACK_O_LANTERN, Material.LEGACY_JACK_O_LANTERN); + registerBukkitToNukkit(BlockID.CAKE_BLOCK, Material.LEGACY_CAKE_BLOCK); + registerBukkitToNukkit(BlockID.UNPOWERED_REPEATER, Material.LEGACY_DIODE_BLOCK_OFF); + registerBukkitToNukkit(BlockID.POWERED_REPEATER, Material.LEGACY_DIODE_BLOCK_ON); + registerBukkitToNukkit(BlockID.STAINED_GLASS, Material.LEGACY_STAINED_GLASS); + registerBukkitToNukkit(BlockID.TRAPDOOR, Material.LEGACY_TRAP_DOOR); + registerBukkitToNukkit(BlockID.MONSTER_EGG, Material.LEGACY_MONSTER_EGGS); + registerBukkitToNukkit(BlockID.STONE_BRICK, Material.LEGACY_SMOOTH_BRICK); + registerBukkitToNukkit(BlockID.BROWN_MUSHROOM_BLOCK, Material.LEGACY_HUGE_MUSHROOM_1); + registerBukkitToNukkit(BlockID.RED_MUSHROOM_BLOCK, Material.LEGACY_HUGE_MUSHROOM_2); + registerBukkitToNukkit(BlockID.IRON_BAR, Material.LEGACY_IRON_FENCE); + registerBukkitToNukkit(BlockID.GLASS_PANE, Material.LEGACY_THIN_GLASS); + registerBukkitToNukkit(BlockID.MELON_BLOCK, Material.LEGACY_MELON_BLOCK); + registerBukkitToNukkit(BlockID.PUMPKIN_STEM, Material.LEGACY_PUMPKIN_STEM); + registerBukkitToNukkit(BlockID.MELON_STEM, Material.LEGACY_MELON_STEM); + registerBukkitToNukkit(BlockID.VINE, Material.LEGACY_VINE); + registerBukkitToNukkit(BlockID.FENCE_GATE, Material.LEGACY_FENCE_GATE); + registerBukkitToNukkit(BlockID.BRICK_STAIRS, Material.LEGACY_BRICK_STAIRS); + registerBukkitToNukkit(BlockID.STONE_BRICK_STAIRS, Material.LEGACY_SMOOTH_STAIRS); + registerBukkitToNukkit(BlockID.MYCELIUM, Material.LEGACY_MYCEL); + registerBukkitToNukkit(BlockID.WATER_LILY, Material.LEGACY_WATER_LILY); + registerBukkitToNukkit(BlockID.NETHER_BRICKS, Material.LEGACY_NETHER_BRICK); + registerBukkitToNukkit(BlockID.NETHER_BRICK_FENCE, Material.LEGACY_NETHER_FENCE); + registerBukkitToNukkit(BlockID.NETHER_BRICKS_STAIRS, Material.LEGACY_NETHER_BRICK_STAIRS); + registerBukkitToNukkit(BlockID.NETHER_WART_BLOCK, Material.LEGACY_NETHER_WARTS); + registerBukkitToNukkit(BlockID.ENCHANTMENT_TABLE, Material.LEGACY_ENCHANTMENT_TABLE); + registerBukkitToNukkit(BlockID.BREWING_STAND_BLOCK, Material.LEGACY_BREWING_STAND); + registerBukkitToNukkit(BlockID.CAULDRON_BLOCK, Material.LEGACY_CAULDRON); + registerBukkitToNukkit(BlockID.END_PORTAL, Material.LEGACY_ENDER_PORTAL); + registerBukkitToNukkit(BlockID.END_PORTAL_FRAME, Material.LEGACY_ENDER_PORTAL_FRAME); + registerBukkitToNukkit(BlockID.END_STONE, Material.LEGACY_ENDER_STONE); + registerBukkitToNukkit(BlockID.DRAGON_EGG, Material.LEGACY_DRAGON_EGG); + registerBukkitToNukkit(BlockID.LIT_REDSTONE_LAMP, Material.LEGACY_REDSTONE_LAMP_OFF); + registerBukkitToNukkit(BlockID.REDSTONE_LAMP, Material.LEGACY_REDSTONE_LAMP_ON); + registerBukkitToNukkit(BlockID.DOUBLE_WOOD_SLAB, Material.LEGACY_WOOD_DOUBLE_STEP); + registerBukkitToNukkit(BlockID.WOOD_SLAB, Material.LEGACY_WOOD_STEP); + registerBukkitToNukkit(BlockID.COCOA, Material.LEGACY_COCOA); + registerBukkitToNukkit(BlockID.SANDSTONE_STAIRS, Material.LEGACY_SANDSTONE_STAIRS); + registerBukkitToNukkit(BlockID.EMERALD_ORE, Material.LEGACY_EMERALD_ORE); + registerBukkitToNukkit(BlockID.ENDER_CHEST, Material.LEGACY_ENDER_CHEST); + registerBukkitToNukkit(BlockID.TRIPWIRE_HOOK, Material.LEGACY_TRIPWIRE_HOOK); + registerBukkitToNukkit(BlockID.TRIPWIRE, Material.LEGACY_TRIPWIRE); + registerBukkitToNukkit(BlockID.EMERALD_BLOCK, Material.LEGACY_EMERALD_BLOCK); + registerBukkitToNukkit(BlockID.SPRUCE_WOOD_STAIRS, Material.LEGACY_SPRUCE_WOOD_STAIRS); + registerBukkitToNukkit(BlockID.BIRCH_WOOD_STAIRS, Material.LEGACY_BIRCH_WOOD_STAIRS); + registerBukkitToNukkit(BlockID.JUNGLE_WOOD_STAIRS, Material.LEGACY_JUNGLE_WOOD_STAIRS); + registerBukkitToNukkit(BlockID.BEACON, Material.LEGACY_BEACON); + registerBukkitToNukkit(BlockID.COBBLE_WALL, Material.LEGACY_COBBLE_WALL); + registerBukkitToNukkit(BlockID.FLOWER_POT_BLOCK, Material.LEGACY_FLOWER_POT); + registerBukkitToNukkit(BlockID.CARROT_BLOCK, Material.LEGACY_CARROT); + registerBukkitToNukkit(BlockID.POTATO_BLOCK, Material.LEGACY_POTATO); + registerBukkitToNukkit(BlockID.WOODEN_BUTTON, Material.LEGACY_WOOD_BUTTON); + registerBukkitToNukkit(BlockID.SKULL_BLOCK, Material.LEGACY_SKULL); + registerBukkitToNukkit(BlockID.ANVIL, Material.LEGACY_ANVIL); + registerBukkitToNukkit(BlockID.TRAPPED_CHEST, Material.LEGACY_TRAPPED_CHEST); + registerBukkitToNukkit(BlockID.LIGHT_WEIGHTED_PRESSURE_PLATE, Material.LEGACY_GOLD_PLATE); + registerBukkitToNukkit(BlockID.HEAVY_WEIGHTED_PRESSURE_PLATE, Material.LEGACY_IRON_PLATE); + registerBukkitToNukkit(BlockID.UNPOWERED_COMPARATOR, Material.LEGACY_REDSTONE_COMPARATOR_OFF); + registerBukkitToNukkit(BlockID.POWERED_COMPARATOR, Material.LEGACY_REDSTONE_COMPARATOR_ON); + registerBukkitToNukkit(BlockID.DAYLIGHT_DETECTOR, Material.LEGACY_DAYLIGHT_DETECTOR); + registerBukkitToNukkit(BlockID.REDSTONE_BLOCK, Material.LEGACY_REDSTONE_BLOCK); + registerBukkitToNukkit(BlockID.QUARTZ_ORE, Material.LEGACY_QUARTZ_ORE); + registerBukkitToNukkit(BlockID.HOPPER_BLOCK, Material.LEGACY_HOPPER); + registerBukkitToNukkit(BlockID.QUARTZ_BLOCK, Material.LEGACY_QUARTZ_BLOCK); + registerBukkitToNukkit(BlockID.QUARTZ_STAIRS, Material.LEGACY_QUARTZ_STAIRS); + registerBukkitToNukkit(BlockID.ACTIVATOR_RAIL, Material.LEGACY_ACTIVATOR_RAIL); + registerBukkitToNukkit(BlockID.DROPPER, Material.LEGACY_DROPPER); + registerBukkitToNukkit(BlockID.STAINED_HARDENED_CLAY, Material.LEGACY_STAINED_CLAY); + registerBukkitToNukkit(BlockID.STAINED_GLASS_PANE, Material.LEGACY_STAINED_GLASS_PANE); + registerBukkitToNukkit(BlockID.LEAVES2, Material.LEGACY_LEAVES_2); + registerBukkitToNukkit(BlockID.LOG2, Material.LEGACY_LOG_2); + registerBukkitToNukkit(BlockID.ACACIA_WOODEN_STAIRS, Material.LEGACY_ACACIA_STAIRS); + registerBukkitToNukkit(BlockID.DARK_OAK_WOODEN_STAIRS, Material.LEGACY_DARK_OAK_STAIRS); + registerBukkitToNukkit(BlockID.SLIME_BLOCK, Material.LEGACY_SLIME_BLOCK); + registerBukkitToNukkit(BlockID.INVISIBLE_BEDROCK, Material.LEGACY_BARRIER); + registerBukkitToNukkit(BlockID.IRON_TRAPDOOR, Material.LEGACY_IRON_TRAPDOOR); + registerBukkitToNukkit(BlockID.PRISMARINE, Material.LEGACY_PRISMARINE); + registerBukkitToNukkit(BlockID.SEA_LANTERN, Material.LEGACY_SEA_LANTERN); + registerBukkitToNukkit(BlockID.HAY_BALE, Material.LEGACY_HAY_BLOCK); + registerBukkitToNukkit(BlockID.CARPET, Material.LEGACY_CARPET); + registerBukkitToNukkit(BlockID.TERRACOTTA, Material.LEGACY_HARD_CLAY); + registerBukkitToNukkit(BlockID.COAL_BLOCK, Material.LEGACY_COAL_BLOCK); + registerBukkitToNukkit(BlockID.PACKED_ICE, Material.LEGACY_PACKED_ICE); + registerBukkitToNukkit(BlockID.DOUBLE_PLANT, Material.LEGACY_DOUBLE_PLANT); + registerBukkitToNukkit(BlockID.DAYLIGHT_DETECTOR_INVERTED, Material.LEGACY_DAYLIGHT_DETECTOR_INVERTED); + registerBukkitToNukkit(BlockID.RED_SANDSTONE, Material.LEGACY_RED_SANDSTONE); + registerBukkitToNukkit(BlockID.RED_SANDSTONE_STAIRS, Material.LEGACY_RED_SANDSTONE_STAIRS); + registerBukkitToNukkit(BlockID.DOUBLE_STONE_SLAB, Material.LEGACY_DOUBLE_STONE_SLAB2); + registerBukkitToNukkit(BlockID.STONE_SLAB, Material.LEGACY_STONE_SLAB2); + registerBukkitToNukkit(BlockID.FENCE_GATE_SPRUCE, Material.LEGACY_SPRUCE_FENCE_GATE); + registerBukkitToNukkit(BlockID.FENCE_GATE_BIRCH, Material.LEGACY_BIRCH_FENCE_GATE); + registerBukkitToNukkit(BlockID.FENCE_GATE_JUNGLE, Material.LEGACY_JUNGLE_FENCE_GATE); + registerBukkitToNukkit(BlockID.FENCE_GATE_DARK_OAK, Material.LEGACY_DARK_OAK_FENCE_GATE); + registerBukkitToNukkit(BlockID.FENCE_GATE_ACACIA, Material.LEGACY_ACACIA_FENCE_GATE); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_SPRUCE_FENCE); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_BIRCH_FENCE); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_JUNGLE_FENCE); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_DARK_OAK_FENCE); + registerBukkitToNukkit(BlockID.FENCE, Material.LEGACY_ACACIA_FENCE); + registerBukkitToNukkit(BlockID.SPRUCE_DOOR_BLOCK, Material.LEGACY_SPRUCE_DOOR); + registerBukkitToNukkit(BlockID.BIRCH_DOOR_BLOCK, Material.LEGACY_BIRCH_DOOR); + registerBukkitToNukkit(BlockID.JUNGLE_DOOR_BLOCK, Material.LEGACY_JUNGLE_DOOR); + registerBukkitToNukkit(BlockID.ACACIA_DOOR_BLOCK, Material.LEGACY_ACACIA_DOOR); + registerBukkitToNukkit(BlockID.DARK_OAK_DOOR_BLOCK, Material.LEGACY_DARK_OAK_DOOR); + registerBukkitToNukkit(BlockID.END_ROD, Material.LEGACY_END_ROD); + registerBukkitToNukkit(BlockID.CHORUS_PLANT, Material.LEGACY_CHORUS_PLANT); + registerBukkitToNukkit(BlockID.CHORUS_FLOWER, Material.LEGACY_CHORUS_FLOWER); + registerBukkitToNukkit(BlockID.PURPUR_BLOCK, Material.LEGACY_PURPUR_BLOCK); + registerBukkitToNukkit(202, Material.LEGACY_PURPUR_PILLAR); + registerBukkitToNukkit(BlockID.PURPUR_STAIRS, Material.LEGACY_PURPUR_STAIRS); + registerBukkitToNukkit(BlockID.END_BRICKS, Material.LEGACY_END_BRICKS); + registerBukkitToNukkit(BlockID.BEETROOT_BLOCK, Material.LEGACY_BEETROOT_BLOCK); + registerBukkitToNukkit(BlockID.GRASS_PATH, Material.LEGACY_GRASS_PATH); + registerBukkitToNukkit(BlockID.END_GATEWAY, Material.LEGACY_END_GATEWAY); + registerBukkitToNukkit(BlockID.ICE_FROSTED, Material.LEGACY_FROSTED_ICE); + registerBukkitToNukkit(BlockID.MAGMA, Material.LEGACY_MAGMA); + registerBukkitToNukkit(BlockID.NETHER_WART_BLOCK, Material.LEGACY_NETHER_WART_BLOCK); + registerBukkitToNukkit(BlockID.RED_NETHER_BRICK, Material.LEGACY_RED_NETHER_BRICK); + registerBukkitToNukkit(BlockID.BONE_BLOCK, Material.LEGACY_BONE_BLOCK); + registerBukkitToNukkit(BlockID.AIR, Material.LEGACY_STRUCTURE_VOID); + registerBukkitToNukkit(BlockID.OBSERVER, Material.LEGACY_OBSERVER); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_WHITE_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_ORANGE_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_MAGENTA_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_LIGHT_BLUE_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_YELLOW_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_LIME_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_PINK_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_GRAY_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_SILVER_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_CYAN_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_PURPLE_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_BLUE_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_BROWN_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_GREEN_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_RED_SHULKER_BOX); + registerBukkitToNukkit(BlockID.SHULKER_BOX, Material.LEGACY_BLACK_SHULKER_BOX); + registerBukkitToNukkit(BlockID.WHITE_GLAZED_TERRACOTTA, Material.LEGACY_WHITE_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.ORANGE_GLAZED_TERRACOTTA, Material.LEGACY_ORANGE_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.MAGENTA_GLAZED_TERRACOTTA, Material.LEGACY_MAGENTA_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.LIGHT_BLUE_GLAZED_TERRACOTTA, Material.LEGACY_LIGHT_BLUE_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.YELLOW_GLAZED_TERRACOTTA, Material.LEGACY_YELLOW_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.LIME_GLAZED_TERRACOTTA, Material.LEGACY_LIME_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.PINK_GLAZED_TERRACOTTA, Material.LEGACY_PINK_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.GRAY_GLAZED_TERRACOTTA, Material.LEGACY_GRAY_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.SILVER_GLAZED_TERRACOTTA, Material.LEGACY_SILVER_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.CYAN_GLAZED_TERRACOTTA, Material.LEGACY_CYAN_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.PURPLE_GLAZED_TERRACOTTA, Material.LEGACY_PURPLE_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.BLUE_GLAZED_TERRACOTTA, Material.LEGACY_BLUE_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.BROWN_GLAZED_TERRACOTTA, Material.LEGACY_BROWN_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.GREEN_GLAZED_TERRACOTTA, Material.LEGACY_GREEN_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.RED_GLAZED_TERRACOTTA, Material.LEGACY_RED_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.BLACK_GLAZED_TERRACOTTA, Material.LEGACY_BLACK_GLAZED_TERRACOTTA); + registerBukkitToNukkit(BlockID.CONCRETE, Material.LEGACY_CONCRETE); + registerBukkitToNukkit(BlockID.CONCRETE_POWDER, Material.LEGACY_CONCRETE_POWDER); + registerBukkitToNukkit(BlockID.AIR, Material.LEGACY_STRUCTURE_BLOCK); + } + + /** + * Gets the Bukkit (non-legacy) material for the given Nukkit block id. + * + * @param nukkitId + * The Nukkit block id. + * @return The material, or AIR for negative Nukkit block ids, or STONE if + * unknown. + */ + public static Material getMaterial(int nukkitId) { + if (nukkitId < 0) { + return Material.AIR; + } + if (nukkitId >= nukkitToBukkit.length) { + return Material.STONE; + } + Material material = nukkitToBukkit[nukkitId]; + if (material == null) { + return Material.STONE; + } + return material; + } + + /** + * Gets the Nukkit block for the Bukkit material. The Bukkit material may be + * a legacy material. + * + * @param material + * The material. + * @param blockData + * The block data, 0 by default. + * @return The block. + */ + public static Block getNukkitBlock(Material material, int blockData) { + int nukkit = bukkitToNukkit[material.ordinal()]; + return cn.nukkit.block.Block.get(nukkit, blockData); + } + + private static void registerBukkitToBukkit(int nukkit, Material bukkit) { + nukkitToBukkit[nukkit] = bukkit; + } + + private static void registerBukkitToNukkit(int nukkit, Material bukkit) { + bukkitToNukkit[bukkit.ordinal()] = (char) nukkit; + } + + private static void registerTwoWay(int nukkit, Material bukkit) { + registerBukkitToNukkit(nukkit, bukkit); + registerBukkitToBukkit(nukkit, bukkit); + } +} diff --git a/src/main/java/nl/rutgerkok/pokkit/blockdata/PokkitBlockData.java b/src/main/java/nl/rutgerkok/pokkit/blockdata/PokkitBlockData.java new file mode 100644 index 0000000..719e862 --- /dev/null +++ b/src/main/java/nl/rutgerkok/pokkit/blockdata/PokkitBlockData.java @@ -0,0 +1,135 @@ +package nl.rutgerkok.pokkit.blockdata; + +import java.util.Objects; + +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + +import nl.rutgerkok.pokkit.Pokkit; + +import cn.nukkit.block.Block; + +/** + * Nukkit does not have block states yet, so implementing this class is a bit + * difficult. + * + */ +public class PokkitBlockData implements BlockData { + + public static PokkitBlockData createBlockData(Material material, int blockData) { + return new PokkitBlockData(BlockMap.getNukkitBlock(material, blockData)); + } + + /** + * Uses a simple "blockId:blockData" format. + * + * @param inputString + * The input string. + * @return The parsed block data. + * @throws IllegalArgumentException + * If no such material exists, or the string is in an invalid + * format. + */ + public static BlockData createBlockData(String inputString) { + String[] parts = inputString.split(":", 2); + try { + int blockId = Integer.parseUnsignedInt(parts[0]); + int blockData = Integer.parseUnsignedInt(parts[1]); + if (blockData >= 16) { + throw new IllegalArgumentException("Invalid block data: " + blockData); + } + return new PokkitBlockData(Block.get(blockId, blockData)); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(Pokkit.NAME + " expects \"blockId:blockData\", got \"" + inputString + "\"."); + } + } + + public static PokkitBlockData toBukkit(cn.nukkit.block.Block block) { + return new PokkitBlockData(block); + } + + public static cn.nukkit.block.Block toNukkit(BlockData blockData) { + return ((PokkitBlockData) blockData).block; + } + + private final cn.nukkit.block.Block block; + + protected PokkitBlockData(Block block) { + this.block = Objects.requireNonNull(block); + } + + @Override + public BlockData clone() { + return new PokkitBlockData(block.clone()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PokkitBlockData other = (PokkitBlockData) obj; + if (!block.equals(other.block)) { + return false; + } + return true; + } + + @Override + public String getAsString() { + return block.getId() + ":" + block.getDamage(); + } + + @Override + public Material getMaterial() { + return BlockMap.getMaterial(block.getId()); + } + + public byte getNukkitData() { + return (byte) block.getDamage(); + } + + /** + * Gets the block id according to the MCPE system. + * @return The block id. + */ + public int getNukkitId() { + return block.getId(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((block == null) ? 0 : block.hashCode()); + return result; + } + + @Override + public boolean matches(BlockData data) { + return block.getFullId() == ((PokkitBlockData) data).block.getFullId(); + } + + @Override + public BlockData merge(BlockData data) { + // Merging not supported + return data.clone(); + } + + /** + * Bridge to old API. + * + * @return Equivalent object in the old API. + */ + @Deprecated + public org.bukkit.material.MaterialData toMaterialData() { + Material material = BlockMap.getMaterial(block.getId()); + return material.getNewData((byte) block.getDamage()); + } +} diff --git a/src/main/java/nl/rutgerkok/pokkit/blockstate/PlainBlockState.java b/src/main/java/nl/rutgerkok/pokkit/blockstate/PlainBlockState.java index d26251c..0bb2c37 100644 --- a/src/main/java/nl/rutgerkok/pokkit/blockstate/PlainBlockState.java +++ b/src/main/java/nl/rutgerkok/pokkit/blockstate/PlainBlockState.java @@ -1,13 +1,14 @@ package nl.rutgerkok.pokkit.blockstate; import org.bukkit.Location; -import org.bukkit.material.MaterialData; + +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; import cn.nukkit.nbt.tag.CompoundTag; final class PlainBlockState extends PokkitBlockState { - PlainBlockState(Location locationOrNull, MaterialData materialData) { + PlainBlockState(Location locationOrNull, PokkitBlockData materialData) { super(locationOrNull, materialData); } diff --git a/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java b/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java index ef06644..9ff6598 100644 --- a/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java +++ b/src/main/java/nl/rutgerkok/pokkit/blockstate/PokkitBlockState.java @@ -3,18 +3,19 @@ import java.util.List; import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.world.PokkitBlock; -import nl.rutgerkok.pokkit.world.PokkitWorld; - import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockState; -import org.bukkit.material.MaterialData; +import org.bukkit.block.data.BlockData; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.world.PokkitBlock; +import nl.rutgerkok.pokkit.world.PokkitWorld; + import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.blockentity.BlockEntitySign; import cn.nukkit.blockentity.BlockEntitySpawnable; @@ -37,16 +38,16 @@ public static PokkitBlockState getBlockState(PokkitBlock block) { BlockEntity blockEntityOrNull = nukkitBlock.getLevel().getBlockEntity(nukkitBlock); - MaterialData materialData = block.getTypeData(); + PokkitBlockData blockData = (PokkitBlockData) block.getBlockData(); Location location = block.getLocation(); if (blockEntityOrNull instanceof BlockEntitySign) { String hiddenData = blockEntityOrNull.namedTag.getString(Pokkit.NAME); - return new SignBlockState(location, materialData, ((BlockEntitySign) blockEntityOrNull).getText(), + return new SignBlockState(location, blockData, ((BlockEntitySign) blockEntityOrNull).getText(), hiddenData); } - return new PlainBlockState(location, materialData); + return new PlainBlockState(location, blockData); } /** @@ -59,8 +60,7 @@ public static PokkitBlockState getBlockState(PokkitBlock block) { * @return The vitual block state. */ public static PokkitBlockState getVirtual(Material material, CompoundTag tag) { - @SuppressWarnings("deprecation") - MaterialData materialData = material.getNewData((byte) 0); + PokkitBlockData materialData = PokkitBlockData.createBlockData(material, 0); if (material == Material.SIGN) { String[] lines = new String[] { tag.getString("Text1"), tag.getString("Text2"), tag.getString("Text3"), @@ -74,9 +74,9 @@ public static PokkitBlockState getVirtual(Material material, CompoundTag tag) { private PokkitWorld worldOrNull; private final int x, y, z; - private MaterialData materialData; + private PokkitBlockData blockData; - protected PokkitBlockState(Location locationOrNull, MaterialData materialData) { + protected PokkitBlockState(Location locationOrNull, PokkitBlockData blockData) { if (locationOrNull == null) { this.worldOrNull = null; this.x = 0; @@ -89,7 +89,7 @@ protected PokkitBlockState(Location locationOrNull, MaterialData materialData) { this.z = locationOrNull.getBlockZ(); } - this.materialData = Objects.requireNonNull(materialData); + this.blockData = Objects.requireNonNull(blockData); } @Override @@ -97,6 +97,11 @@ public PokkitBlock getBlock() { return getWorld().getBlockAt(x, y, z); } + @Override + public BlockData getBlockData() { + return blockData; + } + /** * Gets the Nukkit block entity. * @@ -111,9 +116,10 @@ public Chunk getChunk() { return getWorld().getChunkAt(getLocation()); } + @Deprecated @Override - public MaterialData getData() { - return materialData.clone(); + public org.bukkit.material.MaterialData getData() { + return blockData.toMaterialData(); } @Override @@ -143,21 +149,15 @@ public List getMetadata(String metadataKey) { } @Override - @Deprecated public byte getRawData() { - return materialData.getData(); + return this.blockData.getNukkitData(); } @Override public Material getType() { - return materialData.getItemType(); + return blockData.getMaterial(); } - @Override - @Deprecated - public int getTypeId() { - return getType().getId(); - } @Override public PokkitWorld getWorld() { @@ -207,8 +207,14 @@ public void removeMetadata(String metadataKey, Plugin owningPlugin) { public abstract void saveToTag(CompoundTag tag); @Override - public void setData(MaterialData data) { - this.materialData = Objects.requireNonNull(data, "data"); + public void setBlockData(BlockData data) { + this.blockData = (PokkitBlockData) Objects.requireNonNull(data, "data"); + } + + @Override + @Deprecated + public void setData(org.bukkit.material.MaterialData data) { + this.blockData = PokkitBlockData.createBlockData(data.getItemType(), data.getData()); } @Override @@ -219,25 +225,12 @@ public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { @Override @Deprecated public void setRawData(byte data) { - this.materialData.setData(data); + this.blockData = PokkitBlockData.createBlockData(getType(), data); } @Override public void setType(Material type) { - @SuppressWarnings("deprecation") - MaterialData withNewType = type.getNewData(getRawData()); - this.materialData = withNewType; - } - - @Override - @Deprecated - public boolean setTypeId(int typeId) { - Material material = Material.getMaterial(typeId); - if (material == null) { - return false; - } - setType(material); - return true; + this.blockData = PokkitBlockData.createBlockData(type, 0); } @Override @@ -253,12 +246,12 @@ public final boolean update(boolean force) { @Override public final boolean update(boolean force, boolean applyPhysics) { PokkitBlock block = getBlock(); - if (!block.getTypeData().equals(materialData)) { + if (!block.getBlockData().equals(this.blockData)) { // Block type has changed if (!force) { return false; } - block.setTypeAndData(materialData, applyPhysics); + block.setBlockData(blockData, applyPhysics); } // Update NBT data diff --git a/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java b/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java index 3342b03..de33532 100644 --- a/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java +++ b/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java @@ -2,13 +2,13 @@ import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.block.Sign; -import org.bukkit.material.MaterialData; -import com.google.common.base.Preconditions; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; import cn.nukkit.nbt.tag.CompoundTag; @@ -17,7 +17,7 @@ public final class SignBlockState extends PokkitBlockState implements Sign { private final String[] lines; private String hiddenData; - protected SignBlockState(Location locationOrNull, MaterialData materialData, String[] lines, String hiddenData) { + protected SignBlockState(Location locationOrNull, PokkitBlockData materialData, String[] lines, String hiddenData) { super(locationOrNull, materialData); this.lines = Objects.requireNonNull(lines, "lines"); this.hiddenData = Objects.requireNonNull(hiddenData, "hiddenData"); diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java index 326ab5f..f4c5e86 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java @@ -1,11 +1,15 @@ package nl.rutgerkok.pokkit.enchantment; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; public class PokkitEnchantment { private static Enchantment[] nukkitToBukkit = new Enchantment[25]; - private static byte[] bukkitToNukkit = new byte[100]; + private static Map bukkitToNukkit = new HashMap<>(); static { twoWay(cn.nukkit.item.enchantment.Enchantment.ID_PROTECTION_ALL, Enchantment.PROTECTION_ENVIRONMENTAL); @@ -45,8 +49,7 @@ public static void registerNukkitEnchantmentsInBukkit() { } for (cn.nukkit.item.enchantment.Enchantment nukkitEnchantment : cn.nukkit.item.enchantment.Enchantment.getEnchantments()) { Enchantment bukkitWrapper = PokkitEnchantment.toBukkit(nukkitEnchantment.getId()); - @SuppressWarnings("deprecation") - Enchantment bukkitImpl = new PokkitEnchantmentImpl(nukkitEnchantment, bukkitWrapper.getId()); + Enchantment bukkitImpl = new PokkitEnchantmentImpl(nukkitEnchantment, bukkitWrapper.getKey()); Enchantment.registerEnchantment(bukkitImpl); } @@ -82,20 +85,15 @@ public static Enchantment toBukkit(int nukkit) { * disabled. */ public static int toNukkit(Enchantment enchantment) { - @SuppressWarnings("deprecation") - int bukkitId = enchantment.getId(); - if (bukkitId < 0 || bukkitId > bukkitToNukkit.length) { - return -1; - } - return bukkitToNukkit[bukkitId] & 0xff; + NamespacedKey bukkitId = enchantment.getKey(); + return bukkitToNukkit.getOrDefault(bukkitId, -1).intValue(); } private static void twoWay(int nukkit, Enchantment bukkit) { - @SuppressWarnings("deprecation") - int bukkitId = bukkit.getId(); + NamespacedKey bukkitId = bukkit.getKey(); nukkitToBukkit[nukkit] = bukkit; - bukkitToNukkit[bukkitId] = (byte) nukkit; + bukkitToNukkit.put(bukkitId, nukkit); } } diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentImpl.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentImpl.java index e05e740..2cd617a 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentImpl.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentImpl.java @@ -2,18 +2,19 @@ import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.item.PokkitItemStack; - +import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.ItemStack; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.item.PokkitItemStack; + final class PokkitEnchantmentImpl extends Enchantment { private final cn.nukkit.item.enchantment.Enchantment nukkit; - public PokkitEnchantmentImpl(cn.nukkit.item.enchantment.Enchantment nukkit, int bukkitId) { + public PokkitEnchantmentImpl(cn.nukkit.item.enchantment.Enchantment nukkit, NamespacedKey bukkitId) { super(bukkitId); this.nukkit = Objects.requireNonNull(nukkit, "nukkit"); } diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java index 72d96c5..e1b25ef 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java @@ -26,8 +26,9 @@ public class PokkitEnchantmentTarget { twoWay(EnchantmentType.FISHING_ROD, EnchantmentTarget.FISHING_ROD); twoWay(EnchantmentType.SWORD, EnchantmentTarget.WEAPON); - // For WEARABLE, no suitable Nukkit target exists yet + // For WEARABLE and TRIDENT, no suitable Nukkit target exists yet bukkitToNukkit.put(EnchantmentTarget.WEARABLE, EnchantmentType.BREAKABLE); + bukkitToNukkit.put(EnchantmentTarget.TRIDENT, EnchantmentType.BREAKABLE); } /** diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java index 326abb6..1b47b92 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java @@ -7,12 +7,7 @@ import java.util.Set; import java.util.UUID; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitLocation; -import nl.rutgerkok.pokkit.metadata.PokkitMetadataValue; -import nl.rutgerkok.pokkit.player.PokkitPlayer; -import nl.rutgerkok.pokkit.player.PokkitTeleportCause; -import nl.rutgerkok.pokkit.world.PokkitWorld; +import com.google.common.base.Strings; import org.bukkit.Bukkit; import org.bukkit.EntityEffect; @@ -32,7 +27,12 @@ import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; -import com.google.common.base.Strings; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitLocation; +import nl.rutgerkok.pokkit.metadata.PokkitMetadataValue; +import nl.rutgerkok.pokkit.player.PokkitPlayer; +import nl.rutgerkok.pokkit.player.PokkitTeleportCause; +import nl.rutgerkok.pokkit.world.PokkitWorld; import cn.nukkit.math.Vector3; import cn.nukkit.network.protocol.RemoveEntityPacket; @@ -131,7 +131,6 @@ public double getHeight() { @Override public EntityDamageEvent getLastDamageCause() { cn.nukkit.event.entity.EntityDamageEvent nukkitEvent = nukkit.getLastDamageCause(); - @SuppressWarnings("deprecation") EntityDamageEvent bukkitEvent = new EntityDamageEvent(PokkitEntity.toBukkit(nukkitEvent.getEntity()), PokkitDamageCause.toBukkit(nukkitEvent.getCause()), nukkitEvent.getDamage()); return bukkitEvent; @@ -376,6 +375,11 @@ public boolean isPermissionSet(String name) { return false; // Permissions cannot be set for entities in Nukkit } + @Override + public boolean isPersistent() { + return false; + } + @Override public boolean isSilent() { return false; // No silence support yet @@ -504,18 +508,23 @@ public boolean setPassenger(Entity passenger) { throw Pokkit.unsupported(); } + @Override + public void setPersistent(boolean persistent) { + throw Pokkit.unsupported(); + } + @Override public void setPortalCooldown(int cooldown) { return; // When portals are properly implemented in Nukkit, change this to use Nukkit's API! } - @Override + @Override public void setSilent(boolean flag) { throw Pokkit.unsupported(); } - @Override + @Override public void setTicksLived(int value) { nukkit.ticksLived = value; } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java index d37dfbd..c58085d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitFakeEntity.java @@ -1,12 +1,17 @@ package nl.rutgerkok.pokkit.entity; -import cn.nukkit.math.SimpleAxisAlignedBB; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitLocation; -import nl.rutgerkok.pokkit.world.PokkitWorld; -import org.bukkit.*; + +import org.bukkit.Bukkit; +import org.bukkit.EntityEffect; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.Entity; import org.bukkit.event.entity.EntityDamageEvent; @@ -18,6 +23,12 @@ import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitLocation; +import nl.rutgerkok.pokkit.world.PokkitWorld; + +import cn.nukkit.math.SimpleAxisAlignedBB; + abstract class PokkitFakeEntity implements Entity { @Override @@ -275,6 +286,11 @@ public boolean isPermissionSet(String name) { return false; } + @Override + public boolean isPersistent() { + return false; + } + @Override public boolean isSilent() { return false; @@ -411,6 +427,11 @@ public boolean setPassenger(Entity passenger) { } + @Override + public void setPersistent(boolean persistent) { + throw Pokkit.unsupported(); + } + @Override public void setPortalCooldown(int cooldown) { throw Pokkit.unsupported(); diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java index b0c69c6..8495982 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java @@ -2,13 +2,13 @@ import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.item.PokkitItemStack; - import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.item.PokkitItemStack; + import cn.nukkit.level.Location; /** diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java index b7730dd..a9ba75a 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitLivingEntity.java @@ -5,13 +5,6 @@ import java.util.List; import java.util.Set; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; -import nl.rutgerkok.pokkit.player.PokkitPlayer; -import nl.rutgerkok.pokkit.potion.PokkitPotionEffect; -import nl.rutgerkok.pokkit.potion.PokkitPotionEffectType; -import nl.rutgerkok.pokkit.world.PokkitBlock; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.attribute.Attribute; @@ -26,6 +19,13 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.player.PokkitPlayer; +import nl.rutgerkok.pokkit.potion.PokkitPotionEffect; +import nl.rutgerkok.pokkit.potion.PokkitPotionEffectType; +import nl.rutgerkok.pokkit.world.PokkitBlock; + import cn.nukkit.potion.Effect; public class PokkitLivingEntity extends PokkitEntity implements LivingEntity { @@ -237,6 +237,16 @@ public boolean isLeashed() { throw Pokkit.unsupported(); } + @Override + public boolean isRiptiding() { + return false; + } + + @Override + public boolean isSwimming() { + return nukkit.isSwimming(); + } + @Override public T launchProjectile(Class projectile) { throw Pokkit.unsupported(); @@ -330,12 +340,17 @@ public void setRemoveWhenFarAway(boolean remove) { throw Pokkit.unsupported(); } + @Override + public void setSwimming(boolean swimming) { + nukkit.setSwimming(swimming); + } + private Integer[] toNukkitBlockIds(Set bukkitMaterials) { if (bukkitMaterials == null) { return new Integer[cn.nukkit.block.Block.AIR]; } return bukkitMaterials.stream() - .map(material -> Integer.valueOf(PokkitMaterialData.fromBukkit(material, 0).getNukkitId())) + .map(material -> PokkitBlockData.createBlockData(material, 0).getNukkitId()) .toArray(Integer[]::new); } diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitAbstractInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitAbstractInventory.java index e72b945..00a6764 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitAbstractInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitAbstractInventory.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.ListIterator; +import com.google.common.base.Preconditions; + import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -14,8 +16,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import com.google.common.base.Preconditions; - /** * Abstract class for inventories, implements all methods that can be * implemented on top of others without noticeable permformance loss. (I mean, @@ -63,51 +63,11 @@ public final HashMap addItem(ItemStack... items) throws Ille */ protected abstract int addSingleStack(ItemStack item); - @Override - @Deprecated - public HashMap all(int materialId) { - Material material = Material.getMaterial(materialId); - if (material == null) { - return new HashMap<>(); - } - return all(material); - } - - @Override - @Deprecated - public boolean contains(int materialId) { - Material material = Material.getMaterial(materialId); - if (material == null) { - return false; - } - return contains(material); - } - - @Override - @Deprecated - public boolean contains(int materialId, int amount) { - Material material = Material.getMaterial(materialId); - if (material == null) { - return false; - } - return contains(material, amount); - } - @Override public boolean contains(Material material) throws IllegalArgumentException { return first(material) != -1; } - @Override - @Deprecated - public int first(int materialId) { - Material material = Material.getMaterial(materialId); - if (material == null) { - return -1; - } - return first(material); - } - @Override public Location getLocation() { InventoryHolder holder = getHolder(); @@ -139,15 +99,6 @@ public ListIterator iterator(int index) { return Arrays.asList(getContents()).listIterator(index); } - @Override - public void remove(int materialId) { - @SuppressWarnings("deprecation") - Material material = Material.getMaterial(materialId); - if (material != null) { - remove(material); - } - } - @Override public void setContents(ItemStack[] items) throws IllegalArgumentException { Preconditions.checkArgument(items.length <= getSize()); diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitLiveInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitLiveInventory.java index 1e8fa4a..77acdcd 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitLiveInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitLiveInventory.java @@ -5,11 +5,6 @@ import java.util.Objects; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.item.PokkitItemStack; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; -import nl.rutgerkok.pokkit.player.PokkitPlayer; - import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -17,6 +12,11 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.item.PokkitItemStack; +import nl.rutgerkok.pokkit.player.PokkitPlayer; + import cn.nukkit.item.Item; /** @@ -152,7 +152,7 @@ public boolean contains(ItemStack item, int amount) { @Override public boolean contains(Material material, int amount) throws IllegalArgumentException { Validate.notNull(material, "material"); - int nukkitTypeId = PokkitMaterialData.fromBukkit(material, 0).getNukkitId(); + int nukkitTypeId = PokkitBlockData.createBlockData(material, 0).getNukkitId(); int remaining = amount; @@ -195,7 +195,7 @@ public int first(ItemStack item) { @Override public int first(Material material) throws IllegalArgumentException { Validate.notNull(material, "material"); - int nukkitTypeId = PokkitMaterialData.fromBukkit(material, 0).getNukkitId(); + int nukkitTypeId = PokkitBlockData.createBlockData(material, 0).getNukkitId(); int size = getSize(); for (int i = 0; i < size; i++) { @@ -265,15 +265,15 @@ public void remove(ItemStack item) { if (item == null) { return; } - + ItemStack[] contents = getContents(); - + for (int i = 0; i < contents.length; i++) { if (contents[i] != null && contents[i].equals(item)) { contents[i] = null; } } - + setContents(contents); } @@ -282,15 +282,15 @@ public void remove(Material material) throws IllegalArgumentException { if (material == null) { return; } - + ItemStack[] contents = getContents(); - + for (int i = 0; i < contents.length; i++) { if (contents[i] != null && contents[i].getType().equals(material)) { contents[i] = null; } } - + setContents(contents); } diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java index 503c5a1..33fc32c 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitPlayerInventory.java @@ -7,24 +7,18 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import cn.nukkit.item.Item; - import nl.rutgerkok.pokkit.Pokkit; import nl.rutgerkok.pokkit.entity.PokkitHumanEntity; import nl.rutgerkok.pokkit.item.PokkitItemStack; +import cn.nukkit.item.Item; + public final class PokkitPlayerInventory extends PokkitLiveInventory implements PlayerInventory { public PokkitPlayerInventory(cn.nukkit.inventory.PlayerInventory inventory) { super(inventory); } - @Override - public int clear(int id, int data) { - throw Pokkit.unsupported(); - - } - @Override public ItemStack[] getArmorContents() { Item[] nukkitArmor = nukkit().getArmorContents(); diff --git a/src/main/java/nl/rutgerkok/pokkit/item/ItemMap.java b/src/main/java/nl/rutgerkok/pokkit/item/ItemMap.java new file mode 100644 index 0000000..4498854 --- /dev/null +++ b/src/main/java/nl/rutgerkok/pokkit/item/ItemMap.java @@ -0,0 +1,453 @@ +package nl.rutgerkok.pokkit.item; + +import org.bukkit.Material; + +import cn.nukkit.item.Item; +import cn.nukkit.item.ItemID; + +@SuppressWarnings("deprecation") +public class ItemMap { + + private static Material[] nukkitToBukkit = new Material[700]; + private static char[] bukkitToNukkit = new char[Material.values().length]; + + static { + registerTwoWay(ItemID.IRON_SHOVEL, Material.IRON_SHOVEL); + registerTwoWay(ItemID.IRON_PICKAXE, Material.IRON_PICKAXE); + registerTwoWay(ItemID.IRON_AXE, Material.IRON_AXE); + registerTwoWay(ItemID.FLINT_AND_STEEL, Material.FLINT_AND_STEEL); + registerTwoWay(ItemID.APPLE, Material.APPLE); + registerTwoWay(ItemID.BOW, Material.BOW); + registerTwoWay(ItemID.ARROW, Material.ARROW); + registerTwoWay(ItemID.COAL, Material.COAL); + registerTwoWay(ItemID.DIAMOND, Material.DIAMOND); + registerTwoWay(ItemID.IRON_INGOT, Material.IRON_INGOT); + registerTwoWay(ItemID.GOLD_INGOT, Material.GOLD_INGOT); + registerTwoWay(ItemID.IRON_SWORD, Material.IRON_SWORD); + registerTwoWay(ItemID.WOODEN_SWORD, Material.WOODEN_SWORD); + registerTwoWay(ItemID.WOODEN_SHOVEL, Material.WOODEN_SHOVEL); + registerTwoWay(ItemID.WOODEN_PICKAXE, Material.WOODEN_PICKAXE); + registerTwoWay(ItemID.WOODEN_AXE, Material.WOODEN_AXE); + registerTwoWay(ItemID.STONE_SWORD, Material.STONE_SWORD); + registerTwoWay(ItemID.STONE_SHOVEL, Material.STONE_SHOVEL); + registerTwoWay(ItemID.STONE_PICKAXE, Material.STONE_PICKAXE); + registerTwoWay(ItemID.STONE_AXE, Material.STONE_AXE); + registerTwoWay(ItemID.DIAMOND_SWORD, Material.DIAMOND_SWORD); + registerTwoWay(ItemID.DIAMOND_SHOVEL, Material.DIAMOND_SHOVEL); + registerTwoWay(ItemID.DIAMOND_PICKAXE, Material.DIAMOND_PICKAXE); + registerTwoWay(ItemID.DIAMOND_AXE, Material.DIAMOND_AXE); + registerTwoWay(ItemID.STICK, Material.STICK); + registerTwoWay(ItemID.BOWL, Material.BOWL); + registerTwoWay(ItemID.MUSHROOM_STEW, Material.MUSHROOM_STEW); + registerTwoWay(ItemID.GOLDEN_SWORD, Material.GOLDEN_SWORD); + registerTwoWay(ItemID.GOLDEN_SHOVEL, Material.GOLDEN_SHOVEL); + registerTwoWay(ItemID.GOLDEN_PICKAXE, Material.GOLDEN_PICKAXE); + registerTwoWay(ItemID.GOLDEN_AXE, Material.GOLDEN_AXE); + registerTwoWay(ItemID.STRING, Material.STRING); + registerTwoWay(ItemID.FEATHER, Material.FEATHER); + registerTwoWay(ItemID.GUNPOWDER, Material.GUNPOWDER); + registerTwoWay(ItemID.WOODEN_HOE, Material.WOODEN_HOE); + registerTwoWay(ItemID.STONE_HOE, Material.STONE_HOE); + registerTwoWay(ItemID.IRON_HOE, Material.IRON_HOE); + registerTwoWay(ItemID.DIAMOND_HOE, Material.DIAMOND_HOE); + registerTwoWay(ItemID.GOLDEN_HOE, Material.GOLDEN_HOE); + registerTwoWay(ItemID.WHEAT_SEEDS, Material.WHEAT_SEEDS); + registerTwoWay(ItemID.WHEAT, Material.WHEAT); + registerTwoWay(ItemID.BREAD, Material.BREAD); + registerTwoWay(ItemID.LEATHER_CAP, Material.LEATHER_HELMET); + registerTwoWay(ItemID.LEATHER_TUNIC, Material.LEATHER_CHESTPLATE); + registerTwoWay(ItemID.LEATHER_PANTS, Material.LEATHER_LEGGINGS); + registerTwoWay(ItemID.LEATHER_BOOTS, Material.LEATHER_BOOTS); + registerTwoWay(ItemID.CHAIN_HELMET, Material.CHAINMAIL_HELMET); + registerTwoWay(ItemID.CHAIN_CHESTPLATE, Material.CHAINMAIL_CHESTPLATE); + registerTwoWay(ItemID.CHAIN_LEGGINGS, Material.CHAINMAIL_LEGGINGS); + registerTwoWay(ItemID.CHAIN_BOOTS, Material.CHAINMAIL_BOOTS); + registerTwoWay(ItemID.IRON_HELMET, Material.IRON_HELMET); + registerTwoWay(ItemID.IRON_CHESTPLATE, Material.IRON_CHESTPLATE); + registerTwoWay(ItemID.IRON_LEGGINGS, Material.IRON_LEGGINGS); + registerTwoWay(ItemID.IRON_BOOTS, Material.IRON_BOOTS); + registerTwoWay(ItemID.DIAMOND_HELMET, Material.DIAMOND_HELMET); + registerTwoWay(ItemID.DIAMOND_CHESTPLATE, Material.DIAMOND_CHESTPLATE); + registerTwoWay(ItemID.DIAMOND_LEGGINGS, Material.DIAMOND_LEGGINGS); + registerTwoWay(ItemID.DIAMOND_BOOTS, Material.DIAMOND_BOOTS); + registerTwoWay(ItemID.GOLD_HELMET, Material.GOLDEN_HELMET); + registerTwoWay(ItemID.GOLD_CHESTPLATE, Material.GOLDEN_CHESTPLATE); + registerTwoWay(ItemID.GOLD_LEGGINGS, Material.GOLDEN_LEGGINGS); + registerTwoWay(ItemID.GOLD_BOOTS, Material.GOLDEN_BOOTS); + registerTwoWay(ItemID.RAW_PORKCHOP, Material.PORKCHOP); + registerTwoWay(ItemID.COOKED_PORKCHOP, Material.COOKED_PORKCHOP); + registerTwoWay(ItemID.PAINTING, Material.PAINTING); + registerTwoWay(ItemID.GOLDEN_APPLE, Material.GOLDEN_APPLE); + registerTwoWay(ItemID.SIGN, Material.SIGN); + registerTwoWay(ItemID.WOODEN_DOOR, Material.OAK_DOOR); + registerTwoWay(ItemID.BUCKET, Material.BUCKET); + registerTwoWay(ItemID.MINECART, Material.MINECART); + registerTwoWay(ItemID.SADDLE, Material.SADDLE); + registerTwoWay(ItemID.IRON_DOOR, Material.IRON_DOOR); + registerTwoWay(ItemID.REDSTONE, Material.REDSTONE); + registerTwoWay(ItemID.SNOWBALL, Material.SNOWBALL); + registerTwoWay(ItemID.BOAT, Material.OAK_BOAT); + registerTwoWay(ItemID.LEATHER, Material.LEATHER); + registerTwoWay(ItemID.BRICK, Material.BRICK); + registerTwoWay(ItemID.CLAY, Material.CLAY); + registerTwoWay(ItemID.SUGAR_CANE, Material.SUGAR_CANE); + registerTwoWay(ItemID.PAPER, Material.PAPER); + registerTwoWay(ItemID.BOOK, Material.BOOK); + registerTwoWay(ItemID.SLIMEBALL, Material.SLIME_BALL); + registerTwoWay(ItemID.MINECART_WITH_CHEST, Material.CHEST_MINECART); + registerTwoWay(ItemID.EGG, Material.EGG); + registerTwoWay(ItemID.COMPASS, Material.COMPASS); + registerTwoWay(ItemID.FISHING_ROD, Material.FISHING_ROD); + registerTwoWay(ItemID.CLOCK, Material.CLOCK); + registerTwoWay(ItemID.GLOWSTONE_DUST, Material.GLOWSTONE_DUST); + registerTwoWay(ItemID.RAW_FISH, Material.COD); + registerTwoWay(ItemID.COOKED_FISH, Material.COOKED_COD); + registerTwoWay(ItemID.DYE, Material.ORANGE_DYE); + registerTwoWay(ItemID.BONE, Material.BONE); + registerTwoWay(ItemID.SUGAR, Material.SUGAR); + registerTwoWay(ItemID.CAKE, Material.CAKE); + registerTwoWay(ItemID.BED, Material.RED_BED); + registerTwoWay(ItemID.REPEATER, Material.REPEATER); + registerTwoWay(ItemID.COOKIE, Material.COOKIE); + registerTwoWay(ItemID.MAP, Material.MAP); + registerTwoWay(ItemID.SHEARS, Material.SHEARS); + registerTwoWay(ItemID.MELON, Material.MELON); + registerTwoWay(ItemID.MELON_SLICE, Material.MELON_SLICE); + registerTwoWay(ItemID.PUMPKIN_SEEDS, Material.PUMPKIN_SEEDS); + registerTwoWay(ItemID.MELON_SEEDS, Material.MELON_SEEDS); + registerTwoWay(ItemID.RAW_BEEF, Material.BEEF); + registerTwoWay(ItemID.COOKED_BEEF, Material.COOKED_BEEF); + registerTwoWay(ItemID.RAW_CHICKEN, Material.CHICKEN); + registerTwoWay(ItemID.COOKED_CHICKEN, Material.COOKED_CHICKEN); + registerTwoWay(ItemID.ROTTEN_FLESH, Material.ROTTEN_FLESH); + registerTwoWay(ItemID.ENDER_PEARL, Material.ENDER_PEARL); + registerTwoWay(ItemID.BLAZE_ROD, Material.BLAZE_ROD); + registerTwoWay(ItemID.GHAST_TEAR, Material.GHAST_TEAR); + registerTwoWay(ItemID.GOLD_NUGGET, Material.GOLD_NUGGET); + registerTwoWay(ItemID.NETHER_WART, Material.NETHER_WART); + registerTwoWay(ItemID.POTION, Material.POTION); + registerTwoWay(ItemID.GLASS_BOTTLE, Material.GLASS_BOTTLE); + registerTwoWay(ItemID.SPIDER_EYE, Material.SPIDER_EYE); + registerTwoWay(ItemID.FERMENTED_SPIDER_EYE, Material.FERMENTED_SPIDER_EYE); + registerTwoWay(ItemID.BLAZE_POWDER, Material.BLAZE_POWDER); + registerTwoWay(ItemID.MAGMA_CREAM, Material.MAGMA_CREAM); + registerTwoWay(ItemID.BREWING_STAND, Material.BREWING_STAND); + registerTwoWay(ItemID.CAULDRON, Material.CAULDRON); + registerTwoWay(ItemID.ENDER_EYE, Material.ENDER_EYE); + registerTwoWay(ItemID.GLISTERING_MELON, Material.GLISTERING_MELON_SLICE); + registerTwoWay(ItemID.SPAWN_EGG, Material.PIG_SPAWN_EGG); + registerTwoWay(ItemID.EXPERIENCE_BOTTLE, Material.EXPERIENCE_BOTTLE); + registerTwoWay(ItemID.FIRE_CHARGE, Material.FIRE_CHARGE); + registerTwoWay(ItemID.BOOK_AND_QUILL, Material.WRITABLE_BOOK); + registerTwoWay(ItemID.WRITTEN_BOOK, Material.WRITTEN_BOOK); + registerTwoWay(ItemID.EMERALD, Material.EMERALD); + registerTwoWay(ItemID.ITEM_FRAME, Material.ITEM_FRAME); + registerTwoWay(ItemID.FLOWER_POT, Material.FLOWER_POT); + registerTwoWay(ItemID.CARROT, Material.CARROT); + registerTwoWay(ItemID.CARROTS, Material.CARROTS); + registerTwoWay(ItemID.POTATO, Material.POTATO); + registerTwoWay(ItemID.POTATOES, Material.POTATOES); + registerTwoWay(ItemID.BAKED_POTATO, Material.BAKED_POTATO); + registerTwoWay(ItemID.POISONOUS_POTATO, Material.POISONOUS_POTATO); + registerTwoWay(ItemID.EMPTY_MAP, Material.MAP); + registerTwoWay(ItemID.GOLDEN_CARROT, Material.GOLDEN_CARROT); + registerTwoWay(ItemID.SKULL, Material.SKELETON_SKULL); + registerTwoWay(ItemID.CARROT_ON_A_STICK, Material.CARROT_ON_A_STICK); + registerTwoWay(ItemID.NETHER_STAR, Material.NETHER_STAR); + registerTwoWay(ItemID.PUMPKIN_PIE, Material.PUMPKIN_PIE); + registerTwoWay(ItemID.FIREWORKS, Material.FIREWORK_ROCKET); + + registerTwoWay(ItemID.ENCHANTED_BOOK, Material.ENCHANTED_BOOK); + registerTwoWay(ItemID.COMPARATOR, Material.COMPARATOR); + registerTwoWay(ItemID.NETHER_BRICK, Material.NETHER_BRICK); + registerTwoWay(ItemID.QUARTZ, Material.QUARTZ); + registerTwoWay(ItemID.MINECART_WITH_TNT, Material.TNT_MINECART); + registerTwoWay(ItemID.MINECART_WITH_HOPPER, Material.HOPPER_MINECART); + registerTwoWay(ItemID.PRISMARINE_SHARD, Material.PRISMARINE_SHARD); + registerTwoWay(ItemID.HOPPER, Material.HOPPER); + registerTwoWay(ItemID.RAW_RABBIT, Material.RABBIT); + registerTwoWay(ItemID.COOKED_RABBIT, Material.COOKED_RABBIT); + registerTwoWay(ItemID.RABBIT_STEW, Material.RABBIT_STEW); + registerTwoWay(ItemID.RABBIT_FOOT, Material.RABBIT_FOOT); + registerTwoWay(ItemID.RABBIT_HIDE, Material.RABBIT_HIDE); + registerNukkitToBukkit(ItemID.LEATHER_HORSE_ARMOR, Material.LEATHER); + registerTwoWay(ItemID.IRON_HORSE_ARMOR, Material.IRON_HORSE_ARMOR); + registerTwoWay(ItemID.GOLD_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR); + registerTwoWay(ItemID.DIAMOND_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR); + registerTwoWay(ItemID.LEAD, Material.LEAD); + registerTwoWay(ItemID.NAME_TAG, Material.NAME_TAG); + registerTwoWay(ItemID.PRISMARINE_CRYSTALS, Material.PRISMARINE_CRYSTALS); + registerTwoWay(ItemID.RAW_MUTTON, Material.MUTTON); + registerTwoWay(ItemID.COOKED_MUTTON, Material.COOKED_MUTTON); + registerTwoWay(ItemID.END_CRYSTAL, Material.END_CRYSTAL); + registerTwoWay(ItemID.SPRUCE_DOOR, Material.SPRUCE_DOOR); + registerTwoWay(ItemID.BIRCH_DOOR, Material.BIRCH_DOOR); + registerTwoWay(ItemID.JUNGLE_DOOR, Material.JUNGLE_DOOR); + registerTwoWay(ItemID.ACACIA_DOOR, Material.ACACIA_DOOR); + registerTwoWay(ItemID.DARK_OAK_DOOR, Material.DARK_OAK_DOOR); + registerTwoWay(ItemID.CHORUS_FRUIT, Material.CHORUS_FRUIT); + registerTwoWay(ItemID.POPPED_CHORUS_FRUIT, Material.POPPED_CHORUS_FRUIT); + registerTwoWay(ItemID.DRAGON_BREATH, Material.DRAGON_BREATH); + registerTwoWay(ItemID.SPLASH_POTION, Material.SPLASH_POTION); + registerTwoWay(ItemID.LINGERING_POTION, Material.LINGERING_POTION); + registerTwoWay(ItemID.ELYTRA, Material.ELYTRA); + registerTwoWay(ItemID.SHULKER_SHELL, Material.SHULKER_SHELL); + registerTwoWay(ItemID.BEETROOT, Material.BEETROOT); + registerTwoWay(ItemID.BEETROOT_SEEDS, Material.BEETROOT_SEEDS); + registerTwoWay(ItemID.BEETROOT_SOUP, Material.BEETROOT_SOUP); + registerTwoWay(ItemID.RAW_SALMON, Material.SALMON); + registerTwoWay(ItemID.CLOWNFISH, Material.TROPICAL_FISH); + registerTwoWay(ItemID.PUFFERFISH, Material.PUFFERFISH); + registerTwoWay(ItemID.COOKED_SALMON, Material.COOKED_SALMON); + registerTwoWay(ItemID.GOLDEN_APPLE_ENCHANTED, Material.ENCHANTED_GOLDEN_APPLE); + registerTwoWay(ItemID.RECORD_13, Material.MUSIC_DISC_13); + registerTwoWay(ItemID.RECORD_CAT, Material.MUSIC_DISC_CAT); + registerTwoWay(ItemID.RECORD_BLOCKS, Material.MUSIC_DISC_BLOCKS); + registerTwoWay(ItemID.RECORD_CHIRP, Material.MUSIC_DISC_CHIRP); + registerTwoWay(ItemID.RECORD_FAR, Material.MUSIC_DISC_FAR); + registerTwoWay(ItemID.RECORD_MALL, Material.MUSIC_DISC_MALL); + registerTwoWay(ItemID.RECORD_MELLOHI, Material.MUSIC_DISC_MELLOHI); + registerTwoWay(ItemID.RECORD_STAL, Material.MUSIC_DISC_STAL); + registerTwoWay(ItemID.RECORD_STRAD, Material.MUSIC_DISC_STRAD); + registerTwoWay(ItemID.RECORD_WARD, Material.MUSIC_DISC_WARD); + registerTwoWay(ItemID.RECORD_11, Material.MUSIC_DISC_11); + registerTwoWay(ItemID.RECORD_WAIT, Material.MUSIC_DISC_WAIT); + + // Legacy items + registerBukkitToNukkit(ItemID.IRON_SHOVEL, Material.LEGACY_IRON_SPADE); + registerBukkitToNukkit(ItemID.IRON_PICKAXE, Material.LEGACY_IRON_PICKAXE); + registerBukkitToNukkit(ItemID.IRON_AXE, Material.LEGACY_IRON_AXE); + registerBukkitToNukkit(ItemID.FLINT_AND_STEEL, Material.LEGACY_FLINT_AND_STEEL); + registerBukkitToNukkit(ItemID.APPLE, Material.LEGACY_APPLE); + registerBukkitToNukkit(ItemID.BOW, Material.LEGACY_BOW); + registerBukkitToNukkit(ItemID.ARROW, Material.LEGACY_ARROW); + registerBukkitToNukkit(ItemID.COAL, Material.LEGACY_COAL); + registerBukkitToNukkit(ItemID.DIAMOND, Material.LEGACY_DIAMOND); + registerBukkitToNukkit(ItemID.IRON_INGOT, Material.LEGACY_IRON_INGOT); + registerBukkitToNukkit(ItemID.GOLD_INGOT, Material.LEGACY_GOLD_INGOT); + registerBukkitToNukkit(ItemID.IRON_SWORD, Material.LEGACY_IRON_SWORD); + registerBukkitToNukkit(ItemID.WOODEN_SWORD, Material.LEGACY_WOOD_SWORD); + registerBukkitToNukkit(ItemID.WOODEN_SHOVEL, Material.LEGACY_WOOD_SPADE); + registerBukkitToNukkit(ItemID.WOODEN_PICKAXE, Material.LEGACY_WOOD_PICKAXE); + registerBukkitToNukkit(ItemID.WOODEN_AXE, Material.LEGACY_WOOD_AXE); + registerBukkitToNukkit(ItemID.STONE_SWORD, Material.LEGACY_STONE_SWORD); + registerBukkitToNukkit(ItemID.STONE_SHOVEL, Material.LEGACY_STONE_SPADE); + registerBukkitToNukkit(ItemID.STONE_PICKAXE, Material.LEGACY_STONE_PICKAXE); + registerBukkitToNukkit(ItemID.STONE_AXE, Material.LEGACY_STONE_AXE); + registerBukkitToNukkit(ItemID.DIAMOND_SWORD, Material.LEGACY_DIAMOND_SWORD); + registerBukkitToNukkit(ItemID.DIAMOND_SHOVEL, Material.LEGACY_DIAMOND_SPADE); + registerBukkitToNukkit(ItemID.DIAMOND_PICKAXE, Material.LEGACY_DIAMOND_PICKAXE); + registerBukkitToNukkit(ItemID.DIAMOND_AXE, Material.LEGACY_DIAMOND_AXE); + registerBukkitToNukkit(ItemID.STICK, Material.LEGACY_STICK); + registerBukkitToNukkit(ItemID.BOWL, Material.LEGACY_BOWL); + registerBukkitToNukkit(ItemID.MUSHROOM_STEW, Material.LEGACY_MUSHROOM_SOUP); + registerBukkitToNukkit(ItemID.GOLD_SWORD, Material.LEGACY_GOLD_SWORD); + registerBukkitToNukkit(ItemID.GOLD_SHOVEL, Material.LEGACY_GOLD_SPADE); + registerBukkitToNukkit(ItemID.GOLD_PICKAXE, Material.LEGACY_GOLD_PICKAXE); + registerBukkitToNukkit(ItemID.GOLD_AXE, Material.LEGACY_GOLD_AXE); + registerBukkitToNukkit(ItemID.STRING, Material.LEGACY_STRING); + registerBukkitToNukkit(ItemID.FEATHER, Material.LEGACY_FEATHER); + registerBukkitToNukkit(ItemID.GUNPOWDER, Material.LEGACY_SULPHUR); + registerBukkitToNukkit(ItemID.WOODEN_HOE, Material.LEGACY_WOOD_HOE); + registerBukkitToNukkit(ItemID.STONE_HOE, Material.LEGACY_STONE_HOE); + registerBukkitToNukkit(ItemID.IRON_HOE, Material.LEGACY_IRON_HOE); + registerBukkitToNukkit(ItemID.DIAMOND_HOE, Material.LEGACY_DIAMOND_HOE); + registerBukkitToNukkit(ItemID.GOLD_HOE, Material.LEGACY_GOLD_HOE); + registerBukkitToNukkit(ItemID.SEEDS, Material.LEGACY_SEEDS); + registerBukkitToNukkit(ItemID.WHEAT, Material.LEGACY_WHEAT); + registerBukkitToNukkit(ItemID.BREAD, Material.LEGACY_BREAD); + registerBukkitToNukkit(ItemID.LEATHER_CAP, Material.LEGACY_LEATHER_HELMET); + registerBukkitToNukkit(ItemID.LEATHER_TUNIC, Material.LEGACY_LEATHER_CHESTPLATE); + registerBukkitToNukkit(ItemID.LEATHER_PANTS, Material.LEGACY_LEATHER_LEGGINGS); + registerBukkitToNukkit(ItemID.LEATHER_BOOTS, Material.LEGACY_LEATHER_BOOTS); + registerBukkitToNukkit(ItemID.CHAIN_HELMET, Material.LEGACY_CHAINMAIL_HELMET); + registerBukkitToNukkit(ItemID.CHAIN_CHESTPLATE, Material.LEGACY_CHAINMAIL_CHESTPLATE); + registerBukkitToNukkit(ItemID.CHAIN_LEGGINGS, Material.LEGACY_CHAINMAIL_LEGGINGS); + registerBukkitToNukkit(ItemID.CHAIN_BOOTS, Material.LEGACY_CHAINMAIL_BOOTS); + registerBukkitToNukkit(ItemID.IRON_HELMET, Material.LEGACY_IRON_HELMET); + registerBukkitToNukkit(ItemID.IRON_CHESTPLATE, Material.LEGACY_IRON_CHESTPLATE); + registerBukkitToNukkit(ItemID.IRON_LEGGINGS, Material.LEGACY_IRON_LEGGINGS); + registerBukkitToNukkit(ItemID.IRON_BOOTS, Material.LEGACY_IRON_BOOTS); + registerBukkitToNukkit(ItemID.DIAMOND_HELMET, Material.LEGACY_DIAMOND_HELMET); + registerBukkitToNukkit(ItemID.DIAMOND_CHESTPLATE, Material.LEGACY_DIAMOND_CHESTPLATE); + registerBukkitToNukkit(ItemID.DIAMOND_LEGGINGS, Material.LEGACY_DIAMOND_LEGGINGS); + registerBukkitToNukkit(ItemID.DIAMOND_BOOTS, Material.LEGACY_DIAMOND_BOOTS); + registerBukkitToNukkit(ItemID.GOLD_HELMET, Material.LEGACY_GOLD_HELMET); + registerBukkitToNukkit(ItemID.GOLD_CHESTPLATE, Material.LEGACY_GOLD_CHESTPLATE); + registerBukkitToNukkit(ItemID.GOLD_LEGGINGS, Material.LEGACY_GOLD_LEGGINGS); + registerBukkitToNukkit(ItemID.GOLD_BOOTS, Material.LEGACY_GOLD_BOOTS); + registerBukkitToNukkit(ItemID.FLINT, Material.LEGACY_FLINT); + registerBukkitToNukkit(ItemID.RAW_PORKCHOP, Material.LEGACY_PORK); + registerBukkitToNukkit(ItemID.COOKED_PORKCHOP, Material.LEGACY_GRILLED_PORK); + registerBukkitToNukkit(ItemID.PAINTING, Material.LEGACY_PAINTING); + registerBukkitToNukkit(ItemID.GOLDEN_APPLE, Material.LEGACY_GOLDEN_APPLE); + registerBukkitToNukkit(ItemID.SIGN, Material.LEGACY_SIGN); + registerBukkitToNukkit(ItemID.WOODEN_DOOR, Material.LEGACY_WOOD_DOOR); + registerBukkitToNukkit(ItemID.BUCKET, Material.LEGACY_BUCKET); + registerBukkitToNukkit(ItemID.MINECART, Material.LEGACY_MINECART); + registerBukkitToNukkit(ItemID.SADDLE, Material.LEGACY_SADDLE); + registerBukkitToNukkit(ItemID.IRON_DOOR, Material.LEGACY_IRON_DOOR); + registerBukkitToNukkit(ItemID.REDSTONE, Material.LEGACY_REDSTONE); + registerBukkitToNukkit(ItemID.SNOWBALL, Material.LEGACY_SNOW_BALL); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT); + registerBukkitToNukkit(ItemID.LEATHER, Material.LEGACY_LEATHER); + registerBukkitToNukkit(ItemID.BRICK, Material.LEGACY_CLAY_BRICK); + registerBukkitToNukkit(ItemID.CLAY, Material.LEGACY_CLAY_BALL); + registerBukkitToNukkit(ItemID.SUGAR_CANE, Material.LEGACY_SUGAR_CANE); + registerBukkitToNukkit(ItemID.PAPER, Material.LEGACY_PAPER); + registerBukkitToNukkit(ItemID.BOOK, Material.LEGACY_BOOK); + registerBukkitToNukkit(ItemID.SLIMEBALL, Material.LEGACY_SLIME_BALL); + registerBukkitToNukkit(ItemID.MINECART_WITH_CHEST, Material.LEGACY_STORAGE_MINECART); + registerBukkitToNukkit(ItemID.EGG, Material.LEGACY_EGG); + registerBukkitToNukkit(ItemID.COMPASS, Material.LEGACY_COMPASS); + registerBukkitToNukkit(ItemID.FISHING_ROD, Material.LEGACY_FISHING_ROD); + registerBukkitToNukkit(ItemID.CLOCK, Material.LEGACY_WATCH); + registerBukkitToNukkit(ItemID.GLOWSTONE_DUST, Material.LEGACY_GLOWSTONE_DUST); + registerBukkitToNukkit(ItemID.RAW_FISH, Material.LEGACY_RAW_FISH); + registerBukkitToNukkit(ItemID.COOKED_FISH, Material.LEGACY_COOKED_FISH); + registerBukkitToNukkit(ItemID.BONE, Material.LEGACY_BONE); + registerBukkitToNukkit(ItemID.SUGAR, Material.LEGACY_SUGAR); + registerBukkitToNukkit(ItemID.CAKE, Material.LEGACY_CAKE); + registerBukkitToNukkit(ItemID.BED, Material.LEGACY_BED); + registerBukkitToNukkit(ItemID.REPEATER, Material.LEGACY_DIODE); + registerBukkitToNukkit(ItemID.COOKIE, Material.LEGACY_COOKIE); + registerBukkitToNukkit(ItemID.MAP, Material.LEGACY_MAP); + registerBukkitToNukkit(ItemID.SHEARS, Material.LEGACY_SHEARS); + registerBukkitToNukkit(ItemID.MELON, Material.LEGACY_MELON); + registerBukkitToNukkit(ItemID.PUMPKIN_SEEDS, Material.LEGACY_PUMPKIN_SEEDS); + registerBukkitToNukkit(ItemID.MELON_SEEDS, Material.LEGACY_MELON_SEEDS); + registerBukkitToNukkit(ItemID.RAW_BEEF, Material.LEGACY_RAW_BEEF); + registerBukkitToNukkit(ItemID.COOKED_BEEF, Material.LEGACY_COOKED_BEEF); + registerBukkitToNukkit(ItemID.RAW_CHICKEN, Material.LEGACY_RAW_CHICKEN); + registerBukkitToNukkit(ItemID.COOKED_CHICKEN, Material.LEGACY_COOKED_CHICKEN); + registerBukkitToNukkit(ItemID.ROTTEN_FLESH, Material.LEGACY_ROTTEN_FLESH); + registerBukkitToNukkit(ItemID.ENDER_PEARL, Material.LEGACY_ENDER_PEARL); + registerBukkitToNukkit(ItemID.BLAZE_ROD, Material.LEGACY_BLAZE_ROD); + registerBukkitToNukkit(ItemID.GHAST_TEAR, Material.LEGACY_GHAST_TEAR); + registerBukkitToNukkit(ItemID.GOLD_NUGGET, Material.LEGACY_GOLD_NUGGET); + registerBukkitToNukkit(ItemID.NETHER_WART, Material.LEGACY_NETHER_STALK); + registerBukkitToNukkit(ItemID.POTION, Material.LEGACY_POTION); + registerBukkitToNukkit(ItemID.GLASS_BOTTLE, Material.LEGACY_GLASS_BOTTLE); + registerBukkitToNukkit(ItemID.SPIDER_EYE, Material.LEGACY_SPIDER_EYE); + registerBukkitToNukkit(ItemID.FERMENTED_SPIDER_EYE, Material.LEGACY_FERMENTED_SPIDER_EYE); + registerBukkitToNukkit(ItemID.BLAZE_POWDER, Material.LEGACY_BLAZE_POWDER); + registerBukkitToNukkit(ItemID.MAGMA_CREAM, Material.LEGACY_MAGMA_CREAM); + registerBukkitToNukkit(ItemID.BREWING_STAND, Material.LEGACY_BREWING_STAND_ITEM); + registerBukkitToNukkit(ItemID.CAULDRON, Material.LEGACY_CAULDRON_ITEM); + registerBukkitToNukkit(ItemID.ENDER_EYE, Material.LEGACY_EYE_OF_ENDER); + registerBukkitToNukkit(ItemID.GLISTERING_MELON, Material.LEGACY_SPECKLED_MELON); + registerBukkitToNukkit(ItemID.SPAWN_EGG, Material.LEGACY_MONSTER_EGG); + registerBukkitToNukkit(ItemID.EXPERIENCE_BOTTLE, Material.LEGACY_EXP_BOTTLE); + registerBukkitToNukkit(ItemID.FIRE_CHARGE, Material.LEGACY_FIREBALL); + registerBukkitToNukkit(ItemID.BOOK_AND_QUILL, Material.LEGACY_BOOK_AND_QUILL); + registerBukkitToNukkit(ItemID.WRITTEN_BOOK, Material.LEGACY_WRITTEN_BOOK); + registerBukkitToNukkit(ItemID.EMERALD, Material.LEGACY_EMERALD); + registerBukkitToNukkit(ItemID.ITEM_FRAME, Material.LEGACY_ITEM_FRAME); + registerBukkitToNukkit(ItemID.FLOWER_POT, Material.LEGACY_FLOWER_POT_ITEM); + registerBukkitToNukkit(ItemID.CARROT, Material.LEGACY_CARROT_ITEM); + registerBukkitToNukkit(ItemID.POTATO, Material.LEGACY_POTATO_ITEM); + registerBukkitToNukkit(ItemID.BAKED_POTATO, Material.LEGACY_BAKED_POTATO); + registerBukkitToNukkit(ItemID.POISONOUS_POTATO, Material.LEGACY_POISONOUS_POTATO); + registerBukkitToNukkit(ItemID.EMPTY_MAP, Material.LEGACY_EMPTY_MAP); + registerBukkitToNukkit(ItemID.GOLDEN_CARROT, Material.LEGACY_GOLDEN_CARROT); + registerBukkitToNukkit(ItemID.SKULL, Material.LEGACY_SKULL_ITEM); + registerBukkitToNukkit(ItemID.CARROT_ON_A_STICK, Material.LEGACY_CARROT_STICK); + registerBukkitToNukkit(ItemID.NETHER_STAR, Material.LEGACY_NETHER_STAR); + registerBukkitToNukkit(ItemID.PUMPKIN_PIE, Material.LEGACY_PUMPKIN_PIE); + registerBukkitToNukkit(ItemID.FIREWORKS, Material.LEGACY_FIREWORK); + registerBukkitToNukkit(ItemID.ENCHANTED_BOOK, Material.LEGACY_ENCHANTED_BOOK); + registerBukkitToNukkit(ItemID.COMPARATOR, Material.LEGACY_REDSTONE_COMPARATOR); + registerBukkitToNukkit(ItemID.NETHER_BRICK, Material.LEGACY_NETHER_BRICK_ITEM); + registerBukkitToNukkit(ItemID.QUARTZ, Material.LEGACY_QUARTZ); + registerBukkitToNukkit(ItemID.MINECART_WITH_TNT, Material.LEGACY_EXPLOSIVE_MINECART); + registerBukkitToNukkit(ItemID.MINECART_WITH_HOPPER, Material.LEGACY_HOPPER_MINECART); + registerBukkitToNukkit(ItemID.PRISMARINE_SHARD, Material.LEGACY_PRISMARINE_SHARD); + registerBukkitToNukkit(ItemID.PRISMARINE_CRYSTALS, Material.LEGACY_PRISMARINE_CRYSTALS); + registerBukkitToNukkit(ItemID.RAW_RABBIT, Material.LEGACY_RABBIT); + registerBukkitToNukkit(ItemID.COOKED_RABBIT, Material.LEGACY_COOKED_RABBIT); + registerBukkitToNukkit(ItemID.RABBIT_STEW, Material.LEGACY_RABBIT_STEW); + registerBukkitToNukkit(ItemID.RABBIT_FOOT, Material.LEGACY_RABBIT_FOOT); + registerBukkitToNukkit(ItemID.RABBIT_HIDE, Material.LEGACY_RABBIT_HIDE); + registerBukkitToNukkit(ItemID.IRON_HORSE_ARMOR, Material.LEGACY_IRON_BARDING); + registerBukkitToNukkit(ItemID.GOLD_HORSE_ARMOR, Material.LEGACY_GOLD_BARDING); + registerBukkitToNukkit(ItemID.DIAMOND_HORSE_ARMOR, Material.LEGACY_DIAMOND_BARDING); + registerBukkitToNukkit(ItemID.LEAD, Material.LEGACY_LEASH); + registerBukkitToNukkit(ItemID.NAME_TAG, Material.LEGACY_NAME_TAG); + registerBukkitToNukkit(ItemID.RAW_MUTTON, Material.LEGACY_MUTTON); + registerBukkitToNukkit(ItemID.COOKED_MUTTON, Material.LEGACY_COOKED_MUTTON); + registerBukkitToNukkit(ItemID.END_CRYSTAL, Material.LEGACY_END_CRYSTAL); + registerBukkitToNukkit(ItemID.SPRUCE_DOOR, Material.LEGACY_SPRUCE_DOOR_ITEM); + registerBukkitToNukkit(ItemID.BIRCH_DOOR, Material.LEGACY_BIRCH_DOOR_ITEM); + registerBukkitToNukkit(ItemID.JUNGLE_DOOR, Material.LEGACY_JUNGLE_DOOR_ITEM); + registerBukkitToNukkit(ItemID.ACACIA_DOOR, Material.LEGACY_ACACIA_DOOR_ITEM); + registerBukkitToNukkit(ItemID.DARK_OAK_DOOR, Material.LEGACY_DARK_OAK_DOOR_ITEM); + registerBukkitToNukkit(ItemID.CHORUS_FRUIT, Material.LEGACY_CHORUS_FRUIT); + registerBukkitToNukkit(ItemID.POPPED_CHORUS_FRUIT, Material.LEGACY_CHORUS_FRUIT_POPPED); + registerBukkitToNukkit(ItemID.BEETROOT, Material.LEGACY_BEETROOT); + registerBukkitToNukkit(ItemID.BEETROOT_SEEDS, Material.LEGACY_BEETROOT_SEEDS); + registerBukkitToNukkit(ItemID.BEETROOT_SOUP, Material.LEGACY_BEETROOT_SOUP); + registerBukkitToNukkit(ItemID.DRAGON_BREATH, Material.LEGACY_DRAGONS_BREATH); + registerBukkitToNukkit(ItemID.SPLASH_POTION, Material.LEGACY_SPLASH_POTION); + registerBukkitToNukkit(ItemID.ARROW, Material.LEGACY_SPECTRAL_ARROW); + registerBukkitToNukkit(ItemID.ARROW, Material.LEGACY_TIPPED_ARROW); + registerBukkitToNukkit(ItemID.LINGERING_POTION, Material.LEGACY_LINGERING_POTION); + registerBukkitToNukkit(ItemID.ELYTRA, Material.LEGACY_ELYTRA); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT_SPRUCE); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT_BIRCH); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT_JUNGLE); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT_ACACIA); + registerBukkitToNukkit(ItemID.BOAT, Material.LEGACY_BOAT_DARK_OAK); + registerBukkitToNukkit(ItemID.SHULKER_SHELL, Material.LEGACY_SHULKER_SHELL); + registerBukkitToNukkit(ItemID.WRITTEN_BOOK, Material.LEGACY_KNOWLEDGE_BOOK); + registerBukkitToNukkit(ItemID.RECORD_13, Material.LEGACY_GOLD_RECORD); + registerBukkitToNukkit(ItemID.RECORD_CAT, Material.LEGACY_GREEN_RECORD); + registerBukkitToNukkit(ItemID.RECORD_BLOCKS, Material.LEGACY_RECORD_3); + registerBukkitToNukkit(ItemID.RECORD_CHIRP, Material.LEGACY_RECORD_4); + registerBukkitToNukkit(ItemID.RECORD_FAR, Material.LEGACY_RECORD_5); + registerBukkitToNukkit(ItemID.RECORD_MALL, Material.LEGACY_RECORD_6); + registerBukkitToNukkit(ItemID.RECORD_MELLOHI, Material.LEGACY_RECORD_7); + registerBukkitToNukkit(ItemID.RECORD_STAL, Material.LEGACY_RECORD_8); + registerBukkitToNukkit(ItemID.RECORD_STRAD, Material.LEGACY_RECORD_9); + registerBukkitToNukkit(ItemID.RECORD_WARD, Material.LEGACY_RECORD_10); + registerBukkitToNukkit(ItemID.RECORD_11, Material.LEGACY_RECORD_11); + registerBukkitToNukkit(ItemID.RECORD_WAIT, Material.LEGACY_RECORD_12); + } + + /** + * Gets the Nukkit item. + * @param type The Bukkit material. + * @return The Nukkit item. + */ + public static Item fromBukkit(Material type) { + return Item.get(bukkitToNukkit[type.ordinal()]); + } + + /** + * Gets the material from the Nukkit item, or null if not found. + * @param nukkit The Nukkit item, may be null. + * @return The material, or null if not found. + */ + public static Material fromNukkitOrNull(Item nukkit) { + if (nukkit == null) { + return null; + } + int nukkitId = nukkit.getId(); + if (nukkitId < 0 || nukkitId >= nukkitToBukkit.length) { + return null; + } + return nukkitToBukkit[nukkitId]; + } + + private static void registerBukkitToNukkit(int nukkitId, Material bukkit) { + bukkitToNukkit[bukkit.ordinal()] = (char) nukkitId; + } + + private static void registerNukkitToBukkit(int nukkitId, Material bukkit) { + nukkitToBukkit[nukkitId] = bukkit; + } + + private static void registerTwoWay(int nukkitId, Material bukkit) { + registerBukkitToNukkit(nukkitId, bukkit); + registerNukkitToBukkit(nukkitId, bukkit); + } +} diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitBlockStateMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitBlockStateMeta.java index e65ce7f..739e153 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitBlockStateMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitBlockStateMeta.java @@ -2,20 +2,20 @@ import java.util.Objects; -import nl.rutgerkok.pokkit.blockstate.PokkitBlockState; - import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.inventory.meta.BlockStateMeta; +import nl.rutgerkok.pokkit.blockstate.PokkitBlockState; + import cn.nukkit.nbt.tag.CompoundTag; final class PokkitBlockStateMeta extends PokkitItemMeta implements BlockStateMeta { private final Material material; - PokkitBlockStateMeta(CompoundTag tag, Material material) { - super(tag); + PokkitBlockStateMeta(CompoundTag tag, Material material, int damage) { + super(tag, damage); this.material = Objects.requireNonNull(material, "material"); } diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemFactory.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemFactory.java index b9c7629..3b049f7 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemFactory.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemFactory.java @@ -2,14 +2,14 @@ import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; - import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import nl.rutgerkok.pokkit.Pokkit; + import cn.nukkit.nbt.tag.CompoundTag; public final class PokkitItemFactory implements ItemFactory { @@ -21,7 +21,7 @@ public ItemMeta asMetaFor(ItemMeta meta, ItemStack stack) throws IllegalArgument @Override public ItemMeta asMetaFor(ItemMeta meta, Material material) throws IllegalArgumentException { - return getItemMeta(material, ((PokkitItemMeta) meta).getTag()); + return getItemMeta(material, ((PokkitItemMeta) meta).getTag(), 0); } /** @@ -53,46 +53,96 @@ public Color getDefaultLeatherColor() { @Override public ItemMeta getItemMeta(Material material) { - return getItemMeta(material, new CompoundTag()); + return getItemMeta(material, new CompoundTag(), 0); } - public ItemMeta getItemMeta(Material material, CompoundTag tag) { + @SuppressWarnings("deprecation") + public ItemMeta getItemMeta(Material material, CompoundTag tag, int damage) { switch (material) { case POTION: + case LEGACY_POTION: case SPLASH_POTION: + case LEGACY_SPLASH_POTION: case LINGERING_POTION: + case LEGACY_LINGERING_POTION: case TIPPED_ARROW: - return new PokkitPotionMeta(tag); + case LEGACY_TIPPED_ARROW: + return new PokkitPotionMeta(tag, damage); case SIGN: - case BANNER: + case LEGACY_SIGN: + case BLACK_BANNER: + case BLUE_BANNER: + case BROWN_BANNER: + case CYAN_BANNER: + case GRAY_BANNER: + case GREEN_BANNER: + case LIGHT_BLUE_BANNER: + case LIGHT_GRAY_BANNER: + case LIME_BANNER: + case MAGENTA_BANNER: + case ORANGE_BANNER: + case PINK_BANNER: + case PURPLE_BANNER: + case RED_BANNER: + case WHITE_BANNER: + case YELLOW_BANNER: + case LEGACY_BANNER: case CHEST: + case LEGACY_CHEST: case TRAPPED_CHEST: + case LEGACY_TRAPPED_CHEST: case DISPENSER: + case LEGACY_DISPENSER: case FURNACE: + case LEGACY_FURNACE: case BREWING_STAND: + case LEGACY_BREWING_STAND: case HOPPER: + case LEGACY_HOPPER: case DROPPER: + case LEGACY_DROPPER: case BEACON: - case MOB_SPAWNER: + case LEGACY_BEACON: + case SPAWNER: + case LEGACY_MOB_SPAWNER: case NOTE_BLOCK: + case LEGACY_NOTE_BLOCK: case JUKEBOX: - case ENCHANTMENT_TABLE: - case SKULL_ITEM: - case COMMAND: - case COMMAND_REPEATING: - case COMMAND_CHAIN: + case LEGACY_JUKEBOX: + case ENCHANTING_TABLE: + case LEGACY_ENCHANTMENT_TABLE: + case SKELETON_SKULL: + case WITHER_SKELETON_SKULL: + case ZOMBIE_HEAD: + case CREEPER_HEAD: + case PLAYER_HEAD: + case LEGACY_SKULL_ITEM: + case COMMAND_BLOCK: + case LEGACY_COMMAND: + case REPEATING_COMMAND_BLOCK: + case LEGACY_COMMAND_REPEATING: + case CHAIN_COMMAND_BLOCK: + case LEGACY_COMMAND_CHAIN: case END_GATEWAY: + case LEGACY_END_GATEWAY: case STRUCTURE_BLOCK: + case LEGACY_STRUCTURE_BLOCK: case FLOWER_POT: - case REDSTONE_COMPARATOR: - return new PokkitBlockStateMeta(tag, material); + case LEGACY_FLOWER_POT: + case COMPARATOR: + case LEGACY_REDSTONE_COMPARATOR: + return new PokkitBlockStateMeta(tag, material, damage); case LEATHER_BOOTS: + case LEGACY_LEATHER_BOOTS: case LEATHER_CHESTPLATE: + case LEGACY_LEATHER_CHESTPLATE: case LEATHER_HELMET: + case LEGACY_LEATHER_HELMET: case LEATHER_LEGGINGS: - return new PokkitLeatherArmorMeta(tag); + case LEGACY_LEATHER_LEGGINGS: + return new PokkitLeatherArmorMeta(tag, damage); default: - return new PokkitItemMeta(tag); + return new PokkitItemMeta(tag, damage); } } @@ -110,4 +160,11 @@ private boolean isEqualToNull(ItemMeta meta) { return ((PokkitItemMeta) meta).getTag().isEmpty(); } + @Override + public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException { + // Normally used to change the material, for example when the spawned + // type of a spawn egg has changed + return material; + } + } diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java index 34c4c9b..7250da8 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java @@ -8,28 +8,31 @@ import java.util.Objects; import java.util.Set; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.enchantment.PokkitEnchantment; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.enchantment.PokkitEnchantment; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.nbt.tag.ListTag; import cn.nukkit.nbt.tag.StringTag; import cn.nukkit.nbt.tag.Tag; -public class PokkitItemMeta extends ItemMeta.Spigot implements ItemMeta { +public class PokkitItemMeta extends ItemMeta.Spigot implements ItemMeta, Damageable { protected CompoundTag tag; + private int damage; - PokkitItemMeta(CompoundTag tag) { + PokkitItemMeta(CompoundTag tag, int damage) { this.tag = Objects.requireNonNull(tag, "tag"); + this.damage = damage; } @Override @@ -78,9 +81,10 @@ public void addItemFlags(ItemFlag... itemFlags) { } @Override - public ItemMeta clone() { + public PokkitItemMeta clone() { try { PokkitItemMeta meta = (PokkitItemMeta) super.clone(); + meta.damage = this.damage; meta.tag = this.tag.copy(); return meta; } catch (CloneNotSupportedException e) { @@ -99,9 +103,17 @@ public boolean equals(Object obj) { PokkitItemMeta other = (PokkitItemMeta) obj; if (!tag.equals(other.tag)) return false; + if (damage != other.damage) { + return false; + } return true; } + @Override + public int getDamage() { + return damage; + } + @Override public String getDisplayName() { if (!tag.contains("display")) { @@ -197,6 +209,11 @@ public boolean hasConflictingEnchant(Enchantment ench) { return false; } + @Override + public boolean hasDamage() { + return this.damage != 0; + } + @Override public boolean hasDisplayName() { if (!tag.contains("display")) { @@ -318,6 +335,11 @@ public Map serialize() { throw Pokkit.unsupported(); } + @Override + public void setDamage(int damage) { + this.damage = damage; + } + @Override public void setDisplayName(String name) { if (Strings.isNullOrEmpty(name)) { diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java index a021499..3a0df92 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemStack.java @@ -1,10 +1,9 @@ package nl.rutgerkok.pokkit.item; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; - import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import cn.nukkit.item.Item; import cn.nukkit.nbt.tag.CompoundTag; @@ -33,19 +32,21 @@ private static final PokkitItemFactory getItemFactory() { * The Nukkit item. */ public static void overwriteNukkit(ItemStack bukkit, cn.nukkit.item.Item nukkit) { - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(bukkit.getType(), bukkit.getDurability()); + cn.nukkit.item.Item nukkitType = ItemMap.fromBukkit(bukkit.getType()); - if (materialData.getNukkitId() != nukkit.getId()) { + if (nukkitType.getId() != nukkit.getId()) { Bukkit.getLogger().info("Cannot change item material from " + bukkit.getType() + " to " - + cn.nukkit.item.Item.get(nukkit.getId())); + + nukkit); return; } - nukkit.setDamage(materialData.getNukkitDamage()); nukkit.setCount(bukkit.getAmount()); if (bukkit.hasItemMeta()) { PokkitItemMeta meta = (PokkitItemMeta) bukkit.getItemMeta(); + if (meta instanceof Damageable) { + nukkit.setDamage(((Damageable) meta).getDamage()); + } nukkit.setNamedTag(meta.getTag()); } else { nukkit.clearNamedTag(); @@ -60,21 +61,16 @@ public static void overwriteNukkit(ItemStack bukkit, cn.nukkit.item.Item nukkit) * @return A {@link ItemStack}, or null if Nukkit has an air or null stack. */ public static ItemStack toBukkitCopy(cn.nukkit.item.Item nukkit) { - if (nukkit == null) { - return null; - } - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit); - Material material = materialData.getBukkitMaterial(); + Material material = ItemMap.fromNukkitOrNull(nukkit); if (material == null) { return null; } - ItemStack bukkit = new ItemStack(material, nukkit.getCount(), - materialData.getBukkitDamage()); + ItemStack bukkit = new ItemStack(material, nukkit.getCount()); // Convert item meta CompoundTag extra = nukkit.getNamedTag(); if (extra != null) { - bukkit.setItemMeta(getItemFactory().getItemMeta(material, extra)); + bukkit.setItemMeta(getItemFactory().getItemMeta(material, extra, nukkit.getDamage())); } return bukkit; @@ -84,13 +80,16 @@ public static final cn.nukkit.item.Item toNukkitCopy(ItemStack bukkit) { if (bukkit == null) { return Item.get(Item.AIR); } - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(bukkit.getType(), bukkit.getDurability()); - cn.nukkit.item.Item nukkit = Item.get(materialData.getNukkitId(), materialData.getNukkitDamage(), - bukkit.getAmount()); + + cn.nukkit.item.Item nukkit = ItemMap.fromBukkit(bukkit.getType()); + nukkit.setCount(bukkit.getAmount()); // Convert item meta if (bukkit.hasItemMeta()) { PokkitItemMeta meta = (PokkitItemMeta) bukkit.getItemMeta(); + if (meta instanceof Damageable) { + nukkit.setDamage(((Damageable) meta).getDamage()); + } nukkit.setNamedTag(meta.getTag()); } diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitLeatherArmorMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitLeatherArmorMeta.java index cd3145c..5b7252a 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitLeatherArmorMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitLeatherArmorMeta.java @@ -7,11 +7,17 @@ public class PokkitLeatherArmorMeta extends PokkitItemMeta implements LeatherArmorMeta { - PokkitLeatherArmorMeta(CompoundTag tag) { - super(tag); + PokkitLeatherArmorMeta(CompoundTag tag, int damage) { + super(tag, damage); } - + + @Override + public PokkitLeatherArmorMeta clone() { + return (PokkitLeatherArmorMeta) super.clone(); + } + + //If you find a better way to do this, PLEASE tell me. @Override public Color getColor() { @@ -23,8 +29,8 @@ public Color getColor() { int b = tag.getInt("blue"); return Color.fromRGB(r, g, b); } - - + + @Override public void setColor(Color color) { int rgb = color.getRed() << 16 | color.getGreen() << 8 | color.getBlue(); @@ -33,13 +39,7 @@ public void setColor(Color color) { this.getTag().putInt("green", color.getGreen());//If you find a better way to do this, PLEASE tell me. this.getTag().putInt("blue", color.getBlue());//If you find a better way to do this, PLEASE tell me. } - - - @Override - public LeatherArmorMeta clone() { - return (LeatherArmorMeta) super.clone(); - } - + } diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitPotionMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitPotionMeta.java index 4d490f8..cee1288 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitPotionMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitPotionMeta.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import nl.rutgerkok.pokkit.Pokkit; - import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.inventory.meta.PotionMeta; @@ -13,12 +11,14 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; +import nl.rutgerkok.pokkit.Pokkit; + import cn.nukkit.nbt.tag.CompoundTag; final class PokkitPotionMeta extends PokkitItemMeta implements PotionMeta { - PokkitPotionMeta(CompoundTag tag) { - super(tag); + PokkitPotionMeta(CompoundTag tag, int damage) { + super(tag, damage); } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java b/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java deleted file mode 100644 index a8cb177..0000000 --- a/src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java +++ /dev/null @@ -1,119 +0,0 @@ -package nl.rutgerkok.pokkit.material; - -import org.bukkit.Material; -import org.bukkit.material.MaterialData; - -/** - * Class for converting material data between Nukkit and Bukkit. Lots of raw ids - * here, so lots of {@code @SuppressWarnings("deprecation")}. - * - *

- * Currently, no conversion happens at all between Bukkit and Nukkit ids (it is - * assumed that they are equal). However, the design of the API permits to add - * conversion in the future. - */ -public final class PokkitMaterialData { - - /** - * Creates a universal material object from a Bukkit material. - * - * @param material - * The Bukkit material. - * @param bukkitDamage - * The Bukkit damage/block data. - * @return The universal material object. - */ - public static PokkitMaterialData fromBukkit(Material material, int bukkitDamage) { - @SuppressWarnings("deprecation") - int bukkitId = material.getId(); - return new PokkitMaterialData(bukkitId, bukkitDamage); - } - - /** - * Creates a universal material object from a Bukkit material. - * - * @param materialData - * The Bukkit material and data. - * @return The universal material object. - */ - @SuppressWarnings("deprecation") - public static PokkitMaterialData fromBukkit(MaterialData materialData) { - return fromBukkit(materialData.getItemType(), materialData.getData()); - } - - /** - * Creates a universal material object from a Nukkit item. - * - * @param item - * The Nukkit item. - * @return The universal material object. - */ - public static PokkitMaterialData fromNukkit(cn.nukkit.item.Item item) { - return new PokkitMaterialData(item.getId(), item.getDamage()); - } - - /** - * Creates a universal material object from a Nukkit material. - * - * @param nukkitId - * The Nukkit material. - * @param nukkitDamage - * The Nukkit damage/block data. - * @return The universal material object. - */ - @Deprecated - public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) { - return new PokkitMaterialData(nukkitId, nukkitDamage); - } - - private final int id; - private final int data; - - private PokkitMaterialData(int id, int data) { - this.id = id; - this.data = data; - } - - /** - * Gets the damage value (block data) for use in Bukkit. - * @return The Bukkit damage value. - */ - public short getBukkitDamage() { - return (short) data; - } - - /** - * Gets the material for use in Bukkit. - * @return The material. - */ - @SuppressWarnings("deprecation") - public Material getBukkitMaterial() { - return Material.getMaterial(id); - } - - /** - * Gets the damage value (block data) for use in Nukkit. - * @return The Nukkit damage value. - */ - public int getNukkitDamage() { - return data; - } - - /** - * Gets the material id for use in Nukkit. - * @return The material id. - */ - public int getNukkitId() { - return id; - } - - /** - * Converts this instance to a Bukkit {@link MaterialData} instance. - * @return The Bukkit {@link MaterialData} instance. - */ - @SuppressWarnings("deprecation") - public MaterialData toBukkit() { - return getBukkitMaterial().getNewData((byte) getBukkitDamage()); - } - -} diff --git a/src/main/java/nl/rutgerkok/pokkit/particle/PokkitParticle.java b/src/main/java/nl/rutgerkok/pokkit/particle/PokkitParticle.java index 4c96528..cbc82b6 100644 --- a/src/main/java/nl/rutgerkok/pokkit/particle/PokkitParticle.java +++ b/src/main/java/nl/rutgerkok/pokkit/particle/PokkitParticle.java @@ -4,7 +4,6 @@ public class PokkitParticle { public static int toNukkit(Particle particle) { - int id = 0; switch(particle) { case BARRIER: @@ -14,11 +13,9 @@ public static int toNukkit(Particle particle) { case BLOCK_DUST: break; case CLOUD: - id = cn.nukkit.level.particle.Particle.TYPE_SMOKE; - break; + return cn.nukkit.level.particle.Particle.TYPE_SMOKE; case CRIT: - id = cn.nukkit.level.particle.Particle.TYPE_CRITICAL; - break; + return cn.nukkit.level.particle.Particle.TYPE_CRITICAL; case CRIT_MAGIC: break; case DAMAGE_INDICATOR: @@ -26,82 +23,57 @@ public static int toNukkit(Particle particle) { case DRAGON_BREATH: break; case DRIP_LAVA: - id = cn.nukkit.level.particle.Particle.TYPE_DRIP_LAVA; - break; + return cn.nukkit.level.particle.Particle.TYPE_DRIP_LAVA; case DRIP_WATER: - id = cn.nukkit.level.particle.Particle.TYPE_DRIP_WATER; - break; + return cn.nukkit.level.particle.Particle.TYPE_DRIP_WATER; case ENCHANTMENT_TABLE: - id = cn.nukkit.level.particle.Particle.TYPE_ENCHANTMENT_TABLE; - break; + return cn.nukkit.level.particle.Particle.TYPE_ENCHANTMENT_TABLE; case END_ROD: break; case EXPLOSION_HUGE: - id = cn.nukkit.level.particle.Particle.TYPE_HUGE_EXPLODE; - break; + return cn.nukkit.level.particle.Particle.TYPE_HUGE_EXPLODE; case EXPLOSION_LARGE: - id = cn.nukkit.level.particle.Particle.TYPE_HUGE_EXPLODE; - break; + return cn.nukkit.level.particle.Particle.TYPE_HUGE_EXPLODE; case EXPLOSION_NORMAL: - id = cn.nukkit.level.particle.Particle.TYPE_EXPLODE; - break; + return cn.nukkit.level.particle.Particle.TYPE_EXPLODE; case FALLING_DUST: - id = cn.nukkit.level.particle.Particle.TYPE_DUST; - break; + return cn.nukkit.level.particle.Particle.TYPE_DUST; case FIREWORKS_SPARK: break; case FLAME: - id = cn.nukkit.level.particle.Particle.TYPE_FLAME; - break; - case FOOTSTEP: - break; + return cn.nukkit.level.particle.Particle.TYPE_FLAME; case HEART: - id = cn.nukkit.level.particle.Particle.TYPE_HEART; - break; + return cn.nukkit.level.particle.Particle.TYPE_HEART; case ITEM_CRACK: - id = cn.nukkit.level.particle.Particle.TYPE_ITEM_BREAK; - break; - case ITEM_TAKE: - break; + return cn.nukkit.level.particle.Particle.TYPE_ITEM_BREAK; case LAVA: - id = cn.nukkit.level.particle.Particle.TYPE_LAVA; - break; + return cn.nukkit.level.particle.Particle.TYPE_LAVA; case MOB_APPEARANCE: break; case NOTE: break; case PORTAL: - id = cn.nukkit.level.particle.Particle.TYPE_PORTAL; - break; + return cn.nukkit.level.particle.Particle.TYPE_PORTAL; case REDSTONE: - id = cn.nukkit.level.particle.Particle.TYPE_REDSTONE; - break; + return cn.nukkit.level.particle.Particle.TYPE_REDSTONE; case SLIME: - id = cn.nukkit.level.particle.Particle.TYPE_SLIME; - break; + return cn.nukkit.level.particle.Particle.TYPE_SLIME; case SMOKE_LARGE: - id = cn.nukkit.level.particle.Particle.TYPE_LARGE_SMOKE; - break; + return cn.nukkit.level.particle.Particle.TYPE_LARGE_SMOKE; case SMOKE_NORMAL: - id = cn.nukkit.level.particle.Particle.TYPE_SMOKE; - break; + return cn.nukkit.level.particle.Particle.TYPE_SMOKE; case SNOWBALL: break; case SNOW_SHOVEL: - id = cn.nukkit.level.particle.Particle.TYPE_SNOWBALL_POOF; - break; + return cn.nukkit.level.particle.Particle.TYPE_SNOWBALL_POOF; case SPELL: - id = cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL; - break; + return cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL; case SPELL_INSTANT: - id = cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL_INSTANTANEOUS; - break; + return cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL_INSTANTANEOUS; case SPELL_MOB: - id = cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL; - break; + return cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL; case SPELL_MOB_AMBIENT: - id = cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL_AMBIENT; - break; + return cn.nukkit.level.particle.Particle.TYPE_MOB_SPELL_AMBIENT; case SPELL_WITCH: break; case SUSPENDED: @@ -111,29 +83,45 @@ public static int toNukkit(Particle particle) { case SWEEP_ATTACK: break; case TOWN_AURA: - id = cn.nukkit.level.particle.Particle.TYPE_TOWN_AURA; - break; + return cn.nukkit.level.particle.Particle.TYPE_TOWN_AURA; case VILLAGER_ANGRY: - id = cn.nukkit.level.particle.Particle.TYPE_VILLAGER_ANGRY; - break; + return cn.nukkit.level.particle.Particle.TYPE_VILLAGER_ANGRY; case VILLAGER_HAPPY: - id = cn.nukkit.level.particle.Particle.TYPE_VILLAGER_HAPPY; - break; + return cn.nukkit.level.particle.Particle.TYPE_VILLAGER_HAPPY; case WATER_BUBBLE: break; case WATER_DROP: - id = cn.nukkit.level.particle.Particle.TYPE_RAIN_SPLASH; - break; + return cn.nukkit.level.particle.Particle.TYPE_RAIN_SPLASH; case WATER_SPLASH: - id = cn.nukkit.level.particle.Particle.TYPE_WATER_SPLASH; - break; + return cn.nukkit.level.particle.Particle.TYPE_WATER_SPLASH; case WATER_WAKE: - id = cn.nukkit.level.particle.Particle.TYPE_WATER_WAKE; + return cn.nukkit.level.particle.Particle.TYPE_WATER_WAKE; + case BUBBLE_COLUMN_UP: + break; + case BUBBLE_POP: + break; + case CURRENT_DOWN: + break; + case DOLPHIN: + break; + case LEGACY_BLOCK_CRACK: + break; + case LEGACY_BLOCK_DUST: + break; + case LEGACY_FALLING_DUST: + break; + case NAUTILUS: + break; + case SPIT: + break; + case SQUID_INK: + break; + case TOTEM: break; default: break; } - return id; + return 0; } } diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java index 858ba7d..1b75063 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java @@ -11,24 +11,6 @@ import java.util.UUID; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitGameMode; -import nl.rutgerkok.pokkit.PokkitLocation; -import nl.rutgerkok.pokkit.PokkitSound; -import nl.rutgerkok.pokkit.PokkitVector; -import nl.rutgerkok.pokkit.UniqueIdConversion; -import nl.rutgerkok.pokkit.entity.PokkitHumanEntity; -import nl.rutgerkok.pokkit.inventory.PokkitInventory; -import nl.rutgerkok.pokkit.inventory.PokkitInventoryView; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; -import nl.rutgerkok.pokkit.metadata.PlayerMetadataStore; -import nl.rutgerkok.pokkit.particle.PokkitParticle; -import nl.rutgerkok.pokkit.permission.PokkitPermission; -import nl.rutgerkok.pokkit.permission.PokkitPermissionAttachment; -import nl.rutgerkok.pokkit.permission.PokkitPermissionAttachmentInfo; -import nl.rutgerkok.pokkit.plugin.PokkitPlugin; -import nl.rutgerkok.pokkit.potion.PokkitPotionEffect; - import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Effect; @@ -46,6 +28,7 @@ import org.bukkit.advancement.AdvancementProgress; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; +import org.bukkit.block.data.BlockData; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.conversations.Conversation; import org.bukkit.conversations.ConversationAbandonedEvent; @@ -67,6 +50,27 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.scoreboard.Scoreboard; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; + +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitGameMode; +import nl.rutgerkok.pokkit.PokkitLocation; +import nl.rutgerkok.pokkit.PokkitSound; +import nl.rutgerkok.pokkit.PokkitVector; +import nl.rutgerkok.pokkit.UniqueIdConversion; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.entity.PokkitHumanEntity; +import nl.rutgerkok.pokkit.inventory.PokkitInventory; +import nl.rutgerkok.pokkit.inventory.PokkitInventoryView; +import nl.rutgerkok.pokkit.metadata.PlayerMetadataStore; +import nl.rutgerkok.pokkit.particle.PokkitParticle; +import nl.rutgerkok.pokkit.permission.PokkitPermission; +import nl.rutgerkok.pokkit.permission.PokkitPermissionAttachment; +import nl.rutgerkok.pokkit.permission.PokkitPermissionAttachmentInfo; +import nl.rutgerkok.pokkit.plugin.PokkitPlugin; +import nl.rutgerkok.pokkit.potion.PokkitPotionEffect; + import cn.nukkit.AdventureSettings; import cn.nukkit.block.GlobalBlockPalette; import cn.nukkit.event.player.PlayerChatEvent; @@ -74,8 +78,6 @@ import cn.nukkit.math.Vector3; import cn.nukkit.network.protocol.UpdateBlockPacket; import cn.nukkit.utils.TextFormat; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.BaseComponent; @DelegateDeserialization(PokkitOfflinePlayer.class) public class PokkitPlayer extends PokkitHumanEntity implements Player { @@ -142,12 +144,6 @@ public InetSocketAddress getRawAddress() { return InetSocketAddress.createUnresolved(nukkit.getAddress(), nukkit.getPort()); } - @Override - public void playEffect(Location location, Effect effect, int id, int data, float offsetX, float offsetY, - float offsetZ, float speed, int particleCount, int radius) { - // Silently unsupported! - } - @Override public void respawn() { throw Pokkit.unsupported(); @@ -528,6 +524,18 @@ public Player getPlayer() { return this; } + @Override + public String getPlayerListFooter() { + // Not implemented + return null; + } + + @Override + public String getPlayerListHeader() { + // Not implemented + return null; + } + @Override public String getPlayerListName() { return nukkit.getDisplayName(); // In Nukkit, if you change the player's display name, it also changes in the player list, so... @@ -582,7 +590,7 @@ public Entity getSpectatorTarget() { @Override public int getStatistic(Statistic arg0) throws IllegalArgumentException { switch (arg0) { - case PLAY_ONE_TICK: + case PLAY_ONE_MINUTE: long first = nukkit.getFirstPlayed(); long diff = System.currentTimeMillis() - first; // This is the // difference in @@ -970,23 +978,14 @@ public void saveData() { } @Override - @Deprecated - public void sendBlockChange(Location location, int materialId, byte blockData) { - Material material = Material.getMaterial(materialId); - if (material == null) { - return; - } - sendBlockChange(location, material, blockData); - } + public void sendBlockChange(Location location, BlockData block) { + PokkitBlockData materialData = (PokkitBlockData) block; - @Override - public void sendBlockChange(Location location, Material material, byte blockData) { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(material, blockData); int nukkitBlockId = materialData.getNukkitId(); - int nukkitBlockData = materialData.getNukkitDamage(); + int nukkitBlockData = materialData.getNukkitData(); int flags = UpdateBlockPacket.FLAG_ALL_PRIORITY; UpdateBlockPacket packet = new UpdateBlockPacket(); @@ -998,6 +997,11 @@ public void sendBlockChange(Location location, Material material, byte blockData nukkit.dataPacket(packet, false); } + @Override + public void sendBlockChange(Location location, Material material, byte blockData) { + this.sendBlockChange(location, PokkitBlockData.createBlockData(material, blockData)); + } + @Override public boolean sendChunkChange(Location arg0, int arg1, int arg2, int arg3, byte[] arg4) { throw Pokkit.unsupported(); @@ -1182,6 +1186,21 @@ public void setOp(boolean value) { nukkit.setOp(value); } + @Override + public void setPlayerListFooter(String footer) { + // Ignore - not implemented + } + + @Override + public void setPlayerListHeader(String header) { + // Ignore - not implemented + } + + @Override + public void setPlayerListHeaderFooter(String header, String footer) { + // Ignore - not implemented + } + @Override public void setPlayerListName(String arg0) { throw Pokkit.unsupported(); @@ -1425,6 +1444,11 @@ public void stopSound(String sound, SoundCategory category) { // Silently unsupported! } + @Override + public void updateCommands() { + // Silently unsupported! + } + @Override public void updateInventory() { nukkit.getInventory().sendContents(nukkit); diff --git a/src/main/java/nl/rutgerkok/pokkit/pluginservice/MainScoreboardService.java b/src/main/java/nl/rutgerkok/pokkit/pluginservice/MainScoreboardService.java index 0da3f71..2a0af2f 100644 --- a/src/main/java/nl/rutgerkok/pokkit/pluginservice/MainScoreboardService.java +++ b/src/main/java/nl/rutgerkok/pokkit/pluginservice/MainScoreboardService.java @@ -7,9 +7,11 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; -import cn.nukkit.plugin.PluginBase; +import nl.rutgerkok.pokkit.scoreboard.PokkitScoreboard; import nl.rutgerkok.pokkit.scoreboard.ScoreboardPersister; +import cn.nukkit.plugin.PluginBase; + /** * Saves and loads the main scoreboard. * @@ -37,7 +39,8 @@ public void onDisable(PluginBase pokkit) { @Override public void onLoad(PluginBase pokkit) { YamlConfiguration scoreboardConfig = YamlConfiguration.loadConfiguration(getScoreboardFile(pokkit)); - persister.loadScoreboard(scoreboardConfig, Bukkit.getScoreboardManager().getMainScoreboard()); + persister.loadScoreboard(scoreboardConfig, + (PokkitScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()); } } diff --git a/src/main/java/nl/rutgerkok/pokkit/potion/PokkitPotionEffect.java b/src/main/java/nl/rutgerkok/pokkit/potion/PokkitPotionEffect.java index 6164a28..f2e70b8 100644 --- a/src/main/java/nl/rutgerkok/pokkit/potion/PokkitPotionEffect.java +++ b/src/main/java/nl/rutgerkok/pokkit/potion/PokkitPotionEffect.java @@ -1,5 +1,6 @@ package nl.rutgerkok.pokkit.potion; +import org.bukkit.Color; import org.bukkit.potion.PotionEffect; import cn.nukkit.potion.Effect; @@ -11,7 +12,8 @@ public static Effect toNukkit(PotionEffect bukkitEffect) { nukkitEffect.setAmbient(bukkitEffect.isAmbient()); nukkitEffect.setAmplifier(bukkitEffect.getAmplifier()); nukkitEffect.setDuration(bukkitEffect.getDuration()); - nukkitEffect.setColor(bukkitEffect.getColor().getRed(), bukkitEffect.getColor().getGreen(), bukkitEffect.getColor().getBlue()); + Color color = bukkitEffect.getType().getColor(); + nukkitEffect.setColor(color.getRed(), color.getGreen(), color.getBlue()); nukkitEffect.setVisible(bukkitEffect.hasParticles()); return nukkitEffect; } diff --git a/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitScheduler.java b/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitScheduler.java index 374fbdd..d76f945 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitScheduler.java +++ b/src/main/java/nl/rutgerkok/pokkit/scheduler/PokkitScheduler.java @@ -6,15 +6,15 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.plugin.PokkitPlugin; - import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitWorker; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.plugin.PokkitPlugin; + import cn.nukkit.scheduler.ServerScheduler; /** @@ -47,11 +47,6 @@ public Future callSyncMethod(Plugin plugin, Callable callable) { return future; } - @Override - public void cancelAllTasks() { - nukkit.cancelAllTasks(); - } - @Override public void cancelTask(int taskId) { nukkit.cancelTask(taskId); diff --git a/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitScoreboard.java b/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitScoreboard.java index b59f18d..557713d 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitScoreboard.java +++ b/src/main/java/nl/rutgerkok/pokkit/scoreboard/PokkitScoreboard.java @@ -19,7 +19,7 @@ import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -final class PokkitScoreboard implements Scoreboard { +public final class PokkitScoreboard implements Scoreboard { /** * Map of player names to player score maps. @@ -157,6 +157,14 @@ public Objective registerNewObjective(String name, String criteria) throws Illeg return objective; } + @Override + public Objective registerNewObjective(String name, String criteria, String displayName) + throws IllegalArgumentException { + Objective objective = registerNewObjective(name, criteria); + objective.setDisplayName(displayName); + return objective; + } + @Override public Team registerNewTeam(String name) throws IllegalArgumentException { Validate.notNull(name, "name"); diff --git a/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java b/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java index 5fee06d..f7991b7 100644 --- a/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java +++ b/src/main/java/nl/rutgerkok/pokkit/scoreboard/ScoreboardPersister.java @@ -38,7 +38,7 @@ private void loadObjective(ConfigurationSection config, Objective objective) { * @param scoreboard * The scoreboard. */ - public void loadScoreboard(Configuration config, Scoreboard scoreboard) { + public void loadScoreboard(Configuration config, PokkitScoreboard scoreboard) { // Load teams ConfigurationSection teamsSection = config.getConfigurationSection("teams"); if (teamsSection == null) { diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java index dcea108..f803c36 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java @@ -5,12 +5,6 @@ import java.util.List; import java.util.Objects; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.blockstate.PokkitBlockState; -import nl.rutgerkok.pokkit.item.PokkitItemStack; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; -import nl.rutgerkok.pokkit.metadata.BlockMetadataStore; - import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -20,12 +14,18 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.PistonMoveReaction; +import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_99_R9.CraftServer; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.blockstate.PokkitBlockState; +import nl.rutgerkok.pokkit.item.PokkitItemStack; +import nl.rutgerkok.pokkit.metadata.BlockMetadataStore; + import cn.nukkit.block.BlockAir; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBlock; @@ -78,6 +78,11 @@ public Biome getBiome() { } + @Override + public BlockData getBlockData() { + return PokkitBlockData.toBukkit(nukkit); + } + private BlockMetadataStore getBlockMetadata() { return ((CraftServer) Bukkit.getServer()).getMetadata().getBlockMetadata(); } @@ -101,8 +106,8 @@ public Chunk getChunk() { @Override public byte getData() { - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.toItem()); - return (byte) materialData.getBukkitDamage(); + PokkitBlockData materialData = PokkitBlockData.toBukkit(nukkit); + return materialData.getNukkitData(); } @Override @@ -127,8 +132,7 @@ private Collection getDrops0(cn.nukkit.item.Item item) { Item[] drops = nukkit.getDrops(item); List result = new ArrayList<>(); for (Item drop : drops) { - PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(drop); - ItemStack stack = new ItemStack(materialData.getBukkitMaterial(), drop.getCount(), materialData.getBukkitDamage()); + ItemStack stack = PokkitItemStack.toBukkitCopy(drop); result.add(stack); } this.drops = result; @@ -153,12 +157,14 @@ public double getHumidity() { @Override public byte getLightFromBlocks() { - return (byte) nukkit.getLightLevel(); // TODO: I think this is wrong, but there isn't any way to get the light emitted from blocks + return (byte) nukkit.getLightLevel(); // I think this is wrong, but + // there isn't any way to get + // the light emitted from blocks } @Override public byte getLightFromSky() { - return (byte) nukkit.getLightLevel(); // TODO: Same thing as above + return (byte) nukkit.getLightLevel(); // Same thing as above } @Override @@ -226,23 +232,7 @@ public double getTemperature() { @Override public Material getType() { - return PokkitMaterialData.fromNukkit(nukkit.toItem()).getBukkitMaterial(); - } - - /** - * Gets the material data in one call. - * - * @return The material data. - */ - public MaterialData getTypeData() { - return PokkitMaterialData.fromNukkit(nukkit.toItem()).toBukkit(); - } - - @Override - public int getTypeId() { - @SuppressWarnings("deprecation") - int typeId = getType().getId(); - return typeId; + return PokkitBlockData.toBukkit(nukkit).getMaterial(); } @Override @@ -314,18 +304,13 @@ public void setBiome(Biome bio) { } @Override - public void setData(byte data) { - setData(data, true); + public void setBlockData(BlockData data) { + setBlockData(data, true); } @Override - public void setData(byte data, boolean applyPhysics) { - if (data == getData()) { - return; - } - - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(getType(), data); - setType0(materialData, applyPhysics); + public void setBlockData(BlockData data, boolean applyPhysics) { + this.setType0((PokkitBlockData) data, applyPhysics); } @Override @@ -347,59 +332,18 @@ public void setType(Material type, boolean applyPhysics) { type = Material.AIR; } - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(type, getData()); + PokkitBlockData materialData = PokkitBlockData.createBlockData(type, getData()); setType0(materialData, applyPhysics); } - private void setType0(PokkitMaterialData materialData, boolean applyPhysics) { + private void setType0(PokkitBlockData materialData, boolean applyPhysics) { int nukkitId = materialData.getNukkitId(); - int nukkitData = materialData.getNukkitDamage(); + int nukkitData = materialData.getNukkitData(); nukkit.level.setBlock(nukkit, cn.nukkit.block.Block.get(nukkitId, nukkitData), false, applyPhysics); // Update block reference nukkit = nukkit.level.getBlock(nukkit); } - /** - * Sets a material and data at the same time. - * - * @param materialData - * The material and data. - * @param applyPhysics - * Whether a physics update must be performed. - */ - public void setTypeAndData(MaterialData materialData, boolean applyPhysics) { - setType0(PokkitMaterialData.fromBukkit(materialData), applyPhysics); - } - - @Override - @Deprecated - public boolean setTypeId(int typeId) { - return setTypeId(typeId, true); - } - - @Override - @Deprecated - public boolean setTypeId(int typeId, boolean applyPhysics) { - Material material = Material.getMaterial(typeId); - if (material == null) { - return false; - } - setType(material, applyPhysics); - return true; - } - - @Override - @Deprecated - public boolean setTypeIdAndData(int typeId, byte data, boolean applyPhysics) { - Material type = Material.getMaterial(typeId); - if (type == null) { - return false; - } - - PokkitMaterialData materialData = PokkitMaterialData.fromBukkit(type, data); - setType0(materialData, applyPhysics); - return true; - } } diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java index 2a0c587..23a61ce 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitChunkSnapshot.java @@ -1,12 +1,14 @@ package nl.rutgerkok.pokkit.world; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; - import org.bukkit.ChunkSnapshot; import org.bukkit.Material; import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; + +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import cn.nukkit.block.Block; import cn.nukkit.level.format.generic.BaseFullChunk; public class PokkitChunkSnapshot implements ChunkSnapshot { @@ -14,8 +16,7 @@ public class PokkitChunkSnapshot implements ChunkSnapshot { private final int z; private final String worldname; // X, Y, Z - private Material[][][] blocksIds = new Material[16][256][16]; - private int[][][] blocksData = new int[16][256][16]; + private PokkitBlockData[][][] blocksIds = new PokkitBlockData[16][256][16]; BaseFullChunk nukkit; @@ -30,10 +31,10 @@ public PokkitChunkSnapshot(final int x, final int z, final String wname, BaseFul for (int blockX = 0; blockX < 16; blockX++) { for (int blockY = 0; blockY < 255; blockY++) { for (int blockZ = 0; blockZ < 16; blockZ++) { - @SuppressWarnings("deprecation") - PokkitMaterialData data = PokkitMaterialData.fromNukkit(baseFullChunk.getBlockId(blockX, blockY, blockZ), baseFullChunk.getBlockData(blockX, blockY, blockZ)); - blocksIds[blockX][blockY][blockZ] = data.getBukkitMaterial(); - blocksData[blockX][blockY][blockZ] = data.getBukkitDamage(); + PokkitBlockData data = PokkitBlockData + .toBukkit(Block.get(baseFullChunk.getBlockId(blockX, blockY, blockZ), + baseFullChunk.getBlockData(blockX, blockY, blockZ))); + blocksIds[blockX][blockY][blockZ] = data; } } } @@ -45,8 +46,8 @@ public Biome getBiome(int x, int z) { } @Override - public int getBlockData(int x, int y, int z) { - return blocksData[x][y][z]; + public BlockData getBlockData(int x, int y, int z) { + return blocksIds[x][y][z]; } @Override @@ -61,13 +62,7 @@ public int getBlockSkyLight(int x, int y, int z) { @Override public Material getBlockType(int x, int y, int z) { - return blocksIds[x][y][z]; - } - - @Override - @Deprecated - public int getBlockTypeId(int x, int y, int z) { - return blocksIds[x][y][z].getId(); + return blocksIds[x][y][z].getMaterial(); } @Override @@ -77,14 +72,13 @@ public long getCaptureFullTime() { } @Override - public int getHighestBlockYAt(int x, int z) { - return nukkit.getHighestBlockAt(x, z); + public int getData(int x, int y, int z) { + return blocksIds[x][y][z].getNukkitData(); } @Override - public double getRawBiomeRainfall(int x, int z) { - throw Pokkit.unsupported(); - + public int getHighestBlockYAt(int x, int z) { + return nukkit.getHighestBlockAt(x, z); } @Override diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitGameRule.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitGameRule.java new file mode 100644 index 0000000..f2893c3 --- /dev/null +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitGameRule.java @@ -0,0 +1,42 @@ +package nl.rutgerkok.pokkit.world; + +import java.lang.reflect.Constructor; + +import org.bukkit.GameRule; + +public class PokkitGameRule { + + /** + * Gets the corresponding Bukkit GameRule + * + * @param nukkit + * The Nukkit GameRule. + * @return The Bukkit GameRule. It is created if it does not exist yet. + */ + public static GameRule toBukkit(cn.nukkit.level.GameRule nukkit) { + GameRule bukkit = GameRule.getByName(nukkit.getName()); + if (bukkit == null) { + try { + @SuppressWarnings("rawtypes") + Constructor constructor = GameRule.class.getDeclaredConstructor(String.class, Class.class); + constructor.setAccessible(true); + bukkit = constructor.newInstance(nukkit.getName(), Boolean.class); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Failed to create new game rule", e); + } + } + return bukkit; + } + + /** + * Gets the corresponding Nukkit GameRule. + * + * @param rule + * The Bukkit GameRule. + * @return The Nukkit GameRule, or null if not found. + */ + public static cn.nukkit.level.GameRule toNukkit(GameRule rule) { + return cn.nukkit.level.GameRule.parseString(rule.getName()).orElse(null); + } + +} diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java index 92a05ff..adbf4c1 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java @@ -16,6 +16,7 @@ import org.bukkit.ChunkSnapshot; import org.bukkit.Difficulty; import org.bukkit.Effect; +import org.bukkit.GameRule; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -27,6 +28,7 @@ import org.bukkit.WorldType; import org.bukkit.block.Biome; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_99_R9.CraftServer; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; @@ -39,25 +41,11 @@ import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; -import cn.nukkit.entity.weather.EntityLightning; -import cn.nukkit.level.Explosion; -import cn.nukkit.level.Level; -import cn.nukkit.level.Position; -import cn.nukkit.level.format.FullChunk; -import cn.nukkit.level.format.generic.BaseFullChunk; -import cn.nukkit.level.particle.GenericParticle; -import cn.nukkit.math.Vector3; -import cn.nukkit.nbt.tag.CompoundTag; -import cn.nukkit.nbt.tag.DoubleTag; -import cn.nukkit.nbt.tag.FloatTag; -import cn.nukkit.nbt.tag.ListTag; - import nl.rutgerkok.pokkit.Pokkit; import nl.rutgerkok.pokkit.PokkitLocation; import nl.rutgerkok.pokkit.PokkitSound; @@ -71,6 +59,20 @@ import nl.rutgerkok.pokkit.particle.PokkitParticle; import nl.rutgerkok.pokkit.player.PokkitPlayer; +import cn.nukkit.entity.weather.EntityLightning; +import cn.nukkit.level.Explosion; +import cn.nukkit.level.GameRules; +import cn.nukkit.level.Level; +import cn.nukkit.level.Position; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.level.particle.GenericParticle; +import cn.nukkit.math.Vector3; +import cn.nukkit.nbt.tag.CompoundTag; +import cn.nukkit.nbt.tag.DoubleTag; +import cn.nukkit.nbt.tag.FloatTag; +import cn.nukkit.nbt.tag.ListTag; + public final class PokkitWorld implements World { private static final int WORLD_HEIGHT = 256; @@ -221,22 +223,6 @@ public Block getBlockAt(Location location) { return getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } - @Override - @Deprecated - public int getBlockTypeIdAt(int x, int y, int z) { - cn.nukkit.block.Block nukkitBlock = nukkit.getBlock(new Vector3(x, y, z)); - return Material.getMaterial(nukkitBlock.getId()).getId(); - } - - @Override - @Deprecated - public int getBlockTypeIdAt(Location location) { - cn.nukkit.block.Block nukkitBlock = nukkit.getBlock( - new Vector3(location.getBlockX(), location.getBlockY(), location.getBlockZ()) - ); - return Material.getMaterial(nukkitBlock.getId()).getId(); - } - @Override public Chunk getChunkAt(Block block) { return PokkitChunk.of(block); @@ -304,14 +290,59 @@ public long getFullTime() { } + @Override + public T getGameRuleDefault(GameRule rule) { + return getGameRuleValue0(rule, GameRules.getDefault()); + } + @Override public String[] getGameRules() { - return new String[0]; + cn.nukkit.level.GameRule[] rules = this.nukkit.getGameRules().getRules(); + String[] ruleStrings = new String[rules.length]; + for (int i = 0; i < ruleStrings.length; i++) { + ruleStrings[i] = rules[i].getName(); + } + return ruleStrings; } @Override - public String getGameRuleValue(String rule) { - return null; + public T getGameRuleValue(GameRule rule) { + return getGameRuleValue0(rule, this.nukkit.getGameRules()); + } + + @Override + public String getGameRuleValue(String stringRule) { + if (stringRule == null) { + return null; + } + GameRule rule = GameRule.getByName(stringRule); + if (rule == null) { + return null; + } + return Objects.toString(getGameRuleValue(rule)); + } + + @SuppressWarnings("unchecked") + private T getGameRuleValue0(GameRule rule, GameRules source) { + cn.nukkit.level.GameRule nukkitRule = PokkitGameRule.toNukkit(rule); + if (nukkitRule == null) { + if (rule.getType().equals(Integer.class)) { + return (T) Integer.valueOf(0); + } + if (rule.getType().equals(Boolean.class)) { + return (T) Boolean.FALSE; + } + throw new IllegalArgumentException("Unknown GameRule with unknown type: " + rule); + } + + Class type = rule.getType(); + if (type.equals(Boolean.class)) { + return (T) Boolean.valueOf(source.getBoolean(nukkitRule)); + } + if (type.equals(Integer.class)) { + return (T) Integer.valueOf(source.getInteger(nukkitRule)); + } + throw new IllegalArgumentException("GameRule with unknown type: " + rule + " of type " + type); } @Override @@ -692,10 +723,36 @@ public void setFullTime(long time) { } @Override - public boolean setGameRuleValue(String rule, String value) { + public boolean setGameRule(GameRule rule, T newValue) { + cn.nukkit.level.GameRule nukkitRule = PokkitGameRule.toNukkit(rule); + if (nukkitRule == null) { + return false; + } + if (newValue instanceof Boolean) { + nukkit.getGameRules().setGameRule(nukkitRule, ((Boolean)newValue).booleanValue()); + return true; + } + if (newValue instanceof Integer) { + nukkit.getGameRules().setGameRule(nukkitRule, ((Integer)newValue).intValue()); + return true; + } return false; } + @Override + public boolean setGameRuleValue(String rule, String value) { + cn.nukkit.level.GameRule gameRule = cn.nukkit.level.GameRule.parseString(rule).orElse(null); + if (gameRule == null) { + return false; + } + try { + nukkit.getGameRules().setGameRules(gameRule, value); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + @Override public void setKeepSpawnInMemory(boolean keepLoaded) { throw Pokkit.unsupported(); @@ -831,10 +888,8 @@ public Entity spawnEntity(Location loc, EntityType type) { } @Override - public FallingBlock spawnFallingBlock(Location location, int blockId, byte blockData) - throws IllegalArgumentException { + public FallingBlock spawnFallingBlock(Location location, BlockData data) throws IllegalArgumentException { throw Pokkit.unsupported(); - } @Override @@ -844,7 +899,9 @@ public FallingBlock spawnFallingBlock(Location location, Material material, byte } @Override - public FallingBlock spawnFallingBlock(Location location, MaterialData materialData) throws IllegalArgumentException { + public FallingBlock spawnFallingBlock(Location location, + @SuppressWarnings("deprecation") org.bukkit.material.MaterialData materialData) + throws IllegalArgumentException { throw Pokkit.unsupported(); } diff --git a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java index e35f613..740b151 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java @@ -13,42 +13,28 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; +import java.util.function.Consumer; import java.util.logging.Logger; import java.util.stream.Collectors; -import nl.rutgerkok.pokkit.Pokkit; -import nl.rutgerkok.pokkit.PokkitGameMode; -import nl.rutgerkok.pokkit.PokkitHelpMap; -import nl.rutgerkok.pokkit.PokkitPluginMessenger; -import nl.rutgerkok.pokkit.PokkitUnsafe; -import nl.rutgerkok.pokkit.UniqueIdConversion; -import nl.rutgerkok.pokkit.command.PokkitCommandFetcher; -import nl.rutgerkok.pokkit.command.PokkitCommandSender; -import nl.rutgerkok.pokkit.enchantment.PokkitEnchantment; -import nl.rutgerkok.pokkit.inventory.custom.PokkitCustomInventory; -import nl.rutgerkok.pokkit.item.PokkitItemFactory; -import nl.rutgerkok.pokkit.metadata.AllMetadataStore; -import nl.rutgerkok.pokkit.player.OnlinePlayerData; -import nl.rutgerkok.pokkit.player.PokkitOfflinePlayer; -import nl.rutgerkok.pokkit.player.PokkitPlayer; -import nl.rutgerkok.pokkit.plugin.PokkitPluginManager; -import nl.rutgerkok.pokkit.scheduler.PokkitScheduler; -import nl.rutgerkok.pokkit.scoreboard.PokkitScoreboardManager; -import nl.rutgerkok.pokkit.world.PokkitWorld; -import nl.rutgerkok.pokkit.world.PokkitWorldType; +import com.google.common.collect.ImmutableMap; import org.bukkit.BanList; import org.bukkit.BanList.Type; import org.bukkit.GameMode; +import org.bukkit.Keyed; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Server; +import org.bukkit.Tag; import org.bukkit.UnsafeValues; import org.bukkit.Warning.WarningState; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; import org.bukkit.advancement.Advancement; +import org.bukkit.block.data.BlockData; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; @@ -70,6 +56,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Merchant; import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; import org.bukkit.map.MapView; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -80,10 +67,31 @@ import org.bukkit.scoreboard.ScoreboardManager; import org.bukkit.util.CachedServerIcon; -import com.google.common.collect.ImmutableMap; +import net.md_5.bungee.api.chat.BaseComponent; + +import nl.rutgerkok.pokkit.Pokkit; +import nl.rutgerkok.pokkit.PokkitGameMode; +import nl.rutgerkok.pokkit.PokkitHelpMap; +import nl.rutgerkok.pokkit.PokkitPluginMessenger; +import nl.rutgerkok.pokkit.PokkitUnsafe; +import nl.rutgerkok.pokkit.UniqueIdConversion; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; +import nl.rutgerkok.pokkit.command.PokkitCommandFetcher; +import nl.rutgerkok.pokkit.command.PokkitCommandSender; +import nl.rutgerkok.pokkit.enchantment.PokkitEnchantment; +import nl.rutgerkok.pokkit.inventory.custom.PokkitCustomInventory; +import nl.rutgerkok.pokkit.item.PokkitItemFactory; +import nl.rutgerkok.pokkit.metadata.AllMetadataStore; +import nl.rutgerkok.pokkit.player.OnlinePlayerData; +import nl.rutgerkok.pokkit.player.PokkitOfflinePlayer; +import nl.rutgerkok.pokkit.player.PokkitPlayer; +import nl.rutgerkok.pokkit.plugin.PokkitPluginManager; +import nl.rutgerkok.pokkit.scheduler.PokkitScheduler; +import nl.rutgerkok.pokkit.scoreboard.PokkitScoreboardManager; +import nl.rutgerkok.pokkit.world.PokkitWorld; +import nl.rutgerkok.pokkit.world.PokkitWorldType; import cn.nukkit.level.Level; -import net.md_5.bungee.api.chat.BaseComponent; @SuppressWarnings("deprecation") public final class CraftServer extends Server.Spigot implements Server { @@ -182,6 +190,33 @@ public void clearRecipes() { } + @Override + public BlockData createBlockData(Material material) { + return PokkitBlockData.createBlockData(material, 0); + } + + @Override + public BlockData createBlockData(Material material, Consumer consumer) { + BlockData blockData = PokkitBlockData.createBlockData(material, 0); + consumer.accept(blockData); + return blockData; + } + + @Override + public BlockData createBlockData(Material material, String data) throws IllegalArgumentException { + try { + int blockData = Integer.parseUnsignedInt(data); + return PokkitBlockData.createBlockData(material, blockData); + } catch(NumberFormatException e) { + throw new IllegalArgumentException("Data \""+data+"\"is not valid block data. " + Pokkit.NAME + " expects a number as the block data, as block states do not exist yet in MCPE."); + } + } + + @Override + public BlockData createBlockData(String data) throws IllegalArgumentException { + return PokkitBlockData.createBlockData(data); + } + @Override public BossBar createBossBar(String arg0, BarColor arg1, BarStyle arg2, BarFlag... arg3) { throw Pokkit.unsupported(); @@ -232,7 +267,7 @@ public World createWorld(WorldCreator creator) { if (alreadyLoaded != null) { return alreadyLoaded; } - + if (nukkit.isLevelGenerated(creator.name())) { nukkit.loadLevel(creator.name()); World alreadyGenerated = this.getWorld(creator.name()); @@ -386,6 +421,11 @@ public Logger getLogger() { return logger; } + @Override + public LootTable getLootTable(NamespacedKey key) { + throw Pokkit.unsupported(); + } + @Override public MapView getMap(short arg0) { throw Pokkit.unsupported(); @@ -560,6 +600,11 @@ public int getSpawnRadius() { return nukkit.getSpawnRadius(); } + @Override + public Tag getTag(String registry, NamespacedKey tag, Class clazz) { + throw Pokkit.unsupported(); + } + @Override public int getTicksPerAnimalSpawns() { throw Pokkit.unsupported(); diff --git a/src/test/java/nl/rutgerkok/pokkit/inventory/ItemTest.java b/src/test/java/nl/rutgerkok/pokkit/inventory/ItemTest.java new file mode 100644 index 0000000..ea9efc3 --- /dev/null +++ b/src/test/java/nl/rutgerkok/pokkit/inventory/ItemTest.java @@ -0,0 +1,5 @@ +package nl.rutgerkok.pokkit.inventory; + +public class ItemTest { + +} diff --git a/src/test/java/nl/rutgerkok/pokkit/world/PokkitMaterialTest.java b/src/test/java/nl/rutgerkok/pokkit/world/PokkitMaterialTest.java index af41172..19435aa 100644 --- a/src/test/java/nl/rutgerkok/pokkit/world/PokkitMaterialTest.java +++ b/src/test/java/nl/rutgerkok/pokkit/world/PokkitMaterialTest.java @@ -2,37 +2,42 @@ import static org.junit.Assert.assertEquals; -import nl.rutgerkok.pokkit.material.PokkitMaterialData; - import org.bukkit.Material; -import org.junit.Ignore; +import org.junit.BeforeClass; import org.junit.Test; +import nl.rutgerkok.pokkit.blockdata.PokkitBlockData; + import cn.nukkit.block.Block; public class PokkitMaterialTest { + @BeforeClass + public static void init() { + Block.init(); + } + @Test public void testAir() { - assertEquals(Block.AIR, PokkitMaterialData.fromBukkit(Material.AIR, 0).getNukkitId()); + assertEquals(Block.AIR, PokkitBlockData.createBlockData(Material.AIR, 0).getNukkitId()); } + @SuppressWarnings("deprecation") @Test public void testDamage() { // Damage value must be kept at 3 - assertEquals(3, PokkitMaterialData.fromBukkit(Material.WOOL, 3).getNukkitDamage()); + assertEquals(3, PokkitBlockData.createBlockData(Material.LEGACY_WOOL, 3).getNukkitData()); } @Test - @Ignore // no remap support yet public void testIdRemap() { // GRASS_PATH has a different block id in Bukkit and Nukkit - assertEquals(Block.GRASS_PATH, PokkitMaterialData.fromBukkit(Material.GRASS_PATH, 0).getNukkitId()); + assertEquals(Block.GRASS_PATH, PokkitBlockData.createBlockData(Material.GRASS_PATH, 0).getNukkitId()); } @Test public void testSameIdInBukkitAndNukkit() { - assertEquals(Block.STONE, PokkitMaterialData.fromBukkit(Material.STONE, 0).getNukkitId()); - assertEquals(Block.GRASS, PokkitMaterialData.fromBukkit(Material.GRASS, 0).getNukkitId()); + assertEquals(Block.STONE, PokkitBlockData.createBlockData(Material.STONE, 0).getNukkitId()); + assertEquals(Block.GRASS, PokkitBlockData.createBlockData(Material.GRASS_BLOCK, 0).getNukkitId()); } } From 3541f5fe452aff532b87f4cd6f0890c21b4cc103 Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Sun, 26 Aug 2018 14:40:56 +0200 Subject: [PATCH 11/14] Add the new spawnParticle methods --- .../rutgerkok/pokkit/world/PokkitWorld.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java index adbf4c1..e15cc9c 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java @@ -907,24 +907,30 @@ public FallingBlock spawnFallingBlock(Location location, @Override public void spawnParticle(Particle particle, double x, double y, double z, int count) { - spawnParticle(particle, x, y, z, count); + spawnParticle(particle, x, y, z, count, 0, 0, 0); } @Override public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ) { - spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ); + spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, 0); } @Override public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra) { - spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra); + spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null); } @Override public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) { + spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data, false); + } + + @Override + public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, + double offsetY, double offsetZ, double extra, T data, boolean force) { int id = 0; id = PokkitParticle.toNukkit(particle); @@ -969,25 +975,33 @@ public void spawnParticle(Particle particle, double x, double y, double z, i @Override public void spawnParticle(Particle particle, Location location, int count) { - spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, 0, 0, 0); + spawnParticle(particle, location, count, 0, 0, 0); } @Override public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ) { - spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, 0); + spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, 0); } @Override public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) { - spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, null); + spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, extra, null); } @Override public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) { - spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, data); + spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, extra, data, false); + + } + + @Override + public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, + double offsetZ, double extra, T data, boolean force) { + spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, + extra, data, force); } From 4d6aa0371a810463c12f6c1d74b7e847b1cdf9ac Mon Sep 17 00:00:00 2001 From: Petteri Date: Mon, 18 Feb 2019 15:31:07 +0200 Subject: [PATCH 12/14] Update (#110) * Update README.md * Update pom.xml Uses nukkitx instead of nukkit, which has been discontinued. * Bring some classes up to date * Register new enchantments + add some sounds * Target to latest API version Switched from 1.0.0 to 1.0.7. * Implement some PokkitWorld methods --- README.md | 6 +-- pom.xml | 10 ++-- .../java/nl/rutgerkok/pokkit/PokkitSound.java | 22 ++++---- .../pokkit/blockstate/SignBlockState.java | 9 ++++ .../pokkit/enchantment/PokkitEnchantment.java | 10 +++- .../enchantment/PokkitEnchantmentTarget.java | 6 +-- .../rutgerkok/pokkit/entity/PokkitEntity.java | 6 +++ .../pokkit/entity/PokkitHumanEntity.java | 22 ++++++++ .../pokkit/entity/PokkitItemEntity.java | 5 ++ .../pokkit/entity/PokkitItemFrameEntity.java | 5 ++ .../pokkit/inventory/PokkitInventoryType.java | 2 +- .../custom/NukkitCustomInventory.java | 2 +- .../rutgerkok/pokkit/item/PokkitItemMeta.java | 50 +++++++++++++++++++ .../rutgerkok/pokkit/player/PokkitPlayer.java | 2 +- .../rutgerkok/pokkit/world/PokkitBlock.java | 5 ++ .../rutgerkok/pokkit/world/PokkitWorld.java | 33 ++++++------ .../craftbukkit/v1_99_R9/CraftServer.java | 11 ++++ src/main/resources/plugin.yml | 3 +- 18 files changed, 163 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index b824e4a..8139ab1 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # Pokkit [![Build Status](https://travis-ci.org/rutgerkok/Pokkit.svg?branch=master)](https://travis-ci.org/rutgerkok/Pokkit) -|

Project status

| -|-------------------| -| Currently, Nukkit, on which this project depends, is not actively developed. Pokkit is of course still open for contributions, but I don't really expect any interest. The best option for running Bukkit plugins on Minecraft Pocket Edition (or equivalently, Bedrock Edition) currently seems to be Dragonet DragonProxy. | - -The Minecraft multiplayer scene is fragmented. There are many competing server implementations. A popular server is [Spigot](http://www.spigotmc.org/). Spigot is able to load plugins, which can interact with Minecraft through the Spigot Plugin API. For Minecraft Pocket Edition, the mobile version of Minecraft, a server with a plugin API similar to Spigot exists: [Nukkit](https://forums.nukkit.io/). Unfortunately, plugins written for Spigot cannot run on Nukkit. +The Minecraft multiplayer scene is fragmented. There are many competing server implementations. A popular server is [Spigot](http://www.spigotmc.org/). Spigot is able to load plugins, which can interact with Minecraft through the Spigot Plugin API. For Minecraft Pocket Edition, the mobile version of Minecraft, a server with a plugin API similar to Spigot exists: [Nukkit](https://nukkitx.com/). Unfortunately, plugins written for Spigot cannot run on Nukkit. Pokkit is a translation layer that allows plugins written for Spigot to work on Nukkit. However, it is far from perfect. Because of the size of the Spigot API, it is not possible for me to implement all of the Spigot API. diff --git a/pom.xml b/pom.xml index 7aea07c..f8c30f8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 nl.rutgerkok - pokkit - 0.6-SNAPSHOT + Pokkit + 0.7 Pokkit Run Bukkit and Spigot plugins on Nukkit! @@ -54,8 +54,8 @@ - potestas-repo - https://repo.potestas.xyz/main/ + nukkitx + https://repo.nukkitx.com/main/ spigot-repo @@ -119,4 +119,4 @@ - \ No newline at end of file + diff --git a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java index ed099c1..ae0649e 100644 --- a/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java +++ b/src/main/java/nl/rutgerkok/pokkit/PokkitSound.java @@ -34,15 +34,15 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo case BLOCK_BREWING_STAND_BREW: break; case BLOCK_CHEST_CLOSE: - break; + return cn.nukkit.level.Sound.RANDOM_CHESTCLOSED; case BLOCK_CHEST_LOCKED: break; case BLOCK_CHEST_OPEN: - break; + return cn.nukkit.level.Sound.RANDOM_CHESTOPEN; case BLOCK_CHORUS_FLOWER_DEATH: - break; + return cn.nukkit.level.Sound.BLOCK_CHORUSFLOWER_DEATH; case BLOCK_CHORUS_FLOWER_GROW: - break; + return cn.nukkit.level.Sound.BLOCK_CHORUSFLOWER_GROW; case BLOCK_COMPARATOR_CLICK: break; case BLOCK_DISPENSER_DISPENSE: @@ -740,19 +740,19 @@ public static cn.nukkit.level.Sound toNukkit(Location location, Sound sound, flo case ITEM_SHOVEL_FLATTEN: break; case MUSIC_CREATIVE: - break; + return cn.nukkit.level.Sound.MUSIC_GAME_CREATIVE; case MUSIC_CREDITS: - break; + return cn.nukkit.level.Sound.MUSIC_GAME_CREDITS; case MUSIC_DRAGON: - break; + return cn.nukkit.level.Sound.MUSIC_GAME_ENDBOSS; case MUSIC_END: - break; + return cn.nukkit.level.Sound.MUSIC_GAME_END; case MUSIC_GAME: - break; + return cn.nukkit.level.Sound.MUSIC_GAME; case MUSIC_MENU: - break; + return cn.nukkit.level.Sound.MUSIC_MENU; case MUSIC_NETHER: - break; + return cn.nukkit.level.Sound.MUSIC_GAME_NETHER; case MUSIC_DISC_11: break; case MUSIC_DISC_13: diff --git a/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java b/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java index de33532..16902ab 100644 --- a/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java +++ b/src/main/java/nl/rutgerkok/pokkit/blockstate/SignBlockState.java @@ -79,4 +79,13 @@ public void setLine(int index, String line) throws IndexOutOfBoundsException { lines[index] = line; } + @Override + public boolean isEditable() { + throw Pokkit.unsupported(); + } + + @Override + public void setEditable(boolean editable) { + throw Pokkit.unsupported(); + } } diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java index f4c5e86..caeece9 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantment.java @@ -8,7 +8,7 @@ public class PokkitEnchantment { - private static Enchantment[] nukkitToBukkit = new Enchantment[25]; + private static Enchantment[] nukkitToBukkit = new Enchantment[33]; private static Map bukkitToNukkit = new HashMap<>(); static { @@ -37,6 +37,14 @@ public class PokkitEnchantment { twoWay(cn.nukkit.item.enchantment.Enchantment.ID_BOW_INFINITY, Enchantment.ARROW_INFINITE); twoWay(cn.nukkit.item.enchantment.Enchantment.ID_FORTUNE_FISHING, Enchantment.LUCK); twoWay(cn.nukkit.item.enchantment.Enchantment.ID_LURE, Enchantment.LURE); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_FROST_WALKER, Enchantment.FROST_WALKER); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_MENDING, Enchantment.MENDING); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_BINDING_CURSE, Enchantment.BINDING_CURSE); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_VANISHING_CURSE, Enchantment.VANISHING_CURSE); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_TRIDENT_IMPALING, Enchantment.IMPALING); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_TRIDENT_LOYALTY, Enchantment.LOYALTY); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_TRIDENT_RIPTIDE, Enchantment.RIPTIDE); + twoWay(cn.nukkit.item.enchantment.Enchantment.ID_TRIDENT_CHANNELING, Enchantment.CHANNELING); } /** diff --git a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java index e1b25ef..fafdd99 100644 --- a/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java +++ b/src/main/java/nl/rutgerkok/pokkit/enchantment/PokkitEnchantmentTarget.java @@ -25,10 +25,8 @@ public class PokkitEnchantmentTarget { twoWay(EnchantmentType.DIGGER, EnchantmentTarget.TOOL); twoWay(EnchantmentType.FISHING_ROD, EnchantmentTarget.FISHING_ROD); twoWay(EnchantmentType.SWORD, EnchantmentTarget.WEAPON); - - // For WEARABLE and TRIDENT, no suitable Nukkit target exists yet - bukkitToNukkit.put(EnchantmentTarget.WEARABLE, EnchantmentType.BREAKABLE); - bukkitToNukkit.put(EnchantmentTarget.TRIDENT, EnchantmentType.BREAKABLE); + twoWay(EnchantmentType.WEARABLE, EnchantmentTarget.WEARABLE); + twoWay(EnchantmentType.TRIDENT, EnchantmentTarget.TRIDENT); } /** diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java index 1b47b92..fedc340 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitEntity.java @@ -14,6 +14,7 @@ import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.block.BlockFace; import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -563,4 +564,9 @@ public boolean teleport(Location location) { public boolean teleport(Location location, TeleportCause cause) { return nukkit.teleport(PokkitLocation.toNukkit(location), PokkitTeleportCause.toNukkit(cause)); } + + @Override + public BlockFace getFacing() { + throw Pokkit.unsupported(); + } } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java index 976344a..8254622 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitHumanEntity.java @@ -8,6 +8,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Villager; @@ -19,6 +20,8 @@ import org.bukkit.inventory.Merchant; import org.bukkit.inventory.PlayerInventory; +import java.util.Collection; + public class PokkitHumanEntity extends PokkitLivingEntity implements HumanEntity { public static HumanEntity toBukkit(cn.nukkit.entity.EntityHuman human) { @@ -189,4 +192,23 @@ public boolean setWindowProperty(Property prop, int value) { throw Pokkit.unsupported(); } + @Override + public boolean discoverRecipe(NamespacedKey key) { + throw Pokkit.unsupported(); + } + + @Override + public int discoverRecipes(Collection key) { + throw Pokkit.unsupported(); + } + + @Override + public boolean undiscoverRecipe(NamespacedKey key) { + throw Pokkit.unsupported(); + } + + @Override + public int undiscoverRecipes(Collection key) { + throw Pokkit.unsupported(); + } } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java index 8495982..5c768cc 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemEntity.java @@ -2,6 +2,7 @@ import java.util.Objects; +import org.bukkit.block.BlockFace; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; @@ -56,4 +57,8 @@ public void setPickupDelay(int delay) { throw Pokkit.unsupported(); } + @Override + public BlockFace getFacing() { + throw Pokkit.unsupported(); + } } diff --git a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java index b444a4c..1c7e0e5 100644 --- a/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java +++ b/src/main/java/nl/rutgerkok/pokkit/entity/PokkitItemFrameEntity.java @@ -80,6 +80,11 @@ public void setItem(ItemStack item) { nukkit.setItem(PokkitItemStack.toNukkitCopy(item)); } + @Override + public void setItem(ItemStack item, boolean b) { + nukkit.setItem(PokkitItemStack.toNukkitCopy(item)); + } + @Override public void setRotation(Rotation rotation) throws IllegalArgumentException { throw Pokkit.unsupported(); diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java index e622087..39eb33b 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/PokkitInventoryType.java @@ -27,9 +27,9 @@ public final class PokkitInventoryType { twoWay(cn.nukkit.inventory.InventoryType.WORKBENCH, InventoryType.WORKBENCH); twoWay(cn.nukkit.inventory.InventoryType.ENDER_CHEST, InventoryType.ENDER_CHEST); twoWay(cn.nukkit.inventory.InventoryType.SHULKER_BOX, InventoryType.SHULKER_BOX); + twoWay(cn.nukkit.inventory.InventoryType.BEACON, InventoryType.BEACON); bukkitToNukkit.put(InventoryType.MERCHANT, cn.nukkit.inventory.InventoryType.ANVIL); - bukkitToNukkit.put(InventoryType.BEACON, cn.nukkit.inventory.InventoryType.ENCHANT_TABLE); bukkitToNukkit.put(InventoryType.CREATIVE, cn.nukkit.inventory.InventoryType.PLAYER); nukkitToBukkit.put(cn.nukkit.inventory.InventoryType.CURSOR, InventoryType.PLAYER); // TODO wrong diff --git a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java index ccc858d..92b036f 100644 --- a/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java +++ b/src/main/java/nl/rutgerkok/pokkit/inventory/custom/NukkitCustomInventory.java @@ -6,10 +6,10 @@ import java.util.Objects; import cn.nukkit.Player; -import cn.nukkit.block.GlobalBlockPalette; import cn.nukkit.inventory.BaseInventory; import cn.nukkit.inventory.InventoryType; import cn.nukkit.item.Item; +import cn.nukkit.level.GlobalBlockPalette; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.NBTIO; import cn.nukkit.nbt.tag.CompoundTag; diff --git a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java index 7250da8..898dc1b 100644 --- a/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java +++ b/src/main/java/nl/rutgerkok/pokkit/item/PokkitItemMeta.java @@ -1,6 +1,7 @@ package nl.rutgerkok.pokkit.item; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.List; @@ -10,9 +11,13 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; import org.bukkit.Material; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; @@ -412,4 +417,49 @@ public Spigot spigot() { return this; } + @Override + @SuppressWarnings("rawtypes") + public void setAttributeModifiers(Multimap modifiers) { + throw Pokkit.unsupported(); + } + + @Override + public boolean hasAttributeModifiers() { + throw Pokkit.unsupported(); + } + + @Override + public boolean addAttributeModifier(Attribute a, AttributeModifier m) { + throw Pokkit.unsupported(); + } + + @Override + public boolean removeAttributeModifier(Attribute a) { + throw Pokkit.unsupported(); + } + + @Override + public boolean removeAttributeModifier(Attribute a, AttributeModifier m) { + throw Pokkit.unsupported(); + } + + @Override + public boolean removeAttributeModifier(EquipmentSlot slot) { + throw Pokkit.unsupported(); + } + + @Override + public Multimap getAttributeModifiers() { + throw Pokkit.unsupported(); + } + + @Override + public Collection getAttributeModifiers(Attribute attribute) { + throw Pokkit.unsupported(); + } + + @Override + public Multimap getAttributeModifiers(EquipmentSlot slot) { + throw Pokkit.unsupported(); + } } diff --git a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java index 1b75063..7272828 100644 --- a/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java +++ b/src/main/java/nl/rutgerkok/pokkit/player/PokkitPlayer.java @@ -72,8 +72,8 @@ import nl.rutgerkok.pokkit.potion.PokkitPotionEffect; import cn.nukkit.AdventureSettings; -import cn.nukkit.block.GlobalBlockPalette; import cn.nukkit.event.player.PlayerChatEvent; +import cn.nukkit.level.GlobalBlockPalette; import cn.nukkit.level.particle.GenericParticle; import cn.nukkit.math.Vector3; import cn.nukkit.network.protocol.UpdateBlockPacket; diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java index f803c36..efb750c 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java @@ -292,6 +292,11 @@ public boolean isLiquid() { return nukkit instanceof cn.nukkit.block.BlockLiquid; } + @Override + public boolean isPassable() { + return nukkit.canPassThrough(); + } + @Override public void removeMetadata(String metadataKey, Plugin owningPlugin) { getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin); diff --git a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java index e15cc9c..c3c63b1 100644 --- a/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java +++ b/src/main/java/nl/rutgerkok/pokkit/world/PokkitWorld.java @@ -1,5 +1,6 @@ package nl.rutgerkok.pokkit.world; +import org.bukkit.StructureType; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -286,8 +287,7 @@ public Environment getEnvironment() { @Override public long getFullTime() { - throw Pokkit.unsupported(); - + return nukkit.getTime(); } @Override @@ -483,8 +483,7 @@ public double getTemperature(int x, int z) { @Override public int getThunderDuration() { - throw Pokkit.unsupported(); - + return nukkit.getThunderTime(); } @Override @@ -517,8 +516,7 @@ public int getWaterAnimalSpawnLimit() { @Override public int getWeatherDuration() { - throw Pokkit.unsupported(); - + return nukkit.getRainTime(); } @Override @@ -549,14 +547,13 @@ public boolean hasMetadata(String metadataKey) { @Override public boolean hasStorm() { - throw Pokkit.unsupported(); + return nukkit.isThundering(); } @Override public boolean isAutoSave() { - throw Pokkit.unsupported(); - + return nukkit.getAutoSave(); } @Override @@ -718,8 +715,7 @@ public void setDifficulty(Difficulty difficulty) { @Override public void setFullTime(long time) { - throw Pokkit.unsupported(); - + nukkit.setTime((int) time); } @Override @@ -799,14 +795,12 @@ public boolean setSpawnLocation(Location location) { @Override public void setStorm(boolean hasStorm) { - // Silently unsupported! - // Nukkit doesn't have storms yet, so we just ignore that. + nukkit.setThundering(hasStorm); } @Override public void setThunderDuration(int duration) { - // Silently unsupported! - // Nukkit doesn't have storms yet, so we just ignore that. + nukkit.setThunderTime(duration); } @Override @@ -1086,4 +1080,13 @@ public boolean unloadChunkRequest(int x, int z, boolean safe) { } + @Override + public Location locateNearestStructure(Location location, StructureType type, int i, boolean b) { + throw Pokkit.unsupported(); + } + + @Override + public boolean isChunkGenerated(int x, int z) { + return nukkit.isChunkGenerated(x, z); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java index 740b151..96985c8 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_99_R9/CraftServer.java @@ -23,10 +23,12 @@ import org.bukkit.BanList.Type; import org.bukkit.GameMode; import org.bukkit.Keyed; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Server; +import org.bukkit.StructureType; import org.bukkit.Tag; import org.bukkit.UnsafeValues; import org.bukkit.Warning.WarningState; @@ -837,4 +839,13 @@ public boolean unloadWorld(World world, boolean save) { return nukkit.unloadLevel(level, true); } + @Override + public ItemStack createExplorerMap(World w, Location l, StructureType t) { + return createExplorerMap(w, l, t); + } + + @Override + public ItemStack createExplorerMap(World w, Location l, StructureType t, int i, boolean b) { + throw Pokkit.unsupported(); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 06a8909..1713ac9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,7 @@ name: ${project.name} main: nl.rutgerkok.pokkit.startup.NukkitHook version: "${project.version}" -api: -- 1.0.0 +api: ["1.0.7"] author: "Rutger Kok, ZINGDING" load: POSTWORLD description: ${project.description} From 7bd4b8872d2c60b3890db56aabf4778f5fce4581 Mon Sep 17 00:00:00 2001 From: RaynLegends Date: Mon, 18 Feb 2019 14:37:02 +0100 Subject: [PATCH 13/14] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8139ab1..1086ab7 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,10 @@ Contributions are very much welcomed. If you have any questions, feel free to se Before you start, please read the [contribution guidelines](./CONTRIBUTING.md). I hope to be able to add your name to the list below soon! -### Contributed code since 2018 +### Contributed code in 2019 +* [PetteriM1](https://github.com/PetteriM1) + +### Contributed code in 2018 * [Jesse Boyd](https://github.com/boy0001) * [Rutger Kok](https://github.com/rutgerkok) From c4000f716ed494131bebbc6437793684a1bdd55f Mon Sep 17 00:00:00 2001 From: Rutger Kok Date: Wed, 21 Aug 2019 14:47:59 +0200 Subject: [PATCH 14/14] Replace README with a link to the fork --- README.md | 70 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 1086ab7..1faf91a 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,5 @@ -# Pokkit [![Build Status](https://travis-ci.org/rutgerkok/Pokkit.svg?branch=master)](https://travis-ci.org/rutgerkok/Pokkit) +# Pokkit -The Minecraft multiplayer scene is fragmented. There are many competing server implementations. A popular server is [Spigot](http://www.spigotmc.org/). Spigot is able to load plugins, which can interact with Minecraft through the Spigot Plugin API. For Minecraft Pocket Edition, the mobile version of Minecraft, a server with a plugin API similar to Spigot exists: [Nukkit](https://nukkitx.com/). Unfortunately, plugins written for Spigot cannot run on Nukkit. +**Inactive. Please see the fork at [PetteriM1/Pokkit](https://github.com/PetteriM1/Pokkit).** -Pokkit is a translation layer that allows plugins written for Spigot to work on Nukkit. However, it is far from perfect. Because of the size of the Spigot API, it is not possible for me to implement all of the Spigot API. - -**Do not expect that Pokkit allows you to run a random Spigot plugin on Nukkit.** Pokkit is still very incomplete, so only a handful of plugins will work. A list of plugins that are confirmed to work or not to work can be found on [Google Docs](https://docs.google.com/spreadsheets/d/1afyyvkdQWyJO6bv1kzofrJxqniqlg28TKqr3YK6ouic/edit?usp=sharing). You are encouraged to edit this list yourself if you have found a Spigot plugin that works or doesn't work. - -My motivation for creating Pokkit was to allow some plugins that I use to work on Nukkit. I am not trying to write a complete implementation of the Spigot API myself. This would be impossible. Keep in mind that Spigot was created over the span of five years by hundreds of different programmers. - -## For Spigot plugin developrs -If you are a Spigot plugin developer looking to port your plugin, Pokkit may be very interesting to you. Instead of maintaining two code bases, or introducing large amounts of abstraction into your codebase, you can simply keep using the Spigot API. - -While testing your plugin, you will most likely come accross an unimplemented method or event. You are encouraged to implement these methods and events, and to submit your changes as a pull request. This will bring us closer to a complete implementation of the Spigot API. - -To get started writing code for Pokkit, I have created a [file with examples](./IMPL_EXAMPLES.md) on how I implemented the methods. - -## Download and usage -Download the latest release [here](https://github.com/rutgerkok/Pokkit/releases). Install Pokkit like you would install any Nukkit plugin: place the JAR file in the `plugins` directory of your Nukkit server. Start your server, then stop it again. You'll notice that a new folder has been created inside the `plugins` directory: a folder called `Pokkit`. Open this folder. Inside the folder, there a three things: - -* A folder called `bukkitPlugins`: place any plugin written for Spigot in this folder. -* A file called `permissions.yml`: this is Bukkit's [permissions.yml file](http://wiki.bukkit.org/Permissions.yml). -* A file called `scoreboard.yml`: scoreboard data is saved here. - -It is important to remember that you must **install Bukkit plugins in the `plugins/Pokkit/bukkitPlugins/` directory**, and not in the `plugins/` directory. - -## Compiling instructions -* Make sure you have installed [Maven](https://maven.apache.org/). -* Download a copy of the source code of Pokkit (use one of the buttons on this page). -* Then run `mvn install` in the directory containing the Pokkit source code. -* A JAR file will be placed in the newly created `target` directory. - -## Bug reports -In general, I will only fix a bug for you if happens to also affect me. Pokkit is a personal project that I uploaded in the hope that it will be useful to others, but I'm not willing to spend the time to create a complete, bug-free implementation of the Spigot API. See my reasoning in the introduction. - -Still, I will leave open all valid bug reports, so that anyone interested in improving Pokkit can have a look. - -## License -License is MIT, except for the files that were derived from the Bukkit project. See the [license](./LICENSE.md) file for details. - -## Pull requests -Contributions are very much welcomed. If you have any questions, feel free to send me an e-mail (address is on my Github profile). - -Before you start, please read the [contribution guidelines](./CONTRIBUTING.md). I hope to be able to add your name to the list below soon! - -### Contributed code in 2019 -* [PetteriM1](https://github.com/PetteriM1) - -### Contributed code in 2018 -* [Jesse Boyd](https://github.com/boy0001) -* [Rutger Kok](https://github.com/rutgerkok) - -### Contributed code in 2017 -* [Ankit](https://github.com/AnkitM252) -* [Langsdorf](https://github.com/Langsdorf) -* [MrPowerGamerBR](https://github.com/MrPowerGamerBR) -* [NycuRO](https://github.com/NycuRO) -* [PikyCZ](https://github.com/PikyCZ) -* [RaynLegends](https://github.com/RaynLegends) -* [Rutger Kok](https://github.com/rutgerkok) -* [SuperAlecs](https://github.com/SuperAlecs) - -### Contributed code in 2016 -* [daveboden](https://github.com/daveboden) -* [Langsdorf](https://github.com/Langsdorf) -* [MrPowerGamerBR](https://github.com/MrPowerGamerBR) -* [OliverUv](https://github.com/OliverUv) -* [Rutger Kok](https://github.com/rutgerkok) -* [ZINGDING](https://github.com/ZINGDING) +[Original README](https://github.com/rutgerkok/Pokkit/blob/7bd4b8872d2c60b3890db56aabf4778f5fce4581/README.md)