diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 71e716de3..b5f887ab6 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -3,18 +3,27 @@ Slimefun is a community project, everyone is welcome to open Issues, make Pull Requests or make Pull Requests for an opened Issue. Without your help, this project is going to die. +## General Guidelines + +Rules for all types of posts: + +1. Follow our Templates for Issues and Pull Request, they are designed to tell you what exact Information we need and how you should present it to us. +2. Be nice and give constructive critism. Insulting, Harassment, Racism, Sexism or any form of bullying or discrimination is not tolerated. +3. Try to engage in conversations by pointing out scenarios to replicate Issues, providing fix approaches or other kind of help. +4. Advertisement is inappropriate and will be removed, especially advertisement for Minecraft Servers is completely unaccepted. + ## GitHub Issues Rules for posting an Issue on GitHub: 1. This Issue Section is ONLY for Slimefun-related Issues, Issues about other Plugins or Slimefun Addons should not be posted here. 2. Check other Issues before posting to make sure you are not posting a duplicate. -3. Do not put any Tags inside your title like [IMPORTANT], [URGENT] or [SUGGESTION]. -Try to be professional by making your title as short as possible, we will assign it the required labels if necessary. -4. Do not post your Issue more than once, this is considered spam and does not benefit our community in any way. -Do not repost your Issue if it was closed either. -5. Give us all available information right away, it may be a bit of time-wasting for us to keep asking for more Info. +3. Do not put any Tags inside your title like [IMPORTANT], [URGENT] or [SUGGESTION]. Try to be professional by making your title as short as possible, we will assign it the required labels if necessary. +4. Do not post your Issue more than once, this is considered spam and does not benefit our community in any way. Do not repost your Issue if it was closed either. +5. Give us all available information right away, it may be a bit of time-wasting for us to keep asking for more Info. And this includes any Information to reproduce your Issue step-by-step. 6. Check whether there are newer versions available than the ones you are using, it might be that your Issue has been fixed already. +7. All text logs must be posted via a link to http://pastebin.com or similiar websites. +8. Please read the [FAQ Section](#frequently-asked-questions) before posting. Your Issue will be CLOSED WITHOUT WARNING if we think you violated these Rules. @@ -22,9 +31,11 @@ Your Issue will be CLOSED WITHOUT WARNING if we think you violated these Rules. Guidelines for making a Pull Request on GitHub: -1. Try to be reasonable with your additions. -No, a Bacon flavoured unicorn that flies on a rainbow while dancing Gangnam Style is NOT a reasonable addition to this Project. -2. Try to make your values configurable in the config.yml / Items.yml or any additional file. -This may not be necessary at every instance but it does give the end-users a way to customize their experience. -3. If your Pull Request is made in response to an Issue opened on GitHub, -comment on that Issue and reference your Pull Request to show that you are proposing a fix for it. +1. Try to be reasonable with your additions. No, a Bacon flavoured unicorn that flies on a rainbow while dancing Gangnam Style is NOT a reasonable addition to this Project. +2. Try to make your values configurable in the config.yml / Items.yml or any additional file. This may not be necessary at every instance but it does give the end-users a way to customize their experience. +3. If your Pull Request is made in response to an Issue opened on GitHub, comment on that Issue and reference your Pull Request to show that you are proposing a fix for it. + +## Frequently Asked Questions + +### Slimefun does not work!? +> Install CS-CoreLib... diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b5fc58480..059836237 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -10,5 +10,7 @@ Attach as many Screenshots or Videos if possible. Anything that helps us understand the Issue better, is gonna get your Issue fixed even faster. ## Environment -State what Version of Minecraft, CS-CoreLib and Slimefun you're using -"latest" is not enough, we need the EXACT VERSIONS. +We need the EXACT VERSIONS of the Software you are using. +This includes your Minecraft Version, your CS-CoreLib version and your Slimefun Version. +If you cannot figure out what versions you are running, then please run /sf versions and +show us the output of that command. diff --git a/src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java b/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java similarity index 73% rename from src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java rename to src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java index 765db59cf..62053b2f8 100644 --- a/src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java +++ b/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java @@ -1,149 +1,152 @@ -package me.mrCookieSlime.CSCoreLibSetup; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -import org.bukkit.plugin.Plugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -public class CSCoreLibLoader { - - Plugin plugin; - URL url; - URL download; - File file; - - public CSCoreLibLoader(Plugin plugin) { - this.plugin = plugin; - try { - this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=88802"); - } catch (MalformedURLException e) { - } - } - - public boolean load() { - if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) return true; - else { - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - System.err.println(plugin.getName() + " could not be properly installed!"); - System.err.println("It appears that you have not installed CS-CoreLib"); - System.err.println("And because of that, CS-CoreLib is now going to be"); - System.err.println("downloaded and installed."); - System.err.println("But for the time being " + plugin.getName() + " will remain disabled"); - System.err.println("After the installation process has finished,"); - System.out.println("you will be asked to restart your Server."); - System.err.println("- mrCookieSlime"); - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - if (connect()) install(); - } - }, 10L); - return false; - } - } - - private boolean connect() { - try { - final URLConnection connection = this.url.openConnection(); - connection.setConnectTimeout(5000); - connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)"); - connection.setDoOutput(true); - - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine()); - download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:")); - file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar"); - - return true; - } catch (IOException e) { - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - System.err.println("Could not connect to BukkitDev, is it down?"); - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - return false; - } - } - - private URL traceURL(String location) throws IOException { - HttpURLConnection connection = null; - - while (true) { - URL url = new URL(location); - connection = (HttpURLConnection) url.openConnection(); - - connection.setInstanceFollowRedirects(false); - connection.setConnectTimeout(5000); - connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); - - switch (connection.getResponseCode()) { - case HttpURLConnection.HTTP_MOVED_PERM: - case HttpURLConnection.HTTP_MOVED_TEMP: - String loc = connection.getHeaderField("Location"); - location = new URL(new URL(location), loc).toExternalForm(); - continue; - } - break; - } - - return connection.getURL(); - } - - private void install() { - BufferedInputStream input = null; - FileOutputStream output = null; - try { - input = new BufferedInputStream(download.openStream()); - output = new FileOutputStream(file); - - final byte[] data = new byte[1024]; - int read; - while ((read = input.read(data, 0, 1024)) != -1) { - output.write(data, 0, read); - } - } catch (Exception ex) { - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - System.err.println("Could not download CS-CoreLib"); - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - } finally { - try { - if (input != null) input.close(); - if (output != null) output.close(); - System.err.println(" "); - System.err.println("#################### - WARNING - ####################"); - System.err.println(" "); - System.err.println("Please restart your Server to finish the Installation"); - System.err.println("of " + plugin.getName() + " and CS-CoreLib"); - System.err.println(" "); - System.err.println("#################### - WARNING - ####################"); - System.err.println(" "); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - -} +package me.mrCookieSlime.Slimefun.CSCoreLibSetup; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +import org.bukkit.plugin.Plugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class CSCoreLibLoader { + + Plugin plugin; + URL url; + URL download; + File file; + + public CSCoreLibLoader(Plugin plugin) { + this.plugin = plugin; + try { + this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=88802"); + } catch (MalformedURLException e) { + } + } + + public boolean load() { + if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) return true; + else { + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); + System.err.println(plugin.getName() + " could not be loaded."); + System.err.println("It appears that you have not installed CS-CoreLib"); + System.err.println("Your Server will now try to download and install"); + System.err.println("CS-CoreLib for you."); + System.err.println("You will be asked to restart your Server when it's finished."); + System.err.println("If this somehow fails, please download and install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + + @Override + public void run() { + if (connect()) install(); + } + }, 10L); + return false; + } + } + + private boolean connect() { + try { + final URLConnection connection = this.url.openConnection(); + connection.setConnectTimeout(5000); + connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)"); + connection.setDoOutput(true); + + final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine()); + download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:")); + file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar"); + + return true; + } catch (IOException e) { + System.err.println(" "); + System.err.println("#################### - WARNING - ####################"); + System.err.println(" "); + System.err.println("Could not connect to BukkitDev."); + System.err.println("Please download & install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); + System.err.println(" "); + System.err.println("#################### - WARNING - ####################"); + System.err.println(" "); + return false; + } + } + + private URL traceURL(String location) throws IOException { + HttpURLConnection connection = null; + + while (true) { + URL url = new URL(location); + connection = (HttpURLConnection) url.openConnection(); + + connection.setInstanceFollowRedirects(false); + connection.setConnectTimeout(5000); + connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); + + switch (connection.getResponseCode()) { + case HttpURLConnection.HTTP_MOVED_PERM: + case HttpURLConnection.HTTP_MOVED_TEMP: + String loc = connection.getHeaderField("Location"); + location = new URL(new URL(location), loc).toExternalForm(); + continue; + } + break; + } + + return new URL(connection.getURL().toString().replaceAll(" ", "%20")); + } + + private void install() { + BufferedInputStream input = null; + FileOutputStream output = null; + try { + input = new BufferedInputStream(download.openStream()); + output = new FileOutputStream(file); + + final byte[] data = new byte[1024]; + int read; + while ((read = input.read(data, 0, 1024)) != -1) { + output.write(data, 0, read); + } + } catch (Exception ex) { + System.err.println(" "); + System.err.println("#################### - WARNING - ####################"); + System.err.println(" "); + System.err.println("Failed to download CS-CoreLib"); + System.err.println("Please download & install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); + System.err.println(" "); + System.err.println("#################### - WARNING - ####################"); + System.err.println(" "); + } finally { + try { + if (input != null) input.close(); + if (output != null) output.close(); + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); + System.err.println("Please restart your Server to finish the Installation"); + System.err.println("of " + plugin.getName() + " and CS-CoreLib"); + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/me/mrCookieSlime/Slimefun/Commands/SlimefunCommand.java b/src/me/mrCookieSlime/Slimefun/Commands/SlimefunCommand.java index d21f715f2..4b75cb48d 100644 --- a/src/me/mrCookieSlime/Slimefun/Commands/SlimefunCommand.java +++ b/src/me/mrCookieSlime/Slimefun/Commands/SlimefunCommand.java @@ -18,9 +18,11 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.Plugin; +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Variable; import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.CommandHelp; import me.mrCookieSlime.CSCoreLibPlugin.general.Player.Players; +import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.World.TitleBuilder; import me.mrCookieSlime.CSCoreLibPlugin.general.World.TitleBuilder.TitleType; import me.mrCookieSlime.Slimefun.SlimefunGuide; @@ -152,21 +154,34 @@ public class SlimefunCommand implements CommandExecutor, Listener { } else if (args[0].equalsIgnoreCase("versions")) { if (sender.hasPermission("slimefun.command.versions")|| sender instanceof ConsoleCommandSender) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a" + Bukkit.getName() + " &2" + ReflectionUtils.getVersion())); + sender.sendMessage(""); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aCS-CoreLib &2v" + CSCoreLib.getLib().getDescription().getVersion())); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aSlimefun &2v" + plugin.getDescription().getVersion())); sender.sendMessage(""); - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&oInstalled Addons:")); + + List addons = new ArrayList(); + for (Plugin plugin: Bukkit.getPluginManager().getPlugins()) { if (plugin.getDescription().getDepend().contains("Slimefun") || plugin.getDescription().getSoftDepend().contains("Slimefun")) { if (Bukkit.getPluginManager().isPluginEnabled(plugin)) { - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', " &a" + plugin.getName() + " &2v" + plugin.getDescription().getVersion())); + addons.add(ChatColor.translateAlternateColorCodes('&', " &a" + plugin.getName() + " &2v" + plugin.getDescription().getVersion())); } else { - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', " &c" + plugin.getName() + " &4v" + plugin.getDescription().getVersion())); + addons.add(ChatColor.translateAlternateColorCodes('&', " &c" + plugin.getName() + " &4v" + plugin.getDescription().getVersion())); } } } + + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Installed Addons &8(" + addons.size() + ")")); + + for (String addon: addons) { + sender.sendMessage(addon); + } + } + else { + Messages.local.sendTranslation(sender, "messages.no-permission", true); } - else Messages.local.sendTranslation(sender, "messages.no-permission", true); } else if (args[0].equalsIgnoreCase("give")) { if (args.length == 3) { diff --git a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java index 3fb80e686..9dafc6126 100644 --- a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java +++ b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java @@ -1,26 +1,9 @@ package me.mrCookieSlime.Slimefun; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.AutoEnchanter; -import net.coreprotect.CoreProtect; -import net.coreprotect.CoreProtectAPI; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,10 +20,9 @@ import org.bukkit.scheduler.BukkitRunnable; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; -import me.mrCookieSlime.CSCoreLibPlugin.general.Clock; import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; -import me.mrCookieSlime.CSCoreLibSetup.CSCoreLibLoader; import me.mrCookieSlime.Slimefun.AncientAltar.Pedestals; +import me.mrCookieSlime.Slimefun.CSCoreLibSetup.CSCoreLibLoader; import me.mrCookieSlime.Slimefun.Commands.SlimefunCommand; import me.mrCookieSlime.Slimefun.Commands.SlimefunTabCompleter; import me.mrCookieSlime.Slimefun.GEO.OreGenSystem; @@ -55,6 +37,7 @@ import me.mrCookieSlime.Slimefun.Objects.Research; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunArmorPiece; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.AutoEnchanter; import me.mrCookieSlime.Slimefun.Setup.Files; import me.mrCookieSlime.Slimefun.Setup.Messages; import me.mrCookieSlime.Slimefun.Setup.MiscSetup; @@ -66,6 +49,7 @@ import me.mrCookieSlime.Slimefun.URID.URID; import me.mrCookieSlime.Slimefun.WorldEdit.WESlimefunManager; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; +import me.mrCookieSlime.Slimefun.api.SlimefunBackup; import me.mrCookieSlime.Slimefun.api.TickerTask; import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.energy.EnergyNet; @@ -89,6 +73,8 @@ import me.mrCookieSlime.Slimefun.listeners.ItemListener; import me.mrCookieSlime.Slimefun.listeners.TalismanListener; import me.mrCookieSlime.Slimefun.listeners.TeleporterListener; import me.mrCookieSlime.Slimefun.listeners.ToolListener; +import net.coreprotect.CoreProtect; +import net.coreprotect.CoreProtectAPI; public class SlimefunStartup extends JavaPlugin { @@ -375,7 +361,7 @@ public class SlimefunStartup extends JavaPlugin { connector.pullFile(); } } - }, 60L, 20 * 60 * 20L); + }, 80L, 60 * 60 * 20L); // Hooray! System.out.println("[Slimefun] Finished!"); @@ -408,110 +394,23 @@ public class SlimefunStartup extends JavaPlugin { @Override public void onDisable() { Bukkit.getScheduler().cancelTasks(this); - + + // Finishes all started movements/removals of block data + ticker.HALTED = true; + ticker.run(); + try { - for (Map.Entry entry: ticker.move.entrySet()) { - BlockStorage._integrated_moveBlockInfo(entry.getKey(), entry.getValue()); - } - ticker.move.clear(); - for (World world: Bukkit.getWorlds()) { BlockStorage storage = BlockStorage.getStorage(world); - if (storage != null) storage.save(true); - else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + world.getName() + "\""); - } - - File folder = new File("data-storage/Slimefun/block-backups"); - List backups = Arrays.asList(folder.listFiles()); - if (backups.size() > 20) { - Collections.sort(backups, new Comparator() { - - @Override - public int compare(File f1, File f2) { - try { - return (int) (new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f1.getName().replace(".zip", "")).getTime() - new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f2.getName().replace(".zip", "")).getTime()); - } catch (ParseException e) { - return 0; - } - } - }); - - for (int i = backups.size() - 20; i > 0; i--) { - backups.get(i).delete(); + if (storage != null) { + storage.save(true); + } + else { + System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + world.getName() + "\""); } } - File file = new File("data-storage/Slimefun/block-backups/" + Clock.format(new Date()) + ".zip"); - byte[] buffer = new byte[1024]; - - if (file.exists()) file.delete(); - - try { - file.createNewFile(); - - ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file)); - - for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) { - for (File f: f1.listFiles()) { - ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName()); - output.putNextEntry(entry); - FileInputStream input = new FileInputStream(f); - - int length; - while ((length = input.read(buffer)) > 0) { - output.write(buffer, 0, length); - } - - input.close(); - output.closeEntry(); - } - } - - for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) { - ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName()); - output.putNextEntry(entry); - FileInputStream input = new FileInputStream(f); - - int length; - while ((length = input.read(buffer)) > 0) { - output.write(buffer, 0, length); - } - - input.close(); - output.closeEntry(); - } - - for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) { - ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName()); - output.putNextEntry(entry); - FileInputStream input = new FileInputStream(f); - - int length; - while ((length = input.read(buffer)) > 0) { - output.write(buffer, 0, length); - } - - input.close(); - output.closeEntry(); - } - - ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc"); - output.putNextEntry(entry); - FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc")); - - int length; - while ((length = input.read(buffer)) > 0) { - output.write(buffer, 0, length); - } - - input.close(); - output.closeEntry(); - - output.close(); - System.out.println("[Slimfun] Backed up Blocks to " + file.getName()); - } catch(IOException e) { - e.printStackTrace(); - } + SlimefunBackup.start(); } catch(Exception x) { } diff --git a/src/me/mrCookieSlime/Slimefun/api/SlimefunBackup.java b/src/me/mrCookieSlime/Slimefun/api/SlimefunBackup.java new file mode 100644 index 000000000..76c3fbcb5 --- /dev/null +++ b/src/me/mrCookieSlime/Slimefun/api/SlimefunBackup.java @@ -0,0 +1,119 @@ +package me.mrCookieSlime.Slimefun.api; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import me.mrCookieSlime.CSCoreLibPlugin.general.Clock; + +public class SlimefunBackup { + + public static void start() { + File folder = new File("data-storage/Slimefun/block-backups"); + List backups = Arrays.asList(folder.listFiles()); + if (backups.size() > 20) { + Collections.sort(backups, new Comparator() { + + @Override + public int compare(File f1, File f2) { + try { + return (int) (new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f1.getName().replace(".zip", "")).getTime() - new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f2.getName().replace(".zip", "")).getTime()); + } catch (ParseException e) { + return 0; + } + } + }); + + for (int i = backups.size() - 20; i > 0; i--) { + backups.get(i).delete(); + } + } + + File file = new File("data-storage/Slimefun/block-backups/" + Clock.format(new Date()) + ".zip"); + byte[] buffer = new byte[1024]; + + if (file.exists()) { + file.delete(); + } + + try { + file.createNewFile(); + + ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file)); + + for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) { + for (File f: f1.listFiles()) { + ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName()); + output.putNextEntry(entry); + FileInputStream input = new FileInputStream(f); + + int length; + while ((length = input.read(buffer)) > 0) { + output.write(buffer, 0, length); + } + + input.close(); + output.closeEntry(); + } + } + + for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) { + ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName()); + output.putNextEntry(entry); + FileInputStream input = new FileInputStream(f); + + int length; + while ((length = input.read(buffer)) > 0) { + output.write(buffer, 0, length); + } + + input.close(); + output.closeEntry(); + } + + for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) { + ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName()); + output.putNextEntry(entry); + FileInputStream input = new FileInputStream(f); + + int length; + while ((length = input.read(buffer)) > 0) { + output.write(buffer, 0, length); + } + + input.close(); + output.closeEntry(); + } + + if (new File("data-storage/Slimefun/stored-chunks/chunks.sfc").exists()) { + ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc"); + output.putNextEntry(entry); + FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc")); + + int length; + while ((length = input.read(buffer)) > 0) { + output.write(buffer, 0, length); + } + + input.close(); + output.closeEntry(); + } + + output.close(); + System.out.println("[Slimfun] Backed up Blocks to " + file.getName()); + } catch(IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/me/mrCookieSlime/Slimefun/api/TickerTask.java b/src/me/mrCookieSlime/Slimefun/api/TickerTask.java index d9677a317..23eb982ca 100644 --- a/src/me/mrCookieSlime/Slimefun/api/TickerTask.java +++ b/src/me/mrCookieSlime/Slimefun/api/TickerTask.java @@ -23,6 +23,8 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.handlers.BlockTicker; public class TickerTask implements Runnable { + public boolean HALTED = false; + public Map move = new HashMap(); public Map delete = new HashMap(); @@ -42,6 +44,7 @@ public class TickerTask implements Runnable { @Override public void run() { + long timestamp = System.currentTimeMillis(); skipped = 0; @@ -65,57 +68,59 @@ public class TickerTask implements Runnable { delete.remove(entry.getKey()); } - for (final String c: BlockStorage.getTickingChunks()) { - long timestamp2 = System.currentTimeMillis(); - chunks++; - - blocks: - for (final Block b: BlockStorage.getTickingBlocks(c)) { - if (b.getChunk().isLoaded()) { - final Location l = b.getLocation(); - final SlimefunItem item = BlockStorage.check(l); - if (item != null) { - machines++; - try { - item.getTicker().update(); - if (item.getTicker().isSynchronized()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { - - @Override - public void run() { - try { - long timestamp3 = System.currentTimeMillis(); - item.getTicker().tick(b, item, BlockStorage.getBlockInfo(l)); - - map_machinetime.put(item.getName(), (map_machinetime.containsKey(item.getName()) ? map_machinetime.get(item.getName()): 0) + (System.currentTimeMillis() - timestamp3)); - map_chunk.put(c, (map_chunk.containsKey(c) ? map_chunk.get(c): 0) + 1); - map_machine.put(item.getName(), (map_machine.containsKey(item.getName()) ? map_machine.get(item.getName()): 0) + 1); - block_timings.put(l, System.currentTimeMillis() - timestamp3); - } catch(Exception x) { - int errors = 0; - if (bugged.containsKey(l)) errors = bugged.get(l); - errors++; - - if (errors == 1) { - File file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + ".err"); - if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(2).err"); + if (!HALTED) { + for (final String c: BlockStorage.getTickingChunks()) { + long timestamp2 = System.currentTimeMillis(); + chunks++; + + blocks: + for (final Block b: BlockStorage.getTickingBlocks(c)) { + if (b.getChunk().isLoaded()) { + final Location l = b.getLocation(); + final SlimefunItem item = BlockStorage.check(l); + if (item != null) { + machines++; + try { + item.getTicker().update(); + if (item.getTicker().isSynchronized()) { + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { + + @Override + public void run() { + try { + long timestamp3 = System.currentTimeMillis(); + item.getTicker().tick(b, item, BlockStorage.getBlockInfo(l)); + + map_machinetime.put(item.getName(), (map_machinetime.containsKey(item.getName()) ? map_machinetime.get(item.getName()): 0) + (System.currentTimeMillis() - timestamp3)); + map_chunk.put(c, (map_chunk.containsKey(c) ? map_chunk.get(c): 0) + 1); + map_machine.put(item.getName(), (map_machine.containsKey(item.getName()) ? map_machine.get(item.getName()): 0) + 1); + block_timings.put(l, System.currentTimeMillis() - timestamp3); + } catch(Exception x) { + int errors = 0; + if (bugged.containsKey(l)) errors = bugged.get(l); + errors++; + + if (errors == 1) { + File file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + ".err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(3).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(2).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(4).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(3).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(5).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(4).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(6).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(5).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(7).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(6).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(8).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(7).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(9).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(8).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(10).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(9).err"); + if (file.exists()) { + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(10).err"); + } } } } @@ -124,113 +129,113 @@ public class TickerTask implements Runnable { } } } - } - try { - PrintStream stream = new PrintStream(file); - stream.println(); - stream.println("Server Software: " + Bukkit.getName()); - stream.println(" Build: " + Bukkit.getVersion()); - stream.println(" Minecraft: " + Bukkit.getBukkitVersion()); - stream.println(); - stream.println("Installed Plugins (" + Bukkit.getPluginManager().getPlugins().length + ")"); - for (Plugin p: Bukkit.getPluginManager().getPlugins()) { - if (Bukkit.getPluginManager().isPluginEnabled(p)) { - stream.println(" + " + p.getName() + " " + p.getDescription().getVersion()); - } - else { - stream.println(" - " + p.getName() + " " + p.getDescription().getVersion()); + try { + PrintStream stream = new PrintStream(file); + stream.println(); + stream.println("Server Software: " + Bukkit.getName()); + stream.println(" Build: " + Bukkit.getVersion()); + stream.println(" Minecraft: " + Bukkit.getBukkitVersion()); + stream.println(); + stream.println("Installed Plugins (" + Bukkit.getPluginManager().getPlugins().length + ")"); + for (Plugin p: Bukkit.getPluginManager().getPlugins()) { + if (Bukkit.getPluginManager().isPluginEnabled(p)) { + stream.println(" + " + p.getName() + " " + p.getDescription().getVersion()); + } + else { + stream.println(" - " + p.getName() + " " + p.getDescription().getVersion()); + } } + stream.println(); + stream.println("Ticked Block:"); + stream.println(" World: " + l.getWorld().getName()); + stream.println(" X: " + l.getBlockX()); + stream.println(" Y: " + l.getBlockY()); + stream.println(" Z: " + l.getBlockZ()); + stream.println(); + stream.println("Slimefun Data:"); + stream.println(" ID: " + item.getName()); + stream.println(" Inventory: " + BlockStorage.getStorage(l.getWorld()).hasInventory(l)); + stream.println(" Data: " + BlockStorage.getBlockInfoAsJson(l)); + stream.println(); + stream.println("Stacktrace:"); + stream.println(); + x.printStackTrace(stream); + + stream.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); } - stream.println(); - stream.println("Ticked Block:"); - stream.println(" World: " + l.getWorld().getName()); - stream.println(" X: " + l.getBlockX()); - stream.println(" Y: " + l.getBlockY()); - stream.println(" Z: " + l.getBlockZ()); - stream.println(); - stream.println("Slimefun Data:"); - stream.println(" ID: " + item.getName()); - stream.println(" Inventory: " + BlockStorage.getStorage(l.getWorld()).hasInventory(l)); - stream.println(" Data: " + BlockStorage.getBlockInfoAsJson(l)); - stream.println(); - stream.println("Stacktrace:"); - stream.println(); - x.printStackTrace(stream); - stream.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); + System.err.println("[Slimefun] Exception caught while ticking a Block:" + x.getClass().getName()); + System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ()); + System.err.println("[Slimefun] Saved as: "); + System.err.println("[Slimefun] /plugins/Slimefun/error-reports/" + file.getName()); + System.err.println("[Slimefun] Please consider sending this File to the developer(s) of Slimefun, sending this Error won't get you any help though."); + System.err.println("[Slimefun] "); + + bugged_blocks.put(l, errors); } - - System.err.println("[Slimefun] Exception caught while ticking a Block:" + x.getClass().getName()); - System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ()); - System.err.println("[Slimefun] Saved as: "); - System.err.println("[Slimefun] /plugins/Slimefun/error-reports/" + file.getName()); - System.err.println("[Slimefun] Please consider sending this File to the developer(s) of Slimefun, sending this Error won't get you any help though."); - System.err.println("[Slimefun] "); - - bugged_blocks.put(l, errors); - } - else if (errors == 4) { - System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + "(" + item.getName() + ")"); - System.err.println("[Slimefun] has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated."); - System.err.println("[Slimefun] Check your /plugins/Slimefun/error-reports/ folder for details."); - System.err.println("[Slimefun] "); - - BlockStorage._integrated_removeBlockInfo(l, true); - - Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { + else if (errors == 4) { + System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + "(" + item.getName() + ")"); + System.err.println("[Slimefun] has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated."); + System.err.println("[Slimefun] Check your /plugins/Slimefun/error-reports/ folder for details."); + System.err.println("[Slimefun] "); + + BlockStorage._integrated_removeBlockInfo(l, true); + + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { - @Override - public void run() { - l.getBlock().setType(Material.AIR); - } - - }); - } - else { - bugged_blocks.put(l, errors); + @Override + public void run() { + l.getBlock().setType(Material.AIR); + } + + }); + } + else { + bugged_blocks.put(l, errors); + } } } - } - }); - } - else { - long timestamp3 = System.currentTimeMillis(); - item.getTicker().tick(b, item, BlockStorage.getBlockInfo(l)); + }); + } + else { + long timestamp3 = System.currentTimeMillis(); + item.getTicker().tick(b, item, BlockStorage.getBlockInfo(l)); + + map_machinetime.put(item.getName(), (map_machinetime.containsKey(item.getName()) ? map_machinetime.get(item.getName()): 0) + (System.currentTimeMillis() - timestamp3)); + map_chunk.put(c, (map_chunk.containsKey(c) ? map_chunk.get(c): 0) + 1); + map_machine.put(item.getName(), (map_machine.containsKey(item.getName()) ? map_machine.get(item.getName()): 0) + 1); + block_timings.put(l, System.currentTimeMillis() - timestamp3); + } + tickers.add(item.getTicker()); + } catch(Exception x) { - map_machinetime.put(item.getName(), (map_machinetime.containsKey(item.getName()) ? map_machinetime.get(item.getName()): 0) + (System.currentTimeMillis() - timestamp3)); - map_chunk.put(c, (map_chunk.containsKey(c) ? map_chunk.get(c): 0) + 1); - map_machine.put(item.getName(), (map_machine.containsKey(item.getName()) ? map_machine.get(item.getName()): 0) + 1); - block_timings.put(l, System.currentTimeMillis() - timestamp3); - } - tickers.add(item.getTicker()); - } catch(Exception x) { - - int errors = 0; - if (bugged.containsKey(l)) errors = bugged.get(l); - errors++; - - if (errors == 1) { - File file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + ".err"); - if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(2).err"); + int errors = 0; + if (bugged.containsKey(l)) errors = bugged.get(l); + errors++; + + if (errors == 1) { + File file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + ".err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(3).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(2).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(4).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(3).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(5).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(4).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(6).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(5).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(7).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(6).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(8).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(7).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(9).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(8).err"); if (file.exists()) { - file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(10).err"); + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(9).err"); + if (file.exists()) { + file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(10).err"); + } } } } @@ -239,86 +244,86 @@ public class TickerTask implements Runnable { } } } - } - try { - PrintStream stream = new PrintStream(file); - stream.println(); - stream.println("Server Software: " + Bukkit.getName()); - stream.println(" Build: " + Bukkit.getVersion()); - stream.println(" Minecraft: " + Bukkit.getBukkitVersion()); - stream.println(); - stream.println("Installed Plugins (" + Bukkit.getPluginManager().getPlugins().length + ")"); - for (Plugin p: Bukkit.getPluginManager().getPlugins()) { - if (Bukkit.getPluginManager().isPluginEnabled(p)) { - stream.println(" + " + p.getName() + " " + p.getDescription().getVersion()); - } - else { - stream.println(" - " + p.getName() + " " + p.getDescription().getVersion()); + try { + PrintStream stream = new PrintStream(file); + stream.println(); + stream.println("Server Software: " + Bukkit.getName()); + stream.println(" Build: " + Bukkit.getVersion()); + stream.println(" Minecraft: " + Bukkit.getBukkitVersion()); + stream.println(); + stream.println("Installed Plugins (" + Bukkit.getPluginManager().getPlugins().length + ")"); + for (Plugin p: Bukkit.getPluginManager().getPlugins()) { + if (Bukkit.getPluginManager().isPluginEnabled(p)) { + stream.println(" + " + p.getName() + " " + p.getDescription().getVersion()); + } + else { + stream.println(" - " + p.getName() + " " + p.getDescription().getVersion()); + } } + stream.println(); + stream.println("Ticked Block:"); + stream.println(" World: " + l.getWorld().getName()); + stream.println(" X: " + l.getBlockX()); + stream.println(" Y: " + l.getBlockY()); + stream.println(" Z: " + l.getBlockZ()); + stream.println(); + stream.println("Slimefun Data:"); + stream.println(" ID: " + item.getName()); + stream.println(" Inventory: " + BlockStorage.getStorage(l.getWorld()).hasInventory(l)); + stream.println(" Data: " + BlockStorage.getBlockInfoAsJson(l)); + stream.println(); + stream.println("Stacktrace:"); + stream.println(); + x.printStackTrace(stream); + + stream.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); } - stream.println(); - stream.println("Ticked Block:"); - stream.println(" World: " + l.getWorld().getName()); - stream.println(" X: " + l.getBlockX()); - stream.println(" Y: " + l.getBlockY()); - stream.println(" Z: " + l.getBlockZ()); - stream.println(); - stream.println("Slimefun Data:"); - stream.println(" ID: " + item.getName()); - stream.println(" Inventory: " + BlockStorage.getStorage(l.getWorld()).hasInventory(l)); - stream.println(" Data: " + BlockStorage.getBlockInfoAsJson(l)); - stream.println(); - stream.println("Stacktrace:"); - stream.println(); - x.printStackTrace(stream); - stream.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); + System.err.println("[Slimefun] Exception caught while ticking a Block:" + x.getClass().getName()); + System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ()); + System.err.println("[Slimefun] Saved as: "); + System.err.println("[Slimefun] /plugins/Slimefun/error-reports/" + file.getName()); + System.err.println("[Slimefun] Please consider sending this File to the developer(s) of Slimefun, sending this Error won't get you any help though."); + System.err.println("[Slimefun] "); + + bugged_blocks.put(l, errors); } - - System.err.println("[Slimefun] Exception caught while ticking a Block:" + x.getClass().getName()); - System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ()); - System.err.println("[Slimefun] Saved as: "); - System.err.println("[Slimefun] /plugins/Slimefun/error-reports/" + file.getName()); - System.err.println("[Slimefun] Please consider sending this File to the developer(s) of Slimefun, sending this Error won't get you any help though."); - System.err.println("[Slimefun] "); - - bugged_blocks.put(l, errors); - } - else if (errors == 4) { - System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + "(" + item.getName() + ")"); - System.err.println("[Slimefun] has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated."); - System.err.println("[Slimefun] Check your /plugins/Slimefun/error-reports/ folder for details."); - System.err.println("[Slimefun] "); - - BlockStorage._integrated_removeBlockInfo(l, true); - - Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { + else if (errors == 4) { + System.err.println("[Slimefun] X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + "(" + item.getName() + ")"); + System.err.println("[Slimefun] has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated."); + System.err.println("[Slimefun] Check your /plugins/Slimefun/error-reports/ folder for details."); + System.err.println("[Slimefun] "); + + BlockStorage._integrated_removeBlockInfo(l, true); + + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() { - @Override - public void run() { - l.getBlock().setType(Material.AIR); - } - - }); - } - else { - bugged_blocks.put(l, errors); + @Override + public void run() { + l.getBlock().setType(Material.AIR); + } + + }); + } + else { + bugged_blocks.put(l, errors); + } } } + else skipped++; + } + else { + skipped += BlockStorage.getTickingBlocks(c).size(); + skipped_chunks.add(c); + chunks--; + break blocks; } - else skipped++; - } - else { - skipped += BlockStorage.getTickingBlocks(c).size(); - skipped_chunks.add(c); - chunks--; - break blocks; } + + map_chunktime.put(c, System.currentTimeMillis() - timestamp2); } - - map_chunktime.put(c, System.currentTimeMillis() - timestamp2); } for (Map.Entry entry: move.entrySet()) { @@ -336,6 +341,8 @@ public class TickerTask implements Runnable { public void info(CommandSender sender) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2== &aSlimefun Diagnostic Tool &2==")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Halted: &e&l" + String.valueOf(HALTED).toUpperCase())); + sender.sendMessage(""); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Impact: &e" + time + "ms / 50-750ms")); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Chunks: &e" + chunks)); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Machines: &e" + machines)); diff --git a/src/me/mrCookieSlime/Slimefun/api/inventory/BlockMenu.java b/src/me/mrCookieSlime/Slimefun/api/inventory/BlockMenu.java index 7bb5168fd..24209730b 100644 --- a/src/me/mrCookieSlime/Slimefun/api/inventory/BlockMenu.java +++ b/src/me/mrCookieSlime/Slimefun/api/inventory/BlockMenu.java @@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; public class BlockMenu extends ChestMenu { @@ -105,26 +104,6 @@ public class BlockMenu extends ChestMenu { return this.preset.canOpen(b, p); } - @Override - public ChestMenu addItem(int slot, ItemStack item, MenuClickHandler handler) { - addMenuClickHandler(slot, handler); - return super.addItem(slot, item); - } - - @Override - public ChestMenu addMenuClickHandler(int slot, final MenuClickHandler handler) { - MenuClickHandler ch = new MenuClickHandler() { - - @Override - public boolean onClick(Player p, int slot, ItemStack stack, ClickAction action) { - changes++; - return handler.onClick(p, slot, stack, action); - } - }; - - return super.addMenuClickHandler(slot, ch); - } - @Override public void replaceExistingItem(int slot, ItemStack item) { this.replaceExistingItem(slot, item, true); @@ -141,6 +120,16 @@ public class BlockMenu extends ChestMenu { changes++; } + @Override + public ChestMenu addMenuOpeningHandler(MenuOpeningHandler handler) { + if (handler instanceof SaveHandler) { + return super.addMenuOpeningHandler(new SaveHandler(this, ((SaveHandler) handler).handler)); + } + else { + return super.addMenuOpeningHandler(new SaveHandler(this, handler)); + } + } + public void close() { Iterator iterator = toInventory().getViewers().iterator(); while (iterator.hasNext()) { @@ -148,4 +137,22 @@ public class BlockMenu extends ChestMenu { human.closeInventory(); } } + + public class SaveHandler implements MenuOpeningHandler { + + BlockMenu menu; + MenuOpeningHandler handler; + + public SaveHandler(BlockMenu menu, MenuOpeningHandler handler) { + this.handler = handler; + this.menu = menu; + } + + @Override + public void onOpen(Player p) { + handler.onOpen(p); + menu.changes++; + } + + } } diff --git a/src/plugin.yml b/src/plugin.yml index c24fc8aa0..1654cfc0d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Slimefun -version: 4.1.3 +version: 4.1.5 authors: [mrCookieSlime, John000708, st392, DeathlyPanda, BlackBeltPanda] description: Slimefun basically turns your entire Server into a FTB modpack without installing a single mod website: http://TheBusyBiscuit.github.io/