2015-02-19 07:08:15 +01:00
package com.intellectualcrafters.plot ;
2015-07-06 11:38:37 +02:00
import java.io.BufferedReader ;
2015-07-05 17:44:10 +02:00
import java.io.File ;
import java.io.FileInputStream ;
import java.io.FileOutputStream ;
import java.io.IOException ;
2015-07-06 11:38:37 +02:00
import java.io.InputStream ;
import java.io.InputStreamReader ;
import java.net.URL ;
import java.net.URLConnection ;
import java.nio.file.Files ;
2015-07-05 17:44:10 +02:00
import java.sql.Connection ;
import java.sql.DatabaseMetaData ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.Comparator ;
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 ;
2015-07-06 11:38:37 +02:00
import java.util.regex.Pattern ;
2015-07-05 17:44:10 +02:00
import java.util.zip.ZipEntry ;
import java.util.zip.ZipInputStream ;
import com.intellectualcrafters.configuration.file.YamlConfiguration ;
2015-07-03 11:30:26 +02:00
import com.intellectualcrafters.plot.config.C ;
import com.intellectualcrafters.plot.config.Configuration ;
import com.intellectualcrafters.plot.config.Settings ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.database.DBFunc ;
import com.intellectualcrafters.plot.database.Database ;
import com.intellectualcrafters.plot.database.MySQL ;
import com.intellectualcrafters.plot.database.SQLManager ;
import com.intellectualcrafters.plot.database.SQLite ;
2015-07-03 11:30:26 +02:00
import com.intellectualcrafters.plot.flag.AbstractFlag ;
import com.intellectualcrafters.plot.flag.FlagManager ;
import com.intellectualcrafters.plot.flag.FlagValue ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.generator.AugmentedPopulator ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.generator.ClassicPlotWorld ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.generator.HybridGen ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.generator.HybridPlotWorld ;
import com.intellectualcrafters.plot.generator.HybridUtils ;
import com.intellectualcrafters.plot.generator.SquarePlotManager ;
import com.intellectualcrafters.plot.generator.SquarePlotWorld ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.listeners.APlotListener ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.object.Plot ;
2015-07-17 18:50:32 +02:00
import com.intellectualcrafters.plot.object.PlotAnalysis ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.object.PlotBlock ;
import com.intellectualcrafters.plot.object.PlotCluster ;
2015-07-21 19:08:51 +02:00
import com.intellectualcrafters.plot.object.PlotFilter ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.object.PlotGenerator ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.object.PlotHandler ;
import com.intellectualcrafters.plot.object.PlotId ;
import com.intellectualcrafters.plot.object.PlotManager ;
import com.intellectualcrafters.plot.object.PlotPlayer ;
import com.intellectualcrafters.plot.object.PlotWorld ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.object.comment.CommentManager ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.util.BlockManager ;
import com.intellectualcrafters.plot.util.ChunkManager ;
import com.intellectualcrafters.plot.util.ClusterManager ;
import com.intellectualcrafters.plot.util.EconHandler ;
import com.intellectualcrafters.plot.util.EventUtil ;
import com.intellectualcrafters.plot.util.ExpireManager ;
import com.intellectualcrafters.plot.util.InventoryUtil ;
import com.intellectualcrafters.plot.util.Logger ;
2015-07-21 19:08:51 +02:00
import com.intellectualcrafters.plot.util.MathMan ;
import com.intellectualcrafters.plot.util.StringMan ;
2015-07-03 11:30:26 +02:00
import com.intellectualcrafters.plot.util.Logger.LogLevel ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.util.MainUtil ;
import com.intellectualcrafters.plot.util.PlayerManager ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.util.SetupUtils ;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.util.TaskManager ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.util.bukkit.UUIDHandler ;
import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler ;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler ;
2015-07-03 11:30:26 +02:00
import com.sk89q.worldedit.bukkit.WorldEditPlugin ;
2015-07-03 13:01:15 +02:00
2015-07-03 11:30:26 +02:00
/ * *
* An implementation of the core ,
* with a static getter for easy access
2015-07-03 12:32:32 +02:00
*
* @author Sauilitired | Citymonstret
* @author boy0001 | Empire92
2015-07-03 11:30:26 +02:00
* /
2015-07-03 14:15:20 +02:00
public class PS {
2015-07-03 12:32:32 +02:00
// protected static:
2015-07-26 16:51:12 +02:00
public static PS instance ;
2015-07-03 14:15:20 +02:00
2015-07-03 12:32:32 +02:00
// private final:
2015-07-03 11:30:26 +02:00
private final HashMap < String , PlotWorld > plotworlds = new HashMap < > ( ) ;
private final HashMap < String , PlotManager > plotmanagers = new HashMap < > ( ) ;
2015-07-03 12:32:32 +02:00
// public:
2015-07-03 11:30:26 +02:00
public WorldEditPlugin worldEdit = null ;
2015-07-03 11:45:00 +02:00
public File configFile ;
2015-07-05 17:44:10 +02:00
public File translationFile ;
public YamlConfiguration style ;
2015-07-03 11:45:00 +02:00
public YamlConfiguration config ;
public YamlConfiguration storage ;
2015-07-03 12:32:32 +02:00
public IPlotMain IMP = null ;
2015-07-03 11:45:00 +02:00
public TaskManager TASK ;
2015-07-06 11:38:37 +02:00
public URL update ;
2015-07-03 12:32:32 +02:00
// private:
2015-07-03 11:30:26 +02:00
private File styleFile ;
private File storageFile ;
private File FILE = null ; // This file
private String VERSION = null ;
2015-07-12 21:08:41 +02:00
private String LAST_VERSION ;
2015-07-03 11:30:26 +02:00
private boolean LOADING_WORLD = false ;
private LinkedHashMap < String , HashMap < PlotId , Plot > > plots ;
private Database database ;
private Connection connection ;
2015-07-03 13:01:15 +02:00
/ * *
* Initialize PlotSquared with the desired Implementation class
* @param imp_class
* /
2015-07-26 16:51:12 +02:00
public PS ( final IPlotMain imp_class ) {
2015-07-04 08:37:33 +02:00
instance = this ;
2015-07-03 11:30:26 +02:00
SetupUtils . generators = new HashMap < > ( ) ;
IMP = imp_class ;
try {
2015-07-03 14:15:20 +02:00
FILE = new File ( PS . class . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . toURI ( ) . getPath ( ) ) ;
2015-07-03 11:30:26 +02:00
} catch ( Exception e ) {
log ( " Could not determine file path " ) ;
}
VERSION = IMP . getVersion ( ) ;
EconHandler . manager = IMP . getEconomyHandler ( ) ;
if ( getJavaVersion ( ) < 1 . 7 ) {
log ( C . PREFIX . s ( ) + " &cYour java version is outdated. Please update to at least 1.7. " ) ;
// Didn't know of any other link :D
log ( C . PREFIX . s ( ) + " &cURL: &6https://java.com/en/download/index.jsp " ) ;
IMP . disable ( ) ;
return ;
}
if ( getJavaVersion ( ) < 1 . 8 ) {
log ( C . PREFIX . s ( ) + " &cIt's really recommended to run Java 1.8, as it increases performance " ) ;
}
2015-07-03 11:45:00 +02:00
this . TASK = IMP . getTaskManager ( ) ;
2015-07-03 11:30:26 +02:00
if ( C . ENABLED . s ( ) . length ( ) > 0 ) {
log ( C . ENABLED . s ( ) ) ;
}
setupConfigs ( ) ;
2015-07-05 17:44:10 +02:00
this . translationFile = new File ( IMP . getDirectory ( ) + File . separator + " translations " + File . separator + " PlotSquared.use_THIS.yml " ) ;
C . load ( translationFile ) ;
2015-07-03 11:30:26 +02:00
setupDefaultFlags ( ) ;
setupDatabase ( ) ;
CommentManager . registerDefaultInboxes ( ) ;
// Tasks
if ( Settings . KILL_ROAD_MOBS ) {
IMP . runEntityTask ( ) ;
}
// Events
IMP . registerCommands ( ) ;
IMP . registerPlayerEvents ( ) ;
IMP . registerInventoryEvents ( ) ;
IMP . registerPlotPlusEvents ( ) ;
IMP . registerForceFieldEvents ( ) ;
IMP . registerWorldEditEvents ( ) ;
IMP . registerWorldEvents ( ) ;
if ( Settings . TNT_LISTENER ) {
IMP . registerTNTListener ( ) ;
}
if ( Settings . CHUNK_PROCESSOR ) {
IMP . registerChunkProcessor ( ) ;
}
// create UUIDWrapper
2015-07-24 16:06:58 +02:00
UUIDHandler . setUUIDWrapper ( IMP . initUUIDHandler ( ) ) ;
2015-07-03 11:30:26 +02:00
// create event util class
EventUtil . manager = IMP . initEventUtil ( ) ;
// create Hybrid utility class
HybridUtils . manager = IMP . initHybridUtils ( ) ;
// Inventory utility class
InventoryUtil . manager = IMP . initInventoryUtil ( ) ;
// create setup util class
SetupUtils . manager = IMP . initSetupUtils ( ) ;
// Set block
BlockManager . manager = IMP . initBlockManager ( ) ;
// Set chunk
ChunkManager . manager = IMP . initChunkManager ( ) ;
// Plot listener
APlotListener . manager = IMP . initPlotListener ( ) ;
// Player manager
PlayerManager . manager = IMP . initPlayerManager ( ) ;
2015-07-06 11:38:37 +02:00
// Check for updates
TaskManager . runTaskAsync ( new Runnable ( ) {
@Override
public void run ( ) {
URL url = getUpdate ( ) ;
if ( url ! = null ) {
update = url ;
log ( " &6You are running an older version of PlotSquared... " ) ;
log ( " &8 - &3Use: &7/plot update " ) ;
log ( " &8 - &3Or: &7 " + url ) ;
}
2015-07-12 21:08:41 +02:00
else if ( LAST_VERSION ! = null & & ! VERSION . equals ( LAST_VERSION ) ) {
log ( " &aThanks for updating from: " + LAST_VERSION + " to " + VERSION ) ;
}
2015-07-06 11:38:37 +02:00
}
} ) ;
2015-07-03 11:30:26 +02:00
// PlotMe
if ( Settings . CONVERT_PLOTME | | Settings . CACHE_PLOTME ) {
TaskManager . runTaskLater ( new Runnable ( ) {
2015-07-03 12:16:20 +02:00
2015-07-03 11:30:26 +02:00
public void run ( ) {
if ( IMP . initPlotMeConverter ( ) ) {
log ( " &c=== IMPORTANT === " ) ;
log ( " &cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME! " ) ;
log ( " &c - Make sure 'UUID.read-from-disk' is disabled (false)! " ) ;
log ( " &c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue! " ) ;
log ( " &c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml' " ) ;
}
}
} , 200 ) ;
}
if ( Settings . AUTO_CLEAR ) {
ExpireManager . runTask ( ) ;
}
// Copy files
copyFile ( " town.template " , " templates " ) ;
copyFile ( " skyblock.template " , " templates " ) ;
copyFile ( " german.yml " , " translations " ) ;
copyFile ( " s_chinese_unescaped.yml " , " translations " ) ;
copyFile ( " s_chinese.yml " , " translations " ) ;
copyFile ( " italian.yml " , " translations " ) ;
showDebug ( ) ;
}
2015-07-03 14:15:20 +02:00
2015-07-03 12:32:32 +02:00
/ * *
* Get the instance of PlotSquared
*
* @return the instance created by IPlotMain
* /
2015-07-03 14:15:20 +02:00
public static PS get ( ) {
2015-07-03 11:30:26 +02:00
return instance ;
}
2015-07-12 21:08:41 +02:00
/ * *
* Get the last PlotSquared version
* @return last version in config or null
* /
public String getLastVersion ( ) {
return LAST_VERSION ;
}
/ * *
* Get the current PlotSquared version
* @return current version in config or null
* /
public String getVersion ( ) {
return VERSION ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:32:32 +02:00
/ * *
* Log a message to the IPlotMain logger
*
* @param message Message to log
* @see IPlotMain # log ( String )
* /
2015-07-03 11:30:26 +02:00
public static void log ( final String message ) {
2015-07-03 14:15:20 +02:00
get ( ) . IMP . log ( message ) ;
2015-07-03 11:30:26 +02:00
}
2015-07-03 12:32:32 +02:00
/ * *
* Get the database object
*
* @return Database object
* @see # getConnection ( ) Get the database connection
* /
2015-07-03 11:30:26 +02:00
public Database getDatabase ( ) {
2015-04-29 15:07:12 +02:00
return database ;
2015-02-19 07:08:15 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:32:32 +02:00
/ * *
* Update the global reference
* to a plot object
*
* @param plot Plot Object to update
* /
2015-07-03 11:30:26 +02:00
public void updatePlot ( final Plot plot ) {
2015-02-19 09:51:10 +01:00
final String world = plot . world ;
if ( ! plots . containsKey ( world ) ) {
plots . put ( world , new HashMap < PlotId , Plot > ( ) ) ;
}
plots . get ( world ) . put ( plot . id , plot ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:32:32 +02:00
/ * *
* Get the plot world based on the
* name identifier
*
* @param world World Name
* @return plot world | null if not existing
* @see # getPlotWorldsString ( ) Get all plot world names
* /
2015-07-03 11:30:26 +02:00
public PlotWorld getPlotWorld ( final String world ) {
2015-02-19 09:51:10 +01:00
if ( plotworlds . containsKey ( world ) ) {
return plotworlds . get ( world ) ;
}
return null ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:32:32 +02:00
/ * *
* Add a global reference to a plot world
*
* @param world World Name
* @param plotworld PlotWorld Instance
* @param manager PlotManager
* @see # removePlotWorld ( String ) To remove the reference
* /
2015-07-03 11:30:26 +02:00
public void addPlotWorld ( final String world , final PlotWorld plotworld , final PlotManager manager ) {
2015-02-19 09:51:10 +01:00
plotworlds . put ( world , plotworld ) ;
plotmanagers . put ( world , manager ) ;
if ( ! plots . containsKey ( world ) ) {
plots . put ( world , new HashMap < PlotId , Plot > ( ) ) ;
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:32:32 +02:00
/ * *
* Remove a plot world reference
*
* @param world World name
* @see # addPlotWorld ( String , PlotWorld , PlotManager ) To add a reference
* /
2015-07-03 11:30:26 +02:00
public void removePlotWorld ( final String world ) {
2015-02-19 09:51:10 +01:00
plots . remove ( world ) ;
plotmanagers . remove ( world ) ;
plotworlds . remove ( world ) ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:32:32 +02:00
/ * *
* @param world World Name
* /
2015-07-03 11:30:26 +02:00
public void removePlotWorldAbs ( final String world ) {
2015-06-05 18:04:36 +02:00
plotmanagers . remove ( world ) ;
plotworlds . remove ( world ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:32:32 +02:00
/ * *
* Get all plots as raw objects
*
* @see # getPlots ( ) To get the plot objects
* @see # getPlotsRaw ( ) To get the plot objects
*
* @return HashMap containing the world name , and another map with the plot id and the plot object
* /
2015-07-03 11:30:26 +02:00
public HashMap < String , HashMap < PlotId , Plot > > getAllPlotsRaw ( ) {
2015-02-20 06:40:51 +01:00
return plots ;
}
2015-07-21 19:08:51 +02:00
/ * *
* A more generic way to filter plots - make your own method if you need complex filters
* @param filters
* @return
* /
public Set < Plot > getPlots ( PlotFilter . . . filters ) {
HashSet < Plot > set = new HashSet < > ( ) ;
for ( Entry < String , HashMap < PlotId , Plot > > entry : plots . entrySet ( ) ) {
for ( PlotFilter filter : filters ) {
if ( ! filter . allowsWorld ( entry . getKey ( ) ) ) {
continue ;
}
}
for ( Plot plot : entry . getValue ( ) . values ( ) ) {
for ( PlotFilter filter : filters ) {
if ( ! filter . allowsPlot ( plot ) ) {
continue ;
}
}
set . add ( plot ) ;
}
}
return set ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Set all the plots as a raw object
* @see # getAllPlotsRaw ( ) to get the raw plot object
* @param plots
* /
2015-07-03 11:30:26 +02:00
public void setAllPlotsRaw ( final LinkedHashMap < String , HashMap < PlotId , Plot > > plots ) {
this . plots = plots ;
2015-02-19 09:51:10 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get all the plots in a single set
* @return Set of Plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( ) {
2015-02-19 09:51:10 +01:00
final ArrayList < Plot > newplots = new ArrayList < > ( ) ;
2015-03-12 09:52:26 +01:00
for ( final Entry < String , HashMap < PlotId , Plot > > entry : plots . entrySet ( ) ) {
if ( isPlotWorld ( entry . getKey ( ) ) ) {
newplots . addAll ( entry . getValue ( ) . values ( ) ) ;
}
2015-02-19 09:51:10 +01:00
}
return new LinkedHashSet < > ( newplots ) ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the raw plot object
* @return set of plot
* @see # setAllPlotsRaw ( LinkedHashMap ) to set the raw plot object
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlotsRaw ( ) {
2015-04-11 06:07:19 +02:00
final ArrayList < Plot > newplots = new ArrayList < > ( ) ;
for ( final Entry < String , HashMap < PlotId , Plot > > entry : plots . entrySet ( ) ) {
newplots . addAll ( entry . getValue ( ) . values ( ) ) ;
}
return new LinkedHashSet < > ( newplots ) ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
2015-07-21 19:08:51 +02:00
* Sort a collection of plots by the hashcode ( assumes that all plots are in the same world )
2015-07-03 13:01:15 +02:00
* @param plots
* @return ArrayList of plot
* /
2015-07-21 19:08:51 +02:00
@Deprecated
2015-07-03 11:30:26 +02:00
public ArrayList < Plot > sortPlots ( Collection < Plot > plots ) {
2015-07-21 19:08:51 +02:00
return sortPlotsByWorld ( plots ) ;
}
/ * *
* Sort plots by hashcode
* @param plots
* @return
* /
public ArrayList < Plot > sortPlotsByHash ( Collection < Plot > plots ) {
int hardmax = 256000 ;
int max = 0 ;
int overflowSize = 0 ;
for ( Plot plot : plots ) {
int hash = MathMan . getPositiveId ( plot . hashCode ( ) ) ;
if ( hash > max ) {
if ( hash > = hardmax ) {
overflowSize + + ;
2015-03-11 11:27:30 +01:00
}
else {
2015-07-21 19:08:51 +02:00
max = hash ;
2015-03-11 11:27:30 +01:00
}
2015-07-21 19:08:51 +02:00
}
}
hardmax = Math . min ( hardmax , max ) ;
Plot [ ] cache = new Plot [ hardmax + 1 ] ;
List < Plot > overflow = new ArrayList < Plot > ( overflowSize ) ;
for ( Plot plot : plots ) {
int hash = MathMan . getPositiveId ( plot . hashCode ( ) ) ;
if ( hash < hardmax ) {
cache [ hash ] = plot ;
}
else {
overflow . add ( plot ) ;
}
}
Plot [ ] overflowArray = overflow . toArray ( new Plot [ overflow . size ( ) ] ) ;
sortPlotsByHash ( overflowArray ) ;
ArrayList < Plot > result = new ArrayList < Plot > ( cache . length + overflowArray . length ) ;
for ( Plot plot : cache ) {
if ( plot ! = null ) {
result . add ( plot ) ;
}
}
for ( Plot plot : overflowArray ) {
result . add ( plot ) ;
}
return result ;
}
public static void sortPlotsByHash ( Plot [ ] input ) {
final int SIZE = 100 ;
List < Plot > [ ] bucket = new ArrayList [ SIZE ] ;
for ( int i = 0 ; i < bucket . length ; i + + ) {
bucket [ i ] = new ArrayList < Plot > ( ) ;
}
boolean maxLength = false ;
int tmp = - 1 , placement = 1 ;
while ( ! maxLength ) {
maxLength = true ;
for ( Plot i : input ) {
tmp = MathMan . getPositiveId ( i . hashCode ( ) ) / placement ;
bucket [ tmp % SIZE ] . add ( i ) ;
if ( maxLength & & tmp > 0 ) {
maxLength = false ;
2015-03-11 11:27:30 +01:00
}
2015-07-21 19:08:51 +02:00
}
int a = 0 ;
for ( int b = 0 ; b < SIZE ; b + + ) {
for ( Plot i : bucket [ b ] ) {
input [ a + + ] = i ;
2015-03-11 11:27:30 +01:00
}
2015-07-21 19:08:51 +02:00
bucket [ b ] . clear ( ) ;
2015-03-08 08:59:00 +01:00
}
2015-07-21 19:08:51 +02:00
placement * = SIZE ;
}
2015-03-08 08:59:00 +01:00
}
2015-07-21 19:08:51 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Sort a collection of plots by world ( with a priority world ) , then by hashcode
* @param plots
2015-07-21 19:08:51 +02:00
* @param priorityWorld - Use " world " or " gibberish " if you don ' t care
2015-07-03 13:01:15 +02:00
* @see # sortPlotsByWorld ( Collection ) to sort plots by world , then by hashcode
* @see # sortPlots ( Collection ) to sort plots just by hashcode
* @return ArrayList of plot
* /
2015-07-03 11:30:26 +02:00
public ArrayList < Plot > sortPlots ( Collection < Plot > plots , final String priorityWorld ) {
2015-07-21 19:08:51 +02:00
// group by world
// sort each
HashMap < String , Collection < Plot > > map = new HashMap < > ( ) ;
ArrayList < String > worlds = new ArrayList < String > ( getPlotWorlds ( ) ) ;
int totalSize = 0 ;
for ( Entry < String , HashMap < PlotId , Plot > > entry : this . plots . entrySet ( ) ) {
totalSize + = entry . getValue ( ) . size ( ) ;
}
if ( plots . size ( ) = = totalSize ) {
for ( Entry < String , HashMap < PlotId , Plot > > entry : this . plots . entrySet ( ) ) {
map . put ( entry . getKey ( ) , entry . getValue ( ) . values ( ) ) ;
}
}
else {
for ( String world : worlds ) {
map . put ( world , new ArrayList < Plot > ( plots . size ( ) / worlds . size ( ) ) ) ;
}
Collection < Plot > lastList = null ;
String lastWorld = " " ;
for ( Plot plot : plots ) {
if ( StringMan . isEqual ( lastWorld , plot . world ) ) {
lastList . add ( plot ) ;
}
else {
lastWorld = plot . world ;
lastList = map . get ( lastWorld ) ;
lastList . add ( plot ) ;
2015-03-11 13:26:39 +01:00
}
}
2015-03-11 11:27:30 +01:00
}
2015-07-21 19:08:51 +02:00
Collections . sort ( worlds , new Comparator < String > ( ) {
@Override
public int compare ( String a , String b ) {
if ( StringMan . isEqual ( a , priorityWorld ) ) {
return - 1 ;
2015-03-11 13:26:39 +01:00
}
2015-07-21 19:08:51 +02:00
return a . hashCode ( ) - b . hashCode ( ) ;
2015-03-08 08:59:00 +01:00
}
2015-07-21 19:08:51 +02:00
} ) ;
ArrayList < Plot > toReturn = new ArrayList < Plot > ( plots . size ( ) ) ;
for ( String world : worlds ) {
toReturn . addAll ( sortPlotsByHash ( map . get ( world ) ) ) ;
2015-03-11 11:27:30 +01:00
}
2015-07-21 19:08:51 +02:00
return toReturn ;
2015-02-19 09:51:10 +01:00
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Sort a collection of plots by world , then by hashcode
* @param plots
* @see # sortPlots ( Collection , String ) to sort with a specific priority world
* @see # sortPlots ( Collection ) to sort plots just by hashcode
* @return ArrayList of plot
* /
2015-07-03 11:30:26 +02:00
public ArrayList < Plot > sortPlotsByWorld ( Collection < Plot > plots ) {
2015-04-03 04:42:49 +02:00
ArrayList < Plot > newPlots = new ArrayList < > ( ) ;
2015-07-03 11:30:26 +02:00
ArrayList < String > worlds = new ArrayList < > ( this . plots . keySet ( ) ) ;
2015-07-21 19:08:51 +02:00
HashSet < Plot > set = new HashSet < > ( plots ) ;
2015-04-03 04:42:49 +02:00
Collections . sort ( worlds ) ;
for ( String world : worlds ) {
2015-07-03 11:30:26 +02:00
for ( Plot plot : this . plots . get ( world ) . values ( ) ) {
2015-07-21 19:08:51 +02:00
if ( set . contains ( plot ) ) {
2015-04-03 04:42:49 +02:00
newPlots . add ( plot ) ;
}
}
}
return newPlots ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get all the plots owned by a player name
* @param world
* @param player
* @return Set of Plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( final String world , final String player ) {
2015-02-19 09:51:10 +01:00
final UUID uuid = UUIDHandler . getUUID ( player ) ;
return getPlots ( world , uuid ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Get all plots by a PlotPlayer
* @param world
* @param player
* @return Set of plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( final String world , final PlotPlayer player ) {
2015-02-22 13:51:02 +01:00
final UUID uuid = player . getUUID ( ) ;
return getPlots ( world , uuid ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Get all plots by a UUID in a world
* @param world
* @param uuid
* @return Set of plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( final String world , final UUID uuid ) {
2015-02-19 09:51:10 +01:00
final ArrayList < Plot > myplots = new ArrayList < > ( ) ;
for ( final Plot plot : getPlots ( world ) . values ( ) ) {
if ( plot . hasOwner ( ) ) {
2015-03-20 03:13:27 +01:00
if ( PlotHandler . isOwner ( plot , uuid ) ) {
2015-02-19 09:51:10 +01:00
myplots . add ( plot ) ;
}
}
}
return new HashSet < > ( myplots ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Check if a plot world
* @param world
* @see # getPlotWorld ( String ) to get the PlotWorld object
* @return if a plot world is registered
* /
2015-07-03 11:30:26 +02:00
public boolean isPlotWorld ( final String world ) {
2015-02-19 09:51:10 +01:00
return ( plotworlds . containsKey ( world ) ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the plot manager for a world
* @param world
* @return the PlotManager object , or null if no registered PlotManager
* /
2015-07-03 11:30:26 +02:00
public PlotManager getPlotManager ( final String world ) {
2015-02-19 09:51:10 +01:00
if ( plotmanagers . containsKey ( world ) ) {
return plotmanagers . get ( world ) ;
}
return null ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Get a list of the plot worlds
* @return A String array of the plot world names
* /
2015-07-03 11:30:26 +02:00
public String [ ] getPlotWorldsString ( ) {
2015-02-19 09:51:10 +01:00
final Set < String > strings = plots . keySet ( ) ;
return strings . toArray ( new String [ strings . size ( ) ] ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get a map of the plots for a world
* @param world
* @return HashMap of PlotId to Plot
* /
2015-07-03 11:30:26 +02:00
public HashMap < PlotId , Plot > getPlots ( final String world ) {
2015-02-19 09:51:10 +01:00
if ( plots . containsKey ( world ) ) {
return plots . get ( world ) ;
}
return new HashMap < > ( ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the plots for a PlotPlayer
* @param player
* @return Set of Plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( final PlotPlayer player ) {
2015-03-08 08:59:00 +01:00
return getPlots ( player . getUUID ( ) ) ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the plots for a UUID
* @param uuid
* @return Set of Plot
* /
2015-07-03 11:30:26 +02:00
public Set < Plot > getPlots ( final UUID uuid ) {
2015-02-22 08:07:02 +01:00
final ArrayList < Plot > myplots = new ArrayList < > ( ) ;
for ( final String world : plots . keySet ( ) ) {
if ( isPlotWorld ( world ) ) {
for ( final Plot plot : plots . get ( world ) . values ( ) ) {
if ( plot . hasOwner ( ) ) {
2015-03-20 03:13:27 +01:00
if ( PlotHandler . isOwner ( plot , uuid ) ) {
2015-02-22 08:07:02 +01:00
myplots . add ( plot ) ;
}
}
}
}
}
return new HashSet < > ( myplots ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Unregister a plot from local memory ( does not call DB )
* @param world
* @param id
* @param callEvent If to call an event about the plot being removed
* @return true if plot existed | false if it didn ' t
* /
2015-07-03 11:30:26 +02:00
public boolean removePlot ( final String world , final PlotId id , final boolean callEvent ) {
2015-05-28 17:42:17 +02:00
if ( callEvent ) {
EventUtil . manager . callDelete ( world , id ) ;
}
2015-07-04 08:37:33 +02:00
HashMap < PlotId , Plot > allPlots = plots . get ( world ) ;
if ( allPlots = = null ) {
return false ;
}
Plot plot = allPlots . remove ( id ) ;
2015-02-20 12:23:48 +01:00
if ( MainUtil . lastPlot . containsKey ( world ) ) {
final PlotId last = MainUtil . lastPlot . get ( world ) ;
2015-02-20 07:34:19 +01:00
final int last_max = Math . max ( last . x , last . y ) ;
final int this_max = Math . max ( id . x , id . y ) ;
2015-02-19 09:51:10 +01:00
if ( this_max < last_max ) {
2015-02-20 12:23:48 +01:00
MainUtil . lastPlot . put ( world , id ) ;
2015-02-19 09:51:10 +01:00
}
}
2015-07-03 13:01:15 +02:00
return plot ! = null ;
2015-02-19 09:51:10 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* This method is called by the PlotGenerator class normally < br >
* - Initializes the PlotWorld and PlotManager classes < br >
* - Registers the PlotWorld and PlotManager classes < br >
* - Loads ( and / or generates ) the PlotWorld configuration < br >
* - Sets up the world border if configured < br >
* If loading an augmented plot world : < br >
* - Creates the AugmentedPopulator classes < br >
* - Injects the AugmentedPopulator classes if required
* @param world The world to load
* @param generator The generator for that world , or null if no generator
* /
2015-07-03 11:30:26 +02:00
public void loadWorld ( final String world , PlotGenerator generator ) {
PlotWorld plotWorld = getPlotWorld ( world ) ;
2015-02-24 12:27:30 +01:00
if ( plotWorld ! = null ) {
if ( generator ! = null ) {
generator . init ( plotWorld ) ;
}
2015-02-19 09:51:10 +01:00
return ;
}
final Set < String > worlds = ( config . contains ( " worlds " ) ? config . getConfigurationSection ( " worlds " ) . getKeys ( false ) : new HashSet < String > ( ) ) ;
final PlotGenerator plotGenerator ;
final PlotManager plotManager ;
final String path = " worlds. " + world ;
2015-07-03 11:45:00 +02:00
if ( ! LOADING_WORLD & & ( generator ! = null ) ) {
2015-02-20 07:34:19 +01:00
plotGenerator = generator ;
2015-02-19 09:51:10 +01:00
plotWorld = plotGenerator . getNewPlotWorld ( world ) ;
plotManager = plotGenerator . getPlotManager ( ) ;
if ( ! world . equals ( " CheckingPlotSquaredGenerator " ) ) {
log ( C . PREFIX . s ( ) + " &aDetected world load for ' " + world + " ' " ) ;
log ( C . PREFIX . s ( ) + " &3 - generator: &7 " + plotGenerator . getClass ( ) . getName ( ) ) ;
log ( C . PREFIX . s ( ) + " &3 - plotworld: &7 " + plotWorld . getClass ( ) . getName ( ) ) ;
log ( C . PREFIX . s ( ) + " &3 - manager: &7 " + plotManager . getClass ( ) . getName ( ) ) ;
}
if ( ! config . contains ( path ) ) {
config . createSection ( path ) ;
}
plotWorld . saveConfiguration ( config . getConfigurationSection ( path ) ) ;
plotWorld . loadDefaultConfiguration ( config . getConfigurationSection ( path ) ) ;
try {
config . save ( configFile ) ;
} catch ( final IOException e ) {
e . printStackTrace ( ) ;
}
// Now add it
addPlotWorld ( world , plotWorld , plotManager ) ;
2015-02-24 12:27:30 +01:00
generator . init ( plotWorld ) ;
2015-02-20 12:23:48 +01:00
MainUtil . setupBorder ( world ) ;
2015-02-19 09:51:10 +01:00
} else {
if ( ! worlds . contains ( world ) ) {
return ;
}
if ( ! LOADING_WORLD ) {
LOADING_WORLD = true ;
try {
2015-02-20 07:34:19 +01:00
final String gen_string = config . getString ( " worlds. " + world + " . " + " generator.plugin " ) ;
2015-02-19 09:51:10 +01:00
if ( gen_string = = null ) {
2015-05-09 08:24:03 +02:00
generator = new HybridGen ( world ) ;
2015-02-20 07:34:19 +01:00
} else {
2015-02-26 10:27:49 +01:00
generator = ( PlotGenerator ) IMP . getGenerator ( world , gen_string ) ;
2015-02-19 09:51:10 +01:00
}
2015-02-26 10:27:49 +01:00
loadWorld ( world , generator ) ;
2015-02-20 07:34:19 +01:00
} catch ( final Exception e ) {
2015-02-19 09:51:10 +01:00
log ( " &d=== Oh no! Please set the generator for the " + world + " === " ) ;
e . printStackTrace ( ) ;
LOADING_WORLD = false ;
removePlotWorld ( world ) ;
} finally {
LOADING_WORLD = false ;
}
} else {
2015-02-20 07:34:19 +01:00
final PlotGenerator gen_class = generator ;
2015-02-19 09:51:10 +01:00
plotWorld = gen_class . getNewPlotWorld ( world ) ;
plotManager = gen_class . getPlotManager ( ) ;
2015-07-03 11:30:26 +02:00
2015-02-19 09:51:10 +01:00
if ( ! config . contains ( path ) ) {
config . createSection ( path ) ;
}
2015-06-09 20:54:00 +02:00
plotWorld . TYPE = generator instanceof PlotGenerator ? 0 : 2 ;
2015-02-19 09:51:10 +01:00
plotWorld . TERRAIN = 0 ;
plotWorld . saveConfiguration ( config . getConfigurationSection ( path ) ) ;
plotWorld . loadDefaultConfiguration ( config . getConfigurationSection ( path ) ) ;
2015-07-03 11:30:26 +02:00
2015-02-19 09:51:10 +01:00
try {
config . save ( configFile ) ;
} catch ( final IOException e ) {
e . printStackTrace ( ) ;
}
2015-07-03 11:30:26 +02:00
2015-02-20 07:34:19 +01:00
if ( ( ( plotWorld . TYPE = = 2 ) & & ! Settings . ENABLE_CLUSTERS ) | | ! ( plotManager instanceof SquarePlotManager ) ) {
2015-02-19 09:51:10 +01:00
log ( " &c[ERROR] World ' " + world + " ' in settings.yml is not using PlotSquared generator! Please set the generator correctly or delete the world from the 'settings.yml'! " ) ;
return ;
}
2015-07-04 15:38:47 +02:00
log ( C . PREFIX . s ( ) + " &aDetected world load for ' " + world + " ' " ) ;
log ( C . PREFIX . s ( ) + " &3 - generator: &7 " + gen_class . getClass ( ) . getName ( ) ) ;
log ( C . PREFIX . s ( ) + " &3 - plotworld: &7 " + plotWorld . getClass ( ) . getName ( ) ) ;
log ( C . PREFIX . s ( ) + " &3 - manager: &7 " + plotManager . getClass ( ) . getName ( ) ) ;
log ( C . PREFIX . s ( ) + " &3 - | terrain: &7 " + plotWorld . TERRAIN ) ;
log ( C . PREFIX . s ( ) + " &3 - | type: &7 " + plotWorld . TYPE ) ;
2015-02-19 09:51:10 +01:00
addPlotWorld ( world , plotWorld , plotManager ) ;
if ( plotWorld . TYPE = = 2 ) {
if ( ClusterManager . getClusters ( world ) . size ( ) > 0 ) {
2015-02-20 07:34:19 +01:00
for ( final PlotCluster cluster : ClusterManager . getClusters ( world ) ) {
2015-07-04 15:38:47 +02:00
log ( C . PREFIX . s ( ) + " &3 - &7| cluster: " + cluster ) ;
2015-02-19 09:51:10 +01:00
new AugmentedPopulator ( world , gen_class , cluster , plotWorld . TERRAIN = = 2 , plotWorld . TERRAIN ! = 2 ) ;
}
}
} else if ( plotWorld . TYPE = = 1 ) {
new AugmentedPopulator ( world , gen_class , null , plotWorld . TERRAIN = = 2 , plotWorld . TERRAIN ! = 2 ) ;
}
2015-02-24 12:27:30 +01:00
gen_class . init ( plotWorld ) ;
2015-02-19 09:51:10 +01:00
}
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the configuration for a plot world based on world arguments < br >
* e . g . / mv create < world > normal - g PlotSquared : < args >
* @param world The name of the world
* @param args The arguments
* @return boolean | if valid arguments were provided
* /
public boolean setupPlotWorld ( final String world , final String args ) {
if ( ( args ! = null ) & & ( args . length ( ) > 0 ) ) {
2015-02-19 09:51:10 +01:00
// save configuration
2015-07-03 13:01:15 +02:00
final String [ ] split = args . split ( " , " ) ;
2015-02-20 07:34:19 +01:00
final HybridPlotWorld plotworld = new HybridPlotWorld ( world ) ;
final int width = SquarePlotWorld . PLOT_WIDTH_DEFAULT ;
final int gap = SquarePlotWorld . ROAD_WIDTH_DEFAULT ;
final int height = ClassicPlotWorld . PLOT_HEIGHT_DEFAULT ;
final PlotBlock [ ] floor = ClassicPlotWorld . TOP_BLOCK_DEFAULT ;
final PlotBlock [ ] main = ClassicPlotWorld . MAIN_BLOCK_DEFAULT ;
final PlotBlock wall = ClassicPlotWorld . WALL_FILLING_DEFAULT ;
final PlotBlock border = ClassicPlotWorld . WALL_BLOCK_DEFAULT ;
for ( final String element : split ) {
final String [ ] pair = element . split ( " = " ) ;
2015-02-19 09:51:10 +01:00
if ( pair . length ! = 2 ) {
log ( " &cNo value provided for: &7 " + element ) ;
return false ;
}
2015-02-20 07:34:19 +01:00
final String key = pair [ 0 ] . toLowerCase ( ) ;
final String value = pair [ 1 ] ;
2015-02-19 09:51:10 +01:00
try {
switch ( key ) {
case " s " :
case " size " : {
2015-07-03 11:30:26 +02:00
SquarePlotWorld . PLOT_WIDTH_DEFAULT = Configuration . INTEGER . parseString ( value ) . shortValue ( ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " g " :
case " gap " : {
2015-07-03 11:30:26 +02:00
SquarePlotWorld . ROAD_WIDTH_DEFAULT = Configuration . INTEGER . parseString ( value ) . shortValue ( ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " h " :
case " height " : {
2015-07-03 11:30:26 +02:00
ClassicPlotWorld . PLOT_HEIGHT_DEFAULT = Configuration . INTEGER . parseString ( value ) ;
ClassicPlotWorld . ROAD_HEIGHT_DEFAULT = Configuration . INTEGER . parseString ( value ) ;
ClassicPlotWorld . WALL_HEIGHT_DEFAULT = Configuration . INTEGER . parseString ( value ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " f " :
case " floor " : {
2015-07-03 11:30:26 +02:00
ClassicPlotWorld . TOP_BLOCK_DEFAULT = Configuration . BLOCKLIST . parseString ( value ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " m " :
case " main " : {
2015-07-03 11:30:26 +02:00
ClassicPlotWorld . MAIN_BLOCK_DEFAULT = Configuration . BLOCKLIST . parseString ( value ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " w " :
case " wall " : {
2015-07-03 11:30:26 +02:00
ClassicPlotWorld . WALL_FILLING_DEFAULT = Configuration . BLOCK . parseString ( value ) ;
2015-02-19 09:51:10 +01:00
break ;
}
case " b " :
case " border " : {
2015-07-03 11:30:26 +02:00
ClassicPlotWorld . WALL_BLOCK_DEFAULT = Configuration . BLOCK . parseString ( value ) ;
2015-02-19 09:51:10 +01:00
break ;
}
default : {
log ( " &cKey not found: &7 " + element ) ;
return false ;
}
}
2015-02-20 07:34:19 +01:00
} catch ( final Exception e ) {
2015-02-19 09:51:10 +01:00
e . printStackTrace ( ) ;
log ( " &cInvalid value: &7 " + value + " in arg " + element ) ;
return false ;
}
}
try {
2015-02-20 07:34:19 +01:00
final String root = " worlds. " + world ;
2015-02-19 09:51:10 +01:00
if ( ! config . contains ( root ) ) {
config . createSection ( root ) ;
}
plotworld . saveConfiguration ( config . getConfigurationSection ( root ) ) ;
2015-02-20 07:34:19 +01:00
ClassicPlotWorld . PLOT_HEIGHT_DEFAULT = height ;
ClassicPlotWorld . ROAD_HEIGHT_DEFAULT = height ;
ClassicPlotWorld . WALL_HEIGHT_DEFAULT = height ;
ClassicPlotWorld . TOP_BLOCK_DEFAULT = floor ;
ClassicPlotWorld . MAIN_BLOCK_DEFAULT = main ;
ClassicPlotWorld . WALL_BLOCK_DEFAULT = border ;
ClassicPlotWorld . WALL_FILLING_DEFAULT = wall ;
SquarePlotWorld . PLOT_WIDTH_DEFAULT = width ;
SquarePlotWorld . ROAD_WIDTH_DEFAULT = gap ;
} catch ( final Exception e ) {
2015-02-19 09:51:10 +01:00
e . printStackTrace ( ) ;
}
}
return true ;
}
2015-07-06 11:38:37 +02:00
2015-07-09 06:19:49 +02:00
public boolean canUpdate ( String current , String other ) {
2015-07-06 11:38:37 +02:00
String s1 = normalisedVersion ( current ) ;
String s2 = normalisedVersion ( other ) ;
int cmp = s1 . compareTo ( s2 ) ;
return cmp < 0 ;
}
public String normalisedVersion ( String version ) {
return normalisedVersion ( version , " . " , 4 ) ;
}
public String normalisedVersion ( String version , String sep , int maxWidth ) {
String [ ] split = Pattern . compile ( sep , Pattern . LITERAL ) . split ( version ) ;
StringBuilder sb = new StringBuilder ( ) ;
for ( String s : split ) {
sb . append ( String . format ( " % " + maxWidth + 's' , s ) ) ;
}
return sb . toString ( ) ;
}
/ * *
* Gets the default update URL , or null if the plugin is up to date
* @return
* /
public URL getUpdate ( ) {
String resource = " plotsquared.1177 " ;
String url = " https://www.spigotmc.org/resources/ " + resource + " /history " ;
String download = " <a href= \" resources/ " + resource + " /download?version= " ;
String version = " <td class= \" version \" > " ;
try {
URL history = new URL ( url ) ;
URLConnection con = history . openConnection ( ) ;
2015-07-18 19:30:41 +02:00
con . addRequestProperty ( " User-Agent " , " Mozilla/5.0 " ) ;
2015-07-06 11:38:37 +02:00
InputStream stream = con . getInputStream ( ) ;
BufferedReader in = new BufferedReader ( new InputStreamReader ( stream ) ) ;
String l ;
URL link = null ;
String cur_ver = config . getString ( " version " ) ;
String new_ver = null ;
while ( ( l = in . readLine ( ) ) ! = null ) {
if ( l . length ( ) > version . length ( ) & & l . startsWith ( version ) ) {
new_ver = l . substring ( version . length ( ) , l . length ( ) - 5 ) ;
break ;
}
if ( link = = null & & l . length ( ) > download . length ( ) & & l . startsWith ( download ) ) {
String subString = l . substring ( download . length ( ) ) ;
link = new URL ( " https://www.spigotmc.org/resources/ " + resource + " /download?version= " + subString . substring ( 0 , subString . indexOf ( " \" " ) ) ) ;
continue ;
}
}
stream . close ( ) ;
in . close ( ) ;
if ( new_ver = = null | | ! canUpdate ( cur_ver , new_ver ) ) {
PS . log ( " &7PlotSquared is already up to date! " ) ;
return null ;
}
if ( link = = null ) {
PS . log ( " &dCould not check for updates " ) ;
PS . log ( " &7 - Manually check for updates: " + url ) ;
return null ;
}
return link ;
} catch ( Exception e ) {
PS . log ( " &dCould not check for updates " ) ;
PS . log ( " &7 - Manually check for updates: " + url ) ;
return null ;
}
}
2015-07-18 13:18:45 +02:00
public boolean update ( PlotPlayer sender , URL url ) {
2015-07-06 11:38:37 +02:00
if ( url = = null ) {
return false ;
}
try {
File newJar = new File ( " plugins/update/PlotSquared.jar " ) ;
2015-07-18 13:18:45 +02:00
MainUtil . sendMessage ( sender , " $1Downloading from provided URL: &7 " + url ) ;
MainUtil . sendMessage ( sender , " $2 - User-Agent: " + " Mozilla/4.0 " ) ;
2015-07-06 11:38:37 +02:00
URLConnection con = url . openConnection ( ) ;
con . addRequestProperty ( " User-Agent " , " Mozilla/4.0 " ) ;
InputStream stream = con . getInputStream ( ) ;
File parent = newJar . getParentFile ( ) ;
if ( ! parent . exists ( ) ) {
parent . mkdirs ( ) ;
}
2015-07-18 13:18:45 +02:00
MainUtil . sendMessage ( sender , " $2 - Output: " + newJar ) ;
2015-07-06 11:38:37 +02:00
newJar . delete ( ) ;
Files . copy ( stream , newJar . toPath ( ) ) ;
stream . close ( ) ;
2015-07-18 13:18:45 +02:00
MainUtil . sendMessage ( sender , " $1The update will take effect when the server is restarted next " ) ;
2015-07-06 11:38:37 +02:00
return true ;
}
catch ( Exception e ) {
2015-07-18 13:18:45 +02:00
MainUtil . sendMessage ( sender , " Failed to update PlotSquared " ) ;
MainUtil . sendMessage ( sender , " - Please update manually " ) ;
2015-07-21 19:08:51 +02:00
log ( " ============ Stacktrace ============ " ) ;
2015-07-06 11:38:37 +02:00
e . printStackTrace ( ) ;
2015-07-21 19:08:51 +02:00
log ( " ==================================== " ) ;
2015-07-06 11:38:37 +02:00
}
return false ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the database connection
* @return The database connection
* /
2015-07-03 11:30:26 +02:00
public Connection getConnection ( ) {
return connection ;
}
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Copy a file from inside the jar to a location
* @param file Name of the file inside PlotSquared . jar
* @param folder The output location relative to / plugins / PlotSquared /
* /
2015-04-21 14:48:18 +02:00
public void copyFile ( String file , String folder ) {
2015-02-27 08:50:16 +01:00
try {
byte [ ] buffer = new byte [ 2048 ] ;
2015-07-03 11:30:26 +02:00
File output = IMP . getDirectory ( ) ;
2015-02-27 08:50:16 +01:00
if ( ! output . exists ( ) ) {
output . mkdirs ( ) ;
}
2015-04-21 14:48:18 +02:00
File newFile = new File ( ( output + File . separator + folder + File . separator + file ) ) ;
2015-02-27 08:50:16 +01:00
if ( newFile . exists ( ) ) {
return ;
}
ZipInputStream zis = new ZipInputStream ( new FileInputStream ( FILE ) ) ;
ZipEntry ze = zis . getNextEntry ( ) ;
while ( ze ! = null ) {
String name = ze . getName ( ) ;
if ( name . equals ( file ) ) {
new File ( newFile . getParent ( ) ) . mkdirs ( ) ;
FileOutputStream fos = new FileOutputStream ( newFile ) ;
int len ;
while ( ( len = zis . read ( buffer ) ) > 0 ) {
fos . write ( buffer , 0 , len ) ;
}
fos . close ( ) ;
ze = null ;
}
else {
ze = zis . getNextEntry ( ) ;
}
}
zis . closeEntry ( ) ;
zis . close ( ) ;
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
log ( " &cCould not save " + file ) ;
}
2015-02-19 07:08:15 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Close the database connection
* /
2015-02-19 07:08:15 +01:00
public void disable ( ) {
try {
2015-04-29 15:07:12 +02:00
database . closeConnection ( ) ;
2015-07-24 16:06:58 +02:00
UUIDHandler . handleShutdown ( ) ;
2015-02-19 07:08:15 +01:00
} catch ( NullPointerException | SQLException e ) {
2015-04-29 15:07:12 +02:00
log ( " &cCould not close database connection! " ) ;
2015-02-19 07:08:15 +01:00
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the database connection
* /
2015-02-19 07:08:15 +01:00
public void setupDatabase ( ) {
if ( Settings . DB . USE_MYSQL ) {
try {
2015-07-06 11:38:37 +02:00
database = new MySQL ( Settings . DB . HOST_NAME , Settings . DB . PORT , Settings . DB . DATABASE , Settings . DB . USER , Settings . DB . PASSWORD ) ;
2015-04-29 15:07:12 +02:00
connection = database . openConnection ( ) ;
2015-02-19 07:08:15 +01:00
{
if ( DBFunc . dbManager = = null ) {
DBFunc . dbManager = new SQLManager ( connection , Settings . DB . PREFIX ) ;
}
2015-06-05 12:45:13 +02:00
DBFunc . createTables ( " mysql " ) ;
2015-02-19 07:08:15 +01:00
}
} catch ( final Exception e ) {
log ( " &c[Plots] MySQL is not setup correctly. The plugin will disable itself. " ) ;
if ( ( config = = null ) | | config . getBoolean ( " debug " ) ) {
log ( " &d==== Here is an ugly stacktrace if you are interested in those things ==== " ) ;
e . printStackTrace ( ) ;
log ( " &d==== End of stacktrace ==== " ) ;
log ( " &6Please go to the PlotSquared 'storage.yml' and configure MySQL correctly. " ) ;
}
IMP . disable ( ) ;
return ;
}
plots = DBFunc . getPlots ( ) ;
if ( Settings . ENABLE_CLUSTERS ) {
ClusterManager . clusters = DBFunc . getClusters ( ) ;
}
2015-02-20 07:34:19 +01:00
} else if ( Settings . DB . USE_MONGO ) {
2015-02-19 07:08:15 +01:00
// DBFunc.dbManager = new MongoManager();
log ( C . PREFIX . s ( ) + " MongoDB is not yet implemented " ) ;
2015-02-20 07:34:19 +01:00
} else if ( Settings . DB . USE_SQLITE ) {
2015-02-19 07:08:15 +01:00
try {
2015-07-06 11:38:37 +02:00
this . database = new SQLite ( IMP . getDirectory ( ) + File . separator + Settings . DB . SQLITE_DB + " .db " ) ;
2015-04-29 15:07:12 +02:00
connection = this . database . openConnection ( ) ;
2015-02-19 07:08:15 +01:00
{
DBFunc . dbManager = new SQLManager ( connection , Settings . DB . PREFIX ) ;
final DatabaseMetaData meta = connection . getMetaData ( ) ;
2015-07-03 12:32:32 +02:00
meta . getTables ( null , null , Settings . DB . PREFIX + " plot " , null ) ;
2015-06-05 12:45:13 +02:00
DBFunc . createTables ( " sqlite " ) ;
2015-02-19 07:08:15 +01:00
}
} catch ( final Exception e ) {
log ( C . PREFIX . s ( ) + " &cFailed to open SQLite connection. The plugin will disable itself. " ) ;
log ( " &9==== Here is an ugly stacktrace, if you are interested in those things === " ) ;
e . printStackTrace ( ) ;
IMP . disable ( ) ;
return ;
}
plots = DBFunc . getPlots ( ) ;
if ( Settings . ENABLE_CLUSTERS ) {
ClusterManager . clusters = DBFunc . getClusters ( ) ;
}
} else {
log ( C . PREFIX + " &cNo storage type is set! " ) ;
IMP . disable ( ) ;
}
2015-02-20 07:34:19 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the default flags for PlotSquared < br >
* - Create the flags
* - Register with FlagManager and parse raw flag values
* /
2015-07-03 11:30:26 +02:00
public void setupDefaultFlags ( ) {
2015-04-14 11:32:19 +02:00
final List < String > booleanFlags = Arrays . asList ( " notify-enter " , " notify-leave " , " item-drop " , " invincible " , " instabreak " , " drop-protection " , " forcefield " , " titles " , " pve " , " pvp " , " no-worldedit " , " redstone " , " keep " ) ;
2015-02-19 07:08:15 +01:00
final List < String > intervalFlags = Arrays . asList ( " feed " , " heal " ) ;
final List < String > stringFlags = Arrays . asList ( " greeting " , " farewell " ) ;
2015-05-30 21:47:31 +02:00
final List < String > intFlags = Arrays . asList ( " entity-cap " , " mob-cap " , " animal-cap " , " hostile-cap " , " vehicle-cap " , " music " ) ;
2015-02-19 07:08:15 +01:00
for ( final String flag : stringFlags ) {
FlagManager . addFlag ( new AbstractFlag ( flag ) ) ;
}
for ( final String flag : intervalFlags ) {
FlagManager . addFlag ( new AbstractFlag ( flag , new FlagValue . IntervalValue ( ) ) ) ;
}
for ( final String flag : booleanFlags ) {
FlagManager . addFlag ( new AbstractFlag ( flag , new FlagValue . BooleanValue ( ) ) ) ;
}
2015-03-20 13:04:48 +01:00
for ( final String flag : intFlags ) {
FlagManager . addFlag ( new AbstractFlag ( flag , new FlagValue . UnsignedIntegerValue ( ) ) ) ;
}
2015-07-18 05:19:36 +02:00
FlagManager . addFlag ( new AbstractFlag ( " analysis " , new FlagValue . IntegerListValue ( ) ) , true ) ;
2015-06-24 16:32:27 +02:00
FlagManager . addFlag ( new AbstractFlag ( " disable-physics " , new FlagValue . BooleanValue ( ) ) ) ;
2015-02-19 07:08:15 +01:00
FlagManager . addFlag ( new AbstractFlag ( " fly " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " explosion " , new FlagValue . BooleanValue ( ) ) ) ;
2015-07-09 16:20:19 +02:00
FlagManager . addFlag ( new AbstractFlag ( " mob-place " , new FlagValue . BooleanValue ( ) ) ) ;
2015-02-19 07:08:15 +01:00
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 ( ) ) ) ;
2015-07-09 16:20:19 +02:00
FlagManager . addFlag ( new AbstractFlag ( " misc-place " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " misc-break " , new FlagValue . BooleanValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " hanging-interact " , new FlagValue . BooleanValue ( ) ) ) ;
2015-02-19 07:08:15 +01:00
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 ( ) ) ) ;
2015-07-09 16:20:19 +02:00
FlagManager . addFlag ( new AbstractFlag ( " device-interact " , new FlagValue . BooleanValue ( ) ) ) ;
2015-02-19 07:08:15 +01:00
FlagManager . addFlag ( new AbstractFlag ( " place " , new FlagValue . PlotBlockListValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " break " , new FlagValue . PlotBlockListValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " use " , new FlagValue . PlotBlockListValue ( ) ) ) ;
2015-07-18 13:10:38 +02:00
FlagManager . addFlag ( new AbstractFlag ( " blocked-cmds " , new FlagValue . StringListValue ( ) ) ) ;
2015-07-18 16:49:13 +02:00
FlagManager . addFlag ( new AbstractFlag ( " ice-met " , new FlagValue . BooleanValue ( ) ) ) ;
2015-02-19 07:08:15 +01:00
FlagManager . addFlag ( new AbstractFlag ( " gamemode " ) {
2015-07-03 12:16:20 +02:00
2015-02-19 07:08:15 +01:00
public String parseValueRaw ( final String value ) {
switch ( value ) {
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 ;
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-02-19 07:08:15 +01:00
public String getValueDesc ( ) {
return " Flag value must be a gamemode: 'creative' , 'survival' or 'adventure' " ;
}
} ) ;
FlagManager . addFlag ( new AbstractFlag ( " price " , new FlagValue . UnsignedDoubleValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " time " , new FlagValue . LongValue ( ) ) ) ;
FlagManager . addFlag ( new AbstractFlag ( " weather " ) {
2015-07-03 12:16:20 +02:00
2015-02-19 07:08:15 +01:00
public String parseValueRaw ( final String value ) {
switch ( value ) {
case " rain " :
case " storm " :
case " on " :
return " rain " ;
2015-05-30 21:47:31 +02:00
case " lightning " :
case " thunder " :
return " thunder " ;
2015-02-19 07:08:15 +01:00
case " clear " :
case " off " :
case " sun " :
return " clear " ;
default :
return null ;
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-02-19 07:08:15 +01:00
public String getValueDesc ( ) {
return " Flag value must be weather type: 'clear' or 'rain' " ;
}
} ) ;
2015-07-18 16:49:13 +02:00
FlagManager . addFlag ( new AbstractFlag ( " description " , new FlagValue . StringValue ( ) ) , true ) ;
2015-02-19 07:08:15 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the default configuration ( settings . yml )
* /
2015-07-03 11:30:26 +02:00
public void setupConfig ( ) {
2015-07-12 21:08:41 +02:00
LAST_VERSION = config . getString ( " version " ) ;
2015-02-19 07:08:15 +01:00
config . set ( " version " , VERSION ) ;
2015-04-09 07:41:14 +02:00
2015-02-19 07:08:15 +01:00
final Map < String , Object > options = new HashMap < > ( ) ;
2015-04-18 15:47:13 +02:00
// Command confirmation
2015-03-07 06:22:15 +01:00
options . put ( " confirmation.clear " , Settings . CONFIRM_CLEAR ) ;
options . put ( " confirmation.delete " , Settings . CONFIRM_DELETE ) ;
options . put ( " confirmation.unlink " , Settings . CONFIRM_UNLINK ) ;
2015-04-18 15:47:13 +02:00
// Protection
2015-06-23 23:44:44 +02:00
options . put ( " protection.redstone.disable-offline " , Settings . REDSTONE_DISABLER ) ;
2015-04-01 10:25:58 +02:00
options . put ( " protection.tnt-listener.enabled " , Settings . TNT_LISTENER ) ;
2015-04-15 07:24:54 +02:00
options . put ( " protection.piston.falling-blocks " , Settings . PISTON_FALLING_BLOCK_CHECK ) ;
2015-04-18 15:47:13 +02:00
// Clusters
2015-02-19 07:08:15 +01:00
options . put ( " clusters.enabled " , Settings . ENABLE_CLUSTERS ) ;
2015-04-18 15:47:13 +02:00
// PlotMe
2015-02-19 07:08:15 +01:00
options . put ( " plotme-alias " , Settings . USE_PLOTME_ALIAS ) ;
options . put ( " plotme-convert.enabled " , Settings . CONVERT_PLOTME ) ;
2015-03-31 14:14:38 +02:00
options . put ( " plotme-convert.cache-uuids " , Settings . CACHE_PLOTME ) ;
2015-04-18 15:47:13 +02:00
// UUID
2015-07-24 16:06:58 +02:00
options . put ( " uuid.use_sqluuidhandler " , Settings . USE_SQLUUIDHANDLER ) ;
2015-02-19 07:08:15 +01:00
options . put ( " UUID.offline " , Settings . OFFLINE_MODE ) ;
2015-04-12 07:22:03 +02:00
options . put ( " UUID.force-lowercase " , Settings . UUID_LOWERCASE ) ;
2015-04-18 15:47:13 +02:00
options . put ( " uuid.read-from-disk " , Settings . UUID_FROM_DISK ) ;
// Mob stuff
2015-02-19 07:08:15 +01:00
options . put ( " kill_road_mobs " , Settings . KILL_ROAD_MOBS_DEFAULT ) ;
options . put ( " mob_pathfinding " , Settings . MOB_PATHFINDING_DEFAULT ) ;
2015-04-18 15:47:13 +02:00
// Clearing + Expiry
2015-07-17 18:50:32 +02:00
options . put ( " clear.fastmode " , Settings . ENABLE_CLUSTERS ) ;
options . put ( " clear.on.ban " , false ) ;
2015-02-19 07:08:15 +01:00
options . put ( " clear.auto.enabled " , false ) ;
options . put ( " clear.auto.days " , 365 ) ;
2015-05-15 05:29:23 +02:00
options . put ( " clear.auto.clear-interval-seconds " , Settings . CLEAR_INTERVAL ) ;
2015-07-18 05:19:36 +02:00
options . put ( " clear.auto.calibration.changes " , 1 ) ;
options . put ( " clear.auto.calibration.faces " , 2 ) ;
options . put ( " clear.auto.calibration.data " , 32 ) ;
2015-07-19 15:12:48 +02:00
options . put ( " clear.auto.calibration.air " , 0 ) ;
2015-07-17 18:50:32 +02:00
options . put ( " clear.auto.calibration.variety " , 1 ) ;
options . put ( " clear.auto.calibration.changes_sd " , 64 ) ;
options . put ( " clear.auto.calibration.faces_sd " , 32 ) ;
options . put ( " clear.auto.calibration.data_sd " , 1 ) ;
2015-07-19 15:12:48 +02:00
options . put ( " clear.auto.calibration.air_sd " , 0 ) ;
2015-07-17 18:50:32 +02:00
options . put ( " clear.auto.calibration.variety_sd " , 1 ) ;
2015-07-18 19:28:03 +02:00
2015-07-19 15:12:48 +02:00
int keep = config . getInt ( " clear.keep-if-modified " ) ;
int ignore = config . getInt ( " clear.ignore-if-modified " ) ;
2015-07-18 19:28:03 +02:00
if ( keep > 0 | | ignore > 0 ) {
options . put ( " clear.auto.threshold " , 1 ) ;
log ( " &cIMPORTANT MESSAGE ABOUT THIS UPDATE!!!!!!!!!!!!!!!!!!!!!!!!!!!! " ) ;
log ( " &cSorry for all the exclamation marks, but this could be important. " ) ;
log ( " &cPlot clearing has changed to a new system that requires calibration. " ) ;
log ( " &cThis is how it will work: " ) ;
log ( " &c - Players will rate plots " ) ;
log ( " &c - When enough plots are rated, you can run /plot debugexec calibrate-analysis " ) ;
log ( " &c - You can decide the (rough) percentage of expired plots to clear " ) ;
log ( " &c - To just clear all expired plot, ignore this and set: &7threshold: -1 " ) ;
log ( " &cMore information:&7 https://github.com/IntellectualSites/PlotSquared/wiki/Plot-analysis: " ) ;
}
else {
options . put ( " clear.auto.threshold " , Settings . CLEAR_THRESHOLD ) ;
}
2015-07-19 15:12:48 +02:00
config . set ( " clear.keep-if-modified " , null ) ;
config . set ( " clear.ignore-if-modified " , null ) ;
2015-07-17 18:50:32 +02:00
2015-04-18 15:47:13 +02:00
// Schematics
2015-02-19 07:08:15 +01:00
options . put ( " schematics.save_path " , Settings . SCHEMATIC_SAVE_PATH ) ;
2015-04-18 15:47:13 +02:00
2015-07-10 16:08:07 +02:00
// Web
options . put ( " web.url " , Settings . WEB_URL ) ;
options . put ( " web.server-ip " , Settings . WEB_IP ) ;
2015-04-18 15:47:13 +02:00
// Caching
2015-03-12 10:28:08 +01:00
options . put ( " cache.permissions " , Settings . PERMISSION_CACHING ) ;
2015-06-28 02:54:57 +02:00
options . put ( " cache.ratings " , Settings . CACHE_RATINGS ) ;
2015-04-18 15:47:13 +02:00
// Titles
2015-02-19 07:08:15 +01:00
options . put ( " titles " , Settings . TITLES ) ;
2015-04-18 15:47:13 +02:00
// Teleportation
2015-02-19 07:08:15 +01:00
options . put ( " teleport.on_login " , Settings . TELEPORT_ON_LOGIN ) ;
2015-04-18 15:47:13 +02:00
options . put ( " teleport.delay " , 0 ) ;
// WorldEdit
2015-02-19 07:08:15 +01:00
options . put ( " worldedit.require-selection-in-mask " , Settings . REQUIRE_SELECTION ) ;
2015-06-11 09:12:39 +02:00
options . put ( " worldedit.enable-for-helpers " , Settings . WE_ALLOW_HELPER ) ;
2015-04-18 15:47:13 +02:00
options . put ( " worldedit.max-volume " , Settings . WE_MAX_VOLUME ) ;
options . put ( " worldedit.max-iterations " , Settings . WE_MAX_ITERATIONS ) ;
2015-05-02 15:58:52 +02:00
options . put ( " worldedit.blacklist " , Arrays . asList ( " cs " , " .s " , " restore " , " snapshot " , " delchunks " , " listchunks " ) ) ;
2015-04-18 15:47:13 +02:00
// Chunk processor
2015-04-07 14:17:04 +02:00
options . put ( " chunk-processor.enabled " , Settings . CHUNK_PROCESSOR ) ;
options . put ( " chunk-processor.max-blockstates " , Settings . CHUNK_PROCESSOR_MAX_BLOCKSTATES ) ;
options . put ( " chunk-processor.max-entities " , Settings . CHUNK_PROCESSOR_MAX_ENTITIES ) ;
2015-07-18 13:18:45 +02:00
options . put ( " chunk-processor.disable-physics " , Settings . CHUNK_PROCESSOR_DISABLE_PHYSICS ) ;
2015-04-18 15:47:13 +02:00
// Comments
2015-05-14 12:34:08 +02:00
options . put ( " comments.notifications.enabled " , Settings . COMMENT_NOTIFICATIONS ) ;
2015-04-18 15:47:13 +02:00
// Plot limits
2015-04-14 15:47:12 +02:00
options . put ( " global_limit " , Settings . GLOBAL_LIMIT ) ;
2015-04-18 15:47:13 +02:00
options . put ( " max_plots " , Settings . MAX_PLOTS ) ;
options . put ( " claim.max-auto-area " , Settings . MAX_AUTO_SIZE ) ;
// Misc
options . put ( " console.color " , Settings . CONSOLE_COLOR ) ;
2015-06-24 05:31:13 +02:00
options . put ( " chat.fancy " , Settings . FANCY_CHAT ) ;
2015-04-18 15:47:13 +02:00
options . put ( " metrics " , true ) ;
options . put ( " debug " , true ) ;
options . put ( " auto_update " , false ) ;
2015-02-19 07:08:15 +01:00
for ( final Entry < String , Object > node : options . entrySet ( ) ) {
if ( ! config . contains ( node . getKey ( ) ) ) {
config . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
2015-04-07 14:17:04 +02:00
2015-04-18 15:47:13 +02:00
// Command confirmation
2015-03-07 06:22:15 +01:00
Settings . CONFIRM_CLEAR = config . getBoolean ( " confirmation.clear " ) ;
Settings . CONFIRM_DELETE = config . getBoolean ( " confirmation.delete " ) ;
Settings . CONFIRM_UNLINK = config . getBoolean ( " confirmation.unlink " ) ;
2015-04-18 15:47:13 +02:00
// Protection
2015-07-05 12:51:34 +02:00
Settings . REDSTONE_DISABLER = config . getBoolean ( " protection.redstone.disable-offline " ) ;
2015-04-18 15:47:13 +02:00
Settings . TNT_LISTENER = config . getBoolean ( " protection.tnt-listener.enabled " ) ;
Settings . PISTON_FALLING_BLOCK_CHECK = config . getBoolean ( " protection.piston.falling-blocks " ) ;
// Clusters
Settings . ENABLE_CLUSTERS = config . getBoolean ( " clusters.enabled " ) ;
// PlotMe
2015-02-19 07:08:15 +01:00
Settings . USE_PLOTME_ALIAS = config . getBoolean ( " plotme-alias " ) ;
Settings . CONVERT_PLOTME = config . getBoolean ( " plotme-convert.enabled " ) ;
2015-03-31 14:14:38 +02:00
Settings . CACHE_PLOTME = config . getBoolean ( " plotme-convert.cache-uuids " ) ;
2015-04-18 15:47:13 +02:00
// UUID
2015-07-24 16:06:58 +02:00
Settings . USE_SQLUUIDHANDLER = config . getBoolean ( " uuid.use_sqluuidhandler " ) ;
2015-04-18 15:47:13 +02:00
Settings . OFFLINE_MODE = config . getBoolean ( " UUID.offline " ) ;
2015-06-24 16:32:27 +02:00
Settings . UUID_LOWERCASE = Settings . OFFLINE_MODE & & config . getBoolean ( " UUID.force-lowercase " ) ;
2015-04-18 15:47:13 +02:00
Settings . UUID_FROM_DISK = config . getBoolean ( " uuid.read-from-disk " ) ;
// Mob stuff
2015-02-19 07:08:15 +01:00
Settings . KILL_ROAD_MOBS = config . getBoolean ( " kill_road_mobs " ) ;
2015-05-15 06:00:39 +02:00
Settings . MOB_PATHFINDING = config . getBoolean ( " mob_pathfinding " ) ;
2015-04-18 15:47:13 +02:00
// Clearing + Expiry
Settings . FAST_CLEAR = config . getBoolean ( " clear.fastmode " ) ;
2015-06-07 21:37:40 +02:00
Settings . DELETE_PLOTS_ON_BAN = config . getBoolean ( " clear.on.ban " ) ;
2015-07-17 18:50:32 +02:00
Settings . AUTO_CLEAR_DAYS = config . getInt ( " clear.auto.days " ) ;
2015-07-18 05:19:36 +02:00
Settings . CLEAR_THRESHOLD = config . getInt ( " clear.auto.threshold " ) ;
2015-02-19 07:08:15 +01:00
Settings . AUTO_CLEAR = config . getBoolean ( " clear.auto.enabled " ) ;
2015-05-15 05:29:23 +02:00
Settings . CLEAR_INTERVAL = config . getInt ( " clear.auto.clear-interval-seconds " ) ;
2015-07-17 18:50:32 +02:00
// Clearing modifiers
PlotAnalysis . MODIFIERS . changes = config . getInt ( " clear.auto.calibration.changes " ) ;
PlotAnalysis . MODIFIERS . faces = config . getInt ( " clear.auto.calibration.faces " ) ;
PlotAnalysis . MODIFIERS . data = config . getInt ( " clear.auto.calibration.data " ) ;
PlotAnalysis . MODIFIERS . air = config . getInt ( " clear.auto.calibration.air " ) ;
PlotAnalysis . MODIFIERS . variety = config . getInt ( " clear.auto.calibration.variety " ) ;
PlotAnalysis . MODIFIERS . changes_sd = config . getInt ( " clear.auto.calibration.changes_sd " ) ;
PlotAnalysis . MODIFIERS . faces_sd = config . getInt ( " clear.auto.calibration.faces_sd " ) ;
PlotAnalysis . MODIFIERS . data_sd = config . getInt ( " clear.auto.calibration.data_sd " ) ;
PlotAnalysis . MODIFIERS . air_sd = config . getInt ( " clear.auto.calibration.air_sd " ) ;
PlotAnalysis . MODIFIERS . variety_sd = config . getInt ( " clear.auto.calibration.variety_sd " ) ;
2015-05-15 05:29:23 +02:00
2015-04-18 15:47:13 +02:00
// Schematics
Settings . SCHEMATIC_SAVE_PATH = config . getString ( " schematics.save_path " ) ;
2015-07-10 16:08:07 +02:00
// Web
Settings . WEB_URL = config . getString ( " web.url " ) ;
Settings . WEB_IP = config . getString ( " web.server-ip " ) ;
2015-04-18 15:47:13 +02:00
// Caching
Settings . PERMISSION_CACHING = config . getBoolean ( " cache.permissions " ) ;
2015-06-28 02:54:57 +02:00
Settings . CACHE_RATINGS = config . getBoolean ( " cache.ratings " ) ;
2015-04-18 15:47:13 +02:00
2015-07-03 04:11:41 +02:00
// Rating system
Settings . RATING_CATEGORIES = config . getStringList ( " ratings.categories " ) ;
2015-04-18 15:47:13 +02:00
// Titles
2015-02-19 07:08:15 +01:00
Settings . TITLES = config . getBoolean ( " titles " ) ;
2015-04-18 15:47:13 +02:00
// Teleportation
Settings . TELEPORT_DELAY = config . getInt ( " teleport.delay " ) ;
Settings . TELEPORT_ON_LOGIN = config . getBoolean ( " teleport.on_login " ) ;
// WorldEdit
Settings . REQUIRE_SELECTION = config . getBoolean ( " worldedit.require-selection-in-mask " ) ;
2015-06-11 09:12:39 +02:00
Settings . WE_ALLOW_HELPER = config . getBoolean ( " worldedit.enable-for-helpers " ) ;
2015-04-18 15:47:13 +02:00
Settings . WE_MAX_VOLUME = config . getLong ( " worldedit.max-volume " ) ;
Settings . WE_MAX_ITERATIONS = config . getLong ( " worldedit.max-iterations " ) ;
2015-05-02 15:58:52 +02:00
Settings . WE_BLACKLIST = config . getStringList ( " worldedit.blacklist " ) ;
2015-04-18 15:47:13 +02:00
// Chunk processor
Settings . CHUNK_PROCESSOR = config . getBoolean ( " chunk-processor.enabled " ) ;
Settings . CHUNK_PROCESSOR_MAX_BLOCKSTATES = config . getInt ( " chunk-processor.max-blockstates " ) ;
2015-07-18 13:18:45 +02:00
Settings . CHUNK_PROCESSOR_MAX_ENTITIES = config . getInt ( " chunk-processor.max-entities " ) ;
Settings . CHUNK_PROCESSOR_DISABLE_PHYSICS = config . getBoolean ( " chunk-processor.disable-physics " ) ;
2015-04-18 15:47:13 +02:00
// Comments
2015-05-14 12:34:08 +02:00
Settings . COMMENT_NOTIFICATIONS = config . getBoolean ( " comments.notifications.enabled " ) ;
2015-04-18 15:47:13 +02:00
// Plot limits
Settings . MAX_AUTO_SIZE = config . getInt ( " claim.max-auto-area " ) ;
2015-02-19 07:08:15 +01:00
Settings . MAX_PLOTS = config . getInt ( " max_plots " ) ;
if ( Settings . MAX_PLOTS > 32767 ) {
log ( " &c`max_plots` Is set too high! This is a per player setting and does not need to be very large. " ) ;
Settings . MAX_PLOTS = 32767 ;
}
2015-04-14 15:47:12 +02:00
Settings . GLOBAL_LIMIT = config . getBoolean ( " global_limit " ) ;
2015-04-18 15:47:13 +02:00
// Misc
Settings . DEBUG = config . getBoolean ( " debug " ) ;
if ( Settings . DEBUG ) {
log ( C . PREFIX . s ( ) + " &6Debug Mode Enabled (Default). Edit the config to turn this off. " ) ;
}
Settings . CONSOLE_COLOR = config . getBoolean ( " console.color " ) ;
2015-07-10 05:17:32 +02:00
if ( ! config . getBoolean ( " chat.fancy " ) | | ! IMP . checkVersion ( 1 , 8 , 0 ) ) {
2015-06-24 05:31:13 +02:00
Settings . FANCY_CHAT = false ;
}
2015-04-18 15:47:13 +02:00
Settings . METRICS = config . getBoolean ( " metrics " ) ;
2015-07-24 16:06:58 +02:00
UUIDHandler . implementation = Settings . USE_SQLUUIDHANDLER ? new SQLUUIDHandler ( ) : new FileUUIDHandler ( ) ;
2015-02-19 07:08:15 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup all configuration files < br >
* - Config : settings . yml < br >
* - Storage : storage . yml < br >
* - Translation : PlotSquared . use_THIS . yml , style . yml < br >
* /
2015-07-03 11:30:26 +02:00
public void setupConfigs ( ) {
2015-02-19 07:08:15 +01:00
final File folder = new File ( IMP . getDirectory ( ) + File . separator + " config " ) ;
if ( ! folder . exists ( ) & & ! folder . mkdirs ( ) ) {
log ( C . PREFIX . s ( ) + " &cFailed to create the /plugins/config folder. Please create it manually. " ) ;
}
try {
styleFile = new File ( IMP . getDirectory ( ) + File . separator + " translations " + File . separator + " style.yml " ) ;
if ( ! styleFile . exists ( ) ) {
2015-07-09 06:19:49 +02:00
if ( ! styleFile . getParentFile ( ) . exists ( ) ) {
styleFile . getParentFile ( ) . mkdirs ( ) ;
}
2015-02-19 07:08:15 +01:00
if ( ! styleFile . createNewFile ( ) ) {
log ( " Could not create the style file, please create \" translations/style.yml \" manually " ) ;
}
}
style = YamlConfiguration . loadConfiguration ( styleFile ) ;
setupStyle ( ) ;
} catch ( final Exception err ) {
2015-07-09 06:19:49 +02:00
err . printStackTrace ( ) ;
2015-02-19 07:08:15 +01:00
Logger . add ( LogLevel . DANGER , " Failed to save style.yml " ) ;
2015-02-23 01:33:48 +01:00
log ( " failed to save style.yml " ) ;
2015-02-19 07:08:15 +01:00
}
try {
configFile = new File ( IMP . getDirectory ( ) + File . separator + " config " + File . separator + " settings.yml " ) ;
if ( ! configFile . exists ( ) ) {
if ( ! configFile . createNewFile ( ) ) {
log ( " Could not create the settings file, please create \" settings.yml \" manually. " ) ;
}
}
config = YamlConfiguration . loadConfiguration ( configFile ) ;
setupConfig ( ) ;
} catch ( final Exception err_trans ) {
Logger . add ( LogLevel . DANGER , " Failed to save settings.yml " ) ;
2015-02-23 01:33:48 +01:00
log ( " Failed to save settings.yml " ) ;
2015-02-19 07:08:15 +01:00
}
try {
storageFile = new File ( IMP . getDirectory ( ) + File . separator + " config " + File . separator + " storage.yml " ) ;
if ( ! storageFile . exists ( ) ) {
if ( ! storageFile . createNewFile ( ) ) {
log ( " Could not the storage settings file, please create \" storage.yml \" manually. " ) ;
}
}
storage = YamlConfiguration . loadConfiguration ( storageFile ) ;
setupStorage ( ) ;
} catch ( final Exception err_trans ) {
Logger . add ( LogLevel . DANGER , " Failed to save storage.yml " ) ;
2015-02-23 01:33:48 +01:00
log ( " Failed to save storage.yml " ) ;
2015-02-19 07:08:15 +01:00
}
try {
style . save ( styleFile ) ;
config . save ( configFile ) ;
storage . save ( storageFile ) ;
} catch ( final IOException e ) {
Logger . add ( LogLevel . DANGER , " Configuration file saving failed " ) ;
e . printStackTrace ( ) ;
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the storage file ( load + save missing nodes )
* /
2015-07-03 11:30:26 +02:00
private void setupStorage ( ) {
2015-02-19 07:08:15 +01:00
storage . set ( " version " , VERSION ) ;
final Map < String , Object > options = new HashMap < > ( ) ;
options . put ( " mysql.use " , false ) ;
options . put ( " sqlite.use " , true ) ;
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 " ) ;
options . put ( " prefix " , " " ) ;
for ( final Entry < String , Object > node : options . entrySet ( ) ) {
if ( ! storage . contains ( node . getKey ( ) ) ) {
storage . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
2015-02-20 07:34:19 +01:00
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 " ) ;
Settings . DB . PREFIX = storage . getString ( " prefix " ) ;
Settings . METRICS = config . getBoolean ( " metrics " ) ;
Settings . AUTO_CLEAR = config . getBoolean ( " clear.auto.enabled " ) ;
Settings . AUTO_CLEAR_DAYS = config . getInt ( " clear.auto.days " ) ;
Settings . DELETE_PLOTS_ON_BAN = config . getBoolean ( " clear.on.ban " ) ;
2015-02-23 00:12:33 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Show startup debug information
* /
2015-07-03 11:30:26 +02:00
public void showDebug ( ) {
2015-02-20 07:34:19 +01: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 ) ;
settings . put ( " Delete Plots On Ban " , " " + Settings . DELETE_PLOTS_ON_BAN ) ;
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 ) ;
settings . put ( " Schematics Save Path " , " " + Settings . SCHEMATIC_SAVE_PATH ) ;
settings . put ( " API Location " , " " + Settings . API_URL ) ;
for ( final Entry < String , String > setting : settings . entrySet ( ) ) {
log ( C . PREFIX . s ( ) + String . format ( " &cKey: &6%s&c, Value: &6%s " , setting . getKey ( ) , setting . getValue ( ) ) ) ;
}
2015-02-19 07:08:15 +01:00
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 13:01:15 +02:00
/ * *
* Setup the style . yml file
* /
2015-07-03 11:30:26 +02:00
private void setupStyle ( ) {
2015-02-19 07:08:15 +01:00
style . set ( " version " , VERSION ) ;
final Map < String , Object > o = new HashMap < > ( ) ;
2015-07-05 17:44:10 +02:00
o . put ( " color.1 " , " 6 " ) ;
o . put ( " color.2 " , " 7 " ) ;
o . put ( " color.3 " , " 8 " ) ;
o . put ( " color.4 " , " 3 " ) ;
if ( ! style . contains ( " color " ) ) {
for ( final Entry < String , Object > node : o . entrySet ( ) ) {
2015-02-19 07:08:15 +01:00
style . set ( node . getKey ( ) , node . getValue ( ) ) ;
}
}
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the java version
* @return Java version as a double
* /
2015-07-03 11:30:26 +02:00
public double getJavaVersion ( ) {
2015-02-19 07:08:15 +01:00
return Double . parseDouble ( System . getProperty ( " java.specification.version " ) ) ;
}
2015-02-23 02:32:27 +01:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get the list of plot world names
* @return Set of world names ( String )
* /
2015-07-03 11:30:26 +02:00
public Set < String > getPlotWorlds ( ) {
2015-02-19 07:08:15 +01:00
return plotworlds . keySet ( ) ;
}
2015-07-03 11:30:26 +02:00
2015-07-03 12:16:20 +02:00
2015-07-03 13:01:15 +02:00
/ * *
* Get a list of PlotWorld objects
* @return Collection of PlotWorld objects
* /
2015-07-03 11:30:26 +02:00
public Collection < PlotWorld > getPlotWorldObjects ( ) {
2015-03-10 11:21:38 +01:00
return plotworlds . values ( ) ;
}
2015-02-19 07:08:15 +01:00
}