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 ;
2015-01-10 21:20:20 +11:00
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.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
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.Map.Entry ;
import java.util.Set ;
import java.util.UUID ;
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.OfflinePlayer ;
import org.bukkit.World ;
import org.bukkit.command.PluginCommand ;
import org.bukkit.configuration.file.YamlConfiguration ;
import org.bukkit.entity.Entity ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.event.world.WorldLoadEvent ;
import org.bukkit.generator.ChunkGenerator ;
import org.bukkit.plugin.Plugin ;
import org.bukkit.plugin.RegisteredServiceProvider ;
import org.bukkit.plugin.java.JavaPlugin ;
2015-01-14 03:38:15 +11:00
import com.intellectualcrafters.plot.commands.Buy ;
2015-01-29 17:03:54 +11:00
import com.intellectualcrafters.plot.commands.Cluster ;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.commands.MainCommand ;
2015-01-03 01:38:04 +11:00
import com.intellectualcrafters.plot.commands.WE_Anywhere ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.config.C ;
2015-02-08 10:44:53 +11:00
import com.intellectualcrafters.plot.config.Configuration ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.config.ConfigurationNode ;
import com.intellectualcrafters.plot.config.Settings ;
2015-01-10 21:20:20 +11:00
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 ;
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 ;
2015-01-24 21:40:50 -07:00
import com.intellectualcrafters.plot.flag.FlagValue ;
2015-01-31 18:09:48 +11:00
import com.intellectualcrafters.plot.generator.AugmentedPopulator ;
2014-12-28 23:02:30 +11:00
import com.intellectualcrafters.plot.generator.HybridGen ;
import com.intellectualcrafters.plot.generator.HybridPlotWorld ;
2015-01-10 21:20:20 +11:00
import com.intellectualcrafters.plot.listeners.ForceFieldListener ;
import com.intellectualcrafters.plot.listeners.InventoryListener ;
import com.intellectualcrafters.plot.listeners.PlayerEvents ;
2015-02-08 14:49:00 +11:00
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8 ;
2015-01-10 21:20:20 +11:00
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.object.Plot ;
2015-02-08 10:44:53 +11:00
import com.intellectualcrafters.plot.object.PlotBlock ;
2015-01-31 18:09:48 +11:00
import com.intellectualcrafters.plot.object.PlotCluster ;
2015-01-10 21:20:20 +11:00
import com.intellectualcrafters.plot.object.PlotGenerator ;
import com.intellectualcrafters.plot.object.PlotId ;
import com.intellectualcrafters.plot.object.PlotManager ;
import com.intellectualcrafters.plot.object.PlotWorld ;
2015-01-18 12:11:51 -08:00
import com.intellectualcrafters.plot.titles.AbstractTitle ;
import com.intellectualcrafters.plot.titles.DefaultTitle ;
2015-01-25 21:16:10 -07:00
import com.intellectualcrafters.plot.util.ClusterManager ;
2015-01-10 21:20:20 +11:00
import com.intellectualcrafters.plot.util.ConsoleColors ;
import com.intellectualcrafters.plot.util.ExpireManager ;
import com.intellectualcrafters.plot.util.Lag ;
import com.intellectualcrafters.plot.util.Logger ;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.util.Logger.LogLevel ;
2015-01-10 21:20:20 +11:00
import com.intellectualcrafters.plot.util.Metrics ;
import com.intellectualcrafters.plot.util.PlayerFunctions ;
import com.intellectualcrafters.plot.util.PlotHelper ;
import com.intellectualcrafters.plot.util.SendChunk ;
import com.intellectualcrafters.plot.util.SetBlockFast ;
2015-02-10 23:23:12 +11:00
import com.intellectualcrafters.plot.util.TaskManager ;
2015-01-10 21:20:20 +11:00
import com.intellectualcrafters.plot.util.UUIDHandler ;
2014-12-22 01:59:35 +11:00
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper ;
2014-12-16 15:58:54 +11:00
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper ;
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-22 01:59:35 +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
* /
2015-01-18 12:11:51 -08:00
public class PlotMain extends JavaPlugin implements Listener {
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
/ * *
* 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 ;
2015-02-08 10:44:53 +11:00
private static boolean LOADING_WORLD = false ;
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-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-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 ) {
2015-01-13 03:45:50 +11:00
if ( ( player = = null ) | | player . isOp ( ) | | player . hasPermission ( ADMIN_PERMISSION ) ) {
2014-11-05 14:42:08 +11:00
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 + + ) {
2015-01-31 18:09:48 +11:00
n . append ( nodes [ i ] + ( " . " ) ) ;
2014-11-05 14:42:08 +11:00
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
2015-01-02 12:35:47 +11:00
* - ignores non plot worlds
2014-11-05 14:42:08 +11:00
* /
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 < > ( ) ;
2015-01-02 12:35:47 +11:00
for ( final String world : plots . keySet ( ) ) {
if ( isPlotWorld ( world ) ) {
for ( final Plot plot : plots . get ( world ) . values ( ) ) {
if ( plot . hasOwner ( ) ) {
if ( plot . getOwner ( ) . equals ( uuid ) ) {
myplots . add ( plot ) ;
}
2014-11-05 14:42:08 +11:00
}
}
}
}
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 ) ;
2015-01-07 17:44:03 +11:00
return getPlots ( world , uuid ) ;
}
/ * *
* @param world plot world
* @param player plot owner
*
* @return players plots
* /
public static Set < Plot > getPlots ( final World world , final UUID uuid ) {
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 ) ;
2015-01-22 16:14:14 -08:00
if ( PlotHelper . lastPlot . containsKey ( world ) ) {
PlotId last = PlotHelper . lastPlot . get ( world ) ;
int last_max = Math . max ( last . x , last . y ) ;
int this_max = Math . max ( id . x , id . y ) ;
if ( this_max < last_max ) {
PlotHelper . lastPlot . put ( world , id ) ;
}
}
2014-11-05 14:42:08 +11:00
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-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 ) {
2015-01-10 12:00:26 +11:00
if ( PlotMain . main = = null | | getMain ( ) . getServer ( ) . getConsoleSender ( ) = = null ) {
2014-11-09 12:29:35 +01:00
System . out . println ( ChatColor . stripColor ( ConsoleColors . fromString ( string ) ) ) ;
2014-12-17 20:15:11 -06:00
} else {
2015-01-22 17:06:11 -08:00
String message = ChatColor . translateAlternateColorCodes ( '&' , string ) ;
if ( ! Settings . CONSOLE_COLOR ) {
message = ChatColor . stripColor ( message ) ;
}
getMain ( ) . getServer ( ) . getConsoleSender ( ) . sendMessage ( message ) ;
2014-11-09 12:29:35 +01:00
}
}
/ * *
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 ) {
2015-01-16 22:25:54 -08:00
Plot bot = PlayerFunctions . getBottomPlot ( player . getWorld ( ) , plot ) ;
final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent ( player , from , bot ) ;
2014-11-09 12:29:35 +01:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
if ( ! event . isCancelled ( ) ) {
2015-01-16 22:25:54 -08:00
final Location location = PlotHelper . getPlotHome ( Bukkit . getWorld ( bot . world ) , bot ) ;
2014-11-09 12:29:35 +01:00
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
}
2015-02-10 23:23:12 +11:00
if ( Settings . TELEPORT_DELAY = = 0 | | hasPermission ( player , " plots.teleport.delay.bypass " ) ) {
PlayerFunctions . sendMessage ( player , C . TELEPORTED_TO_PLOT ) ;
player . teleport ( location ) ;
return true ;
}
PlayerFunctions . sendMessage ( player , C . TELEPORT_IN_SECONDS , Settings . TELEPORT_DELAY + " " ) ;
Location loc = player . getLocation ( ) ;
final World world = player . getWorld ( ) ;
final int x = loc . getBlockX ( ) ;
final int z = loc . getBlockZ ( ) ;
TaskManager . runTaskLater ( new Runnable ( ) {
@Override
public void run ( ) {
if ( ! player . isOnline ( ) ) {
return ;
}
Location loc = player . getLocation ( ) ;
if ( ! loc . getWorld ( ) . equals ( world ) ) {
PlayerFunctions . sendMessage ( player , C . TELEPORT_FAILED ) ;
return ;
}
if ( loc . getBlockX ( ) ! = x | | loc . getBlockZ ( ) ! = z ) {
PlayerFunctions . sendMessage ( player , C . TELEPORT_FAILED ) ;
return ;
}
PlayerFunctions . sendMessage ( player , C . TELEPORTED_TO_PLOT ) ;
player . teleport ( location ) ;
}
} , Settings . TELEPORT_DELAY * 20 ) ;
return true ;
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-12-23 02:12:40 +11:00
Settings . API_URL = config . getString ( " uuid.api.location " ) ;
Settings . CUSTOM_API = config . getBoolean ( " uuid.api.custom " ) ;
Settings . UUID_FECTHING = config . getBoolean ( " uuid.fetching " ) ;
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 ;
2015-01-06 14:33:37 +11:00
if ( this . error > 0 ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " KillAllEntities has been running for 6 hours. 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 ;
}
}
}
2015-01-02 12:54:27 +11:00
} , 20L , 20L ) ;
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
* /
2015-01-22 16:44:20 -08:00
public static void setupConfig ( ) {
2014-11-05 14:42:08 +11:00
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 < > ( ) ;
2015-02-10 23:23:12 +11:00
options . put ( " teleport.delay " , 0 ) ;
2014-11-05 14:42:08 +11:00
options . put ( " auto_update " , false ) ;
2015-01-25 21:16:10 -07:00
options . put ( " clusters.enabled " , Settings . ENABLE_CLUSTERS ) ;
2015-01-10 13:19:39 +11:00
options . put ( " plotme-alias " , Settings . USE_PLOTME_ALIAS ) ;
2015-01-10 12:52:48 +11:00
options . put ( " plotme-convert.enabled " , Settings . CONVERT_PLOTME ) ;
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 ) ;
2015-01-24 18:17:11 -07:00
// options.put("worldguard.enabled", Settings.WORLDGUARD);
2014-11-05 14:42:08 +11:00
options . put ( " kill_road_mobs " , Settings . KILL_ROAD_MOBS_DEFAULT ) ;
options . put ( " mob_pathfinding " , Settings . MOB_PATHFINDING_DEFAULT ) ;
2015-01-22 17:06:11 -08:00
options . put ( " console.color " , Settings . CONSOLE_COLOR ) ;
2014-11-05 14:42:08 +11:00
options . put ( " metrics " , true ) ;
options . put ( " debug " , true ) ;
options . put ( " clear.auto.enabled " , false ) ;
options . put ( " clear.auto.days " , 365 ) ;
2015-02-04 15:40:39 +11:00
options . put ( " clear.check-disk " , Settings . AUTO_CLEAR_CHECK_DISK ) ;
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 ) ;
2015-01-22 17:06:11 -08:00
// options.put("uuid.api.location", Settings.API_URL);
// options.put("uuid.api.custom", Settings.CUSTOM_API);
// options.put("uuid.fecthing", Settings.UUID_FECTHING);
options . put ( " uuid.read-from-disk " , Settings . UUID_FROM_DISK ) ;
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-12-29 01:33:40 +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 ( ) ) ;
}
}
2015-01-25 21:16:10 -07:00
Settings . ENABLE_CLUSTERS = config . getBoolean ( " clusters.enabled " ) ;
2014-11-05 14:42:08 +11:00
Settings . DEBUG = config . getBoolean ( " debug " ) ;
if ( Settings . DEBUG ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &6Debug Mode Enabled (Default). Edit the config to turn this off. " ) ;
}
2015-02-10 23:23:12 +11:00
Settings . TELEPORT_DELAY = config . getInt ( " teleport.delay " ) ;
2015-01-22 17:06:11 -08:00
Settings . CONSOLE_COLOR = config . getBoolean ( " console.color " ) ;
2014-11-20 19:29:05 +01:00
Settings . TELEPORT_ON_LOGIN = config . getBoolean ( " teleport.on_login " ) ;
2015-01-10 13:19:39 +11:00
Settings . USE_PLOTME_ALIAS = config . getBoolean ( " plotme-alias " ) ;
2015-01-10 12:52:48 +11:00
Settings . CONVERT_PLOTME = config . getBoolean ( " plotme-convert.enabled " ) ;
2014-11-05 14:42:08 +11:00
Settings . KILL_ROAD_MOBS = config . getBoolean ( " kill_road_mobs " ) ;
2015-01-24 18:17:11 -07:00
// Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
Settings . MOB_PATHFINDING = config . getBoolean ( " mob_pathf "
+ " inding " ) ;
2014-11-05 14:42:08 +11:00
Settings . METRICS = config . getBoolean ( " metrics " ) ;
Settings . AUTO_CLEAR_DAYS = config . getInt ( " clear.auto.days " ) ;
2015-02-04 15:40:39 +11:00
Settings . AUTO_CLEAR_CHECK_DISK = config . getBoolean ( " clear.check-disk " ) ;
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-12-29 01:33:40 +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
2015-01-23 11:02:04 -07:00
Settings . OFFLINE_MODE = config . getBoolean ( " UUID.offline " ) ;
2015-01-22 17:06:11 -08:00
Settings . UUID_FROM_DISK = config . getBoolean ( " uuid.read-from-disk " ) ;
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 " ) ;
}
}
2014-12-30 17:50:55 +11:00
2015-01-10 13:19:39 +11:00
@EventHandler
public void PlayerCommand ( PlayerCommandPreprocessEvent event ) {
String message = event . getMessage ( ) ;
if ( message . toLowerCase ( ) . startsWith ( " /plotme " ) ) {
Plugin plotme = Bukkit . getPluginManager ( ) . getPlugin ( " PlotMe " ) ;
if ( plotme = = null ) {
Player player = event . getPlayer ( ) ;
if ( Settings . USE_PLOTME_ALIAS ) {
player . performCommand ( message . replace ( " /plotme " , " plots " ) ) ;
}
else {
PlayerFunctions . sendMessage ( player , C . NOT_USING_PLOTME ) ;
}
event . setCancelled ( true ) ;
}
}
}
2014-12-30 17:50:55 +11:00
@EventHandler
public static void worldLoad ( WorldLoadEvent event ) {
if ( ! UUIDHandler . CACHED ) {
UUIDHandler . cacheAll ( ) ;
2015-01-30 09:16:31 +11:00
if ( Settings . CONVERT_PLOTME ) {
if ( Bukkit . getPluginManager ( ) . getPlugin ( " PlotMe " ) ! = null ) {
2015-01-30 09:33:28 +11:00
sendConsoleSenderMessage ( " &c[IMPORTANT] THIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME! " ) ;
sendConsoleSenderMessage ( " &c[IMPORTANT] - Make sure 'UUID.read-from-disk' is disabled (false)! " ) ;
sendConsoleSenderMessage ( " &c[IMPORTANT] - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue! " ) ;
sendConsoleSenderMessage ( " &c[IMPORTANT] - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml@' " ) ;
2015-01-30 09:16:31 +11:00
}
2015-01-10 02:02:02 +11:00
try {
new PlotMeConverter ( PlotMain . getMain ( ) ) . runAsync ( ) ;
} catch ( final Exception e ) {
e . printStackTrace ( ) ;
}
}
2014-12-30 17:50:55 +11:00
}
}
2015-01-31 18:09:48 +11:00
2014-11-05 14:42:08 +11:00
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 ;
2015-02-08 10:44:53 +11:00
if ( ! LOADING_WORLD & & ( generator ! = null ) & & ( generator instanceof PlotGenerator ) ) {
2014-12-16 16:03:20 +11:00
plotGenerator = ( PlotGenerator ) generator ;
plotWorld = plotGenerator . getNewPlotWorld ( world ) ;
plotManager = plotGenerator . getPlotManager ( ) ;
2014-12-22 18:05:23 +11:00
if ( ! world . equals ( " CheckingPlotSquaredGenerator " ) ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &aDetected world load for ' " + world + " ' " ) ;
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 ( ) ) ;
}
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 . 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 ) ;
2015-01-15 00:47:03 +11:00
PlotHelper . setupBorder ( world ) ;
2014-12-17 20:15:11 -06:00
} else {
2015-02-08 10:44:53 +11:00
if ( ! worlds . contains ( world ) ) {
return ;
}
if ( ! LOADING_WORLD ) {
LOADING_WORLD = true ;
try {
String gen_string = config . getString ( " worlds. " + world + " . " + " generator.plugin " ) ;
Plugin gen_plugin = gen_string = = null ? null : Bukkit . getPluginManager ( ) . getPlugin ( gen_string ) ;
if ( gen_plugin ! = null & & gen_plugin . isEnabled ( ) ) {
gen_plugin . getDefaultWorldGenerator ( world , " " ) ;
}
else {
new HybridGen ( world ) ;
}
}
catch ( Exception e ) {
System . out . print ( " ERRRRRRRRRRRRRR 6 " ) ;
e . printStackTrace ( ) ;
LOADING_WORLD = false ;
removePlotWorld ( world ) ;
}
finally {
LOADING_WORLD = false ;
}
}
else {
PlotGenerator gen_class = ( PlotGenerator ) generator ;
plotWorld = gen_class . getNewPlotWorld ( world ) ;
plotManager = gen_class . getPlotManager ( ) ;
2014-11-09 12:29:35 +01:00
if ( ! config . contains ( path ) ) {
config . createSection ( path ) ;
2014-11-05 14:42:08 +11:00
}
2015-02-08 10:44:53 +11:00
plotWorld . TYPE = 2 ;
plotWorld . TERRAIN = 0 ;
2014-11-09 12:29:35 +01:00
plotWorld . saveConfiguration ( config . getConfigurationSection ( path ) ) ;
2015-01-31 18:09:48 +11:00
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 ( ) ;
}
2015-02-08 10:44:53 +11:00
if ( plotWorld . TYPE = = 2 & & ! Settings . ENABLE_CLUSTERS ) {
sendConsoleSenderMessage ( " &c[ERROR] World ' " + world + " ' in settings.yml is not using PlotSquared generator! Please enable plot custers or delete this world from your settings.yml! " ) ;
return ;
}
addPlotWorld ( world , plotWorld , plotManager ) ;
if ( plotWorld . TYPE = = 2 ) {
2015-01-31 18:09:48 +11:00
if ( ClusterManager . getClusters ( world ) . size ( ) > 0 ) {
for ( PlotCluster cluster : ClusterManager . getClusters ( world ) ) {
2015-02-08 10:44:53 +11:00
new AugmentedPopulator ( world , gen_class , cluster , plotWorld . TERRAIN = = 2 , plotWorld . TERRAIN ! = 2 ) ;
2015-01-31 18:09:48 +11:00
}
}
}
2015-02-08 10:44:53 +11:00
else if ( plotWorld . TYPE = = 1 ) {
new AugmentedPopulator ( world , gen_class , null , plotWorld . TERRAIN = = 2 , plotWorld . TERRAIN ! = 2 ) ;
}
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 < > ( ) ;
2015-01-07 15:03:07 +11:00
options . put ( " mysql.use " , false ) ;
options . put ( " sqlite.use " , true ) ;
2014-11-05 14:42:08 +11:00
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 ( ) {
2015-01-22 16:26:16 -08:00
final List < String > booleanFlags = Arrays . asList ( " notify-enter " , " notify-leave " , " item-drop " , " invincible " , " instabreak " , " drop-protection " , " forcefield " , " titles " , " pve " , " pvp " , " no-worldedit " ) ;
2014-11-05 14:42:08 +11:00
final List < String > intervalFlags = Arrays . asList ( " feed " , " heal " ) ;
final List < String > stringFlags = Arrays . asList ( " greeting " , " farewell " ) ;
for ( final String flag : stringFlags ) {
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( flag ) ) ;
2014-10-30 16:16:26 +01:00
}
2014-11-05 14:42:08 +11:00
for ( final String flag : intervalFlags ) {
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( flag , new FlagValue . IntervalValue ( ) ) ) ;
2014-10-30 16:16:26 +01:00
}
2014-11-05 14:42:08 +11:00
for ( final String flag : booleanFlags ) {
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( flag , new FlagValue . BooleanValue ( ) ) ) ;
2014-10-30 16:16:26 +01:00
}
}
2014-10-18 10:57:45 +02:00
private static void defaultFlags ( ) {
2014-10-30 16:16:26 +01:00
addPlusFlags ( ) ;
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( " fly " , new FlagValue . BooleanValue ( ) ) ) ;
2015-01-29 22:48:28 +11:00
FlagManager . addFlag ( new AbstractFlag ( " explosion " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " hostile-interact " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " hostile-attack " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " animal-interact " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " animal-attack " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " tamed-interact " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " tamed-attack " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " misc-interact " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " hanging-place " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " hanging-break " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " vehicle-use " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " vehicle-place " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " vehicle-break " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " place " , new FlagValue . PlotBlockListValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " break " , new FlagValue . PlotBlockListValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " use " , new FlagValue . PlotBlockListValue ( ) ) ) ;
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( " gamemode " ) {
@Override
2015-01-24 21:40:50 -07:00
public String parseValueRaw ( 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' " ;
}
} ) ;
2015-01-10 21:20:20 +11:00
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( " price " , new FlagValue . UnsignedDoubleValue ( ) ) ) ;
2014-10-19 21:27:27 +11:00
2015-01-24 21:40:50 -07:00
FlagManager . addFlag ( new AbstractFlag ( " time " , new FlagValue . LongValue ( ) ) ) ;
2014-11-05 14:42:08 +11:00
2014-10-19 21:27:27 +11:00
FlagManager . addFlag ( new AbstractFlag ( " weather " ) {
@Override
2015-01-24 21:40:50 -07:00
public String parseValueRaw ( 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-12-29 00:56:01 +11:00
public static void removePlots ( final String world ) {
plots . put ( world , new HashMap < PlotId , Plot > ( ) ) ;
}
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 ) {
2015-02-08 10:44:53 +11:00
if ( id ! = null & & id . length ( ) > 0 ) {
// save configuration
String [ ] split = id . split ( " , " ) ;
HybridPlotWorld plotworld = new HybridPlotWorld ( world ) ;
int width = HybridPlotWorld . PLOT_WIDTH_DEFAULT ;
int gap = HybridPlotWorld . ROAD_WIDTH_DEFAULT ;
int height = HybridPlotWorld . PLOT_HEIGHT_DEFAULT ;
PlotBlock [ ] floor = HybridPlotWorld . TOP_BLOCK_DEFAULT ;
PlotBlock [ ] main = HybridPlotWorld . MAIN_BLOCK_DEFAULT ;
PlotBlock wall = HybridPlotWorld . WALL_FILLING_DEFAULT ;
PlotBlock border = HybridPlotWorld . WALL_BLOCK_DEFAULT ;
for ( String element : split ) {
String [ ] pair = element . split ( " = " ) ;
if ( pair . length ! = 2 ) {
sendConsoleSenderMessage ( " &cNo value provided for: &7 " + element ) ;
return null ;
}
String key = pair [ 0 ] . toLowerCase ( ) ;
String value = pair [ 1 ] ;
try {
switch ( key ) {
case " s " :
case " size " : {
HybridPlotWorld . PLOT_WIDTH_DEFAULT = ( ( Integer ) Configuration . INTEGER . parseString ( value ) ) . shortValue ( ) ;
break ;
}
case " g " :
case " gap " : {
HybridPlotWorld . ROAD_WIDTH_DEFAULT = ( ( Integer ) Configuration . INTEGER . parseString ( value ) ) . shortValue ( ) ;
break ;
}
case " h " :
case " height " : {
HybridPlotWorld . PLOT_HEIGHT_DEFAULT = ( Integer ) Configuration . INTEGER . parseString ( value ) ;
HybridPlotWorld . ROAD_HEIGHT_DEFAULT = ( Integer ) Configuration . INTEGER . parseString ( value ) ;
HybridPlotWorld . WALL_HEIGHT_DEFAULT = ( Integer ) Configuration . INTEGER . parseString ( value ) ;
break ;
}
case " f " :
case " floor " : {
HybridPlotWorld . TOP_BLOCK_DEFAULT = ( PlotBlock [ ] ) Configuration . BLOCKLIST . parseString ( value ) ;
break ;
}
case " m " :
case " main " : {
HybridPlotWorld . MAIN_BLOCK_DEFAULT = ( PlotBlock [ ] ) Configuration . BLOCKLIST . parseString ( value ) ;
break ;
}
case " w " :
case " wall " : {
HybridPlotWorld . WALL_FILLING_DEFAULT = ( PlotBlock ) Configuration . BLOCK . parseString ( value ) ;
break ;
}
case " b " :
case " border " : {
HybridPlotWorld . WALL_BLOCK_DEFAULT = ( PlotBlock ) Configuration . BLOCK . parseString ( value ) ;
break ;
}
default : {
sendConsoleSenderMessage ( " &cKey not found: &7 " + element ) ;
return null ;
}
}
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
sendConsoleSenderMessage ( " &cInvalid value: &7 " + value + " in arg " + element ) ;
return null ;
}
}
try {
String root = " worlds. " + world ;
if ( ! config . contains ( root ) ) {
config . createSection ( root ) ;
}
plotworld . saveConfiguration ( config . getConfigurationSection ( root ) ) ;
HybridPlotWorld . PLOT_HEIGHT_DEFAULT = height ;
HybridPlotWorld . ROAD_HEIGHT_DEFAULT = height ;
HybridPlotWorld . WALL_HEIGHT_DEFAULT = height ;
HybridPlotWorld . TOP_BLOCK_DEFAULT = floor ;
HybridPlotWorld . MAIN_BLOCK_DEFAULT = main ;
HybridPlotWorld . WALL_BLOCK_DEFAULT = border ;
HybridPlotWorld . WALL_FILLING_DEFAULT = wall ;
HybridPlotWorld . PLOT_WIDTH_DEFAULT = width ;
HybridPlotWorld . ROAD_WIDTH_DEFAULT = gap ;
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
2014-12-28 23:02:30 +11:00
return new HybridGen ( world ) ;
2014-11-09 12:29:35 +01:00
}
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 " ) ;
}
2015-01-10 12:00:26 +11:00
2014-11-09 12:29:35 +01:00
/ * *
* On Load .
* /
@Override
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 ( ) ;
2015-02-10 22:32:58 +11:00
C . saveTranslations ( ) ;
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 ( ) ;
2015-01-29 18:45:14 +11:00
defaultFlags ( ) ;
2014-11-09 12:29:35 +01:00
// 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 ) {
2015-01-20 16:31:06 -08:00
sendConsoleSenderMessage ( C . ENABLED ) ;
2014-11-09 12:29:35 +01:00
}
2015-01-29 18:45:14 +11:00
final String [ ] tables ;
2015-01-29 17:03:54 +11:00
if ( Settings . ENABLE_CLUSTERS ) {
MainCommand . subCommands . add ( new Cluster ( ) ) ;
2015-01-29 18:45:14 +11:00
tables = new String [ ] { " plot_trusted " , " plot_ratings " , " plot_comments " , " cluster " } ;
}
else {
tables = new String [ ] { " plot_trusted " , " plot_ratings " , " plot_comments " } ;
2015-01-29 17:03:54 +11:00
}
2014-11-09 12:29:35 +01:00
2014-11-16 10:16:38 +01:00
// Add tables to this one, if we create more :D
2015-01-29 18:45:14 +11:00
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 ( ) ;
2015-01-25 21:16:10 -07:00
if ( Settings . ENABLE_CLUSTERS ) {
ClusterManager . clusters = DBFunc . getClusters ( ) ;
}
2014-11-09 12:29:35 +01:00
}
// 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 {
2015-01-10 02:02:02 +11:00
connection = new SQLite ( this , this . getDataFolder ( ) + File . separator + Settings . DB . SQLITE_DB + " .db " ) . openConnection ( ) ;
2014-11-09 12:29:35 +01:00
{
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 ( ) ;
2015-01-25 21:16:10 -07:00
if ( Settings . ENABLE_CLUSTERS ) {
ClusterManager . clusters = DBFunc . getClusters ( ) ;
}
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 ;
}
// 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 ) ;
}
2015-02-08 14:49:00 +11:00
2014-11-09 12:29:35 +01:00
// Main event handler
getServer ( ) . getPluginManager ( ) . registerEvents ( new PlayerEvents ( ) , this ) ;
2015-02-08 14:49:00 +11:00
if ( checkVersion ( 1 , 8 , 0 ) ) {
getServer ( ) . getPluginManager ( ) . registerEvents ( new PlayerEvents_1_8 ( ) , this ) ;
}
2014-12-30 17:50:55 +11:00
// World load events
getServer ( ) . getPluginManager ( ) . registerEvents ( this , 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
2015-01-30 11:25:08 +11:00
getServer ( ) . getPluginManager ( ) . registerEvents ( new ForceFieldListener ( ) , this ) ;
2014-11-09 12:29:35 +01:00
// Default flags
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. " ) ;
2015-01-20 16:31:06 -08:00
PlotMain . sendConsoleSenderMessage ( " &cPlease use WorldEdit 6+ for masking support " ) ;
2014-12-04 15:00:08 +11:00
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 ) ;
2015-01-03 01:38:04 +11:00
MainCommand . subCommands . add ( new WE_Anywhere ( ) ) ;
2014-11-09 12:29:35 +01:00
}
}
2015-01-29 14:20:29 +11:00
// if (Settings.WORLDGUARD) {
// if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
// worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");
// worldGuardListener = new WorldGuardListener(this);
// getServer().getPluginManager().registerEvents(worldGuardListener, this);
// }
// }
2014-11-09 12:29:35 +01:00
if ( Settings . AUTO_CLEAR ) {
2015-01-10 01:05:10 +11:00
ExpireManager . runTask ( ) ;
2014-11-09 12:29:35 +01:00
}
// 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 ( ) ;
2015-01-13 20:09:13 +11:00
MainCommand . subCommands . add ( new Buy ( ) ) ;
2014-11-09 12:29:35 +01:00
}
}
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
{
2015-02-08 14:49:00 +11:00
boolean checkVersion = checkVersion ( 1 , 7 , 5 ) ;
2015-01-18 12:11:51 -08:00
if ( ! checkVersion ) {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature. " ) ;
2014-12-31 00:09:11 +11:00
Settings . TITLES = false ;
FlagManager . removeFlag ( FlagManager . getFlag ( " titles " ) ) ;
}
2015-01-18 12:11:51 -08:00
else {
AbstractTitle . TITLE_CLASS = new DefaultTitle ( ) ;
}
2014-12-13 22:59:43 +11:00
if ( Settings . OFFLINE_MODE ) {
UUIDHandler . uuidWrapper = new OfflineUUIDWrapper ( ) ;
2014-12-23 02:12:40 +11:00
Settings . OFFLINE_MODE = true ;
2014-12-13 22:59:43 +11:00
}
2015-01-02 00:22:59 +11:00
else if ( checkVersion ) {
2014-12-22 01:59:35 +11:00
UUIDHandler . uuidWrapper = new DefaultUUIDWrapper ( ) ;
2014-12-23 02:12:40 +11:00
Settings . OFFLINE_MODE = false ;
2014-12-22 01:59:35 +11:00
}
else {
UUIDHandler . uuidWrapper = new OfflineUUIDWrapper ( ) ;
2014-12-23 02:12:40 +11:00
Settings . OFFLINE_MODE = true ;
2014-12-22 01:59:35 +11:00
}
2014-12-23 02:12:40 +11:00
if ( Settings . OFFLINE_MODE ) {
2014-12-31 00:09:11 +11:00
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit " ) ;
2014-12-30 17:50:55 +11:00
}
else {
sendConsoleSenderMessage ( C . PREFIX . s ( ) + " &6PlotSquared is using online UUIDs " ) ;
2014-12-23 02:12:40 +11:00
}
2014-11-09 12:29:35 +01:00
}
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
}
2014-12-22 01:59:35 +11:00
2015-02-08 14:49:00 +11:00
public static boolean checkVersion ( int major , int minor , int minor2 ) {
2014-12-22 01:59:35 +11:00
try {
String [ ] version = Bukkit . getBukkitVersion ( ) . split ( " - " ) [ 0 ] . split ( " \\ . " ) ;
int a = Integer . parseInt ( version [ 0 ] ) ;
int b = Integer . parseInt ( version [ 1 ] ) ;
int c = 0 ;
if ( version . length = = 3 ) {
c = Integer . parseInt ( version [ 2 ] ) ;
}
2015-02-08 14:49:00 +11:00
if ( a > major | | ( a = = major & & b > minor ) | | ( a = = major & & b = = minor & & c > = minor2 ) ) {
return true ;
2014-12-22 01:59:35 +11:00
}
2015-02-08 14:49:00 +11:00
return false ;
2014-12-22 01:59:35 +11:00
}
catch ( Exception e ) {
return false ;
}
}
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
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
}