2014-11-08 20:46:49 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 /
////////////////////////////////////////////////////////////////////////////////////////////////////
2014-09-22 13:02:14 +02:00
package com.intellectualcrafters.plot ;
2014-10-29 17:18:17 +11:00
import com.intellectualcrafters.plot.commands.Auto ;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.commands.MainCommand ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.config.C ;
import com.intellectualcrafters.plot.config.ConfigurationNode ;
import com.intellectualcrafters.plot.config.Settings ;
2014-12-17 20:15:11 -06:00
import com.intellectualcrafters.plot.database.* ;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent ;
2014-09-23 12:08:31 +10:00
import com.intellectualcrafters.plot.events.PlotDeleteEvent ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.flag.AbstractFlag ;
import com.intellectualcrafters.plot.flag.FlagManager ;
2014-10-11 19:05:50 +11:00
import com.intellectualcrafters.plot.generator.DefaultPlotManager ;
import com.intellectualcrafters.plot.generator.DefaultPlotWorld ;
2014-10-10 18:31:51 +11:00
import com.intellectualcrafters.plot.generator.WorldGenerator ;
2014-12-17 20:15:11 -06:00
import com.intellectualcrafters.plot.listeners.* ;
import com.intellectualcrafters.plot.object.* ;
import com.intellectualcrafters.plot.util.* ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.util.Logger.LogLevel ;
2014-12-16 15:58:54 +11:00
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper ;
2014-10-13 21:22:19 +02:00
import com.intellectualcrafters.plot.uuid.PlotUUIDSaver ;
import com.intellectualcrafters.plot.uuid.UUIDSaver ;
2014-09-22 13:02:14 +02:00
import com.sk89q.worldedit.bukkit.WorldEditPlugin ;
2014-09-24 20:29:30 +02:00
import com.sk89q.worldguard.bukkit.WorldGuardPlugin ;
2014-12-17 20:15:11 -06:00
import me.confuser.barapi.BarAPI ;
import net.milkbowl.vault.economy.Economy ;
import org.bukkit.* ;
import org.bukkit.command.PluginCommand ;
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 ;
import java.sql.Connection ;
import java.sql.DatabaseMetaData ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.util.* ;
import java.util.Map.Entry ;
import java.util.concurrent.TimeUnit ;
2014-12-13 22:59:43 +11:00
2014-09-22 13:02:14 +02:00
/ * *
2014-10-28 01:57:14 +01:00
* PlotMain class .
2014-11-05 14:42:08 +11:00
*
2014-10-28 01:57:14 +01:00
* @author Citymonstret
* @author Empire92
2014-09-22 13:02:14 +02:00
* /
2014-12-17 20:15:11 -06:00
@SuppressWarnings ( " unused " ) public class PlotMain extends JavaPlugin {
2014-11-20 19:29:05 +01:00
/ * *
* Permission that allows for " everything "
* /
2014-12-17 20:15:11 -06:00
public static final String ADMIN_PERMISSION = " plots.admin " ;
2014-11-21 23:45:46 +01:00
/ * *
* Storage version
* /
2014-12-17 20:15:11 -06:00
public final static int storage_ver = 1 ;
2014-11-21 23:45:46 +01:00
/ * *
* Boolean Flags ( material )
* /
2014-12-17 20:15:11 -06:00
public final static HashMap < Material , String > booleanFlags = new HashMap < > ( ) ;
2014-11-21 23:45:46 +01:00
/ * *
* Initialize the material flags
* /
static {
booleanFlags . put ( Material . WOODEN_DOOR , " wooden_door " ) ;
booleanFlags . put ( Material . IRON_DOOR , " iron_door " ) ;
booleanFlags . put ( Material . STONE_BUTTON , " stone_button " ) ;
booleanFlags . put ( Material . WOOD_BUTTON , " wooden_button " ) ;
booleanFlags . put ( Material . LEVER , " lever " ) ;
booleanFlags . put ( Material . WOOD_PLATE , " wooden_plate " ) ;
booleanFlags . put ( Material . STONE_PLATE , " stone_plate " ) ;
booleanFlags . put ( Material . CHEST , " chest " ) ;
booleanFlags . put ( Material . TRAPPED_CHEST , " trapped_chest " ) ;
booleanFlags . put ( Material . TRAP_DOOR , " trap_door " ) ;
booleanFlags . put ( Material . DISPENSER , " dispenser " ) ;
booleanFlags . put ( Material . DROPPER , " dropper " ) ;
}
/ * *
* All loaded plot worlds
* /
2014-12-17 20:15:11 -06:00
private final static HashMap < String , PlotWorld > worlds = new HashMap < > ( ) ;
2014-11-21 23:45:46 +01:00
/ * *
* All world managers
* /
2014-12-17 20:15:11 -06:00
private final static HashMap < String , PlotManager > managers = new HashMap < > ( ) ;
2014-11-05 14:42:08 +11:00
/ * *
* settings . properties
* /
2014-12-17 20:15:11 -06:00
public static File configFile ;
2014-10-27 16:27:17 +01:00
/ * *
* The main configuration file
* /
2014-12-17 20:15:11 -06:00
public static YamlConfiguration config ;
2014-10-28 01:57:14 +01:00
/ * *
2014-11-05 14:42:08 +11:00
* storage . properties
* /
2014-12-17 20:15:11 -06:00
public static File storageFile ;
2014-10-27 16:27:17 +01:00
/ * *
* Contains storage options
* /
2014-12-17 20:15:11 -06:00
public static YamlConfiguration storage ;
2014-11-05 14:42:08 +11:00
/ * *
* MySQL Connection
* /
2014-12-17 20:15:11 -06:00
public static Connection connection ;
2014-11-05 14:42:08 +11:00
/ * *
* WorldEdit object
* /
2014-12-17 20:15:11 -06:00
public static WorldEditPlugin worldEdit = null ;
2014-11-05 14:42:08 +11:00
/ * *
* BarAPI object
* /
2014-12-17 20:15:11 -06:00
public static BarAPI barAPI = null ;
2014-11-16 10:16:38 +01:00
/ * *
* World Guard Object
* /
2014-12-17 20:15:11 -06:00
public static WorldGuardPlugin worldGuard = null ;
2014-11-09 12:29:35 +01:00
/ * *
2014-11-16 10:16:38 +01:00
* World Guard Listener
2014-11-09 12:29:35 +01:00
* /
2014-12-17 20:15:11 -06:00
public static WorldGuardListener worldGuardListener = null ;
2014-11-16 10:16:38 +01:00
/ * *
* Economy Object ( vault )
* /
2014-12-17 20:15:11 -06:00
public static Economy economy ;
2014-11-16 10:16:38 +01:00
/ * *
* Use Economy ?
* /
2014-12-17 20:15:11 -06:00
public static boolean useEconomy = false ;
2014-12-19 01:42:47 +01:00
private static PlotMain main = null ;
2014-11-05 14:42:08 +11:00
/ * *
2014-11-09 12:29:35 +01:00
* The UUID Saver
2014-11-05 14:42:08 +11:00
* /
2014-12-17 20:15:11 -06:00
private static UUIDSaver uuidSaver ;
2014-11-09 12:29:35 +01:00
/ * *
* MySQL Object
* /
2014-12-17 20:15:11 -06:00
private static MySQL mySQL ;
2014-11-09 12:29:35 +01:00
/ * *
2014-12-17 20:15:11 -06:00
* List of all plots DO NOT USE EXCEPT FOR DATABASE PURPOSES
2014-11-09 12:29:35 +01:00
* /
private static LinkedHashMap < String , HashMap < PlotId , Plot > > plots ;
2014-11-05 14:42:08 +11:00
2014-12-14 12:34:44 +11:00
/ * *
* Return an instance of MySQL
* /
public static MySQL getMySQL ( ) {
return mySQL ;
}
2014-12-16 16:03:20 +11:00
2014-11-16 10:16:38 +01:00
/ * *
* Check for expired plots
* /
2014-11-05 14:42:08 +11:00
public static void checkForExpiredPlots ( ) {
final JavaPlugin plugin = PlotMain . getMain ( ) ;
Bukkit . getScheduler ( ) . scheduleSyncRepeatingTask ( plugin , new Runnable ( ) {
@Override
public void run ( ) {
2014-11-09 12:29:35 +01:00
try {
checkExpired ( plugin , true ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
e . printStackTrace ( ) ;
}
2014-11-05 14:42:08 +11:00
}
2014-11-20 19:29:05 +01:00
} , 0l , 86_40_00L ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
2014-12-17 20:15:11 -06:00
* Check a range of permissions e . g . ' plots . plot . < 0 - 100 > ' < br > Returns highest integer in range .
*
* @param player to check
* @param stub to check
* @param range tp check
2014-11-05 14:42:08 +11:00
*
* @return permitted range
* /
public static int hasPermissionRange ( final Player player , final String stub , final int range ) {
2014-11-09 12:29:35 +01:00
if ( ( player = = null ) | | player . isOp ( ) | | player . hasPermission ( ADMIN_PERMISSION ) ) {
return Byte . MAX_VALUE ;
2014-10-28 13:34:22 +11:00
}
if ( player . hasPermission ( stub + " .* " ) ) {
2014-11-09 12:29:35 +01:00
return Byte . MAX_VALUE ;
2014-10-28 13:34:22 +11:00
}
2014-11-05 14:42:08 +11:00
for ( int i = range ; i > 0 ; i - - ) {
if ( player . hasPermission ( stub + " . " + i ) ) {
return i ;
}
}
return 0 ;
}
/ * *
2014-12-17 20:15:11 -06:00
* Check a player for a permission < br > - Op has all permissions < br > - checks for '*' nodes
*
* @param player to check
* @param perms to check
2014-11-05 14:42:08 +11:00
*
* @return true of player has permissions
* /
public static boolean hasPermissions ( final Player player , final String [ ] perms ) {
// Assumes null player is console.
2014-11-09 12:29:35 +01:00
if ( ( player = = null ) | | player . isOp ( ) | | player . hasPermission ( ADMIN_PERMISSION ) ) {
2014-11-05 14:42:08 +11:00
return true ;
}
for ( final String perm : perms ) {
2014-11-09 12:29:35 +01:00
boolean permitted = false ;
2014-12-16 16:03:20 +11:00
if ( player . hasPermission ( perm ) ) {
2014-11-09 12:29:35 +01:00
permitted = true ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
final String [ ] nodes = perm . split ( " \\ . " ) ;
final StringBuilder n = new StringBuilder ( ) ;
for ( int i = 0 ; i < ( nodes . length - 1 ) ; i + + ) {
n . append ( nodes [ i ] ) . append ( " . " ) ;
if ( player . hasPermission ( n + " * " ) ) {
2014-11-09 12:29:35 +01:00
permitted = true ;
2014-11-05 14:42:08 +11:00
break ;
}
}
}
2014-11-09 12:29:35 +01:00
if ( ! permitted ) {
2014-11-05 14:42:08 +11:00
return false ;
}
}
return true ;
}
2014-11-09 12:29:35 +01:00
/ * *
* Get the uuid saver
2014-11-21 23:45:46 +01:00
*
2014-11-09 12:29:35 +01:00
* @return uuid saver
2014-12-17 20:15:11 -06:00
*
2014-11-09 12:29:35 +01:00
* @see com . intellectualcrafters . plot . uuid . UUIDSaver ;
* /
2014-10-13 21:22:19 +02:00
public static UUIDSaver getUUIDSaver ( ) {
return uuidSaver ;
}
2014-11-09 12:29:35 +01:00
/ * *
* Set the uuid saver
*
2014-12-17 20:15:11 -06:00
* @param saver new saver
*
2014-11-20 19:29:05 +01:00
* @see com . intellectualcrafters . plot . uuid . UUIDSaver
2014-11-09 12:29:35 +01:00
* /
public static void setUUIDSaver ( final UUIDSaver saver ) {
uuidSaver = saver ;
}
2014-11-05 14:42:08 +11:00
/ * *
2014-12-17 20:15:11 -06:00
* Check a player for a permission < br > - Op has all permissions < br > - checks for '*' nodes
*
* @param player to check
* @param perm to check
2014-11-05 14:42:08 +11:00
*
* @return true if player has the permission
* /
public static boolean hasPermission ( final Player player , final String perm ) {
if ( ( player = = null ) | | player . isOp ( ) ) {
return true ;
}
if ( player . hasPermission ( perm ) ) {
return true ;
}
final String [ ] nodes = perm . split ( " \\ . " ) ;
final StringBuilder n = new StringBuilder ( ) ;
for ( int i = 0 ; i < ( nodes . length - 1 ) ; i + + ) {
n . append ( nodes [ i ] ) . append ( " . " ) ;
if ( player . hasPermission ( n + " * " ) ) {
return true ;
}
}
return false ;
}
/ * *
* Get all plots
*
* @return HashMap containing the plot ID and the plot object .
* /
2014-11-02 21:14:47 +01:00
public static Set < Plot > getPlots ( ) {
2014-11-09 12:29:35 +01:00
final ArrayList < Plot > _plots = new ArrayList < > ( ) ;
2014-11-05 14:42:08 +11:00
for ( final HashMap < PlotId , Plot > world : plots . values ( ) ) {
2014-11-09 12:29:35 +01:00
_plots . addAll ( world . values ( ) ) ;
2014-11-02 21:14:47 +01:00
}
2014-11-09 12:29:35 +01:00
return new LinkedHashSet < > ( _plots ) ;
2014-11-02 21:14:47 +01:00
}
2014-11-09 12:29:35 +01:00
/ * *
* Get a sorted list of plots
2014-11-21 23:45:46 +01:00
*
2014-11-09 12:29:35 +01:00
* @return sorted list
* /
2014-11-05 14:42:08 +11:00
public static LinkedHashSet < Plot > getPlotsSorted ( ) {
2014-11-09 12:29:35 +01:00
final ArrayList < Plot > _plots = new ArrayList < > ( ) ;
2014-11-05 14:42:08 +11:00
for ( final HashMap < PlotId , Plot > world : plots . values ( ) ) {
2014-11-09 12:29:35 +01:00
_plots . addAll ( world . values ( ) ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
return new LinkedHashSet < > ( _plots ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
2014-12-17 20:15:11 -06:00
* @param player player
*
2014-11-05 14:42:08 +11:00
* @return Set Containing the players plots
* /
public static Set < Plot > getPlots ( final Player player ) {
2014-12-13 22:59:43 +11:00
final UUID uuid = UUIDHandler . getUUID ( player ) ;
2014-11-05 14:42:08 +11:00
final ArrayList < Plot > myplots = new ArrayList < > ( ) ;
for ( final HashMap < PlotId , Plot > world : plots . values ( ) ) {
for ( final Plot plot : world . values ( ) ) {
if ( plot . hasOwner ( ) ) {
if ( plot . getOwner ( ) . equals ( uuid ) ) {
myplots . add ( plot ) ;
}
}
}
}
return new HashSet < > ( myplots ) ;
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world plot world
* @param player plot owner
*
2014-11-05 14:42:08 +11:00
* @return players plots
* /
public static Set < Plot > getPlots ( final World world , final Player player ) {
2014-12-13 22:59:43 +11:00
final UUID uuid = UUIDHandler . getUUID ( player ) ;
2014-11-08 20:46:49 +01:00
final ArrayList < Plot > myplots = new ArrayList < > ( ) ;
2014-11-05 14:42:08 +11:00
for ( final Plot plot : getPlots ( world ) . values ( ) ) {
if ( plot . hasOwner ( ) ) {
if ( plot . getOwner ( ) . equals ( uuid ) ) {
myplots . add ( plot ) ;
}
}
}
2014-11-08 20:46:49 +01:00
return new HashSet < > ( myplots ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-20 19:29:05 +01:00
/ * *
* Get plots for the specified world
*
2014-12-17 20:15:11 -06:00
* @param world A world , in which you want to search for plots
*
2014-11-20 19:29:05 +01:00
* @return HashMap containing Plot IDs and Plot Objects
* /
2014-11-05 14:42:08 +11:00
public static HashMap < PlotId , Plot > getPlots ( final String world ) {
2014-10-19 19:26:37 +11:00
if ( plots . containsKey ( world ) ) {
return plots . get ( world ) ;
}
2014-11-08 20:46:49 +01:00
return new HashMap < > ( ) ;
2014-10-19 19:26:37 +11:00
}
2014-10-11 00:33:10 -07:00
2014-11-05 14:42:08 +11:00
/ * *
2014-12-17 20:15:11 -06:00
* @param world plot world
*
2014-11-05 14:42:08 +11:00
* @return plots in world
* /
public static HashMap < PlotId , Plot > getPlots ( final World world ) {
if ( plots . containsKey ( world . getName ( ) ) ) {
return plots . get ( world . getName ( ) ) ;
}
2014-11-08 20:46:49 +01:00
return new HashMap < > ( ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
* get all plot worlds
* /
public static String [ ] getPlotWorlds ( ) {
2014-12-16 16:03:20 +11:00
final Set < String > strings = worlds . keySet ( ) ;
2014-11-08 20:46:49 +01:00
return ( strings . toArray ( new String [ strings . size ( ) ] ) ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
* @return plots worlds
* /
public static String [ ] getPlotWorldsString ( ) {
2014-12-16 16:03:20 +11:00
final Set < String > strings = plots . keySet ( ) ;
2014-11-08 20:46:49 +01:00
return strings . toArray ( new String [ strings . size ( ) ] ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world plotworld ( ? )
*
2014-10-28 01:57:14 +01:00
* @return true if the world is a plotworld
2014-10-19 19:26:37 +11:00
* /
2014-11-05 14:42:08 +11:00
public static boolean isPlotWorld ( final World world ) {
2014-10-19 19:26:37 +11:00
return ( worlds . containsKey ( world . getName ( ) ) ) ;
}
2014-11-05 14:42:08 +11:00
2014-10-19 19:26:37 +11:00
/ * *
2014-12-17 20:15:11 -06:00
* @param world plotworld ( ? )
*
2014-10-28 01:57:14 +01:00
* @return true if the world is a plotworld
2014-10-19 19:26:37 +11:00
* /
2014-11-05 14:42:08 +11:00
public static boolean isPlotWorld ( final String world ) {
2014-10-19 19:26:37 +11:00
return ( worlds . containsKey ( world ) ) ;
}
2014-10-11 00:33:10 -07:00
2014-11-05 14:42:08 +11:00
/ * *
2014-12-17 20:15:11 -06:00
* @param world World to get manager for
*
2014-11-05 14:42:08 +11:00
* @return manager for world
* /
public static PlotManager getPlotManager ( final World world ) {
if ( managers . containsKey ( world . getName ( ) ) ) {
return managers . get ( world . getName ( ) ) ;
}
return null ;
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world world
*
2014-11-08 20:46:49 +01:00
* @return PlotManager
2014-11-05 14:42:08 +11:00
* /
public static PlotManager getPlotManager ( final String world ) {
if ( managers . containsKey ( world ) ) {
return managers . get ( world ) ;
}
return null ;
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world to search
*
2014-11-08 20:46:49 +01:00
* @return PlotWorld object
2014-11-05 14:42:08 +11:00
* /
public static PlotWorld getWorldSettings ( final World world ) {
if ( worlds . containsKey ( world . getName ( ) ) ) {
return worlds . get ( world . getName ( ) ) ;
}
return null ;
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world to search
*
2014-11-08 20:46:49 +01:00
* @return PlotWorld object
2014-11-05 14:42:08 +11:00
* /
public static PlotWorld getWorldSettings ( final String world ) {
if ( worlds . containsKey ( world ) ) {
return worlds . get ( world ) ;
}
return null ;
}
/ * *
2014-12-17 20:15:11 -06:00
* @param world world to search
*
2014-11-05 14:42:08 +11:00
* @return set containing the plots for a world
* /
public static Plot [ ] getWorldPlots ( final World world ) {
2014-12-16 16:03:20 +11:00
final Collection < Plot > values = plots . get ( world . getName ( ) ) . values ( ) ;
2014-11-08 20:46:49 +01:00
return ( values . toArray ( new Plot [ values . size ( ) ] ) ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-20 19:29:05 +01:00
/ * *
* Remove a plot
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param world The Plot World
* @param id The Plot ID
* @param callEvent Whether or not to call the PlotDeleteEvent
*
2014-11-20 19:29:05 +01:00
* @return true if successful , false if not
* /
2014-11-05 14:42:08 +11:00
public static boolean removePlot ( final String world , final PlotId id , final boolean callEvent ) {
if ( callEvent ) {
final PlotDeleteEvent event = new PlotDeleteEvent ( world , id ) ;
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
if ( event . isCancelled ( ) ) {
event . setCancelled ( true ) ;
return false ;
}
}
plots . get ( world ) . remove ( id ) ;
return true ;
}
/ * *
* Replace the plot object with an updated version
*
2014-12-17 20:15:11 -06:00
* @param plot plot object
2014-11-05 14:42:08 +11:00
* /
public static void updatePlot ( final Plot plot ) {
final String world = plot . world ;
if ( ! plots . containsKey ( world ) ) {
plots . put ( world , new HashMap < PlotId , Plot > ( ) ) ;
}
plot . hasChanged = true ;
plots . get ( world ) . put ( plot . id , plot ) ;
}
/ * *
2014-12-17 20:15:11 -06:00
* TODO : < b > Implement better system The whole point of this system is to recycle old plots < / b > < br > So why not just
* allow users to claim old plots , and try to hide the fact that the are owned . < br > < br > Reduce amount of expired
* plots : < br > - On / plot < br > auto < br > - allow claiming of old plot , clear it so the user doesn ' t know < br > - On
* / plot info , < br > - show that the plot is expired and allowed to be claimed Have the task run less often : < br > - Run
* the task when there are very little , or no players online ( great for small servers ) < br > - Run the task at startup
* ( also only useful for small servers ) < br > Also , in terms of faster code : < br > - Have an array of plots , sorted by
* expiry time . < br > - Add new plots to the end . < br > - The task then only needs to go through the first few plots
2014-11-05 14:42:08 +11:00
*
2014-12-17 20:15:11 -06:00
* @param plugin Plugin
* @param async Call async ?
2014-11-05 14:42:08 +11:00
* /
private static void checkExpired ( final JavaPlugin plugin , final boolean async ) {
if ( async ) {
Bukkit . getScheduler ( ) . runTaskAsynchronously ( plugin , new Runnable ( ) {
@Override
public void run ( ) {
for ( final String world : getPlotWorldsString ( ) ) {
if ( plots . containsKey ( world ) ) {
2014-11-08 20:46:49 +01:00
final ArrayList < Plot > toDeletePlot = new ArrayList < > ( ) ;
2014-11-05 14:42:08 +11:00
for ( final Plot plot : plots . get ( world ) . values ( ) ) {
if ( plot . owner = = null ) {
continue ;
}
final long lastPlayed = getLastPlayed ( plot . owner ) ;
if ( lastPlayed = = 0 ) {
continue ;
}
final long compared = System . currentTimeMillis ( ) - lastPlayed ;
if ( TimeUnit . MILLISECONDS . toDays ( compared ) > = Settings . AUTO_CLEAR_DAYS ) {
final PlotDeleteEvent event = new PlotDeleteEvent ( world , plot . id ) ;
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
if ( event . isCancelled ( ) ) {
event . setCancelled ( true ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
toDeletePlot . add ( plot ) ;
}
}
}
for ( final Plot plot : toDeletePlot ) {
final World worldobj = Bukkit . getWorld ( world ) ;
2014-12-16 15:44:25 +11:00
PlotHelper . clear ( worldobj , plot , true ) ;
2014-11-05 14:42:08 +11:00
PlotHelper . removeSign ( worldobj , plot ) ;
2014-10-21 08:18:30 +02:00
DBFunc . delete ( world , plot ) ;
2014-10-22 10:04:44 +11:00
removePlot ( world , plot . id , true ) ;
2014-11-05 14:42:08 +11:00
if ( ( Math . abs ( plot . id . x ) < Math . abs ( Auto . lastPlot . x ) ) & & ( Math . abs ( plot . id . y ) < Math . abs ( Auto . lastPlot . y ) ) ) {
2014-10-29 17:18:17 +11:00
Auto . lastPlot = plot . id ;
}
2014-10-21 08:18:30 +02:00
}
2014-11-05 14:42:08 +11:00
}
}
}
} ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
for ( final String world : getPlotWorldsString ( ) ) {
if ( PlotMain . plots . containsKey ( world ) ) {
for ( final Plot plot : PlotMain . plots . get ( world ) . values ( ) ) {
if ( PlayerFunctions . hasExpired ( plot ) ) {
final PlotDeleteEvent event = new PlotDeleteEvent ( world , plot . id ) ;
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
if ( event . isCancelled ( ) ) {
event . setCancelled ( true ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
DBFunc . delete ( world , plot ) ;
}
}
}
}
}
}
}
2014-11-20 19:29:05 +01:00
/ * *
* Get the java version
*
* @return Java Version as a double
* /
public static double getJavaVersion ( ) {
2014-11-09 12:29:35 +01:00
return Double . parseDouble ( System . getProperty ( " java.specification.version " ) ) ;
}
2014-11-05 14:42:08 +11:00
2014-11-09 12:29:35 +01:00
/ * *
* Get MySQL Connection
*
* @return connection MySQL Connection .
* /
public static Connection getConnection ( ) {
return connection ;
}
/ * *
* Send a message to the console .
*
2014-12-17 20:15:11 -06:00
* @param string message
2014-11-09 12:29:35 +01:00
* /
public static void sendConsoleSenderMessage ( final String string ) {
if ( getMain ( ) . getServer ( ) . getConsoleSender ( ) = = null ) {
System . out . println ( ChatColor . stripColor ( ConsoleColors . fromString ( string ) ) ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-09 12:29:35 +01:00
getMain ( ) . getServer ( ) . getConsoleSender ( ) . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , string ) ) ;
}
}
/ * *
2014-11-20 19:29:05 +01:00
* Teleport a player to a plot
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param player Player to teleport
* @param from Previous Location
* @param plot Plot to teleport to
*
2014-11-20 19:29:05 +01:00
* @return true if successful
2014-11-09 12:29:35 +01:00
* /
public static boolean teleportPlayer ( final Player player , final Location from , final Plot plot ) {
final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent ( player , from , plot ) ;
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
if ( ! event . isCancelled ( ) ) {
final Location location = PlotHelper . getPlotHome ( Bukkit . getWorld ( plot . world ) , plot ) ;
if ( ( location . getBlockX ( ) > = 29999999 ) | | ( location . getBlockX ( ) < = - 29999999 ) | | ( location . getBlockZ ( ) > = 299999999 ) | | ( location . getBlockZ ( ) < = - 29999999 ) ) {
event . setCancelled ( true ) ;
return false ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
player . teleport ( location ) ;
PlayerFunctions . sendMessage ( player , C . TELEPORTED_TO_PLOT ) ;
2014-11-05 14:42:08 +11:00
}
2014-12-19 01:42:47 +01:00
return ! event . isCancelled ( ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
/ * *
* Send a message to the console
*
2014-12-17 20:15:11 -06:00
* @param c message
2014-11-09 12:29:35 +01:00
* /
@SuppressWarnings ( " unused " )
public static void sendConsoleSenderMessage ( final C c ) {
sendConsoleSenderMessage ( c . s ( ) ) ;
2014-11-05 14:42:08 +11:00
}
/ * *
2014-11-09 12:29:35 +01:00
* Broadcast publicly
*
2014-12-17 20:15:11 -06:00
* @param c message
2014-11-05 14:42:08 +11:00
* /
2014-11-09 12:29:35 +01:00
public static void Broadcast ( final C c ) {
Bukkit . broadcastMessage ( ChatColor . translateAlternateColorCodes ( '&' , C . PREFIX . s ( ) + c . s ( ) ) ) ;
}
2014-10-11 00:33:10 -07:00
2014-11-09 12:29:35 +01:00
/ * *
* Returns the main class .
*
* @return ( this class )
* /
public static PlotMain getMain ( ) {
2014-12-14 00:30:29 +11:00
return PlotMain . main ;
2014-11-09 12:29:35 +01:00
}
2014-10-11 00:33:10 -07:00
2014-11-09 12:29:35 +01:00
/ * *
* Broadcast a message to all admins
*
2014-12-17 20:15:11 -06:00
* @param c message
2014-11-09 12:29:35 +01:00
* /
public static void BroadcastWithPerms ( final C c ) {
for ( final Player player : Bukkit . getOnlinePlayers ( ) ) {
if ( player . hasPermission ( ADMIN_PERMISSION ) ) {
PlayerFunctions . sendMessage ( player , c ) ;
2014-11-05 14:42:08 +11:00
}
}
2014-11-09 12:29:35 +01:00
System . out . println ( ChatColor . stripColor ( ChatColor . translateAlternateColorCodes ( '&' , C . PREFIX . s ( ) + c . s ( ) ) ) ) ;
}
2014-10-11 00:33:10 -07:00
2014-11-20 19:29:05 +01:00
/ * *
* Reload all translations
2014-11-21 23:45:46 +01:00
*
2014-11-20 19:29:05 +01:00
* @throws IOException
* /
2014-11-09 12:29:35 +01:00
public static void reloadTranslations ( ) throws IOException {
C . setupTranslations ( ) ;
}
2014-11-20 19:29:05 +01:00
/ * *
* Ge the last played time
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param uuid UUID for the player
*
2014-11-20 19:29:05 +01:00
* @return last play time as a long
* /
2014-11-09 12:29:35 +01:00
public static long getLastPlayed ( final UUID uuid ) {
if ( uuid = = null ) {
return 0 ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
OfflinePlayer player ;
2014-12-14 00:30:29 +11:00
if ( ( ( player = UUIDHandler . uuidWrapper . getOfflinePlayer ( uuid ) ) = = null ) | | ! player . hasPlayedBefore ( ) ) {
2014-11-09 12:29:35 +01:00
return 0 ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
return player . getLastPlayed ( ) ;
}
2014-10-14 16:16:05 +02:00
2014-11-09 12:29:35 +01:00
/ * *
* Load configuration files
* /
@SuppressWarnings ( " deprecation " )
public static void configs ( ) {
final File folder = new File ( getMain ( ) . getDataFolder ( ) + File . separator + " config " ) ;
if ( ! folder . exists ( ) & & ! folder . mkdirs ( ) ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cFailed to create the /plugins/config folder. Please create it manually. " ) ;
}
try {
configFile = new File ( getMain ( ) . getDataFolder ( ) + File . separator + " config " + File . separator + " settings.yml " ) ;
if ( ! configFile . exists ( ) ) {
if ( ! configFile . createNewFile ( ) ) {
sendConsoleSenderMessage ( " Could not create the settings file, please create \" settings.yml \" manually. " ) ;
}
2014-11-05 14:42:08 +11:00
}
config = YamlConfiguration . loadConfiguration ( configFile ) ;
setupConfig ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception err_trans ) {
2014-11-05 14:42:08 +11:00
Logger . add ( LogLevel . DANGER , " Failed to save settings.yml " ) ;
System . out . println ( " Failed to save settings.yml " ) ;
}
try {
storageFile = new File ( getMain ( ) . getDataFolder ( ) + File . separator + " config " + File . separator + " storage.yml " ) ;
if ( ! storageFile . exists ( ) ) {
2014-11-08 20:46:49 +01:00
if ( ! storageFile . createNewFile ( ) ) {
sendConsoleSenderMessage ( " Could not the storage settings file, please create \" storage.yml \" manually. " ) ;
}
2014-11-05 14:42:08 +11:00
}
storage = YamlConfiguration . loadConfiguration ( storageFile ) ;
setupStorage ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception err_trans ) {
2014-11-05 14:42:08 +11:00
Logger . add ( LogLevel . DANGER , " Failed to save storage.yml " ) ;
System . out . println ( " Failed to save storage.yml " ) ;
}
try {
config . save ( configFile ) ;
storage . save ( storageFile ) ;
2014-12-17 20:15:11 -06:00
} catch ( final IOException e ) {
2014-11-05 14:42:08 +11:00
Logger . add ( LogLevel . DANGER , " Configuration file saving failed " ) ;
e . printStackTrace ( ) ;
}
{
Settings . DB . USE_MYSQL = storage . getBoolean ( " mysql.use " ) ;
Settings . DB . USER = storage . getString ( " mysql.user " ) ;
Settings . DB . PASSWORD = storage . getString ( " mysql.password " ) ;
Settings . DB . HOST_NAME = storage . getString ( " mysql.host " ) ;
Settings . DB . PORT = storage . getString ( " mysql.port " ) ;
Settings . DB . DATABASE = storage . getString ( " mysql.database " ) ;
Settings . DB . USE_SQLITE = storage . getBoolean ( " sqlite.use " ) ;
Settings . DB . SQLITE_DB = storage . getString ( " sqlite.db " ) ;
2014-10-27 15:32:15 +01:00
Settings . DB . PREFIX = storage . getString ( " prefix " ) ;
2014-11-05 14:42:08 +11:00
Settings . METRICS = config . getBoolean ( " metrics " ) ;
Settings . AUTO_CLEAR = config . getBoolean ( " clear.auto.enabled " ) ;
Settings . AUTO_CLEAR_DAYS = config . getInt ( " clear.auto.days " ) ;
2014-10-21 18:53:52 +02:00
Settings . DELETE_PLOTS_ON_BAN = config . getBoolean ( " clear.on.ban " ) ;
2014-10-27 20:05:01 +01:00
Settings . API_URL = config . getString ( " api.location " ) ;
2014-10-27 22:00:24 +01:00
Settings . CUSTOM_API = config . getBoolean ( " api.custom " ) ;
2014-11-05 14:42:08 +11:00
}
if ( Settings . DEBUG ) {
final Map < String , String > settings = new HashMap < > ( ) ;
settings . put ( " Kill Road Mobs " , " " + Settings . KILL_ROAD_MOBS ) ;
settings . put ( " Use Metrics " , " " + Settings . METRICS ) ;
2014-10-21 18:53:52 +02:00
settings . put ( " Delete Plots On Ban " , " " + Settings . DELETE_PLOTS_ON_BAN ) ;
2014-11-05 14:42:08 +11:00
settings . put ( " Mob Pathfinding " , " " + Settings . MOB_PATHFINDING ) ;
settings . put ( " DB Mysql Enabled " , " " + Settings . DB . USE_MYSQL ) ;
settings . put ( " DB SQLite Enabled " , " " + Settings . DB . USE_SQLITE ) ;
settings . put ( " Auto Clear Enabled " , " " + Settings . AUTO_CLEAR ) ;
settings . put ( " Auto Clear Days " , " " + Settings . AUTO_CLEAR_DAYS ) ;
2014-10-25 15:02:38 +02:00
settings . put ( " Schematics Save Path " , " " + Settings . SCHEMATIC_SAVE_PATH ) ;
2014-10-27 20:05:01 +01:00
settings . put ( " API Location " , " " + Settings . API_URL ) ;
2014-11-05 14:42:08 +11:00
for ( final Entry < String , String > setting : settings . entrySet ( ) ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + String . format ( " &cKey: &6%s&c, Value: &6%s " , setting . getKey ( ) , setting . getValue ( ) ) ) ;
}
}
}
/ * *
* Kill all entities on roads
* /
@SuppressWarnings ( " deprecation " )
public static void killAllEntities ( ) {
Bukkit . getScheduler ( ) . scheduleSyncRepeatingTask ( getMain ( ) , new Runnable ( ) {
2014-11-01 16:13:44 +01:00
long ticked = 0l ;
2014-12-17 20:15:11 -06:00
long error = 0l ;
2014-11-01 16:13:44 +01:00
{
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " KillAllEntities started. " ) ;
}
@Override
public void run ( ) {
2014-11-09 12:29:35 +01:00
if ( this . ticked > 36_000L ) {
2014-11-01 16:13:44 +01:00
this . ticked = 0l ;
2014-11-05 14:42:08 +11:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " KillAllEntities has been running for 60 minutes. Errors: " + this . error ) ;
2014-11-01 16:13:44 +01:00
this . error = 0l ;
}
2014-12-19 01:42:47 +01:00
World world ;
2014-11-05 14:42:08 +11:00
for ( final String w : getPlotWorlds ( ) ) {
2014-11-01 16:13:44 +01:00
getWorldSettings ( w ) ;
2014-12-19 01:42:47 +01:00
world = Bukkit . getServer ( ) . getWorld ( w ) ;
2014-11-01 16:13:44 +01:00
try {
if ( world . getLoadedChunks ( ) . length < 1 ) {
continue ;
}
2014-11-05 14:42:08 +11:00
for ( final Chunk chunk : world . getLoadedChunks ( ) ) {
final Entity [ ] entities = chunk . getEntities ( ) ;
2014-12-19 01:42:47 +01:00
Entity entity ;
2014-11-01 16:13:44 +01:00
for ( int i = entities . length - 1 ; i > = 0 ; i - - ) {
2014-12-19 01:42:47 +01:00
if ( ! ( ( entity = entities [ i ] ) instanceof Player ) & & ! PlotListener . isInPlot ( entity . getLocation ( ) ) ) {
entity . remove ( ) ;
2014-11-01 16:13:44 +01:00
}
}
}
2014-12-17 20:15:11 -06:00
} catch ( final Throwable e ) {
2014-11-01 16:13:44 +01:00
+ + this . error ;
2014-12-17 20:15:11 -06:00
} finally {
2014-11-01 16:13:44 +01:00
+ + this . ticked ;
}
}
}
} , 2L , 2L ) ;
2014-11-05 14:42:08 +11:00
}
2014-10-11 00:33:10 -07:00
2014-11-05 14:42:08 +11:00
/ * *
* SETUP : settings . yml
* /
private static void setupConfig ( ) {
final int config_ver = 1 ;
2014-10-28 01:57:14 +01:00
config . set ( " version " , config_ver ) ;
2014-11-08 20:46:49 +01:00
final Map < String , Object > options = new HashMap < > ( ) ;
2014-11-05 14:42:08 +11:00
options . put ( " auto_update " , false ) ;
2014-12-15 12:04:13 +11:00
options . put ( " claim.max-auto-area " , Settings . MAX_AUTO_SIZE ) ;
2014-12-13 22:59:43 +11:00
options . put ( " UUID.offline " , Settings . OFFLINE_MODE ) ;
2014-11-05 14:42:08 +11:00
options . put ( " worldguard.enabled " , Settings . WORLDGUARD ) ;
options . put ( " kill_road_mobs " , Settings . KILL_ROAD_MOBS_DEFAULT ) ;
options . put ( " mob_pathfinding " , Settings . MOB_PATHFINDING_DEFAULT ) ;
options . put ( " metrics " , true ) ;
options . put ( " debug " , true ) ;
options . put ( " clear.auto.enabled " , false ) ;
options . put ( " clear.auto.days " , 365 ) ;
2014-10-21 18:53:52 +02:00
options . put ( " clear.on.ban " , false ) ;
2014-10-26 12:25:40 +11:00
options . put ( " max_plots " , Settings . MAX_PLOTS ) ;
options . put ( " schematics.save_path " , Settings . SCHEMATIC_SAVE_PATH ) ;
2014-10-27 20:05:01 +01:00
options . put ( " api.location " , Settings . API_URL ) ;
2014-10-27 22:00:24 +01:00
options . put ( " api.custom " , Settings . CUSTOM_API ) ;
2014-11-01 09:29:08 +11:00
options . put ( " titles " , Settings . TITLES ) ;
2014-11-20 19:29:05 +01:00
options . put ( " teleport.on_login " , Settings . TELEPORT_ON_LOGIN ) ;
2014-11-08 21:35:49 +11:00
options . put ( " perm-based-mob-cap.enabled " , Settings . MOB_CAP_ENABLED ) ;
options . put ( " perm-based-mob-cap.max " , Settings . MOB_CAP ) ;
2014-12-16 16:03:20 +11:00
options . put ( " worldedit.require-selection-in-mask " , Settings . REQUIRE_SELECTION ) ;
2014-10-11 00:33:10 -07:00
2014-11-05 14:42:08 +11:00
for ( final Entry < String , Object > node : options . entrySet ( ) ) {
if ( ! config . contains ( node . getKey ( ) ) ) {
config . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
Settings . DEBUG = config . getBoolean ( " debug " ) ;
if ( Settings . DEBUG ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &6Debug Mode Enabled (Default). Edit the config to turn this off. " ) ;
}
2014-11-20 19:29:05 +01:00
Settings . TELEPORT_ON_LOGIN = config . getBoolean ( " teleport.on_login " ) ;
2014-11-05 14:42:08 +11:00
Settings . KILL_ROAD_MOBS = config . getBoolean ( " kill_road_mobs " ) ;
Settings . WORLDGUARD = config . getBoolean ( " worldguard.enabled " ) ;
Settings . MOB_PATHFINDING = config . getBoolean ( " mob_pathfinding " ) ;
Settings . METRICS = config . getBoolean ( " metrics " ) ;
Settings . AUTO_CLEAR_DAYS = config . getInt ( " clear.auto.days " ) ;
2014-12-15 12:04:13 +11:00
Settings . MAX_AUTO_SIZE = config . getInt ( " claim.max-auto-area " ) ;
2014-11-05 14:42:08 +11:00
Settings . AUTO_CLEAR = config . getBoolean ( " clear.auto.enabled " ) ;
Settings . TITLES = config . getBoolean ( " titles " ) ;
2014-11-08 21:35:49 +11:00
Settings . MOB_CAP_ENABLED = config . getBoolean ( " perm-based-mob-cap.enabled " ) ;
Settings . MOB_CAP = config . getInt ( " perm-based-mob-cap.max " ) ;
2014-11-05 14:42:08 +11:00
Settings . MAX_PLOTS = config . getInt ( " max_plots " ) ;
2014-10-25 15:02:38 +02:00
Settings . SCHEMATIC_SAVE_PATH = config . getString ( " schematics.save_path " ) ;
2014-12-16 16:03:20 +11:00
2014-12-13 22:59:43 +11:00
Settings . OFFLINE_MODE = config . getBoolean ( " UUID.offline " ) ;
2014-12-16 16:03:20 +11:00
2014-12-04 15:00:08 +11:00
Settings . REQUIRE_SELECTION = config . getBoolean ( " worldedit.require-selection-in-mask " ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-20 19:29:05 +01:00
/ * *
* Create a plotworld config section
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param plotworld World to create the section for
2014-11-20 19:29:05 +01:00
* /
2014-11-05 14:42:08 +11:00
public static void createConfiguration ( final PlotWorld plotworld ) {
2014-11-08 20:46:49 +01:00
final Map < String , Object > options = new HashMap < > ( ) ;
2014-11-05 14:42:08 +11:00
for ( final ConfigurationNode setting : plotworld . getSettingNodes ( ) ) {
2014-11-08 20:46:49 +01:00
options . put ( setting . getConstant ( ) , setting . getValue ( ) ) ;
2014-11-05 14:42:08 +11:00
}
for ( final Entry < String , Object > node : options . entrySet ( ) ) {
if ( ! config . contains ( node . getKey ( ) ) ) {
config . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
try {
config . save ( PlotMain . configFile ) ;
2014-12-17 20:15:11 -06:00
} catch ( final IOException e ) {
2014-11-05 14:42:08 +11:00
PlotMain . sendConsoleSenderMessage ( " &c[Warning] PlotSquared failed to save the configuration&7 (settings.yml may differ from the one in memory) \ n - To force a save from console use /plots save " ) ;
}
}
public static void loadWorld ( final String world , final ChunkGenerator generator ) {
if ( getWorldSettings ( world ) ! = null ) {
return ;
}
2014-11-09 12:29:35 +01:00
2014-12-16 16:03:20 +11:00
final Set < String > worlds = ( config . contains ( " worlds " ) ? config . getConfigurationSection ( " worlds " ) . getKeys ( false ) : new HashSet < String > ( ) ) ;
2014-11-09 12:29:35 +01:00
final PlotWorld plotWorld ;
final PlotGenerator plotGenerator ;
final PlotManager plotManager ;
final String path = " worlds. " + world ;
2014-11-05 14:42:08 +11:00
if ( ( generator ! = null ) & & ( generator instanceof PlotGenerator ) ) {
2014-12-16 16:03:20 +11:00
plotGenerator = ( PlotGenerator ) generator ;
plotWorld = plotGenerator . getNewPlotWorld ( world ) ;
plotManager = plotGenerator . getPlotManager ( ) ;
2014-11-06 18:23:21 +11:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &aDetected world load for ' " + world + " ' " ) ;
2014-11-09 12:29:35 +01:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &3 - generator: &7 " + plotGenerator . getClass ( ) . getName ( ) ) ;
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &3 - plotworld: &7 " + plotWorld . getClass ( ) . getName ( ) ) ;
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &3 - manager: &7 " + plotManager . getClass ( ) . getName ( ) ) ;
if ( ! config . contains ( path ) ) {
config . createSection ( path ) ;
2014-11-05 14:42:08 +11:00
}
2014-12-20 15:44:24 +11:00
2014-11-09 12:29:35 +01:00
plotWorld . saveConfiguration ( config . getConfigurationSection ( path ) ) ;
plotWorld . loadDefaultConfiguration ( config . getConfigurationSection ( path ) ) ;
2014-11-05 14:42:08 +11:00
try {
config . save ( configFile ) ;
2014-12-17 20:15:11 -06:00
} catch ( final IOException e ) {
2014-11-05 14:42:08 +11:00
e . printStackTrace ( ) ;
}
2014-12-16 16:03:20 +11:00
// Now add it
2014-11-09 12:29:35 +01:00
addPlotWorld ( world , plotWorld , plotManager ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
if ( worlds . contains ( world ) ) {
sendConsoleSenderMessage ( " &cWorld ' " + world + " ' in settings.yml is not using PlotSquared generator! " ) ;
2014-12-16 16:03:20 +11:00
plotWorld = new DefaultPlotWorld ( world ) ;
plotManager = new DefaultPlotManager ( ) ;
2014-11-05 14:42:08 +11:00
2014-11-09 12:29:35 +01:00
if ( ! config . contains ( path ) ) {
config . createSection ( path ) ;
2014-11-05 14:42:08 +11:00
}
2014-11-09 12:29:35 +01:00
plotWorld . saveConfiguration ( config . getConfigurationSection ( path ) ) ;
plotWorld . loadConfiguration ( config . getConfigurationSection ( path ) ) ;
2014-11-05 14:42:08 +11:00
try {
config . save ( configFile ) ;
2014-12-17 20:15:11 -06:00
} catch ( final IOException e ) {
2014-11-05 14:42:08 +11:00
e . printStackTrace ( ) ;
}
2014-11-09 12:29:35 +01:00
// Now add it :p
addPlotWorld ( world , plotWorld , plotManager ) ;
2014-11-05 14:42:08 +11:00
}
}
}
/ * *
2014-12-17 20:15:11 -06:00
* Adds an external world as a recognized PlotSquared world - The PlotWorld class created is based off the
* configuration in the settings . yml - Do not use this method unless the required world is preconfigured in the
2014-11-05 14:42:08 +11:00
* settings . yml
*
2014-12-17 20:15:11 -06:00
* @param world to load
2014-11-05 14:42:08 +11:00
* /
public static void loadWorld ( final World world ) {
if ( world = = null ) {
return ;
}
final ChunkGenerator generator = world . getGenerator ( ) ;
loadWorld ( world . getName ( ) , generator ) ;
}
/ * *
* SETUP : storage . properties
* /
private static void setupStorage ( ) {
storage . set ( " version " , storage_ver ) ;
2014-11-08 20:46:49 +01:00
final Map < String , Object > options = new HashMap < > ( ) ;
2014-11-05 14:42:08 +11:00
options . put ( " mysql.use " , true ) ;
options . put ( " sqlite.use " , false ) ;
options . put ( " sqlite.db " , " storage " ) ;
options . put ( " mysql.host " , " localhost " ) ;
options . put ( " mysql.port " , " 3306 " ) ;
options . put ( " mysql.user " , " root " ) ;
options . put ( " mysql.password " , " password " ) ;
options . put ( " mysql.database " , " plot_db " ) ;
2014-10-30 17:24:58 +11:00
options . put ( " prefix " , " " ) ;
2014-11-05 14:42:08 +11:00
for ( final Entry < String , Object > node : options . entrySet ( ) ) {
if ( ! storage . contains ( node . getKey ( ) ) ) {
storage . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
}
2014-10-30 16:16:26 +01:00
private static void addPlusFlags ( ) {
2014-11-05 14:42:08 +11:00
final List < String > booleanFlags = Arrays . asList ( " notify-enter " , " notify-leave " , " item-drop " , " invincible " , " instabreak " , " drop-protection " , " forcefield " , " titles " , " pve " , " pvp " ) ;
final List < String > intervalFlags = Arrays . asList ( " feed " , " heal " ) ;
final List < String > stringFlags = Arrays . asList ( " greeting " , " farewell " ) ;
for ( final String flag : stringFlags ) {
2014-10-30 16:16:26 +01:00
FlagManager . addFlag ( new AbstractFlag ( flag ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-30 16:16:26 +01:00
return value ;
}
@Override
public String getValueDesc ( ) {
return " Value must be a string, supports color codes (&) " ;
}
} ) ;
}
2014-11-05 14:42:08 +11:00
for ( final String flag : intervalFlags ) {
2014-10-30 16:16:26 +01:00
FlagManager . addFlag ( new AbstractFlag ( flag ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-30 16:16:26 +01:00
int seconds ;
int amount ;
2014-11-05 14:42:08 +11:00
final String [ ] values = value . split ( " " ) ;
2014-10-30 16:16:26 +01:00
if ( values . length < 2 ) {
seconds = 1 ;
try {
amount = Integer . parseInt ( values [ 0 ] ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-10-30 16:16:26 +01:00
return null ;
}
2014-12-17 20:15:11 -06:00
} else {
2014-10-30 16:16:26 +01:00
try {
amount = Integer . parseInt ( values [ 0 ] ) ;
seconds = Integer . parseInt ( values [ 1 ] ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-10-30 16:16:26 +01:00
return null ;
}
}
return amount + " " + seconds ;
}
@Override
public String getValueDesc ( ) {
return " Value(s) must be numeric. /plot set flag {flag} {amount} [seconds] " ;
}
} ) ;
}
2014-11-05 14:42:08 +11:00
for ( final String flag : booleanFlags ) {
2014-10-30 16:16:26 +01:00
FlagManager . addFlag ( new AbstractFlag ( flag ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-30 16:16:26 +01:00
switch ( value ) {
case " on " :
case " 1 " :
case " true " :
case " enabled " :
return " true " ;
case " off " :
case " 0 " :
case " false " :
case " disabled " :
return " false " ;
default :
return null ;
}
}
@Override
public String getValueDesc ( ) {
return " Value must be true/false, 1/0, on/off, enabled/disabled " ;
}
} ) ;
}
}
2014-10-18 10:57:45 +02:00
private static void defaultFlags ( ) {
2014-10-30 16:16:26 +01:00
addPlusFlags ( ) ;
2014-10-21 18:53:52 +02:00
FlagManager . addFlag ( new AbstractFlag ( " fly " ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-21 18:53:52 +02:00
switch ( value ) {
case " on " :
case " enabled " :
case " true " :
case " 1 " :
return " true " ;
case " off " :
case " disabled " :
case " false " :
case " 0 " :
return " false " ;
default :
return null ;
}
}
@Override
public String getValueDesc ( ) {
return " Flag value must be a boolean: true, false, enabled, disabled " ;
}
} ) ;
2014-11-05 14:42:08 +11:00
for ( final String str : booleanFlags . values ( ) ) {
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( str ) {
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-19 21:27:27 +11:00
switch ( value ) {
2014-10-21 07:35:15 +02:00
case " true " :
case " 1 " :
case " yes " :
return " true " ;
case " false " :
case " off " :
case " 0 " :
return " false " ;
default :
return null ;
2014-10-19 21:27:27 +11:00
}
}
@Override
public String getValueDesc ( ) {
return " Flag value must be a boolean: true, false " ;
}
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
} ) ;
2014-10-18 13:44:51 +02:00
}
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( " gamemode " ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-19 21:27:27 +11:00
switch ( value ) {
2014-10-21 07:35:15 +02:00
case " creative " :
case " c " :
case " 1 " :
return " creative " ;
case " survival " :
case " s " :
case " 0 " :
return " survival " ;
case " adventure " :
case " a " :
case " 2 " :
return " adventure " ;
default :
return null ;
2014-10-19 21:27:27 +11:00
}
}
@Override
public String getValueDesc ( ) {
return " Flag value must be a gamemode: 'creative' , 'survival' or 'adventure' " ;
}
} ) ;
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( " time " ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-19 21:27:27 +11:00
try {
2014-11-05 14:42:08 +11:00
return Long . parseLong ( value ) + " " ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-10-19 21:27:27 +11:00
return null ;
}
}
@Override
public String getValueDesc ( ) {
return " Flag value must be a time in ticks: 0=sunrise 12000=noon 18000=sunset 24000=night " ;
}
} ) ;
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( " weather " ) {
@Override
2014-11-05 14:42:08 +11:00
public String parseValue ( final String value ) {
2014-10-19 21:27:27 +11:00
switch ( value ) {
2014-11-05 14:42:08 +11:00
case " rain " :
case " storm " :
case " on " :
return " rain " ;
case " clear " :
case " off " :
case " sun " :
return " clear " ;
default :
return null ;
2014-10-19 21:27:27 +11:00
}
}
@Override
public String getValueDesc ( ) {
return " Flag value must be weather type: 'clear' or 'rain' " ;
}
} ) ;
2014-10-18 10:57:45 +02:00
}
2014-11-20 19:29:05 +01:00
/ * *
* Add a Plot world
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param world World to add
* @param plotworld PlotWorld Object
* @param manager Plot Manager for the new world
2014-11-20 19:29:05 +01:00
* /
2014-11-05 14:42:08 +11:00
public static void addPlotWorld ( final String world , final PlotWorld plotworld , final PlotManager manager ) {
worlds . put ( world , plotworld ) ;
managers . put ( world , manager ) ;
if ( ! plots . containsKey ( world ) ) {
plots . put ( world , new HashMap < PlotId , Plot > ( ) ) ;
}
}
2014-11-20 19:29:05 +01:00
/ * *
* Remove a plot world
2014-11-21 23:45:46 +01:00
*
2014-12-17 20:15:11 -06:00
* @param world World to remove
2014-11-20 19:29:05 +01:00
* /
2014-11-05 14:42:08 +11:00
public static void removePlotWorld ( final String world ) {
plots . remove ( world ) ;
managers . remove ( world ) ;
worlds . remove ( world ) ;
}
2014-10-28 01:57:14 +01:00
2014-11-20 19:29:05 +01:00
/ * *
* Get all plots
2014-11-21 23:45:46 +01:00
*
2014-11-20 19:29:05 +01:00
* @return All Plos in a hashmap ( world , Hashmap contiang ids and objects ) )
* /
2014-11-05 14:42:08 +11:00
public static HashMap < String , HashMap < PlotId , Plot > > getAllPlotsRaw ( ) {
2014-10-20 20:50:54 +11:00
return plots ;
}
2014-11-20 19:29:05 +01:00
/ * *
* Set all plots
*
2014-12-19 01:42:47 +01:00
* @param plots New Plot HashMap
2014-11-20 19:29:05 +01:00
* /
2014-12-19 01:42:47 +01:00
public static void setAllPlotsRaw ( final HashMap < String , HashMap < PlotId , Plot > > plots ) {
PlotMain . plots = new LinkedHashMap < > ( plots ) ;
// PlotMain.plots.putAll(plots);
2014-11-20 19:29:05 +01:00
}
/ * *
* Set all plots
*
2014-12-19 01:42:47 +01:00
* @param plots New Plot LinkedHashMap
2014-11-20 19:29:05 +01:00
* /
2014-12-19 01:42:47 +01:00
public static void setAllPlotsRaw ( final LinkedHashMap < String , HashMap < PlotId , Plot > > plots ) {
PlotMain . plots = plots ;
2014-11-09 12:29:35 +01:00
}
/ * *
2014-11-20 19:29:05 +01:00
* Get the PlotSquared World Generator
*
* @see com . intellectualcrafters . plot . generator . WorldGenerator
2014-11-09 12:29:35 +01:00
* /
@Override
2014-11-20 19:29:05 +01:00
final public ChunkGenerator getDefaultWorldGenerator ( final String world , final String id ) {
2014-11-09 12:29:35 +01:00
return new WorldGenerator ( world ) ;
}
2014-11-20 19:29:05 +01:00
/ * *
* Setup the logger mechanics
* /
2014-11-09 12:29:35 +01:00
private void setupLogger ( ) {
final File log = new File ( getMain ( ) . getDataFolder ( ) + File . separator + " logs " + File . separator + " plots.log " ) ;
if ( ! log . exists ( ) ) {
try {
if ( ! new File ( getMain ( ) . getDataFolder ( ) + File . separator + " logs " ) . mkdirs ( ) ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cFailed to create logs folder. Do it manually. " ) ;
}
if ( log . createNewFile ( ) ) {
final FileWriter writer = new FileWriter ( log ) ;
writer . write ( " Created at: " + new Date ( ) . toString ( ) + " \ n \ n \ n " ) ;
writer . close ( ) ;
}
2014-12-17 20:15:11 -06:00
} catch ( final IOException e ) {
2014-11-09 12:29:35 +01:00
e . printStackTrace ( ) ;
}
}
Logger . setup ( log ) ;
Logger . add ( LogLevel . GENERAL , " Logger enabled " ) ;
}
/ * *
* On Load .
* /
@Override
@SuppressWarnings ( " deprecation " )
2014-11-20 19:29:05 +01:00
final public void onEnable ( ) {
2014-12-14 00:30:29 +11:00
PlotMain . main = this ;
2014-11-21 23:55:30 +01:00
// Setup the logger mechanics
setupLogger ( ) ;
2014-11-28 18:55:08 +11:00
// Setup translations
C . setupTranslations ( ) ;
2014-11-21 23:55:30 +01:00
// Check for outdated java version.
if ( getJavaVersion ( ) < 1 . 7 ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cYour java version is outdated. Please update to at least 1.7. " ) ;
// Didn't know of any other link :D
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cURL: &6https://java.com/en/download/index.jsp " ) ;
Bukkit . getPluginManager ( ) . disablePlugin ( this ) ;
return ;
2014-12-17 20:15:11 -06:00
} else if ( getJavaVersion ( ) < 1 . 8 ) {
2014-11-21 23:55:30 +01:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cIt's really recommended to run Java 1.8, as it increases performance " ) ;
2014-11-09 12:29:35 +01:00
}
// Setup configuration
configs ( ) ;
// Setup metrics
if ( Settings . METRICS ) {
try {
final Metrics metrics = new Metrics ( this ) ;
metrics . start ( ) ;
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &6Metrics enabled. " ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cFailed to load up metrics. " ) ;
}
2014-12-17 20:15:11 -06:00
} else {
2014-11-16 10:16:38 +01:00
// We should at least make them feel bad.
sendConsoleSenderMessage ( " Using metrics will allow us to improve the plugin \ nPlease consider it :) " ) ;
2014-11-09 12:29:35 +01:00
}
// Kill mobs on roads?
if ( Settings . KILL_ROAD_MOBS ) {
killAllEntities ( ) ;
}
if ( C . ENABLED . s ( ) . length ( ) > 0 ) {
Broadcast ( C . ENABLED ) ;
}
2014-11-16 10:16:38 +01:00
// Add tables to this one, if we create more :D
2014-12-17 20:15:11 -06:00
final String [ ] tables = new String [ ] { " plot_trusted " , " plot_ratings " , " plot_comments " } ;
2014-11-09 12:29:35 +01:00
// Use mysql?
if ( Settings . DB . USE_MYSQL ) {
try {
mySQL = new MySQL ( this , Settings . DB . HOST_NAME , Settings . DB . PORT , Settings . DB . DATABASE , Settings . DB . USER , Settings . DB . PASSWORD ) ;
connection = mySQL . openConnection ( ) ;
{
2014-11-15 12:53:26 +01:00
if ( DBFunc . dbManager = = null ) {
DBFunc . dbManager = new SQLManager ( connection , Settings . DB . PREFIX ) ;
}
2014-11-09 12:29:35 +01:00
final DatabaseMetaData meta = connection . getMetaData ( ) ;
ResultSet res = meta . getTables ( null , null , Settings . DB . PREFIX + " plot " , null ) ;
if ( ! res . next ( ) ) {
DBFunc . createTables ( " mysql " , true ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-12-16 16:03:20 +11:00
for ( final String table : tables ) {
2014-11-09 12:29:35 +01:00
res = meta . getTables ( null , null , Settings . DB . PREFIX + table , null ) ;
if ( ! res . next ( ) ) {
DBFunc . createTables ( " mysql " , false ) ;
}
}
// We should not repeat our self :P
}
}
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
Logger . add ( LogLevel . DANGER , " MySQL connection failed. " ) ;
sendConsoleSenderMessage ( " &c[Plots] MySQL is not setup correctly. The plugin will disable itself. " ) ;
if ( ( config = = null ) | | config . getBoolean ( " debug " ) ) {
sendConsoleSenderMessage ( " &d==== Here is an ugly stacktrace if you are interested in those things ==== " ) ;
e . printStackTrace ( ) ;
sendConsoleSenderMessage ( " &d==== End of stacktrace ==== " ) ;
sendConsoleSenderMessage ( " &6Please go to the PlotSquared 'storage.yml' and configure MySQL correctly. " ) ;
}
Bukkit . getPluginManager ( ) . disablePlugin ( this ) ;
return ;
}
plots = DBFunc . getPlots ( ) ;
}
// TODO: Implement mongo
else if ( Settings . DB . USE_MONGO ) {
// DBFunc.dbManager = new MongoManager();
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " MongoDB is not yet implemented " ) ;
2014-12-17 20:15:11 -06:00
} else if ( Settings . DB . USE_SQLITE ) {
2014-11-09 12:29:35 +01:00
try {
connection = new SQLite ( this , Settings . DB . SQLITE_DB + " .db " ) . openConnection ( ) ;
{
2014-11-15 12:53:26 +01:00
DBFunc . dbManager = new SQLManager ( connection , Settings . DB . PREFIX ) ;
2014-11-09 12:29:35 +01:00
final DatabaseMetaData meta = connection . getMetaData ( ) ;
ResultSet res = meta . getTables ( null , null , Settings . DB . PREFIX + " plot " , null ) ;
if ( ! res . next ( ) ) {
DBFunc . createTables ( " sqlite " , true ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-12-16 16:03:20 +11:00
for ( final String table : tables ) {
2014-11-09 12:29:35 +01:00
res = meta . getTables ( null , null , Settings . DB . PREFIX + table , null ) ;
if ( ! res . next ( ) ) {
DBFunc . createTables ( " sqlite " , false ) ;
}
}
}
}
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
Logger . add ( LogLevel . DANGER , " SQLite connection failed " ) ;
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &cFailed to open SQLite connection. The plugin will disable itself. " ) ;
sendConsoleSenderMessage ( " &9==== Here is an ugly stacktrace, if you are interested in those things === " ) ;
e . printStackTrace ( ) ;
Bukkit . getPluginManager ( ) . disablePlugin ( this ) ;
return ;
}
plots = DBFunc . getPlots ( ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-09 12:29:35 +01:00
Logger . add ( LogLevel . DANGER , " No storage type is set. " ) ;
sendConsoleSenderMessage ( C . PREFIX + " &cNo storage type is set! " ) ;
getServer ( ) . getPluginManager ( ) . disablePlugin ( this ) ;
return ;
}
2014-11-16 10:16:38 +01:00
// We should not start the plugin if
// plotme is present. Maybe do this
// earlier, and no register any commands
// nor listeners, just run the converter?
2014-11-09 12:29:35 +01:00
if ( getServer ( ) . getPluginManager ( ) . getPlugin ( " PlotMe " ) ! = null ) {
try {
new PlotMeConverter ( this ) . runAsync ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
e . printStackTrace ( ) ;
}
}
// Setup the command handler
{
final MainCommand command = new MainCommand ( ) ;
final PluginCommand plotCommand = getCommand ( " plots " ) ;
plotCommand . setExecutor ( command ) ;
2014-12-16 16:03:20 +11:00
plotCommand . setAliases ( Arrays . asList ( " p " , " ps " , " plotme " , " plot " ) ) ;
2014-11-09 12:29:35 +01:00
plotCommand . setTabCompleter ( command ) ;
}
if ( Settings . MOB_CAP_ENABLED ) {
getServer ( ) . getPluginManager ( ) . registerEvents ( new EntityListener ( ) , this ) ;
}
// Main event handler
getServer ( ) . getPluginManager ( ) . registerEvents ( new PlayerEvents ( ) , this ) ;
2014-11-18 23:21:08 +01:00
// Info Inventory
getServer ( ) . getPluginManager ( ) . registerEvents ( new InventoryListener ( ) , this ) ;
2014-11-09 12:29:35 +01:00
// Flag runnable
PlotPlusListener . startRunnable ( this ) ;
// Flag+ listener
getServer ( ) . getPluginManager ( ) . registerEvents ( new PlotPlusListener ( ) , this ) ;
// Forcefield listener
getServer ( ) . getPluginManager ( ) . registerEvents ( new ForceFieldListener ( this ) , this ) ;
// Default flags
defaultFlags ( ) ;
if ( getServer ( ) . getPluginManager ( ) . getPlugin ( " BarAPI " ) ! = null ) {
barAPI = ( BarAPI ) getServer ( ) . getPluginManager ( ) . getPlugin ( " BarAPI " ) ;
}
if ( getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldEdit " ) ! = null ) {
worldEdit = ( WorldEditPlugin ) getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldEdit " ) ;
final String version = worldEdit . getDescription ( ) . getVersion ( ) ;
if ( ( version ! = null ) & & version . startsWith ( " 5. " ) ) {
2014-12-04 15:00:08 +11:00
PlotMain . sendConsoleSenderMessage ( " &cThis version of WorldEdit does not support PlotSquared. " ) ;
PlotMain . sendConsoleSenderMessage ( " &cPlease use WorldEdit 6+ " ) ;
PlotMain . sendConsoleSenderMessage ( " &c - http://builds.enginehub.org/job/worldedit " ) ;
2014-12-17 20:15:11 -06:00
} else {
2014-11-09 12:29:35 +01:00
getServer ( ) . getPluginManager ( ) . registerEvents ( new WorldEditListener ( ) , this ) ;
}
}
if ( Settings . WORLDGUARD ) {
if ( getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldGuard " ) ! = null ) {
worldGuard = ( WorldGuardPlugin ) getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldGuard " ) ;
worldGuardListener = new WorldGuardListener ( this ) ;
getServer ( ) . getPluginManager ( ) . registerEvents ( worldGuardListener , this ) ;
}
}
if ( Settings . AUTO_CLEAR ) {
checkExpired ( PlotMain . getMain ( ) , true ) ;
checkForExpiredPlots ( ) ;
}
// Economy setup
{
if ( ( getServer ( ) . getPluginManager ( ) . getPlugin ( " Vault " ) ! = null ) & & getServer ( ) . getPluginManager ( ) . getPlugin ( " Vault " ) . isEnabled ( ) ) {
final RegisteredServiceProvider < Economy > economyProvider = getServer ( ) . getServicesManager ( ) . getRegistration ( net . milkbowl . vault . economy . Economy . class ) ;
if ( economyProvider ! = null ) {
economy = economyProvider . getProvider ( ) ;
}
}
useEconomy = ( economy ! = null ) ;
}
// TPS Measurement
{
getServer ( ) . getScheduler ( ) . scheduleSyncRepeatingTask ( this , new Lag ( ) , 100L , 1L ) ;
}
// Test for SetBlockFast
{
try {
new SetBlockFast ( ) ;
PlotHelper . canSetFast = true ;
2014-12-17 20:15:11 -06:00
} catch ( final Throwable e ) {
2014-11-09 12:29:35 +01:00
PlotHelper . canSetFast = false ;
}
2014-11-21 23:45:46 +01:00
2014-11-21 14:11:41 +11:00
try {
new SendChunk ( ) ;
PlotHelper . canSendChunk = true ;
2014-12-17 20:15:11 -06:00
} catch ( final Throwable e ) {
2014-11-21 14:11:41 +11:00
PlotHelper . canSendChunk = false ;
}
2014-11-09 12:29:35 +01:00
}
// Setup the setup command
{
com . intellectualcrafters . plot . commands . plugin . setup ( this ) ;
}
// Handle UUIDS
{
2014-12-13 22:59:43 +11:00
if ( Settings . OFFLINE_MODE ) {
UUIDHandler . uuidWrapper = new OfflineUUIDWrapper ( ) ;
}
2014-11-09 12:29:35 +01:00
setUUIDSaver ( new PlotUUIDSaver ( ) ) ;
// Looks really cool xD
getUUIDSaver ( ) . globalPopulate ( ) ;
}
2014-11-21 23:55:30 +01:00
// Now we're finished :D
if ( C . ENABLED . s ( ) . length ( ) > 0 ) {
Broadcast ( C . ENABLED ) ;
}
2014-11-09 12:29:35 +01:00
}
/ * *
* On unload
* /
@Override
2014-11-20 19:29:05 +01:00
final public void onDisable ( ) {
2014-11-09 12:29:35 +01:00
try {
C . saveTranslations ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( final Exception e ) {
2014-11-09 12:29:35 +01:00
sendConsoleSenderMessage ( " Failed to save translations " ) ;
Logger . add ( LogLevel . DANGER , " Failed to save translations " ) ;
e . printStackTrace ( ) ;
}
Logger . add ( LogLevel . GENERAL , " Logger disabled " ) ;
try {
Logger . write ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( final IOException e1 ) {
2014-11-09 12:29:35 +01:00
e1 . printStackTrace ( ) ;
}
try {
connection . close ( ) ;
mySQL . closeConnection ( ) ;
2014-12-17 20:15:11 -06:00
} catch ( NullPointerException | SQLException e ) {
2014-11-09 12:29:35 +01:00
if ( connection ! = null ) {
Logger . add ( LogLevel . DANGER , " Could not close mysql connection " ) ;
}
}
2014-11-02 21:14:47 +01:00
}
2014-09-24 22:21:43 +10:00
}