Fix nether warts

This commit is contained in:
Brianna 2020-01-19 17:59:43 -05:00
parent a84bd5ddc2
commit 27dbc0ff48

View File

@ -1,22 +1,19 @@
package com.songoda.core.utils;
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.Method;
import java.util.EnumSet;
import java.util.Set;
import java.util.logging.Level;
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 {
@ -69,10 +66,10 @@ public class BlockUtils {
if (isOpenable(bType)) {
toggleDoorStates(true, b);
return true;
} else if(bType == Material.LEVER) {
} else if (bType == Material.LEVER) {
toggleLever(b);
return true;
} else if(bType.name().endsWith("_BUTTON")) {
} else if (bType.name().endsWith("_BUTTON")) {
pressButton(b);
return true;
}
@ -82,6 +79,7 @@ public class BlockUtils {
/**
* Change a pressure plate's redstone state
*
* @param plate plate to update
* @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) {
final Material m = button.getType();
if(!m.name().endsWith("_BUTTON")) return;
if (!m.name().endsWith("_BUTTON")) return;
try {
legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8)));
button.getState().update();
@ -135,7 +133,7 @@ public class BlockUtils {
private static void _releaseButtonLegacy(Block button) {
final Material m = button.getType();
if(!m.name().endsWith("_BUTTON")) return;
if (!m.name().endsWith("_BUTTON")) return;
try {
legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8));
button.getState().update();
@ -154,7 +152,7 @@ public class BlockUtils {
private static void _toggleLeverLegacy(Block lever) {
final Material m = lever.getType();
if(m != Material.LEVER) return;
if (m != Material.LEVER) return;
try {
legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8));
lever.getState().update();
@ -189,6 +187,7 @@ public class BlockUtils {
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
* open, it will be closed afterwards. If the door is closed, it will become
@ -312,6 +311,7 @@ public class BlockUtils {
/**
* Manually trigger the updateAdjacentComparators method for containers
*
* @param containerLocation location of the container
*/
public static void updateAdjacentComparators(Location containerLocation) {
@ -363,7 +363,8 @@ public class BlockUtils {
if (mat == null || !mat.isCrop()) {
return false;
} 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()) {
return -1;
} 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()) {
return -1;
} 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());
if (mat != null && mat.isCrop()) {
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) {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
}
@ -440,7 +444,8 @@ public class BlockUtils {
BlockUtilsModern._incrementGrowthStage(block);
} else {
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 {
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
} catch (Exception ex) {