1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #25 from John000708/master

Added Advanced Farmer Android
This commit is contained in:
TheBusyBiscuit 2016-11-20 00:59:03 +01:00 committed by GitHub
commit eb52630355
6 changed files with 391 additions and 346 deletions

View File

@ -5,6 +5,7 @@ public enum AndroidType {
NONE, NONE,
MINER, MINER,
FARMER, FARMER,
ADVANCED_FARMER,
WOODCUTTER, WOODCUTTER,
FIGHTER, FIGHTER,
FISHERMAN, FISHERMAN,

View File

@ -45,7 +45,11 @@ public enum ScriptPart {
// Action - Hoe // Action - Hoe
FARM_FORWARD(AndroidType.FARMER, "§bHarvest and Replant", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGRlOWE1MjJjM2Q5ZTdkODVmM2Q4MmMzNzVkYzM3ZmVjYzg1NmRiZDgwMWViM2JjZWRjMTE2NTE5OGJmIn19fQ=="), FARM_FORWARD(AndroidType.FARMER, "§bHarvest and Replant", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGRlOWE1MjJjM2Q5ZTdkODVmM2Q4MmMzNzVkYzM3ZmVjYzg1NmRiZDgwMWViM2JjZWRjMTE2NTE5OGJmIn19fQ=="),
FARM_DOWN(AndroidType.FARMER, "§bHarvest and Replant §7(Block underneath)", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmQ0Mjk2YjMzM2QyNTMxOWFmM2YzMzA1MTc5N2Y5ZTZkODIxY2QxOWEwMTRmYjcxMzdiZWI4NmE0ZTllOTYifX19"), FARM_DOWN(AndroidType.FARMER, "§bHarvest and Replant §7(Block underneath)", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmQ0Mjk2YjMzM2QyNTMxOWFmM2YzMzA1MTc5N2Y5ZTZkODIxY2QxOWEwMTRmYjcxMzdiZWI4NmE0ZTllOTYifX19"),
// Action - ExoticGarden
FARM_EXOTIC_FORWARD(AndroidType.ADVANCED_FARMER, "§bAdvanced Harvest and Replant", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGRlOWE1MjJjM2Q5ZTdkODVmM2Q4MmMzNzVkYzM3ZmVjYzg1NmRiZDgwMWViM2JjZWRjMTE2NTE5OGJmIn19fQ=="),
FARM_EXOTIC_DOWN(AndroidType.ADVANCED_FARMER, "§bAdvanced Harvest and Replant §7(Block underneath)", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmQ0Mjk2YjMzM2QyNTMxOWFmM2YzMzA1MTc5N2Y5ZTZkODIxY2QxOWEwMTRmYjcxMzdiZWI4NmE0ZTllOTYifX19"),
// Action - Interface // Action - Interface
INTERFACE_ITEMS(AndroidType.NONE, "§9Push Inventory Contents to the faced Interface", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTBhNGRiZjY2MjVjNDJiZTU3YThiYTJjMzMwOTU0YTc2YmRmMjI3ODU1NDBlODdhNWM5NjcyNjg1MjM4ZWMifX19"), INTERFACE_ITEMS(AndroidType.NONE, "§9Push Inventory Contents to the faced Interface", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTBhNGRiZjY2MjVjNDJiZTU3YThiYTJjMzMwOTU0YTc2YmRmMjI3ODU1NDBlODdhNWM5NjcyNjg1MjM4ZWMifX19"),
INTERFACE_FUEL(AndroidType.NONE, "§cPull Fuel from the faced Interface", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjQzMmY1MjgyYTUwNzQ1YjkxMmJlMTRkZWRhNTgxYmQ0YTA5Yjk3N2EzYzMyZDdlOTU3ODQ5MWZlZThmYTcifX19"); INTERFACE_FUEL(AndroidType.NONE, "§cPull Fuel from the faced Interface", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjQzMmY1MjgyYTUwNzQ1YjkxMmJlMTRkZWRhNTgxYmQ0YTA5Yjk3N2EzYzMyZDdlOTU3ODQ5MWZlZThmYTcifX19");

View File

@ -512,6 +512,7 @@ public class SlimefunItems {
public static ItemStack PROGRAMMABLE_ANDROID_2 = null; public static ItemStack PROGRAMMABLE_ANDROID_2 = null;
public static ItemStack PROGRAMMABLE_ANDROID_2_FISHERMAN = null; public static ItemStack PROGRAMMABLE_ANDROID_2_FISHERMAN = null;
public static ItemStack PROGRAMMABLE_ANDROID_2_FARMER = null;
public static ItemStack PROGRAMMABLE_ANDROID_2_BUTCHER = null; public static ItemStack PROGRAMMABLE_ANDROID_2_BUTCHER = null;
public static ItemStack PROGRAMMABLE_ANDROID_3 = null; public static ItemStack PROGRAMMABLE_ANDROID_3 = null;
@ -703,6 +704,7 @@ public class SlimefunItems {
PROGRAMMABLE_ANDROID_2 = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzUwM2NiN2VkODQ1ZTdhNTA3ZjU2OWFmYzY0N2M0N2FjNDgzNzcxNDY1YzlhNjc5YTU0NTk0Yzc2YWZiYSJ9fX0="), "§cAdvanced Programmable Android &7(Normal)", "", "§8\u21E8 §7Function: None", "§8\u21E8 §7Fuel Efficiency: 1.5x"); PROGRAMMABLE_ANDROID_2 = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzUwM2NiN2VkODQ1ZTdhNTA3ZjU2OWFmYzY0N2M0N2FjNDgzNzcxNDY1YzlhNjc5YTU0NTk0Yzc2YWZiYSJ9fX0="), "§cAdvanced Programmable Android &7(Normal)", "", "§8\u21E8 §7Function: None", "§8\u21E8 §7Fuel Efficiency: 1.5x");
PROGRAMMABLE_ANDROID_2_FISHERMAN = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzQ1ZTg3MzNhNzMxMTQzMzNiOThiMzYwMTc1MTI0MTcyMmY0NzEzZTFhMWE1ZDM2ZmJiMTMyNDkzZjFjNyJ9fX0="), "§cAdvanced Programmable Android &7(Fisherman)", "", "§8\u21E8 §7Function: Fishing", "§8\u21E8 §7Success Rate: 20%", "§8\u21E8 §7Fuel Efficiency: 1.5x"); PROGRAMMABLE_ANDROID_2_FISHERMAN = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzQ1ZTg3MzNhNzMxMTQzMzNiOThiMzYwMTc1MTI0MTcyMmY0NzEzZTFhMWE1ZDM2ZmJiMTMyNDkzZjFjNyJ9fX0="), "§cAdvanced Programmable Android &7(Fisherman)", "", "§8\u21E8 §7Function: Fishing", "§8\u21E8 §7Success Rate: 20%", "§8\u21E8 §7Fuel Efficiency: 1.5x");
PROGRAMMABLE_ANDROID_2_FARMER = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjlkMzMzNTdlODQxODgyM2JmNzgzZGU5MmRlODAyOTFiNGViZDM5MmFlYzg3MDY2OThlMDY4OTZkNDk4ZjYifX19"), "§cAdvanced Programmable Android &7(Farmer)", "", "§8\u21E8 §7Function: Farming", "§8\u21E8 §7Fuel Efficiency: 1.5x", "§8\u21E8 §7Can harvest Exotic Garden plants");
PROGRAMMABLE_ANDROID_2_BUTCHER = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2I0NzJkZjBhZDlhM2JlODhmMmU1ZDVkNDIyZDAyYjExNmQ2NGQ4ZGYxNDc1ZWQzMmU1NDZhZmM4NGIzMSJ9fX0="), "§cAdvanced Programmable Android &7(Butcher)", "", "§8\u21E8 §7Function: Slaughtering", "§8\u21E8 §7Damage: 8", "§8\u21E8 §7Fuel Efficiency: 1.5x"); PROGRAMMABLE_ANDROID_2_BUTCHER = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2I0NzJkZjBhZDlhM2JlODhmMmU1ZDVkNDIyZDAyYjExNmQ2NGQ4ZGYxNDc1ZWQzMmU1NDZhZmM4NGIzMSJ9fX0="), "§cAdvanced Programmable Android &7(Butcher)", "", "§8\u21E8 §7Function: Slaughtering", "§8\u21E8 §7Damage: 8", "§8\u21E8 §7Fuel Efficiency: 1.5x");
PROGRAMMABLE_ANDROID_3 = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzUwM2NiN2VkODQ1ZTdhNTA3ZjU2OWFmYzY0N2M0N2FjNDgzNzcxNDY1YzlhNjc5YTU0NTk0Yzc2YWZiYSJ9fX0="), "§eEmpowered Programmable Android &7(Normal)", "", "§8\u21E8 §7Function: None", "§8\u21E8 §7Fuel Efficiency: 3.0x"); PROGRAMMABLE_ANDROID_3 = new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzUwM2NiN2VkODQ1ZTdhNTA3ZjU2OWFmYzY0N2M0N2FjNDgzNzcxNDY1YzlhNjc5YTU0NTk0Yzc2YWZiYSJ9fX0="), "§eEmpowered Programmable Android &7(Normal)", "", "§8\u21E8 §7Function: None", "§8\u21E8 §7Fuel Efficiency: 3.0x");

