2014-11-08 20:27:09 +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-10-22 14:22:00 +02:00
package com.intellectualcrafters.plot.commands ;
2015-01-13 17:38:15 +01:00
import java.util.ArrayList ;
import java.util.UUID ;
2014-12-28 14:47:35 +01:00
2014-12-18 03:15:11 +01:00
import org.bukkit.Bukkit ;
import org.bukkit.Chunk ;
import org.bukkit.Location ;
import org.bukkit.World ;
import org.bukkit.block.Block ;
import org.bukkit.block.Sign ;
import org.bukkit.entity.Player ;
2015-01-13 17:38:15 +01:00
import com.google.common.collect.BiMap ;
2015-02-19 09:51:10 +01:00
import com.intellectualcrafters.plot.PlotSquared ;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.C ;
import com.intellectualcrafters.plot.database.DBFunc ;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent ;
import com.intellectualcrafters.plot.object.Plot ;
import com.intellectualcrafters.plot.object.PlotId ;
import com.intellectualcrafters.plot.object.PlotManager ;
2015-02-21 12:38:44 +01:00
import com.intellectualcrafters.plot.object.PlotPlayer ;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.object.PlotWorld ;
import com.intellectualcrafters.plot.object.StringWrapper ;
2015-02-20 12:23:48 +01:00
import com.intellectualcrafters.plot.util.MainUtil ;
2015-02-20 12:24:58 +01:00
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions ;
2015-02-20 07:28:21 +01:00
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler ;
2014-10-22 14:22:00 +02:00
/ * *
* @author Citymonstret
* /
public class DebugClaimTest extends SubCommand {
2014-11-05 04:42:08 +01:00
public DebugClaimTest ( ) {
2014-11-10 11:54:36 +01:00
super ( Command . DEBUGCLAIMTEST , " If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary " , " debugclaimtest " , CommandCategory . DEBUG , false ) ;
2014-11-05 04:42:08 +01:00
}
2015-02-20 07:34:19 +01:00
2014-11-16 10:48:18 +01:00
@SuppressWarnings ( " unused " )
public static boolean claimPlot ( final Player player , final Plot plot , final boolean teleport ) {
return claimPlot ( player , plot , teleport , " " ) ;
}
2015-02-20 07:34:19 +01:00
2014-11-16 10:48:18 +01:00
public static boolean claimPlot ( final Player player , final Plot plot , final boolean teleport , @SuppressWarnings ( " unused " ) final String schematic ) {
2014-11-19 18:05:09 +01:00
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent ( player , plot , true ) ;
2014-11-16 10:48:18 +01:00
Bukkit . getPluginManager ( ) . callEvent ( event ) ;
if ( ! event . isCancelled ( ) ) {
2015-02-20 12:23:48 +01:00
MainUtil . createPlot ( player , plot ) ;
MainUtil . setSign ( player , plot ) ;
2015-02-21 05:32:01 +01:00
MainUtil . sendMessage ( BukkitUtil . getPlayer ( player ) , C . CLAIMED ) ;
2014-11-16 10:48:18 +01:00
if ( teleport ) {
2015-02-19 11:29:17 +01:00
PlotSquared . teleportPlayer ( player , BukkitUtil . getLocation ( entity ) , plot ) ;
2014-11-16 10:48:18 +01:00
}
}
return event . isCancelled ( ) ;
}
2015-02-20 07:34:19 +01:00
2014-11-05 04:42:08 +01:00
@Override
2015-02-21 08:30:55 +01:00
public boolean execute ( final PlotPlayer plr , final String . . . args ) {
2014-11-05 04:42:08 +01:00
if ( plr = = null ) {
if ( args . length < 3 ) {
2015-02-21 12:24:46 +01:00
return ! MainUtil . sendMessage ( null , " If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \ n \ n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max} " ) ;
2014-11-05 04:42:08 +01:00
}
final World world = Bukkit . getWorld ( args [ 0 ] ) ;
2015-02-19 09:51:10 +01:00
if ( ( world = = null ) | | ! PlotSquared . isPlotWorld ( world ) ) {
2015-02-21 12:24:46 +01:00
return ! MainUtil . sendMessage ( null , " &cInvalid plot world! " ) ;
2014-11-05 04:42:08 +01:00
}
PlotId min , max ;
try {
final String [ ] split1 = args [ 1 ] . split ( " ; " ) ;
final String [ ] split2 = args [ 2 ] . split ( " ; " ) ;
min = new PlotId ( Integer . parseInt ( split1 [ 0 ] ) , Integer . parseInt ( split1 [ 1 ] ) ) ;
max = new PlotId ( Integer . parseInt ( split2 [ 0 ] ) , Integer . parseInt ( split2 [ 1 ] ) ) ;
2014-12-18 03:15:11 +01:00
} catch ( final Exception e ) {
2015-02-21 12:24:46 +01:00
return ! MainUtil . sendMessage ( null , " &cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords \ nThe conversion will only check the plots in the selected area. " ) ;
2014-11-05 04:42:08 +01:00
}
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " &3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while... " ) ;
MainUtil . sendMessage ( null , " &3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min) " ) ;
2015-02-19 09:51:10 +01:00
final PlotManager manager = PlotSquared . getPlotManager ( world ) ;
2015-02-20 09:55:04 +01:00
final PlotWorld plotworld = PlotSquared . getPlotWorld ( world ) ;
2014-11-08 20:27:09 +01:00
final ArrayList < Plot > plots = new ArrayList < > ( ) ;
2015-02-20 12:24:58 +01:00
for ( final PlotId id : BukkitPlayerFunctions . getPlotSelectionIds ( min , max ) ) {
2015-02-20 12:23:48 +01:00
final Plot plot = MainUtil . getPlot ( world , id ) ;
2015-02-19 09:51:10 +01:00
final boolean contains = PlotSquared . getPlots ( world ) . containsKey ( plot . id ) ;
2014-10-22 14:22:00 +02:00
if ( contains ) {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " - &cDB Already contains: " + plot . id ) ;
2014-10-22 14:22:00 +02:00
continue ;
}
2014-11-05 04:42:08 +01:00
final Location loc = manager . getSignLoc ( world , plotworld , plot ) ;
final Chunk chunk = world . getChunkAt ( loc ) ;
2014-10-22 14:22:00 +02:00
if ( ! chunk . isLoaded ( ) ) {
2014-11-05 04:42:08 +01:00
final boolean result = chunk . load ( false ) ;
2014-10-22 14:22:00 +02:00
if ( ! result ) {
continue ;
}
}
2014-11-05 04:42:08 +01:00
final Block block = world . getBlockAt ( loc ) ;
if ( block ! = null ) {
2014-10-22 14:22:00 +02:00
if ( block . getState ( ) instanceof Sign ) {
2014-11-05 04:42:08 +01:00
final Sign sign = ( Sign ) block . getState ( ) ;
2014-11-08 20:27:09 +01:00
String line = sign . getLine ( 2 ) ;
if ( ( line ! = null ) & & ( line . length ( ) > 2 ) ) {
line = line . substring ( 2 ) ;
final BiMap < StringWrapper , UUID > map = UUIDHandler . getUuidMap ( ) ;
UUID uuid = ( map . get ( new StringWrapper ( line ) ) ) ;
if ( uuid = = null ) {
for ( final StringWrapper string : map . keySet ( ) ) {
if ( string . value . toLowerCase ( ) . startsWith ( line . toLowerCase ( ) ) ) {
uuid = map . get ( string ) ;
break ;
2014-10-22 14:22:00 +02:00
}
}
2014-11-08 20:27:09 +01:00
}
if ( uuid = = null ) {
uuid = UUIDHandler . getUUID ( line ) ;
}
if ( uuid ! = null ) {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " - &aFound plot: " + plot . id + " : " + line ) ;
2014-11-08 20:27:09 +01:00
plot . owner = uuid ;
plot . hasChanged = true ;
plots . add ( plot ) ;
2014-12-18 03:15:11 +01:00
} else {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " - &cInvalid playername: " + plot . id + " : " + line ) ;
2014-10-22 14:22:00 +02:00
}
}
}
}
2014-11-05 04:42:08 +01:00
}
if ( plots . size ( ) > 0 ) {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " &3Sign Block&8->&3PlotSquared&8: &7Updating ' " + plots . size ( ) + " ' plots! " ) ;
2014-11-05 04:42:08 +01:00
DBFunc . createPlots ( plots ) ;
DBFunc . createAllSettingsAndHelpers ( plots ) ;
for ( final Plot plot : plots ) {
2015-02-19 09:51:10 +01:00
PlotSquared . updatePlot ( plot ) ;
2014-11-05 04:42:08 +01:00
}
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " &3Sign Block&8->&3PlotSquared&8: &7Complete! " ) ;
2014-12-18 03:15:11 +01:00
} else {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( null , " No plots were found for the given search. " ) ;
2014-11-05 04:42:08 +01:00
}
2014-12-18 03:15:11 +01:00
} else {
2015-02-21 12:24:46 +01:00
MainUtil . sendMessage ( plr , " &6This command can only be executed by console as it has been deemed unsafe if abused. " ) ;
2014-11-05 04:42:08 +01:00
}
2014-10-22 14:22:00 +02:00
return true ;
2014-11-05 04:42:08 +01:00
}
2014-10-22 14:22:00 +02:00
}