mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-06 18:47:44 +01:00
Convert on Chest Open, delete lost legacy brews
This commit is contained in:
parent
318963b379
commit
48a15a0e82
@ -903,6 +903,10 @@ public class Brew {
|
||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
||||
Brew brew = new Brew(ingredients, quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
||||
brew.persistent = persistent;
|
||||
if (brew.lastUpdate <= 0) {
|
||||
// We failed to save the lastUpdate, restart the countdown
|
||||
brew.touch();
|
||||
}
|
||||
legacyPotions.put(uid, brew);
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,31 @@ public class BData {
|
||||
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
|
||||
boolean persistent = section.getBoolean(uid + ".persist", false);
|
||||
boolean stat = section.getBoolean(uid + ".stat", false);
|
||||
int lastUpdate = section.getInt("lastUpdate", 0);
|
||||
int lastUpdate = section.getInt(uid + ".lastUpdate", 0);
|
||||
|
||||
Brew.loadLegacy(ingredients, P.p.parseInt(uid), quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove Legacy Potions that haven't been touched in a long time, these may have been lost
|
||||
if (!Brew.noLegacy()) {
|
||||
int currentHoursAfterInstall = (int) ((double) (System.currentTimeMillis() - Brew.installTime) / 3600000D);
|
||||
int purgeTime = currentHoursAfterInstall - (24 * 30 * 4); // Purge Time is 4 Months ago
|
||||
if (purgeTime > 0) {
|
||||
int removed = 0;
|
||||
for (Iterator<Brew> iterator = Brew.legacyPotions.values().iterator(); iterator.hasNext(); ) {
|
||||
Brew brew = iterator.next();
|
||||
if (brew.getLastUpdate() < purgeTime) {
|
||||
iterator.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
if (removed > 0) {
|
||||
P.p.log("Removed " + removed + " Legacy Brews older than 3 months");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading BPlayer
|
||||
section = data.getConfigurationSection("Player");
|
||||
if (section != null) {
|
||||
@ -133,7 +152,7 @@ public class BData {
|
||||
}
|
||||
|
||||
} else {
|
||||
P.p.errorLog("No data.yml found, will create new one!");
|
||||
P.p.log("No data.yml found, will create new one!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
package com.dre.brewery.integration.barrel;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.brewery.P;
|
||||
|
||||
import vg.civcraft.mc.citadel.Citadel;
|
||||
import vg.civcraft.mc.citadel.ReinforcementManager;
|
||||
import vg.civcraft.mc.citadel.reinforcement.NullReinforcement;
|
||||
import vg.civcraft.mc.citadel.reinforcement.PlayerReinforcement;
|
||||
import vg.civcraft.mc.citadel.reinforcement.Reinforcement;
|
||||
|
||||
/**
|
||||
* Basic Citadel support to prevent randos from stealing your barrel aging brews
|
||||
*
|
||||
* @author ProgrammerDan
|
||||
*/
|
||||
public class CitadelBarrel {
|
||||
static P brewery = P.p;
|
||||
|
||||
public static boolean checkAccess(Player player, Block sign) {
|
||||
ReinforcementManager manager = Citadel.getReinforcementManager();
|
||||
|
||||
Reinforcement rein = manager.getReinforcement(sign);
|
||||
|
||||
if (rein == null) return true; // no protections in place.
|
||||
|
||||
if (rein instanceof PlayerReinforcement) {
|
||||
PlayerReinforcement prein = (PlayerReinforcement) rein;
|
||||
if (prein.canAccessChests(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (rein instanceof NullReinforcement) {
|
||||
return true;
|
||||
}
|
||||
// no support for multiblock atm, would require namelayer support.
|
||||
|
||||
// special locked, or no access.
|
||||
brewery.msg(player, brewery.languageReader.get("Error_NoBarrelAccess"));
|
||||
return false;
|
||||
}
|
||||
}
|
@ -249,6 +249,27 @@ public class InventoryListener implements Listener {
|
||||
|
||||
//public static boolean opening = false;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(ignoreCancelled = false)
|
||||
public void onInventoryOpenLegacyConvert(InventoryOpenEvent event) {
|
||||
if (Brew.noLegacy()) {
|
||||
return;
|
||||
}
|
||||
if (event.getInventory().getType() == InventoryType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack item : event.getInventory().getContents()) {
|
||||
if (item != null && item.getType() == Material.POTION) {
|
||||
int uid = Brew.getUID(item);
|
||||
// Check if the uid exists first, otherwise it will log that it can't find the id
|
||||
if (uid < 0 && Brew.legacyPotions.containsKey(uid)) {
|
||||
// This will convert the Brew
|
||||
Brew.get(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (!P.use1_14) return;
|
||||
|
Loading…
Reference in New Issue
Block a user