Merge branch 'development'

This commit is contained in:
Brianna 2020-01-19 18:08:15 -05:00
commit 7b8a808827
2 changed files with 36 additions and 31 deletions

View File

@ -4,7 +4,7 @@ stages:
variables: variables:
name: "SongodaCore" name: "SongodaCore"
path: "/builds/$CI_PROJECT_PATH" path: "/builds/$CI_PROJECT_PATH"
version: "2.3.2" version: "2.3.3"
build: build:
stage: build stage: build

View File

@ -1,22 +1,19 @@
package com.songoda.core.utils; package com.songoda.core.utils;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion; import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.CropState;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.material.Crops;
public class BlockUtils { public class BlockUtils {
@ -69,10 +66,10 @@ public class BlockUtils {
if (isOpenable(bType)) { if (isOpenable(bType)) {
toggleDoorStates(true, b); toggleDoorStates(true, b);
return true; return true;
} else if(bType == Material.LEVER) { } else if (bType == Material.LEVER) {
toggleLever(b); toggleLever(b);
return true; return true;
} else if(bType.name().endsWith("_BUTTON")) { } else if (bType.name().endsWith("_BUTTON")) {
pressButton(b); pressButton(b);
return true; return true;
} }
@ -82,6 +79,7 @@ public class BlockUtils {
/** /**
* Change a pressure plate's redstone state * Change a pressure plate's redstone state
*
* @param plate plate to update * @param plate plate to update
* @param power power to set to 0-15 (wood plates are active if greater than 0) * @param power power to set to 0-15 (wood plates are active if greater than 0)
*/ */
@ -105,7 +103,7 @@ public class BlockUtils {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
} }
} }
public static void pressButton(Block button) { public static void pressButton(Block button) {
if (useLegacy && legacySetBlockData != null) { if (useLegacy && legacySetBlockData != null) {
_pressButtonLegacy(button); _pressButtonLegacy(button);
@ -113,7 +111,7 @@ public class BlockUtils {
BlockUtilsModern._pressButtonModern(button); BlockUtilsModern._pressButtonModern(button);
} }
} }
public static void releaseButton(Block button) { public static void releaseButton(Block button) {
if (useLegacy && legacySetBlockData != null) { if (useLegacy && legacySetBlockData != null) {
_releaseButtonLegacy(button); _releaseButtonLegacy(button);
@ -124,7 +122,7 @@ public class BlockUtils {
private static void _pressButtonLegacy(Block button) { private static void _pressButtonLegacy(Block button) {
final Material m = button.getType(); final Material m = button.getType();
if(!m.name().endsWith("_BUTTON")) return; if (!m.name().endsWith("_BUTTON")) return;
try { try {
legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8))); legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8)));
button.getState().update(); button.getState().update();
@ -132,10 +130,10 @@ public class BlockUtils {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
} }
} }
private static void _releaseButtonLegacy(Block button) { private static void _releaseButtonLegacy(Block button) {
final Material m = button.getType(); final Material m = button.getType();
if(!m.name().endsWith("_BUTTON")) return; if (!m.name().endsWith("_BUTTON")) return;
try { try {
legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8)); legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8));
button.getState().update(); button.getState().update();
@ -143,7 +141,7 @@ public class BlockUtils {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
} }
} }
public static void toggleLever(Block lever) { public static void toggleLever(Block lever) {
if (useLegacy && legacySetBlockData != null) { if (useLegacy && legacySetBlockData != null) {
_toggleLeverLegacy(lever); _toggleLeverLegacy(lever);
@ -154,7 +152,7 @@ public class BlockUtils {
private static void _toggleLeverLegacy(Block lever) { private static void _toggleLeverLegacy(Block lever) {
final Material m = lever.getType(); final Material m = lever.getType();
if(m != Material.LEVER) return; if (m != Material.LEVER) return;
try { try {
legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8)); legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8));
lever.getState().update(); lever.getState().update();
@ -189,6 +187,7 @@ public class BlockUtils {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
} }
} }
/** /**
* Change all of the given door states to be inverse; that is, if a door is * Change all of the given door states to be inverse; that is, if a door is
* open, it will be closed afterwards. If the door is closed, it will become * open, it will be closed afterwards. If the door is closed, it will become
@ -197,8 +196,8 @@ public class BlockUtils {
* Note that the blocks given must be the bottom block of the door. * Note that the blocks given must be the bottom block of the door.
* *
* @param allowDoorToOpen If FALSE, and the door is currently CLOSED, it * @param allowDoorToOpen If FALSE, and the door is currently CLOSED, it
* will NOT be opened! * will NOT be opened!
* @param doors Blocks given must be the bottom block of the door * @param doors Blocks given must be the bottom block of the door
*/ */
public static void toggleDoorStates(boolean allowDoorToOpen, Block... doors) { public static void toggleDoorStates(boolean allowDoorToOpen, Block... doors) {
if (useLegacy && legacySetBlockData != null) { if (useLegacy && legacySetBlockData != null) {
@ -312,6 +311,7 @@ public class BlockUtils {
/** /**
* Manually trigger the updateAdjacentComparators method for containers * Manually trigger the updateAdjacentComparators method for containers
*
* @param containerLocation location of the container * @param containerLocation location of the container
*/ */
public static void updateAdjacentComparators(Location containerLocation) { public static void updateAdjacentComparators(Location containerLocation) {
@ -363,7 +363,8 @@ public class BlockUtils {
if (mat == null || !mat.isCrop()) { if (mat == null || !mat.isCrop()) {
return false; return false;
} else { } else {
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS ? 3 : 7); return block.getData() >= (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
} }
} }
@ -383,7 +384,8 @@ public class BlockUtils {
if (mat == null || !mat.isCrop()) { if (mat == null || !mat.isCrop()) {
return -1; return -1;
} else { } else {
return mat == CompatibleMaterial.BEETROOTS ? 3 : 7; return (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
} }
} }
@ -403,7 +405,8 @@ public class BlockUtils {
if (mat == null || !mat.isCrop()) { if (mat == null || !mat.isCrop()) {
return -1; return -1;
} else { } else {
return mat == CompatibleMaterial.BEETROOTS ? 3 : 7; return (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
} }
} }
@ -421,7 +424,8 @@ public class BlockUtils {
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
if (mat != null && mat.isCrop()) { if (mat != null && mat.isCrop()) {
try { try {
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, mat == CompatibleMaterial.BEETROOTS ? 3 : 7))); legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7))));
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
} }
@ -440,7 +444,8 @@ public class BlockUtils {
BlockUtilsModern._incrementGrowthStage(block); BlockUtilsModern._incrementGrowthStage(block);
} else { } else {
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) { if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) {
try { try {
legacySetBlockData.invoke(block, (byte) (block.getData() + 1)); legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
} catch (Exception ex) { } catch (Exception ex) {
@ -473,7 +478,7 @@ public class BlockUtils {
/** /**
* Check to see if this material does not impede player/mob movement at all. * Check to see if this material does not impede player/mob movement at all.
* *
* @param m material to check * @param m material to check
* @return true if this material doesn't have a solid hitbox * @return true if this material doesn't have a solid hitbox
*/ */
@ -625,7 +630,7 @@ public class BlockUtils {
case "WITHER_ROSE": case "WITHER_ROSE":
case "YELLOW_BANNER": case "YELLOW_BANNER":
case "YELLOW_WALL_BANNER": case "YELLOW_WALL_BANNER":
// Legacy values: // Legacy values:
case "WEB": case "WEB":
case "LONG_GRASS": case "LONG_GRASS":
case "YELLOW_FLOWER": case "YELLOW_FLOWER":
@ -658,7 +663,7 @@ public class BlockUtils {
/** /**
* Check to see if a player can walk into this material<br /> * Check to see if a player can walk into this material<br />
* This includes blocks like slabs and stairs * This includes blocks like slabs and stairs
* *
* @param m material to check * @param m material to check
* @return true if this is a block that can be walked though or up * @return true if this is a block that can be walked though or up
*/ */
@ -936,7 +941,7 @@ public class BlockUtils {
case "YELLOW_BANNER": case "YELLOW_BANNER":
case "YELLOW_CARPET": case "YELLOW_CARPET":
case "YELLOW_WALL_BANNER": case "YELLOW_WALL_BANNER":
// Legacy values: // Legacy values:
case "WEB": case "WEB":
case "LONG_GRASS": case "LONG_GRASS":
case "YELLOW_FLOWER": case "YELLOW_FLOWER":