2016-04-23 17:45:01 +02:00
|
|
|
package com.dre.brewery;
|
|
|
|
|
2019-10-16 17:21:04 +02:00
|
|
|
import com.dre.brewery.filedata.BConfig;
|
|
|
|
import com.dre.brewery.filedata.BData;
|
2019-08-18 15:42:22 +02:00
|
|
|
import com.dre.brewery.filedata.DataSave;
|
|
|
|
import com.dre.brewery.filedata.LanguageReader;
|
|
|
|
import com.dre.brewery.filedata.UpdateChecker;
|
2019-10-16 17:21:04 +02:00
|
|
|
import com.dre.brewery.integration.IntegrationListener;
|
2019-11-06 19:44:52 +01:00
|
|
|
import com.dre.brewery.integration.barrel.LogBlockBarrel;
|
2019-10-12 13:52:55 +02:00
|
|
|
import com.dre.brewery.listeners.*;
|
2019-11-06 19:44:52 +01:00
|
|
|
import com.dre.brewery.recipe.BCauldronRecipe;
|
|
|
|
import com.dre.brewery.recipe.BRecipe;
|
2019-10-16 20:07:09 +02:00
|
|
|
import com.dre.brewery.utility.BUtil;
|
2019-10-20 21:06:35 +02:00
|
|
|
import com.dre.brewery.utility.LegacyUtil;
|
2016-04-23 17:45:01 +02:00
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2019-11-14 16:16:12 +01:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2016-04-23 17:45:01 +02:00
|
|
|
import org.bukkit.event.HandlerList;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2019-08-18 15:42:22 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
2016-04-23 17:45:01 +02:00
|
|
|
public class P extends JavaPlugin {
|
|
|
|
public static P p;
|
|
|
|
public static boolean debug;
|
|
|
|
public static boolean useUUID;
|
2019-10-20 21:06:35 +02:00
|
|
|
public static boolean useNBT;
|
2016-04-23 17:45:01 +02:00
|
|
|
public static boolean use1_9;
|
2018-10-31 22:25:32 +01:00
|
|
|
public static boolean use1_11;
|
2018-01-28 20:48:27 +01:00
|
|
|
public static boolean use1_13;
|
2019-06-28 16:53:44 +02:00
|
|
|
public static boolean use1_14;
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
// Listeners
|
|
|
|
public BlockListener blockListener;
|
|
|
|
public PlayerListener playerListener;
|
|
|
|
public EntityListener entityListener;
|
|
|
|
public InventoryListener inventoryListener;
|
|
|
|
public WorldListener worldListener;
|
2016-07-09 00:01:31 +02:00
|
|
|
public IntegrationListener integrationListener;
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
// Language
|
|
|
|
public String language;
|
|
|
|
public LanguageReader languageReader;
|
|
|
|
|
2019-11-23 19:59:53 +01:00
|
|
|
// Metrics
|
|
|
|
public int brewsCreated;
|
|
|
|
public int exc, good, norm, bad, terr;
|
|
|
|
|
2016-04-23 17:45:01 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
p = this;
|
|
|
|
|
|
|
|
// Version check
|
|
|
|
String v = Bukkit.getBukkitVersion();
|
2018-10-30 15:59:56 +01:00
|
|
|
useUUID = !v.matches("(^|.*[^.\\d])1\\.[0-6]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.7\\.[0-5]([^\\d].*|$)");
|
|
|
|
use1_9 = !v.matches("(^|.*[^.\\d])1\\.[0-8]([^\\d].*|$)");
|
2018-10-31 22:25:32 +01:00
|
|
|
use1_11 = !v.matches("(^|.*[^.\\d])1\\.10([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)");
|
2018-10-30 15:59:56 +01:00
|
|
|
use1_13 = !v.matches("(^|.*[^.\\d])1\\.1[0-2]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)");
|
2019-06-28 16:53:44 +02:00
|
|
|
use1_14 = !v.matches("(^|.*[^.\\d])1\\.1[0-3]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)");
|
|
|
|
|
2019-10-20 21:06:35 +02:00
|
|
|
//MC 1.13 uses a different NBT API than the newer versions..
|
|
|
|
// We decide here which to use, the new or the old or none at all
|
|
|
|
P.debug = true;
|
|
|
|
if (LegacyUtil.initNbt()) {
|
|
|
|
useNBT = true;
|
|
|
|
}
|
|
|
|
|
2019-06-28 16:53:44 +02:00
|
|
|
//P.p.log("§" + (use1_9 ? "a":"c") + "1.9 " + "§" + (use1_11 ? "a":"c") + "1.11 " + "§" + (use1_13 ? "a":"c") + "1.13 " + "§" + (use1_14 ? "a":"c") + "1.14");
|
2016-04-23 17:45:01 +02:00
|
|
|
|
2016-06-29 22:44:19 +02:00
|
|
|
/*long master = new SecureRandom().nextLong();
|
|
|
|
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
|
|
|
XORScrambleStream scramble = new XORScrambleStream(new Base91EncoderStream(byteStream), master);
|
|
|
|
DataOutputStream data = new DataOutputStream(scramble);
|
|
|
|
DataInputStream dataIn = null;
|
|
|
|
try {
|
|
|
|
scramble.start();
|
|
|
|
data.writeLong(12345L);
|
|
|
|
scramble.stop();
|
|
|
|
data.writeInt(1);
|
|
|
|
data.writeInt(1);
|
|
|
|
scramble.start();
|
|
|
|
data.writeDouble(0.55555D);
|
|
|
|
data.writeInt(234323);
|
|
|
|
//data.writeUTF("Hallo Peter");
|
|
|
|
data.writeLong(5419L); // Skip
|
|
|
|
data.writeDouble(0.55555D);
|
|
|
|
|
|
|
|
data.close();
|
|
|
|
|
|
|
|
XORUnscrambleStream unscramble = new XORUnscrambleStream(new Base91DecoderStream(new ByteArrayInputStream(byteStream.toByteArray())), master);
|
|
|
|
dataIn = new DataInputStream(unscramble);
|
|
|
|
unscramble.start();
|
|
|
|
P.p.log(dataIn.readLong() + "");
|
|
|
|
unscramble.stop();
|
|
|
|
P.p.log(dataIn.readInt() + "");
|
|
|
|
P.p.log(dataIn.readInt() + "");
|
|
|
|
unscramble.start();
|
|
|
|
P.p.log(dataIn.readDouble() + "");
|
|
|
|
dataIn.mark(1000);
|
|
|
|
P.p.log(dataIn.readInt() + "");
|
|
|
|
//P.p.log(dataIn.readUTF());
|
|
|
|
dataIn.skip(8);
|
|
|
|
P.p.log(dataIn.readDouble() + "");
|
|
|
|
P.p.log("reset");
|
|
|
|
dataIn.reset();
|
|
|
|
P.p.log(dataIn.readInt() + "");
|
|
|
|
//P.p.log(dataIn.readUTF());
|
|
|
|
dataIn.skip(8);
|
|
|
|
P.p.log(dataIn.readDouble() + "");
|
|
|
|
|
|
|
|
dataIn.close();
|
|
|
|
|
|
|
|
*//*for (int i = 0; i < 10; i++) {
|
|
|
|
byteStream = new ByteArrayOutputStream();
|
|
|
|
scramble = new XORScrambleStream(new Base91EncoderStream(byteStream));
|
|
|
|
data = new DataOutputStream(scramble);
|
|
|
|
data.writeInt(i);
|
|
|
|
scramble.start();
|
|
|
|
data.writeLong(12345L);
|
|
|
|
data.writeLong(12345L);
|
|
|
|
scramble.stop();
|
|
|
|
data.writeInt(1);
|
|
|
|
data.writeInt(1);
|
|
|
|
scramble.start();
|
|
|
|
data.writeInt(234323);
|
|
|
|
data.writeDouble(0.55555D);
|
|
|
|
|
|
|
|
P.p.log(byteStream.toString());
|
|
|
|
data.close();
|
|
|
|
}*//*
|
|
|
|
|
|
|
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
for (int i = 0; i < 100000; i++) {
|
|
|
|
unscramble = new XORUnscrambleStream(new Base91DecoderStream(new ByteArrayInputStream(byteStream.toByteArray())), master);
|
|
|
|
dataIn = new DataInputStream(unscramble);
|
|
|
|
unscramble.start();
|
|
|
|
dataIn.readLong();
|
|
|
|
unscramble.stop();
|
|
|
|
dataIn.readInt();
|
|
|
|
dataIn.readInt();
|
|
|
|
unscramble.start();
|
|
|
|
dataIn.readDouble();
|
|
|
|
dataIn.mark(1000);
|
|
|
|
dataIn.readInt();
|
|
|
|
//dataIn.readUTF();
|
|
|
|
dataIn.skip(8);
|
|
|
|
dataIn.readDouble();
|
|
|
|
dataIn.reset();
|
|
|
|
dataIn.readInt();
|
|
|
|
//dataIn.readUTF();
|
|
|
|
dataIn.skip(8);
|
|
|
|
dataIn.readDouble();
|
|
|
|
|
|
|
|
dataIn.close();
|
|
|
|
}
|
|
|
|
long time2 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
for (int i = 0; i < 100000; i++) {
|
|
|
|
unscramble = new XORUnscrambleStream(new ByteArrayInputStream(byteStream.toByteArray()), master);
|
|
|
|
dataIn = new DataInputStream(unscramble);
|
|
|
|
unscramble.start();
|
|
|
|
dataIn.skip(2);
|
|
|
|
dataIn.readLong();
|
|
|
|
unscramble.stop();
|
|
|
|
dataIn.readInt();
|
|
|
|
dataIn.readInt();
|
|
|
|
unscramble.start();
|
|
|
|
dataIn.readDouble();
|
|
|
|
dataIn.mark(1000);
|
|
|
|
dataIn.readInt();
|
|
|
|
//dataIn.readUTF();
|
|
|
|
dataIn.skip(8);
|
|
|
|
dataIn.readDouble();
|
|
|
|
dataIn.reset();
|
|
|
|
dataIn.readInt();
|
|
|
|
//dataIn.readUTF();
|
|
|
|
dataIn.skip(8);
|
|
|
|
dataIn.readDouble();
|
|
|
|
|
|
|
|
dataIn.close();
|
|
|
|
}
|
|
|
|
long time3 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
P.p.log("Time with base91: " + (time2 - time));
|
|
|
|
P.p.log("Time without base91: " + (time3 - time2));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2016-06-29 23:24:39 +02:00
|
|
|
} catch (InvalidKeyException e) {
|
|
|
|
e.printStackTrace();
|
2016-06-29 22:44:19 +02:00
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
data.close();
|
|
|
|
if (dataIn != null) {
|
|
|
|
dataIn.close();
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}*/
|
2016-05-28 14:08:33 +02:00
|
|
|
|
2016-06-16 22:13:21 +02:00
|
|
|
/*try {
|
2016-05-28 14:08:33 +02:00
|
|
|
ItemMeta meta = new ItemStack(Material.POTION).getItemMeta();
|
2016-06-13 23:26:10 +02:00
|
|
|
DataOutputStream data = new DataOutputStream(new Base91EncoderStream(new LoreSaveStream(meta, 3)));
|
2016-05-28 14:08:33 +02:00
|
|
|
|
|
|
|
data.writeInt(2);
|
|
|
|
data.writeLong(5);
|
|
|
|
|
|
|
|
byte[] test = new byte[128];
|
|
|
|
test[1] = 6;
|
|
|
|
test[2] = 12;
|
|
|
|
test[3] = 21;
|
2016-05-28 18:47:51 +02:00
|
|
|
test[127] = 99;
|
2016-05-28 14:08:33 +02:00
|
|
|
data.write(test);
|
|
|
|
|
|
|
|
data.writeInt(123324);
|
|
|
|
data.writeLong(12343843);
|
|
|
|
|
|
|
|
data.close();
|
|
|
|
meta.getLore();
|
|
|
|
|
2016-06-13 23:26:10 +02:00
|
|
|
DataInputStream dataIn = new DataInputStream(new Base91DecoderStream(new LoreLoadStream(meta)));
|
2016-05-28 18:47:51 +02:00
|
|
|
|
|
|
|
P.p.log(dataIn.readInt() + ", " + dataIn.readLong() + ", ");
|
2016-05-28 22:18:03 +02:00
|
|
|
|
2016-05-28 18:47:51 +02:00
|
|
|
byte[] testIn = new byte[128];
|
|
|
|
dataIn.read(testIn);
|
|
|
|
P.p.log(testIn[1] + ", " + testIn[2] + ", " + testIn[3] + ", " + testIn[127]);
|
|
|
|
|
|
|
|
P.p.log(dataIn.readInt() + ", " + dataIn.readLong() + ", ");
|
|
|
|
|
|
|
|
dataIn.close();
|
|
|
|
|
2016-05-28 14:08:33 +02:00
|
|
|
|
|
|
|
|
2016-06-16 22:13:21 +02:00
|
|
|
basE91 basE91 = new basE91();
|
2016-05-28 14:08:33 +02:00
|
|
|
int[] input = new int[] {12, 65, 324, 5, 12, 129459, 1234567, Integer.MIN_VALUE, Integer.MAX_VALUE};
|
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(stream);
|
|
|
|
for (int i = 0; i < input.length; i++) {
|
|
|
|
data.writeInt(input[i]);
|
|
|
|
}
|
|
|
|
data.flush();
|
|
|
|
data.close();
|
|
|
|
byte[] in = stream.toByteArray();
|
|
|
|
byte[] out = new byte[4096];
|
|
|
|
int lenght = basE91.encode(in, in.length, out);
|
|
|
|
basE91.encEnd(out);
|
|
|
|
String done = new String(out, 0, lenght);
|
|
|
|
|
|
|
|
byte[] tin = done.getBytes();
|
|
|
|
|
|
|
|
byte[] tout = new byte[4096];
|
|
|
|
lenght = basE91.decode(tin, tin.length, tout);
|
|
|
|
basE91.decEnd(tout);
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream tstream = new ByteArrayInputStream(tout, 0, lenght);
|
|
|
|
DataInputStream tdata = new DataInputStream(tstream);
|
|
|
|
int[] test = new int[4096];
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
if (tstream.available() <= 0) break;
|
|
|
|
test[j] = tdata.readInt();
|
|
|
|
|
|
|
|
}
|
|
|
|
tdata.close();
|
|
|
|
test = test;*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*basE91 basE91 = new basE91();
|
|
|
|
int[] input = new int[] {12, 65, 324, 5, 12, 129459, 1234567, Integer.MIN_VALUE, Integer.MAX_VALUE};
|
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(stream);
|
|
|
|
for (int i = 0; i < input.length; i++) {
|
|
|
|
data.writeInt(input[i]);
|
|
|
|
}
|
|
|
|
data.flush();
|
|
|
|
data.close();
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
ByteArrayInputStream in = new ByteArrayInputStream(stream.toByteArray());
|
|
|
|
|
|
|
|
encode(in, out, in.available());
|
|
|
|
|
|
|
|
in.close();
|
|
|
|
out.flush();
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
String done = new String(out.toByteArray());
|
|
|
|
|
|
|
|
ByteArrayInputStream tin = new ByteArrayInputStream(done.getBytes());
|
|
|
|
ByteArrayOutputStream tout = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
decode(tin, tout, tin.available());
|
|
|
|
|
|
|
|
tin.close();
|
|
|
|
tout.flush();
|
|
|
|
tout.close();
|
|
|
|
|
|
|
|
ByteArrayInputStream tstream = new ByteArrayInputStream(tout.toByteArray());
|
|
|
|
DataInputStream tdata = new DataInputStream(tstream);
|
|
|
|
int[] test = new int[4096];
|
|
|
|
for (int j = 0; j < 9; j++) {
|
|
|
|
if (tstream.available() <= 0) break;
|
|
|
|
test[j] = tdata.readInt();
|
|
|
|
|
|
|
|
}
|
|
|
|
tdata.close();
|
2016-06-16 22:13:21 +02:00
|
|
|
test = test;
|
2016-05-28 14:08:33 +02:00
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2016-06-16 22:13:21 +02:00
|
|
|
}*/
|
2016-05-28 14:08:33 +02:00
|
|
|
|
|
|
|
|
2016-04-23 17:45:01 +02:00
|
|
|
// load the Config
|
|
|
|
try {
|
2019-11-14 16:16:12 +01:00
|
|
|
FileConfiguration cfg = BConfig.loadConfigFile();
|
|
|
|
if (cfg == null || !BConfig.readConfig(cfg)) {
|
2016-04-23 17:45:01 +02:00
|
|
|
p = null;
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
p = null;
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-16 17:21:04 +02:00
|
|
|
BData.readData();
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
// Setup Metrics
|
2019-10-12 13:52:55 +02:00
|
|
|
/*try {
|
2019-01-17 16:37:55 +01:00
|
|
|
Metrics metrics = new Metrics(this);
|
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
|
2019-11-23 19:59:53 +01:00
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> brewsCreated));
|
2019-01-17 16:37:55 +01:00
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("barrels_built", () -> Barrel.barrels.size()));
|
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("cauldrons_boiling", () -> BCauldron.bcauldrons.size()));
|
|
|
|
metrics.addCustomChart(new Metrics.AdvancedPie("brew_quality", () -> {
|
2019-01-17 17:28:58 +01:00
|
|
|
Map<String, Integer> map = new HashMap<>(5);
|
2019-01-17 16:37:55 +01:00
|
|
|
map.put("excellent", exc);
|
|
|
|
map.put("good", good);
|
|
|
|
map.put("normal", norm);
|
|
|
|
map.put("bad", bad);
|
|
|
|
map.put("terrible", terr);
|
|
|
|
return map;
|
|
|
|
}));
|
2019-01-17 17:28:58 +01:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("number_of_recipes", () -> {
|
2019-11-23 19:59:53 +01:00
|
|
|
int recipes = BRecipe.getAllRecipes().size();
|
2019-01-17 17:28:58 +01:00
|
|
|
if (recipes < 7) {
|
|
|
|
return "Less than 7";
|
|
|
|
} else if (recipes < 11) {
|
|
|
|
return "7-10";
|
|
|
|
} else if (recipes == 11) {
|
|
|
|
// There are 11 default recipes, so show this as its own slice
|
|
|
|
return "11";
|
|
|
|
} else if (recipes <= 31) {
|
|
|
|
if (recipes % 2 == 0) {
|
|
|
|
return recipes + "-" + (recipes + 1);
|
|
|
|
} else {
|
|
|
|
return (recipes - 1) + "-" + recipes;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "More than 31";
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
2019-01-17 16:37:55 +01:00
|
|
|
} catch (Throwable e) {
|
2018-10-27 12:09:53 +02:00
|
|
|
e.printStackTrace();
|
2019-10-12 13:52:55 +02:00
|
|
|
}*/
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
// Listeners
|
|
|
|
blockListener = new BlockListener();
|
|
|
|
playerListener = new PlayerListener();
|
|
|
|
entityListener = new EntityListener();
|
|
|
|
inventoryListener = new InventoryListener();
|
|
|
|
worldListener = new WorldListener();
|
2016-07-09 00:01:31 +02:00
|
|
|
integrationListener = new IntegrationListener();
|
2016-04-23 17:45:01 +02:00
|
|
|
getCommand("Brewery").setExecutor(new CommandListener());
|
2018-10-30 18:22:04 +01:00
|
|
|
getCommand("Brewery").setTabCompleter(new TabListener());
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
|
|
|
p.getServer().getPluginManager().registerEvents(playerListener, p);
|
|
|
|
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
|
|
|
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
|
|
|
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
2016-07-09 00:01:31 +02:00
|
|
|
p.getServer().getPluginManager().registerEvents(integrationListener, p);
|
2016-06-28 21:35:37 +02:00
|
|
|
if (use1_9) {
|
|
|
|
p.getServer().getPluginManager().registerEvents(new CauldronListener(), p);
|
|
|
|
}
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
// Heartbeat
|
|
|
|
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
|
|
|
|
p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120);
|
|
|
|
|
2019-10-16 17:21:04 +02:00
|
|
|
if (BConfig.updateCheck) {
|
2019-06-28 16:12:52 +02:00
|
|
|
try {
|
|
|
|
p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-04-23 17:45:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.log(this.getDescription().getName() + " enabled!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
|
|
|
|
// Disable listeners
|
|
|
|
HandlerList.unregisterAll(this);
|
|
|
|
|
|
|
|
// Stop shedulers
|
|
|
|
getServer().getScheduler().cancelTasks(this);
|
|
|
|
|
|
|
|
if (p == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// save Data to Disk
|
|
|
|
DataSave.save(true);
|
|
|
|
|
|
|
|
// delete Data from Ram
|
|
|
|
Barrel.barrels.clear();
|
|
|
|
BCauldron.bcauldrons.clear();
|
2019-11-09 17:02:48 +01:00
|
|
|
BRecipe.getConfigRecipes().clear();
|
|
|
|
BRecipe.numConfigRecipes = 0;
|
2019-10-29 16:20:32 +01:00
|
|
|
BCauldronRecipe.acceptedMaterials.clear();
|
2019-11-06 19:44:52 +01:00
|
|
|
BCauldronRecipe.acceptedCustom.clear();
|
|
|
|
BCauldronRecipe.acceptedSimple.clear();
|
2019-11-09 17:02:48 +01:00
|
|
|
BCauldronRecipe.getConfigRecipes().clear();
|
|
|
|
BCauldronRecipe.numConfigRecipes = 0;
|
2019-10-29 16:20:32 +01:00
|
|
|
BConfig.customItems.clear();
|
2019-11-06 19:44:52 +01:00
|
|
|
BConfig.hasSlimefun = null;
|
|
|
|
BConfig.hasMMOItems = null;
|
2016-04-23 17:45:01 +02:00
|
|
|
BPlayer.clear();
|
2016-06-16 22:13:21 +02:00
|
|
|
Brew.legacyPotions.clear();
|
2016-04-23 17:45:01 +02:00
|
|
|
Wakeup.wakeups.clear();
|
2019-10-16 17:21:04 +02:00
|
|
|
DistortChat.words.clear();
|
|
|
|
DistortChat.ignoreText.clear();
|
|
|
|
DistortChat.commands = null;
|
2016-04-23 17:45:01 +02:00
|
|
|
|
|
|
|
this.log(this.getDescription().getName() + " disabled!");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload(CommandSender sender) {
|
2016-05-25 19:22:29 +02:00
|
|
|
if (sender != null && !sender.equals(getServer().getConsoleSender())) {
|
2019-10-16 17:21:04 +02:00
|
|
|
BConfig.reloader = sender;
|
2016-05-25 19:22:29 +02:00
|
|
|
}
|
2019-11-14 16:16:12 +01:00
|
|
|
FileConfiguration cfg = BConfig.loadConfigFile();
|
|
|
|
if (cfg == null) {
|
|
|
|
// Could not read yml file, do not proceed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-23 17:45:01 +02:00
|
|
|
// clear all existent config Data
|
2019-11-09 17:02:48 +01:00
|
|
|
BRecipe.getConfigRecipes().clear();
|
|
|
|
BRecipe.numConfigRecipes = 0;
|
2019-10-29 16:20:32 +01:00
|
|
|
BCauldronRecipe.acceptedMaterials.clear();
|
2019-11-06 19:44:52 +01:00
|
|
|
BCauldronRecipe.acceptedCustom.clear();
|
|
|
|
BCauldronRecipe.acceptedSimple.clear();
|
2019-11-09 17:02:48 +01:00
|
|
|
BCauldronRecipe.getConfigRecipes().clear();
|
|
|
|
BCauldronRecipe.numConfigRecipes = 0;
|
2019-10-29 16:20:32 +01:00
|
|
|
BConfig.customItems.clear();
|
2019-11-06 19:44:52 +01:00
|
|
|
BConfig.hasSlimefun = null;
|
|
|
|
BConfig.hasMMOItems = null;
|
2019-10-16 17:21:04 +02:00
|
|
|
DistortChat.commands = null;
|
|
|
|
BConfig.drainItems.clear();
|
|
|
|
if (BConfig.useLB) {
|
2016-04-23 17:45:01 +02:00
|
|
|
try {
|
|
|
|
LogBlockBarrel.clear();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the Config
|
|
|
|
try {
|
2019-11-14 16:16:12 +01:00
|
|
|
if (!BConfig.readConfig(cfg)) {
|
2016-04-23 17:45:01 +02:00
|
|
|
p = null;
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
p = null;
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-08 16:22:58 +01:00
|
|
|
// load LanguageReader
|
2016-04-23 17:45:01 +02:00
|
|
|
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
|
|
|
|
|
|
|
|
// Reload Recipes
|
2018-10-27 12:41:27 +02:00
|
|
|
boolean successful = true;
|
2016-06-16 22:13:21 +02:00
|
|
|
for (Brew brew : Brew.legacyPotions.values()) {
|
2016-04-23 17:45:01 +02:00
|
|
|
if (!brew.reloadRecipe()) {
|
|
|
|
successful = false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-17 18:53:06 +02:00
|
|
|
if (!successful && sender != null) {
|
2016-04-23 17:45:01 +02:00
|
|
|
msg(sender, p.languageReader.get("Error_Recipeload"));
|
2019-11-14 16:16:12 +01:00
|
|
|
} else {
|
|
|
|
p.msg(sender, p.languageReader.get("CMD_Reload"));
|
2016-04-23 17:45:01 +02:00
|
|
|
}
|
2019-10-16 17:21:04 +02:00
|
|
|
BConfig.reloader = null;
|
2016-04-23 17:45:01 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 20:00:05 +01:00
|
|
|
public static P getInstance() {
|
2019-11-13 22:07:22 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2019-11-23 19:59:53 +01:00
|
|
|
public void metricsForCreate(Brew brew) {
|
|
|
|
if (brewsCreated == Integer.MAX_VALUE) return;
|
|
|
|
brewsCreated++;
|
|
|
|
if (brew.getQuality() >= 9) {
|
|
|
|
exc++;
|
|
|
|
} else if (brew.getQuality() >= 7) {
|
|
|
|
good++;
|
|
|
|
} else if (brew.getQuality() >= 5) {
|
|
|
|
norm++;
|
|
|
|
} else if (brew.getQuality() >= 3) {
|
|
|
|
bad++;
|
|
|
|
} else {
|
|
|
|
terr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 17:21:04 +02:00
|
|
|
// Utility
|
|
|
|
|
2016-04-23 17:45:01 +02:00
|
|
|
public void msg(CommandSender sender, String msg) {
|
|
|
|
sender.sendMessage(color("&2[Brewery] &f" + msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void log(String msg) {
|
|
|
|
this.msg(Bukkit.getConsoleSender(), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void debugLog(String msg) {
|
|
|
|
if (debug) {
|
|
|
|
this.msg(Bukkit.getConsoleSender(), "&2[Debug] &f" + msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void errorLog(String msg) {
|
|
|
|
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
2019-10-16 17:21:04 +02:00
|
|
|
if (BConfig.reloader != null) {
|
|
|
|
BConfig.reloader.sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
2016-04-23 17:45:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int parseInt(String string) {
|
|
|
|
return NumberUtils.toInt(string, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String color(String msg) {
|
2019-10-12 13:52:55 +02:00
|
|
|
return BUtil.color(msg);
|
2016-04-23 17:45:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Runnables
|
|
|
|
|
2019-10-16 17:21:04 +02:00
|
|
|
public static class DrunkRunnable implements Runnable {
|
2016-04-23 17:45:01 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (!BPlayer.isEmpty()) {
|
|
|
|
BPlayer.drunkeness();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BreweryRunnable implements Runnable {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-10-16 17:21:04 +02:00
|
|
|
BConfig.reloader = null;
|
2019-11-08 16:22:58 +01:00
|
|
|
for (BCauldron cauldron : BCauldron.bcauldrons.values()) {
|
2016-04-23 17:45:01 +02:00
|
|
|
cauldron.onUpdate();// runs every min to update cooking time
|
|
|
|
}
|
|
|
|
Barrel.onUpdate();// runs every min to check and update ageing time
|
2019-08-17 18:53:06 +02:00
|
|
|
if (use1_14) MCBarrel.onUpdate();
|
2016-04-23 17:45:01 +02:00
|
|
|
BPlayer.onUpdate();// updates players drunkeness
|
|
|
|
|
|
|
|
debugLog("Update");
|
|
|
|
|
|
|
|
DataSave.autoSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|