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)
*/ */
@ -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();
@ -135,7 +133,7 @@ public class BlockUtils {
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();
@ -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) {
@ -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":
@ -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":