Moved 1.14 Material Checker to own Module.

This commit is contained in:
jameslfc19 2020-07-04 17:39:30 +01:00
parent 85ef414e40
commit 7b57a2da00
6 changed files with 131 additions and 132 deletions

View File

@ -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<Material> version_1_14_Items;
static List<Material> 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<Material> graphically2DList() {
return version_1_14_Items;
}
@Override
protected List<Material> ignoredMaterials() {
return version_1_14_Ignored_Items;
}
};
/**
* API-Specific implementation for materials checks.
@ -99,6 +23,14 @@ public abstract class MaterialChecker {
*/
protected abstract List<Material> 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<Material> getGlassPanes(){
List<Material> 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;
}
}

View File

@ -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<Material> materials;
private List<Material> ignoredMaterials;
static List<Material> version_1_14_Items;
static List<Material> 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<Material> graphically2DList() {
private static List<Material> getGlassPanes(){
List<Material> 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<Material> graphically2DList() {
return version_1_14_Items;
}
@Override
protected List<Material> ignoredMaterials() {
return ignoredMaterials;
return version_1_14_Ignored_Items;
}
}

View File

@ -41,6 +41,12 @@
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_14</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -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<Material> materials;
private List<Material> 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;
}
}

View File

@ -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<Material> materials;
private List<Material> 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());

View File

@ -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; }
}