mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-05 18:37:40 +01:00
Finalized Merge of 2.0-StoreDataInLore
Rebased onto Master Branch commit e5438e7ae3
And moved to new branch v2.0
This commit is contained in:
parent
519c4821d9
commit
4a1f606e99
@ -1,18 +1,20 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.api.events.IngedientAddEvent;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import com.dre.brewery.api.events.IngedientAddEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class BCauldron {
|
||||
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>(); // TODO find best Collection
|
||||
|
||||
private BIngredients ingredients = new BIngredients();
|
||||
@ -35,7 +37,7 @@ public class BCauldron {
|
||||
|
||||
public void onUpdate() {
|
||||
// Check if fire still alive
|
||||
if (!Util.isChunkLoaded(block) || LegacyUtil.isFireForCauldron(block.getRelative(BlockFace.DOWN))) {
|
||||
if (!BUtil.isChunkLoaded(block) || LegacyUtil.isFireForCauldron(block.getRelative(BlockFace.DOWN))) {
|
||||
// add a minute to cooking time
|
||||
state++;
|
||||
if (someRemoved) {
|
||||
@ -74,7 +76,7 @@ public class BCauldron {
|
||||
// Calls the IngredientAddEvent and may be cancelled or changed
|
||||
public static boolean ingredientAdd(Block block, ItemStack ingredient, Player player) {
|
||||
// if not empty
|
||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||
if (LegacyUtil.getFillLevel(block) != EMPTY) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron == null) {
|
||||
bcauldron = new BCauldron(block);
|
||||
@ -84,7 +86,7 @@ public class BCauldron {
|
||||
P.p.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
bcauldron.add(event.getIngredient());
|
||||
return event.shouldTakeItem();
|
||||
return event.willTakeItem();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -169,7 +171,7 @@ public class BCauldron {
|
||||
|
||||
// reset to normal cauldron
|
||||
public static boolean remove(Block block) {
|
||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||
if (LegacyUtil.getFillLevel(block) != EMPTY) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
@ -190,7 +192,7 @@ public class BCauldron {
|
||||
}
|
||||
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
Util.createWorldSections(config);
|
||||
BUtil.createWorldSections(config);
|
||||
|
||||
if (!bcauldrons.isEmpty()) {
|
||||
int id = 0;
|
||||
@ -199,7 +201,7 @@ public class BCauldron {
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = Util.getDxlName(worldName) + "." + id;
|
||||
prefix = BUtil.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = cauldron.block.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class BEffect {
|
||||
public void apply(int quality, Player player) {
|
||||
PotionEffect effect = generateEffect(quality);
|
||||
if (effect != null) {
|
||||
Util.reapplyPotionEffect(player, effect, true);
|
||||
BUtil.reapplyPotionEffect(player, effect, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,11 +128,11 @@ public class BIngredients {
|
||||
}
|
||||
|
||||
potionMeta.setDisplayName(P.p.color("&f" + cookedName));
|
||||
if (!P.use1_14) {
|
||||
//if (!P.use1_14) {
|
||||
// Before 1.14 the effects duration would strangely be only a quarter of what we tell it to be
|
||||
// This is due to the Duration Modifier, that is removed in 1.14
|
||||
uid *= 4;
|
||||
}
|
||||
// uid *= 4;
|
||||
//}
|
||||
// This effect stores the UID in its Duration
|
||||
//potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
|
||||
|
||||
@ -363,7 +363,7 @@ public class BIngredients {
|
||||
public String toString() {
|
||||
return "BIngredients{" +
|
||||
"cookedTime=" + cookedTime +
|
||||
", total ingedients: " + getIngredientsCount() + '}';
|
||||
", total ingredients: " + getIngredientsCount() + '}';
|
||||
}
|
||||
|
||||
/*public void testStore(DataOutputStream out) throws IOException {
|
||||
|
@ -22,13 +22,7 @@ import org.bukkit.util.Vector;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class BPlayer {
|
||||
private static Map<String, BPlayer> players = new HashMap<>();// Players name/uuid and BPlayer
|
||||
@ -69,7 +63,7 @@ public class BPlayer {
|
||||
|
||||
public static BPlayer get(Player player) {
|
||||
if (!players.isEmpty()) {
|
||||
return players.get(Util.playerString(player));
|
||||
return players.get(BUtil.playerString(player));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -117,18 +111,18 @@ public class BPlayer {
|
||||
}
|
||||
|
||||
public static boolean hasPlayer(Player player) {
|
||||
return players.containsKey(Util.playerString(player));
|
||||
return players.containsKey(BUtil.playerString(player));
|
||||
}
|
||||
|
||||
// Create a new BPlayer and add it to the list
|
||||
public static BPlayer addPlayer(Player player) {
|
||||
BPlayer bPlayer = new BPlayer();
|
||||
players.put(Util.playerString(player), bPlayer);
|
||||
players.put(BUtil.playerString(player), bPlayer);
|
||||
return bPlayer;
|
||||
}
|
||||
|
||||
public static void remove(Player player) {
|
||||
players.remove(Util.playerString(player));
|
||||
players.remove(BUtil.playerString(player));
|
||||
}
|
||||
|
||||
public static int numDrunkPlayers() {
|
||||
@ -353,7 +347,7 @@ public class BPlayer {
|
||||
}
|
||||
hangoverEffects(player);
|
||||
// wird der spieler noch gebraucht?
|
||||
players.remove(Util.playerString(player));
|
||||
players.remove(BUtil.playerString(player));
|
||||
|
||||
} else if (offlineDrunk - drunkeness >= 30) {
|
||||
Location randomLoc = Wakeup.getRandom(player.getLocation());
|
||||
@ -514,7 +508,7 @@ public class BPlayer {
|
||||
return;
|
||||
}
|
||||
for (PotionEffect effect : effects) {
|
||||
Util.reapplyPotionEffect(player, effect, true);
|
||||
BUtil.reapplyPotionEffect(player, effect, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -582,7 +576,7 @@ public class BPlayer {
|
||||
|
||||
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
||||
for (PotionEffect effect : getQualityEffects(quality, brewAlc)) {
|
||||
Util.reapplyPotionEffect(player, effect, true);
|
||||
BUtil.reapplyPotionEffect(player, effect, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,8 +609,8 @@ public class BPlayer {
|
||||
}
|
||||
int amplifier = getHangoverQuality() / 3;
|
||||
|
||||
Util.reapplyPotionEffect(player, PotionEffectType.SLOW.createEffect(duration, amplifier), true);
|
||||
Util.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(duration, amplifier), true);
|
||||
BUtil.reapplyPotionEffect(player, PotionEffectType.SLOW.createEffect(duration, amplifier), true);
|
||||
BUtil.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(duration, amplifier), true);
|
||||
}
|
||||
|
||||
|
||||
@ -629,7 +623,7 @@ public class BPlayer {
|
||||
|
||||
if (bplayer.drunkeness > 30) {
|
||||
if (bplayer.offlineDrunk == 0) {
|
||||
Player player = Util.getPlayerfromString(name);
|
||||
Player player = BUtil.getPlayerfromString(name);
|
||||
if (player != null) {
|
||||
|
||||
bplayer.drunkEffects(player);
|
||||
@ -657,7 +651,7 @@ public class BPlayer {
|
||||
// Prevent 0 drunkeness
|
||||
soberPerMin++;
|
||||
}
|
||||
if (bplayer.drain(Util.getPlayerfromString(name), soberPerMin)) {
|
||||
if (bplayer.drain(BUtil.getPlayerfromString(name), soberPerMin)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
@ -257,11 +257,11 @@ public class BRecipe {
|
||||
|
||||
Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false);
|
||||
potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
|
||||
if (!P.use1_14) {
|
||||
//if (!P.use1_14) {
|
||||
// Before 1.14 the effects duration would strangely be only a quarter of what we tell it to be
|
||||
// This is due to the Duration Modifier, that is removed in 1.14
|
||||
uid *= 4;
|
||||
}
|
||||
// uid *= 4;
|
||||
//}
|
||||
// This effect stores the UID in its Duration
|
||||
//potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
|
||||
|
||||
@ -288,7 +288,7 @@ public class BRecipe {
|
||||
|
||||
BIngredients bIngredients = new BIngredients(list, cookingTime);
|
||||
|
||||
return new Brew(bIngredients, quality, distillruns, getAge(), wood, getName(5), false, true);
|
||||
return new Brew(bIngredients, quality, distillruns, getAge(), wood, getName(5), false, true, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,13 +1,94 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BUtil {
|
||||
|
||||
/******************************************/
|
||||
/********** **********/
|
||||
/********** Bukkit Utils **********/
|
||||
/********** **********/
|
||||
/******************************************/
|
||||
|
||||
// Check if the Chunk of a Block is loaded !without loading it in the process!
|
||||
public static boolean isChunkLoaded(Block block) {
|
||||
return block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4);
|
||||
}
|
||||
|
||||
public static String color(String msg) {
|
||||
if (msg != null) {
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Returns either uuid or Name of player, depending on bukkit version
|
||||
public static String playerString(Player player) {
|
||||
if (P.useUUID) {
|
||||
return player.getUniqueId().toString();
|
||||
} else {
|
||||
return player.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// returns the Player if online
|
||||
public static Player getPlayerfromString(String name) {
|
||||
if (P.useUUID) {
|
||||
try {
|
||||
return Bukkit.getPlayer(UUID.fromString(name));
|
||||
} catch (Exception e) {
|
||||
return Bukkit.getPlayerExact(name);
|
||||
}
|
||||
}
|
||||
return Bukkit.getPlayerExact(name);
|
||||
}
|
||||
|
||||
// Apply a Potion Effect, if player already has this effect, overwrite the existing effect.
|
||||
// Optionally only overwrite if the new one is stronger, i.e. has higher level or longer duration
|
||||
public static void reapplyPotionEffect(Player player, PotionEffect effect, boolean onlyIfStronger) {
|
||||
final PotionEffectType type = effect.getType();
|
||||
if (player.hasPotionEffect(type)) {
|
||||
PotionEffect plEffect;
|
||||
if (P.use1_11) {
|
||||
plEffect = player.getPotionEffect(type);
|
||||
} else {
|
||||
plEffect = player.getActivePotionEffects().stream().filter(e -> e.getType().equals(type)).findAny().get();
|
||||
}
|
||||
if (plEffect.getAmplifier() < effect.getAmplifier() || (plEffect.getAmplifier() == effect.getAmplifier() && plEffect.getDuration() < effect.getDuration())) {
|
||||
player.removePotionEffect(type);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
effect.apply(player);
|
||||
}
|
||||
|
||||
/******************************************/
|
||||
/********** **********/
|
||||
/********** String Utils **********/
|
||||
/********** **********/
|
||||
/******************************************/
|
||||
|
||||
// Returns the Index of a String from the list that contains this substring
|
||||
public static int indexOfSubstring(List<String> list, String substring) {
|
||||
if (list.isEmpty()) return -1;
|
||||
@ -30,71 +111,143 @@ public class BUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
---- Barrel ----
|
||||
*/
|
||||
/******************************************/
|
||||
/********** **********/
|
||||
/********** Brewery Utils **********/
|
||||
/********** **********/
|
||||
/******************************************/
|
||||
|
||||
// create empty World save Sections
|
||||
public static void createWorldSections(ConfigurationSection section) {
|
||||
for (World world : P.p.getServer().getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
worldName = getDxlName(worldName);
|
||||
} else {
|
||||
worldName = world.getUID().toString();
|
||||
}
|
||||
section.createSection(worldName);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the Block can be destroyed by the Player or something else (null)
|
||||
public static boolean blockDestroy(Block block, Player player, BarrelDestroyEvent.Reason reason) {
|
||||
switch (block.getType()) {
|
||||
case CAULDRON:
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
return true;
|
||||
case FENCE:
|
||||
case NETHER_FENCE:
|
||||
case ACACIA_FENCE:
|
||||
case BIRCH_FENCE:
|
||||
case DARK_OAK_FENCE:
|
||||
case IRON_FENCE:
|
||||
case JUNGLE_FENCE:
|
||||
case SPRUCE_FENCE:
|
||||
// remove barrel and throw potions on the ground
|
||||
Barrel barrel = Barrel.getBySpigot(block);
|
||||
if (barrel != null) {
|
||||
if (barrel.hasPermsDestroy(player, block, reason)) {
|
||||
barrel.remove(null, player);
|
||||
Material type = block.getType();
|
||||
if (type == Material.CAULDRON) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isFence(type)) {
|
||||
// remove barrel and throw potions on the ground
|
||||
Barrel barrel = Barrel.getBySpigot(block);
|
||||
if (barrel != null) {
|
||||
if (barrel.hasPermsDestroy(player, block, reason)) {
|
||||
barrel.remove(null, player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isSign(type)) {
|
||||
// remove small Barrels
|
||||
Barrel barrel2 = Barrel.getBySpigot(block);
|
||||
if (barrel2 != null) {
|
||||
if (!barrel2.isLarge()) {
|
||||
if (barrel2.hasPermsDestroy(player, block, reason)) {
|
||||
barrel2.remove(null, player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
barrel2.destroySign();
|
||||
}
|
||||
return true;
|
||||
case SIGN_POST:
|
||||
case WALL_SIGN:
|
||||
// remove small Barrels
|
||||
Barrel barrel2 = Barrel.getBySpigot(block);
|
||||
if (barrel2 != null) {
|
||||
if (!barrel2.isLarge()) {
|
||||
if (barrel2.hasPermsDestroy(player, block, reason)) {
|
||||
barrel2.remove(null, player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
barrel2.destroySign();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)){
|
||||
Barrel barrel3 = Barrel.getByWood(block);
|
||||
if (barrel3 != null) {
|
||||
if (barrel3.hasPermsDestroy(player, block, reason)) {
|
||||
barrel3.remove(block, player);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
case WOOD:
|
||||
case WOOD_STAIRS:
|
||||
case BIRCH_WOOD_STAIRS:
|
||||
case JUNGLE_WOOD_STAIRS:
|
||||
case SPRUCE_WOOD_STAIRS:
|
||||
case ACACIA_STAIRS:
|
||||
case DARK_OAK_STAIRS:
|
||||
Barrel barrel3 = Barrel.getByWood(block);
|
||||
if (barrel3 != null) {
|
||||
if (barrel3.hasPermsDestroy(player, block, reason)) {
|
||||
barrel3.remove(block, player);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************/
|
||||
/********** **********/
|
||||
/********** Other Utils **********/
|
||||
/********** **********/
|
||||
/******************************************/
|
||||
|
||||
// prints a list of Strings at the specified page
|
||||
public static void list(CommandSender sender, ArrayList<String> strings, int page) {
|
||||
int pages = (int) Math.ceil(strings.size() / 7F);
|
||||
if (page > pages || page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
sender.sendMessage(color("&7-------------- &f" + P.p.languageReader.get("Etc_Page") + " &6" + page + "&f/&6" + pages + " &7--------------"));
|
||||
|
||||
ListIterator<String> iter = strings.listIterator((page - 1) * 7);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (iter.hasNext()) {
|
||||
sender.sendMessage(color(iter.next()));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gets the Name of a DXL World
|
||||
public static String getDxlName(String worldName) {
|
||||
File dungeonFolder = new File(worldName);
|
||||
if (dungeonFolder.isDirectory()) {
|
||||
for (File file : dungeonFolder.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
if (file.getName().startsWith(".id_")) {
|
||||
return file.getName().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return worldName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static void saveFile(InputStream in, File dest, String name, boolean overwrite) throws IOException {
|
||||
if (in == null) return;
|
||||
if (!dest.exists()) {
|
||||
dest.mkdirs();
|
||||
}
|
||||
File result = new File(dest, name);
|
||||
if (result.exists()) {
|
||||
if (overwrite) {
|
||||
result.delete();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(result);
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
//copy the file content in bytes
|
||||
while ((length = in.read(buffer)) > 0){
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,14 +4,11 @@ import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||
import com.dre.brewery.api.events.barrel.BarrelCreateEvent;
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
||||
import com.dre.brewery.integration.CitadelBarrel;
|
||||
import com.dre.brewery.integration.GriefPreventionBarrel;
|
||||
import com.dre.brewery.integration.LWCBarrel;
|
||||
import com.dre.brewery.integration.LogBlockBarrel;
|
||||
import com.dre.brewery.lore.BrewLore;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@ -21,10 +18,6 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.Wood;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -142,7 +135,7 @@ public class Barrel implements InventoryHolder {
|
||||
if (plugin != null) {
|
||||
|
||||
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
||||
if (!isSign(event.getClickedBlock())) {
|
||||
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
||||
Block sign = getSignOfSpigot();
|
||||
// If the Barrel does not have a Sign, it cannot be locked
|
||||
if (!sign.equals(event.getClickedBlock())) {
|
||||
@ -410,14 +403,14 @@ public class Barrel implements InventoryHolder {
|
||||
inventory.clear();
|
||||
if (P.p.useLB && breaker != null) {
|
||||
try {
|
||||
LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation());
|
||||
LogBlockBarrel.breakBarrel(breaker, items, spigot.getLocation());
|
||||
} catch (Throwable e) {
|
||||
P.p.errorLog("Failed to Log Barrel-break to LogBlock!");
|
||||
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (event.shouldItemsDrop()) {
|
||||
if (event.willItemsDrop()) {
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
Brew brew = Brew.get(item);
|
||||
@ -462,7 +455,7 @@ public class Barrel implements InventoryHolder {
|
||||
|
||||
// Saves all data
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
Util.createWorldSections(config);
|
||||
BUtil.createWorldSections(config);
|
||||
|
||||
if (!barrels.isEmpty()) {
|
||||
int id = 0;
|
||||
@ -472,7 +465,7 @@ public class Barrel implements InventoryHolder {
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = Util.getDxlName(worldName) + "." + id;
|
||||
prefix = BUtil.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
@ -638,7 +631,7 @@ public class Barrel implements InventoryHolder {
|
||||
// the barrel needs to be formed correctly
|
||||
// flag force to also check if chunk is not loaded
|
||||
public Block getBrokenBlock(boolean force) {
|
||||
if (force || Util.isChunkLoaded(spigot)) {
|
||||
if (force || BUtil.isChunkLoaded(spigot)) {
|
||||
spigot = getSpigotOfSign(spigot);
|
||||
if (LegacyUtil.isSign(spigot.getType())) {
|
||||
return checkSBarrel();
|
||||
@ -825,7 +818,6 @@ public class Barrel implements InventoryHolder {
|
||||
P.p.debugLog("Barrel at " + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ()
|
||||
+ " has been destroyed unexpectedly, contents will drop");
|
||||
// remove the barrel if it was destroyed
|
||||
barrel.willDestroy(); // TODO Check if still needed
|
||||
barrel.remove(broken, null);
|
||||
} else {
|
||||
// Dont check this barrel again, its enough to check it once after every restart
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||
import com.dre.brewery.lore.*;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.BrewerInventory;
|
||||
@ -42,7 +42,7 @@ public class Brew {
|
||||
private boolean unlabeled;
|
||||
private boolean persistent; // Only for legacy
|
||||
private boolean immutable; // static/immutable potions should not be changed
|
||||
//private int lastUpdate; // last update in hours after install time
|
||||
private int lastUpdate; // last update in hours after install time
|
||||
|
||||
public Brew(BIngredients ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
@ -56,7 +56,7 @@ public class Brew {
|
||||
}
|
||||
|
||||
// loading with all values set
|
||||
public Brew(BIngredients ingredients, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable) {
|
||||
public Brew(BIngredients ingredients, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable, int lastUpdate) {
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
this.distillRuns = distillRuns;
|
||||
@ -64,6 +64,7 @@ public class Brew {
|
||||
this.wood = wood;
|
||||
this.unlabeled = unlabeled;
|
||||
this.immutable = immutable;
|
||||
this.lastUpdate = lastUpdate;
|
||||
setRecipeFromString(recipe);
|
||||
}
|
||||
|
||||
@ -77,6 +78,7 @@ public class Brew {
|
||||
if (meta instanceof PotionMeta && ((PotionMeta) meta).hasCustomEffect(PotionEffectType.REGENERATION)) {
|
||||
Brew brew = load(meta);
|
||||
if (brew != null) {
|
||||
// Load Legacy
|
||||
brew = getFromPotionEffect(((PotionMeta) meta), false);
|
||||
}
|
||||
return brew;
|
||||
@ -98,6 +100,7 @@ public class Brew {
|
||||
if (brew != null) {
|
||||
((PotionMeta) meta).removeCustomEffect(PotionEffectType.REGENERATION);
|
||||
} else {
|
||||
// Load Legacy and convert
|
||||
brew = getFromPotionEffect(((PotionMeta) meta), true);
|
||||
if (brew == null) return null;
|
||||
brew.save(meta);
|
||||
@ -113,6 +116,7 @@ public class Brew {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Legacy Brew Loading
|
||||
private static Brew getFromPotionEffect(PotionMeta potionMeta, boolean remove) {
|
||||
for (PotionEffect effect : potionMeta.getCustomEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.REGENERATION)) {
|
||||
@ -365,9 +369,8 @@ public class Brew {
|
||||
}
|
||||
|
||||
// Do some regular updates
|
||||
// Currently does nothing, but may be used to update something on this brew
|
||||
public void touch() {
|
||||
//lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
|
||||
lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
|
||||
}
|
||||
|
||||
public byte getDistillRuns() {
|
||||
@ -439,9 +442,9 @@ public class Brew {
|
||||
}
|
||||
}
|
||||
|
||||
/*public int getLastUpdate() {
|
||||
public int getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}*/
|
||||
}
|
||||
|
||||
// Distilling section ---------------
|
||||
|
||||
@ -459,6 +462,7 @@ public class Brew {
|
||||
// distill custom potion in given slot
|
||||
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
||||
if (immutable) return;
|
||||
//List<Consumer<Brew>> fcts = new ArrayList<>();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, BrewModifyEvent.Type.DISTILL);
|
||||
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||
if (modifyEvent.isCancelled()) return;
|
||||
@ -574,7 +578,7 @@ public class Brew {
|
||||
factor = 2;
|
||||
} else if (ageTime > 10) {
|
||||
factor = 2;
|
||||
factor += (float) ageTime / 10F;
|
||||
factor += ageTime / 10F;
|
||||
}
|
||||
if (wood > to) {
|
||||
wood -= time / factor;
|
||||
@ -723,8 +727,8 @@ public class Brew {
|
||||
}
|
||||
|
||||
// Load potion data from data file for backwards compatibility
|
||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat) {
|
||||
Brew brew = new Brew(ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, stat);
|
||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
||||
Brew brew = new Brew(ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
||||
brew.persistent = persistent;
|
||||
legacyPotions.put(uid, brew);
|
||||
}
|
||||
@ -751,7 +755,7 @@ public class Brew {
|
||||
if (hasRecipe()) {
|
||||
BrewLore lore = new BrewLore(this, potionMeta);
|
||||
lore.removeEffects();
|
||||
PotionColor.valueOf(currentRecipe.getColor()).colorBrew(potionMeta, item, canDistill());
|
||||
PotionColor.fromString(currentRecipe.getColor()).colorBrew(potionMeta, item, canDistill());
|
||||
} else {
|
||||
PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
|
||||
}
|
||||
@ -792,9 +796,9 @@ public class Brew {
|
||||
if (brew.immutable) {
|
||||
idConfig.set("stat", true);
|
||||
}
|
||||
/*if (brew.lastUpdate > 0) {
|
||||
if (brew.lastUpdate > 0) {
|
||||
idConfig.set("lastUpdate", brew.lastUpdate);
|
||||
}*/
|
||||
}
|
||||
// save the ingredients
|
||||
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.dre.brewery.BCauldron.EMPTY;
|
||||
import static com.dre.brewery.BCauldron.SOME;
|
||||
import static com.dre.brewery.BCauldron.FULL;
|
||||
|
||||
@SuppressWarnings("JavaReflectionMemberAccess")
|
||||
public class LegacyUtil {
|
||||
|
||||
@ -190,27 +194,27 @@ public class LegacyUtil {
|
||||
// 0 = empty, 1 = something in, 2 = full
|
||||
public static byte getFillLevel(Block block) {
|
||||
if (block.getType() != Material.CAULDRON) {
|
||||
return 0;
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
if (P.use1_13) {
|
||||
Levelled cauldron = ((Levelled) block.getBlockData());
|
||||
if (cauldron.getLevel() == 0) {
|
||||
return 0;
|
||||
return EMPTY;
|
||||
} else if (cauldron.getLevel() == cauldron.getMaximumLevel()) {
|
||||
return 2;
|
||||
return FULL;
|
||||
} else {
|
||||
return 1;
|
||||
return SOME;
|
||||
}
|
||||
|
||||
} else {
|
||||
Cauldron cauldron = (Cauldron) block.getState().getData();
|
||||
if (cauldron.isEmpty()) {
|
||||
return 0;
|
||||
return EMPTY;
|
||||
} else if (cauldron.isFull()) {
|
||||
return 2;
|
||||
return FULL;
|
||||
} else {
|
||||
return 1;
|
||||
return SOME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,8 @@ import com.dre.brewery.filedata.DataSave;
|
||||
import com.dre.brewery.filedata.DataUpdater;
|
||||
import com.dre.brewery.filedata.LanguageReader;
|
||||
import com.dre.brewery.filedata.UpdateChecker;
|
||||
import com.dre.brewery.integration.IntegrationListener;
|
||||
import com.dre.brewery.integration.LogBlockBarrel;
|
||||
import com.dre.brewery.integration.WGBarrel;
|
||||
import com.dre.brewery.integration.WGBarrel7;
|
||||
import com.dre.brewery.integration.WGBarrelNew;
|
||||
import com.dre.brewery.integration.WGBarrelOld;
|
||||
import com.dre.brewery.listeners.BlockListener;
|
||||
import com.dre.brewery.listeners.CauldronListener;
|
||||
import com.dre.brewery.listeners.CommandListener;
|
||||
import com.dre.brewery.listeners.EntityListener;
|
||||
import com.dre.brewery.listeners.InventoryListener;
|
||||
import com.dre.brewery.listeners.PlayerListener;
|
||||
import com.dre.brewery.listeners.WorldListener;
|
||||
import com.dre.brewery.integration.*;
|
||||
import com.dre.brewery.listeners.*;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -25,7 +14,6 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import com.dre.brewery.lore.LoreOutputStream;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -38,14 +26,11 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -360,7 +345,7 @@ public class P extends JavaPlugin {
|
||||
readData();
|
||||
|
||||
// Setup Metrics
|
||||
try {
|
||||
/*try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> Brew.potions.size()));
|
||||
@ -416,7 +401,7 @@ public class P extends JavaPlugin {
|
||||
}));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
// Listeners
|
||||
blockListener = new BlockListener();
|
||||
@ -592,9 +577,6 @@ public class P extends JavaPlugin {
|
||||
|
||||
// Third-Party
|
||||
useWG = config.getBoolean("useWorldGuard", true) && getServer().getPluginManager().isPluginEnabled("WorldGuard");
|
||||
useLWC = config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC");
|
||||
useGP = config.getBoolean("useGriefPrevention", true) && getServer().getPluginManager().isPluginEnabled("GriefPrevention");
|
||||
useLB = config.getBoolean("useLogBlock", false) && getServer().getPluginManager().isPluginEnabled("LogBlock");
|
||||
hasVault = getServer().getPluginManager().isPluginEnabled("Vault");
|
||||
|
||||
if (useWG) {
|
||||
@ -773,9 +755,9 @@ public class P extends JavaPlugin {
|
||||
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
|
||||
boolean persistent = section.getBoolean(uid + ".persist", false);
|
||||
boolean stat = section.getBoolean(uid + ".stat", false);
|
||||
//int lastUpdate = section.getInt("lastUpdate", 0);
|
||||
int lastUpdate = section.getInt("lastUpdate", 0);
|
||||
|
||||
Brew.loadLegacy(ingredients, parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat);
|
||||
Brew.loadLegacy(ingredients, parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -806,7 +788,7 @@ public class P extends JavaPlugin {
|
||||
|
||||
for (World world : p.getServer().getWorlds()) {
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
loadWorldData(Util.getDxlName(world.getName()), world);
|
||||
loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
} else {
|
||||
loadWorldData(world.getUID().toString(), world);
|
||||
}
|
||||
@ -967,7 +949,7 @@ public class P extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Util.saveFile(defconf, getDataFolder(), "config.yml", false);
|
||||
BUtil.saveFile(defconf, getDataFolder(), "config.yml", false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@ -988,8 +970,8 @@ public class P extends JavaPlugin {
|
||||
for (String l : new String[] {"de", "en", "fr", "it", "zh", "tw"}) {
|
||||
File lfold = new File(configs, l);
|
||||
try {
|
||||
Util.saveFile(getResource("config/" + (use1_13 ? "v13/" : "v12/") + l + "/config.yml"), lfold, "config.yml", overwrite);
|
||||
Util.saveFile(getResource("languages/" + l + ".yml"), languages, l + ".yml", false); // Never overwrite languages for now
|
||||
BUtil.saveFile(getResource("config/" + (use1_13 ? "v13/" : "v12/") + l + "/config.yml"), lfold, "config.yml", overwrite);
|
||||
BUtil.saveFile(getResource("languages/" + l + ".yml"), languages, l + ".yml", false); // Never overwrite languages for now
|
||||
} catch (IOException e) {
|
||||
if (!(l.equals("zh") || l.equals("tw"))) {
|
||||
e.printStackTrace();
|
||||
@ -1004,60 +986,8 @@ public class P extends JavaPlugin {
|
||||
return NumberUtils.toInt(string, 0);
|
||||
}
|
||||
|
||||
|
||||
// Returns true if the Block can be destroyed by the Player or something else (null)
|
||||
public boolean blockDestroy(Block block, Player player) {
|
||||
Material type = block.getType();
|
||||
if (type == Material.CAULDRON) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isFence(type)) {
|
||||
// remove barrel and throw potions on the ground
|
||||
Barrel barrel = Barrel.getBySpigot(block);
|
||||
if (barrel != null) {
|
||||
if (barrel.hasPermsDestroy(player)) {
|
||||
barrel.remove(null, player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isSign(type)) {
|
||||
// remove small Barrels
|
||||
Barrel barrel2 = Barrel.getBySpigot(block);
|
||||
if (barrel2 != null) {
|
||||
if (!barrel2.isLarge()) {
|
||||
if (barrel2.hasPermsDestroy(player)) {
|
||||
barrel2.remove(null, player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
barrel2.destroySign();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)){
|
||||
Barrel barrel3 = Barrel.getByWood(block);
|
||||
if (barrel3 != null) {
|
||||
if (barrel3.hasPermsDestroy(player)) {
|
||||
barrel3.remove(block, player);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String color(String msg) {
|
||||
return Util.color(msg);
|
||||
return BUtil.color(msg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,157 +0,0 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Util {
|
||||
|
||||
/********** Bukkit Utils **********/
|
||||
|
||||
// Check if the Chunk of a Block is loaded !without loading it in the process!
|
||||
public static boolean isChunkLoaded(Block block) {
|
||||
return block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4);
|
||||
}
|
||||
|
||||
public static String color(String msg) {
|
||||
if (msg != null) {
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Returns either uuid or Name of player, depending on bukkit version
|
||||
public static String playerString(Player player) {
|
||||
if (P.useUUID) {
|
||||
return player.getUniqueId().toString();
|
||||
} else {
|
||||
return player.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// returns the Player if online
|
||||
public static Player getPlayerfromString(String name) {
|
||||
if (P.useUUID) {
|
||||
try {
|
||||
return Bukkit.getPlayer(UUID.fromString(name));
|
||||
} catch (Exception e) {
|
||||
return Bukkit.getPlayerExact(name);
|
||||
}
|
||||
}
|
||||
return Bukkit.getPlayerExact(name);
|
||||
}
|
||||
|
||||
// Apply a Potion Effect, if player already has this effect, overwrite the existing effect.
|
||||
// Optionally only overwrite if the new one is stronger, i.e. has higher level or longer duration
|
||||
public static void reapplyPotionEffect(Player player, PotionEffect effect, boolean onlyIfStronger) {
|
||||
final PotionEffectType type = effect.getType();
|
||||
if (player.hasPotionEffect(type)) {
|
||||
PotionEffect plEffect;
|
||||
if (P.use1_11) {
|
||||
plEffect = player.getPotionEffect(type);
|
||||
} else {
|
||||
plEffect = player.getActivePotionEffects().stream().filter(e -> e.getType().equals(type)).findAny().get();
|
||||
}
|
||||
if (plEffect.getAmplifier() < effect.getAmplifier() || (plEffect.getAmplifier() == effect.getAmplifier() && plEffect.getDuration() < effect.getDuration())) {
|
||||
player.removePotionEffect(type);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
effect.apply(player);
|
||||
}
|
||||
|
||||
/********** Other Utils **********/
|
||||
|
||||
// prints a list of Strings at the specified page
|
||||
public static void list(CommandSender sender, ArrayList<String> strings, int page) {
|
||||
int pages = (int) Math.ceil(strings.size() / 7F);
|
||||
if (page > pages || page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
sender.sendMessage(color("&7-------------- &f" + P.p.languageReader.get("Etc_Page") + " &6" + page + "&f/&6" + pages + " &7--------------"));
|
||||
|
||||
ListIterator<String> iter = strings.listIterator((page - 1) * 7);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (iter.hasNext()) {
|
||||
sender.sendMessage(color(iter.next()));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gets the Name of a DXL World
|
||||
public static String getDxlName(String worldName) {
|
||||
File dungeonFolder = new File(worldName);
|
||||
if (dungeonFolder.isDirectory()) {
|
||||
for (File file : dungeonFolder.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
if (file.getName().startsWith(".id_")) {
|
||||
return file.getName().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return worldName;
|
||||
}
|
||||
|
||||
// create empty World save Sections
|
||||
public static void createWorldSections(ConfigurationSection section) {
|
||||
for (World world : P.p.getServer().getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
worldName = getDxlName(worldName);
|
||||
} else {
|
||||
worldName = world.getUID().toString();
|
||||
}
|
||||
section.createSection(worldName);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static void saveFile(InputStream in, File dest, String name, boolean overwrite) throws IOException {
|
||||
if (in == null) return;
|
||||
if (!dest.exists()) {
|
||||
dest.mkdirs();
|
||||
}
|
||||
File result = new File(dest, name);
|
||||
if (result.exists()) {
|
||||
if (overwrite) {
|
||||
result.delete();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(result);
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
//copy the file content in bytes
|
||||
while ((length = in.read(buffer)) > 0){
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
@ -140,7 +140,7 @@ public class Wakeup {
|
||||
locs.add("&6" + s + id + "&f" + s + ": " + world + " " + x + "," + y + "," + z);
|
||||
}
|
||||
}
|
||||
Util.list(sender, locs, page);
|
||||
BUtil.list(sender, locs, page);
|
||||
}
|
||||
|
||||
public static void check(CommandSender sender, int id, boolean all) {
|
||||
@ -228,7 +228,7 @@ public class Wakeup {
|
||||
|
||||
|
||||
public static void save(ConfigurationSection section, ConfigurationSection oldData) {
|
||||
Util.createWorldSections(section);
|
||||
BUtil.createWorldSections(section);
|
||||
|
||||
// loc is saved as a String in world sections with format x/y/z/pitch/yaw
|
||||
if (!wakeups.isEmpty()) {
|
||||
@ -245,7 +245,7 @@ public class Wakeup {
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = Util.getDxlName(worldName) + "." + id;
|
||||
prefix = BUtil.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = wakeup.loc.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.dre.brewery.api.events;
|
||||
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.LegacyUtil;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -40,7 +43,7 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
||||
}
|
||||
|
||||
// Get the item currently being added to the cauldron by the player
|
||||
// Can be changed directly or with the setter
|
||||
// Can be changed directly (mutable) or with the setter Method
|
||||
// The amount is ignored and always one added
|
||||
public ItemStack getIngredient() {
|
||||
return ingredient;
|
||||
@ -55,7 +58,7 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
// If the amount of the item in the players hand should be decreased
|
||||
// Default true
|
||||
public boolean shouldTakeItem() {
|
||||
public boolean willTakeItem() {
|
||||
return takeItem;
|
||||
}
|
||||
|
||||
@ -64,22 +67,21 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
||||
this.takeItem = takeItem;
|
||||
}
|
||||
|
||||
// Get the MaterialData of the Cauldron
|
||||
// Get the BlockData of the Cauldron
|
||||
// May be null if the Cauldron does not exist anymore
|
||||
public Cauldron getCauldronData() {
|
||||
BlockState state = block.getState();
|
||||
if (state != null) {
|
||||
MaterialData data = state.getData();
|
||||
if (data instanceof Cauldron) {
|
||||
return ((Cauldron) state);
|
||||
}
|
||||
public Levelled getCauldronData() {
|
||||
BlockData data = block.getBlockData();
|
||||
if (data instanceof Levelled) {
|
||||
return (Levelled) data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the Water Fill level of the Cauldron
|
||||
// 0 = empty, 1 = something in, 2 = full
|
||||
public int getFillLevel() {
|
||||
return BCauldron.getFillLevel(block);
|
||||
// Can use BCauldron.EMPTY, BCauldron.SOME, BCauldron.FULL
|
||||
public byte getFillLevel() {
|
||||
return LegacyUtil.getFillLevel(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ public class PlayerPushEvent extends PlayerEvent implements Cancellable {
|
||||
this.bPlayer = bPlayer;
|
||||
}
|
||||
|
||||
public BPlayer getbPlayer() {
|
||||
public BPlayer getBPlayer() {
|
||||
return bPlayer;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class BarrelRemoveEvent extends BarrelEvent {
|
||||
super(barrel);
|
||||
}
|
||||
|
||||
public boolean shouldItemsDrop() {
|
||||
public boolean willItemsDrop() {
|
||||
return itemsDrop;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Type type;
|
||||
private boolean cancelled;
|
||||
//private List<Consumer<Brew>> fcts;
|
||||
|
||||
public BrewModifyEvent(Brew brew, Type type) {
|
||||
super(brew);
|
||||
@ -22,6 +23,10 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
|
||||
return type;
|
||||
}
|
||||
|
||||
/*public void addModification(Consumer<Brew> predicate) {
|
||||
fcts.add(predicate);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
@ -4,7 +4,7 @@ package com.dre.brewery.filedata;
|
||||
import java.io.File;
|
||||
|
||||
import com.dre.brewery.MCBarrel;
|
||||
import com.dre.brewery.Util;
|
||||
import com.dre.brewery.BUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -157,7 +157,7 @@ public class DataSave extends BukkitRunnable {
|
||||
for (World world : P.p.getServer().getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
worldName = Util.getDxlName(worldName);
|
||||
worldName = BUtil.getDxlName(worldName);
|
||||
root.set("Worlds." + worldName, 0);
|
||||
} else {
|
||||
worldName = world.getUID().toString();
|
||||
|
@ -31,7 +31,6 @@ public class GriefPreventionBarrel {
|
||||
playerData.lastClaim = claim;
|
||||
String noContainersReason = claim.allowContainers(player);
|
||||
if (noContainersReason != null) {
|
||||
brewery.msg(player, brewery.languageReader.get("Error_NoBarrelAccess") + " " + noContainersReason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.dre.brewery.P;
|
||||
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -25,10 +26,16 @@ public class IntegrationListener implements Listener {
|
||||
} catch (Throwable e) {
|
||||
event.setCancelled(true);
|
||||
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 to 7.0 of WorldGuard!");
|
||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||
e.printStackTrace();
|
||||
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||
P.p.msg(player, "&cWorldGuard check Error, Brewery was tested with up to v7.0 of Worldguard");
|
||||
P.p.msg(player, "&cSet &7useWorldGuard: false &cin the config and /brew reload");
|
||||
} else {
|
||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,10 +52,16 @@ public class IntegrationListener implements Listener {
|
||||
} catch (Throwable e) {
|
||||
event.setCancelled(true);
|
||||
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
|
||||
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.4");
|
||||
P.p.errorLog("Brewery was tested with GriefPrevention v14.5 - v16.9");
|
||||
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
|
||||
e.printStackTrace();
|
||||
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||
P.p.msg(player, "&cGriefPrevention check Error, Brewery was tested with up to v16.9 of GriefPrevention");
|
||||
P.p.msg(player, "&cSet &7useGriefPrevention: false &cin the config and /brew reload");
|
||||
} else {
|
||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,7 +82,13 @@ public class IntegrationListener implements Listener {
|
||||
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
||||
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
||||
e.printStackTrace();
|
||||
P.p.msg(event.getPlayerOptional(), "&cError breaking Barrel, please report to an Admin!");
|
||||
Player player = event.getPlayerOptional();
|
||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||
P.p.msg(player, "&cLWC check Error, Brewery was tested with up to v4.5.0 of LWC");
|
||||
P.p.msg(player, "&cSet &7useLWC: false &cin the config and /brew reload");
|
||||
} else {
|
||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
@ -55,12 +55,7 @@ public class WGBarrel7 implements WGBarrel {
|
||||
|
||||
RegionQuery query = platform.getRegionContainer().createQuery();
|
||||
|
||||
if (!query.testBuild(new Location(world, spigot.getX(), spigot.getY(), spigot.getZ()), wg.wrapPlayer(player), Flags.USE, Flags.CHEST_ACCESS)) {
|
||||
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return query.testBuild(new Location(world, spigot.getX(), spigot.getY(), spigot.getZ()), wg.wrapPlayer(player), Flags.USE, Flags.CHEST_ACCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dre.brewery.Util;
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -12,12 +9,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.dre.brewery.BIngredients;
|
||||
import com.dre.brewery.BRecipe;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Wakeup;
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.Brew;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CommandListener implements CommandExecutor {
|
||||
|
||||
@ -168,7 +161,7 @@ public class CommandListener implements CommandExecutor {
|
||||
p.msg(sender, "&6" + p.getDescription().getName() + " v" + p.getDescription().getVersion());
|
||||
}
|
||||
|
||||
Util.list(sender, commands, page);
|
||||
BUtil.list(sender, commands, page);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,6 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.BRecipe;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.MCBarrel;
|
||||
import com.dre.brewery.integration.LogBlockBarrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.lore.BrewLore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -19,15 +13,7 @@ import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.BrewEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.BrewerInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@ -38,7 +24,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -203,13 +188,25 @@ public class InventoryListener implements Listener {
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
item = inv.getItem(slot);
|
||||
if (item != null) {
|
||||
if (item.getType() == Material.POTION) {
|
||||
if (item.hasItemMeta()) {
|
||||
Brew pot = Brew.get(item);
|
||||
if (pot != null && (!distill || pot.canDistill())) { // need at least one distillable potion.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
contents[slot] = Brew.get(item);
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
private byte hasCustom(BrewerInventory brewer) {
|
||||
ItemStack item = brewer.getItem(3); // ingredient
|
||||
boolean glowstone = (item != null && Material.GLOWSTONE_DUST == item.getType()); // need dust in the top slot.
|
||||
byte customFound = 0;
|
||||
for (Brew brew : getDistillContents(brewer)) {
|
||||
if (brew != null) {
|
||||
if (!glowstone) {
|
||||
return 1;
|
||||
}
|
||||
if (brew.canDistill()) {
|
||||
return 2;
|
||||
} else {
|
||||
customFound = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,24 +228,14 @@ public class InventoryListener implements Listener {
|
||||
|
||||
private boolean runDistill(BrewerInventory inv) {
|
||||
boolean custom = false;
|
||||
Boolean[] contents = new Boolean[3];
|
||||
while (slot < 3) {
|
||||
item = inv.getItem(slot);
|
||||
contents[slot] = false;
|
||||
if (item != null) {
|
||||
if (item.getType() == Material.POTION) {
|
||||
if (item.hasItemMeta()) {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
// has custom potion in "slot"
|
||||
if (brew.canDistill()) {
|
||||
// is further distillable
|
||||
contents[slot] = true;
|
||||
custom = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Brew[] contents = getDistillContents(inv);
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
if (contents[slot] == null) continue;
|
||||
if (contents[slot].canDistill()) {
|
||||
// is further distillable
|
||||
custom = true;
|
||||
} else {
|
||||
contents[slot] = null;
|
||||
}
|
||||
}
|
||||
if (custom) {
|
||||
@ -299,7 +286,7 @@ public class InventoryListener implements Listener {
|
||||
P.p.log(potion.getLore().get(0).replaceAll("§", ""));
|
||||
P.p.log("similar to beispiel? " + BRecipe.get("Beispiel").createBrew(10).isSimilar(brew));
|
||||
|
||||
//brew.touch();
|
||||
brew.touch();
|
||||
|
||||
/*try {
|
||||
DataInputStream in = new DataInputStream(new Base91DecoderStream(new LoreLoadStream(potion)));
|
||||
@ -457,18 +444,6 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (P.p.useLB) {
|
||||
if (event.getInventory().getHolder() instanceof Barrel) {
|
||||
try {
|
||||
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
|
||||
} catch (Exception e) {
|
||||
P.p.errorLog("Failed to Log Barrel to LogBlock!");
|
||||
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!P.use1_14) return;
|
||||
|
||||
// Barrel Closing Sound
|
||||
|
@ -1,13 +1,6 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.BIngredients;
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Wakeup;
|
||||
import com.dre.brewery.Words;
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.filedata.UpdateChecker;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
|
@ -3,7 +3,7 @@ package com.dre.brewery.listeners;
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Util;
|
||||
import com.dre.brewery.BUtil;
|
||||
import com.dre.brewery.filedata.DataSave;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -19,7 +19,7 @@ public class WorldListener implements Listener {
|
||||
World world = event.getWorld();
|
||||
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
P.p.loadWorldData(Util.getDxlName(world.getName()), world);
|
||||
P.p.loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
} else {
|
||||
P.p.loadWorldData(world.getUID().toString(), world);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user