View File

@ -4081,6 +4081,27 @@ public class SlimefunSetup {
} }
.register(true); .register(true);
new ProgrammableAndroid(Categories.ELECTRICITY, SlimefunItems.PROGRAMMABLE_ANDROID_2_FARMER, "PROGRAMMABLE_ANDROID_2_FARMER", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, SlimefunItems.GPS_TRANSMITTER, null, new ItemStack(Material.DIAMOND_HOE), SlimefunItems.PROGRAMMABLE_ANDROID_2, new ItemStack(Material.DIAMOND_HOE), null, SlimefunItems.ELECTRIC_MOTOR, null}) {
@Override
public AndroidType getAndroidType() {
return AndroidType.ADVANCED_FARMER;
}
@Override
public float getFuelEfficiency() {
return 1.5F;
}
@Override
public int getTier() {
return 2;
}
}
.register(true);
new ProgrammableAndroid(Categories.ELECTRICITY, SlimefunItems.PROGRAMMABLE_ANDROID_3, "PROGRAMMABLE_ANDROID_3", RecipeType.ENHANCED_CRAFTING_TABLE, new ProgrammableAndroid(Categories.ELECTRICITY, SlimefunItems.PROGRAMMABLE_ANDROID_3, "PROGRAMMABLE_ANDROID_3", RecipeType.ENHANCED_CRAFTING_TABLE,

View File

@ -82,39 +82,42 @@ import me.mrCookieSlime.Slimefun.listeners.ItemListener;
import me.mrCookieSlime.Slimefun.listeners.TalismanListener; import me.mrCookieSlime.Slimefun.listeners.TalismanListener;
import me.mrCookieSlime.Slimefun.listeners.TeleporterListener; import me.mrCookieSlime.Slimefun.listeners.TeleporterListener;
import me.mrCookieSlime.Slimefun.listeners.ToolListener; import me.mrCookieSlime.Slimefun.listeners.ToolListener;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class SlimefunStartup extends JavaPlugin { public class SlimefunStartup extends JavaPlugin {
public static SlimefunStartup instance; public static SlimefunStartup instance;
static PluginUtils utils; static PluginUtils utils;
static Config researches; static Config researches;
static Config items; static Config items;
static Config whitelist; static Config whitelist;
static Config config; static Config config;
public static TickerTask ticker; public static TickerTask ticker;
private boolean clearlag = false; private boolean clearlag = false;
private boolean exoticGarden = false;
// Supported Versions of Minecraft // Supported Versions of Minecraft
final String[] supported = {"v1_9_", "v1_10_", "PluginBukkitBridge"}; final String[] supported = {"v1_9_", "v1_10_", "PluginBukkitBridge"};
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onEnable() { public void onEnable() {
CSCoreLibLoader loader = new CSCoreLibLoader(this); CSCoreLibLoader loader = new CSCoreLibLoader(this);
if (loader.load()) { if (loader.load()) {
boolean compatibleVersion = false; boolean compatibleVersion = false;
for (String version: supported) { for (String version: supported) {
if (ReflectionUtils.getVersion().startsWith(version)) { if (ReflectionUtils.getVersion().startsWith(version)) {
compatibleVersion = true; compatibleVersion = true;
break; break;
} }
} }
// Looks like you are using an unsupported Minecraft Version // Looks like you are using an unsupported Minecraft Version
if (!compatibleVersion) { if (!compatibleVersion) {
System.err.println("### Slimefun failed to load!"); System.err.println("### Slimefun failed to load!");
@ -130,21 +133,21 @@ public class SlimefunStartup extends JavaPlugin {
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
instance = this; instance = this;
System.out.println("[Slimefun] Loading Files..."); System.out.println("[Slimefun] Loading Files...");
Files.cleanup(); Files.cleanup();
System.out.println("[Slimefun] Loading Config..."); System.out.println("[Slimefun] Loading Config...");
utils = new PluginUtils(this); utils = new PluginUtils(this);
utils.setupConfig(); utils.setupConfig();
// Loading all extra configs // Loading all extra configs
researches = new Config(Files.RESEARCHES); researches = new Config(Files.RESEARCHES);
items = new Config(Files.ITEMS); items = new Config(Files.ITEMS);
whitelist = new Config(Files.WHITELIST); whitelist = new Config(Files.WHITELIST);
// Init Config, Updater, Metrics and messages.yml // Init Config, Updater, Metrics and messages.yml
utils.setupUpdater(53485, getFile()); utils.setupUpdater(53485, getFile());
utils.setupMetrics(); utils.setupMetrics();
@ -164,9 +167,9 @@ public class SlimefunStartup extends JavaPlugin {
if (!new File("plugins/Slimefun/scripts").exists()) new File("plugins/Slimefun/scripts").mkdirs(); if (!new File("plugins/Slimefun/scripts").exists()) new File("plugins/Slimefun/scripts").mkdirs();
if (!new File("plugins/Slimefun/generators").exists()) new File("plugins/Slimefun/generators").mkdirs(); if (!new File("plugins/Slimefun/generators").exists()) new File("plugins/Slimefun/generators").mkdirs();
if (!new File("plugins/Slimefun/error-reports").exists()) new File("plugins/Slimefun/error-reports").mkdirs(); if (!new File("plugins/Slimefun/error-reports").exists()) new File("plugins/Slimefun/error-reports").mkdirs();
SlimefunManager.plugin = this; SlimefunManager.plugin = this;
System.out.println("[Slimefun] Loading Items..."); System.out.println("[Slimefun] Loading Items...");
MiscSetup.setupItemSettings(); MiscSetup.setupItemSettings();
try { try {
@ -175,17 +178,17 @@ public class SlimefunStartup extends JavaPlugin {
e1.printStackTrace(); e1.printStackTrace();
} }
MiscSetup.loadDescriptions(); MiscSetup.loadDescriptions();
System.out.println("[Slimefun] Loading Researches..."); System.out.println("[Slimefun] Loading Researches...");
Research.enabled = getResearchCfg().getBoolean("enable-researching"); Research.enabled = getResearchCfg().getBoolean("enable-researching");
ResearchSetup.setupResearches(); ResearchSetup.setupResearches();
MiscSetup.setupMisc(); MiscSetup.setupMisc();
BlockStorage.info_delay = config.getInt("URID.info-delay"); BlockStorage.info_delay = config.getInt("URID.info-delay");
System.out.println("[Slimefun] Loading World Generators..."); System.out.println("[Slimefun] Loading World Generators...");
// Generating Oil as an OreGenResource (its a cool API) // Generating Oil as an OreGenResource (its a cool API)
OreGenSystem.registerResource(new OreGenResource() { OreGenSystem.registerResource(new OreGenResource() {
@ -197,20 +200,20 @@ public class SlimefunStartup extends JavaPlugin {
case BEACHES: { case BEACHES: {
return CSCoreLib.randomizer().nextInt(6) + 2; return CSCoreLib.randomizer().nextInt(6) + 2;
} }
case DESERT: case DESERT:
case DESERT_HILLS: case DESERT_HILLS:
case MUTATED_DESERT: { case MUTATED_DESERT: {
return CSCoreLib.randomizer().nextInt(40) + 19; return CSCoreLib.randomizer().nextInt(40) + 19;
} }
case EXTREME_HILLS: case EXTREME_HILLS:
case MUTATED_EXTREME_HILLS: case MUTATED_EXTREME_HILLS:
case SMALLER_EXTREME_HILLS: case SMALLER_EXTREME_HILLS:
case RIVER: { case RIVER: {
return CSCoreLib.randomizer().nextInt(14) + 13; return CSCoreLib.randomizer().nextInt(14) + 13;
} }
case ICE_MOUNTAINS: case ICE_MOUNTAINS:
case ICE_FLATS: case ICE_FLATS:
case MUTATED_ICE_FLATS: case MUTATED_ICE_FLATS:
@ -218,13 +221,13 @@ public class SlimefunStartup extends JavaPlugin {
case FROZEN_RIVER: { case FROZEN_RIVER: {
return CSCoreLib.randomizer().nextInt(11) + 3; return CSCoreLib.randomizer().nextInt(11) + 3;
} }
case SKY: case SKY:
case HELL: { case HELL: {
return 0; return 0;
} }
case MESA: case MESA:
case MESA_CLEAR_ROCK: case MESA_CLEAR_ROCK:
case MESA_ROCK: case MESA_ROCK:
@ -240,12 +243,12 @@ public class SlimefunStartup extends JavaPlugin {
case OCEAN: { case OCEAN: {
return CSCoreLib.randomizer().nextInt(62) + 24; return CSCoreLib.randomizer().nextInt(62) + 24;
} }
case SWAMPLAND: case SWAMPLAND:
case MUTATED_SWAMPLAND: { case MUTATED_SWAMPLAND: {
return CSCoreLib.randomizer().nextInt(20) + 4; return CSCoreLib.randomizer().nextInt(20) + 4;
} }
default: { default: {
return CSCoreLib.randomizer().nextInt(10) + 6; return CSCoreLib.randomizer().nextInt(10) + 6;
} }
@ -267,7 +270,7 @@ public class SlimefunStartup extends JavaPlugin {
return "Buckets"; return "Buckets";
} }
}); });
// All Slimefun Listeners // All Slimefun Listeners
new ArmorListener(this); new ArmorListener(this);
new ItemListener(this); new ItemListener(this);
@ -280,7 +283,7 @@ public class SlimefunStartup extends JavaPlugin {
new FurnaceListener(this); new FurnaceListener(this);
new TeleporterListener(this); new TeleporterListener(this);
new AndroidKillingListener(this); new AndroidKillingListener(this);
// Toggleable Listeners for performance // Toggleable Listeners for performance
if (config.getBoolean("items.talismans")) new TalismanListener(this); if (config.getBoolean("items.talismans")) new TalismanListener(this);
if (config.getBoolean("items.backpacks")) new BackpackListener(this); if (config.getBoolean("items.backpacks")) new BackpackListener(this);
@ -290,7 +293,7 @@ public class SlimefunStartup extends JavaPlugin {
// TODO: Move it to its own class, was too lazy // TODO: Move it to its own class, was too lazy
if (config.getBoolean("options.give-guide-on-first-join")) { if (config.getBoolean("options.give-guide-on-first-join")) {
getServer().getPluginManager().registerEvents(new Listener() { getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
if (!e.getPlayer().hasPlayedBefore()) { if (!e.getPlayer().hasPlayedBefore()) {
@ -300,43 +303,43 @@ public class SlimefunStartup extends JavaPlugin {
p.getInventory().addItem(SlimefunGuide.getItem(config.getBoolean("guide.default-view-book"))); p.getInventory().addItem(SlimefunGuide.getItem(config.getBoolean("guide.default-view-book")));
} }
} }
}, this); }, this);
} }
// Load/Unload Worlds in Slimefun // Load/Unload Worlds in Slimefun
// TODO: Move it to its own class, was too lazy // TODO: Move it to its own class, was too lazy
getServer().getPluginManager().registerEvents(new Listener() { getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler @EventHandler
public void onWorldLoad(WorldLoadEvent e) { public void onWorldLoad(WorldLoadEvent e) {
BlockStorage.getForcedStorage(e.getWorld()); BlockStorage.getForcedStorage(e.getWorld());
SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled", true); SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled", true);
SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE", true); SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE", true);
SlimefunStartup.getWhitelist().save(); SlimefunStartup.getWhitelist().save();
} }
@EventHandler @EventHandler
public void onWorldUnload(WorldUnloadEvent e) { public void onWorldUnload(WorldUnloadEvent e) {
BlockStorage storage = BlockStorage.getStorage(e.getWorld()); BlockStorage storage = BlockStorage.getStorage(e.getWorld());
if (storage != null) storage.save(true); if (storage != null) storage.save(true);
else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + e.getWorld().getName() + "\""); else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + e.getWorld().getName() + "\"");
} }
}, this); }, this);
// Clear the Slimefun Guide History upon Player Leaving // Clear the Slimefun Guide History upon Player Leaving
// TODO: Move it to its own class, was too lazy // TODO: Move it to its own class, was too lazy
getServer().getPluginManager().registerEvents(new Listener() { getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler @EventHandler
public void onDisconnect(PlayerQuitEvent e) { public void onDisconnect(PlayerQuitEvent e) {
if (SlimefunGuide.history.containsKey(e.getPlayer().getUniqueId())) SlimefunGuide.history.remove(e.getPlayer().getUniqueId()); if (SlimefunGuide.history.containsKey(e.getPlayer().getUniqueId())) SlimefunGuide.history.remove(e.getPlayer().getUniqueId());
} }
}, this); }, this);
// Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading) // Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading)
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
@ -344,15 +347,15 @@ public class SlimefunStartup extends JavaPlugin {
Slimefun.emeraldenchants = getServer().getPluginManager().isPluginEnabled("EmeraldEnchants"); Slimefun.emeraldenchants = getServer().getPluginManager().isPluginEnabled("EmeraldEnchants");
SlimefunGuide.all_recipes = config.getBoolean("options.show-vanilla-recipes-in-guide"); SlimefunGuide.all_recipes = config.getBoolean("options.show-vanilla-recipes-in-guide");
MiscSetup.loadItems(); MiscSetup.loadItems();
for (World world: Bukkit.getWorlds()) { for (World world: Bukkit.getWorlds()) {
new BlockStorage(world); new BlockStorage(world);
} }
if (SlimefunItem.getByName("ANCIENT_ALTAR") != null) new AncientAltarListener((SlimefunStartup) instance); if (SlimefunItem.getByName("ANCIENT_ALTAR") != null) new AncientAltarListener((SlimefunStartup) instance);
} }
}, 0); }, 0);
// WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent // WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent
if (getServer().getPluginManager().isPluginEnabled("WorldEdit")) { if (getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
try { try {
@ -364,14 +367,14 @@ public class SlimefunStartup extends JavaPlugin {
System.err.println("[Slimefun] Maybe consider updating WorldEdit or Slimefun?"); System.err.println("[Slimefun] Maybe consider updating WorldEdit or Slimefun?");
} }
} }
getCommand("slimefun").setExecutor(new SlimefunCommand(this)); getCommand("slimefun").setExecutor(new SlimefunCommand(this));
getCommand("slimefun").setTabCompleter(new SlimefunTabCompleter()); getCommand("slimefun").setTabCompleter(new SlimefunTabCompleter());
// Armor Update Task // Armor Update Task
if (config.getBoolean("options.enable-armor-effects")) { if (config.getBoolean("options.enable-armor-effects")) {
getServer().getScheduler().runTaskTimer(this, new Runnable() { getServer().getScheduler().runTaskTimer(this, new Runnable() {
@Override @Override
public void run() { public void run() {
for (Player p: Bukkit.getOnlinePlayers()) { for (Player p: Bukkit.getOnlinePlayers()) {
@ -394,7 +397,7 @@ public class SlimefunStartup extends JavaPlugin {
} }
} }
} }
for (ItemStack radioactive: SlimefunItem.radioactive) { for (ItemStack radioactive: SlimefunItem.radioactive) {
if (p.getInventory().containsAtLeast(radioactive, 1)) { if (p.getInventory().containsAtLeast(radioactive, 1)) {
boolean hasFullHazmat = false; boolean hasFullHazmat = false;
@ -407,7 +410,7 @@ public class SlimefunStartup extends JavaPlugin {
} }
} }
} }
if (!hasFullHazmat){ if (!hasFullHazmat){
p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3)); p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3));
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3)); p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3));
@ -424,41 +427,48 @@ public class SlimefunStartup extends JavaPlugin {
} }
}, 0L, config.getInt("options.armor-update-interval") * 20L); }, 0L, config.getInt("options.armor-update-interval") * 20L);
} }
ticker = new TickerTask(); ticker = new TickerTask();
// Starting all ASYNC Tasks // Starting all ASYNC Tasks
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoSavingTask(), 1200L, config.getInt("options.auto-save-delay-in-minutes") * 60L * 20L); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoSavingTask(), 1200L, config.getInt("options.auto-save-delay-in-minutes") * 60L * 20L);
getServer().getScheduler().scheduleAsyncRepeatingTask(this, ticker, 100L, config.getInt("URID.custom-ticker-delay")); getServer().getScheduler().scheduleAsyncRepeatingTask(this, ticker, 100L, config.getInt("URID.custom-ticker-delay"));
// Hooray! // Hooray!
System.out.println("[Slimefun] Finished!"); System.out.println("[Slimefun] Finished!");
clearlag = getServer().getPluginManager().isPluginEnabled("ClearLag"); clearlag = getServer().getPluginManager().isPluginEnabled("ClearLag");
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable() {
@Override
public void run() {
exoticGarden = getServer().getPluginManager().isPluginEnabled("ExoticGarden"); //Had to do it this way, otherwise it seems disabled.
}
}, 0);
if (clearlag) new ClearLaggIntegration(this); if (clearlag) new ClearLaggIntegration(this);
// Do not show /sf elevator command in our Log, it could get quite spammy // Do not show /sf elevator command in our Log, it could get quite spammy
CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})"); CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})");
} }
} }
@Override @Override
public void onDisable() { public void onDisable() {
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);
try { try {
for (Map.Entry<Block, Block> entry: ticker.move.entrySet()) { for (Map.Entry<Block, Block> entry: ticker.move.entrySet()) {
BlockStorage._integrated_moveBlockInfo(entry.getKey(), entry.getValue()); BlockStorage._integrated_moveBlockInfo(entry.getKey(), entry.getValue());
} }
ticker.move.clear(); ticker.move.clear();
for (World world: Bukkit.getWorlds()) { for (World world: Bukkit.getWorlds()) {
BlockStorage storage = BlockStorage.getStorage(world); BlockStorage storage = BlockStorage.getStorage(world);
if (storage != null) storage.save(true); if (storage != null) storage.save(true);
else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + world.getName() + "\""); else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + world.getName() + "\"");
} }
File folder = new File("data-storage/Slimefun/block-backups"); File folder = new File("data-storage/Slimefun/block-backups");
List<File> backups = Arrays.asList(folder.listFiles()); List<File> backups = Arrays.asList(folder.listFiles());
if (backups.size() > 20) { if (backups.size() > 20) {
@ -473,78 +483,78 @@ public class SlimefunStartup extends JavaPlugin {
} }
} }
}); });
for (int i = backups.size() - 20; i > 0; i--) { for (int i = backups.size() - 20; i > 0; i--) {
backups.get(i).delete(); backups.get(i).delete();
} }
} }
File file = new File("data-storage/Slimefun/block-backups/" + Clock.format(new Date()) + ".zip"); File file = new File("data-storage/Slimefun/block-backups/" + Clock.format(new Date()) + ".zip");
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
if (file.exists()) file.delete(); if (file.exists()) file.delete();
try { try {
file.createNewFile(); file.createNewFile();
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file)); ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file));
for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) { for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) {
for (File f: f1.listFiles()) { for (File f: f1.listFiles()) {
ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName()); ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName());
output.putNextEntry(entry); output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f); FileInputStream input = new FileInputStream(f);
int length; int length;
while ((length = input.read(buffer)) > 0) { while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length); output.write(buffer, 0, length);
} }
input.close(); input.close();
output.closeEntry(); output.closeEntry();
} }
} }
for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) { for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) {
ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName()); ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName());
output.putNextEntry(entry); output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f); FileInputStream input = new FileInputStream(f);
int length; int length;
while ((length = input.read(buffer)) > 0) { while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length); output.write(buffer, 0, length);
} }
input.close(); input.close();
output.closeEntry(); output.closeEntry();
} }
for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) { for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) {
ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName()); ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName());
output.putNextEntry(entry); output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f); FileInputStream input = new FileInputStream(f);
int length; int length;
while ((length = input.read(buffer)) > 0) { while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length); output.write(buffer, 0, length);
} }
input.close(); input.close();
output.closeEntry(); output.closeEntry();
} }
ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc"); ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc");
output.putNextEntry(entry); output.putNextEntry(entry);
FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc")); FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc"));
int length; int length;
while ((length = input.read(buffer)) > 0) { while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length); output.write(buffer, 0, length);
} }
input.close(); input.close();
output.closeEntry(); output.closeEntry();
output.close(); output.close();
System.out.println("[Slimfun] Backed up Blocks to " + file.getName()); System.out.println("[Slimfun] Backed up Blocks to " + file.getName());
} catch(IOException e) { } catch(IOException e) {
@ -552,7 +562,7 @@ public class SlimefunStartup extends JavaPlugin {
} }
} catch(Exception x) { } catch(Exception x) {
} }
config = null; config = null;
researches = null; researches = null;
items = null; items = null;
@ -607,38 +617,41 @@ public class SlimefunStartup extends JavaPlugin {
BlockStorage.universal_inventories = null; BlockStorage.universal_inventories = null;
TickerTask.block_timings = null; TickerTask.block_timings = null;
OreGenSystem.map = null; OreGenSystem.map = null;
for (Player p: Bukkit.getOnlinePlayers()) { for (Player p: Bukkit.getOnlinePlayers()) {
p.closeInventory(); p.closeInventory();
} }
} }
public static Config getCfg() { public static Config getCfg() {
return config; return config;
} }
public static Config getResearchCfg() { public static Config getResearchCfg() {
return researches; return researches;
} }
public static Config getItemCfg() { public static Config getItemCfg() {
return items; return items;
} }
public static Config getWhitelist() { public static Config getWhitelist() {
return whitelist; return whitelist;
} }
public static int randomize(int max) { public static int randomize(int max) {
return CSCoreLib.randomizer().nextInt(max); return CSCoreLib.randomizer().nextInt(max);
} }
public static boolean chance(int max, int percentage) { public static boolean chance(int max, int percentage) {
return CSCoreLib.randomizer().nextInt(max) <= percentage; return CSCoreLib.randomizer().nextInt(max) <= percentage;
} }
public boolean isClearLagInstalled() { public boolean isClearLagInstalled() {
return clearlag; return clearlag;
} }
public boolean isExoticGardenInstalled () {
return exoticGarden;
}
} }