From 15bf8e3ecefbc0d074c251c0d2d48b5081fc7cfc Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 13 Mar 2013 22:06:55 +0100 Subject: [PATCH] Move utility methods for altering flags to the BlockFlags utility class. --- .../compat/blocks/BlocksMC1_5.java | 42 ++++++------------- .../nocheatplus/utilities/BlockFlags.java | 40 ++++++++++++++++++ 2 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockFlags.java diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java index 4ff773ce..be69b044 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java @@ -4,6 +4,7 @@ import org.bukkit.Material; import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup; import fr.neatmonster.nocheatplus.config.WorldConfigProvider; +import fr.neatmonster.nocheatplus.utilities.BlockFlags; import fr.neatmonster.nocheatplus.utilities.BlockProperties; /** @@ -33,63 +34,46 @@ public class BlocksMC1_5 implements BlockPropertiesSetup { //////////////////// // 146 Trapped Chest - setFlagsAs(146, Material.CHEST); + BlockFlags.setFlagsAs(146, Material.CHEST); BlockProperties.setBlockProps(146, BlockProperties.getBlockProps(Material.CHEST.getId())); // 147 Weighted Pressure Plate (Light) // 148 Weighted Pressure Plate (Heavy) - addFlags(147, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); - addFlags(148, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(147, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(148, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); // 149 Redstone Comparator (inactive) // 150 Redstone Comparator (active) - addFlags(149, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); - addFlags(150, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(149, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(150, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); // 151 Daylight Sensor - addFlags(151, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(151, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); // 152 Block of Redstone // 153 Nether Quartz Ore // 155 Block of Quartz // 154 Hopper - addFlags(144, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT); + BlockFlags.addFlags(144, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT); // 158 Dropper - setFlagsAs(158, Material.DISPENSER); + BlockFlags.setFlagsAs(158, Material.DISPENSER); // 156 Quartz Stairs - setFlagsAs(156, Material.COBBLESTONE_STAIRS); + BlockFlags.setFlagsAs(156, Material.COBBLESTONE_STAIRS); // 157 Activator Rail - setFlagsAs(157, Material.DETECTOR_RAIL); + BlockFlags.setFlagsAs(157, Material.DETECTOR_RAIL); ///////////////////// // Changed blocks //////////////////// // 78 Snow - addFlags(78, BlockProperties.F_HEIGHT_8_INC); - removeFlags(78, BlockProperties.F_HEIGHT_8SIM_INC); + BlockFlags.addFlags(78, BlockProperties.F_HEIGHT_8_INC); + BlockFlags.removeFlags(78, BlockProperties.F_HEIGHT_8SIM_INC); } - - /** - * Set flags of id same as with material. - * @param id - * @param mat - */ - public static void setFlagsAs(int id, Material mat){ - BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(mat.getId())); - } - - public static void addFlags(int id, long flags){ - BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(id) | flags); - } - - public static void removeFlags(int id, long flags){ - BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(id) & ~flags); - } } diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockFlags.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockFlags.java new file mode 100644 index 00000000..67c18e24 --- /dev/null +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockFlags.java @@ -0,0 +1,40 @@ +package fr.neatmonster.nocheatplus.utilities; + +import org.bukkit.Material; + +/** + * Utilities for block-flags.
+ * Later the flag constant definitions and parsing might be moved here. + * @author mc_dev + * + */ +public class BlockFlags { + + /** + * Set flags of id same as already set with flags for the given material. (Uses BlockProperties.) + * @param id + * @param mat + */ + public static void setFlagsAs(int id, Material mat){ + BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(mat.getId())); + } + + /** + * Add flags to existent flags. (Uses BlockProperties.) + * @param id + * @param flags + */ + public static void addFlags(int id, long flags){ + BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(id) | flags); + } + + /** + * Remove the given flags from existent flags. (Uses BlockProperties.) + * @param id + * @param flags + */ + public static void removeFlags(int id, long flags){ + BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(id) & ~flags); + } + +}