mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-14 10:15:38 +01:00
Refractoring
This commit is contained in:
parent
595df50ca5
commit
7c0dcefb1b
@ -9,12 +9,18 @@ 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.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class BCauldron {
|
||||
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
||||
private static Set<UUID> plInteracted = new HashSet<>();
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>(); // TODO find best Collection
|
||||
|
||||
private BIngredients ingredients = new BIngredients();
|
||||
@ -95,62 +101,57 @@ public class BCauldron {
|
||||
}
|
||||
|
||||
// fills players bottle with cooked brew
|
||||
public static boolean fill(Player player, Block block) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
if (!player.hasPermission("brewery.cauldron.fill")) {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoCauldronFill"));
|
||||
return true;
|
||||
public boolean fill(Player player, Block block) {
|
||||
if (!player.hasPermission("brewery.cauldron.fill")) {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoCauldronFill"));
|
||||
return true;
|
||||
}
|
||||
ItemStack potion = ingredients.cook(state);
|
||||
if (potion == null) return false;
|
||||
|
||||
if (P.use1_13) {
|
||||
BlockData data = block.getBlockData();
|
||||
Levelled cauldron = ((Levelled) data);
|
||||
if (cauldron.getLevel() <= 0) {
|
||||
bcauldrons.remove(this);
|
||||
return false;
|
||||
}
|
||||
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
|
||||
if (potion != null) {
|
||||
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 (P.use1_13) {
|
||||
BlockData data = block.getBlockData();
|
||||
Levelled cauldron = ((Levelled) data);
|
||||
if (cauldron.getLevel() <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
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) {
|
||||
bcauldrons.remove(this);
|
||||
} else {
|
||||
someRemoved = true;
|
||||
}
|
||||
|
||||
if (cauldron.getLevel() <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
}
|
||||
} else {
|
||||
byte data = block.getData();
|
||||
if (data > 3) {
|
||||
data = 3;
|
||||
} else if (data <= 0) {
|
||||
bcauldrons.remove(this);
|
||||
return false;
|
||||
}
|
||||
data -= 1;
|
||||
LegacyUtil.setData(block, data);
|
||||
|
||||
} else {
|
||||
byte data = block.getData();
|
||||
if (data > 3) {
|
||||
data = 3;
|
||||
} else if (data <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
return false;
|
||||
}
|
||||
data -= 1;
|
||||
LegacyUtil.setData(block, data);
|
||||
|
||||
if (data == 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
}
|
||||
}
|
||||
// Bukkit Bug, inventory not updating while in event so this
|
||||
// will delay the give
|
||||
// but could also just use deprecated updateInventory()
|
||||
giveItem(player, potion);
|
||||
// player.getInventory().addItem(potion);
|
||||
// player.getInventory().updateInventory();
|
||||
return true;
|
||||
if (data == 0) {
|
||||
bcauldrons.remove(this);
|
||||
} else {
|
||||
someRemoved = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// Bukkit Bug, inventory not updating while in event so this
|
||||
// will delay the give
|
||||
// but could also just use deprecated updateInventory()
|
||||
giveItem(player, potion);
|
||||
// player.getInventory().addItem(potion);
|
||||
// player.getInventory().updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
// prints the current cooking time to the player
|
||||
@ -169,6 +170,129 @@ public class BCauldron {
|
||||
}
|
||||
}
|
||||
|
||||
public static void clickCauldron(PlayerInteractEvent event) {
|
||||
Material materialInHand = event.getMaterial();
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
|
||||
if (materialInHand == null || materialInHand == Material.AIR || materialInHand == Material.BUCKET) {
|
||||
return;
|
||||
|
||||
} else if (materialInHand == LegacyUtil.CLOCK) {
|
||||
printTime(player, clickedBlock);
|
||||
return;
|
||||
|
||||
// fill a glass bottle with potion
|
||||
} else if (materialInHand == Material.GLASS_BOTTLE) {
|
||||
if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) {
|
||||
BCauldron bcauldron = get(clickedBlock);
|
||||
if (bcauldron != null) {
|
||||
if (bcauldron.fill(player, clickedBlock)) {
|
||||
event.setCancelled(true);
|
||||
if (player.hasPermission("brewery.cauldron.fill")) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
setItemInHand(event, Material.AIR, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
|
||||
// reset cauldron when refilling to prevent unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (!P.use1_9) {
|
||||
// We catch >=1.9 cases in the Cauldron Listener
|
||||
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if fire alive below cauldron when adding ingredients
|
||||
Block down = clickedBlock.getRelative(BlockFace.DOWN);
|
||||
if (LegacyUtil.isFireForCauldron(down)) {
|
||||
|
||||
event.setCancelled(true);
|
||||
boolean handSwap = false;
|
||||
|
||||
// Interact event is called twice!!!?? in 1.9, once for each hand.
|
||||
// Certain Items in Hand cause one of them to be cancelled or not called at all sometimes.
|
||||
// We mark if a player had the event for the main hand
|
||||
// If not, we handle the main hand in the event for the off hand
|
||||
if (P.use1_9) {
|
||||
if (event.getHand() == EquipmentSlot.HAND) {
|
||||
final UUID id = player.getUniqueId();
|
||||
plInteracted.add(id);
|
||||
P.p.getServer().getScheduler().runTask(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plInteracted.remove(id);
|
||||
}
|
||||
});
|
||||
} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
if (!plInteracted.remove(player.getUniqueId())) {
|
||||
item = player.getInventory().getItemInMainHand();
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
materialInHand = item.getType();
|
||||
handSwap = true;
|
||||
} else {
|
||||
item = event.getItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item == null) return;
|
||||
|
||||
// add ingredient to cauldron that meet the previous conditions
|
||||
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
|
||||
if (player.hasPermission("brewery.cauldron.insert")) {
|
||||
if (ingredientAdd(clickedBlock, item, player)) {
|
||||
boolean isBucket = item.getType().equals(Material.WATER_BUCKET)
|
||||
|| item.getType().equals(Material.LAVA_BUCKET)
|
||||
|| item.getType().equals(Material.MILK_BUCKET);
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
|
||||
if (isBucket) {
|
||||
giveItem(player, new ItemStack(Material.BUCKET));
|
||||
}
|
||||
} else {
|
||||
if (isBucket) {
|
||||
setItemInHand(event, Material.BUCKET, handSwap);
|
||||
} else {
|
||||
setItemInHand(event, Material.AIR, handSwap);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoCauldronInsert"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
// reset to normal cauldron
|
||||
public static boolean remove(Block block) {
|
||||
if (LegacyUtil.getFillLevel(block) != EMPTY) {
|
||||
|
202
src/com/dre/brewery/BDistiller.java
Normal file
202
src/com/dre/brewery/BDistiller.java
Normal file
@ -0,0 +1,202 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.BrewerInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Updated for 1.9 to replicate the "Brewing" process for distilling.
|
||||
* Because of how metadata has changed, the brewer no longer triggers as previously described.
|
||||
* So, I've added some event tracking and manual forcing of the brewing "animation" if the
|
||||
* set of ingredients in the brewer can be distilled.
|
||||
* Nothing here should interfere with vanilla brewing.
|
||||
*
|
||||
* @author ProgrammerDan (1.9 distillation update only)
|
||||
*/
|
||||
public class BDistiller {
|
||||
|
||||
private static final int DISTILLTIME = 400;
|
||||
private static Map<Block, BDistiller> trackedDistillers = new HashMap<>();
|
||||
|
||||
private int taskId;
|
||||
private int runTime = -1;
|
||||
private int brewTime = -1;
|
||||
private Block standBlock;
|
||||
private int fuel;
|
||||
|
||||
public BDistiller(Block standBlock, int fuel) {
|
||||
this.standBlock = standBlock;
|
||||
this.fuel = fuel;
|
||||
}
|
||||
|
||||
public void cancelDistill() {
|
||||
Bukkit.getScheduler().cancelTask(taskId); // cancel prior
|
||||
}
|
||||
|
||||
public void start() {
|
||||
taskId = new DistillRunnable().runTaskTimer(P.p, 2L, 1L).getTaskId();
|
||||
}
|
||||
|
||||
public static void distillerClick(InventoryClickEvent event) {
|
||||
BrewerInventory standInv = (BrewerInventory) event.getInventory();
|
||||
final Block standBlock = standInv.getHolder().getBlock();
|
||||
|
||||
// If we were already tracking the brewer, cancel any ongoing event due to the click.
|
||||
BDistiller distiller = trackedDistillers.get(standBlock);
|
||||
if (distiller != null) {
|
||||
distiller.cancelDistill();
|
||||
standInv.getHolder().setBrewingTime(0); // Fixes brewing continuing without fuel for normal potions
|
||||
standInv.getHolder().update();
|
||||
}
|
||||
final int fuel = standInv.getHolder().getFuelLevel();
|
||||
|
||||
// Now check if we should bother to track it.
|
||||
trackedDistillers.put(standBlock, new BDistiller(standBlock, fuel)).start();
|
||||
}
|
||||
|
||||
// Returns a Brew or null for every Slot in the BrewerInventory
|
||||
public static Brew[] getDistillContents(BrewerInventory inv) {
|
||||
ItemStack item;
|
||||
Brew[] contents = new Brew[3];
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
item = inv.getItem(slot);
|
||||
if (item != null) {
|
||||
contents[slot] = Brew.get(item);
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
public static byte hasBrew(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return customFound;
|
||||
}
|
||||
|
||||
public static boolean runDistill(BrewerInventory inv) {
|
||||
boolean custom = false;
|
||||
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) {
|
||||
Brew.distillAll(inv, contents);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getLongestDistillTime(BrewerInventory inv) {
|
||||
int bestTime = 0;
|
||||
int time;
|
||||
Brew[] contents = getDistillContents(inv);
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
if (contents[slot] == null) continue;
|
||||
time = contents[slot].getDistillTimeNextRun();
|
||||
if (time == 0) {
|
||||
// Undefined Potion needs 40 seconds
|
||||
time = 800;
|
||||
}
|
||||
if (time > bestTime) {
|
||||
bestTime = time;
|
||||
}
|
||||
}
|
||||
if (bestTime > 0) {
|
||||
return bestTime;
|
||||
}
|
||||
return 800;
|
||||
}
|
||||
|
||||
public class DistillRunnable extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BlockState now = standBlock.getState();
|
||||
if (now instanceof BrewingStand) {
|
||||
BrewingStand stand = (BrewingStand) now;
|
||||
if (brewTime == -1) { // only check at the beginning (and end) for distillables
|
||||
switch (hasBrew(stand.getInventory())) {
|
||||
case 1:
|
||||
// Custom potion but not for distilling. Stop any brewing and cancel this task
|
||||
if (stand.getBrewingTime() > 0) {
|
||||
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
|
||||
stand.setBrewingTime(Short.MAX_VALUE);
|
||||
} else {
|
||||
// Brewing time is sent and stored as short
|
||||
// This sends a negative short value to the Client
|
||||
// In the client the Brewer will look like it is not doing anything
|
||||
stand.setBrewingTime(Short.MAX_VALUE << 1);
|
||||
}
|
||||
stand.setFuelLevel(fuel);
|
||||
stand.update();
|
||||
}
|
||||
case 0:
|
||||
// No custom potion, cancel and ignore
|
||||
this.cancel();
|
||||
trackedDistillers.remove(standBlock);
|
||||
P.p.debugLog("nothing to distill");
|
||||
return;
|
||||
default:
|
||||
runTime = getLongestDistillTime(stand.getInventory());
|
||||
brewTime = runTime;
|
||||
P.p.debugLog("using brewtime: " + runTime);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
brewTime--; // count down.
|
||||
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
|
||||
|
||||
if (brewTime <= 1) { // Done!
|
||||
stand.setBrewingTime(0);
|
||||
stand.update();
|
||||
BrewerInventory brewer = stand.getInventory();
|
||||
if (!runDistill(brewer)) {
|
||||
this.cancel();
|
||||
trackedDistillers.remove(standBlock);
|
||||
P.p.debugLog("All done distilling");
|
||||
} else {
|
||||
brewTime = -1; // go again.
|
||||
P.p.debugLog("Can distill more! Continuing.");
|
||||
}
|
||||
} else {
|
||||
stand.update();
|
||||
}
|
||||
} else {
|
||||
this.cancel();
|
||||
trackedDistillers.remove(standBlock);
|
||||
P.p.debugLog("The block was replaced; not a brewing stand.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.dre.brewery.api.events.PlayerDrinkEffectEvent;
|
||||
import com.dre.brewery.api.events.PlayerPukeEvent;
|
||||
import com.dre.brewery.api.events.PlayerPushEvent;
|
||||
import com.dre.brewery.api.events.brew.BrewDrinkEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -34,17 +35,6 @@ public class BPlayer {
|
||||
private static Method gh;
|
||||
private static Field age;
|
||||
|
||||
// Settings
|
||||
public static Map<Material, Integer> drainItems = new HashMap<>();// DrainItem Material and Strength
|
||||
public static Material pukeItem;
|
||||
public static int pukeDespawntime;
|
||||
public static int hangoverTime;
|
||||
public static boolean overdrinkKick;
|
||||
public static boolean enableHome;
|
||||
public static boolean enableLoginDisallow;
|
||||
public static boolean enablePuke;
|
||||
public static String homeType;
|
||||
|
||||
private int quality = 0;// = quality of drunkeness * drunkeness
|
||||
private int drunkeness = 0;// = amount of drunkeness
|
||||
private int offlineDrunk = 0;// drunkeness when gone offline
|
||||
@ -191,7 +181,7 @@ public class BPlayer {
|
||||
public void drinkCap(Player player) {
|
||||
quality = getQuality() * 100;
|
||||
drunkeness = 100;
|
||||
if (overdrinkKick && !player.hasPermission("brewery.bypass.overdrink")) {
|
||||
if (BConfig.overdrinkKick && !player.hasPermission("brewery.bypass.overdrink")) {
|
||||
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> passOut(player), 1);
|
||||
} else {
|
||||
addPuke(player, 60 + (int) (Math.random() * 60.0));
|
||||
@ -209,7 +199,7 @@ public class BPlayer {
|
||||
|
||||
// Eat something to drain the drunkeness
|
||||
public void drainByItem(Player player, Material mat) {
|
||||
int strength = drainItems.get(mat);
|
||||
int strength = BConfig.drainItems.get(mat);
|
||||
if (drain(player, strength)) {
|
||||
remove(player);
|
||||
}
|
||||
@ -233,7 +223,7 @@ public class BPlayer {
|
||||
}
|
||||
quality = getQuality();
|
||||
if (drunkeness <= -offlineDrunk) {
|
||||
return drunkeness <= -hangoverTime;
|
||||
return drunkeness <= -BConfig.hangoverTime;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -301,7 +291,7 @@ public class BPlayer {
|
||||
if (drunkeness <= 70) {
|
||||
return 0;
|
||||
}
|
||||
if (!enableLoginDisallow) {
|
||||
if (!BConfig.enableLoginDisallow) {
|
||||
if (drunkeness <= 100) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -342,7 +332,7 @@ public class BPlayer {
|
||||
public void login(final Player player) {
|
||||
if (drunkeness < 10) {
|
||||
if (offlineDrunk > 60) {
|
||||
if (enableHome && !player.hasPermission("brewery.bypass.teleport")) {
|
||||
if (BConfig.enableHome && !player.hasPermission("brewery.bypass.teleport")) {
|
||||
goHome(player);
|
||||
}
|
||||
}
|
||||
@ -368,6 +358,7 @@ public class BPlayer {
|
||||
}
|
||||
|
||||
public void goHome(final Player player) {
|
||||
String homeType = BConfig.homeType;
|
||||
if (homeType != null) {
|
||||
Location home = null;
|
||||
if (homeType.equalsIgnoreCase("bed")) {
|
||||
@ -407,7 +398,7 @@ public class BPlayer {
|
||||
|
||||
// make a Player puke "count" items
|
||||
public static void addPuke(Player player, int count) {
|
||||
if (!enablePuke) {
|
||||
if (!BConfig.enablePuke) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -450,8 +441,8 @@ public class BPlayer {
|
||||
if (pukeRand == null) {
|
||||
pukeRand = new Random();
|
||||
}
|
||||
if (pukeItem == null || pukeItem == Material.AIR) {
|
||||
pukeItem = Material.SOUL_SAND;
|
||||
if (BConfig.pukeItem == null || BConfig.pukeItem == Material.AIR) {
|
||||
BConfig.pukeItem = Material.SOUL_SAND;
|
||||
}
|
||||
Location loc = player.getLocation();
|
||||
loc.setY(loc.getY() + 1.1);
|
||||
@ -460,11 +451,12 @@ public class BPlayer {
|
||||
Vector direction = loc.getDirection();
|
||||
direction.multiply(0.5);
|
||||
loc.add(direction);
|
||||
Item item = player.getWorld().dropItem(loc, new ItemStack(pukeItem));
|
||||
Item item = player.getWorld().dropItem(loc, new ItemStack(BConfig.pukeItem));
|
||||
item.setVelocity(direction);
|
||||
item.setPickupDelay(32767); // Item can never be picked up when pickup delay is 32767
|
||||
//item.setTicksLived(6000 - pukeDespawntime); // Well this does not work...
|
||||
if (modAge) {
|
||||
int pukeDespawntime = BConfig.pukeDespawntime;
|
||||
if (pukeDespawntime >= 5800) {
|
||||
return;
|
||||
}
|
||||
@ -494,7 +486,7 @@ public class BPlayer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
modAge = false;
|
||||
P.p.errorLog("Failed to set Despawn Time on item " + pukeItem.name());
|
||||
P.p.errorLog("Failed to set Despawn Time on item " + BConfig.pukeItem.name());
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,7 +621,7 @@ public class BPlayer {
|
||||
|
||||
bplayer.drunkEffects(player);
|
||||
|
||||
if (enablePuke) {
|
||||
if (BConfig.enablePuke) {
|
||||
bplayer.drunkPuke(player);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -54,7 +55,7 @@ public class BRecipe {
|
||||
if (matParts.length == 2) {
|
||||
durability = (short) P.p.parseInt(matParts[1]);
|
||||
}
|
||||
if (mat == null && P.p.hasVault) {
|
||||
if (mat == null && BConfig.hasVault) {
|
||||
try {
|
||||
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(matParts[0]);
|
||||
if (vaultItem != null) {
|
||||
@ -247,6 +248,7 @@ public class BRecipe {
|
||||
|
||||
/**
|
||||
* Create a Potion from this Recipe with best values. Quality can be set, but will reset to 10 if put in a barrel
|
||||
*
|
||||
* @param quality The Quality of the Brew
|
||||
* @return The Created Item
|
||||
*/
|
||||
@ -256,6 +258,7 @@ public class BRecipe {
|
||||
|
||||
/**
|
||||
* Create a Brew from this Recipe with best values. Quality can be set, but will reset to 10 if put in a barrel
|
||||
*
|
||||
* @param quality The Quality of the Brew
|
||||
* @return The created Brew
|
||||
*/
|
||||
|
@ -4,11 +4,14 @@ 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.filedata.BConfig;
|
||||
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.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@ -130,35 +133,6 @@ public class Barrel implements InventoryHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event != null && P.p.useLWC) {
|
||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("LWC");
|
||||
if (plugin != null) {
|
||||
|
||||
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
||||
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())) {
|
||||
try {
|
||||
return LWCBarrel.checkAccess(player, sign, event, plugin);
|
||||
} catch (Throwable e) {
|
||||
P.p.errorLog("Failed to Check LWC for Barrel Open Permissions!");
|
||||
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();
|
||||
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 breaking Barrel, please report to an Admin!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -204,7 +178,7 @@ public class Barrel implements InventoryHolder {
|
||||
// reset barreltime, potions have new age
|
||||
time = 0;
|
||||
|
||||
if (P.p.useLB) {
|
||||
if (BConfig.useLB) {
|
||||
try {
|
||||
LogBlockBarrel.openBarrel(player, inventory, spigot.getLocation());
|
||||
} catch (Throwable e) {
|
||||
@ -216,6 +190,27 @@ public class Barrel implements InventoryHolder {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void playOpeningSound() {
|
||||
float randPitch = (float) (Math.random() * 0.1);
|
||||
if (isLarge()) {
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.4f, 0.55f + randPitch);
|
||||
//getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.5f, 0.6f + randPitch);
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 0.4f, 0.45f + randPitch);
|
||||
} else {
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_OPEN, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||
}
|
||||
}
|
||||
|
||||
public void playClosingSound() {
|
||||
float randPitch = (float) (Math.random() * 0.1);
|
||||
if (isLarge()) {
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.5f + randPitch);
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.2f, 0.6f + randPitch);
|
||||
} else {
|
||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
@ -401,7 +396,7 @@ public class Barrel implements InventoryHolder {
|
||||
}
|
||||
ItemStack[] items = inventory.getContents();
|
||||
inventory.clear();
|
||||
if (P.p.useLB && breaker != null) {
|
||||
if (BConfig.useLB && breaker != null) {
|
||||
try {
|
||||
LogBlockBarrel.breakBarrel(breaker, items, spigot.getLocation());
|
||||
} catch (Throwable e) {
|
||||
@ -439,93 +434,11 @@ public class Barrel implements InventoryHolder {
|
||||
barrels.remove(this);
|
||||
}
|
||||
|
||||
//unloads barrels that are in a unloading world
|
||||
public static void onUnload(String name) {
|
||||
for (Barrel barrel : barrels) {
|
||||
if (barrel.spigot.getWorld().getName().equals(name)) {
|
||||
barrels.remove(barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the Sign of a Large Barrel gets destroyed, set signOffset to 0
|
||||
public void destroySign() {
|
||||
signoffset = 0;
|
||||
}
|
||||
|
||||
// Saves all data
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
BUtil.createWorldSections(config);
|
||||
|
||||
if (!barrels.isEmpty()) {
|
||||
int id = 0;
|
||||
for (Barrel barrel : barrels) {
|
||||
|
||||
String worldName = barrel.spigot.getWorld().getName();
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = BUtil.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
|
||||
// block: x/y/z
|
||||
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());
|
||||
|
||||
if (barrel.signoffset != 0) {
|
||||
config.set(prefix + ".sign", barrel.signoffset);
|
||||
}
|
||||
if (barrel.stairsloc != null && barrel.stairsloc.length > 0) {
|
||||
StringBuilder st = new StringBuilder();
|
||||
for (int i : barrel.stairsloc) {
|
||||
st.append(i).append(",");
|
||||
}
|
||||
config.set(prefix + ".st", st.substring(0, st.length() - 1));
|
||||
}
|
||||
if (barrel.woodsloc != null && barrel.woodsloc.length > 0) {
|
||||
StringBuilder wo = new StringBuilder();
|
||||
for (int i : barrel.woodsloc) {
|
||||
wo.append(i).append(",");
|
||||
}
|
||||
config.set(prefix + ".wo", wo.substring(0, wo.length() - 1));
|
||||
}
|
||||
|
||||
if (barrel.inventory != null) {
|
||||
int slot = 0;
|
||||
ItemStack item;
|
||||
ConfigurationSection invConfig = null;
|
||||
while (slot < barrel.inventory.getSize()) {
|
||||
item = barrel.inventory.getItem(slot);
|
||||
if (item != null) {
|
||||
if (invConfig == null) {
|
||||
if (barrel.time != 0) {
|
||||
config.set(prefix + ".time", barrel.time);
|
||||
}
|
||||
invConfig = config.createSection(prefix + ".inv");
|
||||
}
|
||||
// ItemStacks are configurationSerializeable, makes them
|
||||
// really easy to save
|
||||
invConfig.set(slot + "", item);
|
||||
}
|
||||
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
id++;
|
||||
}
|
||||
}
|
||||
// also save barrels that are not loaded
|
||||
if (oldData != null){
|
||||
for (String uuid : oldData.getKeys(false)) {
|
||||
if (!config.contains(uuid)) {
|
||||
config.set(uuid, oldData.get(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// direction of the barrel from the spigot
|
||||
public static int getDirection(Block spigot) {
|
||||
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
|
||||
@ -805,6 +718,88 @@ public class Barrel implements InventoryHolder {
|
||||
return null;
|
||||
}
|
||||
|
||||
//unloads barrels that are in a unloading world
|
||||
public static void onUnload(String name) {
|
||||
for (Barrel barrel : barrels) {
|
||||
if (barrel.spigot.getWorld().getName().equals(name)) {
|
||||
barrels.remove(barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Saves all data
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
BUtil.createWorldSections(config);
|
||||
|
||||
if (barrels.isEmpty()) {
|
||||
int id = 0;
|
||||
for (Barrel barrel : barrels) {
|
||||
|
||||
String worldName = barrel.spigot.getWorld().getName();
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = BUtil.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
|
||||
// block: x/y/z
|
||||
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());
|
||||
|
||||
if (barrel.signoffset != 0) {
|
||||
config.set(prefix + ".sign", barrel.signoffset);
|
||||
}
|
||||
if (barrel.stairsloc != null && barrel.stairsloc.length > 0) {
|
||||
StringBuilder st = new StringBuilder();
|
||||
for (int i : barrel.stairsloc) {
|
||||
st.append(i).append(",");
|
||||
}
|
||||
config.set(prefix + ".st", st.substring(0, st.length() - 1));
|
||||
}
|
||||
if (barrel.woodsloc != null && barrel.woodsloc.length > 0) {
|
||||
StringBuilder wo = new StringBuilder();
|
||||
for (int i : barrel.woodsloc) {
|
||||
wo.append(i).append(",");
|
||||
}
|
||||
config.set(prefix + ".wo", wo.substring(0, wo.length() - 1));
|
||||
}
|
||||
|
||||
if (barrel.inventory != null) {
|
||||
int slot = 0;
|
||||
ItemStack item;
|
||||
ConfigurationSection invConfig = null;
|
||||
while (slot < barrel.inventory.getSize()) {
|
||||
item = barrel.inventory.getItem(slot);
|
||||
if (item != null) {
|
||||
if (invConfig == null) {
|
||||
if (barrel.time != 0) {
|
||||
config.set(prefix + ".time", barrel.time);
|
||||
}
|
||||
invConfig = config.createSection(prefix + ".inv");
|
||||
}
|
||||
// ItemStacks are configurationSerializeable, makes them
|
||||
// really easy to save
|
||||
invConfig.set(slot + "", item);
|
||||
}
|
||||
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
id++;
|
||||
}
|
||||
}
|
||||
// also save barrels that are not loaded
|
||||
if (oldData != null){
|
||||
for (String uuid : oldData.getKeys(false)) {
|
||||
if (!config.contains(uuid)) {
|
||||
config.set(uuid, oldData.get(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class BarrelCheck extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.lore.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -26,8 +27,6 @@ public class Brew {
|
||||
private static long saveSeed;
|
||||
public static Map<Integer, Brew> legacyPotions = new HashMap<>();
|
||||
public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch
|
||||
public static Boolean colorInBarrels; // color the Lore while in Barrels
|
||||
public static Boolean colorInBrewer; // color the Lore while in Brewer
|
||||
|
||||
private BIngredients ingredients;
|
||||
private int quality;
|
||||
@ -72,46 +71,43 @@ public class Brew {
|
||||
|
||||
// returns a Brew by ItemMeta
|
||||
public static Brew get(ItemMeta meta) {
|
||||
if (meta.hasLore()) {
|
||||
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;
|
||||
} else {
|
||||
return load(meta);
|
||||
if (!meta.hasLore()) return null;
|
||||
|
||||
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;
|
||||
} else {
|
||||
return load(meta);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// returns a Brew by ItemStack
|
||||
public static Brew get(ItemStack item) {
|
||||
if (item.getType() == Material.POTION) {
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasLore()) {
|
||||
if (meta instanceof PotionMeta && ((PotionMeta) meta).hasCustomEffect(PotionEffectType.REGENERATION)) {
|
||||
Brew brew = load(meta);
|
||||
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);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return brew;
|
||||
} else {
|
||||
return load(meta);
|
||||
}
|
||||
}
|
||||
if (item.getType() != Material.POTION) return null;
|
||||
if (!item.hasItemMeta()) return null;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (!meta.hasLore()) return null;
|
||||
|
||||
if (meta instanceof PotionMeta && ((PotionMeta) meta).hasCustomEffect(PotionEffectType.REGENERATION)) {
|
||||
Brew brew = load(meta);
|
||||
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);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return brew;
|
||||
} else {
|
||||
return load(meta);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Legacy Brew Loading
|
||||
@ -482,11 +478,11 @@ public class Brew {
|
||||
|
||||
// Distill Lore
|
||||
if (currentRecipe != null) {
|
||||
if (colorInBrewer != BrewLore.hasColorLore(potionMeta)) {
|
||||
lore.convertLore(colorInBrewer);
|
||||
if (BConfig.colorInBrewer != BrewLore.hasColorLore(potionMeta)) {
|
||||
lore.convertLore(BConfig.colorInBrewer);
|
||||
}
|
||||
}
|
||||
lore.updateDistillLore(colorInBrewer);
|
||||
lore.updateDistillLore(BConfig.colorInBrewer);
|
||||
lore.write();
|
||||
touch();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, potionMeta, BrewModifyEvent.Type.DISTILL);
|
||||
@ -551,15 +547,15 @@ public class Brew {
|
||||
|
||||
// Lore
|
||||
if (currentRecipe != null) {
|
||||
if (colorInBarrels != BrewLore.hasColorLore(potionMeta)) {
|
||||
lore.convertLore(colorInBarrels);
|
||||
if (BConfig.colorInBarrels != BrewLore.hasColorLore(potionMeta)) {
|
||||
lore.convertLore(BConfig.colorInBarrels);
|
||||
}
|
||||
}
|
||||
if (ageTime >= 1) {
|
||||
lore.updateAgeLore(colorInBarrels);
|
||||
lore.updateAgeLore(BConfig.colorInBarrels);
|
||||
}
|
||||
if (ageTime > 0.5) {
|
||||
if (colorInBarrels && !unlabeled && currentRecipe != null) {
|
||||
if (BConfig.colorInBarrels && !unlabeled && currentRecipe != null) {
|
||||
lore.updateWoodLore(true);
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Words {
|
||||
public class DistortChat {
|
||||
|
||||
// represends Words and letters, that are replaced in drunk players messages
|
||||
|
||||
public static ArrayList<Words> words = new ArrayList<>();
|
||||
public static ArrayList<DistortChat> words = new ArrayList<>();
|
||||
public static List<String> commands;
|
||||
public static List<String[]> ignoreText = new ArrayList<>();
|
||||
public static Boolean doSigns;
|
||||
@ -27,7 +27,7 @@ public class Words {
|
||||
private int alcohol = 1;
|
||||
private int percentage = 100;
|
||||
|
||||
public Words(Map<?, ?> part) {
|
||||
public DistortChat(Map<?, ?> part) {
|
||||
for (Map.Entry<?, ?> wordPart : part.entrySet()) {
|
||||
String key = (String) wordPart.getKey();
|
||||
|
||||
@ -164,7 +164,7 @@ public class Words {
|
||||
// distorts a message without checking ignoreText letters
|
||||
private static String distortString(String message, int drunkeness) {
|
||||
if (message.length() > 1) {
|
||||
for (Words word : words) {
|
||||
for (DistortChat word : words) {
|
||||
if (word.alcohol <= drunkeness) {
|
||||
message = word.distort(message);
|
||||
}
|
@ -97,6 +97,26 @@ public class MCBarrel {
|
||||
}
|
||||
}
|
||||
|
||||
public void countBrews() {
|
||||
brews = 0;
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
if (item != null) {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
brews++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static void onUpdate() {
|
||||
mcBarrelTime++;
|
||||
}
|
||||
|
||||
// Used to visually stop Players from placing more than 6 (configurable) brews in the MC Barrels.
|
||||
// There are still methods to place more Brews in that would be too tedious to catch.
|
||||
// This is only for direct visual Notification, the age routine above will never age more than 6 brews in any case.
|
||||
@ -184,24 +204,4 @@ public class MCBarrel {
|
||||
}
|
||||
}
|
||||
|
||||
public void countBrews() {
|
||||
brews = 0;
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
if (item != null) {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
brews++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static void onUpdate() {
|
||||
mcBarrelTime++;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,58 +1,30 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.filedata.ConfigUpdater;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.filedata.BData;
|
||||
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.*;
|
||||
import com.dre.brewery.integration.IntegrationListener;
|
||||
import com.dre.brewery.integration.LogBlockBarrel;
|
||||
import com.dre.brewery.listeners.*;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
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.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class P extends JavaPlugin {
|
||||
public static P p;
|
||||
public static final String configVersion = "1.8";
|
||||
public static boolean debug;
|
||||
public static boolean useUUID;
|
||||
public static boolean use1_9;
|
||||
public static boolean use1_11;
|
||||
public static boolean use1_13;
|
||||
public static boolean use1_14;
|
||||
public static boolean updateCheck;
|
||||
|
||||
// Third Party Enabled
|
||||
public boolean useWG; //WorldGuard
|
||||
public WGBarrel wg;
|
||||
public boolean useLWC; //LWC
|
||||
public boolean useLB; //LogBlock
|
||||
public boolean useGP; //GriefPrevention
|
||||
public boolean hasVault; // Vault
|
||||
public boolean useCitadel; // CivCraft/DevotedMC Citadel
|
||||
|
||||
// Listeners
|
||||
public BlockListener blockListener;
|
||||
@ -66,8 +38,6 @@ public class P extends JavaPlugin {
|
||||
public String language;
|
||||
public LanguageReader languageReader;
|
||||
|
||||
private CommandSender reloader;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
p = this;
|
||||
@ -331,7 +301,7 @@ public class P extends JavaPlugin {
|
||||
|
||||
// load the Config
|
||||
try {
|
||||
if (!readConfig()) {
|
||||
if (!BConfig.readConfig()) {
|
||||
p = null;
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
@ -342,7 +312,7 @@ public class P extends JavaPlugin {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
readData();
|
||||
BData.readData();
|
||||
|
||||
// Setup Metrics
|
||||
/*try {
|
||||
@ -427,7 +397,7 @@ public class P extends JavaPlugin {
|
||||
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
|
||||
p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120);
|
||||
|
||||
if (updateCheck) {
|
||||
if (BConfig.updateCheck) {
|
||||
try {
|
||||
p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
|
||||
} catch (Exception e) {
|
||||
@ -466,26 +436,26 @@ public class P extends JavaPlugin {
|
||||
BPlayer.clear();
|
||||
Brew.legacyPotions.clear();
|
||||
Wakeup.wakeups.clear();
|
||||
Words.words.clear();
|
||||
Words.ignoreText.clear();
|
||||
Words.commands = null;
|
||||
DistortChat.words.clear();
|
||||
DistortChat.ignoreText.clear();
|
||||
DistortChat.commands = null;
|
||||
|
||||
this.log(this.getDescription().getName() + " disabled!");
|
||||
}
|
||||
|
||||
public void reload(CommandSender sender) {
|
||||
if (sender != null && !sender.equals(getServer().getConsoleSender())) {
|
||||
reloader = sender;
|
||||
BConfig.reloader = sender;
|
||||
}
|
||||
// clear all existent config Data
|
||||
BIngredients.possibleIngredients.clear();
|
||||
BIngredients.recipes.clear();
|
||||
BIngredients.cookedNames.clear();
|
||||
Words.words.clear();
|
||||
Words.ignoreText.clear();
|
||||
Words.commands = null;
|
||||
BPlayer.drainItems.clear();
|
||||
if (useLB) {
|
||||
DistortChat.words.clear();
|
||||
DistortChat.ignoreText.clear();
|
||||
DistortChat.commands = null;
|
||||
BConfig.drainItems.clear();
|
||||
if (BConfig.useLB) {
|
||||
try {
|
||||
LogBlockBarrel.clear();
|
||||
} catch (Exception e) {
|
||||
@ -495,7 +465,7 @@ public class P extends JavaPlugin {
|
||||
|
||||
// load the Config
|
||||
try {
|
||||
if (!readConfig()) {
|
||||
if (!BConfig.readConfig()) {
|
||||
p = null;
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
@ -521,9 +491,11 @@ public class P extends JavaPlugin {
|
||||
if (!successful && sender != null) {
|
||||
msg(sender, p.languageReader.get("Error_Recipeload"));
|
||||
}
|
||||
reloader = null;
|
||||
BConfig.reloader = null;
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
||||
public void msg(CommandSender sender, String msg) {
|
||||
sender.sendMessage(color("&2[Brewery] &f" + msg));
|
||||
}
|
||||
@ -540,446 +512,11 @@ public class P extends JavaPlugin {
|
||||
|
||||
public void errorLog(String msg) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||
if (reloader != null) {
|
||||
reloader.sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||
if (BConfig.reloader != null) {
|
||||
BConfig.reloader.sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean readConfig() {
|
||||
File file = new File(p.getDataFolder(), "config.yml");
|
||||
if (!checkConfigs()) {
|
||||
return false;
|
||||
}
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// Set the Language
|
||||
language = config.getString("language", "en");
|
||||
|
||||
// Load LanguageReader
|
||||
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
|
||||
|
||||
// Has to config still got old materials
|
||||
boolean oldMat = config.getBoolean("oldMat", false);
|
||||
|
||||
// Check if config is the newest version
|
||||
String version = config.getString("version", null);
|
||||
if (version != null) {
|
||||
if (!version.equals(configVersion) || (oldMat && use1_13)) {
|
||||
copyDefaultConfigs(true);
|
||||
new ConfigUpdater(file).update(version, oldMat, language);
|
||||
P.p.log("Config Updated to version: " + configVersion);
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
}
|
||||
|
||||
// If the Update Checker should be enabled
|
||||
updateCheck = config.getBoolean("updateCheck", false);
|
||||
|
||||
// Third-Party
|
||||
useWG = config.getBoolean("useWorldGuard", true) && getServer().getPluginManager().isPluginEnabled("WorldGuard");
|
||||
|
||||
if (useWG) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin != null) {
|
||||
String wgv = plugin.getDescription().getVersion();
|
||||
if (wgv.startsWith("6.")) {
|
||||
wg = new WGBarrelNew();
|
||||
} else if (wgv.startsWith("5.")) {
|
||||
wg = new WGBarrelOld();
|
||||
} else {
|
||||
wg = new WGBarrel7();
|
||||
}
|
||||
}
|
||||
if (wg == null) {
|
||||
P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 and 7.0 of WorldGuard!");
|
||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||
}
|
||||
}
|
||||
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");
|
||||
useCitadel = config.getBoolean("useCitadel", false) && getServer().getPluginManager().isPluginEnabled("Citadel");
|
||||
// The item util has been removed in Vault 1.7+
|
||||
hasVault = getServer().getPluginManager().isPluginEnabled("Vault")
|
||||
&& Integer.parseInt(getServer().getPluginManager().getPlugin("Vault").getDescription().getVersion().split("\\.")[1]) <= 6;
|
||||
|
||||
// various Settings
|
||||
DataSave.autosave = config.getInt("autosave", 3);
|
||||
debug = config.getBoolean("debug", false);
|
||||
BPlayer.pukeItem = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND"));
|
||||
BPlayer.hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60;
|
||||
BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
|
||||
BPlayer.enableHome = config.getBoolean("enableHome", false);
|
||||
BPlayer.enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
|
||||
BPlayer.enablePuke = config.getBoolean("enablePuke", false);
|
||||
BPlayer.pukeDespawntime = config.getInt("pukeDespawntime", 60) * 20;
|
||||
BPlayer.homeType = config.getString("homeType", null);
|
||||
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
|
||||
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
|
||||
PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
|
||||
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);
|
||||
|
||||
// loading recipes
|
||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||
if (configSection != null) {
|
||||
for (String recipeId : configSection.getKeys(false)) {
|
||||
BRecipe recipe = new BRecipe(configSection, recipeId);
|
||||
if (recipe.isValid()) {
|
||||
BIngredients.recipes.add(recipe);
|
||||
} else {
|
||||
errorLog("Loading the Recipe with id: '" + recipeId + "' failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading cooked names and possible ingredients
|
||||
configSection = config.getConfigurationSection("cooked");
|
||||
if (configSection != null) {
|
||||
for (String ingredient : configSection.getKeys(false)) {
|
||||
Material mat = Material.matchMaterial(ingredient);
|
||||
if (mat == null && hasVault) {
|
||||
try {
|
||||
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(ingredient);
|
||||
if (vaultItem != null) {
|
||||
mat = vaultItem.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
P.p.errorLog("Could not check vault for Item Name");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (mat != null) {
|
||||
BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
|
||||
BIngredients.possibleIngredients.add(mat);
|
||||
} else {
|
||||
errorLog("Unknown Material: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading drainItems
|
||||
List<String> drainList = config.getStringList("drainItems");
|
||||
if (drainList != null) {
|
||||
for (String drainString : drainList) {
|
||||
String[] drainSplit = drainString.split("/");
|
||||
if (drainSplit.length > 1) {
|
||||
Material mat = Material.matchMaterial(drainSplit[0]);
|
||||
int strength = p.parseInt(drainSplit[1]);
|
||||
if (mat == null && hasVault && strength > 0) {
|
||||
try {
|
||||
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(drainSplit[0]);
|
||||
if (vaultItem != null) {
|
||||
mat = vaultItem.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
P.p.errorLog("Could not check vault for Item Name");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (mat != null && strength > 0) {
|
||||
BPlayer.drainItems.put(mat, strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loading Words
|
||||
if (config.getBoolean("enableChatDistortion", false)) {
|
||||
for (Map<?, ?> map : config.getMapList("words")) {
|
||||
new Words(map);
|
||||
}
|
||||
for (String bypass : config.getStringList("distortBypass")) {
|
||||
Words.ignoreText.add(bypass.split(","));
|
||||
}
|
||||
Words.commands = config.getStringList("distortCommands");
|
||||
}
|
||||
Words.log = config.getBoolean("logRealChat", false);
|
||||
Words.doSigns = config.getBoolean("distortSignText", false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// load all Data
|
||||
public void readData() {
|
||||
File file = new File(p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
|
||||
MCBarrel.mcBarrelTime = data.getLong("MCBarrelTime", 0);
|
||||
|
||||
Brew.loadSeed(data);
|
||||
|
||||
// Check if data is the newest version
|
||||
String version = data.getString("Version", null);
|
||||
if (version != null) {
|
||||
if (!version.equals(DataSave.dataVersion)) {
|
||||
P.p.log("Data File is being updated...");
|
||||
new DataUpdater(data, file).update(version);
|
||||
data = YamlConfiguration.loadConfiguration(file);
|
||||
P.p.log("Data Updated to version: " + DataSave.dataVersion);
|
||||
}
|
||||
}
|
||||
|
||||
// loading Ingredients into ingMap
|
||||
Map<String, BIngredients> ingMap = new HashMap<>();
|
||||
ConfigurationSection section = data.getConfigurationSection("Ingredients");
|
||||
if (section != null) {
|
||||
for (String id : section.getKeys(false)) {
|
||||
ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
ArrayList<ItemStack> ingredients = deserializeIngredients(matSection);
|
||||
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0), true));
|
||||
} else {
|
||||
errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Brew legacy
|
||||
section = data.getConfigurationSection("Brew");
|
||||
if (section != null) {
|
||||
// All sections have the UID as name
|
||||
for (String uid : section.getKeys(false)) {
|
||||
BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
|
||||
int quality = section.getInt(uid + ".quality", 0);
|
||||
byte distillRuns = (byte) section.getInt(uid + ".distillRuns", 0);
|
||||
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
||||
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
||||
String recipe = section.getString(uid + ".recipe", null);
|
||||
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);
|
||||
|
||||
Brew.loadLegacy(ingredients, parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
// loading BPlayer
|
||||
section = data.getConfigurationSection("Player");
|
||||
if (section != null) {
|
||||
// keys have players name
|
||||
for (String name : section.getKeys(false)) {
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
UUID.fromString(name);
|
||||
if (!useUUID) {
|
||||
continue;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (useUUID) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int quality = section.getInt(name + ".quality");
|
||||
int drunk = section.getInt(name + ".drunk");
|
||||
int offDrunk = section.getInt(name + ".offDrunk", 0);
|
||||
|
||||
new BPlayer(name, quality, drunk, offDrunk);
|
||||
}
|
||||
}
|
||||
|
||||
for (World world : p.getServer().getWorlds()) {
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
} else {
|
||||
loadWorldData(world.getUID().toString(), world);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
errorLog("No data.yml found, will create new one!");
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> deserializeIngredients(ConfigurationSection matSection) {
|
||||
ArrayList<ItemStack> ingredients = new ArrayList<>();
|
||||
for (String mat : matSection.getKeys(false)) {
|
||||
String[] matSplit = mat.split(",");
|
||||
Material m = Material.getMaterial(matSplit[0]);
|
||||
if (m == null && use1_13) {
|
||||
if (matSplit[0].equals("LONG_GRASS")) {
|
||||
m = Material.GRASS;
|
||||
} else {
|
||||
m = Material.matchMaterial(matSplit[0], true);
|
||||
}
|
||||
debugLog("converting Data Material from " + matSplit[0] + " to " + m);
|
||||
}
|
||||
if (m == null) continue;
|
||||
ItemStack item = new ItemStack(m, matSection.getInt(mat));
|
||||
if (matSplit.length == 2) {
|
||||
item.setDurability((short) P.p.parseInt(matSplit[1]));
|
||||
}
|
||||
ingredients.add(item);
|
||||
}
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
// returns Ingredients by id from the specified ingMap
|
||||
public BIngredients getIngredients(Map<String, BIngredients> ingMap, String id) {
|
||||
if (!ingMap.isEmpty()) {
|
||||
if (ingMap.containsKey(id)) {
|
||||
return ingMap.get(id);
|
||||
}
|
||||
}
|
||||
errorLog("Ingredient id: '" + id + "' not found in data.yml");
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// loads BIngredients from an ingredient section
|
||||
public BIngredients loadIngredients(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
return new BIngredients(deserializeIngredients(section), 0);
|
||||
} else {
|
||||
errorLog("Cauldron is missing Ingredient Section");
|
||||
}
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// load Block locations of given world
|
||||
public void loadWorldData(String uuid, World world) {
|
||||
|
||||
File file = new File(p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// loading BCauldron
|
||||
if (data.contains("BCauldron." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
|
||||
for (String cauldron : section.getKeys(false)) {
|
||||
// block is splitted into x/y/z
|
||||
String block = section.getString(cauldron + ".block");
|
||||
if (block != null) {
|
||||
String[] splitted = block.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
Block worldBlock = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
|
||||
BIngredients ingredients = loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
|
||||
int state = section.getInt(cauldron + ".state", 1);
|
||||
|
||||
new BCauldron(worldBlock, ingredients, state);
|
||||
} else {
|
||||
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
} else {
|
||||
errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Barrel
|
||||
if (data.contains("Barrel." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
|
||||
for (String barrel : section.getKeys(false)) {
|
||||
// block spigot is splitted into x/y/z
|
||||
String spigot = section.getString(barrel + ".spigot");
|
||||
if (spigot != null) {
|
||||
String[] splitted = spigot.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
// load itemStacks from invSection
|
||||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||
Block block = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
|
||||
float time = (float) section.getDouble(barrel + ".time", 0.0);
|
||||
byte sign = (byte) section.getInt(barrel + ".sign", 0);
|
||||
String[] st = section.getString(barrel + ".st", "").split(",");
|
||||
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
||||
|
||||
if (invSection != null) {
|
||||
new Barrel(block, sign, st, wo, invSection.getValues(true), time);
|
||||
} else {
|
||||
// Barrel has no inventory
|
||||
new Barrel(block, sign, st, wo, null, time);
|
||||
}
|
||||
|
||||
} else {
|
||||
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
} else {
|
||||
errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Wakeup
|
||||
if (data.contains("Wakeup." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
|
||||
for (String wakeup : section.getKeys(false)) {
|
||||
// loc of wakeup is splitted into x/y/z/pitch/yaw
|
||||
String loc = section.getString(wakeup);
|
||||
if (loc != null) {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
Wakeup.wakeups.add(new Wakeup(location));
|
||||
|
||||
} else {
|
||||
errorLog("Incomplete Location-Data in data.yml: " + section.getCurrentPath() + "." + wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkConfigs() {
|
||||
File cfg = new File(p.getDataFolder(), "config.yml");
|
||||
if (!cfg.exists()) {
|
||||
errorLog("No config.yml found, creating default file! You may want to choose a config according to your language!");
|
||||
errorLog("You can find them in plugins/Brewery/configs/");
|
||||
InputStream defconf = getResource("config/" + (use1_13 ? "v13/" : "v12/") + "en/config.yml");
|
||||
if (defconf == null) {
|
||||
errorLog("default config file not found, your jarfile may be corrupt. Disabling Brewery!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
BUtil.saveFile(defconf, getDataFolder(), "config.yml", false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!cfg.exists()) {
|
||||
errorLog("default config file could not be copied, your jarfile may be corrupt. Disabling Brewery!");
|
||||
return false;
|
||||
}
|
||||
|
||||
copyDefaultConfigs(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void copyDefaultConfigs(boolean overwrite) {
|
||||
File configs = new File(getDataFolder(), "configs");
|
||||
File languages = new File(getDataFolder(), "languages");
|
||||
for (String l : new String[] {"de", "en", "fr", "it", "zh", "tw"}) {
|
||||
File lfold = new File(configs, l);
|
||||
try {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
||||
public int parseInt(String string) {
|
||||
return NumberUtils.toInt(string, 0);
|
||||
}
|
||||
@ -991,7 +528,7 @@ public class P extends JavaPlugin {
|
||||
|
||||
// Runnables
|
||||
|
||||
public class DrunkRunnable implements Runnable {
|
||||
public static class DrunkRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!BPlayer.isEmpty()) {
|
||||
@ -1003,7 +540,7 @@ public class P extends JavaPlugin {
|
||||
public class BreweryRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
reloader = null;
|
||||
BConfig.reloader = null;
|
||||
for (BCauldron cauldron : BCauldron.bcauldrons) {
|
||||
cauldron.onUpdate();// runs every min to update cooking time
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Wakeup {
|
||||
|
||||
public static ArrayList<Wakeup> wakeups = new ArrayList<>();
|
||||
|
257
src/com/dre/brewery/filedata/BConfig.java
Normal file
257
src/com/dre/brewery/filedata/BConfig.java
Normal file
@ -0,0 +1,257 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BConfig {
|
||||
|
||||
public static final String configVersion = "1.8";
|
||||
public static boolean updateCheck;
|
||||
public static CommandSender reloader;
|
||||
|
||||
// Third Party Enabled
|
||||
public static boolean useWG; //WorldGuard
|
||||
public static WGBarrel wg;
|
||||
public static boolean useLWC; //LWC
|
||||
public static boolean useLB; //LogBlock
|
||||
public static boolean useGP; //GriefPrevention
|
||||
public static boolean hasVault; // Vault
|
||||
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
|
||||
|
||||
// Barrel
|
||||
public static boolean openEverywhere;
|
||||
|
||||
//BPlayer
|
||||
public static Map<Material, Integer> drainItems = new HashMap<>();// DrainItem Material and Strength
|
||||
public static Material pukeItem;
|
||||
public static int pukeDespawntime;
|
||||
public static int hangoverTime;
|
||||
public static boolean overdrinkKick;
|
||||
public static boolean enableHome;
|
||||
public static boolean enableLoginDisallow;
|
||||
public static boolean enablePuke;
|
||||
public static String homeType;
|
||||
|
||||
//Brew
|
||||
public static boolean colorInBarrels; // color the Lore while in Barrels
|
||||
public static boolean colorInBrewer; // color the Lore while in Brewer
|
||||
|
||||
public static P p = P.p;
|
||||
|
||||
private static boolean checkConfigs() {
|
||||
File cfg = new File(p.getDataFolder(), "config.yml");
|
||||
if (!cfg.exists()) {
|
||||
p.errorLog("No config.yml found, creating default file! You may want to choose a config according to your language!");
|
||||
p.errorLog("You can find them in plugins/Brewery/configs/");
|
||||
InputStream defconf = p.getResource("config/" + (P.use1_13 ? "v13/" : "v12/") + "en/config.yml");
|
||||
if (defconf == null) {
|
||||
p.errorLog("default config file not found, your jarfile may be corrupt. Disabling Brewery!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
BUtil.saveFile(defconf, p.getDataFolder(), "config.yml", false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!cfg.exists()) {
|
||||
p.errorLog("default config file could not be copied, your jarfile may be corrupt. Disabling Brewery!");
|
||||
return false;
|
||||
}
|
||||
|
||||
copyDefaultConfigs(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void copyDefaultConfigs(boolean overwrite) {
|
||||
File configs = new File(p.getDataFolder(), "configs");
|
||||
File languages = new File(p.getDataFolder(), "languages");
|
||||
for (String l : new String[] {"de", "en", "fr", "it", "zh", "tw"}) {
|
||||
File lfold = new File(configs, l);
|
||||
try {
|
||||
BUtil.saveFile(p.getResource("config/" + (P.use1_13 ? "v13/" : "v12/") + l + "/config.yml"), lfold, "config.yml", overwrite);
|
||||
BUtil.saveFile(p.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean readConfig() {
|
||||
File file = new File(P.p.getDataFolder(), "config.yml");
|
||||
if (!checkConfigs()) {
|
||||
return false;
|
||||
}
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// Set the Language
|
||||
p.language = config.getString("language", "en");
|
||||
|
||||
// Load LanguageReader
|
||||
p.languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + p.language + ".yml"));
|
||||
|
||||
// Has to config still got old materials
|
||||
boolean oldMat = config.getBoolean("oldMat", false);
|
||||
|
||||
// Check if config is the newest version
|
||||
String version = config.getString("version", null);
|
||||
if (version != null) {
|
||||
if (!version.equals(configVersion) || (oldMat && P.use1_13)) {
|
||||
copyDefaultConfigs(true);
|
||||
new ConfigUpdater(file).update(version, oldMat, p.language);
|
||||
P.p.log("Config Updated to version: " + configVersion);
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
}
|
||||
|
||||
// If the Update Checker should be enabled
|
||||
updateCheck = config.getBoolean("updateCheck", false);
|
||||
|
||||
PluginManager plMan = p.getServer().getPluginManager();
|
||||
|
||||
// Third-Party
|
||||
useWG = config.getBoolean("useWorldGuard", true) && plMan.isPluginEnabled("WorldGuard");
|
||||
|
||||
if (useWG) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin != null) {
|
||||
String wgv = plugin.getDescription().getVersion();
|
||||
if (wgv.startsWith("6.")) {
|
||||
wg = new WGBarrelNew();
|
||||
} else if (wgv.startsWith("5.")) {
|
||||
wg = new WGBarrelOld();
|
||||
} else {
|
||||
wg = new WGBarrel7();
|
||||
}
|
||||
}
|
||||
if (wg == null) {
|
||||
P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 and 7.0 of WorldGuard!");
|
||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||
}
|
||||
}
|
||||
useLWC = config.getBoolean("useLWC", true) && plMan.isPluginEnabled("LWC");
|
||||
useGP = config.getBoolean("useGriefPrevention", true) && plMan.isPluginEnabled("GriefPrevention");
|
||||
useLB = config.getBoolean("useLogBlock", false) && plMan.isPluginEnabled("LogBlock");
|
||||
useCitadel = config.getBoolean("useCitadel", false) && plMan.isPluginEnabled("Citadel");
|
||||
// The item util has been removed in Vault 1.7+
|
||||
hasVault = plMan.isPluginEnabled("Vault")
|
||||
&& Integer.parseInt(plMan.getPlugin("Vault").getDescription().getVersion().split("\\.")[1]) <= 6;
|
||||
|
||||
// various Settings
|
||||
DataSave.autosave = config.getInt("autosave", 3);
|
||||
P.debug = config.getBoolean("debug", false);
|
||||
pukeItem = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND"));
|
||||
hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60;
|
||||
overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
|
||||
enableHome = config.getBoolean("enableHome", false);
|
||||
enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
|
||||
enablePuke = config.getBoolean("enablePuke", false);
|
||||
pukeDespawntime = config.getInt("pukeDespawntime", 60) * 20;
|
||||
homeType = config.getString("homeType", null);
|
||||
colorInBarrels = config.getBoolean("colorInBarrels", false);
|
||||
colorInBrewer = config.getBoolean("colorInBrewer", false);
|
||||
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
|
||||
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);
|
||||
|
||||
// loading recipes
|
||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||
if (configSection != null) {
|
||||
for (String recipeId : configSection.getKeys(false)) {
|
||||
BRecipe recipe = new BRecipe(configSection, recipeId);
|
||||
if (recipe.isValid()) {
|
||||
BIngredients.recipes.add(recipe);
|
||||
} else {
|
||||
p.errorLog("Loading the Recipe with id: '" + recipeId + "' failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading cooked names and possible ingredients
|
||||
configSection = config.getConfigurationSection("cooked");
|
||||
if (configSection != null) {
|
||||
for (String ingredient : configSection.getKeys(false)) {
|
||||
Material mat = Material.matchMaterial(ingredient);
|
||||
if (mat == null && hasVault) {
|
||||
try {
|
||||
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(ingredient);
|
||||
if (vaultItem != null) {
|
||||
mat = vaultItem.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
P.p.errorLog("Could not check vault for Item Name");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (mat != null) {
|
||||
BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
|
||||
BIngredients.possibleIngredients.add(mat);
|
||||
} else {
|
||||
p.errorLog("Unknown Material: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading drainItems
|
||||
List<String> drainList = config.getStringList("drainItems");
|
||||
if (drainList != null) {
|
||||
for (String drainString : drainList) {
|
||||
String[] drainSplit = drainString.split("/");
|
||||
if (drainSplit.length > 1) {
|
||||
Material mat = Material.matchMaterial(drainSplit[0]);
|
||||
int strength = p.parseInt(drainSplit[1]);
|
||||
if (mat == null && hasVault && strength > 0) {
|
||||
try {
|
||||
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(drainSplit[0]);
|
||||
if (vaultItem != null) {
|
||||
mat = vaultItem.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
P.p.errorLog("Could not check vault for Item Name");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (mat != null && strength > 0) {
|
||||
drainItems.put(mat, strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loading Words
|
||||
if (config.getBoolean("enableChatDistortion", false)) {
|
||||
for (Map<?, ?> map : config.getMapList("words")) {
|
||||
new DistortChat(map);
|
||||
}
|
||||
for (String bypass : config.getStringList("distortBypass")) {
|
||||
DistortChat.ignoreText.add(bypass.split(","));
|
||||
}
|
||||
DistortChat.commands = config.getStringList("distortCommands");
|
||||
}
|
||||
DistortChat.log = config.getBoolean("logRealChat", false);
|
||||
DistortChat.doSigns = config.getBoolean("distortSignText", false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
258
src/com/dre/brewery/filedata/BData.java
Normal file
258
src/com/dre/brewery/filedata/BData.java
Normal file
@ -0,0 +1,258 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BData {
|
||||
|
||||
|
||||
// load all Data
|
||||
public static void readData() {
|
||||
File file = new File(P.p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
|
||||
MCBarrel.mcBarrelTime = data.getLong("MCBarrelTime", 0);
|
||||
|
||||
Brew.loadSeed(data);
|
||||
|
||||
// Check if data is the newest version
|
||||
String version = data.getString("Version", null);
|
||||
if (version != null) {
|
||||
if (!version.equals(DataSave.dataVersion)) {
|
||||
P.p.log("Data File is being updated...");
|
||||
new DataUpdater(data, file).update(version);
|
||||
data = YamlConfiguration.loadConfiguration(file);
|
||||
P.p.log("Data Updated to version: " + DataSave.dataVersion);
|
||||
}
|
||||
}
|
||||
|
||||
// loading Ingredients into ingMap
|
||||
Map<String, BIngredients> ingMap = new HashMap<>();
|
||||
ConfigurationSection section = data.getConfigurationSection("Ingredients");
|
||||
if (section != null) {
|
||||
for (String id : section.getKeys(false)) {
|
||||
ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
ArrayList<ItemStack> ingredients = deserializeIngredients(matSection);
|
||||
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0), true));
|
||||
} else {
|
||||
P.p.errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Brew legacy
|
||||
section = data.getConfigurationSection("Brew");
|
||||
if (section != null) {
|
||||
// All sections have the UID as name
|
||||
for (String uid : section.getKeys(false)) {
|
||||
BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
|
||||
int quality = section.getInt(uid + ".quality", 0);
|
||||
byte distillRuns = (byte) section.getInt(uid + ".distillRuns", 0);
|
||||
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
||||
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
||||
String recipe = section.getString(uid + ".recipe", null);
|
||||
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);
|
||||
|
||||
Brew.loadLegacy(ingredients, P.p.parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
// loading BPlayer
|
||||
section = data.getConfigurationSection("Player");
|
||||
if (section != null) {
|
||||
// keys have players name
|
||||
for (String name : section.getKeys(false)) {
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
UUID.fromString(name);
|
||||
if (!P.useUUID) {
|
||||
continue;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (P.useUUID) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int quality = section.getInt(name + ".quality");
|
||||
int drunk = section.getInt(name + ".drunk");
|
||||
int offDrunk = section.getInt(name + ".offDrunk", 0);
|
||||
|
||||
new BPlayer(name, quality, drunk, offDrunk);
|
||||
}
|
||||
}
|
||||
|
||||
for (World world : P.p.getServer().getWorlds()) {
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
} else {
|
||||
loadWorldData(world.getUID().toString(), world);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
P.p.errorLog("No data.yml found, will create new one!");
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<ItemStack> deserializeIngredients(ConfigurationSection matSection) {
|
||||
ArrayList<ItemStack> ingredients = new ArrayList<>();
|
||||
for (String mat : matSection.getKeys(false)) {
|
||||
String[] matSplit = mat.split(",");
|
||||
Material m = Material.getMaterial(matSplit[0]);
|
||||
if (m == null && P.use1_13) {
|
||||
if (matSplit[0].equals("LONG_GRASS")) {
|
||||
m = Material.GRASS;
|
||||
} else {
|
||||
m = Material.matchMaterial(matSplit[0], true);
|
||||
}
|
||||
P.p.debugLog("converting Data Material from " + matSplit[0] + " to " + m);
|
||||
}
|
||||
if (m == null) continue;
|
||||
ItemStack item = new ItemStack(m, matSection.getInt(mat));
|
||||
if (matSplit.length == 2) {
|
||||
item.setDurability((short) P.p.parseInt(matSplit[1]));
|
||||
}
|
||||
ingredients.add(item);
|
||||
}
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
// returns Ingredients by id from the specified ingMap
|
||||
public static BIngredients getIngredients(Map<String, BIngredients> ingMap, String id) {
|
||||
if (!ingMap.isEmpty()) {
|
||||
if (ingMap.containsKey(id)) {
|
||||
return ingMap.get(id);
|
||||
}
|
||||
}
|
||||
P.p.errorLog("Ingredient id: '" + id + "' not found in data.yml");
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// loads BIngredients from an ingredient section
|
||||
public static BIngredients loadIngredients(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
return new BIngredients(deserializeIngredients(section), 0);
|
||||
} else {
|
||||
P.p.errorLog("Cauldron is missing Ingredient Section");
|
||||
}
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// load Block locations of given world
|
||||
public static void loadWorldData(String uuid, World world) {
|
||||
|
||||
File file = new File(P.p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// loading BCauldron
|
||||
if (data.contains("BCauldron." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
|
||||
for (String cauldron : section.getKeys(false)) {
|
||||
// block is splitted into x/y/z
|
||||
String block = section.getString(cauldron + ".block");
|
||||
if (block != null) {
|
||||
String[] splitted = block.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
Block worldBlock = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
BIngredients ingredients = loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
|
||||
int state = section.getInt(cauldron + ".state", 1);
|
||||
|
||||
new BCauldron(worldBlock, ingredients, state);
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Barrel
|
||||
if (data.contains("Barrel." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
|
||||
for (String barrel : section.getKeys(false)) {
|
||||
// block spigot is splitted into x/y/z
|
||||
String spigot = section.getString(barrel + ".spigot");
|
||||
if (spigot != null) {
|
||||
String[] splitted = spigot.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
// load itemStacks from invSection
|
||||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||
Block block = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
float time = (float) section.getDouble(barrel + ".time", 0.0);
|
||||
byte sign = (byte) section.getInt(barrel + ".sign", 0);
|
||||
String[] st = section.getString(barrel + ".st", "").split(",");
|
||||
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
||||
|
||||
if (invSection != null) {
|
||||
new Barrel(block, sign, st, wo, invSection.getValues(true), time);
|
||||
} else {
|
||||
// Barrel has no inventory
|
||||
new Barrel(block, sign, st, wo, null, time);
|
||||
}
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Wakeup
|
||||
if (data.contains("Wakeup." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
|
||||
for (String wakeup : section.getKeys(false)) {
|
||||
// loc of wakeup is splitted into x/y/z/pitch/yaw
|
||||
String loc = section.getString(wakeup);
|
||||
if (loc != null) {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
Wakeup.wakeups.add(new Wakeup(location));
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Location-Data in data.yml: " + section.getCurrentPath() + "." + wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
package com.dre.brewery.integration;
|
||||
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.LegacyUtil;
|
||||
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 com.dre.brewery.filedata.BConfig;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -16,11 +19,11 @@ public class IntegrationListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBarrelAccessLowest(BarrelAccessEvent event) {
|
||||
if (P.p.useWG) {
|
||||
if (BConfig.useWG) {
|
||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (plugin != null) {
|
||||
try {
|
||||
if (!P.p.wg.checkAccess(event.getPlayer(), event.getSpigot(), plugin)) {
|
||||
if (!BConfig.wg.checkAccess(event.getPlayer(), event.getSpigot(), plugin)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@ -43,11 +46,12 @@ public class IntegrationListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBarrelAccess(BarrelAccessEvent event) {
|
||||
if (P.p.useGP) {
|
||||
if (BConfig.useGP) {
|
||||
if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) {
|
||||
try {
|
||||
if (!GriefPreventionBarrel.checkAccess(event)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
event.setCancelled(true);
|
||||
@ -65,11 +69,42 @@ public class IntegrationListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (BConfig.useLWC) {
|
||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("LWC");
|
||||
if (plugin != null) {
|
||||
|
||||
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
||||
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
||||
Block sign = event.getBarrel().getSignOfSpigot();
|
||||
// If the Barrel does not have a Sign, it cannot be locked
|
||||
if (!sign.equals(event.getClickedBlock())) {
|
||||
Player player = event.getPlayer();
|
||||
try {
|
||||
if (!LWCBarrel.checkAccess(player, sign, plugin)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
P.p.errorLog("Failed to Check LWC for Barrel Open Permissions!");
|
||||
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();
|
||||
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 breaking Barrel, please report to an Admin!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onBarrelDestroy(BarrelDestroyEvent event) {
|
||||
if (!P.p.useLWC) return;
|
||||
if (!BConfig.useLWC) return;
|
||||
|
||||
if (event.hasPlayer()) {
|
||||
try {
|
||||
@ -113,7 +148,7 @@ public class IntegrationListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBarrelRemove(BarrelRemoveEvent event) {
|
||||
if (!P.p.useLWC) return;
|
||||
if (!BConfig.useLWC) return;
|
||||
|
||||
try {
|
||||
LWCBarrel.remove(event.getBarrel());
|
||||
@ -126,7 +161,7 @@ public class IntegrationListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (P.p.useLB) {
|
||||
if (BConfig.useLB) {
|
||||
if (event.getInventory().getHolder() instanceof Barrel) {
|
||||
try {
|
||||
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
|
||||
|
@ -7,11 +7,15 @@ import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.model.Flag;
|
||||
import com.griefcraft.model.Protection;
|
||||
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
@ -46,7 +50,7 @@ public class LWCBarrel {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
|
||||
public static boolean checkAccess(Player player, Block sign, Plugin plugin) {
|
||||
LWC lwc = LWC.getInstance();
|
||||
|
||||
// Disallow Chest Access with these permissions
|
||||
@ -56,7 +60,7 @@ public class LWCBarrel {
|
||||
}
|
||||
|
||||
// We just fake a BlockInteractEvent on the Sign for LWC, it handles it nicely. Otherwise we could copy LWCs listener in here...
|
||||
PlayerInteractEvent lwcEvent = new PlayerInteractEvent(player, event.getAction(), event.getItem(), sign, event.getBlockFace());
|
||||
PlayerInteractEvent lwcEvent = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), sign, BlockFace.EAST);
|
||||
for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
|
||||
if (listener.getListener() instanceof LWCPlayerListener) {
|
||||
try {
|
||||
|
@ -1,79 +1,79 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.BUtil;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Words;
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
String[] lines = event.getLines();
|
||||
|
||||
if (lines[0].equalsIgnoreCase("Barrel") || lines[0].equalsIgnoreCase(P.p.languageReader.get("Etc_Barrel"))) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPermission("brewery.createbarrel.small") && !player.hasPermission("brewery.createbarrel.big")) {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoBarrelCreate"));
|
||||
return;
|
||||
}
|
||||
if (Barrel.create(event.getBlock(), player)) {
|
||||
P.p.msg(player, P.p.languageReader.get("Player_BarrelCreated"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onSignChangeLow(SignChangeEvent event) {
|
||||
if (Words.doSigns) {
|
||||
if (BPlayer.hasPlayer(event.getPlayer())) {
|
||||
Words.signWrite(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!BUtil.blockDestroy(event.getBlock(), event.getPlayer(), BarrelDestroyEvent.Reason.PLAYER)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
BUtil.blockDestroy(event.getBlock(), null, BarrelDestroyEvent.Reason.BURNED);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||
if (event.isSticky()) {
|
||||
Block block = event.getRetractLocation().getBlock();
|
||||
|
||||
if (Barrel.get(block) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||
for (Block block : event.getBlocks()) {
|
||||
if (Barrel.get(block) != null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.BUtil;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.DistortChat;
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
String[] lines = event.getLines();
|
||||
|
||||
if (lines[0].equalsIgnoreCase("Barrel") || lines[0].equalsIgnoreCase(P.p.languageReader.get("Etc_Barrel"))) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPermission("brewery.createbarrel.small") && !player.hasPermission("brewery.createbarrel.big")) {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoBarrelCreate"));
|
||||
return;
|
||||
}
|
||||
if (Barrel.create(event.getBlock(), player)) {
|
||||
P.p.msg(player, P.p.languageReader.get("Player_BarrelCreated"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onSignChangeLow(SignChangeEvent event) {
|
||||
if (DistortChat.doSigns) {
|
||||
if (BPlayer.hasPlayer(event.getPlayer())) {
|
||||
DistortChat.signWrite(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!BUtil.blockDestroy(event.getBlock(), event.getPlayer(), BarrelDestroyEvent.Reason.PLAYER)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
BUtil.blockDestroy(event.getBlock(), null, BarrelDestroyEvent.Reason.BURNED);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||
if (event.isSticky()) {
|
||||
Block block = event.getRetractLocation().getBlock();
|
||||
|
||||
if (Barrel.get(block) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||
for (Block block : event.getBlocks()) {
|
||||
if (Barrel.get(block) != null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -323,7 +324,7 @@ public class CommandListener implements CommandExecutor {
|
||||
if (player != null) {
|
||||
bPlayer.drinkCap(player);
|
||||
} else {
|
||||
if (!BPlayer.overdrinkKick) {
|
||||
if (!BConfig.overdrinkKick) {
|
||||
bPlayer.setData(100, 0);
|
||||
}
|
||||
}
|
||||
@ -360,82 +361,81 @@ public class CommandListener implements CommandExecutor {
|
||||
}
|
||||
|
||||
public void cmdItemName(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = P.use1_9 ? player.getInventory().getItemInMainHand() : player.getItemInHand();
|
||||
if (hand != null) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Configname", hand.getType().name().toLowerCase(Locale.ENGLISH)));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("CMD_Configname_Error"));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = P.use1_9 ? player.getInventory().getItemInMainHand() : player.getItemInHand();
|
||||
if (hand != null) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Configname", hand.getType().name().toLowerCase(Locale.ENGLISH)));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("CMD_Configname_Error"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cmdCopy(CommandSender sender, int count) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (count < 1 || count > 36) {
|
||||
p.msg(sender, p.languageReader.get("Etc_Usage"));
|
||||
p.msg(sender, p.languageReader.get("Help_Copy"));
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
if (count < 1 || count > 36) {
|
||||
p.msg(sender, p.languageReader.get("Etc_Usage"));
|
||||
p.msg(sender, p.languageReader.get("Help_Copy"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
while (count > 0) {
|
||||
ItemStack item = hand.clone();
|
||||
if (!(player.getInventory().addItem(item)).isEmpty()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "" + count));
|
||||
return;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
if (brew.isPersistent()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_CopyNotPersistent"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
while (count > 0) {
|
||||
ItemStack item = hand.clone();
|
||||
if (!(player.getInventory().addItem(item)).isEmpty()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "" + count));
|
||||
return;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
if (brew.isPersistent()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_CopyNotPersistent"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
}
|
||||
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cmdDelete(CommandSender sender) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isPersistent()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_PersistRemove"));
|
||||
} else {
|
||||
//brew.remove(hand);
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
} else {
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isPersistent()) {
|
||||
p.msg(sender, p.languageReader.get("CMD_PersistRemove"));
|
||||
} else {
|
||||
//brew.remove(hand);
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
}
|
||||
|
||||
@ -443,101 +443,101 @@ public class CommandListener implements CommandExecutor {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cmdPersist(CommandSender sender) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isPersistent()) {
|
||||
brew.removePersistence();
|
||||
brew.setStatic(false, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_UnPersist"));
|
||||
} else {
|
||||
brew.makePersistent();
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Persistent"));
|
||||
}
|
||||
brew.touch();
|
||||
brew.save(hand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
} else {
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isPersistent()) {
|
||||
brew.removePersistence();
|
||||
brew.setStatic(false, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_UnPersist"));
|
||||
} else {
|
||||
brew.makePersistent();
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Persistent"));
|
||||
}
|
||||
brew.touch();
|
||||
brew.save(hand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cmdStatic(CommandSender sender) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isStatic()) {
|
||||
if (!brew.isPersistent()) {
|
||||
brew.setStatic(false, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_NonStatic"));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_PersistStatic"));
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
if (brew.isStatic()) {
|
||||
if (!brew.isPersistent()) {
|
||||
brew.setStatic(false, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_NonStatic"));
|
||||
} else {
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Static"));
|
||||
p.msg(sender, p.languageReader.get("Error_PersistStatic"));
|
||||
}
|
||||
brew.touch();
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.STATIC);
|
||||
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||
if (modifyEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
brew.save(meta);
|
||||
hand.setItemMeta(meta);
|
||||
} else {
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Static"));
|
||||
}
|
||||
brew.touch();
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.STATIC);
|
||||
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||
if (modifyEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
brew.save(meta);
|
||||
hand.setItemMeta(meta);
|
||||
return;
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cmdUnlabel(CommandSender sender) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
ItemMeta origMeta = hand.getItemMeta();
|
||||
brew.unLabel(hand);
|
||||
brew.touch();
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.UNLABEL);
|
||||
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||
if (modifyEvent.isCancelled()) {
|
||||
hand.setItemMeta(origMeta);
|
||||
return;
|
||||
}
|
||||
brew.save(meta);
|
||||
hand.setItemMeta(meta);
|
||||
p.msg(sender, p.languageReader.get("CMD_UnLabel"));
|
||||
if (!(sender instanceof Player)) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
ItemMeta origMeta = hand.getItemMeta();
|
||||
brew.unLabel(hand);
|
||||
brew.touch();
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.UNLABEL);
|
||||
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||
if (modifyEvent.isCancelled()) {
|
||||
hand.setItemMeta(origMeta);
|
||||
return;
|
||||
}
|
||||
brew.save(meta);
|
||||
hand.setItemMeta(meta);
|
||||
p.msg(sender, p.languageReader.get("CMD_UnLabel"));
|
||||
return;
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||
|
||||
}
|
||||
|
||||
@ -572,54 +572,55 @@ public class CommandListener implements CommandExecutor {
|
||||
player = p.getServer().getPlayer(pName);
|
||||
}
|
||||
|
||||
if (sender instanceof Player || player != null) {
|
||||
if (player == null) {
|
||||
player = ((Player) sender);
|
||||
}
|
||||
int stringLength = args.length - 1;
|
||||
if (pName != null) {
|
||||
stringLength--;
|
||||
}
|
||||
if (hasQuality) {
|
||||
stringLength--;
|
||||
}
|
||||
|
||||
String name;
|
||||
if (stringLength > 1) {
|
||||
StringBuilder builder = new StringBuilder(args[1]);
|
||||
|
||||
for (int i = 2; i < stringLength + 1; i++) {
|
||||
builder.append(" ").append(args[i]);
|
||||
}
|
||||
name = builder.toString();
|
||||
} else {
|
||||
name = args[1];
|
||||
}
|
||||
|
||||
if (player.getInventory().firstEmpty() == -1) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "1"));
|
||||
return;
|
||||
}
|
||||
|
||||
BRecipe recipe = null;
|
||||
for (BRecipe r : BIngredients.recipes) {
|
||||
if (r.hasName(name)) {
|
||||
recipe = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (recipe != null) {
|
||||
ItemStack item = recipe.create(quality);
|
||||
if (item != null) {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_NoBrewName", name));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!(sender instanceof Player) && player == null) {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
player = ((Player) sender);
|
||||
}
|
||||
int stringLength = args.length - 1;
|
||||
if (pName != null) {
|
||||
stringLength--;
|
||||
}
|
||||
if (hasQuality) {
|
||||
stringLength--;
|
||||
}
|
||||
|
||||
String name;
|
||||
if (stringLength > 1) {
|
||||
StringBuilder builder = new StringBuilder(args[1]);
|
||||
|
||||
for (int i = 2; i < stringLength + 1; i++) {
|
||||
builder.append(" ").append(args[i]);
|
||||
}
|
||||
name = builder.toString();
|
||||
} else {
|
||||
name = args[1];
|
||||
}
|
||||
|
||||
if (player.getInventory().firstEmpty() == -1) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "1"));
|
||||
return;
|
||||
}
|
||||
|
||||
BRecipe recipe = null;
|
||||
for (BRecipe r : BIngredients.recipes) {
|
||||
if (r.hasName(name)) {
|
||||
recipe = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (recipe != null) {
|
||||
ItemStack item = recipe.create(quality);
|
||||
if (item != null) {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_NoBrewName", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
if (!Brew.noLegacy()) return;
|
||||
if (Brew.noLegacy()) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity.getType() == EntityType.DROPPED_ITEM) {
|
||||
if (entity instanceof Item) {
|
||||
|
@ -1,14 +1,9 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.lore.BrewLore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -19,28 +14,15 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Updated for 1.9 to replicate the "Brewing" process for distilling.
|
||||
* Because of how metadata has changed, the brewer no longer triggers as previously described.
|
||||
* So, I've added some event tracking and manual forcing of the brewing "animation" if the
|
||||
* set of ingredients in the brewer can be distilled.
|
||||
* Nothing here should interfere with vanilla brewing.
|
||||
*
|
||||
* @author ProgrammerDan (1.9 distillation update only)
|
||||
*/
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
/* === Recreating manually the prior BrewEvent behavior. === */
|
||||
private HashSet<UUID> trackedBrewmen = new HashSet<>();
|
||||
private HashMap<Block, Integer> trackedBrewers = new HashMap<>();
|
||||
private static final int DISTILLTIME = 400;
|
||||
|
||||
/**
|
||||
* Start tracking distillation for a person when they open the brewer window.
|
||||
@ -91,6 +73,7 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBrewerClick(InventoryClickEvent event) {
|
||||
if (!P.use1_9) return;
|
||||
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
Inventory inv = event.getInventory();
|
||||
if (player == null || !(inv instanceof BrewerInventory)) return;
|
||||
@ -101,171 +84,22 @@ public class InventoryListener implements Listener {
|
||||
if (InventoryType.BREWING != inv.getType()) return;
|
||||
if (event.getAction() == InventoryAction.NOTHING) return; // Ignore clicks that do nothing
|
||||
|
||||
BrewerInventory brewer = (BrewerInventory) inv;
|
||||
final Block brewery = brewer.getHolder().getBlock();
|
||||
|
||||
// If we were already tracking the brewer, cancel any ongoing event due to the click.
|
||||
Integer curTask = trackedBrewers.get(brewery);
|
||||
if (curTask != null) {
|
||||
Bukkit.getScheduler().cancelTask(curTask); // cancel prior
|
||||
brewer.getHolder().setBrewingTime(0); // Fixes brewing continuing without fuel for normal potions
|
||||
brewer.getHolder().update();
|
||||
}
|
||||
final int fuel = brewer.getHolder().getFuelLevel();
|
||||
|
||||
// Now check if we should bother to track it.
|
||||
trackedBrewers.put(brewery, new BukkitRunnable() {
|
||||
private int runTime = -1;
|
||||
private int brewTime = -1;
|
||||
@Override
|
||||
public void run() {
|
||||
BlockState now = brewery.getState();
|
||||
if (now instanceof BrewingStand) {
|
||||
BrewingStand stand = (BrewingStand) now;
|
||||
if (brewTime == -1) { // only check at the beginning (and end) for distillables
|
||||
switch (hasCustom(stand.getInventory())) {
|
||||
case 1:
|
||||
// Custom potion but not for distilling. Stop any brewing and cancel this task
|
||||
if (stand.getBrewingTime() > 0) {
|
||||
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
|
||||
stand.setBrewingTime(Short.MAX_VALUE);
|
||||
} else {
|
||||
// Brewing time is sent and stored as short
|
||||
// This sends a negative short value to the Client
|
||||
// In the client the Brewer will look like it is not doing anything
|
||||
stand.setBrewingTime(Short.MAX_VALUE << 1);
|
||||
}
|
||||
stand.setFuelLevel(fuel);
|
||||
stand.update();
|
||||
}
|
||||
case 0:
|
||||
// No custom potion, cancel and ignore
|
||||
this.cancel();
|
||||
trackedBrewers.remove(brewery);
|
||||
P.p.debugLog("nothing to distill");
|
||||
return;
|
||||
default:
|
||||
runTime = getLongestDistillTime(stand.getInventory());
|
||||
brewTime = runTime;
|
||||
P.p.debugLog("using brewtime: " + runTime);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
brewTime--; // count down.
|
||||
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
|
||||
|
||||
if (brewTime <= 1) { // Done!
|
||||
stand.setBrewingTime(0);
|
||||
stand.update();
|
||||
BrewerInventory brewer = stand.getInventory();
|
||||
if (!runDistill(brewer)) {
|
||||
this.cancel();
|
||||
trackedBrewers.remove(brewery);
|
||||
P.p.debugLog("All done distilling");
|
||||
} else {
|
||||
brewTime = -1; // go again.
|
||||
P.p.debugLog("Can distill more! Continuing.");
|
||||
}
|
||||
} else {
|
||||
stand.update();
|
||||
}
|
||||
} else {
|
||||
this.cancel();
|
||||
trackedBrewers.remove(brewery);
|
||||
P.p.debugLog("The block was replaced; not a brewing stand.");
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(P.p, 2L, 1L).getTaskId());
|
||||
}
|
||||
|
||||
// Returns a Brew or null for every Slot in the BrewerInventory
|
||||
private Brew[] getDistillContents(BrewerInventory inv) {
|
||||
ItemStack item;
|
||||
Brew[] contents = new Brew[3];
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
item = inv.getItem(slot);
|
||||
if (item != null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return customFound;
|
||||
BDistiller.distillerClick(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBrew(BrewEvent event) {
|
||||
if (P.use1_9) {
|
||||
if (hasCustom(event.getContents()) != 0) {
|
||||
if (BDistiller.hasBrew(event.getContents()) != 0) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (runDistill(event.getContents())) {
|
||||
if (BDistiller.runDistill(event.getContents())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean runDistill(BrewerInventory inv) {
|
||||
boolean custom = false;
|
||||
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) {
|
||||
Brew.distillAll(inv, contents);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getLongestDistillTime(BrewerInventory inv) {
|
||||
int bestTime = 0;
|
||||
int time;
|
||||
Brew[] contents = getDistillContents(inv);
|
||||
for (int slot = 0; slot < 3; slot++) {
|
||||
if (contents[slot] == null) continue;
|
||||
time = contents[slot].getDistillTimeNextRun();
|
||||
if (time == 0) {
|
||||
// Undefined Potion needs 40 seconds
|
||||
time = 800;
|
||||
}
|
||||
if (time > bestTime) {
|
||||
bestTime = time;
|
||||
}
|
||||
}
|
||||
if (bestTime > 0) {
|
||||
return bestTime;
|
||||
}
|
||||
return 800;
|
||||
}
|
||||
|
||||
// Clicked a Brew somewhere, do some updating
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
|
||||
public void onInventoryClickLow(InventoryClickEvent event) {
|
||||
@ -366,19 +200,15 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item != null) {
|
||||
if (item.getType() == Material.POTION) {
|
||||
if (item.hasItemMeta()) {
|
||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
Brew brew = Brew.get(meta);
|
||||
if (brew != null) {
|
||||
if (BrewLore.hasColorLore(meta)) {
|
||||
BrewLore lore = new BrewLore(brew, meta);
|
||||
lore.convertLore(false);
|
||||
lore.write();
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (item != null && item.getType() == Material.POTION && item.hasItemMeta()) {
|
||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
Brew brew = Brew.get(meta);
|
||||
if (brew != null) {
|
||||
if (BrewLore.hasColorLore(meta)) {
|
||||
BrewLore lore = new BrewLore(brew, meta);
|
||||
lore.convertLore(false);
|
||||
lore.write();
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -437,7 +267,7 @@ public class InventoryListener implements Listener {
|
||||
// block the pickup of items where getPickupDelay is > 1000 (puke)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryPickupItem(InventoryPickupItemEvent event){
|
||||
if (event.getItem().getPickupDelay() > 1000 && event.getItem().getItemStack().getType() == BPlayer.pukeItem) {
|
||||
if (event.getItem().getPickupDelay() > 1000 && event.getItem().getItemStack().getType() == BConfig.pukeItem) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -449,13 +279,7 @@ public class InventoryListener implements Listener {
|
||||
// Barrel Closing Sound
|
||||
if (event.getInventory().getHolder() instanceof Barrel) {
|
||||
Barrel barrel = ((Barrel) event.getInventory().getHolder());
|
||||
float randPitch = (float) (Math.random() * 0.1);
|
||||
if (barrel.isLarge()) {
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.5f + randPitch);
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.2f, 0.6f + randPitch);
|
||||
} else {
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||
}
|
||||
barrel.playClosingSound();
|
||||
}
|
||||
|
||||
// Check for MC Barrel
|
||||
|
@ -1,13 +1,11 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.filedata.UpdateChecker;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,219 +16,93 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
public static boolean openEverywhere;
|
||||
private static Set<UUID> interacted = new HashSet<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
if (clickedBlock == null) return;
|
||||
|
||||
if (clickedBlock != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isSneaking()) {
|
||||
Material type = clickedBlock.getType();
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
|
||||
// Interacting with a Cauldron
|
||||
if (type == Material.CAULDRON) {
|
||||
Material materialInHand = event.getMaterial();
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
if (player.isSneaking()) return;
|
||||
|
||||
if (materialInHand == null || materialInHand == Material.BUCKET) {
|
||||
return;
|
||||
Material type = clickedBlock.getType();
|
||||
|
||||
} else if (materialInHand == LegacyUtil.CLOCK) {
|
||||
BCauldron.printTime(player, clickedBlock);
|
||||
return;
|
||||
// Interacting with a Cauldron
|
||||
if (type == Material.CAULDRON) {
|
||||
// Handle the Cauldron Interact
|
||||
// The Event might get cancelled in here
|
||||
BCauldron.clickCauldron(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// fill a glass bottle with potion
|
||||
} else if (materialInHand == Material.GLASS_BOTTLE) {
|
||||
if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) {
|
||||
if (BCauldron.fill(player, clickedBlock)) {
|
||||
event.setCancelled(true);
|
||||
if (player.hasPermission("brewery.cauldron.fill")) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
setItemInHand(event, Material.AIR, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
// Do not process Off Hand for Barrel interaction
|
||||
if (P.use1_9 && event.getHand() != EquipmentSlot.HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reset cauldron when refilling to prevent unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (!P.use1_9) {
|
||||
// We catch >=1.9 cases in the Cauldron Listener
|
||||
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if fire alive below cauldron when adding ingredients
|
||||
Block down = clickedBlock.getRelative(BlockFace.DOWN);
|
||||
if (LegacyUtil.isFireForCauldron(down)) {
|
||||
|
||||
event.setCancelled(true);
|
||||
boolean handSwap = false;
|
||||
|
||||
// Interact event is called twice!!!?? in 1.9, once for each hand.
|
||||
// Certain Items in Hand cause one of them to be cancelled or not called at all sometimes.
|
||||
// We mark if a player had the event for the main hand
|
||||
// If not, we handle the main hand in the event for the off hand
|
||||
if (P.use1_9) {
|
||||
if (event.getHand() == EquipmentSlot.HAND) {
|
||||
final UUID id = player.getUniqueId();
|
||||
interacted.add(id);
|
||||
P.p.getServer().getScheduler().runTask(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
interacted.remove(id);
|
||||
}
|
||||
});
|
||||
} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
if (!interacted.remove(player.getUniqueId())) {
|
||||
item = player.getInventory().getItemInMainHand();
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
materialInHand = item.getType();
|
||||
handSwap = true;
|
||||
} else {
|
||||
item = event.getItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item == null) return;
|
||||
|
||||
// add ingredient to cauldron that meet the previous conditions
|
||||
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
|
||||
if (player.hasPermission("brewery.cauldron.insert")) {
|
||||
if (BCauldron.ingredientAdd(clickedBlock, item, player)) {
|
||||
boolean isBucket = item.getType().equals(Material.WATER_BUCKET)
|
||||
|| item.getType().equals(Material.LAVA_BUCKET)
|
||||
|| item.getType().equals(Material.MILK_BUCKET);
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
|
||||
if (isBucket) {
|
||||
BCauldron.giveItem(player, new ItemStack(Material.BUCKET));
|
||||
}
|
||||
} else {
|
||||
if (isBucket) {
|
||||
setItemInHand(event, Material.BUCKET, handSwap);
|
||||
} else {
|
||||
setItemInHand(event, Material.AIR, handSwap);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoCauldronInsert"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (P.use1_9 && event.getHand() != EquipmentSlot.HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Access a Barrel
|
||||
Barrel barrel = null;
|
||||
if (LegacyUtil.isWoodPlanks(type)) {
|
||||
if (openEverywhere) {
|
||||
barrel = Barrel.get(clickedBlock);
|
||||
}
|
||||
} else if (LegacyUtil.isWoodStairs(type)) {
|
||||
for (Barrel barrel2 : Barrel.barrels) {
|
||||
if (barrel2.hasStairsBlock(clickedBlock)) {
|
||||
if (openEverywhere || !barrel2.isLarge()) {
|
||||
barrel = barrel2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type)) {
|
||||
barrel = Barrel.getBySpigot(clickedBlock);
|
||||
}
|
||||
|
||||
if (barrel != null) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (!barrel.hasPermsOpen(player, event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
barrel.open(player);
|
||||
|
||||
if (P.use1_14) {
|
||||
|
||||
// When right clicking a normal Block in 1.14 with a potion or any edible item in hand,
|
||||
// even when cancelled the consume animation will continue playing while opening the Barrel inventory.
|
||||
// The Animation and sound will play endlessly while the inventory is open, though no item is consumed.
|
||||
// This seems to be a client bug.
|
||||
// This workaround switches the currently selected slot to another for a short time, it needs to be a slot with a different item in it.
|
||||
// This seems to make the client stop animating a consumption
|
||||
// If there is a better way to do this please let me know
|
||||
Material hand = event.getMaterial();
|
||||
if ((hand == Material.POTION || hand.isEdible()) && !LegacyUtil.isSign(type)) {
|
||||
PlayerInventory inv = player.getInventory();
|
||||
final int held = inv.getHeldItemSlot();
|
||||
int useSlot = -1;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack item = inv.getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
useSlot = i;
|
||||
break;
|
||||
} else if (useSlot == -1 && item.getType() != hand) {
|
||||
useSlot = i;
|
||||
}
|
||||
}
|
||||
if (useSlot != -1) {
|
||||
inv.setHeldItemSlot(useSlot);
|
||||
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.getInventory().setHeldItemSlot(held), 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Barrel opening Sound
|
||||
float randPitch = (float) (Math.random() * 0.1);
|
||||
if (barrel.isLarge()) {
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.4f, 0.55f + randPitch);
|
||||
//barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.5f, 0.6f + randPitch);
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 0.4f, 0.45f + randPitch);
|
||||
} else {
|
||||
barrel.getSpigot().getWorld().playSound(barrel.getSpigot().getLocation(), Sound.BLOCK_BARREL_OPEN, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||
}
|
||||
}
|
||||
// Access a Barrel
|
||||
Barrel barrel = null;
|
||||
if (LegacyUtil.isWoodPlanks(type)) {
|
||||
if (BConfig.openEverywhere) {
|
||||
barrel = Barrel.get(clickedBlock);
|
||||
}
|
||||
} else if (LegacyUtil.isWoodStairs(type)) {
|
||||
for (Barrel barrel2 : Barrel.barrels) {
|
||||
if (barrel2.hasStairsBlock(clickedBlock)) {
|
||||
if (BConfig.openEverywhere || !barrel2.isLarge()) {
|
||||
barrel = barrel2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type)) {
|
||||
barrel = Barrel.getBySpigot(clickedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public 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));
|
||||
if (barrel != null) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (!barrel.hasPermsOpen(player, event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
barrel.open(player);
|
||||
|
||||
if (P.use1_14) {
|
||||
|
||||
// When right clicking a normal Block in 1.14 with a potion or any edible item in hand,
|
||||
// even when cancelled, the consume animation will continue playing while opening the Barrel inventory.
|
||||
// The Animation and sound will play endlessly while the inventory is open, though no item is consumed.
|
||||
// This seems to be a client bug.
|
||||
// This workaround switches the currently selected slot to another for a short time, it needs to be a slot with a different item in it.
|
||||
// This seems to make the client stop animating a consumption
|
||||
// If there is a better way to do this please let me know
|
||||
Material hand = event.getMaterial();
|
||||
if ((hand == Material.POTION || hand.isEdible()) && !LegacyUtil.isSign(type)) {
|
||||
PlayerInventory inv = player.getInventory();
|
||||
final int held = inv.getHeldItemSlot();
|
||||
int useSlot = -1;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack item = inv.getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
useSlot = i;
|
||||
break;
|
||||
} else if (useSlot == -1 && item.getType() != hand) {
|
||||
useSlot = i;
|
||||
}
|
||||
}
|
||||
if (useSlot != -1) {
|
||||
inv.setHeldItemSlot(useSlot);
|
||||
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.getInventory().setHeldItemSlot(held), 2);
|
||||
}
|
||||
}
|
||||
|
||||
barrel.playOpeningSound();
|
||||
}
|
||||
} else {
|
||||
event.getPlayer().setItemInHand(new ItemStack(mat));
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,7 +145,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
||||
} else if (BConfig.drainItems.containsKey(item.getType())) {
|
||||
BPlayer bplayer = BPlayer.get(player);
|
||||
if (bplayer != null) {
|
||||
bplayer.drainByItem(player, item.getType());
|
||||
@ -306,13 +178,13 @@ public class PlayerListener implements Listener {
|
||||
// player talks while drunk, but he cant speak very well
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
Words.playerChat(event);
|
||||
DistortChat.playerChat(event);
|
||||
}
|
||||
|
||||
// player commands while drunk, distort chat commands
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
|
||||
Words.playerCommand(event);
|
||||
DistortChat.playerCommand(event);
|
||||
}
|
||||
|
||||
// player joins while passed out
|
||||
|
@ -4,6 +4,7 @@ import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.BUtil;
|
||||
import com.dre.brewery.filedata.BData;
|
||||
import com.dre.brewery.filedata.DataSave;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -19,9 +20,9 @@ public class WorldListener implements Listener {
|
||||
World world = event.getWorld();
|
||||
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
P.p.loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
BData.loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
} else {
|
||||
P.p.loadWorldData(world.getUID().toString(), world);
|
||||
BData.loadWorldData(world.getUID().toString(), world);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user