From 2fcb3dbf13e2cfa23932666c630bb20d3efa3ae3 Mon Sep 17 00:00:00 2001 From: magnu401 Date: Sat, 19 Apr 2014 13:23:12 -0500 Subject: [PATCH 1/3] BlockSapling had a long method d full of duplicate logic and fulfilled the purpose similar to that of a separate class. Our refactoring addressed these issues by creating a separate SaplingHelper class that extracted the duplicate logic from d into a few key methods. We think that this greatly improves readability of d, drastically reduces the method's size, and focuses the method's scope. We ommited a ticket number because this was purely a refactoring exercise for academic purposes, and we do not want it to make it back to bukkit since we altered code in the server part. Also lack of testing makes us question our change's correctness. --- .../net/minecraft/server/BlockSapling.java | 104 +++++--------- .../net/minecraft/server/SaplingHelper.java | 134 ++++++++++++++++++ 2 files changed, 173 insertions(+), 65 deletions(-) create mode 100644 src/main/java/net/minecraft/server/SaplingHelper.java diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index 830eb65dc0..e93f8e3d5b 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -47,32 +47,31 @@ public void grow(World world, int i, int j, int k, Random random, boolean boneme public void d(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) { int l = world.getData(i, j, k) & 7; // CraftBukkit start - Records tree generation and calls StructureGrowEvent - StructureGrowDelegate delegate = new StructureGrowDelegate(world); TreeType treeType = null; - boolean grownTree = false; // Turn ternary operator into if statement to set treeType //Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true); TreeGenerator object; // Changed to TreeGenerator - if (random.nextInt(10) == 0) { - treeType = TreeType.BIG_TREE; - object = new WorldGenBigTree(true); - } else { - treeType = TreeType.TREE; - object = new WorldGenTrees(true); - } + // if (random.nextInt(10) == 0) { + // treeType = TreeType.BIG_TREE; + // object = new WorldGenBigTree(true); + // } else { + // treeType = TreeType.TREE; + // object = new WorldGenTrees(true); + // } // CraftBukkit end int i1 = 0; int j1 = 0; boolean flag = false; - + + SaplingHelper sapling = new SaplingHelper(i,j,k,world,l,player,this);; switch (l) { case 0: default: break; case 1: - treeType = TreeType.REDWOOD; // CraftBukkit - label78: + /** treeType = TreeType.REDWOOD; // CraftBukkit + label78: for (i1 = 0; i1 >= -1; --i1) { for (j1 = 0; j1 >= -1; --j1) { if (this.a(world, i + i1, j, k + j1, 1) && this.a(world, i + i1 + 1, j, k + j1, 1) && this.a(world, i + i1, j, k + j1 + 1, 1) && this.a(world, i + i1 + 1, j, k + j1 + 1, 1)) { @@ -81,23 +80,24 @@ public void d(World world, int i, int j, int k, Random random, boolean bonemeal, break label78; } } - } - - if (!flag) { + } **/ + sapling.calcTree(TreeType.REDWOOD, new WorldGenMegaTree(false, random.nextBoolean())); + /**if (!flag) { j1 = 0; i1 = 0; object = new WorldGenTaiga2(true); - } + } **/ + sapling.notFlag(new WorldGenTaiga2(true)); break; - case 2: - treeType = TreeType.BIRCH; // CraftBukkit - object = new WorldGenForest(true, false); + /*treeType = TreeType.BIRCH; // CraftBukkit + object = new WorldGenForest(true, false);*/ + sapling.setTreeAndGen(new WorldGenForest(true, false), TreeType.BIRCH); break; case 3: - label93: - for (i1 = 0; i1 >= -1; --i1) { + //label93: + /*for (i1 = 0; i1 >= -1; --i1) { for (j1 = 0; j1 >= -1; --j1) { if (this.a(world, i + i1, j, k + j1, 3) && this.a(world, i + i1 + 1, j, k + j1, 3) && this.a(world, i + i1, j, k + j1 + 1, 3) && this.a(world, i + i1 + 1, j, k + j1 + 1, 3)) { treeType = TreeType.JUNGLE; // CraftBukkit @@ -106,23 +106,25 @@ public void d(World world, int i, int j, int k, Random random, boolean bonemeal, break label93; } } - } - - if (!flag) { + }*/ + sapling.calcTree(TreeType.JUNGLE, new WorldGenJungleTree(true, 10, 20, 3, 3)); + /*if (!flag) { j1 = 0; i1 = 0; treeType = TreeType.SMALL_JUNGLE; // CraftBukkit object = new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false); - } + }*/ + sapling.setTreeAndGen(new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false), TreeType.SMALL_JUNGLE); break; case 4: - treeType = TreeType.ACACIA; // CraftBukkit - object = new WorldGenAcaciaTree(true); + /*treeType = TreeType.ACACIA; // CraftBukkit + object = new WorldGenAcaciaTree(true);*/ + sapling.setTreeAndGen(new WorldGenAcaciaTree(true), TreeType.ACACIA); break; case 5: - label108: + /*label108: for (i1 = 0; i1 >= -1; --i1) { for (j1 = 0; j1 >= -1; --j1) { if (this.a(world, i + i1, j, k + j1, 5) && this.a(world, i + i1 + 1, j, k + j1, 5) && this.a(world, i + i1, j, k + j1 + 1, 5) && this.a(world, i + i1 + 1, j, k + j1 + 1, 5)) { @@ -132,14 +134,14 @@ public void d(World world, int i, int j, int k, Random random, boolean bonemeal, break label108; } } - } - - if (!flag) { + }*/ + sapling.calcTree(TreeType.DARK_OAK, new WorldGenForestTree(true)); + if (!sapling.getFlag()) { return; } } - Block block = Blocks.AIR; + /*Block block = Blocks.AIR; if (flag) { world.setTypeAndData(i + i1, j, k + j1, block, 0, 4); @@ -148,41 +150,13 @@ public void d(World world, int i, int j, int k, Random random, boolean bonemeal, world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, block, 0, 4); } else { world.setTypeAndData(i, j, k, block, 0, 4); - } + }*/ // CraftBukkit start - grownTree = object.generate(new CraftBlockChangeDelegate(delegate), random, i + i1, j, k + j1); - if (grownTree) { - Location location = new Location(world.getWorld(), i, j, k); - StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks()); - org.bukkit.Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - grownTree = false; - } else { - for (org.bukkit.block.BlockState state : event.getBlocks()) { - state.update(true); - } - if (event.isFromBonemeal() && itemstack != null) { - --itemstack.count; - } - } - } else if (bonemeal && itemstack != null) { - // We always consume bonemeal when trying to grow - --itemstack.count; - } - // No need to generate the tree again. - if (!grownTree) { - // CraftBukkit end - if (flag) { - world.setTypeAndData(i + i1, j, k + j1, this, l, 4); - world.setTypeAndData(i + i1 + 1, j, k + j1, this, l, 4); - world.setTypeAndData(i + i1, j, k + j1 + 1, this, l, 4); - world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, this, l, 4); - } else { - world.setTypeAndData(i, j, k, this, l, 4); - } - } - } + + sapling.worldSetter(); + sapling.growTree(itemstack); + } public boolean a(World world, int i, int j, int k, int l) { return world.getType(i, j, k) == this && (world.getData(i, j, k) & 7) == l; diff --git a/src/main/java/net/minecraft/server/SaplingHelper.java b/src/main/java/net/minecraft/server/SaplingHelper.java new file mode 100644 index 0000000000..e812740f39 --- /dev/null +++ b/src/main/java/net/minecraft/server/SaplingHelper.java @@ -0,0 +1,134 @@ +package net.minecraft.server; + +import net.minecraft.server.BlockSapling.TreeGenerator; + +import org.bukkit.Location; +import org.bukkit.TreeType; +import org.bukkit.craftbukkit.CraftBlockChangeDelegate; +import org.bukkit.craftbukkit.util.StructureGrowDelegate; +import org.bukkit.entity.Player; +import org.bukkit.event.world.StructureGrowEvent; + +import java.util.Random; + +public class SaplingHelper { + + private int i; + private int i1 = 0; + private int j; + private int j1 = 0; + private int k; + private World world; + private int type; + private TreeType treeType; + private boolean bonemeal; + private Player player; + private TreeGenerator object; + private boolean flag = false; + private BlockSapling sapling; + + public SaplingHelper(int tempI, int tempJ, int tempK, World tempWorld, int tempType, Player tempPlayer, BlockSapling tempSapling){ + i = tempI; + j = tempJ; + k = tempK; + sapling = tempSapling; + world = tempWorld; + type = tempType; + player = tempPlayer; + Random random = new Random(); + if (random.nextInt(10) == 0) { + treeType = TreeType.BIG_TREE; + object = new WorldGenBigTree(true); + } else { + treeType = TreeType.TREE; + object = new WorldGenTrees(true); + } + } + + public void calcTree(TreeType tempType, TreeGenerator tempGenerator){ + treeType = tempType; // CraftBukkit + label78: + for (i1 = 0; i1 >= -1; --i1) { + for (j1 = 0; j1 >= -1; --j1) { + if (sapling.a(world, i + i1, j, k + j1, type) + && sapling.a(world, i + i1 + 1, j, k + j1, type) + && sapling.a(world, i + i1, j, k + j1 + 1, type) + && sapling.a(world, i + i1 + 1, j, k + j1 + 1, type)) { + object = tempGenerator; + flag = true; + break label78; + } + } + } + } + + public void notFlag(TreeGenerator tempGenerator){ + if(!flag){ + j1 = 0; + i1 = 0; + object = tempGenerator; + } + } + + public void setTreeAndGen(TreeGenerator tempGenerator, TreeType tempType){ + if(!flag){ + object = tempGenerator; + treeType = tempType; + j1 = 0; + i1 = 0; + } + } + + public boolean getFlag(){ + return flag; + } + + public void worldSetter(){ + Block block = Blocks.AIR; + if (flag) { + world.setTypeAndData(i + i1, j, k + j1, block, 0, 4); + world.setTypeAndData(i + i1 + 1, j, k + j1, block, 0, 4); + world.setTypeAndData(i + i1, j, k + j1 + 1, block, 0, 4); + world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, block, 0, 4); + } else { + world.setTypeAndData(i, j, k, block, 0, 4); + } + } + + public void growTree(ItemStack itemstack) { + Random random = new Random(); + StructureGrowDelegate delegate = new StructureGrowDelegate(world); + boolean grownTree; + grownTree = object.generate(new CraftBlockChangeDelegate(delegate), random, i + i1, j, k + j1); + if (grownTree) { + Location location = new Location(world.getWorld(), i, j, k); + StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks()); + org.bukkit.Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + grownTree = false; + } else { + for (org.bukkit.block.BlockState state : event.getBlocks()) { + state.update(true); + } + if (event.isFromBonemeal() && itemstack != null) { + --itemstack.count; + } + } + } else if (bonemeal && itemstack != null) { + // We always consume bonemeal when trying to grow + --itemstack.count; + } + // No need to generate the tree again. + if (!grownTree) { + // CraftBukkit end + if (flag) { + world.setTypeAndData(i + i1, j, k + j1, sapling, type, 4); + world.setTypeAndData(i + i1 + 1, j, k + j1, sapling, type, 4); + world.setTypeAndData(i + i1, j, k + j1 + 1, sapling, type, 4); + world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, sapling, type, 4); + } else { + world.setTypeAndData(i, j, k, sapling, type, 4); + } + } + } +} From 44070b7dfcc7007a9f7e9cd296bcdbdb87b7867c Mon Sep 17 00:00:00 2001 From: magnu401 Date: Thu, 24 Apr 2014 11:06:58 -0500 Subject: [PATCH 2/3] Changed Sapling Helper to SproutSapling. Also we removed commented code and unused variables. --- .../net/minecraft/server/BlockSapling.java | 78 +------------------ ...{SaplingHelper.java => SproutSapling.java} | 4 +- 2 files changed, 4 insertions(+), 78 deletions(-) rename src/main/java/net/minecraft/server/{SaplingHelper.java => SproutSapling.java} (97%) diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index e93f8e3d5b..b3890ef09c 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -47,113 +47,39 @@ public void grow(World world, int i, int j, int k, Random random, boolean boneme public void d(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) { int l = world.getData(i, j, k) & 7; // CraftBukkit start - Records tree generation and calls StructureGrowEvent - TreeType treeType = null; - // Turn ternary operator into if statement to set treeType - //Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true); - TreeGenerator object; // Changed to TreeGenerator - // if (random.nextInt(10) == 0) { - // treeType = TreeType.BIG_TREE; - // object = new WorldGenBigTree(true); - // } else { - // treeType = TreeType.TREE; - // object = new WorldGenTrees(true); - // } // CraftBukkit end - int i1 = 0; - int j1 = 0; - boolean flag = false; - SaplingHelper sapling = new SaplingHelper(i,j,k,world,l,player,this);; + SproutSapling sapling = new SproutSapling(i,j,k,world,l,player,this);; switch (l) { case 0: default: break; case 1: - /** treeType = TreeType.REDWOOD; // CraftBukkit - label78: - for (i1 = 0; i1 >= -1; --i1) { - for (j1 = 0; j1 >= -1; --j1) { - if (this.a(world, i + i1, j, k + j1, 1) && this.a(world, i + i1 + 1, j, k + j1, 1) && this.a(world, i + i1, j, k + j1 + 1, 1) && this.a(world, i + i1 + 1, j, k + j1 + 1, 1)) { - object = new WorldGenMegaTree(false, random.nextBoolean()); - flag = true; - break label78; - } - } - } **/ sapling.calcTree(TreeType.REDWOOD, new WorldGenMegaTree(false, random.nextBoolean())); - /**if (!flag) { - j1 = 0; - i1 = 0; - object = new WorldGenTaiga2(true); - } **/ sapling.notFlag(new WorldGenTaiga2(true)); break; case 2: - /*treeType = TreeType.BIRCH; // CraftBukkit - object = new WorldGenForest(true, false);*/ + // CraftBukkit sapling.setTreeAndGen(new WorldGenForest(true, false), TreeType.BIRCH); break; case 3: - //label93: - /*for (i1 = 0; i1 >= -1; --i1) { - for (j1 = 0; j1 >= -1; --j1) { - if (this.a(world, i + i1, j, k + j1, 3) && this.a(world, i + i1 + 1, j, k + j1, 3) && this.a(world, i + i1, j, k + j1 + 1, 3) && this.a(world, i + i1 + 1, j, k + j1 + 1, 3)) { - treeType = TreeType.JUNGLE; // CraftBukkit - object = new WorldGenJungleTree(true, 10, 20, 3, 3); - flag = true; - break label93; - } - } - }*/ sapling.calcTree(TreeType.JUNGLE, new WorldGenJungleTree(true, 10, 20, 3, 3)); - /*if (!flag) { - j1 = 0; - i1 = 0; - treeType = TreeType.SMALL_JUNGLE; // CraftBukkit - object = new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false); - }*/ sapling.setTreeAndGen(new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false), TreeType.SMALL_JUNGLE); break; case 4: - /*treeType = TreeType.ACACIA; // CraftBukkit - object = new WorldGenAcaciaTree(true);*/ sapling.setTreeAndGen(new WorldGenAcaciaTree(true), TreeType.ACACIA); break; case 5: - /*label108: - for (i1 = 0; i1 >= -1; --i1) { - for (j1 = 0; j1 >= -1; --j1) { - if (this.a(world, i + i1, j, k + j1, 5) && this.a(world, i + i1 + 1, j, k + j1, 5) && this.a(world, i + i1, j, k + j1 + 1, 5) && this.a(world, i + i1 + 1, j, k + j1 + 1, 5)) { - object = new WorldGenForestTree(true); - treeType = TreeType.DARK_OAK; // CraftBukkit - flag = true; - break label108; - } - } - }*/ sapling.calcTree(TreeType.DARK_OAK, new WorldGenForestTree(true)); if (!sapling.getFlag()) { return; } } - - /*Block block = Blocks.AIR; - - if (flag) { - world.setTypeAndData(i + i1, j, k + j1, block, 0, 4); - world.setTypeAndData(i + i1 + 1, j, k + j1, block, 0, 4); - world.setTypeAndData(i + i1, j, k + j1 + 1, block, 0, 4); - world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, block, 0, 4); - } else { - world.setTypeAndData(i, j, k, block, 0, 4); - }*/ - // CraftBukkit start - sapling.worldSetter(); sapling.growTree(itemstack); } diff --git a/src/main/java/net/minecraft/server/SaplingHelper.java b/src/main/java/net/minecraft/server/SproutSapling.java similarity index 97% rename from src/main/java/net/minecraft/server/SaplingHelper.java rename to src/main/java/net/minecraft/server/SproutSapling.java index e812740f39..3d14a3e568 100644 --- a/src/main/java/net/minecraft/server/SaplingHelper.java +++ b/src/main/java/net/minecraft/server/SproutSapling.java @@ -11,7 +11,7 @@ import java.util.Random; -public class SaplingHelper { +public class SproutSapling { private int i; private int i1 = 0; @@ -27,7 +27,7 @@ public class SaplingHelper { private boolean flag = false; private BlockSapling sapling; - public SaplingHelper(int tempI, int tempJ, int tempK, World tempWorld, int tempType, Player tempPlayer, BlockSapling tempSapling){ + public SproutSapling(int tempI, int tempJ, int tempK, World tempWorld, int tempType, Player tempPlayer, BlockSapling tempSapling){ i = tempI; j = tempJ; k = tempK; From c7c28891f357b654cc077f79ff7d9afb3ca63ef7 Mon Sep 17 00:00:00 2001 From: magnu401 Date: Wed, 30 Apr 2014 14:29:23 -0500 Subject: [PATCH 3/3] Refactors CraftEnchantment- This commit addresses the switch statements in the CraftEnchantment class. Previously CraftEnchantment had two very bulky switch statements. This process is inefficient and takes up more space than other solutions to the same problem. This commit addresses this issue by replacing the switch statements with hashmaps thus reducing the size of CraftEnchantment and improving the logic flow. --- .../enchantments/CraftEnchantment.java | 130 ++++++++---------- 1 file changed, 54 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java index 18a6e3897a..8124156f6b 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -1,5 +1,9 @@ package org.bukkit.craftbukkit.enchantments; +import java.util.HashMap; + +import net.minecraft.server.EnchantmentSlotType; + import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; @@ -8,6 +12,49 @@ public class CraftEnchantment extends Enchantment { private final net.minecraft.server.Enchantment target; + private static final HashMap slotTarget = + new HashMap(); + static + { + slotTarget.put("ALL", EnchantmentTarget.ALL); + slotTarget.put("ARMOR", EnchantmentTarget.ARMOR); + slotTarget.put("ARMOR_FEET", EnchantmentTarget.ARMOR_FEET); + slotTarget.put("ARMOR_HEAD", EnchantmentTarget.ARMOR_HEAD); + slotTarget.put("ARMOR_LEGS", EnchantmentTarget.ARMOR_LEGS); + slotTarget.put("ARMOR_TORSO", EnchantmentTarget.ARMOR_TORSO); + slotTarget.put("DIGGER", EnchantmentTarget.TOOL); + slotTarget.put("WEAPON", EnchantmentTarget.WEAPON); + slotTarget.put("BOW", EnchantmentTarget.BOW); + slotTarget.put("FISHING_ROD", EnchantmentTarget.FISHING_ROD); + } + private static final HashMap nameMap = new HashMap(); + static + { + nameMap.put(0, "PROTECTION_ENVIRONMENTAL"); + nameMap.put(1, "PROTECTION_FIRE"); + nameMap.put(2, "PROTECTION_FALL"); + nameMap.put(3, "PROTECTION_EXPLOSIONS"); + nameMap.put(4, "PROTECTION_PROJECTILE"); + nameMap.put(5, "OXYGEN"); + nameMap.put(6, "WATER_WORKER"); + nameMap.put(7, "THORNS"); + nameMap.put(16, "DAMAGE_ALL"); + nameMap.put(17, "DAMAGE_UNDEAD"); + nameMap.put(18, "DAMAGE_ARTHROPODS"); + nameMap.put(19, "KNOCKBACK"); + nameMap.put(20, "FIRE_ASPECT"); + nameMap.put(21, "LOOT_BONUS_MOBS"); + nameMap.put(32, "DIG_SPEED"); + nameMap.put(33, "SILK_TOUCH"); + nameMap.put(34, "DURABILITY"); + nameMap.put(35, "LOOT_BONUS_BLOCKS"); + nameMap.put(48, "ARROW_DAMAGE"); + nameMap.put(49, "ARROW_KNOCKBACK"); + nameMap.put(50, "ARROW_FIRE"); + nameMap.put(51, "ARROW_INFINITE"); + nameMap.put(61, "LUCK"); + nameMap.put(62, "LURE"); + } public CraftEnchantment(net.minecraft.server.Enchantment target) { super(target.id); @@ -26,30 +73,8 @@ public int getStartLevel() { @Override public EnchantmentTarget getItemTarget() { - switch (target.slot) { - case ALL: - return EnchantmentTarget.ALL; - case ARMOR: - return EnchantmentTarget.ARMOR; - case ARMOR_FEET: - return EnchantmentTarget.ARMOR_FEET; - case ARMOR_HEAD: - return EnchantmentTarget.ARMOR_HEAD; - case ARMOR_LEGS: - return EnchantmentTarget.ARMOR_LEGS; - case ARMOR_TORSO: - return EnchantmentTarget.ARMOR_TORSO; - case DIGGER: - return EnchantmentTarget.TOOL; - case WEAPON: - return EnchantmentTarget.WEAPON; - case BOW: - return EnchantmentTarget.BOW; - case FISHING_ROD: - return EnchantmentTarget.FISHING_ROD; - default: - return null; - } + return slotTarget.get(target.slot.toString()); + } @Override @@ -59,58 +84,11 @@ public boolean canEnchantItem(ItemStack item) { @Override public String getName() { - switch (target.id) { - case 0: - return "PROTECTION_ENVIRONMENTAL"; - case 1: - return "PROTECTION_FIRE"; - case 2: - return "PROTECTION_FALL"; - case 3: - return "PROTECTION_EXPLOSIONS"; - case 4: - return "PROTECTION_PROJECTILE"; - case 5: - return "OXYGEN"; - case 6: - return "WATER_WORKER"; - case 7: - return "THORNS"; - case 16: - return "DAMAGE_ALL"; - case 17: - return "DAMAGE_UNDEAD"; - case 18: - return "DAMAGE_ARTHROPODS"; - case 19: - return "KNOCKBACK"; - case 20: - return "FIRE_ASPECT"; - case 21: - return "LOOT_BONUS_MOBS"; - case 32: - return "DIG_SPEED"; - case 33: - return "SILK_TOUCH"; - case 34: - return "DURABILITY"; - case 35: - return "LOOT_BONUS_BLOCKS"; - case 48: - return "ARROW_DAMAGE"; - case 49: - return "ARROW_KNOCKBACK"; - case 50: - return "ARROW_FIRE"; - case 51: - return "ARROW_INFINITE"; - case 61: - return "LUCK"; - case 62: - return "LURE"; - default: - return "UNKNOWN_ENCHANT_" + target.id; - } + if(nameMap.get(target.id)==null){ + return "UNKNOWN_ENCHANT_" + target.id; + } else { + return nameMap.get(target.id); + } } public static net.minecraft.server.Enchantment getRaw(Enchantment enchantment) {