From 7b57a2da00b355dd8bb19ac46c65ce219d34ee88 Mon Sep 17 00:00:00 2001 From: jameslfc19 Date: Sat, 4 Jul 2020 17:39:30 +0100 Subject: [PATCH] Moved 1.14 Material Checker to own Module. --- .../minecraft/chests/MaterialChecker.java | 122 ++---------------- .../chests/MaterialChecker_1_14.java | 108 ++++++++++++++-- ChestsPlusPlus_1_15/pom.xml | 6 + .../chests/MaterialChecker_1_15.java | 15 ++- .../chests/MaterialChecker_1_16.java | 5 +- .../chests/api_interfaces/ApiSpecific.java | 7 +- 6 files changed, 131 insertions(+), 132 deletions(-) diff --git a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java index 7402d72..8dddcd5 100644 --- a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java +++ b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java @@ -1,88 +1,12 @@ package com.jamesdpeters.minecraft.chests; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.Tag; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; import java.util.List; public abstract class MaterialChecker { - static List version_1_14_Items; - static List version_1_14_Ignored_Items; - - static { - version_1_14_Items = new ArrayList<>(); - version_1_14_Items.addAll(Tag.SIGNS.getValues()); - version_1_14_Items.addAll(Tag.WALL_SIGNS.getValues()); - version_1_14_Items.addAll(Tag.DOORS.getValues()); - version_1_14_Items.addAll(Tag.SAPLINGS.getValues()); - version_1_14_Items.addAll(Tag.SMALL_FLOWERS.getValues()); - version_1_14_Items.addAll(Tag.RAILS.getValues()); - version_1_14_Items.addAll(Tag.CORAL_PLANTS.getValues()); - version_1_14_Items.addAll(getGlassPanes()); - version_1_14_Items.add(Material.BROWN_MUSHROOM); - version_1_14_Items.add(Material.RED_MUSHROOM); - version_1_14_Items.add(Material.END_ROD); - version_1_14_Items.add(Material.COBWEB); - version_1_14_Items.add(Material.GRASS); - version_1_14_Items.add(Material.FERN); - version_1_14_Items.add(Material.DEAD_BUSH); - version_1_14_Items.add(Material.SEAGRASS); - version_1_14_Items.add(Material.SEA_PICKLE); - version_1_14_Items.add(Material.LADDER); - version_1_14_Items.add(Material.IRON_BARS); - version_1_14_Items.add(Material.VINE); - version_1_14_Items.add(Material.LILY_PAD); - version_1_14_Items.add(Material.SUNFLOWER); - version_1_14_Items.add(Material.LILAC); - version_1_14_Items.add(Material.ROSE_BUSH); - version_1_14_Items.add(Material.PEONY); - version_1_14_Items.add(Material.TALL_GRASS); - version_1_14_Items.add(Material.LARGE_FERN); - version_1_14_Items.add(Material.BELL); - version_1_14_Items.add(Material.CAMPFIRE); - version_1_14_Items.add(Material.LANTERN); - version_1_14_Items.add(Material.TURTLE_EGG); - version_1_14_Items.add(Material.SUGAR_CANE); - version_1_14_Items.add(Material.KELP); - version_1_14_Items.add(Material.BAMBOO); - version_1_14_Items.add(Material.LEVER); - version_1_14_Items.add(Material.TRIPWIRE_HOOK); - version_1_14_Items.add(Material.REPEATER); - version_1_14_Items.add(Material.COMPARATOR); - version_1_14_Items.add(Material.CAULDRON); - version_1_14_Items.add(Material.BREWING_STAND); - version_1_14_Items.add(Material.HOPPER); - - version_1_14_Ignored_Items = new ArrayList<>(); - version_1_14_Ignored_Items.addAll(Tag.BEDS.getValues()); - version_1_14_Ignored_Items.addAll(Tag.BANNERS.getValues()); - version_1_14_Ignored_Items.add(Material.DRAGON_HEAD); - version_1_14_Ignored_Items.add(Material.PLAYER_HEAD); - version_1_14_Ignored_Items.add(Material.ZOMBIE_HEAD); - version_1_14_Ignored_Items.add(Material.SKELETON_SKULL); - version_1_14_Ignored_Items.add(Material.CREEPER_HEAD); - version_1_14_Ignored_Items.add(Material.SHIELD); - version_1_14_Ignored_Items.add(Material.CROSSBOW); - version_1_14_Ignored_Items.add(Material.TRIDENT); - - } - - public static MaterialChecker Version_1_14 = new MaterialChecker() { - @Override - protected List graphically2DList() { - return version_1_14_Items; - } - - @Override - protected List ignoredMaterials() { - return version_1_14_Ignored_Items; - } - }; /** * API-Specific implementation for materials checks. @@ -99,6 +23,14 @@ public abstract class MaterialChecker { */ protected abstract List ignoredMaterials(); + /** + * This returns true if an item is held like a pickaxe/sword etc. + * Also for items like sticks an fishing rods. + * @param itemStack + * @return + */ + public abstract boolean isTool(ItemStack itemStack); + /** * Used to test if an item is graphically 2D (e.g a sign is a block but is held like an item.) * @param itemStack @@ -118,43 +50,7 @@ public abstract class MaterialChecker { return ignoredMaterials().contains(itemStack.getType()); } - private static List getGlassPanes(){ - List materials = new ArrayList<>(); - materials.add(Material.GLASS_PANE); - materials.add(Material.BLACK_STAINED_GLASS_PANE); - materials.add(Material.BLUE_STAINED_GLASS_PANE); - materials.add(Material.BROWN_STAINED_GLASS_PANE); - materials.add(Material.CYAN_STAINED_GLASS_PANE); - materials.add(Material.GRAY_STAINED_GLASS_PANE); - materials.add(Material.GREEN_STAINED_GLASS_PANE); - materials.add(Material.LIME_STAINED_GLASS_PANE); - materials.add(Material.MAGENTA_STAINED_GLASS_PANE); - materials.add(Material.ORANGE_STAINED_GLASS_PANE); - materials.add(Material.PINK_STAINED_GLASS_PANE); - materials.add(Material.PURPLE_STAINED_GLASS_PANE); - materials.add(Material.RED_STAINED_GLASS_PANE); - materials.add(Material.WHITE_STAINED_GLASS_PANE); - materials.add(Material.YELLOW_STAINED_GLASS_PANE); - materials.add(Material.LIGHT_BLUE_STAINED_GLASS_PANE); - materials.add(Material.LIGHT_GRAY_STAINED_GLASS_PANE); - return materials; - } - /** - * This returns true if an item is held like a pickaxe/sword etc. - * @param itemStack - * @return - */ - public boolean isTool(ItemStack itemStack){ - String matType = itemStack.getType().toString(); - if(matType.contains("AXE")) return true; - if(matType.contains("SWORD")) return true; - if(matType.contains("PICKAXE")) return true; - if(matType.contains("HOE")) return true; - if(matType.contains("SHOVEL")) return true; - if(itemStack.getType() == Material.FISHING_ROD) return true; - if(itemStack.getType() == Material.CARROT_ON_A_STICK) return true; - return false; - } + } diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java index 09c6b52..4241d11 100644 --- a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java @@ -1,34 +1,118 @@ package com.jamesdpeters.minecraft.chests; - -import net.minecraft.server.v1_14_R1.TileEntityChest; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_14_R1.block.CraftChest; +import org.bukkit.Tag; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; public class MaterialChecker_1_14 extends MaterialChecker { - private List materials; - private List ignoredMaterials; + static List version_1_14_Items; + static List version_1_14_Ignored_Items; public MaterialChecker_1_14(){ - materials = new ArrayList<>(); - materials.addAll(version_1_14_Items); + version_1_14_Items = new ArrayList<>(); + version_1_14_Items.addAll(Tag.SIGNS.getValues()); + version_1_14_Items.addAll(Tag.WALL_SIGNS.getValues()); + version_1_14_Items.addAll(Tag.DOORS.getValues()); + version_1_14_Items.addAll(Tag.SAPLINGS.getValues()); + version_1_14_Items.addAll(Tag.SMALL_FLOWERS.getValues()); + version_1_14_Items.addAll(Tag.RAILS.getValues()); + version_1_14_Items.addAll(Tag.CORAL_PLANTS.getValues()); + version_1_14_Items.addAll(getGlassPanes()); + version_1_14_Items.add(Material.BROWN_MUSHROOM); + version_1_14_Items.add(Material.RED_MUSHROOM); + version_1_14_Items.add(Material.END_ROD); + version_1_14_Items.add(Material.COBWEB); + version_1_14_Items.add(Material.GRASS); + version_1_14_Items.add(Material.FERN); + version_1_14_Items.add(Material.DEAD_BUSH); + version_1_14_Items.add(Material.SEAGRASS); + version_1_14_Items.add(Material.SEA_PICKLE); + version_1_14_Items.add(Material.LADDER); + version_1_14_Items.add(Material.IRON_BARS); + version_1_14_Items.add(Material.VINE); + version_1_14_Items.add(Material.LILY_PAD); + version_1_14_Items.add(Material.SUNFLOWER); + version_1_14_Items.add(Material.LILAC); + version_1_14_Items.add(Material.ROSE_BUSH); + version_1_14_Items.add(Material.PEONY); + version_1_14_Items.add(Material.TALL_GRASS); + version_1_14_Items.add(Material.LARGE_FERN); + version_1_14_Items.add(Material.BELL); + version_1_14_Items.add(Material.CAMPFIRE); + version_1_14_Items.add(Material.LANTERN); + version_1_14_Items.add(Material.TURTLE_EGG); + version_1_14_Items.add(Material.SUGAR_CANE); + version_1_14_Items.add(Material.KELP); + version_1_14_Items.add(Material.BAMBOO); + version_1_14_Items.add(Material.LEVER); + version_1_14_Items.add(Material.TRIPWIRE_HOOK); + version_1_14_Items.add(Material.REPEATER); + version_1_14_Items.add(Material.COMPARATOR); + version_1_14_Items.add(Material.CAULDRON); + version_1_14_Items.add(Material.BREWING_STAND); + version_1_14_Items.add(Material.HOPPER); - ignoredMaterials = new ArrayList<>(); - ignoredMaterials.addAll(version_1_14_Ignored_Items); + version_1_14_Ignored_Items = new ArrayList<>(); + version_1_14_Ignored_Items.addAll(Tag.BEDS.getValues()); + version_1_14_Ignored_Items.addAll(Tag.BANNERS.getValues()); + version_1_14_Ignored_Items.add(Material.DRAGON_HEAD); + version_1_14_Ignored_Items.add(Material.PLAYER_HEAD); + version_1_14_Ignored_Items.add(Material.ZOMBIE_HEAD); + version_1_14_Ignored_Items.add(Material.SKELETON_SKULL); + version_1_14_Ignored_Items.add(Material.CREEPER_HEAD); + version_1_14_Ignored_Items.add(Material.SHIELD); + version_1_14_Ignored_Items.add(Material.CROSSBOW); + version_1_14_Ignored_Items.add(Material.TRIDENT); } - @Override - protected List graphically2DList() { + private static List getGlassPanes(){ + List materials = new ArrayList<>(); + materials.add(Material.GLASS_PANE); + materials.add(Material.BLACK_STAINED_GLASS_PANE); + materials.add(Material.BLUE_STAINED_GLASS_PANE); + materials.add(Material.BROWN_STAINED_GLASS_PANE); + materials.add(Material.CYAN_STAINED_GLASS_PANE); + materials.add(Material.GRAY_STAINED_GLASS_PANE); + materials.add(Material.GREEN_STAINED_GLASS_PANE); + materials.add(Material.LIME_STAINED_GLASS_PANE); + materials.add(Material.MAGENTA_STAINED_GLASS_PANE); + materials.add(Material.ORANGE_STAINED_GLASS_PANE); + materials.add(Material.PINK_STAINED_GLASS_PANE); + materials.add(Material.PURPLE_STAINED_GLASS_PANE); + materials.add(Material.RED_STAINED_GLASS_PANE); + materials.add(Material.WHITE_STAINED_GLASS_PANE); + materials.add(Material.YELLOW_STAINED_GLASS_PANE); + materials.add(Material.LIGHT_BLUE_STAINED_GLASS_PANE); + materials.add(Material.LIGHT_GRAY_STAINED_GLASS_PANE); return materials; } + @Override + public boolean isTool(ItemStack itemStack){ + String matType = itemStack.getType().toString(); + if(matType.contains("AXE")) return true; + if(matType.contains("SWORD")) return true; + if(matType.contains("PICKAXE")) return true; + if(matType.contains("HOE")) return true; + if(matType.contains("SHOVEL")) return true; + if(itemStack.getType() == Material.FISHING_ROD) return true; + if(itemStack.getType() == Material.CARROT_ON_A_STICK) return true; + if(itemStack.getType() == Material.STICK) return true; + return false; + } + + @Override + protected List graphically2DList() { + return version_1_14_Items; + } + @Override protected List ignoredMaterials() { - return ignoredMaterials; + return version_1_14_Ignored_Items; } } diff --git a/ChestsPlusPlus_1_15/pom.xml b/ChestsPlusPlus_1_15/pom.xml index 79aa4ac..935e09d 100644 --- a/ChestsPlusPlus_1_15/pom.xml +++ b/ChestsPlusPlus_1_15/pom.xml @@ -41,6 +41,12 @@ 1.15.2-R0.1-SNAPSHOT provided + + com.jamesdpeters.minecraft.chests + ChestsPlusPlus_1_14 + 1.0-SNAPSHOT + compile + diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java index 02bad6c..8d75812 100644 --- a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java @@ -3,6 +3,7 @@ package com.jamesdpeters.minecraft.chests; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; @@ -11,13 +12,16 @@ public class MaterialChecker_1_15 extends MaterialChecker { private List materials; private List ignoredMaterials; + private MaterialChecker materialChecker1_14; public MaterialChecker_1_15(){ + //Must add previous version values first! + materialChecker1_14 = new MaterialChecker_1_14(); materials = new ArrayList<>(); - materials.addAll(version_1_14_Items); + materials.addAll(materialChecker1_14.graphically2DList()); ignoredMaterials = new ArrayList<>(); - ignoredMaterials.addAll(version_1_14_Ignored_Items); + ignoredMaterials.addAll(materialChecker1_14.ignoredMaterials()); } @Override @@ -30,4 +34,11 @@ public class MaterialChecker_1_15 extends MaterialChecker { return ignoredMaterials; } + @Override + public boolean isTool(ItemStack itemStack) { + //Check previous version first. + if(materialChecker1_14.isTool(itemStack)) return true; + return false; + } + } diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java index a3c4e30..cab7659 100644 --- a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java @@ -1,22 +1,21 @@ package com.jamesdpeters.minecraft.chests; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class MaterialChecker_1_16 extends MaterialChecker { private List materials; private List ignoredMaterials; - MaterialChecker_1_15 version1_15; + private MaterialChecker_1_15 version1_15; public MaterialChecker_1_16(){ version1_15 = new MaterialChecker_1_15(); + materials = new ArrayList<>(); materials.addAll(version1_15.graphically2DList()); materials.addAll(Tag.CROPS.getValues()); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java index af28d48..a942de7 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java @@ -6,6 +6,7 @@ import com.jamesdpeters.minecraft.chests.ChestOpener_1_15; import com.jamesdpeters.minecraft.chests.ChestOpener_1_16; import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.MaterialChecker_1_14; import com.jamesdpeters.minecraft.chests.MaterialChecker_1_15; import com.jamesdpeters.minecraft.chests.MaterialChecker_1_16; import org.bukkit.Bukkit; @@ -48,9 +49,10 @@ public class ApiSpecific { private static MaterialChecker getMaterialChecker(Version version){ switch (version){ - case API_1_16: return new MaterialChecker_1_16(); + //Return latest version as default since only builds newer won't be present here. + default: return new MaterialChecker_1_16(); case API_1_15: return new MaterialChecker_1_15(); - default: return MaterialChecker.Version_1_14; + case API_1_14: return new MaterialChecker_1_14(); } } @@ -71,4 +73,5 @@ public class ApiSpecific { public static ChestOpener getChestOpener() { return chestOpener; } + public static Version getApiVersion(){ return version; } }