Refractor Utility

This commit is contained in:
Sn0wStorm 2019-10-16 20:07:09 +02:00
parent 7d177a3d9f
commit 437f521a9b
28 changed files with 147 additions and 128 deletions

View File

@ -1,6 +1,8 @@
package com.dre.brewery;
import com.dre.brewery.api.events.IngedientAddEvent;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
import com.dre.brewery.utility.BUtil;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;

View File

@ -2,6 +2,7 @@ package com.dre.brewery;
import com.dre.brewery.api.events.brew.BrewModifyEvent;
import com.dre.brewery.lore.BrewLore;
import com.dre.brewery.utility.PotionColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;

View File

@ -6,6 +6,7 @@ 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 com.dre.brewery.utility.BUtil;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@ -1,6 +1,7 @@
package com.dre.brewery;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.utility.PotionColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;

View File

@ -7,6 +7,8 @@ import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.integration.LogBlockBarrel;
import com.dre.brewery.lore.BrewLore;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;

View File

@ -1,5 +1,7 @@
package com.dre.brewery;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@ -3,6 +3,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 com.dre.brewery.utility.PotionColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.BrewerInventory;

View File

@ -8,6 +8,7 @@ import com.dre.brewery.filedata.UpdateChecker;
import com.dre.brewery.integration.IntegrationListener;
import com.dre.brewery.integration.LogBlockBarrel;
import com.dre.brewery.listeners.*;
import com.dre.brewery.utility.BUtil;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
import com.dre.brewery.utility.BUtil;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;

View File

