diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index ca068eb00..87ab390da 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -1,13 +1,50 @@ -/* - * Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute - * and/or monetize any of our intellectual property. IntellectualCrafters is not - * affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. - * - * >> File = Main.java >> Generated by: Citymonstret at 2014-08-09 01:43 - */ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot; +import com.intellectualcrafters.plot.Logger.LogLevel; +import com.intellectualcrafters.plot.commands.Auto; +import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.database.*; +import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.generator.DefaultPlotManager; +import com.intellectualcrafters.plot.generator.DefaultPlotWorld; +import com.intellectualcrafters.plot.generator.WorldGenerator; +import com.intellectualcrafters.plot.listeners.*; +import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; +import com.intellectualcrafters.plot.uuid.UUIDSaver; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import me.confuser.barapi.BarAPI; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.*; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -15,62 +52,10 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; import java.util.concurrent.TimeUnit; -import me.confuser.barapi.BarAPI; -import net.milkbowl.vault.economy.Economy; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -import com.intellectualcrafters.plot.Logger.LogLevel; -import com.intellectualcrafters.plot.commands.Auto; -import com.intellectualcrafters.plot.commands.MainCommand; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.database.MySQL; -import com.intellectualcrafters.plot.database.PlotMeConverter; -import com.intellectualcrafters.plot.database.SQLManager; -import com.intellectualcrafters.plot.database.SQLite; -import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; -import com.intellectualcrafters.plot.events.PlotDeleteEvent; -import com.intellectualcrafters.plot.generator.DefaultPlotManager; -import com.intellectualcrafters.plot.generator.DefaultPlotWorld; -import com.intellectualcrafters.plot.generator.WorldGenerator; -import com.intellectualcrafters.plot.listeners.EntityListener; -import com.intellectualcrafters.plot.listeners.ForceFieldListener; -import com.intellectualcrafters.plot.listeners.PlayerEvents; -import com.intellectualcrafters.plot.listeners.PlotListener; -import com.intellectualcrafters.plot.listeners.PlotPlusListener; -import com.intellectualcrafters.plot.listeners.WorldEditListener; -import com.intellectualcrafters.plot.listeners.WorldGuardListener; -import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; -import com.intellectualcrafters.plot.uuid.UUIDSaver; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; - /** * PlotMain class. * @@ -315,7 +300,7 @@ public class PlotMain extends JavaPlugin { */ public static Set getPlots(final World world, final Player player) { final UUID uuid = player.getUniqueId(); - final ArrayList myplots = new ArrayList(); + final ArrayList myplots = new ArrayList<>(); for (final Plot plot : getPlots(world).values()) { if (plot.hasOwner()) { if (plot.getOwner().equals(uuid)) { @@ -323,14 +308,14 @@ public class PlotMain extends JavaPlugin { } } } - return new HashSet(myplots); + return new HashSet<>(myplots); } public static HashMap getPlots(final String world) { if (plots.containsKey(world)) { return plots.get(world); } - return new HashMap(); + return new HashMap<>(); } /** @@ -342,21 +327,23 @@ public class PlotMain extends JavaPlugin { if (plots.containsKey(world.getName())) { return plots.get(world.getName()); } - return new HashMap(); + return new HashMap<>(); } /** * get all plot worlds */ public static String[] getPlotWorlds() { - return (worlds.keySet().toArray(new String[0])); + Set strings = worlds.keySet(); + return (strings.toArray(new String[strings.size()])); } /** * @return plots worlds */ public static String[] getPlotWorldsString() { - return plots.keySet().toArray(new String[0]); + Set strings = plots.keySet(); + return strings.toArray(new String[strings.size()]); } /** @@ -390,8 +377,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world - * @return + * @param world world + * @return PlotManager */ public static PlotManager getPlotManager(final String world) { if (managers.containsKey(world)) { @@ -401,8 +388,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world - * @return + * @param world to search + * @return PlotWorld object */ public static PlotWorld getWorldSettings(final World world) { if (worlds.containsKey(world.getName())) { @@ -412,8 +399,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world - * @return + * @param world to search + * @return PlotWorld object */ public static PlotWorld getWorldSettings(final String world) { if (worlds.containsKey(world)) { @@ -423,11 +410,12 @@ public class PlotMain extends JavaPlugin { } /** - * @param world + * @param world world to search * @return set containing the plots for a world */ public static Plot[] getWorldPlots(final World world) { - return (plots.get(world.getName()).values().toArray(new Plot[0])); + Collection values = plots.get(world.getName()).values(); + return (values.toArray(new Plot[values.size()])); } public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) { @@ -492,7 +480,7 @@ public class PlotMain extends JavaPlugin { for (final String world : getPlotWorldsString()) { if (plots.containsKey(world)) { - final ArrayList toDeletePlot = new ArrayList(); + final ArrayList toDeletePlot = new ArrayList<>(); for (final Plot plot : plots.get(world).values()) { if (plot.owner == null) { @@ -915,7 +903,9 @@ public class PlotMain extends JavaPlugin { try { configFile = new File(getMain().getDataFolder() + File.separator + "config" + File.separator + "settings.yml"); if (!configFile.exists()) { - configFile.createNewFile(); + if (!configFile.createNewFile()) { + sendConsoleSenderMessage("Could not create the settings file, please create \"settings.yml\" manually."); + } } config = YamlConfiguration.loadConfiguration(configFile); setupConfig(); @@ -927,7 +917,9 @@ public class PlotMain extends JavaPlugin { try { storageFile = new File(getMain().getDataFolder() + File.separator + "config" + File.separator + "storage.yml"); if (!storageFile.exists()) { - storageFile.createNewFile(); + if (!storageFile.createNewFile()) { + sendConsoleSenderMessage("Could not the storage settings file, please create \"storage.yml\" manually."); + } } storage = YamlConfiguration.loadConfiguration(storageFile); setupStorage(); @@ -939,7 +931,9 @@ public class PlotMain extends JavaPlugin { try { translationsFile = new File(getMain().getDataFolder() + File.separator + "config" + File.separator + "translations.yml"); if (!translationsFile.exists()) { - translationsFile.createNewFile(); + if (!translationsFile.createNewFile()) { + sendConsoleSenderMessage("Could not create the translations file, please create \"translations.yml\" manually."); + } } translations = YamlConfiguration.loadConfiguration(translationsFile); setupTranslations(); @@ -1113,7 +1107,7 @@ public class PlotMain extends JavaPlugin { private static void setupConfig() { final int config_ver = 1; config.set("version", config_ver); - final Map options = new HashMap(); + final Map options = new HashMap<>(); options.put("auto_update", false); options.put("worldguard.enabled", Settings.WORLDGUARD); options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); @@ -1154,12 +1148,13 @@ public class PlotMain extends JavaPlugin { Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); } + @SuppressWarnings("unused") public static void createConfiguration(final PlotWorld plotworld) { - final Map options = new HashMap(); + final Map options = new HashMap<>(); for (final ConfigurationNode setting : plotworld.getSettingNodes()) { - setting.getConstant(); - setting.getValue(); + options.put(setting.getConstant(), setting.getValue()); + //TODO: Make jesse expalain wth was going on here } for (final Entry node : options.entrySet()) { @@ -1185,7 +1180,7 @@ public class PlotMain extends JavaPlugin { worlds = config.getConfigurationSection("worlds").getKeys(false); } else { - worlds = new HashSet(); + worlds = new HashSet<>(); } if ((generator != null) && (generator instanceof PlotGenerator)) { sendConsoleSenderMessage(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); @@ -1245,7 +1240,7 @@ public class PlotMain extends JavaPlugin { * use this method unless the required world is preconfigured in the * settings.yml * - * @param world + * @param world to load */ public static void loadWorld(final World world) { if (world == null) { @@ -1260,7 +1255,7 @@ public class PlotMain extends JavaPlugin { */ private static void setupStorage() { storage.set("version", storage_ver); - final Map options = new HashMap(); + final Map options = new HashMap<>(); options.put("mysql.use", true); options.put("sqlite.use", false); options.put("sqlite.db", "storage"); @@ -1562,8 +1557,9 @@ public class PlotMain extends JavaPlugin { PlotMain.plots = plots; } + @SuppressWarnings("unused") public static void setAllPlotsRaw(final HashMap> plots) { - PlotMain.plots = new LinkedHashMap>(); + PlotMain.plots = new LinkedHashMap<>(); PlotMain.plots.putAll(plots); } }