Merge branch 'master' into master

This commit is contained in:
Sn0wStorm
2021-06-15 15:45:13 +02:00
committed by GitHub
39 changed files with 1146 additions and 218 deletions
+27 -26
View File
@@ -60,7 +60,7 @@ public class BCauldron {
if (!BUtil.isChunkLoaded(block)) {
increaseState();
} else {
if (block.getType() != Material.CAULDRON) {
if (!LegacyUtil.isWaterCauldron(block.getType())) {
// Catch any WorldEdit etc. removal
return false;
}
@@ -172,21 +172,34 @@ public class BCauldron {
if (P.use1_13) {
BlockData data = block.getBlockData();
if (!(data instanceof Levelled)) {
bcauldrons.remove(block);
return false;
}
Levelled cauldron = ((Levelled) data);
if (cauldron.getLevel() <= 0) {
bcauldrons.remove(block);
return false;
}
cauldron.setLevel(cauldron.getLevel() - 1);
// Update the new Level to the Block
// 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
block.setBlockData(data);
if (cauldron.getLevel() <= 0) {
// If the Water_Cauldron type exists and the cauldron is on last level
if (LegacyUtil.WATER_CAULDRON != null && cauldron.getLevel() == 1) {
// Empty Cauldron
block.setType(Material.CAULDRON);
bcauldrons.remove(block);
} else {
changed = true;
cauldron.setLevel(cauldron.getLevel() - 1);
// Update the new Level to the Block
// 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
block.setBlockData(data);
if (cauldron.getLevel() <= 0) {
bcauldrons.remove(block);
} else {
changed = true;
}
}
} else {
@@ -389,7 +402,7 @@ public class BCauldron {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
} else {
setItemInHand(event, Material.AIR, false);
BUtil.setItemInHand(event, Material.AIR, false);
}
}
}
@@ -399,9 +412,10 @@ public class BCauldron {
}
return;
// reset cauldron when refilling to prevent unlimited source of potions
// Ignore Water Buckets
} else if (materialInHand == Material.WATER_BUCKET) {
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
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
// will only remove when existing
@@ -458,30 +472,17 @@ public class BCauldron {
}
} else {
if (isBucket) {
setItemInHand(event, Material.BUCKET, handSwap);
BUtil.setItemInHand(event, Material.BUCKET, handSwap);
} else if (isBottle) {
setItemInHand(event, Material.GLASS_BOTTLE, handSwap);
BUtil.setItemInHand(event, Material.GLASS_BOTTLE, handSwap);
} else {
setItemInHand(event, Material.AIR, handSwap);
BUtil.setItemInHand(event, Material.AIR, handSwap);
}
}
}
}
}
@SuppressWarnings("deprecation")
public static void setItemInHand(PlayerInteractEvent event, Material mat, boolean swapped) {
if (P.use1_9) {
if ((event.getHand() == EquipmentSlot.OFF_HAND) != swapped) {
event.getPlayer().getInventory().setItemInOffHand(new ItemStack(mat));
} else {
event.getPlayer().getInventory().setItemInMainHand(new ItemStack(mat));
}
} else {
event.getPlayer().setItemInHand(new ItemStack(mat));
}
}
/**
* Recalculate the Cauldron Particle Recipe
*/
+3 -2
View File
@@ -175,7 +175,7 @@ public class BDistiller {
BlockState now = standBlock.getState();
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == -1) { // only check at the beginning (and end) for distillables
if (brewTime == -1) { // check at the beginning for distillables
if (!prepareForDistillables(stand)) {
return;
}
@@ -185,7 +185,7 @@ public class BDistiller {
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
if (brewTime <= 1) { // Done!
contents = getDistillContents(stand.getInventory());
contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
@@ -220,6 +220,7 @@ public class BDistiller {
if (P.use1_11) {
// The trick below doesnt work in 1.11, but we dont need it anymore
// This should only happen with older Brews that have been made with the old Potion Color System
// This causes standard potions to not brew in the brewing stand if put together with Brews, but the bubble animation will play
stand.setBrewingTime(Short.MAX_VALUE);
} else {
// Brewing time is sent and stored as short
+70 -66
View File
@@ -8,6 +8,7 @@ import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.lore.BrewLore;
import com.dre.brewery.recipe.BEffect;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.PermissionUtil;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.mutable.MutableInt;
@@ -27,24 +28,19 @@ import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
public class 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 int taskId;
private static boolean modAge = true;
private static Random pukeRand;
private static Method itemHandle;
private static Field age;
private final String uuid;
private int quality = 0;// = quality of drunkeness * drunkeness
private int drunkeness = 0;// = amount of drunkeness
private int offlineDrunk = 0;// drunkeness when gone offline
private int alcRecovery = -1; // Drunkeness reduce per minute
private Vector push = new Vector(0, 0, 0);
private int time = 20;
@@ -161,6 +157,7 @@ public class BPlayer {
if (bPlayer == null) {
bPlayer = addPlayer(player);
}
// In this event the added alcohol amount is calculated, based on the sensitivity permission
BrewDrinkEvent drinkEvent = new BrewDrinkEvent(brew, meta, player, bPlayer);
if (meta != null) {
P.p.getServer().getPluginManager().callEvent(drinkEvent);
@@ -181,30 +178,36 @@ public class BPlayer {
int quality = drinkEvent.getQuality();
List<PotionEffect> effects = getBrewEffects(brew.getEffects(), quality);
if (brewAlc < 1) {
//no alcohol so we dont need to add a BPlayer
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
if (bPlayer.drunkeness <= 0) {
bPlayer.remove();
}
return true;
}
bPlayer.drunkeness += brewAlc;
if (quality > 0) {
bPlayer.quality += quality * brewAlc;
} else {
bPlayer.quality += brewAlc;
}
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
if (brewAlc < 0) {
// If the Drink has negative alcohol, drain some alcohol
bPlayer.drain(player, -brewAlc);
} else if (brewAlc > 0) {
bPlayer.drunkeness += brewAlc;
if (quality > 0) {
bPlayer.quality += quality * brewAlc;
} else {
bPlayer.quality += brewAlc;
}
applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
}
if (bPlayer.drunkeness > 100) {
bPlayer.drinkCap(player);
}
bPlayer.syncToSQL(false);
if (BConfig.showStatusOnDrink) {
bPlayer.showDrunkeness(player);
// Only show the Player his drunkeness if he is already drunk, or this drink changed his drunkeness
if (brewAlc != 0 || bPlayer.drunkeness > 0) {
bPlayer.showDrunkeness(player);
}
}
if (bPlayer.drunkeness <= 0) {
bPlayer.remove();
} else {
bPlayer.syncToSQL(false);
}
return true;
}
@@ -343,7 +346,7 @@ public class BPlayer {
}
// drain the drunkeness by amount, returns true when player has to be removed
public boolean drain(Player player, int amount) {
public boolean drain(@Nullable Player player, int amount) {
if (drunkeness > 0) {
quality -= getQuality() * amount;
}
@@ -481,14 +484,13 @@ public class BPlayer {
showDrunkeness(player);
}
if (drunkeness <= 0) {
// wird der spieler noch gebraucht?
remove(player);
}
} else if (offlineDrunk - drunkeness >= 30) {
Location randomLoc = Wakeup.getRandom(player.getLocation());
if (randomLoc != null) {
if (!player.hasPermission("brewery.bypass.teleport")) {
if (BConfig.enableWake && !player.hasPermission("brewery.bypass.teleport")) {
Location randomLoc = Wakeup.getRandom(player.getLocation());
if (randomLoc != null) {
player.teleport(randomLoc);
P.p.msg(player, P.p.languageReader.get("Player_Wake"));
}
@@ -523,6 +525,16 @@ public class BPlayer {
}
}
public void recalculateAlcRecovery(@Nullable Player player) {
setAlcRecovery(2);
if (player != null) {
int rec = PermissionUtil.getAlcRecovery(player);
if (rec > -1) {
setAlcRecovery(rec);
}
}
}
// #### Puking ####
@@ -604,39 +616,23 @@ public class BPlayer {
item.setVelocity(direction);
item.setPickupDelay(32767); // Item can never be picked up when pickup delay is 32767
item.setMetadata("brewery_puke", new FixedMetadataValue(P.getInstance(), true));
//item.setTicksLived(6000 - pukeDespawntime); // Well this does not work...
if (modAge) {
int pukeDespawntime = BConfig.pukeDespawntime;
if (pukeDespawntime >= 5800) {
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);
}
if (P.use1_14) item.setPersistent(false); // No need to save Puke items
// Setting the age determines when an item is despawned. At age 6000 it is removed.
if (pukeDespawntime <= 0) {
// Just show the item for a tick
age.setInt(entityItem, 5999);
} else if (pukeDespawntime <= 120) {
// 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)));
} else {
// Add up to 5 sec randomly
age.setInt(entityItem, 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());
int pukeDespawntime = BConfig.pukeDespawntime;
if (pukeDespawntime >= 5800) {
return;
}
// Setting the age determines when an item is despawned. At age 6000 it is removed.
if (pukeDespawntime <= 0) {
// Just show the item for a few ticks
item.setTicksLived(5996);
} else if (pukeDespawntime <= 120) {
// it should despawn in less than 6 sec. Add up to half of that randomly
item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt((int) (pukeDespawntime / 2F)));
} else {
// Add up to 5 sec randomly
item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt(100));
}
}
@@ -802,17 +798,18 @@ public class BPlayer {
// decreasing drunkeness over time
public static void onUpdate() {
if (!players.isEmpty()) {
int soberPerMin = 2;
Iterator<Map.Entry<String, BPlayer>> iter = players.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, BPlayer> entry = iter.next();
String uuid = entry.getKey();
BPlayer bplayer = entry.getValue();
if (bplayer.drunkeness == soberPerMin) {
// Prevent 0 drunkeness
soberPerMin++;
Player playerIfOnline = BUtil.getPlayerfromString(uuid);
if (bplayer.getAlcRecovery() == -1) {
bplayer.recalculateAlcRecovery(playerIfOnline);
}
if (bplayer.drain(BUtil.getPlayerfromString(uuid), soberPerMin)) {
if (bplayer.drain(playerIfOnline, bplayer.getAlcRecovery())) {
iter.remove();
if (BConfig.sqlDrunkSync && BConfig.sqlSync != null) {
BConfig.sqlSync.removePlayer(UUID.fromString(uuid));
@@ -898,4 +895,11 @@ public class BPlayer {
return offlineDrunk;
}
public int getAlcRecovery() {
return alcRecovery;
}
public void setAlcRecovery(int alcRecovery) {
this.alcRecovery = alcRecovery;
}
}
+16 -13
View File
@@ -373,9 +373,7 @@ public class Brew implements Cloneable {
// quality decides 10% - 100%
alc *= ((float) quality / 10.0f);
}
if (alc > 0) {
return alc;
}
return alc;
}
return 0;
}
@@ -516,7 +514,10 @@ public class Brew implements Cloneable {
}
public int getOrCalcAlc() {
return alc > 0 ? alc : (alc = calcAlcohol());
if (alc == 0) {
alc = calcAlcohol();
}
return alc;
}
public void setAlc(int alc) {
@@ -1004,18 +1005,20 @@ public class Brew implements Cloneable {
quality = 10;
}
alc = Math.min(alc, Short.MAX_VALUE);
alc = Math.max(alc, Short.MIN_VALUE);
out.writeByte((byte) quality);
int bools = 0;
bools |= ((distillRuns != 0) ? 1 : 0);
bools |= (ageTime > 0 ? 2 : 0);
bools |= (wood != -1 ? 4 : 0);
bools |= ((distillRuns != 0) ? 1 : 0);
bools |= (ageTime > 0 ? 2 : 0);
bools |= (wood != -1 ? 4 : 0);
bools |= (currentRecipe != null ? 8 : 0);
bools |= (unlabeled ? 16 : 0);
bools |= (immutable ? 32 : 0);
bools |= (alc > 0 ? 64 : 0);
bools |= (stripped ? 128 : 0);
bools |= (unlabeled ? 16 : 0);
bools |= (immutable ? 32 : 0);
bools |= (alc != 0 ? 64 : 0);
bools |= (stripped ? 128 : 0);
out.writeByte(bools);
if (alc > 0) {
if (alc != 0) {
out.writeShort(alc);
}
if (distillRuns != 0) {
@@ -1142,7 +1145,7 @@ public class Brew implements Cloneable {
if (brew.quality != 0) {
idConfig.set("quality", brew.quality);
}
if (brew.alc > 0) {
if (brew.alc != 0) {
idConfig.set("alc", brew.alc);
}
if (brew.distillRuns != 0) {
+42 -17
View File
@@ -1,3 +1,27 @@
/**
*
* Brewery Minecraft-Plugin for an alternate Brewing Process
* Copyright (C) 2021 Milan Albrecht
*
* This file is part of Brewery.
*
* Brewery is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Brewery is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Brewery. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.dre.brewery;
import com.dre.brewery.filedata.BConfig;
@@ -16,6 +40,7 @@ import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.apache.commons.lang.math.NumberUtils;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -286,12 +311,12 @@ public class P extends JavaPlugin {
private void setupMetrics() {
try {
Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> brewsCreated));
metrics.addCustomChart(new Metrics.SingleLineChart("barrels_built", () -> Barrel.barrels.size()));
metrics.addCustomChart(new Metrics.SingleLineChart("cauldrons_boiling", () -> BCauldron.bcauldrons.size()));
metrics.addCustomChart(new Metrics.AdvancedPie("brew_quality", () -> {
Metrics metrics = new Metrics(this, 3494);
metrics.addCustomChart(new SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
metrics.addCustomChart(new SingleLineChart("brews_in_existence", () -> brewsCreated));
metrics.addCustomChart(new SingleLineChart("barrels_built", Barrel.barrels::size));
metrics.addCustomChart(new SingleLineChart("cauldrons_boiling", BCauldron.bcauldrons::size));
metrics.addCustomChart(new AdvancedPie("brew_quality", () -> {
Map<String, Integer> map = new HashMap<>(8);
map.put("excellent", exc);
map.put("good", good);
@@ -300,14 +325,14 @@ public class P extends JavaPlugin {
map.put("terrible", terr);
return map;
}));
metrics.addCustomChart(new Metrics.AdvancedPie("brews_created", () -> {
metrics.addCustomChart(new AdvancedPie("brews_created", () -> {
Map<String, Integer> map = new HashMap<>(4);
map.put("by command", brewsCreatedCmd);
map.put("brewing", brewsCreated - brewsCreatedCmd);
return map;
}));
metrics.addCustomChart(new Metrics.SimplePie("number_of_recipes", () -> {
metrics.addCustomChart(new SimplePie("number_of_recipes", () -> {
int recipes = BRecipe.getAllRecipes().size();
if (recipes < 7) {
return "Less than 7";
@@ -339,8 +364,8 @@ public class P extends JavaPlugin {
}));
metrics.addCustomChart(new Metrics.SimplePie("wakeups", () -> {
if (!BConfig.enableHome) {
metrics.addCustomChart(new SimplePie("wakeups", () -> {
if (!BConfig.enableWake) {
return "disabled";
}
int wakeups = Wakeup.wakeups.size();
@@ -356,7 +381,7 @@ public class P extends JavaPlugin {
return "More than 20";
}
}));
metrics.addCustomChart(new Metrics.SimplePie("v2_mc_version", () -> {
metrics.addCustomChart(new SimplePie("v2_mc_version", () -> {
String mcv = Bukkit.getBukkitVersion();
mcv = mcv.substring(0, mcv.indexOf('.', 2));
int index = mcv.indexOf('-');
@@ -370,7 +395,7 @@ public class P extends JavaPlugin {
return "undef";
}
}));
metrics.addCustomChart(new Metrics.DrilldownPie("plugin_mc_version", () -> {
metrics.addCustomChart(new DrilldownPie("plugin_mc_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>(3);
String mcv = Bukkit.getBukkitVersion();
mcv = mcv.substring(0, mcv.indexOf('.', 2));
@@ -389,9 +414,9 @@ public class P extends JavaPlugin {
map.put(getDescription().getVersion(), innerMap);
return map;
}));
metrics.addCustomChart(new Metrics.SimplePie("language", () -> language));
metrics.addCustomChart(new Metrics.SimplePie("config_scramble", () -> BConfig.enableEncode ? "enabled" : "disabled"));
metrics.addCustomChart(new Metrics.SimplePie("config_lore_color", () -> {
metrics.addCustomChart(new SimplePie("language", () -> language));
metrics.addCustomChart(new SimplePie("config_scramble", () -> BConfig.enableEncode ? "enabled" : "disabled"));
metrics.addCustomChart(new SimplePie("config_lore_color", () -> {
if (BConfig.colorInBarrels) {
if (BConfig.colorInBrewer) {
return "both";
@@ -406,7 +431,7 @@ public class P extends JavaPlugin {
}
}
}));
metrics.addCustomChart(new Metrics.SimplePie("config_always_show", () -> {
metrics.addCustomChart(new SimplePie("config_always_show", () -> {
if (BConfig.alwaysShowQuality) {
if (BConfig.alwaysShowAlc) {
return "both";
@@ -421,7 +446,7 @@ public class P extends JavaPlugin {
}
}
}));
} catch (Throwable e) {
} catch (Exception | LinkageError e) {
e.printStackTrace();
}
}
+7 -11
View File
@@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
public class Wakeup {
@@ -31,15 +32,10 @@ public class Wakeup {
return null;
}
ArrayList<Wakeup> worldWakes = new ArrayList<>();
for (Wakeup wakeup : wakeups) {
if (wakeup.active) {
if (wakeup.loc.getWorld().equals(playerLoc.getWorld())) {
worldWakes.add(wakeup);
}
}
}
List<Wakeup> worldWakes = wakeups.stream()
.filter(w -> w.active)
.filter(w -> w.loc.getWorld().equals(playerLoc.getWorld()))
.collect(Collectors.toList());
if (worldWakes.isEmpty()) {
return null;
@@ -74,14 +70,14 @@ public class Wakeup {
}
if (w1.loc.distance(playerLoc) > w2.loc.distance(playerLoc)) {
if (w1.loc.distanceSquared(playerLoc) > w2.loc.distanceSquared(playerLoc)) {
return w2.loc;
}
}
return w1.loc;
}
public static Wakeup calcRandom(ArrayList<Wakeup> worldWakes) {
public static Wakeup calcRandom(List<Wakeup> worldWakes) {
if (worldWakes.isEmpty()) {
return null;
}
@@ -2,10 +2,12 @@ package com.dre.brewery.api.events.brew;
import com.dre.brewery.BPlayer;
import com.dre.brewery.Brew;
import com.dre.brewery.utility.PermissionUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
/**
@@ -25,10 +27,30 @@ public class BrewDrinkEvent extends BrewEvent implements Cancellable {
super(brew, meta);
this.player = player;
this.bPlayer = bPlayer;
alc = brew.getOrCalcAlc();
alc = calcAlcWSensitivity(brew.getOrCalcAlc());
quality = brew.getQuality();
}
/**
* Calculate the Alcohol to add to the player using his sensitivity permission (if existing)
*
* <p>If the player has been given the brewery.sensitive.xx permission, will factor in the sensitivity to the given alcohol amount.
* <p>Will return the calculated value without changing the event
*
* @param alc The base amount of alcohol
* @return The amount of alcohol given the players alcohol-sensitivity
*/
@Contract(pure = true)
public int calcAlcWSensitivity(int alc) {
int sensitive = PermissionUtil.getDrinkSensitive(player);
if (sensitive == 0) {
alc = 0;
} else if (sensitive > 0) {
alc *= ((float) sensitive) / 100f;
}
return alc;
}
public Player getPlayer() {
return player;
}
@@ -82,6 +82,7 @@ public class BConfig {
public static boolean enableLoginDisallow;
public static boolean enablePuke;
public static String homeType;
public static boolean enableWake;
//Brew
public static boolean colorInBarrels; // color the Lore while in Barrels
@@ -89,6 +90,7 @@ public class BConfig {
public static boolean enableEncode;
public static boolean alwaysShowQuality; // Always show quality stars
public static boolean alwaysShowAlc; // Always show alc%
public static boolean brewHopperDump; // Allow Dumping of Brew liquid into Hoppers
//Features
public static boolean craftSealingTable; // Allow Crafting of Sealing Table
@@ -228,6 +230,7 @@ public class BConfig {
stumbleModifier = ((float) config.getInt("stumblePercent", 100)) / 100f;
showStatusOnDrink = config.getBoolean("showStatusOnDrink", false);
homeType = config.getString("homeType", null);
enableWake = config.getBoolean("enableWake", false);
craftSealingTable = config.getBoolean("craftSealingTable", false);
enableSealingTable = config.getBoolean("enableSealingTable", false);
colorInBarrels = config.getBoolean("colorInBarrels", false);
@@ -240,6 +243,7 @@ public class BConfig {
minimalParticles = config.getBoolean("minimalParticles", false);
useOffhandForCauldron = config.getBoolean("useOffhandForCauldron", false);
loadDataAsync = config.getBoolean("loadDataAsync", true);
brewHopperDump = config.getBoolean("brewHopperDump", false);
if (P.use1_14) {
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);
@@ -15,7 +15,7 @@ import com.dre.brewery.integration.item.MMOItemsPluginItem;
import com.dre.brewery.recipe.BCauldronRecipe;
import com.dre.brewery.recipe.RecipeItem;
import com.dre.brewery.utility.LegacyUtil;
import net.mmogroup.mmolib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -318,12 +318,13 @@ public class IntegrationListener implements Listener {
// Catch the Interact Event early, so MMOItems does not act before us and cancel the event while we try to add it to the Cauldron
if (!P.use1_9) return;
if (BConfig.hasMMOItems == null) {
BConfig.hasMMOItems = P.p.getServer().getPluginManager().isPluginEnabled("MMOItems");
BConfig.hasMMOItems = P.p.getServer().getPluginManager().isPluginEnabled("MMOItems")
&& P.p.getServer().getPluginManager().isPluginEnabled("MythicLib");
}
if (!BConfig.hasMMOItems) return;
try {
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());
if (item.hasType()) {
for (RecipeItem rItem : BCauldronRecipe.acceptedCustom) {
@@ -3,7 +3,7 @@ package com.dre.brewery.integration.item;
import com.dre.brewery.P;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.recipe.PluginItem;
import net.mmogroup.mmolib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.bukkit.inventory.ItemStack;
public class MMOItemsPluginItem extends PluginItem {
@@ -15,7 +15,8 @@ public class MMOItemsPluginItem extends PluginItem {
@Override
public boolean matches(ItemStack item) {
if (BConfig.hasMMOItems == null) {
BConfig.hasMMOItems = P.p.getServer().getPluginManager().isPluginEnabled("MMOItems");
BConfig.hasMMOItems = P.p.getServer().getPluginManager().isPluginEnabled("MMOItems")
&& P.p.getServer().getPluginManager().isPluginEnabled("MythicLib");
}
if (!BConfig.hasMMOItems) return false;
@@ -23,9 +23,9 @@ public class SlimefunPluginItem extends PluginItem {
try {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem != null) {
return sfItem.getID().equalsIgnoreCase(getItemId());
return sfItem.getId().equalsIgnoreCase(getItemId());
}
} catch (Throwable e) {
} catch (Exception | LinkageError e) {
e.printStackTrace();
P.p.errorLog("Could not check Slimefun for Item ID");
BConfig.hasSlimefun = false;
@@ -1,6 +1,11 @@
package com.dre.brewery.listeners;
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.EventPriority;
import org.bukkit.event.Listener;
@@ -8,8 +13,44 @@ import org.bukkit.event.block.CauldronLevelChangeEvent;
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)
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();
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());
// 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.getReason() == CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) {
return;
@@ -512,7 +512,8 @@ public class CommandListener implements CommandExecutor {
int ingQ = ingredients.getIngredientQuality(recipe);
int cookQ = ingredients.getCookingQuality(recipe, false);
int cookDistQ = ingredients.getCookingQuality(recipe, true);
P.p.log(recipe.getRecipeName() + ": ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ);
int ageQ = ingredients.getAgeQuality(recipe, brew.getAgeTime());
P.p.log(recipe.getRecipeName() + ": ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ + ", ageQlty: " + ageQ);
}
BRecipe distill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), true);
BRecipe nonDistill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), false);
@@ -535,7 +536,8 @@ public class CommandListener implements CommandExecutor {
int ingQ = ingredients.getIngredientQuality(recipe);
int cookQ = ingredients.getCookingQuality(recipe, false);
int cookDistQ = ingredients.getCookingQuality(recipe, true);
P.p.log("ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ);
int ageQ = ingredients.getAgeQuality(recipe, brew.getAgeTime());
P.p.log("ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ + ", ageQlty: " + ageQ);
}
P.p.msg(player, "Debug Info for item written into Log");
@@ -3,12 +3,15 @@ package com.dre.brewery.listeners;
import com.dre.brewery.*;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.filedata.UpdateChecker;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.utility.PermissionUtil;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -29,20 +32,31 @@ public class PlayerListener implements Listener {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
Player player = event.getPlayer();
if (player.isSneaking()) return;
Material type = clickedBlock.getType();
// Interacting with a Cauldron
if (type == Material.CAULDRON) {
// Handle the Cauldron Interact
// The Event might get cancelled in here
BCauldron.clickCauldron(event);
// -- Clicking an Hopper --
if (type == Material.HOPPER) {
if (BConfig.brewHopperDump && event.getPlayer().isSneaking()) {
if (!P.use1_9 || event.getHand() == EquipmentSlot.HAND) {
ItemStack item = event.getItem();
if (Brew.isBrew(item)) {
event.setCancelled(true);
BUtil.setItemInHand(event, Material.GLASS_BOTTLE, false);
if (P.use1_11) {
clickedBlock.getWorld().playSound(clickedBlock.getLocation(), Sound.ITEM_BOTTLE_EMPTY, 1f, 1f);
}
}
}
}
return;
}
// -- Opening a Sealing Table --
if (P.use1_14 && BSealer.isBSealer(clickedBlock)) {
if (player.isSneaking()) {
event.setUseInteractedBlock(Event.Result.DENY);
return;
}
event.setCancelled(true);
if (BConfig.enableSealingTable) {
BSealer sealer = new BSealer(player);
@@ -52,6 +66,18 @@ public class PlayerListener implements Listener {
}
return;
}
if (player.isSneaking()) return;
// -- Interacting with a Cauldron --
if (LegacyUtil.isWaterCauldron(type)) {
// Handle the Cauldron Interact
// The Event might get cancelled in here
BCauldron.clickCauldron(event);
return;
}
// -- Opening a Minecraft Barrel --
if (P.use1_14 && type == Material.BARREL) {
if (!player.hasPermission("brewery.openbarrel.mc")) {
event.setCancelled(true);
@@ -65,7 +91,7 @@ public class PlayerListener implements Listener {
return;
}
// Access a Barrel
// -- Access a Barrel --
Barrel barrel = null;
if (LegacyUtil.isWoodPlanks(type)) {
if (BConfig.openEverywhere) {
+1 -1
View File
@@ -275,7 +275,7 @@ public class BrewLore {
}
public void updateAlc(boolean inDistiller) {
if (!brew.isUnlabeled() && (inDistiller || BConfig.alwaysShowAlc) && (!brew.hasRecipe() || brew.getCurrentRecipe().getAlcohol() > 0)) {
if (!brew.isUnlabeled() && (inDistiller || BConfig.alwaysShowAlc) && (!brew.hasRecipe() || brew.getCurrentRecipe().getAlcohol() != 0)) {
int alc = brew.getOrCalcAlc();
addOrReplaceLore(Type.ALC, "§8", P.p.languageReader.get("Brew_Alc", alc + ""));
} else {
+1 -5
View File
@@ -326,7 +326,7 @@ public class BRecipe {
P.p.errorLog("Invalid distilltime '" + distillTime + "' in Recipe: " + getRecipeName());
return false;
}
if (wood < 0 || wood > 6) {
if (wood < 0 || wood > 8) {
P.p.errorLog("Invalid wood type '" + wood + "' in Recipe: " + getRecipeName());
return false;
}
@@ -338,10 +338,6 @@ public class BRecipe {
P.p.errorLog("Invalid difficulty '" + difficulty + "' in Recipe: " + getRecipeName());
return false;
}
if (alcohol < 0) {
P.p.errorLog("Invalid alcohol '" + alcohol + "' in Recipe: " + getRecipeName());
return false;
}
return true;
}
+27 -1
View File
@@ -13,6 +13,9 @@ import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;
@@ -78,6 +81,26 @@ public class BUtil {
);
}
/**
* Sets the Item in the Players hand, depending on which hand he used and if the hand should be swapped
*
* @param event Interact Event to tell which hand the player used
* @param mat The Material of the new item
* @param swapped If true, will set the opposite Hand instead of the one he used
*/
@SuppressWarnings("deprecation")
public static void setItemInHand(PlayerInteractEvent event, Material mat, boolean swapped) {
if (P.use1_9) {
if ((event.getHand() == EquipmentSlot.OFF_HAND) != swapped) {
event.getPlayer().getInventory().setItemInOffHand(new ItemStack(mat));
} else {
event.getPlayer().getInventory().setItemInMainHand(new ItemStack(mat));
}
} else {
event.getPlayer().setItemInHand(new ItemStack(mat));
}
}
/**
* Returns either uuid or Name of player, depending on bukkit version
*/
@@ -234,8 +257,11 @@ public class BUtil {
* @return True if the Block can be destroyed
*/
public static boolean blockDestroy(Block block, Player player, BarrelDestroyEvent.Reason reason) {
if (block == null || block.getType() == null) {
return true;
}
Material type = block.getType();
if (type == Material.CAULDRON) {
if (type == Material.CAULDRON || type == LegacyUtil.WATER_CAULDRON) {
// will only remove when existing
BCauldron.remove(block);
return true;
+9 -1
View File
@@ -78,6 +78,7 @@ public class LegacyUtil {
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 CAMPFIRE = get("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
*
* @return 0 = empty, 1 = something in, 2 = full
*/
public static byte getFillLevel(Block block) {
if (block.getType() != Material.CAULDRON) {
if (!isWaterCauldron(block.getType())) {
return EMPTY;
}
@@ -1,9 +1,13 @@
package com.dre.brewery.utility;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class PermissionUtil {
@@ -76,6 +80,59 @@ public class PermissionUtil {
return sender.hasPermission(bPerm.permission);
}
/**
* Returns the Sensitivity of the Player towards Alcohol in percent.
* <p>Sensitivity describes how much of the alcohol gets transferred to the players drunkeness
*
* <p>100 means normal alcohol sensitivity
* <p>less than 100 means less alcohol gets added.
* <p>more than 100 means more alcohol gets added.
* <p>0 means no alcohol gets added.
*
* @param player The player of whom to get the sensitivity of
* @return The Players alcohol sensitivity
*/
public static int getDrinkSensitive(Permissible player) {
return getRangedPermission(player, "brewery.sensitive.");
}
/**
* Returns the Alcohol recovery rate of the player in drunkeness per minute.
* <p>The default is 2 drunkeness per minute
*
*
* @param player The player of whom to get the recovery rate of
* @return The Players alcohol recovery rate
*/
public static int getAlcRecovery(Permissible player) {
return getRangedPermission(player, "brewery.recovery.");
}
/**
* Get the number behind the given permission
* <p>i.e. for brewery.sensitive.100 it returns 100
*
* @param player The player to get the ranged permission of
* @param subPermission The permission string before the number
* @return The permission number as int
*/
public static int getRangedPermission(Permissible player, String subPermission) {
Optional<PermissionAttachmentInfo> found = player.getEffectivePermissions().stream().
filter(PermissionAttachmentInfo::getValue). // Only active permissions
filter(x -> x.getPermission().startsWith(subPermission)).
findFirst();
if (found.isPresent()) {
String permission = found.get().getPermission();
int lastDot = permission.lastIndexOf('.');
int value = NumberUtils.toInt(permission.substring(lastDot + 1), -1);
if (value >= 0) {
return value;
}
}
return -1;
}
/**
* Brewery Permissions of _only_ the Commands