@ -1,9 +1,8 @@
package com.dre.brewery.api.events;
import com.dre.brewery.BCauldron;
import com.dre.brewery.LegacyUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Player;
@ -11,8 +10,6 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Cauldron;
import org.bukkit.material.MaterialData;
/*
* Player adding an ingredient to a cauldron

View File

@ -3,8 +3,9 @@ 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 com.dre.brewery.integration.WGBarrel6;
import com.dre.brewery.integration.WGBarrel5;
import com.dre.brewery.utility.BUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
@ -138,9 +139,9 @@ public class BConfig {
if (plugin != null) {
String wgv = plugin.getDescription().getVersion();
if (wgv.startsWith("6.")) {
wg = new WGBarrelNew();
wg = new WGBarrel6();
} else if (wgv.startsWith("5.")) {
wg = new WGBarrelOld();
wg = new WGBarrel5();
} else {
wg = new WGBarrel7();
}

View File

@ -1,6 +1,7 @@
package com.dre.brewery.filedata;
import com.dre.brewery.*;
import com.dre.brewery.utility.BUtil;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@ -1,6 +1,6 @@
package com.dre.brewery.filedata;
import com.dre.brewery.LegacyUtil;
import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.P;
import org.bukkit.Material;

View File

@ -4,7 +4,7 @@ package com.dre.brewery.filedata;
import java.io.File;
import com.dre.brewery.MCBarrel;
import com.dre.brewery.BUtil;
import com.dre.brewery.utility.BUtil;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

View File

@ -1,107 +1,106 @@
package com.dre.brewery.filedata;
import com.dre.brewery.LegacyUtil;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import com.dre.brewery.P;
public class DataUpdater {
private FileConfiguration data;
private File file;
public DataUpdater(FileConfiguration data, File file) {
this.data = data;
this.file = file;
}
public void update(String fromVersion) {
if (fromVersion.equalsIgnoreCase("1.0")) {
update10();
//fromVersion = "1.1";
}
try {
data.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void update10() {
data.set("Version", DataSave.dataVersion);
ConfigurationSection section = data.getConfigurationSection("Ingredients");
try {
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
Map<String, Integer> ingredients = new HashMap<>();
for (String ingredient : matSection.getKeys(false)) {
// convert to Material
Material mat = LegacyUtil.getMaterial(P.p.parseInt(ingredient));
if (mat != null) {
ingredients.put(mat.name(), matSection.getInt(ingredient));
}
}
section.set(id + ".mats", ingredients);
} else {
P.p.errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
}
}
}
} catch (Exception e) {
// Getting Material by id may not work in the future
P.p.errorLog("Error Converting Ingredient Section of the Data File, newer versions of Bukkit may not support the old Save File anymore:");
e.printStackTrace();
}
section = data.getConfigurationSection("BCauldron");
if (section != null) {
try {
for (String uuid : section.getKeys(false)) {
ConfigurationSection cauldrons = section.getConfigurationSection(uuid);
if (cauldrons != null) {
for (String id : cauldrons.getKeys(false)) {
ConfigurationSection ingredientSection = cauldrons.getConfigurationSection(id + ".ingredients");
if (ingredientSection != null) {
// has all the materials + amount as Integers
Map<String, Integer> ingredients = new HashMap<>();
for (String ingredient : ingredientSection.getKeys(false)) {
// convert to Material
Material mat = LegacyUtil.getMaterial(P.p.parseInt(ingredient));
if (mat != null) {
ingredients.put(mat.name(), ingredientSection.getInt(ingredient));
}
}
cauldrons.set(id + ".ingredients", ingredients);
} else {
P.p.errorLog("BCauldron " + id + " is missing Ingredient Section");
}
}
}
}
} catch (Exception e) {
// Getting Material by id may not work in the future
P.p.errorLog("Error Converting Ingredient Section of Cauldrons, newer versions of Bukkit may not support the old Save File anymore:");
e.printStackTrace();
}
}
}
}
package com.dre.brewery.filedata;
import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.P;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class DataUpdater {
private FileConfiguration data;
private File file;
public DataUpdater(FileConfiguration data, File file) {
this.data = data;
this.file = file;
}
public void update(String fromVersion) {
if (fromVersion.equalsIgnoreCase("1.0")) {
update10();
//fromVersion = "1.1";
}
try {
data.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void update10() {
data.set("Version", DataSave.dataVersion);
ConfigurationSection section = data.getConfigurationSection("Ingredients");
try {
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
Map<String, Integer> ingredients = new HashMap<>();
for (String ingredient : matSection.getKeys(false)) {
// convert to Material
Material mat = LegacyUtil.getMaterial(P.p.parseInt(ingredient));
if (mat != null) {
ingredients.put(mat.name(), matSection.getInt(ingredient));
}
}
section.set(id + ".mats", ingredients);
} else {
P.p.errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
}
}
}
} catch (Exception e) {
// Getting Material by id may not work in the future
P.p.errorLog("Error Converting Ingredient Section of the Data File, newer versions of Bukkit may not support the old Save File anymore:");
e.printStackTrace();
}
section = data.getConfigurationSection("BCauldron");
if (section != null) {
try {
for (String uuid : section.getKeys(false)) {
ConfigurationSection cauldrons = section.getConfigurationSection(uuid);
if (cauldrons != null) {
for (String id : cauldrons.getKeys(false)) {
ConfigurationSection ingredientSection = cauldrons.getConfigurationSection(id + ".ingredients");
if (ingredientSection != null) {
// has all the materials + amount as Integers
Map<String, Integer> ingredients = new HashMap<>();
for (String ingredient : ingredientSection.getKeys(false)) {
// convert to Material
Material mat = LegacyUtil.getMaterial(P.p.parseInt(ingredient));
if (mat != null) {
ingredients.put(mat.name(), ingredientSection.getInt(ingredient));
}
}
cauldrons.set(id + ".ingredients", ingredients);
} else {
P.p.errorLog("BCauldron " + id + " is missing Ingredient Section");
}
}
}
}
} catch (Exception e) {
// Getting Material by id may not work in the future
P.p.errorLog("Error Converting Ingredient Section of Cauldrons, newer versions of Bukkit may not support the old Save File anymore:");
e.printStackTrace();
}
}
}
}

View File

@ -1,7 +1,7 @@
package com.dre.brewery.integration;
import com.dre.brewery.Barrel;
import com.dre.brewery.LegacyUtil;
import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.P;
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;

View File

@ -1,6 +1,6 @@
package com.dre.brewery.integration;
import com.dre.brewery.LegacyUtil;
import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.P;
import de.diddiz.LogBlock.Actor;

View File

@ -17,13 +17,13 @@ import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
public class WGBarrelOld implements WGBarrel {
public class WGBarrel5 implements WGBarrel {
private Method allows;
private Method canBuild;
private Method getApplicableRegions;
public WGBarrelOld() {
public WGBarrel5() {
try {
allows = ApplicableRegionSet.class.getMethod("allows", StateFlag.class, LocalPlayer.class);
canBuild = ApplicableRegionSet.class.getMethod("canBuild", LocalPlayer.class);

View File

@ -9,7 +9,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WGBarrelNew implements WGBarrel {
public class WGBarrel6 implements WGBarrel {
public boolean checkAccess(Player player, Block spigot, Plugin plugin) {
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;

View File

@ -1,7 +1,7 @@
package com.dre.brewery.listeners;
import com.dre.brewery.BPlayer;
import com.dre.brewery.BUtil;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.Barrel;
import com.dre.brewery.P;
import com.dre.brewery.DistortChat;

View File

@ -3,6 +3,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 com.dre.brewery.utility.BUtil;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;

View File

@ -3,6 +3,7 @@ package com.dre.brewery.listeners;
import com.dre.brewery.*;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.filedata.UpdateChecker;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@ -2,8 +2,7 @@ package com.dre.brewery.listeners;
import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel;
import com.dre.brewery.P;
import com.dre.brewery.BUtil;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.filedata.BData;
import com.dre.brewery.filedata.DataSave;
import org.bukkit.World;

View File

@ -1,6 +1,7 @@
package com.dre.brewery.lore;
import com.dre.brewery.*;
import com.dre.brewery.utility.BUtil;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

View File

@ -1,5 +1,8 @@
package com.dre.brewery;
package com.dre.brewery.utility;
import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel;
import com.dre.brewery.P;
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
package com.dre.brewery.utility;
import com.dre.brewery.P;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
package com.dre.brewery.utility;
import com.dre.brewery.P;
import org.bukkit.Color;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -39,6 +40,7 @@ public class PotionColor {
// gets the Damage Value, that sets a color on the potion
// offset +32 is not accepted by brewer, so not further destillable
// Only for minecraft pre 1.9
public short getColorId(boolean destillable) {
if (destillable) {
return (short) (colorId + 64);