mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-24 21:31:22 +01:00
Update to 1.17
This commit is contained in:
parent
da9f84acb4
commit
b43c647c5f
2
pom.xml
2
pom.xml
@ -148,7 +148,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
<version>1.17-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -60,7 +60,7 @@ public class BCauldron {
|
|||||||
if (!BUtil.isChunkLoaded(block)) {
|
if (!BUtil.isChunkLoaded(block)) {
|
||||||
increaseState();
|
increaseState();
|
||||||
} else {
|
} else {
|
||||||
if (block.getType() != Material.CAULDRON) {
|
if (!LegacyUtil.isWaterCauldron(block.getType())) {
|
||||||
// Catch any WorldEdit etc. removal
|
// Catch any WorldEdit etc. removal
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -172,12 +172,25 @@ public class BCauldron {
|
|||||||
|
|
||||||
if (P.use1_13) {
|
if (P.use1_13) {
|
||||||
BlockData data = block.getBlockData();
|
BlockData data = block.getBlockData();
|
||||||
|
if (!(data instanceof Levelled)) {
|
||||||
|
bcauldrons.remove(block);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Levelled cauldron = ((Levelled) data);
|
Levelled cauldron = ((Levelled) data);
|
||||||
if (cauldron.getLevel() <= 0) {
|
if (cauldron.getLevel() <= 0) {
|
||||||
bcauldrons.remove(block);
|
bcauldrons.remove(block);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LegacyUtil.WATER_CAULDRON != null && cauldron.getLevel() == 1) {
|
||||||
|
// Empty Cauldron
|
||||||
|
P.p.log("Empty Cauldron");
|
||||||
|
block.setType(Material.CAULDRON);
|
||||||
|
bcauldrons.remove(block);
|
||||||
|
} else {
|
||||||
|
P.p.log("Setting level to : " + (cauldron.getLevel() - 1));
|
||||||
cauldron.setLevel(cauldron.getLevel() - 1);
|
cauldron.setLevel(cauldron.getLevel() - 1);
|
||||||
|
|
||||||
// Update the new Level to the Block
|
// Update the new Level to the Block
|
||||||
// We have to use the BlockData variable "data" here instead of the casted "cauldron"
|
// We have to use the BlockData variable "data" here instead of the casted "cauldron"
|
||||||
// otherwise < 1.13 crashes on plugin load for not finding the BlockData Class
|
// otherwise < 1.13 crashes on plugin load for not finding the BlockData Class
|
||||||
@ -188,6 +201,7 @@ public class BCauldron {
|
|||||||
} else {
|
} else {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
byte data = block.getData();
|
byte data = block.getData();
|
||||||
@ -399,9 +413,10 @@ public class BCauldron {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// reset cauldron when refilling to prevent unlimited source of potions
|
// Ignore Water Buckets
|
||||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||||
if (!P.use1_9) {
|
if (!P.use1_9) {
|
||||||
|
// reset < 1.9 cauldron when refilling to prevent unlimited source of potions
|
||||||
// We catch >=1.9 cases in the Cauldron Listener
|
// We catch >=1.9 cases in the Cauldron Listener
|
||||||
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
||||||
// will only remove when existing
|
// will only remove when existing
|
||||||
|
@ -27,19 +27,13 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class BPlayer {
|
public class BPlayer {
|
||||||
private static Map<String, BPlayer> players = new HashMap<>();// Players uuid and BPlayer
|
private static Map<String, BPlayer> players = new HashMap<>();// Players uuid and BPlayer
|
||||||
private static Map<Player, MutableInt> pTasks = new HashMap<>();// Player and count
|
private static Map<Player, MutableInt> pTasks = new HashMap<>();// Player and count
|
||||||
private static int taskId;
|
private static int taskId;
|
||||||
private static boolean modAge = true;
|
|
||||||
private static Random pukeRand;
|
private static Random pukeRand;
|
||||||
private static Method itemHandle;
|
|
||||||
private static Field age;
|
|
||||||
|
|
||||||
private final String uuid;
|
private final String uuid;
|
||||||
private int quality = 0;// = quality of drunkeness * drunkeness
|
private int quality = 0;// = quality of drunkeness * drunkeness
|
||||||
@ -620,39 +614,23 @@ public class BPlayer {
|
|||||||
Item item = player.getWorld().dropItem(loc, new ItemStack(BConfig.pukeItem));
|
Item item = player.getWorld().dropItem(loc, new ItemStack(BConfig.pukeItem));
|
||||||
item.setVelocity(direction);
|
item.setVelocity(direction);
|
||||||
item.setPickupDelay(32767); // Item can never be picked up when pickup delay is 32767
|
item.setPickupDelay(32767); // Item can never be picked up when pickup delay is 32767
|
||||||
//item.setTicksLived(6000 - pukeDespawntime); // Well this does not work...
|
if (P.use1_14) item.setPersistent(false); // No need to save Puke items
|
||||||
if (modAge) {
|
|
||||||
int pukeDespawntime = BConfig.pukeDespawntime;
|
int pukeDespawntime = BConfig.pukeDespawntime;
|
||||||
if (pukeDespawntime >= 5800) {
|
if (pukeDespawntime >= 5800) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
if (itemHandle == null) {
|
|
||||||
itemHandle = Class.forName(P.p.getServer().getClass().getPackage().getName() + ".entity.CraftItem").getMethod("getHandle", (Class<?>[]) null);
|
|
||||||
}
|
|
||||||
Object entityItem = itemHandle.invoke(item, (Object[]) null);
|
|
||||||
if (age == null) {
|
|
||||||
age = entityItem.getClass().getDeclaredField("age");
|
|
||||||
age.setAccessible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting the age determines when an item is despawned. At age 6000 it is removed.
|
// Setting the age determines when an item is despawned. At age 6000 it is removed.
|
||||||
if (pukeDespawntime <= 0) {
|
if (pukeDespawntime <= 0) {
|
||||||
// Just show the item for a tick
|
// Just show the item for a few ticks
|
||||||
age.setInt(entityItem, 5999);
|
item.setTicksLived(5996);
|
||||||
} else if (pukeDespawntime <= 120) {
|
} else if (pukeDespawntime <= 120) {
|
||||||
// it should despawn in less than 6 sec. Add up to half of that randomly
|
// it should despawn in less than 6 sec. Add up to half of that randomly
|
||||||
age.setInt(entityItem, 6000 - pukeDespawntime + pukeRand.nextInt((int) (pukeDespawntime / 2F)));
|
item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt((int) (pukeDespawntime / 2F)));
|
||||||
} else {
|
} else {
|
||||||
// Add up to 5 sec randomly
|
// Add up to 5 sec randomly
|
||||||
age.setInt(entityItem, 6000 - pukeDespawntime + pukeRand.nextInt(100));
|
item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt(100));
|
||||||
}
|
|
||||||
return;
|
|
||||||
} catch (InvocationTargetException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
modAge = false;
|
|
||||||
P.p.errorLog("Failed to set Despawn Time on item " + BConfig.pukeItem.name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public class IntegrationListener implements Listener {
|
|||||||
if (!BConfig.hasMMOItems) return;
|
if (!BConfig.hasMMOItems) return;
|
||||||
try {
|
try {
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getHand() == EquipmentSlot.HAND) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getHand() == EquipmentSlot.HAND) {
|
||||||
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.CAULDRON) {
|
if (event.getClickedBlock() != null && LegacyUtil.isWaterCauldron(event.getClickedBlock().getType())) {
|
||||||
NBTItem item = NBTItem.get(event.getItem());
|
NBTItem item = NBTItem.get(event.getItem());
|
||||||
if (item.hasType()) {
|
if (item.hasType()) {
|
||||||
for (RecipeItem rItem : BCauldronRecipe.acceptedCustom) {
|
for (RecipeItem rItem : BCauldronRecipe.acceptedCustom) {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package com.dre.brewery.listeners;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
import com.dre.brewery.BCauldron;
|
import com.dre.brewery.BCauldron;
|
||||||
|
import com.dre.brewery.P;
|
||||||
|
import com.dre.brewery.utility.LegacyUtil;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.data.Levelled;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -8,8 +13,49 @@ import org.bukkit.event.block.CauldronLevelChangeEvent;
|
|||||||
|
|
||||||
public class CauldronListener implements Listener {
|
public class CauldronListener implements Listener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Water in Cauldron gets filled up: remove BCauldron to disallow unlimited Brews
|
||||||
|
* Water in Cauldron gets removed: remove BCauldron to remove Brew data and stop particles
|
||||||
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onCauldronChange(CauldronLevelChangeEvent event) {
|
public void onCauldronChange(CauldronLevelChangeEvent event) {
|
||||||
|
if (LegacyUtil.WATER_CAULDRON == null) {
|
||||||
|
// < 1.17
|
||||||
|
oldCauldronChange(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material currentType = event.getBlock().getType();
|
||||||
|
BlockState newState = event.getNewState();
|
||||||
|
Material newType = newState.getType();
|
||||||
|
|
||||||
|
P.p.log("OldType: " + currentType + " NewType: " + newType);
|
||||||
|
|
||||||
|
|
||||||
|
if (currentType == Material.WATER_CAULDRON) {
|
||||||
|
if (newType != Material.WATER_CAULDRON) {
|
||||||
|
// Change from water to anything else
|
||||||
|
if (event.getReason() != CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) {
|
||||||
|
BCauldron.remove(event.getBlock());
|
||||||
|
}
|
||||||
|
} else { // newType == Material.WATER_CAULDRON
|
||||||
|
// Water level change
|
||||||
|
Levelled oldCauldron = ((Levelled) event.getBlock().getBlockData());
|
||||||
|
Levelled newCauldron = ((Levelled) newState.getBlockData());
|
||||||
|
|
||||||
|
P.p.log("OldLevel: " + oldCauldron.getLevel() + " Newlevel: " + newCauldron.getLevel());
|
||||||
|
|
||||||
|
// Water Level increased somehow, might be Bucket, Bottle, Rain, etc.
|
||||||
|
if (newCauldron.getLevel() > oldCauldron.getLevel()) {
|
||||||
|
BCauldron.remove(event.getBlock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void oldCauldronChange(CauldronLevelChangeEvent event) {
|
||||||
if (event.getNewLevel() == 0 && event.getOldLevel() != 0) {
|
if (event.getNewLevel() == 0 && event.getOldLevel() != 0) {
|
||||||
if (event.getReason() == CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) {
|
if (event.getReason() == CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) {
|
||||||
return;
|
return;
|
||||||
|
@ -70,7 +70,7 @@ public class PlayerListener implements Listener {
|
|||||||
if (player.isSneaking()) return;
|
if (player.isSneaking()) return;
|
||||||
|
|
||||||
// -- Interacting with a Cauldron --
|
// -- Interacting with a Cauldron --
|
||||||
if (type == Material.CAULDRON) {
|
if (LegacyUtil.isWaterCauldron(type)) {
|
||||||
// Handle the Cauldron Interact
|
// Handle the Cauldron Interact
|
||||||
// The Event might get cancelled in here
|
// The Event might get cancelled in here
|
||||||
BCauldron.clickCauldron(event);
|
BCauldron.clickCauldron(event);
|
||||||
|
@ -257,8 +257,11 @@ public class BUtil {
|
|||||||
* @return True if the Block can be destroyed
|
* @return True if the Block can be destroyed
|
||||||
*/
|
*/
|
||||||
public static boolean blockDestroy(Block block, Player player, BarrelDestroyEvent.Reason reason) {
|
public static boolean blockDestroy(Block block, Player player, BarrelDestroyEvent.Reason reason) {
|
||||||
|
if (block == null || block.getType() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Material type = block.getType();
|
Material type = block.getType();
|
||||||
if (type == Material.CAULDRON) {
|
if (type == Material.CAULDRON || type == LegacyUtil.WATER_CAULDRON) {
|
||||||
// will only remove when existing
|
// will only remove when existing
|
||||||
BCauldron.remove(block);
|
BCauldron.remove(block);
|
||||||
return true;
|
return true;
|
||||||
|
@ -78,6 +78,7 @@ public class LegacyUtil {
|
|||||||
FENCES = fences;
|
FENCES = fences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Material WATER_CAULDRON = get("WATER_CAULDRON");
|
||||||
public static final Material MAGMA_BLOCK = get("MAGMA_BLOCK", "MAGMA");
|
public static final Material MAGMA_BLOCK = get("MAGMA_BLOCK", "MAGMA");
|
||||||
public static final Material CAMPFIRE = get("CAMPFIRE");
|
public static final Material CAMPFIRE = get("CAMPFIRE");
|
||||||
public static final Material SOUL_CAMPFIRE = get("SOUL_CAMPFIRE");
|
public static final Material SOUL_CAMPFIRE = get("SOUL_CAMPFIRE");
|
||||||
@ -220,13 +221,20 @@ public class LegacyUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if this Material Type is a Cauldron filled with water, or any cauldron in 1.16 and lower
|
||||||
|
*/
|
||||||
|
public static boolean isWaterCauldron(Material type) {
|
||||||
|
return WATER_CAULDRON != null ? type == WATER_CAULDRON : type == Material.CAULDRON;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get The Fill Level of a Cauldron Block, 0 = empty, 1 = something in, 2 = full
|
* Get The Fill Level of a Cauldron Block, 0 = empty, 1 = something in, 2 = full
|
||||||
*
|
*
|
||||||
* @return 0 = empty, 1 = something in, 2 = full
|
* @return 0 = empty, 1 = something in, 2 = full
|
||||||
*/
|
*/
|
||||||
public static byte getFillLevel(Block block) {
|
public static byte getFillLevel(Block block) {
|
||||||
if (block.getType() != Material.CAULDRON) {
|
if (!isWaterCauldron(block.getType())) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user