mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Reformat code
This commit is contained in:
parent
02ee1e8fa1
commit
1646cd0f5a
@ -7,16 +7,8 @@ import com.intellectualcrafters.plot.config.C;
|
|||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
import com.intellectualcrafters.plot.flag.Flags;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.intellectualcrafters.plot.util.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -26,16 +18,11 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotSquared API.
|
* PlotSquared API.
|
||||||
*
|
* <p>
|
||||||
* <p>Useful classes:
|
* <p>Useful classes:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link BukkitUtil}</li>
|
* <li>{@link BukkitUtil}</li>
|
||||||
@ -45,25 +32,27 @@ import java.util.UUID;
|
|||||||
* <li>{@link PlotArea}</li>
|
* <li>{@link PlotArea}</li>
|
||||||
* <li>{@link PS}</li>
|
* <li>{@link PS}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @version 3.3.3
|
* @version 3.3.3
|
||||||
*/
|
*/
|
||||||
public class PlotAPI {
|
public class PlotAPI {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated, does nothing.
|
* Deprecated, does nothing.
|
||||||
|
*
|
||||||
* @param plugin not needed
|
* @param plugin not needed
|
||||||
* @deprecated Not needed
|
* @deprecated Not needed
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public PlotAPI(JavaPlugin plugin) {
|
||||||
public PlotAPI(JavaPlugin plugin) {}
|
}
|
||||||
|
|
||||||
public PlotAPI(){}
|
public PlotAPI() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all plots.
|
* Get all plots.
|
||||||
*
|
*
|
||||||
* @return all plots
|
* @return all plots
|
||||||
*
|
|
||||||
* @see PS#getPlots()
|
* @see PS#getPlots()
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getAllPlots() {
|
public Set<Plot> getAllPlots() {
|
||||||
@ -74,7 +63,6 @@ public class PlotAPI {
|
|||||||
* Return all plots for a player.
|
* Return all plots for a player.
|
||||||
*
|
*
|
||||||
* @param player Player, whose plots to search for
|
* @param player Player, whose plots to search for
|
||||||
*
|
|
||||||
* @return all plots that a player owns
|
* @return all plots that a player owns
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(Player player) {
|
public Set<Plot> getPlayerPlots(Player player) {
|
||||||
@ -93,8 +81,8 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the PlotSquared configurations file.
|
* Returns the PlotSquared configurations file.
|
||||||
* @return main configuration
|
|
||||||
*
|
*
|
||||||
|
* @return main configuration
|
||||||
* @see PS#config
|
* @see PS#config
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration getConfig() {
|
public YamlConfiguration getConfig() {
|
||||||
@ -103,8 +91,8 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotSquared storage file.
|
* Get the PlotSquared storage file.
|
||||||
* @return storage configuration
|
|
||||||
*
|
*
|
||||||
|
* @return storage configuration
|
||||||
* @see PS#storage
|
* @see PS#storage
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration getStorage() {
|
public YamlConfiguration getStorage() {
|
||||||
@ -115,7 +103,6 @@ public class PlotAPI {
|
|||||||
* Get the main class for this plugin. Only use this if you really need it.
|
* Get the main class for this plugin. Only use this if you really need it.
|
||||||
*
|
*
|
||||||
* @return PlotSquared PlotSquared Main Class
|
* @return PlotSquared PlotSquared Main Class
|
||||||
*
|
|
||||||
* @see PS
|
* @see PS
|
||||||
*/
|
*/
|
||||||
public PS getMain() {
|
public PS getMain() {
|
||||||
@ -133,7 +120,6 @@ public class PlotAPI {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return ChunkManager
|
* @return ChunkManager
|
||||||
*
|
|
||||||
* @see ChunkManager
|
* @see ChunkManager
|
||||||
*/
|
*/
|
||||||
public ChunkManager getChunkManager() {
|
public ChunkManager getChunkManager() {
|
||||||
@ -142,6 +128,7 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block/biome set queue
|
* Get the block/biome set queue
|
||||||
|
*
|
||||||
* @return GlobalBlockQueue.IMP
|
* @return GlobalBlockQueue.IMP
|
||||||
*/
|
*/
|
||||||
public GlobalBlockQueue getBlockQueue() {
|
public GlobalBlockQueue getBlockQueue() {
|
||||||
@ -153,7 +140,6 @@ public class PlotAPI {
|
|||||||
* to use the UUIDHandler class instead.
|
* to use the UUIDHandler class instead.
|
||||||
*
|
*
|
||||||
* @return UUIDWrapper
|
* @return UUIDWrapper
|
||||||
*
|
|
||||||
* @see UUIDWrapper
|
* @see UUIDWrapper
|
||||||
*/
|
*/
|
||||||
public UUIDWrapper getUUIDWrapper() {
|
public UUIDWrapper getUUIDWrapper() {
|
||||||
@ -165,11 +151,9 @@ public class PlotAPI {
|
|||||||
* - Flag related stuff
|
* - Flag related stuff
|
||||||
*
|
*
|
||||||
* @return FlagManager
|
* @return FlagManager
|
||||||
*
|
|
||||||
* @deprecated Use {@link FlagManager} directly
|
* @deprecated Use {@link FlagManager} directly
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public FlagManager getFlagManager() {
|
||||||
public FlagManager getFlagManager() {
|
|
||||||
return new FlagManager();
|
return new FlagManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +163,7 @@ public class PlotAPI {
|
|||||||
* @return MainUtil
|
* @return MainUtil
|
||||||
* @deprecated Use {@link MainUtil} directly
|
* @deprecated Use {@link MainUtil} directly
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public MainUtil getMainUtil() {
|
||||||
public MainUtil getMainUtil() {
|
|
||||||
return new MainUtil();
|
return new MainUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,12 +171,10 @@ public class PlotAPI {
|
|||||||
* Do not use this. Instead use C.PERMISSION_[method] in your code.
|
* Do not use this. Instead use C.PERMISSION_[method] in your code.
|
||||||
*
|
*
|
||||||
* @return Array of strings
|
* @return Array of strings
|
||||||
*
|
|
||||||
* @see Permissions
|
* @see Permissions
|
||||||
* @deprecated Use {@link C} to list all the permissions
|
* @deprecated Use {@link C} to list all the permissions
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public String[] getPermissions() {
|
||||||
public String[] getPermissions() {
|
|
||||||
ArrayList<String> perms = new ArrayList<>();
|
ArrayList<String> perms = new ArrayList<>();
|
||||||
for (C caption : C.values()) {
|
for (C caption : C.values()) {
|
||||||
if ("static.permissions".equals(caption.getCategory())) {
|
if ("static.permissions".equals(caption.getCategory())) {
|
||||||
@ -208,7 +189,6 @@ public class PlotAPI {
|
|||||||
* and writing schematics.
|
* and writing schematics.
|
||||||
*
|
*
|
||||||
* @return SchematicHandler
|
* @return SchematicHandler
|
||||||
*
|
|
||||||
* @see SchematicHandler
|
* @see SchematicHandler
|
||||||
*/
|
*/
|
||||||
public SchematicHandler getSchematicHandler() {
|
public SchematicHandler getSchematicHandler() {
|
||||||
@ -221,8 +201,7 @@ public class PlotAPI {
|
|||||||
* @return C
|
* @return C
|
||||||
* @deprecated Use {@link C}
|
* @deprecated Use {@link C}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public C[] getCaptions() {
|
||||||
public C[] getCaptions() {
|
|
||||||
return C.values();
|
return C.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,15 +210,11 @@ public class PlotAPI {
|
|||||||
* through the MainUtil.
|
* through the MainUtil.
|
||||||
*
|
*
|
||||||
* @param world the world to retrieve the manager from
|
* @param world the world to retrieve the manager from
|
||||||
*
|
|
||||||
* @return PlotManager
|
* @return PlotManager
|
||||||
*
|
|
||||||
* @see PlotManager
|
* @see PlotManager
|
||||||
* @see PS#getPlotManager(Plot)
|
* @see PS#getPlotManager(Plot)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public PlotManager getPlotManager(World world) {
|
||||||
@Deprecated
|
|
||||||
public PlotManager getPlotManager(World world) {
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -248,6 +223,7 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of PlotAreas in the world.
|
* Get a list of PlotAreas in the world.
|
||||||
|
*
|
||||||
* @param world The world to check for plot areas
|
* @param world The world to check for plot areas
|
||||||
* @return A set of PlotAreas
|
* @return A set of PlotAreas
|
||||||
*/
|
*/
|
||||||
@ -263,14 +239,11 @@ public class PlotAPI {
|
|||||||
* plot merging, clearing, and tessellation.
|
* plot merging, clearing, and tessellation.
|
||||||
*
|
*
|
||||||
* @param world The world
|
* @param world The world
|
||||||
*
|
|
||||||
* @return PlotManager
|
* @return PlotManager
|
||||||
*
|
|
||||||
* @see PS#getPlotManager(Plot)
|
* @see PS#getPlotManager(Plot)
|
||||||
* @see PlotManager
|
* @see PlotManager
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public PlotManager getPlotManager(String world) {
|
||||||
public PlotManager getPlotManager(String world) {
|
|
||||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
||||||
switch (areas.size()) {
|
switch (areas.size()) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -278,7 +251,8 @@ public class PlotAPI {
|
|||||||
case 1:
|
case 1:
|
||||||
return areas.iterator().next().manager;
|
return areas.iterator().next().manager;
|
||||||
default:
|
default:
|
||||||
PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
PS.debug(
|
||||||
|
"PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,15 +263,11 @@ public class PlotAPI {
|
|||||||
* DefaultPlotWorld class implements PlotArea
|
* DefaultPlotWorld class implements PlotArea
|
||||||
*
|
*
|
||||||
* @param world The World
|
* @param world The World
|
||||||
*
|
|
||||||
* @return The {@link PlotArea} for the world or null if not in plotworld
|
* @return The {@link PlotArea} for the world or null if not in plotworld
|
||||||
*
|
|
||||||
* @see #getPlotAreas(World)
|
* @see #getPlotAreas(World)
|
||||||
* @see PlotArea
|
* @see PlotArea
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public PlotArea getWorldSettings(World world) {
|
||||||
@Deprecated
|
|
||||||
public PlotArea getWorldSettings(World world) {
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -308,14 +278,11 @@ public class PlotAPI {
|
|||||||
* Get the settings for a world.
|
* Get the settings for a world.
|
||||||
*
|
*
|
||||||
* @param world the world to retrieve settings from
|
* @param world the world to retrieve settings from
|
||||||
*
|
|
||||||
* @return The {@link PlotArea} for the world or null if not in plotworld
|
* @return The {@link PlotArea} for the world or null if not in plotworld
|
||||||
*
|
|
||||||
* @see PS#getPlotArea(String, String)
|
* @see PS#getPlotArea(String, String)
|
||||||
* @see PlotArea
|
* @see PlotArea
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public PlotArea getWorldSettings(String world) {
|
||||||
public PlotArea getWorldSettings(String world) {
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -326,7 +293,8 @@ public class PlotAPI {
|
|||||||
case 1:
|
case 1:
|
||||||
return areas.iterator().next();
|
return areas.iterator().next();
|
||||||
default:
|
default:
|
||||||
PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
PS.debug(
|
||||||
|
"PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +304,6 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @param player the recipient of the message
|
* @param player the recipient of the message
|
||||||
* @param caption the message
|
* @param caption the message
|
||||||
*
|
|
||||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||||
*/
|
*/
|
||||||
public void sendMessage(Player player, C caption) {
|
public void sendMessage(Player player, C caption) {
|
||||||
@ -348,7 +315,6 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @param player the recipient of the message
|
* @param player the recipient of the message
|
||||||
* @param string the message
|
* @param string the message
|
||||||
*
|
|
||||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||||
*/
|
*/
|
||||||
public void sendMessage(Player player, String string) {
|
public void sendMessage(Player player, String string) {
|
||||||
@ -359,7 +325,6 @@ public class PlotAPI {
|
|||||||
* Send a message to the console. The message supports color codes.
|
* Send a message to the console. The message supports color codes.
|
||||||
*
|
*
|
||||||
* @param message the message
|
* @param message the message
|
||||||
*
|
|
||||||
* @see MainUtil#sendConsoleMessage(C, String...)
|
* @see MainUtil#sendConsoleMessage(C, String...)
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(String message) {
|
public void sendConsoleMessage(String message) {
|
||||||
@ -370,7 +335,6 @@ public class PlotAPI {
|
|||||||
* Send a message to the console.
|
* Send a message to the console.
|
||||||
*
|
*
|
||||||
* @param caption the message
|
* @param caption the message
|
||||||
*
|
|
||||||
* @see #sendConsoleMessage(String)
|
* @see #sendConsoleMessage(String)
|
||||||
* @see C
|
* @see C
|
||||||
*/
|
*/
|
||||||
@ -382,7 +346,6 @@ public class PlotAPI {
|
|||||||
* Registers a flag for use in plots.
|
* Registers a flag for use in plots.
|
||||||
*
|
*
|
||||||
* @param flag the flag to register
|
* @param flag the flag to register
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void addFlag(Flag<?> flag) {
|
public void addFlag(Flag<?> flag) {
|
||||||
Flags.registerFlag(flag);
|
Flags.registerFlag(flag);
|
||||||
@ -394,14 +357,10 @@ public class PlotAPI {
|
|||||||
* @param world the world the plot is located in
|
* @param world the world the plot is located in
|
||||||
* @param x The PlotID x coordinate
|
* @param x The PlotID x coordinate
|
||||||
* @param z The PlotID y coordinate
|
* @param z The PlotID y coordinate
|
||||||
*
|
|
||||||
* @return plot, null if ID is wrong
|
* @return plot, null if ID is wrong
|
||||||
*
|
|
||||||
* @see PlotArea#getPlot(PlotId)
|
* @see PlotArea#getPlot(PlotId)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public Plot getPlot(World world, int x, int z) {
|
||||||
@Deprecated
|
|
||||||
public Plot getPlot(World world, int x, int z) {
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -416,9 +375,7 @@ public class PlotAPI {
|
|||||||
* Get a plot based on the location.
|
* Get a plot based on the location.
|
||||||
*
|
*
|
||||||
* @param location the location to check
|
* @param location the location to check
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot
|
* @return plot if found, otherwise it creates a temporary plot
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot(Location location) {
|
public Plot getPlot(Location location) {
|
||||||
@ -432,9 +389,7 @@ public class PlotAPI {
|
|||||||
* Get a plot based on the player location.
|
* Get a plot based on the player location.
|
||||||
*
|
*
|
||||||
* @param player the player to check
|
* @param player the player to check
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot
|
* @return plot if found, otherwise it creates a temporary plot
|
||||||
*
|
|
||||||
* @see #getPlot(Location)
|
* @see #getPlot(Location)
|
||||||
* @see Plot
|
* @see Plot
|
||||||
*/
|
*/
|
||||||
@ -448,12 +403,10 @@ public class PlotAPI {
|
|||||||
* @param player Player that you want to check for
|
* @param player Player that you want to check for
|
||||||
* @param world The world to check
|
* @param world The world to check
|
||||||
* @return true if player has a plot, false if not.
|
* @return true if player has a plot, false if not.
|
||||||
*
|
|
||||||
* @see #getPlots(World, Player, boolean)
|
* @see #getPlots(World, Player, boolean)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public boolean hasPlot(World world,
|
||||||
@Deprecated
|
Player player) {
|
||||||
public boolean hasPlot(World world, Player player) {
|
|
||||||
return getPlots(world, player, true).length > 0;
|
return getPlots(world, player, true).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,8 +418,7 @@ public class PlotAPI {
|
|||||||
* @param justOwner should we just search for owner? Or with rights?
|
* @param justOwner should we just search for owner? Or with rights?
|
||||||
* @return An array of plots for the player
|
* @return An array of plots for the player
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public Plot[] getPlots(World world, Player player, boolean justOwner) {
|
||||||
public Plot[] getPlots(World world, Player player, boolean justOwner) {
|
|
||||||
ArrayList<Plot> pPlots = new ArrayList<>();
|
ArrayList<Plot> pPlots = new ArrayList<>();
|
||||||
UUID uuid = BukkitUtil.getPlayer(player).getUUID();
|
UUID uuid = BukkitUtil.getPlayer(player).getUUID();
|
||||||
for (Plot plot : PS.get().getPlots(world.getName())) {
|
for (Plot plot : PS.get().getPlots(world.getName())) {
|
||||||
@ -485,14 +437,11 @@ public class PlotAPI {
|
|||||||
* Get all plots for the world.
|
* Get all plots for the world.
|
||||||
*
|
*
|
||||||
* @param world to get plots of
|
* @param world to get plots of
|
||||||
*
|
|
||||||
* @return Plot[] - array of plot objects in world
|
* @return Plot[] - array of plot objects in world
|
||||||
*
|
|
||||||
* @see PS#getPlots(String)
|
* @see PS#getPlots(String)
|
||||||
* @see Plot
|
* @see Plot
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public Plot[] getPlots(World world) {
|
||||||
public Plot[] getPlots(World world) {
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return new Plot[0];
|
return new Plot[0];
|
||||||
}
|
}
|
||||||
@ -504,11 +453,8 @@ public class PlotAPI {
|
|||||||
* Get all plot worlds.
|
* Get all plot worlds.
|
||||||
*
|
*
|
||||||
* @return World[] - array of plot worlds
|
* @return World[] - array of plot worlds
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public String[] getPlotWorlds() {
|
||||||
@Deprecated
|
|
||||||
public String[] getPlotWorlds() {
|
|
||||||
Set<String> plotWorldStrings = PS.get().getPlotWorldStrings();
|
Set<String> plotWorldStrings = PS.get().getPlotWorldStrings();
|
||||||
return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
|
return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
|
||||||
}
|
}
|
||||||
@ -517,13 +463,10 @@ public class PlotAPI {
|
|||||||
* Get if plotworld.
|
* Get if plotworld.
|
||||||
*
|
*
|
||||||
* @param world The world to check
|
* @param world The world to check
|
||||||
*
|
|
||||||
* @return boolean (if plot world or not)
|
* @return boolean (if plot world or not)
|
||||||
*
|
|
||||||
* @see PS#hasPlotArea(String)
|
* @see PS#hasPlotArea(String)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public boolean isPlotWorld(World world) {
|
||||||
public boolean isPlotWorld(World world) {
|
|
||||||
return PS.get().hasPlotArea(world.getName());
|
return PS.get().hasPlotArea(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,16 +474,11 @@ public class PlotAPI {
|
|||||||
* Get plot locations.
|
* Get plot locations.
|
||||||
*
|
*
|
||||||
* @param plot Plot to get the locations for
|
* @param plot Plot to get the locations for
|
||||||
*
|
|
||||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
|
* @deprecated As merged plots may not have a rectangular shape
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public Location[] getLocations(Plot plot) {
|
||||||
@Deprecated
|
|
||||||
public Location[] getLocations(Plot plot) {
|
|
||||||
Location bukkitBottom = BukkitUtil.getLocation(plot.getCorners()[0]);
|
Location bukkitBottom = BukkitUtil.getLocation(plot.getCorners()[0]);
|
||||||
Location bukkitTop = BukkitUtil.getLocation(plot.getCorners()[1]);
|
Location bukkitTop = BukkitUtil.getLocation(plot.getCorners()[1]);
|
||||||
Location bukkitHome = BukkitUtil.getLocation(plot.getHome());
|
Location bukkitHome = BukkitUtil.getLocation(plot.getHome());
|
||||||
@ -551,9 +489,7 @@ public class PlotAPI {
|
|||||||
* Get home location.
|
* Get home location.
|
||||||
*
|
*
|
||||||
* @param plot Plot that you want to get the location for
|
* @param plot Plot that you want to get the location for
|
||||||
*
|
|
||||||
* @return plot bottom location
|
* @return plot bottom location
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
*/
|
*/
|
||||||
public Location getHomeLocation(Plot plot) {
|
public Location getHomeLocation(Plot plot) {
|
||||||
@ -564,16 +500,11 @@ public class PlotAPI {
|
|||||||
* Get Bottom Location (min, min, min).
|
* Get Bottom Location (min, min, min).
|
||||||
*
|
*
|
||||||
* @param plot Plot that you want to get the location for
|
* @param plot Plot that you want to get the location for
|
||||||
*
|
|
||||||
* @return plot bottom location
|
* @return plot bottom location
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
|
* @deprecated As merged plots may not have a rectangular shape
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public Location getBottomLocation(Plot plot) {
|
||||||
@Deprecated
|
|
||||||
public Location getBottomLocation(Plot plot) {
|
|
||||||
return BukkitUtil.getLocation(plot.getCorners()[0]);
|
return BukkitUtil.getLocation(plot.getCorners()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,16 +512,11 @@ public class PlotAPI {
|
|||||||
* Get Top Location (max, max, max).
|
* Get Top Location (max, max, max).
|
||||||
*
|
*
|
||||||
* @param plot Plot that you want to get the location for
|
* @param plot Plot that you want to get the location for
|
||||||
*
|
|
||||||
* @return plot top location
|
* @return plot top location
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
|
* @deprecated As merged plots may not have a rectangular shape
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Deprecated public Location getTopLocation(Plot plot) {
|
||||||
@Deprecated
|
|
||||||
public Location getTopLocation(Plot plot) {
|
|
||||||
return BukkitUtil.getLocation(plot.getCorners()[1]);
|
return BukkitUtil.getLocation(plot.getCorners()[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,9 +524,7 @@ public class PlotAPI {
|
|||||||
* Check whether or not a player is in a plot.
|
* Check whether or not a player is in a plot.
|
||||||
*
|
*
|
||||||
* @param player who we're checking for
|
* @param player who we're checking for
|
||||||
*
|
|
||||||
* @return true if the player is in a plot, false if not-
|
* @return true if the player is in a plot, false if not-
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public boolean isInPlot(Player player) {
|
public boolean isInPlot(Player player) {
|
||||||
return getPlot(player) != null;
|
return getPlot(player) != null;
|
||||||
@ -608,12 +532,12 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a subcommand.
|
* Register a subcommand.
|
||||||
* @deprecated Command registration is done on object creation
|
*
|
||||||
* @param c SubCommand, that we want to register
|
* @param c SubCommand, that we want to register
|
||||||
* @see SubCommand
|
* @see SubCommand
|
||||||
|
* @deprecated Command registration is done on object creation
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public void registerCommand(SubCommand c) {
|
||||||
public void registerCommand(SubCommand c) {
|
|
||||||
PS.debug("SubCommands are now registered on creation");
|
PS.debug("SubCommands are now registered on creation");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,7 +545,6 @@ public class PlotAPI {
|
|||||||
* Gets the PlotSquared class.
|
* Gets the PlotSquared class.
|
||||||
*
|
*
|
||||||
* @return PlotSquared Class
|
* @return PlotSquared Class
|
||||||
*
|
|
||||||
* @see PS
|
* @see PS
|
||||||
*/
|
*/
|
||||||
public PS getPlotSquared() {
|
public PS getPlotSquared() {
|
||||||
@ -633,9 +556,7 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @param world Specify the world we want to select the plots from
|
* @param world Specify the world we want to select the plots from
|
||||||
* @param player Player, for whom we're getting the plot count
|
* @param player Player, for whom we're getting the plot count
|
||||||
*
|
|
||||||
* @return the number of plots the player has
|
* @return the number of plots the player has
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public int getPlayerPlotCount(World world, Player player) {
|
public int getPlayerPlotCount(World world, Player player) {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
@ -649,11 +570,8 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @param world Specify the world we want to select the plots from
|
* @param world Specify the world we want to select the plots from
|
||||||
* @param player Player, for whom we're getting the plots
|
* @param player Player, for whom we're getting the plots
|
||||||
*
|
|
||||||
* @return a set containing the players plots
|
* @return a set containing the players plots
|
||||||
*
|
|
||||||
* @see PS#getPlots(String, PlotPlayer)
|
* @see PS#getPlots(String, PlotPlayer)
|
||||||
*
|
|
||||||
* @see Plot
|
* @see Plot
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(World world, Player player) {
|
public Set<Plot> getPlayerPlots(World world, Player player) {
|
||||||
@ -667,9 +585,7 @@ public class PlotAPI {
|
|||||||
* Gets the number of plots, which the player is able to build in.
|
* Gets the number of plots, which the player is able to build in.
|
||||||
*
|
*
|
||||||
* @param player player, for whom we're getting the plots
|
* @param player player, for whom we're getting the plots
|
||||||
*
|
|
||||||
* @return the number of allowed plots
|
* @return the number of allowed plots
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public int getAllowedPlots(Player player) {
|
public int getAllowedPlots(Player player) {
|
||||||
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
||||||
@ -680,10 +596,9 @@ public class PlotAPI {
|
|||||||
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
||||||
* will provide useful functions relating to players.
|
* will provide useful functions relating to players.
|
||||||
*
|
*
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
* @param player the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(Player player) {
|
public PlotPlayer wrapPlayer(Player player) {
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
@ -691,14 +606,13 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotPlayer for a UUID.
|
* Get the PlotPlayer for a UUID.
|
||||||
*
|
* <p>
|
||||||
* <p><i>Please note that PlotSquared can be configured to provide
|
* <p><i>Please note that PlotSquared can be configured to provide
|
||||||
* different UUIDs than bukkit</i>
|
* different UUIDs than bukkit</i>
|
||||||
*
|
*
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param uuid the uuid of the player to wrap
|
* @param uuid the uuid of the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
public PlotPlayer wrapPlayer(UUID uuid) {
|
||||||
return PlotPlayer.wrap(uuid);
|
return PlotPlayer.wrap(uuid);
|
||||||
@ -707,10 +621,9 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the PlotPlayer for a username.
|
* Get the PlotPlayer for a username.
|
||||||
*
|
*
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
* @param player the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(String player) {
|
public PlotPlayer wrapPlayer(String player) {
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
@ -718,14 +631,13 @@ public class PlotAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotPlayer for an offline player.
|
* Get the PlotPlayer for an offline player.
|
||||||
*
|
* <p>
|
||||||
* <p>Note that this will work if the player is offline, however not all
|
* <p>Note that this will work if the player is offline, however not all
|
||||||
* functionality will work.
|
* functionality will work.
|
||||||
*
|
*
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
* @param player the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(OfflinePlayer player) {
|
public PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.plotsquared.bukkit;
|
package com.plotsquared.bukkit;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||||
import com.intellectualcrafters.plot.IPlotMain;
|
import com.intellectualcrafters.plot.IPlotMain;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
@ -12,89 +10,27 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
|||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
|
||||||
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
|
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
|
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
import com.intellectualcrafters.plot.util.*;
|
||||||
import com.intellectualcrafters.plot.util.ChatManager;
|
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
|
||||||
import com.intellectualcrafters.plot.util.ConsoleColors;
|
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.EventUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.block.QueueProvider;
|
import com.intellectualcrafters.plot.util.block.QueueProvider;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
||||||
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
||||||
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.plotsquared.bukkit.listeners.ChunkListener;
|
import com.plotsquared.bukkit.listeners.*;
|
||||||
import com.plotsquared.bukkit.listeners.EntityPortal_1_7_9;
|
|
||||||
import com.plotsquared.bukkit.listeners.EntitySpawnListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents183;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_9;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener_1_12;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener_Legacy;
|
|
||||||
import com.plotsquared.bukkit.listeners.SingleWorldListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
|
||||||
import com.plotsquared.bukkit.titles.DefaultTitle_111;
|
import com.plotsquared.bukkit.titles.DefaultTitle_111;
|
||||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
import com.plotsquared.bukkit.util.*;
|
||||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
import com.plotsquared.bukkit.util.block.*;
|
||||||
import com.plotsquared.bukkit.util.BukkitCommand;
|
import com.plotsquared.bukkit.uuid.*;
|
||||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitEventUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitSchematicHandler;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitTaskManager;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
|
||||||
import com.plotsquared.bukkit.util.Metrics;
|
|
||||||
import com.plotsquared.bukkit.util.SendChunk;
|
|
||||||
import com.plotsquared.bukkit.util.SetGenCB;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_7;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8_3;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_9;
|
|
||||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.FileUUIDHandler;
|
|
||||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import java.io.File;
|
import org.bukkit.*;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -107,8 +43,17 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||||
|
|
||||||
|
public static WorldEdit worldEdit;
|
||||||
private static ConcurrentHashMap<String, Plugin> pluginMap;
|
private static ConcurrentHashMap<String, Plugin> pluginMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -128,14 +73,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Plugin> lookupNames = (Map<String, Plugin>) lookupNamesField.get(manager);
|
Map<String, Plugin> lookupNames =
|
||||||
|
(Map<String, Plugin>) lookupNamesField.get(manager);
|
||||||
lookupNames.remove("PlotMe");
|
lookupNames.remove("PlotMe");
|
||||||
lookupNames.remove("PlotMe-DefaultGenerator");
|
lookupNames.remove("PlotMe-DefaultGenerator");
|
||||||
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
|
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
|
||||||
@Override
|
@Override public boolean add(Plugin plugin) {
|
||||||
public boolean add(Plugin plugin) {
|
|
||||||
if (plugin.getName().startsWith("PlotMe")) {
|
if (plugin.getName().startsWith("PlotMe")) {
|
||||||
System.out.print("Disabling `" + plugin.getName() + "` for PlotMe conversion (configure in PlotSquared settings.yml)");
|
System.out.print("Disabling `" + plugin.getName()
|
||||||
|
+ "` for PlotMe conversion (configure in PlotSquared settings.yml)");
|
||||||
} else {
|
} else {
|
||||||
return super.add(plugin);
|
return super.add(plugin);
|
||||||
}
|
}
|
||||||
@ -143,8 +89,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
pluginMap = new ConcurrentHashMap<String, Plugin>(lookupNames) {
|
pluginMap = new ConcurrentHashMap<String, Plugin>(lookupNames) {
|
||||||
@Override
|
@Override public Plugin put(String key, Plugin plugin) {
|
||||||
public Plugin put(String key, Plugin plugin) {
|
|
||||||
if (!plugin.getName().startsWith("PlotMe")) {
|
if (!plugin.getName().startsWith("PlotMe")) {
|
||||||
return super.put(key, plugin);
|
return super.put(key, plugin);
|
||||||
}
|
}
|
||||||
@ -153,17 +98,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
};
|
};
|
||||||
lookupNamesField.set(manager, pluginMap);
|
lookupNamesField.set(manager, pluginMap);
|
||||||
}
|
}
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorldEdit worldEdit;
|
|
||||||
|
|
||||||
private int[] version;
|
private int[] version;
|
||||||
private String name;
|
private String name;
|
||||||
private SingleWorldListener singleWorldListener;
|
private SingleWorldListener singleWorldListener;
|
||||||
|
private Method methodUnloadChunk0;
|
||||||
|
private boolean methodUnloadSetup = false;
|
||||||
|
|
||||||
@Override
|
@Override public int[] getServerVersion() {
|
||||||
public int[] getServerVersion() {
|
|
||||||
if (this.version == null) {
|
if (this.version == null) {
|
||||||
try {
|
try {
|
||||||
this.version = new int[3];
|
this.version = new int[3];
|
||||||
@ -183,8 +128,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onEnable() {
|
||||||
public void onEnable() {
|
|
||||||
if (pluginMap != null) {
|
if (pluginMap != null) {
|
||||||
pluginMap.put("PlotMe-DefaultGenerator", this);
|
pluginMap.put("PlotMe-DefaultGenerator", this);
|
||||||
}
|
}
|
||||||
@ -199,8 +143,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
if (Settings.Enabled_Components.WORLDS) {
|
if (Settings.Enabled_Components.WORLDS) {
|
||||||
TaskManager.IMP.taskRepeat(new Runnable() {
|
TaskManager.IMP.taskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
}, 20);
|
}, 20);
|
||||||
@ -216,15 +159,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return singleWorldListener;
|
return singleWorldListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method methodUnloadChunk0;
|
|
||||||
private boolean methodUnloadSetup = false;
|
|
||||||
|
|
||||||
public void unload() {
|
public void unload() {
|
||||||
if (!methodUnloadSetup) {
|
if (!methodUnloadSetup) {
|
||||||
methodUnloadSetup = true;
|
methodUnloadSetup = true;
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||||
methodUnloadChunk0 = classCraftWorld.getRealClass().getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
methodUnloadChunk0 = classCraftWorld.getRealClass()
|
||||||
|
.getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
||||||
methodUnloadChunk0.setAccessible(true);
|
methodUnloadChunk0.setAccessible(true);
|
||||||
} catch (Throwable ignore) {
|
} catch (Throwable ignore) {
|
||||||
ignore.printStackTrace();
|
ignore.printStackTrace();
|
||||||
@ -238,7 +179,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
char char0 = name.charAt(0);
|
char char0 = name.charAt(0);
|
||||||
if (!Character.isDigit(char0) && char0 != '-') continue;
|
if (!Character.isDigit(char0) && char0 != '-')
|
||||||
|
continue;
|
||||||
if (!world.getPlayers().isEmpty()) {
|
if (!world.getPlayers().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -265,19 +207,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
boolean result;
|
boolean result;
|
||||||
if (methodUnloadChunk0 != null) {
|
if (methodUnloadChunk0 != null) {
|
||||||
try {
|
try {
|
||||||
result = (boolean) methodUnloadChunk0.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
result = (boolean) methodUnloadChunk0
|
||||||
|
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
methodUnloadChunk0 = null;
|
methodUnloadChunk0 = null;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = world.unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
|
result = world
|
||||||
|
.unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
} while (index < chunks.length && System.currentTimeMillis() - start < 5);
|
} while (index < chunks.length
|
||||||
|
&& System.currentTimeMillis() - start < 5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,14 +232,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onDisable() {
|
||||||
public void onDisable() {
|
|
||||||
PS.get().disable();
|
PS.get().disable();
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void log(String message) {
|
||||||
public void log(String message) {
|
|
||||||
try {
|
try {
|
||||||
message = C.color(message);
|
message = C.color(message);
|
||||||
if (!Settings.Chat.CONSOLE_COLOR) {
|
if (!Settings.Chat.CONSOLE_COLOR) {
|
||||||
@ -306,32 +249,29 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void disable() {
|
||||||
public void disable() {
|
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int[] getPluginVersion() {
|
||||||
public int[] getPluginVersion() {
|
|
||||||
String ver = getDescription().getVersion();
|
String ver = getDescription().getVersion();
|
||||||
if (ver.contains("-")) {
|
if (ver.contains("-")) {
|
||||||
ver = ver.split("-")[0];
|
ver = ver.split("-")[0];
|
||||||
}
|
}
|
||||||
String[] split = ver.split("\\.");
|
String[] split = ver.split("\\.");
|
||||||
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
|
return new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
||||||
|
Integer.parseInt(split[2])};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getPluginVersionString() {
|
@Override public String getPluginVersionString() {
|
||||||
return getDescription().getVersion();
|
return getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getPluginName() {
|
||||||
public String getPluginName() {
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerCommands() {
|
||||||
public void registerCommands() {
|
|
||||||
BukkitCommand bukkitCommand = new BukkitCommand();
|
BukkitCommand bukkitCommand = new BukkitCommand();
|
||||||
PluginCommand plotCommand = getCommand("plots");
|
PluginCommand plotCommand = getCommand("plots");
|
||||||
plotCommand.setExecutor(bukkitCommand);
|
plotCommand.setExecutor(bukkitCommand);
|
||||||
@ -339,30 +279,24 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
plotCommand.setTabCompleter(bukkitCommand);
|
plotCommand.setTabCompleter(bukkitCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public File getDirectory() {
|
||||||
public File getDirectory() {
|
|
||||||
return getDataFolder();
|
return getDataFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public File getWorldContainer() {
|
||||||
public File getWorldContainer() {
|
|
||||||
return Bukkit.getWorldContainer();
|
return Bukkit.getWorldContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public TaskManager getTaskManager() {
|
||||||
public TaskManager getTaskManager() {
|
|
||||||
return new BukkitTaskManager(this);
|
return new BukkitTaskManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void runEntityTask() {
|
||||||
public void runEntityTask() {
|
|
||||||
PS.log(C.PREFIX + "KillAllEntities started.");
|
PS.log(C.PREFIX + "KillAllEntities started.");
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||||
@Override
|
@Override public void run(PlotArea plotArea) {
|
||||||
public void run(PlotArea plotArea) {
|
|
||||||
World world = Bukkit.getWorld(plotArea.worldname);
|
World world = Bukkit.getWorld(plotArea.worldname);
|
||||||
try {
|
try {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
@ -416,7 +350,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
case MINECART_TNT:
|
case MINECART_TNT:
|
||||||
case BOAT:
|
case BOAT:
|
||||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||||
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
|
com.intellectualcrafters.plot.object.Location location =
|
||||||
|
BukkitUtil.getLocation(entity.getLocation());
|
||||||
Plot plot = location.getPlot();
|
Plot plot = location.getPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (location.isPlotArea()) {
|
if (location.isPlotArea()) {
|
||||||
@ -503,10 +438,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
Location location = entity.getLocation();
|
Location location = entity.getLocation();
|
||||||
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity =
|
||||||
if (!livingEntity.isLeashed() || !entity.hasMetadata("keep")) {
|
(LivingEntity) entity;
|
||||||
|
if (!livingEntity.isLeashed() || !entity
|
||||||
|
.hasMetadata("keep")) {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
if (!(passenger instanceof Player) && entity
|
||||||
|
.getMetadata("keep").isEmpty()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -514,7 +452,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
if (!(passenger instanceof Player) && entity
|
||||||
|
.getMetadata("keep").isEmpty()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -529,18 +468,28 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||||
if (meta != null && !meta.isEmpty()) {
|
if (meta != null && !meta.isEmpty()) {
|
||||||
if (livingEntity.isLeashed()) continue;
|
if (livingEntity.isLeashed())
|
||||||
|
continue;
|
||||||
|
|
||||||
List<MetadataValue> keep = entity.getMetadata("keep");
|
List<MetadataValue> keep =
|
||||||
if (keep != null && !keep.isEmpty()) continue;
|
entity.getMetadata("keep");
|
||||||
|
if (keep != null && !keep.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
PlotId originalPlotId =
|
||||||
|
(PlotId) meta.get(0).value();
|
||||||
if (originalPlotId != null) {
|
if (originalPlotId != null) {
|
||||||
com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation());
|
com.intellectualcrafters.plot.object.Location
|
||||||
|
pLoc = BukkitUtil
|
||||||
|
.getLocation(entity.getLocation());
|
||||||
PlotArea area = pLoc.getPlotArea();
|
PlotArea area = pLoc.getPlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
PlotId currentPlotId =
|
||||||
if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(originalPlotId).equals(area.getPlot(currentPlotId)))) {
|
PlotId.of(area.getPlotAbs(pLoc));
|
||||||
|
if (!originalPlotId.equals(currentPlotId)
|
||||||
|
&& (currentPlotId == null || !area
|
||||||
|
.getPlot(originalPlotId)
|
||||||
|
.equals(area.getPlot(currentPlotId)))) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
@ -548,12 +497,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||||
com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation());
|
com.intellectualcrafters.plot.object.Location pLoc =
|
||||||
|
BukkitUtil.getLocation(entity.getLocation());
|
||||||
PlotArea area = pLoc.getPlotArea();
|
PlotArea area = pLoc.getPlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
PlotId currentPlotId =
|
||||||
|
PlotId.of(area.getPlotAbs(pLoc));
|
||||||
if (currentPlotId != null) {
|
if (currentPlotId != null) {
|
||||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, currentPlotId));
|
entity.setMetadata("plot",
|
||||||
|
new FixedMetadataValue(
|
||||||
|
(Plugin) PS.get().IMP,
|
||||||
|
currentPlotId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,8 +525,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
|
||||||
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
|
|
||||||
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
|
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
|
||||||
initPlotMeConverter();
|
initPlotMeConverter();
|
||||||
Settings.Enabled_Components.PLOTME_CONVERTER = false;
|
Settings.Enabled_Components.PLOTME_CONVERTER = false;
|
||||||
@ -589,8 +542,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return (ChunkGenerator) result.specify(world);
|
return (ChunkGenerator) result.specify(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerPlayerEvents() {
|
||||||
public void registerPlayerEvents() {
|
|
||||||
PlayerEvents main = new PlayerEvents();
|
PlayerEvents main = new PlayerEvents();
|
||||||
getServer().getPluginManager().registerEvents(main, this);
|
getServer().getPluginManager().registerEvents(main, this);
|
||||||
try {
|
try {
|
||||||
@ -630,13 +582,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerInventoryEvents() {
|
||||||
public void registerInventoryEvents() {
|
|
||||||
// Part of PlayerEvents - can be moved if necessary
|
// Part of PlayerEvents - can be moved if necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerPlotPlusEvents() {
|
||||||
public void registerPlotPlusEvents() {
|
|
||||||
PlotPlusListener.startRunnable(this);
|
PlotPlusListener.startRunnable(this);
|
||||||
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_12_0)) {
|
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_12_0)) {
|
||||||
@ -646,12 +596,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerForceFieldEvents() {
|
||||||
public void registerForceFieldEvents() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean initWorldEdit() {
|
||||||
public boolean initWorldEdit() {
|
|
||||||
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||||
worldEdit = WorldEdit.getInstance();
|
worldEdit = WorldEdit.getInstance();
|
||||||
return true;
|
return true;
|
||||||
@ -659,8 +607,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public EconHandler getEconomyHandler() {
|
||||||
public EconHandler getEconomyHandler() {
|
|
||||||
try {
|
try {
|
||||||
BukkitEconHandler econ = new BukkitEconHandler();
|
BukkitEconHandler econ = new BukkitEconHandler();
|
||||||
if (econ.init()) {
|
if (econ.init()) {
|
||||||
@ -672,13 +619,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public QueueProvider initBlockQueue() {
|
||||||
public QueueProvider initBlockQueue() {
|
|
||||||
try {
|
try {
|
||||||
new SendChunk();
|
new SendChunk();
|
||||||
MainUtil.canSendChunk = true;
|
MainUtil.canSendChunk = true;
|
||||||
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
||||||
PS.debug(SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
|
PS.debug(
|
||||||
|
SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_13_0)) {
|
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_13_0)) {
|
||||||
@ -696,13 +643,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class);
|
return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public WorldUtil initWorldUtil() {
|
||||||
public WorldUtil initWorldUtil() {
|
|
||||||
return new BukkitUtil();
|
return new BukkitUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean initPlotMeConverter() {
|
||||||
public boolean initPlotMeConverter() {
|
|
||||||
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
|
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
|
||||||
return true;
|
return true;
|
||||||
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
|
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
|
||||||
@ -711,8 +656,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public GeneratorWrapper<?> getGenerator(String world, String name) {
|
||||||
public GeneratorWrapper<?> getGenerator(String world, String name) {
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -728,23 +672,21 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HybridUtils initHybridUtils() {
|
||||||
public HybridUtils initHybridUtils() {
|
|
||||||
return new BukkitHybridUtils();
|
return new BukkitHybridUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public SetupUtils initSetupUtils() {
|
||||||
public SetupUtils initSetupUtils() {
|
|
||||||
return new BukkitSetupUtils();
|
return new BukkitSetupUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
||||||
public UUIDHandlerImplementation initUUIDHandler() {
|
|
||||||
boolean checkVersion = false;
|
boolean checkVersion = false;
|
||||||
try {
|
try {
|
||||||
OfflinePlayer.class.getDeclaredMethod("getUniqueId");
|
OfflinePlayer.class.getDeclaredMethod("getUniqueId");
|
||||||
checkVersion = true;
|
checkVersion = true;
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
UUIDWrapper wrapper;
|
UUIDWrapper wrapper;
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||||
@ -765,17 +707,19 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
Settings.UUID.OFFLINE = true;
|
Settings.UUID.OFFLINE = true;
|
||||||
}
|
}
|
||||||
if (!checkVersion) {
|
if (!checkVersion) {
|
||||||
PS.log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
PS.log(C.PREFIX
|
||||||
|
+ " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||||
Settings.TITLES = false;
|
Settings.TITLES = false;
|
||||||
} else {
|
} else {
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
|
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
|
||||||
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
if (wrapper instanceof DefaultUUIDWrapper
|
||||||
|
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||||
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
PS.log(C.PREFIX
|
PS.log(C.PREFIX + " &6" + getPluginName()
|
||||||
+ " &6" + getPluginName() + " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||||
+ "Bukkit");
|
+ "Bukkit");
|
||||||
} else {
|
} else {
|
||||||
PS.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
PS.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
||||||
@ -787,53 +731,45 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChunkManager initChunkManager() {
|
||||||
public ChunkManager initChunkManager() {
|
|
||||||
return new BukkitChunkManager();
|
return new BukkitChunkManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public EventUtil initEventUtil() {
|
||||||
public EventUtil initEventUtil() {
|
|
||||||
return new BukkitEventUtil();
|
return new BukkitEventUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void unregister(PlotPlayer player) {
|
||||||
public void unregister(PlotPlayer player) {
|
|
||||||
BukkitUtil.removePlayer(player.getName());
|
BukkitUtil.removePlayer(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerChunkProcessor() {
|
||||||
public void registerChunkProcessor() {
|
|
||||||
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerWorldEvents() {
|
||||||
public void registerWorldEvents() {
|
|
||||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public IndependentPlotGenerator getDefaultGenerator() {
|
||||||
public IndependentPlotGenerator getDefaultGenerator() {
|
|
||||||
return new HybridGen();
|
return new HybridGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public InventoryUtil initInventoryUtil() {
|
||||||
public InventoryUtil initInventoryUtil() {
|
|
||||||
return new BukkitInventoryUtil();
|
return new BukkitInventoryUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void startMetrics() {
|
||||||
public void startMetrics() {
|
|
||||||
new Metrics(this).start();
|
new Metrics(this).start();
|
||||||
PS.log(C.PREFIX + "&6Metrics enabled.");
|
PS.log(C.PREFIX + "&6Metrics enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setGenerator(String worldName) {
|
||||||
public void setGenerator(String worldName) {
|
|
||||||
World world = BukkitUtil.getWorld(worldName);
|
World world = BukkitUtil.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
// create world
|
// create world
|
||||||
ConfigurationSection worldConfig = PS.get().worlds.getConfigurationSection("worlds." + worldName);
|
ConfigurationSection worldConfig =
|
||||||
|
PS.get().worlds.getConfigurationSection("worlds." + worldName);
|
||||||
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
||||||
SetupObject setup = new SetupObject();
|
SetupObject setup = new SetupObject();
|
||||||
setup.plotManager = manager;
|
setup.plotManager = manager;
|
||||||
@ -865,19 +801,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public SchematicHandler initSchematicHandler() {
|
||||||
public SchematicHandler initSchematicHandler() {
|
|
||||||
return new BukkitSchematicHandler();
|
return new BukkitSchematicHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public AbstractTitle initTitleManager() {
|
||||||
public AbstractTitle initTitleManager() {
|
|
||||||
// Already initialized in UUID handler
|
// Already initialized in UUID handler
|
||||||
return AbstractTitle.TITLE_CLASS;
|
return AbstractTitle.TITLE_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotPlayer wrapPlayer(Object player) {
|
||||||
public PlotPlayer wrapPlayer(Object player) {
|
|
||||||
if (player instanceof Player) {
|
if (player instanceof Player) {
|
||||||
return BukkitUtil.getPlayer((Player) player);
|
return BukkitUtil.getPlayer((Player) player);
|
||||||
}
|
}
|
||||||
@ -893,14 +826,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getNMSPackage() {
|
||||||
public String getNMSPackage() {
|
|
||||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
return name.substring(name.lastIndexOf('.') + 1);
|
return name.substring(name.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChatManager<?> initChatManager() {
|
||||||
public ChatManager<?> initChatManager() {
|
|
||||||
if (Settings.Chat.INTERACTIVE) {
|
if (Settings.Chat.INTERACTIVE) {
|
||||||
return new BukkitChatManager();
|
return new BukkitChatManager();
|
||||||
} else {
|
} else {
|
||||||
@ -913,11 +844,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return new BukkitPlotGenerator(generator);
|
return new BukkitPlotGenerator(generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<String> getPluginIds() {
|
||||||
public List<String> getPluginIds() {
|
|
||||||
ArrayList<String> names = new ArrayList<>();
|
ArrayList<String> names = new ArrayList<>();
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin.isEnabled());
|
names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin
|
||||||
|
.isEnabled());
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ import java.util.Collection;
|
|||||||
*/
|
*/
|
||||||
public final class ArrayWrapper<E> {
|
public final class ArrayWrapper<E> {
|
||||||
|
|
||||||
|
private E[] _array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array wrapper with some elements.
|
* Creates an array wrapper with some elements.
|
||||||
*
|
*
|
||||||
@ -28,7 +30,38 @@ public final class ArrayWrapper<E> {
|
|||||||
setArray(elements);
|
setArray(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private E[] _array;
|
/**
|
||||||
|
* Converts an iterable element collection to an array of elements.
|
||||||
|
* The iteration order of the specified object will be used as the array element order.
|
||||||
|
*
|
||||||
|
* @param list The iterable of objects which will be converted to an array.
|
||||||
|
* @param c The type of the elements of the array.
|
||||||
|
* @return An array of elements in the specified iterable.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked") public static <T> T[] toArray(Iterable<? extends T> list,
|
||||||
|
Class<T> c) {
|
||||||
|
int size = -1;
|
||||||
|
if (list instanceof Collection<?>) {
|
||||||
|
@SuppressWarnings("rawtypes") Collection coll = (Collection) list;
|
||||||
|
size = coll.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (size < 0) {
|
||||||
|
size = 0;
|
||||||
|
// Ugly hack: Count it ourselves
|
||||||
|
for (@SuppressWarnings("unused") T element : list) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T[] result = (T[]) Array.newInstance(c, size);
|
||||||
|
int i = 0;
|
||||||
|
for (T element : list) { // Assumes iteration order is consistent
|
||||||
|
result[i++] = element; // Assign array element at index THEN increment counter
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a reference to the wrapped array instance.
|
* Retrieves a reference to the wrapped array instance.
|
||||||
@ -54,9 +87,7 @@ public final class ArrayWrapper<E> {
|
|||||||
*
|
*
|
||||||
* @see Arrays#equals(Object[], Object[])
|
* @see Arrays#equals(Object[], Object[])
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes") @Override public boolean equals(Object other) {
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (!(other instanceof ArrayWrapper)) {
|
if (!(other instanceof ArrayWrapper)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -69,43 +100,8 @@ public final class ArrayWrapper<E> {
|
|||||||
* @return This object's hash code.
|
* @return This object's hash code.
|
||||||
* @see Arrays#hashCode(Object[])
|
* @see Arrays#hashCode(Object[])
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public int hashCode() {
|
||||||
public int hashCode() {
|
|
||||||
return Arrays.hashCode(_array);
|
return Arrays.hashCode(_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an iterable element collection to an array of elements.
|
|
||||||
* The iteration order of the specified object will be used as the array element order.
|
|
||||||
*
|
|
||||||
* @param list The iterable of objects which will be converted to an array.
|
|
||||||
* @param c The type of the elements of the array.
|
|
||||||
* @return An array of elements in the specified iterable.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
|
|
||||||
int size = -1;
|
|
||||||
if (list instanceof Collection<?>) {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
Collection coll = (Collection) list;
|
|
||||||
size = coll.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
size = 0;
|
|
||||||
// Ugly hack: Count it ourselves
|
|
||||||
for (@SuppressWarnings("unused") T element : list) {
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
T[] result = (T[]) Array.newInstance(c, size);
|
|
||||||
int i = 0;
|
|
||||||
for (T element : list) { // Assumes iteration order is consistent
|
|
||||||
result[i++] = element; // Assign array element at index THEN increment counter
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import org.bukkit.Achievement;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Statistic;
|
|
||||||
import org.bukkit.Statistic.Type;
|
import org.bukkit.Statistic.Type;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
@ -22,19 +16,12 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Field;
|
import java.util.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
|
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
|
||||||
* This class allows plugins to emulate the functionality of the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Commands#tellraw">tellraw command</a>.
|
* This class allows plugins to emulate the functionality of the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Commands#tellraw">tellraw command</a>.
|
||||||
@ -45,7 +32,14 @@ import java.util.logging.Level;
|
|||||||
* optionally initializing it with text. Further property-setting method calls will affect that editing component.
|
* optionally initializing it with text. Further property-setting method calls will affect that editing component.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<MessagePart>, ConfigurationSerializable {
|
public class FancyMessage
|
||||||
|
implements JsonRepresentedObject, Cloneable, Iterable<MessagePart>, ConfigurationSerializable {
|
||||||
|
|
||||||
|
private static Constructor<?> nmsPacketPlayOutChatConstructor;
|
||||||
|
// The ChatSerializer's instance of Gson
|
||||||
|
private static Object nmsChatSerializerGsonInstance;
|
||||||
|
private static Method fromJsonMethod;
|
||||||
|
private static JsonParser _stringParser = new JsonParser();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ConfigurationSerialization.registerClass(FancyMessage.class);
|
ConfigurationSerialization.registerClass(FancyMessage.class);
|
||||||
@ -55,20 +49,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
private String jsonString;
|
private String jsonString;
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
|
||||||
private static Constructor<?> nmsPacketPlayOutChatConstructor;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FancyMessage clone() throws CloneNotSupportedException {
|
|
||||||
FancyMessage instance = (FancyMessage) super.clone();
|
|
||||||
instance.messageParts = new ArrayList<>(messageParts.size());
|
|
||||||
for (int i = 0; i < messageParts.size(); i++) {
|
|
||||||
instance.messageParts.add(i, messageParts.get(i).clone());
|
|
||||||
}
|
|
||||||
instance.dirty = false;
|
|
||||||
instance.jsonString = null;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a JSON message with text.
|
* Creates a JSON message with text.
|
||||||
*
|
*
|
||||||
@ -85,10 +65,12 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
dirty = false;
|
dirty = false;
|
||||||
if (nmsPacketPlayOutChatConstructor == null) {
|
if (nmsPacketPlayOutChatConstructor == null) {
|
||||||
try {
|
try {
|
||||||
nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
|
nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat")
|
||||||
|
.getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
|
||||||
nmsPacketPlayOutChatConstructor.setAccessible(true);
|
nmsPacketPlayOutChatConstructor.setAccessible(true);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e);
|
||||||
}
|
}
|
||||||
@ -102,6 +84,112 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
this((TextualComponent) null);
|
this((TextualComponent) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a JSON-represented message from a mapping of key-value pairs.
|
||||||
|
* This is called by the Bukkit serialization API.
|
||||||
|
* It is not intended for direct public API consumption.
|
||||||
|
*
|
||||||
|
* @param serialized The key-value mapping which represents a fancy message.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked") public static FancyMessage deserialize(
|
||||||
|
Map<String, Object> serialized) {
|
||||||
|
FancyMessage msg = new FancyMessage();
|
||||||
|
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
||||||
|
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
||||||
|
msg.dirty = !serialized.containsKey("JSON");
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a fancy message from its JSON representation. This JSON representation is of the format of
|
||||||
|
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
||||||
|
*
|
||||||
|
* @param json The JSON string which represents a fancy message.
|
||||||
|
* @return A {@code FancyMessage} representing the parameterized JSON message.
|
||||||
|
*/
|
||||||
|
public static FancyMessage deserialize(String json) {
|
||||||
|
JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
||||||
|
JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
||||||
|
FancyMessage returnVal = new FancyMessage();
|
||||||
|
returnVal.messageParts.clear();
|
||||||
|
for (JsonElement mPrt : extra) {
|
||||||
|
MessagePart component = new MessagePart();
|
||||||
|
JsonObject messagePart = mPrt.getAsJsonObject();
|
||||||
|
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
||||||
|
// Deserialize text
|
||||||
|
if (TextualComponent.isTextKey(entry.getKey())) {
|
||||||
|
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
||||||
|
Map<String, Object> serializedMapForm =
|
||||||
|
new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
||||||
|
serializedMapForm.put("key", entry.getKey());
|
||||||
|
if (entry.getValue().isJsonPrimitive()) {
|
||||||
|
// Assume string
|
||||||
|
serializedMapForm.put("value", entry.getValue().getAsString());
|
||||||
|
} else {
|
||||||
|
// Composite object, but we assume each element is a string
|
||||||
|
for (Map.Entry<String, JsonElement> compositeNestedElement : entry
|
||||||
|
.getValue().getAsJsonObject().entrySet()) {
|
||||||
|
serializedMapForm.put("value." + compositeNestedElement.getKey(),
|
||||||
|
compositeNestedElement.getValue().getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
component.text = TextualComponent.deserialize(serializedMapForm);
|
||||||
|
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
|
||||||
|
if (entry.getValue().getAsBoolean()) {
|
||||||
|
component.styles
|
||||||
|
.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));
|
||||||
|
}
|
||||||
|
} else if (entry.getKey().equals("color")) {
|
||||||
|
component.color =
|
||||||
|
ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
||||||
|
} else if (entry.getKey().equals("clickEvent")) {
|
||||||
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
|
component.clickActionName = object.get("action").getAsString();
|
||||||
|
component.clickActionData = object.get("value").getAsString();
|
||||||
|
} else if (entry.getKey().equals("hoverEvent")) {
|
||||||
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
|
component.hoverActionName = object.get("action").getAsString();
|
||||||
|
if (object.get("value").isJsonPrimitive()) {
|
||||||
|
// Assume string
|
||||||
|
component.hoverActionData =
|
||||||
|
new JsonString(object.get("value").getAsString());
|
||||||
|
} else {
|
||||||
|
// Assume composite type
|
||||||
|
// The only composite type we currently store is another FancyMessage
|
||||||
|
// Therefore, recursion time!
|
||||||
|
component.hoverActionData = deserialize(object.get("value").toString() /* This should properly serialize the JSON object as a JSON string */);
|
||||||
|
}
|
||||||
|
} else if (entry.getKey().equals("insertion")) {
|
||||||
|
component.insertionData = entry.getValue().getAsString();
|
||||||
|
} else if (entry.getKey().equals("with")) {
|
||||||
|
for (JsonElement object : entry.getValue().getAsJsonArray()) {
|
||||||
|
if (object.isJsonPrimitive()) {
|
||||||
|
component.translationReplacements
|
||||||
|
.add(new JsonString(object.getAsString()));
|
||||||
|
} else {
|
||||||
|
// Only composite type stored in this array is - again - FancyMessages
|
||||||
|
// Recurse within this function to parse this as a translation replacement
|
||||||
|
component.translationReplacements.add(deserialize(object.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
returnVal.messageParts.add(component);
|
||||||
|
}
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public FancyMessage clone() throws CloneNotSupportedException {
|
||||||
|
FancyMessage instance = (FancyMessage) super.clone();
|
||||||
|
instance.messageParts = new ArrayList<>(messageParts.size());
|
||||||
|
for (int i = 0; i < messageParts.size(); i++) {
|
||||||
|
instance.messageParts.add(i, messageParts.get(i).clone());
|
||||||
|
}
|
||||||
|
instance.dirty = false;
|
||||||
|
instance.jsonString = null;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the text of the current editing component to a value.
|
* Sets the text of the current editing component to a value.
|
||||||
*
|
*
|
||||||
@ -242,8 +330,12 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
*/
|
*/
|
||||||
public FancyMessage achievementTooltip(final Achievement which) {
|
public FancyMessage achievementTooltip(final Achievement which) {
|
||||||
try {
|
try {
|
||||||
Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
|
Object achievement = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement",
|
||||||
|
Achievement.class).invoke(null, which);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name")
|
||||||
|
.get(achievement));
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
@ -251,7 +343,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,11 +360,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
public FancyMessage statisticTooltip(final Statistic which) {
|
public FancyMessage statisticTooltip(final Statistic which) {
|
||||||
Type type = which.getType();
|
Type type = which.getType();
|
||||||
if (type != Type.UNTYPED) {
|
if (type != Type.UNTYPED) {
|
||||||
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
|
throw new IllegalArgumentException(
|
||||||
|
"That statistic requires an additional " + type + " parameter!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic",
|
||||||
|
Statistic.class).invoke(null, which);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
@ -279,7 +377,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,11 +398,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
if ((type == Type.BLOCK && item.isBlock()) || type == Type.ENTITY) {
|
if ((type == Type.BLOCK && item.isBlock()) || type == Type.ENTITY) {
|
||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException(
|
||||||
|
"Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic",
|
||||||
|
Statistic.class, Material.class).invoke(null, which, item);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
@ -311,7 +415,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,11 +436,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
if (type != Type.ENTITY) {
|
if (type != Type.ENTITY) {
|
||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException(
|
||||||
|
"Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic",
|
||||||
|
Statistic.class, EntityType.class).invoke(null, which, entity);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
@ -343,7 +453,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,7 +467,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final String itemJSON) {
|
public FancyMessage itemTooltip(final String itemJSON) {
|
||||||
onHover("show_item", new JsonString(itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
|
onHover("show_item", new JsonString(
|
||||||
|
itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,8 +481,13 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
||||||
try {
|
try {
|
||||||
Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
Object nmsItem = Reflection
|
||||||
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound")).invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
|
.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy",
|
||||||
|
ItemStack.class).invoke(null, itemStack);
|
||||||
|
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save",
|
||||||
|
Reflection.getNMSClass("NBTTagCompound"))
|
||||||
|
.invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance())
|
||||||
|
.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return this;
|
return this;
|
||||||
@ -400,6 +517,22 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
tooltip(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, String.class));
|
tooltip(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, String.class));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||||
|
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||||
|
* @return This builder instance.
|
||||||
|
*/ /* ------------
|
||||||
|
public FancyMessage translationReplacements(final Iterable<? extends CharSequence> replacements){
|
||||||
|
for(CharSequence str : replacements){
|
||||||
|
latest().translationReplacements.add(new JsonString(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||||
@ -453,15 +586,19 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
|
|
||||||
FancyMessage result = new FancyMessage();
|
FancyMessage result = new FancyMessage();
|
||||||
result.messageParts.clear(); // Remove the one existing text component that exists by default, which destabilizes the object
|
result.messageParts
|
||||||
|
.clear(); // Remove the one existing text component that exists by default, which destabilizes the object
|
||||||
|
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
try {
|
try {
|
||||||
for (MessagePart component : lines[i]) {
|
for (MessagePart component : lines[i]) {
|
||||||
if (component.clickActionData != null && component.clickActionName != null) {
|
if (component.clickActionData != null && component.clickActionName != null) {
|
||||||
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
throw new IllegalArgumentException(
|
||||||
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
"The tooltip text cannot have click data.");
|
||||||
throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
|
} else if (component.hoverActionData != null
|
||||||
|
&& component.hoverActionName != null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"The tooltip text cannot have a tooltip.");
|
||||||
}
|
}
|
||||||
if (component.hasText()) {
|
if (component.hasText()) {
|
||||||
result.messageParts.add(component.clone());
|
result.messageParts.add(component.clone());
|
||||||
@ -475,7 +612,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formattedTooltip(result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
|
return formattedTooltip(
|
||||||
|
result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -486,7 +624,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
||||||
return formattedTooltip(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, FancyMessage.class));
|
return formattedTooltip(
|
||||||
|
com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -503,22 +642,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
|
||||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
|
||||||
* @return This builder instance.
|
|
||||||
*/ /* ------------
|
|
||||||
public FancyMessage translationReplacements(final Iterable<? extends CharSequence> replacements){
|
|
||||||
for(CharSequence str : replacements){
|
|
||||||
latest().translationReplacements.add(new JsonString(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||||
@ -543,7 +666,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
||||||
return translationReplacements(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(replacements, FancyMessage.class));
|
return translationReplacements(
|
||||||
|
com.plotsquared.bukkit.chat.ArrayWrapper.toArray(replacements, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -588,8 +712,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
if (messageParts.size() == 1) {
|
if (messageParts.size() == 1) {
|
||||||
latest().writeJson(writer);
|
latest().writeJson(writer);
|
||||||
} else {
|
} else {
|
||||||
@ -641,8 +764,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
try {
|
||||||
Object handle = Reflection.getHandle(player);
|
Object handle = Reflection.getHandle(player);
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection =
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
|
Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Reflection
|
||||||
|
.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet"))
|
||||||
|
.invoke(connection, createChatPacket(jsonString));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@ -650,7 +776,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -658,11 +785,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ChatSerializer's instance of Gson
|
private Object createChatPacket(String json)
|
||||||
private static Object nmsChatSerializerGsonInstance;
|
throws IllegalArgumentException, IllegalAccessException, InstantiationException,
|
||||||
private static Method fromJsonMethod;
|
InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||||
|
|
||||||
private Object createChatPacket(String json) throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
|
||||||
if (nmsChatSerializerGsonInstance == null) {
|
if (nmsChatSerializerGsonInstance == null) {
|
||||||
// Find the field and its value, completely bypassing obfuscation
|
// Find the field and its value, completely bypassing obfuscation
|
||||||
Class<?> chatSerializerClazz;
|
Class<?> chatSerializerClazz;
|
||||||
@ -673,7 +798,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
// Y = minor
|
// Y = minor
|
||||||
// Z = revision
|
// Z = revision
|
||||||
final String version = Reflection.getVersion();
|
final String version = Reflection.getVersion();
|
||||||
String[] split = version.substring(1, version.length() - 1).split("_"); // Remove trailing dot
|
String[] split =
|
||||||
|
version.substring(1, version.length() - 1).split("_"); // Remove trailing dot
|
||||||
//int majorVersion = Integer.parseInt(split[0]);
|
//int majorVersion = Integer.parseInt(split[0]);
|
||||||
int minorVersion = Integer.parseInt(split[1]);
|
int minorVersion = Integer.parseInt(split[1]);
|
||||||
int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R
|
int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R
|
||||||
@ -689,11 +815,14 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Field declaredField : chatSerializerClazz.getDeclaredFields()) {
|
for (Field declaredField : chatSerializerClazz.getDeclaredFields()) {
|
||||||
if (Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType().getName().endsWith("Gson")) {
|
if (Modifier.isFinal(declaredField.getModifiers()) && Modifier
|
||||||
|
.isStatic(declaredField.getModifiers()) && declaredField.getType().getName()
|
||||||
|
.endsWith("Gson")) {
|
||||||
// We've found our field
|
// We've found our field
|
||||||
declaredField.setAccessible(true);
|
declaredField.setAccessible(true);
|
||||||
nmsChatSerializerGsonInstance = declaredField.get(null);
|
nmsChatSerializerGsonInstance = declaredField.get(null);
|
||||||
fromJsonMethod = nmsChatSerializerGsonInstance.getClass().getMethod("fromJson", String.class, Class.class);
|
fromJsonMethod = nmsChatSerializerGsonInstance.getClass()
|
||||||
|
.getMethod("fromJson", String.class, Class.class);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -701,7 +830,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
|
|
||||||
// Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' than to reflectively call it
|
// Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' than to reflectively call it
|
||||||
// Of course, the implementation may change, but fuzzy matches might break with signature changes
|
// Of course, the implementation may change, but fuzzy matches might break with signature changes
|
||||||
Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent"));
|
Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json,
|
||||||
|
Reflection.getNMSClass("IChatBaseComponent"));
|
||||||
|
|
||||||
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
|
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
|
||||||
}
|
}
|
||||||
@ -786,22 +916,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes a JSON-represented message from a mapping of key-value pairs.
|
|
||||||
* This is called by the Bukkit serialization API.
|
|
||||||
* It is not intended for direct public API consumption.
|
|
||||||
*
|
|
||||||
* @param serialized The key-value mapping which represents a fancy message.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static FancyMessage deserialize(Map<String, Object> serialized) {
|
|
||||||
FancyMessage msg = new FancyMessage();
|
|
||||||
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
|
||||||
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
|
||||||
msg.dirty = !serialized.containsKey("JSON");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>Internally called method. Not for API consumption.</b>
|
* <b>Internally called method. Not for API consumption.</b>
|
||||||
*/
|
*/
|
||||||
@ -809,78 +923,4 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return messageParts.iterator();
|
return messageParts.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonParser _stringParser = new JsonParser();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes a fancy message from its JSON representation. This JSON representation is of the format of
|
|
||||||
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
|
||||||
*
|
|
||||||
* @param json The JSON string which represents a fancy message.
|
|
||||||
* @return A {@code FancyMessage} representing the parameterized JSON message.
|
|
||||||
*/
|
|
||||||
public static FancyMessage deserialize(String json) {
|
|
||||||
JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
|
||||||
JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
|
||||||
FancyMessage returnVal = new FancyMessage();
|
|
||||||
returnVal.messageParts.clear();
|
|
||||||
for (JsonElement mPrt : extra) {
|
|
||||||
MessagePart component = new MessagePart();
|
|
||||||
JsonObject messagePart = mPrt.getAsJsonObject();
|
|
||||||
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
|
||||||
// Deserialize text
|
|
||||||
if (TextualComponent.isTextKey(entry.getKey())) {
|
|
||||||
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
|
||||||
Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
|
||||||
serializedMapForm.put("key", entry.getKey());
|
|
||||||
if (entry.getValue().isJsonPrimitive()) {
|
|
||||||
// Assume string
|
|
||||||
serializedMapForm.put("value", entry.getValue().getAsString());
|
|
||||||
} else {
|
|
||||||
// Composite object, but we assume each element is a string
|
|
||||||
for (Map.Entry<String, JsonElement> compositeNestedElement : entry.getValue().getAsJsonObject().entrySet()) {
|
|
||||||
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
component.text = TextualComponent.deserialize(serializedMapForm);
|
|
||||||
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
|
|
||||||
if (entry.getValue().getAsBoolean()) {
|
|
||||||
component.styles.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));
|
|
||||||
}
|
|
||||||
} else if (entry.getKey().equals("color")) {
|
|
||||||
component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
|
||||||
} else if (entry.getKey().equals("clickEvent")) {
|
|
||||||
JsonObject object = entry.getValue().getAsJsonObject();
|
|
||||||
component.clickActionName = object.get("action").getAsString();
|
|
||||||
component.clickActionData = object.get("value").getAsString();
|
|
||||||
} else if (entry.getKey().equals("hoverEvent")) {
|
|
||||||
JsonObject object = entry.getValue().getAsJsonObject();
|
|
||||||
component.hoverActionName = object.get("action").getAsString();
|
|
||||||
if (object.get("value").isJsonPrimitive()) {
|
|
||||||
// Assume string
|
|
||||||
component.hoverActionData = new JsonString(object.get("value").getAsString());
|
|
||||||
} else {
|
|
||||||
// Assume composite type
|
|
||||||
// The only composite type we currently store is another FancyMessage
|
|
||||||
// Therefore, recursion time!
|
|
||||||
component.hoverActionData = deserialize(object.get("value").toString() /* This should properly serialize the JSON object as a JSON string */);
|
|
||||||
}
|
|
||||||
} else if (entry.getKey().equals("insertion")) {
|
|
||||||
component.insertionData = entry.getValue().getAsString();
|
|
||||||
} else if (entry.getKey().equals("with")) {
|
|
||||||
for (JsonElement object : entry.getValue().getAsJsonArray()) {
|
|
||||||
if (object.isJsonPrimitive()) {
|
|
||||||
component.translationReplacements.add(new JsonString(object.getAsString()));
|
|
||||||
} else {
|
|
||||||
// Only composite type stored in this array is - again - FancyMessages
|
|
||||||
// Recurse within this function to parse this as a translation replacement
|
|
||||||
component.translationReplacements.add(deserialize(object.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returnVal.messageParts.add(component);
|
|
||||||
}
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ interface JsonRepresentedObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the JSON representation of this object to the specified writer.
|
* Writes the JSON representation of this object to the specified writer.
|
||||||
|
*
|
||||||
* @param writer The JSON writer which will receive the object.
|
* @param writer The JSON writer which will receive the object.
|
||||||
* @throws IOException If an error occurs writing to the stream.
|
* @throws IOException If an error occurs writing to the stream.
|
||||||
*/
|
*/
|
||||||
|
@ -20,8 +20,11 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
|
|||||||
_value = value == null ? null : value.toString();
|
_value = value == null ? null : value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static JsonString deserialize(Map<String, Object> map) {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
return new JsonString(map.get("stringValue").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
writer.value(getValue());
|
writer.value(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,12 +38,7 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
|
|||||||
return theSingleValue;
|
return theSingleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonString deserialize(Map<String, Object> map) {
|
@Override public String toString() {
|
||||||
return new JsonString(map.get("stringValue").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,43 +19,6 @@ import java.util.logging.Level;
|
|||||||
*/
|
*/
|
||||||
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
|
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
|
||||||
|
|
||||||
ChatColor color = ChatColor.WHITE;
|
|
||||||
ArrayList<ChatColor> styles = new ArrayList<>();
|
|
||||||
String clickActionName = null;
|
|
||||||
String clickActionData = null;
|
|
||||||
String hoverActionName = null;
|
|
||||||
JsonRepresentedObject hoverActionData = null;
|
|
||||||
TextualComponent text = null;
|
|
||||||
String insertionData = null;
|
|
||||||
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
|
||||||
|
|
||||||
MessagePart(final TextualComponent text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagePart() {
|
|
||||||
this.text = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasText() {
|
|
||||||
return text != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public MessagePart clone() throws CloneNotSupportedException {
|
|
||||||
MessagePart obj = (MessagePart) super.clone();
|
|
||||||
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
|
||||||
if (hoverActionData instanceof JsonString) {
|
|
||||||
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
|
||||||
} else if (hoverActionData instanceof FancyMessage) {
|
|
||||||
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
|
||||||
}
|
|
||||||
obj.translationReplacements = (ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
|
||||||
return obj;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static final BiMap<ChatColor, String> stylesToNames;
|
static final BiMap<ChatColor, String> stylesToNames;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -83,6 +46,62 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
stylesToNames = builder.build();
|
stylesToNames = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
ConfigurationSerialization.registerClass(MessagePart.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatColor color = ChatColor.WHITE;
|
||||||
|
ArrayList<ChatColor> styles = new ArrayList<>();
|
||||||
|
String clickActionName = null;
|
||||||
|
String clickActionData = null;
|
||||||
|
String hoverActionName = null;
|
||||||
|
JsonRepresentedObject hoverActionData = null;
|
||||||
|
TextualComponent text = null;
|
||||||
|
String insertionData = null;
|
||||||
|
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
||||||
|
|
||||||
|
MessagePart(final TextualComponent text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePart() {
|
||||||
|
this.text = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static MessagePart deserialize(Map<String, Object> serialized) {
|
||||||
|
MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
||||||
|
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
||||||
|
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
||||||
|
part.hoverActionName = (String) serialized.get("hoverActionName");
|
||||||
|
part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
|
||||||
|
part.clickActionName = (String) serialized.get("clickActionName");
|
||||||
|
part.clickActionData = (String) serialized.get("clickActionData");
|
||||||
|
part.insertionData = (String) serialized.get("insertion");
|
||||||
|
part.translationReplacements =
|
||||||
|
(ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasText() {
|
||||||
|
return text != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @SuppressWarnings("unchecked") public MessagePart clone()
|
||||||
|
throws CloneNotSupportedException {
|
||||||
|
MessagePart obj = (MessagePart) super.clone();
|
||||||
|
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
||||||
|
if (hoverActionData instanceof JsonString) {
|
||||||
|
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
||||||
|
} else if (hoverActionData instanceof FancyMessage) {
|
||||||
|
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
||||||
|
}
|
||||||
|
obj.translationReplacements =
|
||||||
|
(ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void writeJson(JsonWriter json) {
|
public void writeJson(JsonWriter json) {
|
||||||
try {
|
try {
|
||||||
json.beginObject();
|
json.beginObject();
|
||||||
@ -92,16 +111,11 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
json.name(stylesToNames.get(style)).value(true);
|
json.name(stylesToNames.get(style)).value(true);
|
||||||
}
|
}
|
||||||
if (clickActionName != null && clickActionData != null) {
|
if (clickActionName != null && clickActionData != null) {
|
||||||
json.name("clickEvent")
|
json.name("clickEvent").beginObject().name("action").value(clickActionName)
|
||||||
.beginObject()
|
.name("value").value(clickActionData).endObject();
|
||||||
.name("action").value(clickActionName)
|
|
||||||
.name("value").value(clickActionData)
|
|
||||||
.endObject();
|
|
||||||
}
|
}
|
||||||
if (hoverActionName != null && hoverActionData != null) {
|
if (hoverActionName != null && hoverActionData != null) {
|
||||||
json.name("hoverEvent")
|
json.name("hoverEvent").beginObject().name("action").value(hoverActionName)
|
||||||
.beginObject()
|
|
||||||
.name("action").value(hoverActionName)
|
|
||||||
.name("value");
|
.name("value");
|
||||||
hoverActionData.writeJson(json);
|
hoverActionData.writeJson(json);
|
||||||
json.endObject();
|
json.endObject();
|
||||||
@ -109,7 +123,8 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
if (insertionData != null) {
|
if (insertionData != null) {
|
||||||
json.name("insertion").value(insertionData);
|
json.name("insertion").value(insertionData);
|
||||||
}
|
}
|
||||||
if (translationReplacements.size() > 0 && text != null && TextualComponent.isTranslatableText(text)) {
|
if (translationReplacements.size() > 0 && text != null && TextualComponent
|
||||||
|
.isTranslatableText(text)) {
|
||||||
json.name("with").beginArray();
|
json.name("with").beginArray();
|
||||||
for (JsonRepresentedObject obj : translationReplacements) {
|
for (JsonRepresentedObject obj : translationReplacements) {
|
||||||
obj.writeJson(json);
|
obj.writeJson(json);
|
||||||
@ -118,7 +133,8 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
}
|
}
|
||||||
json.endObject();
|
json.endObject();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A problem occured during writing of JSON string", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,22 +152,4 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static MessagePart deserialize(Map<String, Object> serialized) {
|
|
||||||
MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
|
||||||
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
|
||||||
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
|
||||||
part.hoverActionName = (String) serialized.get("hoverActionName");
|
|
||||||
part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
|
|
||||||
part.clickActionName = (String) serialized.get("clickActionName");
|
|
||||||
part.clickActionData = (String) serialized.get("clickActionData");
|
|
||||||
part.insertionData = (String) serialized.get("insertion");
|
|
||||||
part.translationReplacements = (ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
ConfigurationSerialization.registerClass(MessagePart.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,12 @@ public final class Reflection {
|
|||||||
* Contains loaded methods in a cache.
|
* Contains loaded methods in a cache.
|
||||||
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
||||||
*/
|
*/
|
||||||
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
|
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>>
|
||||||
|
_loadedMethods = new HashMap<>();
|
||||||
private static String _versionString;
|
private static String _versionString;
|
||||||
|
|
||||||
private Reflection() { }
|
private Reflection() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version string from the package name of the CraftBukkit server implementation.
|
* Gets the version string from the package name of the CraftBukkit server implementation.
|
||||||
@ -109,7 +111,8 @@ public final class Reflection {
|
|||||||
* @param obj The object for which to retrieve an NMS handle.
|
* @param obj The object for which to retrieve an NMS handle.
|
||||||
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
||||||
*/
|
*/
|
||||||
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
public synchronized static Object getHandle(Object obj)
|
||||||
|
throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
||||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +184,8 @@ public final class Reflection {
|
|||||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
|
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames =
|
||||||
|
_loadedMethods.get(clazz);
|
||||||
if (!loadedMethodNames.containsKey(name)) {
|
if (!loadedMethodNames.containsKey(name)) {
|
||||||
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
|
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
|
||||||
// Arbitrary text component
|
// Arbitrary text component
|
||||||
return ArbitraryTextTypeComponent.deserialize(map);
|
return ArbitraryTextTypeComponent.deserialize(map);
|
||||||
} else if (map.size() >= 2 && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
|
} else if (map.size() >= 2 && map.containsKey("key") && !map
|
||||||
|
.containsKey("value") /* It contains keys that START WITH value */) {
|
||||||
// Complex JSON object
|
// Complex JSON object
|
||||||
return ComplexTextTypeComponent.deserialize(map);
|
return ComplexTextTypeComponent.deserialize(map);
|
||||||
}
|
}
|
||||||
@ -36,16 +37,18 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isTextKey(String key) {
|
static boolean isTextKey(String key) {
|
||||||
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
|
return key.equals("translate") || key.equals("text") || key.equals("score") || key
|
||||||
|
.equals("selector");
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isTranslatableText(TextualComponent component) {
|
static boolean isTranslatableText(TextualComponent component) {
|
||||||
return component instanceof ComplexTextTypeComponent && component.getKey().equals("translate");
|
return component instanceof ComplexTextTypeComponent && component.getKey()
|
||||||
|
.equals("translate");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a textual component representing a string literal.
|
* Create a textual component representing a string literal.
|
||||||
*
|
* <p>
|
||||||
* <p>This is the default type of textual component when a single string
|
* <p>This is the default type of textual component when a single string
|
||||||
* literal is given to a method.
|
* literal is given to a method.
|
||||||
*
|
*
|
||||||
@ -73,7 +76,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void throwUnsupportedSnapshot() {
|
private static void throwUnsupportedSnapshot() {
|
||||||
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
|
throw new UnsupportedOperationException(
|
||||||
|
"This feature is only supported in snapshot releases.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +98,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Create a textual component representing a scoreboard value.
|
* Create a textual component representing a scoreboard value.
|
||||||
* The client will see the score of the specified player for the specified objective as the text represented by this component.
|
* The client will see the score of the specified player for the specified objective as the text represented by this component.
|
||||||
*
|
* <p>
|
||||||
* <p><b>This method is currently guaranteed to throw an {@code UnsupportedOperationException}
|
* <p><b>This method is currently guaranteed to throw an {@code UnsupportedOperationException}
|
||||||
* as it is only supported on snapshot clients.</b>
|
* as it is only supported on snapshot clients.</b>
|
||||||
*
|
*
|
||||||
@ -112,10 +116,9 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
||||||
// OVERLOADS documentation accordingly
|
// OVERLOADS documentation accordingly
|
||||||
|
|
||||||
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String>builder()
|
return new ComplexTextTypeComponent("score",
|
||||||
.put("name", playerName)
|
ImmutableMap.<String, String>builder().put("name", playerName)
|
||||||
.put("objective", scoreboardObjective)
|
.put("objective", scoreboardObjective).build());
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,8 +139,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
return new ArbitraryTextTypeComponent("selector", selector);
|
return new ArbitraryTextTypeComponent("selector", selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
return getReadableString();
|
return getReadableString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +157,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
* Clones a textual component instance.
|
* Clones a textual component instance.
|
||||||
* The returned object should not reference this textual component instance, but should maintain the same key and value.
|
* The returned object should not reference this textual component instance, but should maintain the same key and value.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public abstract TextualComponent clone() throws CloneNotSupportedException;
|
||||||
public abstract TextualComponent clone() throws CloneNotSupportedException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the text data represented by this textual component to the specified JSON writer object.
|
* Writes the text data represented by this textual component to the specified JSON writer object.
|
||||||
@ -171,7 +172,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
* Internal class used to represent all types of text components.
|
* Internal class used to represent all types of text components.
|
||||||
* Exception validating done is on keys and values.
|
* Exception validating done is on keys and values.
|
||||||
*/
|
*/
|
||||||
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ArbitraryTextTypeComponent extends TextualComponent
|
||||||
|
implements ConfigurationSerializable {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
@ -182,16 +184,17 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
|
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
|
||||||
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
|
return new ArbitraryTextTypeComponent(map.get("key").toString(),
|
||||||
|
map.get("value").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getKey() {
|
||||||
public String getKey() {
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
public void setKey(String key) {
|
||||||
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
|
Preconditions
|
||||||
|
.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,20 +207,16 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public TextualComponent clone() throws CloneNotSupportedException {
|
||||||
public TextualComponent clone() throws CloneNotSupportedException {
|
|
||||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||||
return new ArbitraryTextTypeComponent(getKey(), getValue());
|
return new ArbitraryTextTypeComponent(getKey(), getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
writer.name(getKey()).value(getValue());
|
writer.name(getKey()).value(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @SuppressWarnings("serial") public Map<String, Object> serialize() {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
return new HashMap<String, Object>() {
|
return new HashMap<String, Object>() {
|
||||||
{
|
{
|
||||||
put("key", getKey());
|
put("key", getKey());
|
||||||
@ -226,19 +225,20 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getReadableString() {
|
||||||
public String getReadableString() {
|
|
||||||
return getValue();
|
return getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class used to represent a text component with a nested JSON
|
* Internal class used to represent a text component with a nested JSON
|
||||||
* value.
|
* value.
|
||||||
*
|
* <p>
|
||||||
* <p>Exception validating done is on keys and values.
|
* <p>Exception validating done is on keys and values.
|
||||||
*/
|
*/
|
||||||
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ComplexTextTypeComponent extends TextualComponent
|
||||||
|
implements ConfigurationSerializable {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private Map<String, String> value;
|
private Map<String, String> value;
|
||||||
@ -255,19 +255,20 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
if (valEntry.getKey().equals("key")) {
|
if (valEntry.getKey().equals("key")) {
|
||||||
key = (String) valEntry.getValue();
|
key = (String) valEntry.getValue();
|
||||||
} else if (valEntry.getKey().startsWith("value.")) {
|
} else if (valEntry.getKey().startsWith("value.")) {
|
||||||
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
|
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */,
|
||||||
|
valEntry.getValue().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ComplexTextTypeComponent(key, value);
|
return new ComplexTextTypeComponent(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getKey() {
|
||||||
public String getKey() {
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
public void setKey(String key) {
|
||||||
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
|
Preconditions
|
||||||
|
.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,14 +281,12 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public TextualComponent clone() {
|
||||||
public TextualComponent clone() {
|
|
||||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||||
return new ComplexTextTypeComponent(getKey(), getValue());
|
return new ComplexTextTypeComponent(getKey(), getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
writer.name(getKey());
|
writer.name(getKey());
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
|
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
|
||||||
@ -296,9 +295,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @SuppressWarnings("serial") public Map<String, Object> serialize() {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
return new java.util.HashMap<String, Object>() {
|
return new java.util.HashMap<String, Object>() {
|
||||||
{
|
{
|
||||||
put("key", getKey());
|
put("key", getKey());
|
||||||
@ -309,8 +306,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getReadableString() {
|
||||||
public String getReadableString() {
|
|
||||||
return getKey();
|
return getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,7 @@ import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.*;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.uuid.DatFileFilter;
|
import com.plotsquared.bukkit.uuid.DatFileFilter;
|
||||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||||
@ -23,32 +19,22 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
|||||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||||
import com.plotsquared.general.commands.Argument;
|
import com.plotsquared.general.commands.Argument;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "uuidconvert", permission = "plots.admin", description = "Debug UUID conversion", usage = "/plot uuidconvert <lower|offline|online>", requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG)
|
||||||
command = "uuidconvert",
|
|
||||||
permission = "plots.admin",
|
|
||||||
description = "Debug UUID conversion",
|
|
||||||
usage = "/plot uuidconvert <lower|offline|online>",
|
|
||||||
requiredType = RequiredType.CONSOLE,
|
|
||||||
category = CommandCategory.DEBUG)
|
|
||||||
public class DebugUUID extends SubCommand {
|
public class DebugUUID extends SubCommand {
|
||||||
|
|
||||||
public DebugUUID() {
|
public DebugUUID() {
|
||||||
super(Argument.String);
|
super(Argument.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
|
||||||
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||||
final UUIDWrapper newWrapper;
|
final UUIDWrapper newWrapper;
|
||||||
|
|
||||||
@ -67,7 +53,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
Class<?> clazz = Class.forName(args[0]);
|
Class<?> clazz = Class.forName(args[0]);
|
||||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||||
|
"/plot uuidconvert <lower|offline|online>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,23 +62,29 @@ public class DebugUUID extends SubCommand {
|
|||||||
if (args.length != 2 || !"-o".equals(args[1])) {
|
if (args.length != 2 || !"-o".equals(args[1])) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||||
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
|
MainUtil.sendMessage(player,
|
||||||
MainUtil.sendMessage(player, "&8 - &cIf the process is interrupted, all plots could be deleted");
|
"&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||||
|
MainUtil.sendMessage(player,
|
||||||
|
"&8 - &cIf the process is interrupted, all plots could be deleted");
|
||||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||||
MainUtil.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
MainUtil
|
||||||
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
|
.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||||
|
MainUtil.sendMessage(player,
|
||||||
|
"&7Retype the command with the override parameter when ready :)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
|
if (currentUUIDWrapper.getClass().getCanonicalName()
|
||||||
|
.equals(newWrapper.getClass().getCanonicalName())) {
|
||||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
||||||
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
||||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||||
entry.getValue().kick("UUID conversion has been initiated. You may reconnect when finished.");
|
entry.getValue()
|
||||||
|
.kick("UUID conversion has been initiated. You may reconnect when finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Initializing map");
|
MainUtil.sendMessage(player, "&7 - Initializing map");
|
||||||
@ -135,12 +128,14 @@ public class DebugUUID extends SubCommand {
|
|||||||
OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||||
uuid = currentUUIDWrapper.getUUID(op);
|
uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse
|
||||||
|
.containsKey(uuid2)) {
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
MainUtil.sendMessage(player,
|
||||||
|
C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
@ -175,8 +170,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||||
String name = UUIDHandler.getName(entry.getKey());
|
String name = UUIDHandler.getName(entry.getKey());
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
@ -189,7 +183,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
List<String> lines =
|
||||||
|
Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
try {
|
try {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
@ -199,7 +194,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
String name = split[0];
|
String name = split[0];
|
||||||
if (name.isEmpty() || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
|
if (name.isEmpty() || name.length() > 16 || !StringMan
|
||||||
|
.isAlphanumericUnd(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UUID old = currentUUIDWrapper.getUUID(name);
|
UUID old = currentUUIDWrapper.getUUID(name);
|
||||||
@ -249,9 +245,9 @@ public class DebugUUID extends SubCommand {
|
|||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
DBFunc.createPlotsAndData(new ArrayList<>(PS.get().getPlots()),
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override public void run() {
|
||||||
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -272,18 +268,17 @@ public class DebugUUID extends SubCommand {
|
|||||||
try {
|
try {
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PS.get().worlds.save(PS.get().worldsFile);
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
MainUtil.sendMessage(player, "Could not save configuration. It will need to be manual set!");
|
MainUtil.sendMessage(player,
|
||||||
|
"Could not save configuration. It will need to be manual set!");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||||
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
MainUtil.sendMessage(player, "&aConversion complete!");
|
MainUtil.sendMessage(player, "&aConversion complete!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -291,7 +286,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
});
|
});
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
||||||
MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete");
|
MainUtil.sendMessage(player,
|
||||||
|
"&cConversion is still in progress, you will be notified when it is complete");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -13,9 +13,11 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public abstract class APlotMeConnector {
|
public abstract class APlotMeConnector {
|
||||||
|
|
||||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
|
String dataFolder);
|
||||||
|
|
||||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
|
throws SQLException;
|
||||||
|
|
||||||
public abstract boolean accepts(String version);
|
public abstract boolean accepts(String version);
|
||||||
|
|
||||||
@ -31,9 +33,11 @@ public abstract class APlotMeConnector {
|
|||||||
String wallBlock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
String wallBlock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".wall.block", wallBlock);
|
PS.get().worlds.set("worlds." + actualWorldName + ".wall.block", wallBlock);
|
||||||
String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
PS.get().worlds
|
||||||
|
.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
||||||
String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
PS.get().worlds
|
||||||
|
.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
||||||
String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.block", road);
|
PS.get().worlds.set("worlds." + actualWorldName + ".road.block", road);
|
||||||
int height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
int height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||||
@ -58,7 +62,8 @@ public abstract class APlotMeConnector {
|
|||||||
return new Location(null, x, 1, z);
|
return new Location(null, x, 1, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world,
|
||||||
|
PlotId id, int direction) {
|
||||||
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||||
PlotId id2 = new PlotId(id.x, id.y);
|
PlotId id2 = new PlotId(id.x, id.y);
|
||||||
boolean[] merge1;
|
boolean[] merge1;
|
||||||
|
@ -6,20 +6,12 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.database.SQLite;
|
import com.intellectualcrafters.plot.database.SQLite;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -29,8 +21,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
private String plugin = "PlotMe";
|
private String plugin = "PlotMe";
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
@Override
|
@Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
String dataFolder) {
|
||||||
this.plugin = plugin.toLowerCase();
|
this.plugin = plugin.toLowerCase();
|
||||||
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
|
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
|
||||||
try {
|
try {
|
||||||
@ -40,7 +32,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
String con = plotConfig.getString("mySQLconn");
|
String con = plotConfig.getString("mySQLconn");
|
||||||
return DriverManager.getConnection(con, user, password);
|
return DriverManager.getConnection(con, user, password);
|
||||||
} else {
|
} else {
|
||||||
return new SQLite(new File(dataFolder + File.separator + "plots.db")).openConnection();
|
return new SQLite(new File(dataFolder + File.separator + "plots.db"))
|
||||||
|
.openConnection();
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -48,13 +41,14 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
throws SQLException {
|
||||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||||
HashMap<String, Integer> roadWidth = new HashMap<>();
|
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Plots`");
|
PreparedStatement statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.prefix + "Plots`");
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
String column = null;
|
String column = null;
|
||||||
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerid");
|
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerid");
|
||||||
@ -64,7 +58,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
} else if (checkUUID2) {
|
} else if (checkUUID2) {
|
||||||
column = "ownerId";
|
column = "ownerId";
|
||||||
}
|
}
|
||||||
boolean merge = !"plotme".equalsIgnoreCase(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
boolean merge =
|
||||||
|
!"plotme".equalsIgnoreCase(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
||||||
int missing = 0;
|
int missing = 0;
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
||||||
@ -122,7 +117,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
missing++;
|
missing++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
owner = UUID.nameUUIDFromBytes(
|
||||||
|
("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UUIDHandler.add(new StringWrapper(name), owner);
|
UUIDHandler.add(new StringWrapper(name), owner);
|
||||||
@ -134,7 +130,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
PS.log("&cSome names could not be identified:");
|
PS.log("&cSome names could not be identified:");
|
||||||
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
||||||
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
||||||
PS.log("&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will "
|
PS.log(
|
||||||
|
"&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will "
|
||||||
+ "remain unknown until the player connects)");
|
+ "remain unknown until the player connects)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,12 +225,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
resultSet.close();
|
resultSet.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
} catch (SQLException ignored) {
|
||||||
|
}
|
||||||
return plots;
|
return plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean accepts(String version) {
|
||||||
public boolean accepts(String version) {
|
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get()
|
||||||
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get().canUpdate("0.999.999", version);
|
.canUpdate("0.999.999", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,11 @@ import com.intellectualcrafters.plot.object.PlotArea;
|
|||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.bukkit.command.CommandException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -20,17 +25,9 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.command.CommandException;
|
|
||||||
|
|
||||||
public class LikePlotMeConverter {
|
public class LikePlotMeConverter {
|
||||||
|
|
||||||
@ -54,7 +51,8 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPlotMePath() {
|
public String getPlotMePath() {
|
||||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator
|
||||||
|
+ plugin + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||||
@ -71,8 +69,9 @@ public class LikePlotMeConverter {
|
|||||||
|
|
||||||
public void mergeWorldYml(FileConfiguration plotConfig) {
|
public void mergeWorldYml(FileConfiguration plotConfig) {
|
||||||
try {
|
try {
|
||||||
File genConfig =
|
File genConfig = new File(
|
||||||
new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
"plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator"
|
||||||
|
+ File.separator + "config.yml");
|
||||||
if (genConfig.exists()) {
|
if (genConfig.exists()) {
|
||||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
||||||
for (String key : yml.getKeys(true)) {
|
for (String key : yml.getKeys(true)) {
|
||||||
@ -103,7 +102,8 @@ public class LikePlotMeConverter {
|
|||||||
content = content.replace("AthionPlots", pluginName);
|
content = content.replace("AthionPlots", pluginName);
|
||||||
content = content.replace("PlotZWorld", pluginName);
|
content = content.replace("PlotZWorld", pluginName);
|
||||||
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
|
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyConfig(ConfigurationSection plotmeDgYml, String world) throws IOException {
|
private void copyConfig(ConfigurationSection plotmeDgYml, String world) throws IOException {
|
||||||
@ -111,20 +111,25 @@ public class LikePlotMeConverter {
|
|||||||
String plotMeWorldName = world.toLowerCase();
|
String plotMeWorldName = world.toLowerCase();
|
||||||
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".road.width", pathWidth);
|
PS.get().worlds.set("worlds." + world + ".road.width", pathWidth);
|
||||||
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight", plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64)); //
|
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight",
|
||||||
|
plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64)); //
|
||||||
PS.get().worlds.set("worlds." + world + ".road.height", height);
|
PS.get().worlds.set("worlds." + world + ".road.height", height);
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.height", height);
|
PS.get().worlds.set("worlds." + world + ".wall.height", height);
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.height", height);
|
PS.get().worlds.set("worlds." + world + ".plot.height", height);
|
||||||
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
|
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.size", plotSize);
|
PS.get().worlds.set("worlds." + world + ".plot.size", plotSize);
|
||||||
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".UnclaimedBorder", plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44")); //
|
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".UnclaimedBorder",
|
||||||
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44")); //
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.block", wallblock);
|
PS.get().worlds.set("worlds." + world + ".wall.block", wallblock);
|
||||||
String claimed = plotmeDgYml.getString("worlds." + plotMeWorldName + ".ProtectedWallBlock", "44:1"); //
|
String claimed =
|
||||||
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".ProtectedWallBlock", "44:1"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.block_claimed", claimed);
|
PS.get().worlds.set("worlds." + world + ".wall.block_claimed", claimed);
|
||||||
String floor = plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
|
String floor =
|
||||||
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
PS.get().worlds.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
||||||
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
|
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
PS.get().worlds
|
||||||
|
.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
||||||
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
|
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
|
||||||
PS.get().worlds.set("worlds." + world + ".road.block", road);
|
PS.get().worlds.set("worlds." + world + ".road.block", road);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
||||||
@ -158,7 +163,8 @@ public class LikePlotMeConverter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage("PlotMe conversion has started. To disable this, please set 'enabled-components -> plotme-converter' to false in the 'settings.yml'");
|
sendMessage(
|
||||||
|
"PlotMe conversion has started. To disable this, please set 'enabled-components -> plotme-converter' to false in the 'settings.yml'");
|
||||||
|
|
||||||
mergeWorldYml(plotConfig);
|
mergeWorldYml(plotConfig);
|
||||||
|
|
||||||
@ -201,7 +207,9 @@ public class LikePlotMeConverter {
|
|||||||
sendMessage(" - " + dbPrefix + "Allowed");
|
sendMessage(" - " + dbPrefix + "Allowed");
|
||||||
|
|
||||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||||
File plotmeDgFile = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
File plotmeDgFile = new File(
|
||||||
|
dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator
|
||||||
|
+ "config.yml");
|
||||||
if (plotmeDgFile.exists()) {
|
if (plotmeDgFile.exists()) {
|
||||||
YamlConfiguration plotmeDgYml = YamlConfiguration.loadConfiguration(plotmeDgFile);
|
YamlConfiguration plotmeDgYml = YamlConfiguration.loadConfiguration(plotmeDgFile);
|
||||||
try {
|
try {
|
||||||
@ -227,7 +235,8 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world
|
PS.debug("&c[WARNING] Found " + duplicate
|
||||||
|
+ " duplicate plots already in DB for world: '" + world
|
||||||
+ "'. Have you run the converter already?");
|
+ "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -242,7 +251,8 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world
|
PS.debug("&c[WARNING] Found " + duplicate
|
||||||
|
+ " duplicate plots already in DB for world: '" + world
|
||||||
+ "'. Have you run the converter already?");
|
+ "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -255,18 +265,20 @@ public class LikePlotMeConverter {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
final AtomicBoolean done = new AtomicBoolean(false);
|
final AtomicBoolean done = new AtomicBoolean(false);
|
||||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (done.get()) {
|
if (done.get()) {
|
||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PS.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PS.debug(
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
"&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
|
PS.debug(
|
||||||
|
"&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
PS.debug("&c - Start the server");
|
PS.debug("&c - Start the server");
|
||||||
PS.get().setPlots(DBFunc.getPlots());
|
PS.get().setPlots(DBFunc.getPlots());
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage(
|
||||||
|
"&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,57 +290,70 @@ public class LikePlotMeConverter {
|
|||||||
sendMessage(" - &cFailed to save configuration.");
|
sendMessage(" - &cFailed to save configuration.");
|
||||||
}
|
}
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
boolean mv = false;
|
boolean mv = false;
|
||||||
boolean mw = false;
|
boolean mw = false;
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null)
|
||||||
.isEnabled()) {
|
&& Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
mv = true;
|
mv = true;
|
||||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld")
|
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null)
|
||||||
.isEnabled()) {
|
&& Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
mw = true;
|
mw = true;
|
||||||
}
|
}
|
||||||
for (String worldName : worlds) {
|
for (String worldName : worlds) {
|
||||||
World world = Bukkit.getWorld(getWorld(worldName));
|
World world = Bukkit.getWorld(getWorld(worldName));
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldName);
|
sendMessage(
|
||||||
|
"&cInvalid world in PlotMe configuration: " + worldName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String actualWorldName = world.getName();
|
String actualWorldName = world.getName();
|
||||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
sendMessage(
|
||||||
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName().equals(worldName)) {
|
"Reloading generator for world: '" + actualWorldName + "'...");
|
||||||
sendMessage("&cYou need to stop the server to reload this world properly");
|
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName()
|
||||||
|
.equals(worldName)) {
|
||||||
|
sendMessage(
|
||||||
|
"&cYou need to stop the server to reload this world properly");
|
||||||
} else {
|
} else {
|
||||||
PS.get().removePlotAreas(actualWorldName);
|
PS.get().removePlotAreas(actualWorldName);
|
||||||
if (mv) {
|
if (mv) {
|
||||||
// unload world with MV
|
// unload world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MV
|
// load world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
Bukkit.getServer()
|
||||||
"mv import " + actualWorldName + " normal -g " + PS.imp().getPluginName());
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv import " + actualWorldName + " normal -g " + PS
|
||||||
|
.imp().getPluginName());
|
||||||
} else if (mw) {
|
} else if (mw) {
|
||||||
// unload world with MW
|
// unload world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MW
|
// load world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
Bukkit.getServer()
|
||||||
"mw create " + actualWorldName + " plugin:" + PS.imp().getPluginName());
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw create " + actualWorldName + " plugin:" + PS.imp()
|
||||||
|
.getPluginName());
|
||||||
} else {
|
} else {
|
||||||
// Load using Bukkit API
|
// Load using Bukkit API
|
||||||
// - User must set generator manually
|
// - User must set generator manually
|
||||||
Bukkit.getServer().unloadWorld(world, true);
|
Bukkit.getServer().unloadWorld(world, true);
|
||||||
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator())).createWorld();
|
World myWorld = WorldCreator.name(actualWorldName).generator(
|
||||||
|
new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator()))
|
||||||
|
.createWorld();
|
||||||
myWorld.save();
|
myWorld.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,11 +365,14 @@ public class LikePlotMeConverter {
|
|||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PS.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PS.debug(
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
"&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
|
PS.debug(
|
||||||
|
"&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
PS.debug("&c - Start the server");
|
PS.debug("&c - Start the server");
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage(
|
||||||
|
"&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,11 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.database.SQLite;
|
import com.intellectualcrafters.plot.database.SQLite;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -25,8 +17,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
|
|
||||||
private String plugin;
|
private String plugin;
|
||||||
|
|
||||||
@Override
|
@Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
String dataFolder) {
|
||||||
this.plugin = plugin.toLowerCase();
|
this.plugin = plugin.toLowerCase();
|
||||||
try {
|
try {
|
||||||
if (plotConfig.getBoolean("usemySQL")) {
|
if (plotConfig.getBoolean("usemySQL")) {
|
||||||
@ -39,7 +31,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return new SQLite(file).openConnection();
|
return new SQLite(file).openConnection();
|
||||||
}
|
}
|
||||||
return new SQLite(new File(dataFolder + File.separator + "plots.db")).openConnection();
|
return new SQLite(new File(dataFolder + File.separator + "plots.db"))
|
||||||
|
.openConnection();
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -47,8 +40,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
throws SQLException {
|
||||||
ResultSet resultSet;
|
ResultSet resultSet;
|
||||||
PreparedStatement statement;
|
PreparedStatement statement;
|
||||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||||
@ -56,18 +49,21 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
HashMap<Integer, Plot> plots = new HashMap<>();
|
HashMap<Integer, Plot> plots = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_plots`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_plots`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
PS.debug("========= Table does not exist =========");
|
PS.debug("========= Table does not exist =========");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("=======================================");
|
PS.debug("=======================================");
|
||||||
PS.debug("&8 - &7The database does not match the version specified in the PlotMe config");
|
PS.debug(
|
||||||
|
"&8 - &7The database does not match the version specified in the PlotMe config");
|
||||||
PS.debug("&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3");
|
PS.debug("&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerID");
|
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerID");
|
||||||
boolean merge = !"plotme".equals(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
boolean merge =
|
||||||
|
!"plotme".equals(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
int key = resultSet.getInt("plot_id");
|
int key = resultSet.getInt("plot_id");
|
||||||
PlotId id = new PlotId(resultSet.getInt("plotX"), resultSet.getInt("plotZ"));
|
PlotId id = new PlotId(resultSet.getInt("plotX"), resultSet.getInt("plotZ"));
|
||||||
@ -115,7 +111,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + '\'');
|
PS.log(
|
||||||
|
"&cCould not identify owner for plot: " + id + " -> '" + name + '\'');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +134,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
statement.close();
|
statement.close();
|
||||||
try {
|
try {
|
||||||
PS.log(" - " + this.plugin + "core_denied");
|
PS.log(" - " + this.plugin + "core_denied");
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_denied`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_denied`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -153,7 +151,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PS.log(" - " + this.plugin + "core_allowed");
|
PS.log(" - " + this.plugin + "core_allowed");
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_allowed`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_allowed`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -186,8 +185,7 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean accepts(String version) {
|
||||||
public boolean accepts(String version) {
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,18 +49,15 @@ public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
|||||||
return this.flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,18 +45,15 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
|||||||
return this.auto;
|
return this.auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,7 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,7 @@ public class PlayerLeavePlotEvent extends PlayerEvent {
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,7 @@ public class PlayerPlotHelperEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,7 @@ public class PlayerPlotTrustedEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,6 @@ import org.bukkit.event.player.PlayerEvent;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player teleports to a plot
|
* Called when a player teleports to a plot
|
||||||
*
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
||||||
|
|
||||||
@ -37,8 +34,7 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +56,11 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean cancelled) {
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot is cleared
|
* Called when a plot is cleared
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public PlotClearEvent(Plot plot) {
|
public PlotClearEvent(Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
}
|
}
|
||||||
@ -39,18 +39,15 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
|||||||
return getPlot().getWorldName();
|
return getPlot().getWorldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot component is set
|
* Called when a plot component is set
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotComponentSetEvent extends PlotEvent {
|
public class PlotComponentSetEvent extends PlotEvent {
|
||||||
|
|
||||||
@ -49,8 +48,7 @@ public class PlotComponentSetEvent extends PlotEvent {
|
|||||||
return this.component;
|
return this.component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot is deleted
|
* Called when a plot is deleted
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotDeleteEvent extends PlotEvent {
|
public class PlotDeleteEvent extends PlotEvent {
|
||||||
|
|
||||||
@ -38,8 +37,7 @@ public class PlotDeleteEvent extends PlotEvent {
|
|||||||
return getPlot().getWorldName();
|
return getPlot().getWorldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a Flag is added to a plot.
|
* Called when a Flag is added to a plot.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
@ -39,18 +38,15 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final boolean isCancelled() {
|
||||||
public final boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setCancelled(boolean cancelled) {
|
||||||
public final void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a flag is removed from a plot
|
* Called when a flag is removed from a plot
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
@ -39,18 +38,15 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final boolean isCancelled() {
|
||||||
public final boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setCancelled(boolean cancelled) {
|
||||||
public final void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,18 +45,15 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.world;
|
return this.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ public class PlotRateEvent extends PlotEvent {
|
|||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,18 +50,15 @@ public class PlotUnlinkEvent extends Event implements Cancellable {
|
|||||||
return this.area;
|
return this.area;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
|||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void populate(World world, Random r, Chunk chunk) {
|
||||||
public void populate(World world, Random r, Chunk chunk) {
|
|
||||||
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,7 @@ package com.plotsquared.bukkit.generator;
|
|||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.ChunkWrapper;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
|
||||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
|
||||||
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@ -20,26 +13,24 @@ import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
|||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.bukkit.util.block.GenChunk;
|
import com.plotsquared.bukkit.util.block.GenChunk;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper<ChunkGenerator> {
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BukkitPlotGenerator extends ChunkGenerator
|
||||||
|
implements GeneratorWrapper<ChunkGenerator> {
|
||||||
|
|
||||||
private final GenChunk chunkSetter;
|
private final GenChunk chunkSetter;
|
||||||
private final PseudoRandom random = new PseudoRandom();
|
private final PseudoRandom random = new PseudoRandom();
|
||||||
private final IndependentPlotGenerator plotGenerator;
|
private final IndependentPlotGenerator plotGenerator;
|
||||||
private List<BlockPopulator> populators;
|
|
||||||
private final ChunkGenerator platformGenerator;
|
private final ChunkGenerator platformGenerator;
|
||||||
private final boolean full;
|
private final boolean full;
|
||||||
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
|
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
|
||||||
|
private List<BlockPopulator> populators;
|
||||||
private boolean loaded = false;
|
private boolean loaded = false;
|
||||||
|
|
||||||
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
||||||
@ -53,12 +44,12 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
private LocalBlockQueue queue;
|
private LocalBlockQueue queue;
|
||||||
|
|
||||||
@Override
|
@Override public void populate(World world, Random r, Chunk c) {
|
||||||
public void populate(World world, Random r, Chunk c) {
|
|
||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
||||||
}
|
}
|
||||||
byte[][] resultData = dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
|
byte[][] resultData =
|
||||||
|
dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
|
||||||
if (resultData == null) {
|
if (resultData == null) {
|
||||||
GenChunk result = BukkitPlotGenerator.this.chunkSetter;
|
GenChunk result = BukkitPlotGenerator.this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
@ -90,7 +81,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
||||||
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
|
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
|
||||||
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
|
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
|
||||||
if (BukkitPlotGenerator.this.plotGenerator.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) {
|
if (BukkitPlotGenerator.this.plotGenerator
|
||||||
|
.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) {
|
||||||
queue.flush();
|
queue.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,25 +94,24 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
||||||
if (cg instanceof BukkitPlotGenerator) {
|
if (cg instanceof BukkitPlotGenerator) {
|
||||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!");
|
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
||||||
|
+ " is already a BukkitPlotGenerator!");
|
||||||
}
|
}
|
||||||
this.full = false;
|
this.full = false;
|
||||||
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
||||||
this.platformGenerator = cg;
|
this.platformGenerator = cg;
|
||||||
this.plotGenerator = new IndependentPlotGenerator() {
|
this.plotGenerator = new IndependentPlotGenerator() {
|
||||||
@Override
|
@Override public void processSetup(SetupObject setup) {
|
||||||
public void processSetup(SetupObject setup) {}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void initialize(PlotArea area) {
|
||||||
public void initialize(PlotArea area) {}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotManager getNewPlotManager() {
|
||||||
public PlotManager getNewPlotManager() {
|
|
||||||
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
|
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
return cg.getClass().getName();
|
return cg.getClass().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,20 +121,19 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) {
|
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings,
|
||||||
|
PseudoRandom random) {
|
||||||
World w = BukkitUtil.getWorld(world);
|
World w = BukkitUtil.getWorld(world);
|
||||||
Location min = result.getMin();
|
Location min = result.getMin();
|
||||||
int cx = min.getX() >> 4;
|
int cx = min.getX() >> 4;
|
||||||
int cz = min.getZ() >> 4;
|
int cz = min.getZ() >> 4;
|
||||||
Random r = new Random(MathMan.pair((short) cx, (short) cz));
|
Random r = new Random(MathMan.pair((short) cx, (short) cz));
|
||||||
BiomeGrid grid = new BiomeGrid() {
|
BiomeGrid grid = new BiomeGrid() {
|
||||||
@Override
|
@Override public void setBiome(int x, int z, Biome biome) {
|
||||||
public void setBiome(int x, int z, Biome biome) {
|
|
||||||
result.setBiome(x, z, biome.name());
|
result.setBiome(x, z, biome.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Biome getBiome(int arg0, int arg1) {
|
||||||
public Biome getBiome(int arg0, int arg1) {
|
|
||||||
return Biome.FOREST;
|
return Biome.FOREST;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -153,7 +143,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
// Populator spillage
|
// Populator spillage
|
||||||
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
|
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
@ -188,28 +179,23 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void augment(PlotArea area) {
|
||||||
public void augment(PlotArea area) {
|
|
||||||
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.worldname));
|
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.worldname));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isFull() {
|
||||||
public boolean isFull() {
|
|
||||||
return this.full;
|
return this.full;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public IndependentPlotGenerator getPlotGenerator() {
|
||||||
public IndependentPlotGenerator getPlotGenerator() {
|
|
||||||
return this.plotGenerator;
|
return this.plotGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChunkGenerator getPlatformGenerator() {
|
||||||
public ChunkGenerator getPlatformGenerator() {
|
|
||||||
return this.platformGenerator;
|
return this.platformGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
|
||||||
try {
|
try {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
@ -309,8 +295,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
ChunkManager.postProcessChunk(result);
|
ChunkManager.postProcessChunk(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public short[][] generateExtBlockSections(World world, Random r, int cx, int cz,
|
||||||
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid grid) {
|
BiomeGrid grid) {
|
||||||
GenChunk result = this.chunkSetter;
|
GenChunk result = this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
|
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
|
||||||
@ -342,18 +328,17 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow spawning everywhere.
|
* Allow spawning everywhere.
|
||||||
|
*
|
||||||
* @param world Ignored
|
* @param world Ignored
|
||||||
* @param x Ignored
|
* @param x Ignored
|
||||||
* @param z Ignored
|
* @param z Ignored
|
||||||
* @return always true
|
* @return always true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public boolean canSpawn(World world, int x, int z) {
|
||||||
public boolean canSpawn(World world, int x, int z) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
if (this.platformGenerator == this) {
|
if (this.platformGenerator == this) {
|
||||||
return this.plotGenerator.getName();
|
return this.plotGenerator.getName();
|
||||||
}
|
}
|
||||||
@ -364,8 +349,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean equals(Object obj) {
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
|||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -29,6 +27,8 @@ import org.bukkit.event.entity.ItemSpawnEvent;
|
|||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ public class ChunkListener implements Listener {
|
|||||||
private RefMethod methodGetHandleChunk;
|
private RefMethod methodGetHandleChunk;
|
||||||
private RefField mustSave;
|
private RefField mustSave;
|
||||||
private Chunk lastChunk;
|
private Chunk lastChunk;
|
||||||
|
private boolean ignoreUnload = false;
|
||||||
|
|
||||||
public ChunkListener() {
|
public ChunkListener() {
|
||||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||||
@ -46,7 +47,8 @@ public class ChunkListener implements Listener {
|
|||||||
this.mustSave = classChunk.getField("mustSave");
|
this.mustSave = classChunk.getField("mustSave");
|
||||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
PS.debug(PS.imp().getPluginName() + "/Server not compatible for chunk processor trim/gc");
|
PS.debug(PS.imp().getPluginName()
|
||||||
|
+ "/Server not compatible for chunk processor trim/gc");
|
||||||
Settings.Chunk_Processor.AUTO_TRIM = false;
|
Settings.Chunk_Processor.AUTO_TRIM = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,8 +59,7 @@ public class ChunkListener implements Listener {
|
|||||||
world.setAutoSave(false);
|
world.setAutoSave(false);
|
||||||
}
|
}
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
HashSet<Chunk> toUnload = new HashSet<>();
|
HashSet<Chunk> toUnload = new HashSet<>();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
@ -67,11 +68,14 @@ public class ChunkListener implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||||
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
Object chunkMap =
|
||||||
Method methodIsChunkInUse = chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||||
|
Method methodIsChunkInUse = chunkMap.getClass()
|
||||||
|
.getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||||
Chunk[] chunks = world.getLoadedChunks();
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
for (Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
if ((boolean) methodIsChunkInUse.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
if ((boolean) methodIsChunkInUse
|
||||||
|
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int x = chunk.getX();
|
int x = chunk.getX();
|
||||||
@ -100,8 +104,6 @@ public class ChunkListener implements Listener {
|
|||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ignoreUnload = false;
|
|
||||||
|
|
||||||
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
|
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
|
||||||
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
|
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
|
||||||
return false;
|
return false;
|
||||||
@ -144,8 +146,7 @@ public class ChunkListener implements Listener {
|
|||||||
return plot != null && plot.hasOwner();
|
return plot != null && plot.hasOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
|
||||||
if (ignoreUnload) {
|
if (ignoreUnload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,13 +164,11 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
|
||||||
processChunk(event.getChunk(), false);
|
processChunk(event.getChunk(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) {
|
||||||
public void onItemSpawn(ItemSpawnEvent event) {
|
|
||||||
Item entity = event.getEntity();
|
Item entity = event.getEntity();
|
||||||
Chunk chunk = entity.getLocation().getChunk();
|
Chunk chunk = entity.getLocation().getChunk();
|
||||||
if (chunk == this.lastChunk) {
|
if (chunk == this.lastChunk) {
|
||||||
@ -223,8 +222,7 @@ public class ChunkListener implements Listener {
|
|||||||
TaskManager.index.incrementAndGet();
|
TaskManager.index.incrementAndGet();
|
||||||
final Integer currentIndex = TaskManager.index.get();
|
final Integer currentIndex = TaskManager.index.get();
|
||||||
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||||
TaskManager.tasks.remove(currentIndex);
|
TaskManager.tasks.remove(currentIndex);
|
||||||
@ -270,11 +268,13 @@ public class ChunkListener implements Listener {
|
|||||||
ent.remove();
|
ent.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PS.debug(C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
PS.debug(C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4)
|
||||||
|
+ "," + (chunk.getX() << 4));
|
||||||
}
|
}
|
||||||
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
||||||
if (unload) {
|
if (unload) {
|
||||||
PS.debug(C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
PS.debug(C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
|
||||||
|
chunk.getX() << 4));
|
||||||
cleanChunk(chunk);
|
cleanChunk(chunk);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
@ -17,62 +16,21 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class EntityPortal_1_7_9 implements Listener {
|
public class EntityPortal_1_7_9 implements Listener {
|
||||||
|
private static boolean ignoreTP = false;
|
||||||
|
|
||||||
public EntityPortal_1_7_9() {
|
public EntityPortal_1_7_9() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleUpdateEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleDestroyEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleEntityCollisionEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleCreateEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleBlockCollisionEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onTeleport(EntityTeleportEvent event) {
|
|
||||||
Entity ent = event.getEntity();
|
|
||||||
if (ent instanceof Vehicle || ent instanceof ArmorStand) test(event.getEntity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void spawn(CreatureSpawnEvent event) {
|
|
||||||
switch (event.getEntityType()) {
|
|
||||||
case ARMOR_STAND:
|
|
||||||
test(event.getEntity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean ignoreTP = false;
|
|
||||||
|
|
||||||
public static void test(Entity entity) {
|
public static void test(Entity entity) {
|
||||||
List<MetadataValue> meta = entity.getMetadata("plotworld");
|
List<MetadataValue> meta = entity.getMetadata("plotworld");
|
||||||
World world = entity.getLocation().getWorld();
|
World world = entity.getLocation().getWorld();
|
||||||
if (meta == null || meta.isEmpty()) {
|
if (meta == null || meta.isEmpty()) {
|
||||||
if (PS.get().isPlotWorld(world.getName())) {
|
if (PS.get().isPlotWorld(world.getName())) {
|
||||||
entity.setMetadata("plotworld", new FixedMetadataValue((Plugin) PS.get().IMP, entity.getLocation()));
|
entity.setMetadata("plotworld",
|
||||||
|
new FixedMetadataValue((Plugin) PS.get().IMP, entity.getLocation()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Location origin = (Location) meta.get(0).value();
|
Location origin = (Location) meta.get(0).value();
|
||||||
@ -96,4 +54,42 @@ public class EntityPortal_1_7_9 implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleUpdateEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleDestroyEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleEntityCollisionEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleCreateEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onTeleport(EntityTeleportEvent event) {
|
||||||
|
Entity ent = event.getEntity();
|
||||||
|
if (ent instanceof Vehicle || ent instanceof ArmorStand)
|
||||||
|
test(event.getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void spawn(CreatureSpawnEvent event) {
|
||||||
|
switch (event.getEntityType()) {
|
||||||
|
case ARMOR_STAND:
|
||||||
|
test(event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,8 @@ public class EntitySpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
case SHULKER:
|
case SHULKER:
|
||||||
if (!entity.hasMetadata("plot")) {
|
if (!entity.hasMetadata("plot")) {
|
||||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot.getId()));
|
entity.setMetadata("plot",
|
||||||
|
new FixedMetadataValue((Plugin) PS.get().IMP, plot.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,22 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
public class ForceFieldListener {
|
public class ForceFieldListener {
|
||||||
|
|
||||||
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||||
Set<PlotPlayer> players = new HashSet<>();
|
Set<PlotPlayer> players = new HashSet<>();
|
||||||
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
|
for (Player nearPlayer : Iterables
|
||||||
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
|
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||||
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -32,9 +35,11 @@ public class ForceFieldListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
||||||
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
|
for (Player nearPlayer : Iterables
|
||||||
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
|
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||||
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (plot.isAdded(plotPlayer.getUUID())) {
|
if (plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -81,7 +86,8 @@ public class ForceFieldListener {
|
|||||||
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||||
for (PlotPlayer oPlayer : players) {
|
for (PlotPlayer oPlayer : players) {
|
||||||
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||||
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
((BukkitPlayer) oPlayer).player
|
||||||
|
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,9 +11,6 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.listener.PlotListener;
|
import com.plotsquared.listener.PlotListener;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -31,12 +28,17 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event.isShiftClick()) {
|
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
|
||||||
|
.isShiftClick()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HumanEntity entity = event.getWhoClicked();
|
HumanEntity entity = event.getWhoClicked();
|
||||||
@ -71,7 +73,8 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
|||||||
switch (newItem.getType()) {
|
switch (newItem.getType()) {
|
||||||
case BANNER:
|
case BANNER:
|
||||||
case SKULL_ITEM:
|
case SKULL_ITEM:
|
||||||
if (newMeta != null) break;
|
if (newMeta != null)
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,9 +92,11 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
|||||||
switch (stateType) {
|
switch (stateType) {
|
||||||
case STANDING_BANNER:
|
case STANDING_BANNER:
|
||||||
case WALL_BANNER:
|
case WALL_BANNER:
|
||||||
if (itemType == Material.BANNER) break;
|
if (itemType == Material.BANNER)
|
||||||
|
break;
|
||||||
case SKULL:
|
case SKULL:
|
||||||
if (itemType == Material.SKULL_ITEM) break;
|
if (itemType == Material.SKULL_ITEM)
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -124,12 +129,15 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem.getDurability())) {
|
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
|
||||||
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
.getDurability())) {
|
||||||
|
event.setCursor(
|
||||||
|
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
event.setCursor(
|
||||||
|
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,6 @@ import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
|||||||
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.listener.PlotListener;
|
import com.plotsquared.listener.PlotListener;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -27,6 +23,11 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlotPlusListener extends PlotListener implements Listener {
|
public class PlotPlusListener extends PlotListener implements Listener {
|
||||||
|
|
||||||
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
|
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
|
||||||
@ -34,10 +35,10 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
|
|
||||||
public static void startRunnable(JavaPlugin plugin) {
|
public static void startRunnable(JavaPlugin plugin) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (!healRunnable.isEmpty()) {
|
if (!healRunnable.isEmpty()) {
|
||||||
for (Iterator<Entry<String, Interval>> iterator = healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
for (Iterator<Entry<String, Interval>> iterator =
|
||||||
|
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||||
Entry<String, Interval> entry = iterator.next();
|
Entry<String, Interval> entry = iterator.next();
|
||||||
Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
@ -56,7 +57,8 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!feedRunnable.isEmpty()) {
|
if (!feedRunnable.isEmpty()) {
|
||||||
for (Iterator<Entry<String, Interval>> iterator = feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
for (Iterator<Entry<String, Interval>> iterator =
|
||||||
|
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||||
Entry<String, Interval> entry = iterator.next();
|
Entry<String, Interval> entry = iterator.next();
|
||||||
Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
@ -78,8 +80,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}, 0L, 20L);
|
}, 0L, 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH) public void onInteract(BlockDamageEvent event) {
|
||||||
public void onInteract(BlockDamageEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||||
return;
|
return;
|
||||||
@ -98,8 +99,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||||
public void onDamage(EntityDamageEvent event) {
|
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,8 +113,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
||||||
public void onItemDrop(PlayerDropItemEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
@ -129,8 +128,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||||
public void onPlotEnter(PlayerEnterPlotEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
||||||
@ -145,16 +143,14 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
feedRunnable.remove(name);
|
feedRunnable.remove(name);
|
||||||
healRunnable.remove(name);
|
healRunnable.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
|
||||||
public void onPlotLeave(PlayerLeavePlotEvent event) {
|
|
||||||
Player leaver = event.getPlayer();
|
Player leaver = event.getPlayer();
|
||||||
Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
|
@ -4,16 +4,16 @@ import com.intellectualcrafters.plot.flag.Flags;
|
|||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlotPlusListener_1_12 implements Listener {
|
public class PlotPlusListener_1_12 implements Listener {
|
||||||
@EventHandler
|
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
||||||
public void onItemPickup(EntityPickupItemEvent event) {
|
|
||||||
LivingEntity ent = event.getEntity();
|
LivingEntity ent = event.getEntity();
|
||||||
if (ent instanceof Player) {
|
if (ent instanceof Player) {
|
||||||
Player player = (Player) ent;
|
Player player = (Player) ent;
|
||||||
|
@ -4,15 +4,15 @@ import com.intellectualcrafters.plot.flag.Flags;
|
|||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlotPlusListener_Legacy implements Listener {
|
public class PlotPlusListener_Legacy implements Listener {
|
||||||
@EventHandler
|
@EventHandler public void onItemPickup(PlayerPickupItemEvent event) {
|
||||||
public void onItemPickup(PlayerPickupItemEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
|
@ -4,8 +4,6 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -16,6 +14,8 @@ import org.bukkit.event.world.ChunkEvent;
|
|||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -42,10 +42,14 @@ public class SingleWorldListener implements Listener {
|
|||||||
public void markChunkAsClean(Chunk chunk) {
|
public void markChunkAsClean(Chunk chunk) {
|
||||||
try {
|
try {
|
||||||
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
||||||
if (done != null) this.done.set(nmsChunk, true);
|
if (done != null)
|
||||||
if (mustSave != null) this.mustSave.set(nmsChunk, false);
|
this.done.set(nmsChunk, true);
|
||||||
if (lit != null) this.lit.set(nmsChunk, false);
|
if (mustSave != null)
|
||||||
if (s != null) this.s.set(nmsChunk, false);
|
this.mustSave.set(nmsChunk, false);
|
||||||
|
if (lit != null)
|
||||||
|
this.lit.set(nmsChunk, false);
|
||||||
|
if (s != null)
|
||||||
|
this.s.set(nmsChunk, false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -55,8 +59,10 @@ public class SingleWorldListener implements Listener {
|
|||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
PlotAreaManager man = PS.get().getPlotAreaManager();
|
PlotAreaManager man = PS.get().getPlotAreaManager();
|
||||||
if (!(man instanceof SinglePlotAreaManager)) return;
|
if (!(man instanceof SinglePlotAreaManager))
|
||||||
if (!isPlotId(name)) return;
|
return;
|
||||||
|
if (!isPlotId(name))
|
||||||
|
return;
|
||||||
|
|
||||||
markChunkAsClean(event.getChunk());
|
markChunkAsClean(event.getChunk());
|
||||||
}
|
}
|
||||||
@ -66,8 +72,7 @@ public class SingleWorldListener implements Listener {
|
|||||||
// handle(event);
|
// handle(event);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST) public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
|
||||||
handle(event);
|
handle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ public class BukkitLazyBlock extends LazyBlock {
|
|||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getPlotBlock() {
|
||||||
public PlotBlock getPlotBlock() {
|
|
||||||
if (this.pb != null) {
|
if (this.pb != null) {
|
||||||
return this.pb;
|
return this.pb;
|
||||||
}
|
}
|
||||||
@ -127,8 +126,7 @@ public class BukkitLazyBlock extends LazyBlock {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getId() {
|
||||||
public int getId() {
|
|
||||||
if (this.id == 0) {
|
if (this.id == 0) {
|
||||||
this.id = this.block.getTypeId();
|
this.id = this.block.getTypeId();
|
||||||
}
|
}
|
||||||
|
@ -19,23 +19,19 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID() {
|
||||||
public UUID getUUID() {
|
|
||||||
return this.player.getUniqueId();
|
return this.player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public long getLastPlayed() {
|
||||||
public long getLastPlayed() {
|
|
||||||
return this.player.getLastPlayed();
|
return this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOnline() {
|
||||||
public boolean isOnline() {
|
|
||||||
return this.player.isOnline();
|
return this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
return this.player.getName();
|
return this.player.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.object.Location;
|
|||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.*;
|
import com.intellectualcrafters.plot.util.*;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.WeatherType;
|
import org.bukkit.WeatherType;
|
||||||
@ -14,13 +13,12 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventException;
|
import org.bukkit.event.EventException;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
|
||||||
|
|
||||||
public class BukkitPlayer extends PlotPlayer {
|
public class BukkitPlayer extends PlotPlayer {
|
||||||
|
|
||||||
public final Player player;
|
public final Player player;
|
||||||
@ -31,6 +29,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
/**
|
/**
|
||||||
* <p>Please do not use this method. Instead use
|
* <p>Please do not use this method. Instead use
|
||||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||||
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer(Player player) {
|
public BukkitPlayer(Player player) {
|
||||||
@ -44,14 +43,12 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
super.populatePersistentMetaMap();
|
super.populatePersistentMetaMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getLocation() {
|
||||||
public Location getLocation() {
|
|
||||||
Location location = super.getLocation();
|
Location location = super.getLocation();
|
||||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID() {
|
||||||
public UUID getUUID() {
|
|
||||||
if (this.uuid == null) {
|
if (this.uuid == null) {
|
||||||
this.uuid = UUIDHandler.getUUID(this);
|
this.uuid = UUIDHandler.getUUID(this);
|
||||||
}
|
}
|
||||||
@ -62,8 +59,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return this.player.getLastPlayed();
|
return this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean canTeleport(Location loc) {
|
||||||
public boolean canTeleport(Location loc) {
|
|
||||||
org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
||||||
org.bukkit.Location from = player.getLocation();
|
org.bukkit.Location from = player.getLocation();
|
||||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||||
@ -95,16 +91,14 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean hasPermission(String permission) {
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
if (this.offline && EconHandler.manager != null) {
|
if (this.offline && EconHandler.manager != null) {
|
||||||
return EconHandler.manager.hasPermission(getName(), permission);
|
return EconHandler.manager.hasPermission(getName(), permission);
|
||||||
}
|
}
|
||||||
return this.player.hasPermission(permission);
|
return this.player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int hasPermissionRange(String stub, int range) {
|
||||||
public int hasPermissionRange(String stub, int range) {
|
|
||||||
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@ -131,8 +125,10 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
String end = perm.substring(stubPlus.length());
|
String end = perm.substring(stubPlus.length());
|
||||||
if (MathMan.isInteger(end)) {
|
if (MathMan.isInteger(end)) {
|
||||||
int val = Integer.parseInt(end);
|
int val = Integer.parseInt(end);
|
||||||
if (val > range) return val;
|
if (val > range)
|
||||||
if (val > max) max = val;
|
return val;
|
||||||
|
if (val > max)
|
||||||
|
max = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,57 +142,52 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isPermissionSet(String permission) {
|
||||||
public boolean isPermissionSet(String permission) {
|
|
||||||
return this.player.isPermissionSet(permission);
|
return this.player.isPermissionSet(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void sendMessage(String message) {
|
||||||
public void sendMessage(String message) {
|
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (
|
||||||
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
||||||
setMeta("lastMessage", message);
|
setMeta("lastMessage", message);
|
||||||
setMeta("lastMessageTime", System.currentTimeMillis());
|
setMeta("lastMessageTime", System.currentTimeMillis());
|
||||||
this.player.sendMessage(message);
|
this.player.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void teleport(Location location) {
|
||||||
public void teleport(Location location) {
|
|
||||||
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.player.teleport(
|
this.player.teleport(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, location.getY(), location.getZ() + 0.5,
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
|
||||||
location.getYaw(), location.getPitch()), TeleportCause.COMMAND);
|
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()),
|
||||||
|
TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
if (this.name == null) {
|
if (this.name == null) {
|
||||||
this.name = this.player.getName();
|
this.name = this.player.getName();
|
||||||
}
|
}
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOnline() {
|
||||||
public boolean isOnline() {
|
|
||||||
return !this.offline && this.player.isOnline();
|
return !this.offline && this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCompassTarget(Location location) {
|
||||||
public void setCompassTarget(Location location) {
|
|
||||||
this.player.setCompassTarget(
|
this.player.setCompassTarget(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ()));
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(),
|
||||||
|
location.getY(), location.getZ()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getLocationFull() {
|
||||||
public Location getLocationFull() {
|
|
||||||
return BukkitUtil.getLocationFull(this.player);
|
return BukkitUtil.getLocationFull(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setWeather(PlotWeather weather) {
|
||||||
public void setWeather(PlotWeather weather) {
|
|
||||||
switch (weather) {
|
switch (weather) {
|
||||||
case CLEAR:
|
case CLEAR:
|
||||||
this.player.setPlayerWeather(WeatherType.CLEAR);
|
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||||
@ -213,8 +204,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotGameMode getGameMode() {
|
||||||
public PlotGameMode getGameMode() {
|
|
||||||
switch (this.player.getGameMode()) {
|
switch (this.player.getGameMode()) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return PlotGameMode.ADVENTURE;
|
return PlotGameMode.ADVENTURE;
|
||||||
@ -229,8 +219,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setGameMode(PlotGameMode gameMode) {
|
||||||
public void setGameMode(PlotGameMode gameMode) {
|
|
||||||
switch (gameMode) {
|
switch (gameMode) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
this.player.setGameMode(GameMode.ADVENTURE);
|
this.player.setGameMode(GameMode.ADVENTURE);
|
||||||
@ -250,8 +239,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setTime(long time) {
|
||||||
public void setTime(long time) {
|
|
||||||
if (time != Long.MAX_VALUE) {
|
if (time != Long.MAX_VALUE) {
|
||||||
this.player.setPlayerTime(time, false);
|
this.player.setPlayerTime(time, false);
|
||||||
} else {
|
} else {
|
||||||
@ -259,24 +247,20 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean getFlight() {
|
||||||
public void setFlight(boolean fly) {
|
|
||||||
this.player.setAllowFlight(fly);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getFlight() {
|
|
||||||
return player.getAllowFlight();
|
return player.getAllowFlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setFlight(boolean fly) {
|
||||||
public void playMusic(Location location, int id) {
|
this.player.setAllowFlight(fly);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void playMusic(Location location, int id) {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void kick(String message) {
|
||||||
public void kick(String message) {
|
|
||||||
this.player.kickPlayer(message);
|
this.player.kickPlayer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,8 +270,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isBanned() {
|
||||||
public boolean isBanned() {
|
|
||||||
return this.player.isBanned();
|
return this.player.isBanned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,34 +2,11 @@ package com.plotsquared.bukkit.object.entity;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
import com.plotsquared.bukkit.util.BukkitVersion;
|
||||||
import org.bukkit.Art;
|
import org.bukkit.*;
|
||||||
import org.bukkit.DyeColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Rotation;
|
|
||||||
import org.bukkit.TreeSpecies;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Bat;
|
|
||||||
import org.bukkit.entity.Boat;
|
|
||||||
import org.bukkit.entity.EnderDragon;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Guardian;
|
|
||||||
import org.bukkit.entity.Horse;
|
|
||||||
import org.bukkit.entity.IronGolem;
|
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.entity.ItemFrame;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Painting;
|
|
||||||
import org.bukkit.entity.Rabbit;
|
|
||||||
import org.bukkit.entity.Rabbit.Type;
|
import org.bukkit.entity.Rabbit.Type;
|
||||||
import org.bukkit.entity.Sheep;
|
|
||||||
import org.bukkit.entity.Skeleton;
|
|
||||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||||
import org.bukkit.entity.Slime;
|
|
||||||
import org.bukkit.entity.Tameable;
|
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -87,7 +64,8 @@ public class EntityWrapper {
|
|||||||
if (depth == 1) {
|
if (depth == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
|
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0)
|
||||||
|
|| entity instanceof ArmorStand) {
|
||||||
if (!entity.hasGravity()) {
|
if (!entity.hasGravity()) {
|
||||||
this.noGravity = true;
|
this.noGravity = true;
|
||||||
}
|
}
|
||||||
@ -220,13 +198,16 @@ public class EntityWrapper {
|
|||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
case SKELETON:
|
case SKELETON:
|
||||||
this.dataByte = getOrdinal(SkeletonType.values(),((Skeleton)entity).getSkeletonType());
|
this.dataByte =
|
||||||
|
getOrdinal(SkeletonType.values(), ((Skeleton) entity).getSkeletonType());
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
case ARMOR_STAND:
|
case ARMOR_STAND:
|
||||||
ArmorStand stand = (ArmorStand) entity;
|
ArmorStand stand = (ArmorStand) entity;
|
||||||
this.inventory = new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(),
|
this.inventory =
|
||||||
stand.getLeggings().clone(), stand.getBoots().clone()};
|
new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
||||||
|
stand.getChestplate().clone(), stand.getLeggings().clone(),
|
||||||
|
stand.getBoots().clone()};
|
||||||
storeLiving(stand);
|
storeLiving(stand);
|
||||||
this.stand = new ArmorStandStats();
|
this.stand = new ArmorStandStats();
|
||||||
|
|
||||||
@ -315,13 +296,11 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean equals(Object obj) {
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return this.hash == obj.hashCode();
|
return this.hash == obj.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int hashCode() {
|
||||||
public int hashCode() {
|
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,7 +452,8 @@ public class EntityWrapper {
|
|||||||
if (this.base.passenger != null) {
|
if (this.base.passenger != null) {
|
||||||
try {
|
try {
|
||||||
entity.setPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
entity.setPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.base.fall != 0) {
|
if (this.base.fall != 0) {
|
||||||
entity.setFallDistance(this.base.fall);
|
entity.setFallDistance(this.base.fall);
|
||||||
@ -488,7 +468,8 @@ public class EntityWrapper {
|
|||||||
if (this.depth == 1) {
|
if (this.depth == 1) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
|
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0)
|
||||||
|
|| entity instanceof ArmorStand) {
|
||||||
if (this.noGravity) {
|
if (this.noGravity) {
|
||||||
entity.setGravity(false);
|
entity.setGravity(false);
|
||||||
}
|
}
|
||||||
@ -642,27 +623,37 @@ public class EntityWrapper {
|
|||||||
stand.setBoots(this.inventory[4]);
|
stand.setBoots(this.inventory[4]);
|
||||||
}
|
}
|
||||||
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
EulerAngle pose =
|
||||||
|
new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
||||||
stand.setHeadPose(pose);
|
stand.setHeadPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
EulerAngle pose =
|
||||||
|
new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
||||||
stand.setBodyPose(pose);
|
stand.setBodyPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0 || this.stand.leftLeg[2] != 0) {
|
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
|
|| this.stand.leftLeg[2] != 0) {
|
||||||
|
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
|
||||||
|
this.stand.leftLeg[2]);
|
||||||
stand.setLeftLegPose(pose);
|
stand.setLeftLegPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0 || this.stand.rightLeg[2] != 0) {
|
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
|
|| this.stand.rightLeg[2] != 0) {
|
||||||
|
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
|
||||||
|
this.stand.rightLeg[2]);
|
||||||
stand.setRightLegPose(pose);
|
stand.setRightLegPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0 || this.stand.leftArm[2] != 0) {
|
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
|
|| this.stand.leftArm[2] != 0) {
|
||||||
|
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
|
||||||
|
this.stand.leftArm[2]);
|
||||||
stand.setLeftArmPose(pose);
|
stand.setLeftArmPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0 || this.stand.rightArm[2] != 0) {
|
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
|
|| this.stand.rightArm[2] != 0) {
|
||||||
|
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
|
||||||
|
this.stand.rightArm[2]);
|
||||||
stand.setRightArmPose(pose);
|
stand.setRightArmPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.invisible) {
|
if (this.stand.invisible) {
|
||||||
@ -729,9 +720,7 @@ public class EntityWrapper {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override public String toString() {
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.object.schematic;
|
package com.plotsquared.bukkit.object.schematic;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.ByteTag;
|
import com.intellectualcrafters.jnbt.*;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
|
||||||
import com.intellectualcrafters.jnbt.ListTag;
|
|
||||||
import com.intellectualcrafters.jnbt.ShortTag;
|
|
||||||
import com.intellectualcrafters.jnbt.Tag;
|
|
||||||
import com.intellectualcrafters.plot.object.schematic.ItemType;
|
import com.intellectualcrafters.plot.object.schematic.ItemType;
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -89,7 +85,8 @@ public class StateWrapper {
|
|||||||
InventoryHolder inv = (InventoryHolder) this.state;
|
InventoryHolder inv = (InventoryHolder) this.state;
|
||||||
ItemStack[] contents = inv.getInventory().getContents();
|
ItemStack[] contents = inv.getInventory().getContents();
|
||||||
Map<String, Tag> values = new HashMap<>();
|
Map<String, Tag> values = new HashMap<>();
|
||||||
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
|
values.put("Items",
|
||||||
|
new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
|
||||||
return new CompoundTag(values);
|
return new CompoundTag(values);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -18,7 +18,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
* @param stayTime Stay on screen time
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeOutTime Fade out time
|
* @param fadeOutTime Fade out time
|
||||||
*/
|
*/
|
||||||
DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime,
|
||||||
|
int fadeOutTime) {
|
||||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if (this.packetTitle != null) {
|
if (this.packetTitle != null) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
@ -41,38 +43,44 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
Object packet = this.packetTitle
|
||||||
|
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE,
|
||||||
|
Integer.TYPE, Integer.TYPE)
|
||||||
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
// Send if set
|
// Send if set
|
||||||
if (this.fadeInTime != -1 && this.fadeOutTime != -1 && this.stayTime != -1) {
|
if (this.fadeInTime != -1 && this.fadeOutTime != -1 && this.stayTime != -1) {
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||||
+ '}');
|
+ "\",color:" + this.titleColor.name().toLowerCase() + '}');
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[0], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
if (!this.getSubtitle().isEmpty()) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
|
||||||
.toLowerCase() + '}');
|
+ "\",color:" + this.subtitleColor.name().toLowerCase() + '}');
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void clearTitle(Player player)
|
||||||
public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null);
|
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[3], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +92,15 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public void resetTitle(Player player)
|
||||||
public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null);
|
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[4], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +117,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
|
|
||||||
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
if (m.getName().equals(name) && (args.length == 0 || classListEqual(args, m.getParameterTypes()))) {
|
if (m.getName().equals(name) && (args.length == 0 || classListEqual(args,
|
||||||
|
m.getParameterTypes()))) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -17,23 +17,23 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
|
|||||||
* @param stayTime Stay on screen time
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeOutTime Fade out time
|
* @param fadeOutTime Fade out time
|
||||||
*/
|
*/
|
||||||
DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime,
|
||||||
|
int fadeOutTime) {
|
||||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load spigot and NMS classes.
|
* Load spigot and NMS classes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override void loadClasses() {
|
||||||
void loadClasses() {
|
|
||||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||||
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||||
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void send(Player player)
|
||||||
public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if (this.packetTitle != null) {
|
if (this.packetTitle != null) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
@ -43,26 +43,29 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
|
|||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle
|
Object packet = this.packetTitle
|
||||||
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE,
|
||||||
.newInstance(actions[2], null,
|
Integer.TYPE, Integer.TYPE)
|
||||||
this.fadeInTime * (this.ticks ? 1 : 20),
|
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
// Send if set
|
// Send if set
|
||||||
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||||
+ "}");
|
+ "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[0], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
if (!this.getSubtitle().isEmpty()) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
|
||||||
.toLowerCase() + "}");
|
+ "\",color:" + this.subtitleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ import com.plotsquared.bukkit.object.BukkitPlayer;
|
|||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
import com.plotsquared.bukkit.util.BukkitVersion;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") public class DefaultTitle_111 extends AbstractTitle {
|
||||||
public class DefaultTitle_111 extends AbstractTitle {
|
|
||||||
|
|
||||||
private final boolean valid;
|
private final boolean valid;
|
||||||
|
|
||||||
@ -24,7 +23,8 @@ public class DefaultTitle_111 extends AbstractTitle {
|
|||||||
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
|
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
|
||||||
title.send(playerObj);
|
title.send(playerObj);
|
||||||
return;
|
return;
|
||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_180();
|
AbstractTitle.TITLE_CLASS = new DefaultTitle_180();
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
||||||
|
@ -6,8 +6,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") public class DefaultTitle_19 extends AbstractTitle {
|
||||||
public class DefaultTitle_19 extends AbstractTitle {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||||
@ -15,8 +14,7 @@ public class DefaultTitle_19 extends AbstractTitle {
|
|||||||
final Player playerObj = ((BukkitPlayer) player).player;
|
final Player playerObj = ((BukkitPlayer) player).player;
|
||||||
playerObj.sendTitle(head, sub);
|
playerObj.sendTitle(head, sub);
|
||||||
TaskManager.runTaskLater(new Runnable() {
|
TaskManager.runTaskLater(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
playerObj.sendTitle("", "");
|
playerObj.sendTitle("", "");
|
||||||
}
|
}
|
||||||
}, delay * 20);
|
}, delay * 20);
|
||||||
|
@ -26,14 +26,14 @@ public class HackTitleManager extends TitleManager {
|
|||||||
/**
|
/**
|
||||||
* Load spigot and NMS classes.
|
* Load spigot and NMS classes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override void loadClasses() {
|
||||||
void loadClasses() {
|
|
||||||
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
@ -42,8 +42,9 @@ public class HackTitleManager extends TitleManager {
|
|||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2],
|
Object packet = this.packetTitle
|
||||||
this.fadeInTime * (this.ticks ? 1 : 20),
|
.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
||||||
|
.newInstance(actions[2], this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
this.stayTime * (this.ticks ? 1 : 20),
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
this.fadeOutTime * (this.ticks ? 1 : 20));
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
// Send if set
|
// Send if set
|
||||||
@ -52,43 +53,49 @@ public class HackTitleManager extends TitleManager {
|
|||||||
}
|
}
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||||
+ "}");
|
+ "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
packet = this.packetTitle
|
||||||
|
.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||||
.newInstance(actions[0], serialized);
|
.newInstance(actions[0], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
if (!this.getSubtitle().isEmpty()) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
|
||||||
.toLowerCase() + "}");
|
+ "\",color:" + this.subtitleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
packet = this.packetTitle.getConstructor(this.packetActions,
|
||||||
|
Reflection.getNMSClass("IChatBaseComponent"))
|
||||||
.newInstance(actions[1], serialized);
|
.newInstance(actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void clearTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
Object packet =
|
||||||
|
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void resetTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
Object packet =
|
||||||
|
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +109,8 @@ public class HackTitleManager extends TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
private int getProtocolVersion(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
private int getProtocolVersion(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object networkManager = getValue("networkManager", connection);
|
Object networkManager = getValue("networkManager", connection);
|
||||||
@ -127,15 +135,18 @@ public class HackTitleManager extends TitleManager {
|
|||||||
private Class<?> getClass(String namespace) {
|
private Class<?> getClass(String namespace) {
|
||||||
try {
|
try {
|
||||||
return Class.forName(namespace);
|
return Class.forName(namespace);
|
||||||
} catch (ClassNotFoundException ignored) {}
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(String name, Class<?> clazz) throws NoSuchFieldException, SecurityException {
|
private Field getField(String name, Class<?> clazz)
|
||||||
|
throws NoSuchFieldException, SecurityException {
|
||||||
return clazz.getDeclaredField(name);
|
return clazz.getDeclaredField(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getValue(String name, Object obj) throws ReflectiveOperationException, SecurityException, IllegalArgumentException {
|
private Object getValue(String name, Object obj)
|
||||||
|
throws ReflectiveOperationException, SecurityException, IllegalArgumentException {
|
||||||
Field f = getField(name, obj.getClass());
|
Field f = getField(name, obj.getClass());
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
return f.get(obj);
|
return f.get(obj);
|
||||||
@ -154,7 +165,8 @@ public class HackTitleManager extends TitleManager {
|
|||||||
|
|
||||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
if (m.getName().equals(name) && ((args.length == 0) || classListEqual(args, m.getParameterTypes()))) {
|
if (m.getName().equals(name) && ((args.length == 0) || classListEqual(args,
|
||||||
|
m.getParameterTypes()))) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,13 @@ import java.util.Map;
|
|||||||
public abstract class TitleManager {
|
public abstract class TitleManager {
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||||
/* Title packet */
|
/* Title packet */ Class<?> packetTitle;
|
||||||
Class<?> packetTitle;
|
/* Title packet actions ENUM */ Class<?> packetActions;
|
||||||
/* Title packet actions ENUM */
|
/* Chat serializer */ Class<?> nmsChatSerializer;
|
||||||
Class<?> packetActions;
|
|
||||||
/* Chat serializer */
|
|
||||||
Class<?> nmsChatSerializer;
|
|
||||||
Class<?> chatBaseComponent;
|
Class<?> chatBaseComponent;
|
||||||
ChatColor titleColor = ChatColor.WHITE;
|
ChatColor titleColor = ChatColor.WHITE;
|
||||||
ChatColor subtitleColor = ChatColor.WHITE;
|
ChatColor subtitleColor = ChatColor.WHITE;
|
||||||
/* Title timings */
|
/* Title timings */ int fadeInTime = -1;
|
||||||
int fadeInTime = -1;
|
|
||||||
int stayTime = -1;
|
int stayTime = -1;
|
||||||
int fadeOutTime = -1;
|
int fadeOutTime = -1;
|
||||||
boolean ticks = false;
|
boolean ticks = false;
|
||||||
@ -154,7 +150,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts the title to all players.
|
* Broadcasts the title to all players.
|
||||||
@ -175,7 +172,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void clearTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the title settings.
|
* Resets the title settings.
|
||||||
@ -185,7 +183,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void resetTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||||
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
package com.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minecraft 1.8 Title
|
* Minecraft 1.8 Title
|
||||||
* For 1.11
|
* For 1.11
|
||||||
@ -17,6 +17,8 @@ import org.bukkit.entity.Player;
|
|||||||
* @version 1.1.0
|
* @version 1.1.0
|
||||||
*/
|
*/
|
||||||
public class TitleManager_1_11 {
|
public class TitleManager_1_11 {
|
||||||
|
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES =
|
||||||
|
new HashMap<Class<?>, Class<?>>();
|
||||||
/* Title packet */
|
/* Title packet */
|
||||||
private static Class<?> packetTitle;
|
private static Class<?> packetTitle;
|
||||||
/* Title packet actions ENUM */
|
/* Title packet actions ENUM */
|
||||||
@ -43,8 +45,6 @@ public class TitleManager_1_11 {
|
|||||||
private int fadeOutTime = -1;
|
private int fadeOutTime = -1;
|
||||||
private boolean ticks = false;
|
private boolean ticks = false;
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>();
|
|
||||||
|
|
||||||
public TitleManager_1_11() {
|
public TitleManager_1_11() {
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
@ -98,7 +98,8 @@ public class TitleManager_1_11 {
|
|||||||
* @param stayTime Stay on screen time
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeOutTime Fade out time
|
* @param fadeOutTime Fade out time
|
||||||
*/
|
*/
|
||||||
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime,
|
||||||
|
int fadeOutTime) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.subtitle = subtitle;
|
this.subtitle = subtitle;
|
||||||
this.fadeInTime = fadeInTime;
|
this.fadeInTime = fadeInTime;
|
||||||
@ -107,6 +108,15 @@ public class TitleManager_1_11 {
|
|||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||||
|
if (a.length != o.length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < a.length; i++)
|
||||||
|
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load spigot and NMS classes
|
* Load spigot and NMS classes
|
||||||
*/
|
*/
|
||||||
@ -118,23 +128,13 @@ public class TitleManager_1_11 {
|
|||||||
nmsChatSerializer = getNMSClass("ChatComponentText");
|
nmsChatSerializer = getNMSClass("ChatComponentText");
|
||||||
nmsPlayer = getNMSClass("EntityPlayer");
|
nmsPlayer = getNMSClass("EntityPlayer");
|
||||||
nmsPlayerConnection = getNMSClass("PlayerConnection");
|
nmsPlayerConnection = getNMSClass("PlayerConnection");
|
||||||
playerConnection = getField(nmsPlayer,
|
playerConnection = getField(nmsPlayer, "playerConnection");
|
||||||
"playerConnection");
|
|
||||||
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
|
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
|
||||||
obcPlayer = getOBCClass("entity.CraftPlayer");
|
obcPlayer = getOBCClass("entity.CraftPlayer");
|
||||||
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
|
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title text
|
|
||||||
*
|
|
||||||
* @param title Title
|
|
||||||
*/
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get title text
|
* Get title text
|
||||||
*
|
*
|
||||||
@ -145,12 +145,12 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set subtitle text
|
* Set title text
|
||||||
*
|
*
|
||||||
* @param subtitle Subtitle text
|
* @param title Title
|
||||||
*/
|
*/
|
||||||
public void setSubtitle(String subtitle) {
|
public void setTitle(String title) {
|
||||||
this.subtitle = subtitle;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,48 +163,12 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the title color
|
* Set subtitle text
|
||||||
*
|
*
|
||||||
* @param color Chat color
|
* @param subtitle Subtitle text
|
||||||
*/
|
*/
|
||||||
public void setTitleColor(ChatColor color) {
|
public void setSubtitle(String subtitle) {
|
||||||
this.titleColor = color;
|
this.subtitle = subtitle;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the subtitle color
|
|
||||||
*
|
|
||||||
* @param color Chat color
|
|
||||||
*/
|
|
||||||
public void setSubtitleColor(ChatColor color) {
|
|
||||||
this.subtitleColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title fade in time
|
|
||||||
*
|
|
||||||
* @param time Time
|
|
||||||
*/
|
|
||||||
public void setFadeInTime(int time) {
|
|
||||||
this.fadeInTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title fade out time
|
|
||||||
*
|
|
||||||
* @param time Time
|
|
||||||
*/
|
|
||||||
public void setFadeOutTime(int time) {
|
|
||||||
this.fadeOutTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title stay time
|
|
||||||
*
|
|
||||||
* @param time Time
|
|
||||||
*/
|
|
||||||
public void setStayTime(int time) {
|
|
||||||
this.stayTime = time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,12 +199,10 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle
|
||||||
chatBaseComponent, Integer.TYPE, Integer.TYPE,
|
.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE,
|
||||||
Integer.TYPE).newInstance(actions[3], null,
|
Integer.TYPE).newInstance(actions[3], null, fadeInTime * (ticks ? 1 : 20),
|
||||||
fadeInTime * (ticks ? 1 : 20),
|
stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20));
|
||||||
stayTime * (ticks ? 1 : 20),
|
|
||||||
fadeOutTime * (ticks ? 1 : 20));
|
|
||||||
// Send if set
|
// Send if set
|
||||||
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
@ -248,22 +210,18 @@ public class TitleManager_1_11 {
|
|||||||
Object serialized;
|
Object serialized;
|
||||||
if (!subtitle.equals("")) {
|
if (!subtitle.equals("")) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = nmsChatSerializer.getConstructor(String.class)
|
serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
.newInstance(subtitleColor +
|
subtitleColor + ChatColor.translateAlternateColorCodes('&', subtitle));
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
subtitle));
|
.newInstance(actions[1], serialized);
|
||||||
packet = packetTitle.getConstructor(packetActions,
|
|
||||||
chatBaseComponent).newInstance(actions[1],
|
|
||||||
serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send title
|
// Send title
|
||||||
serialized = nmsChatSerializer.getConstructor(
|
serialized = nmsChatSerializer.getConstructor(String.class)
|
||||||
String.class).newInstance(titleColor +
|
.newInstance(titleColor + ChatColor.translateAlternateColorCodes('&', title));
|
||||||
ChatColor.translateAlternateColorCodes('&', title));
|
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
packet = packetTitle.getConstructor(packetActions,
|
.newInstance(actions[0], serialized);
|
||||||
chatBaseComponent).newInstance(actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -278,19 +236,12 @@ public class TitleManager_1_11 {
|
|||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
new Class[]{TitleManager_1_11.packetActions, chatBaseComponent,
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent, Integer.TYPE,
|
||||||
Integer.TYPE, Integer.TYPE, Integer.TYPE})
|
Integer.TYPE, Integer.TYPE})
|
||||||
.newInstance(
|
.newInstance(actions[3], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
actions[3],
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
null,
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
this.fadeInTime
|
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
||||||
* (this.ticks ? 1 : 20),
|
|
||||||
this.stayTime
|
|
||||||
* (this.ticks ? 1 : 20),
|
|
||||||
this.fadeOutTime
|
|
||||||
* (this.ticks ? 1 : 20));
|
|
||||||
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1)
|
|
||||||
&& (this.stayTime != -1)) {
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -303,21 +254,14 @@ public class TitleManager_1_11 {
|
|||||||
if (TitleManager_1_11.packetTitle != null) {
|
if (TitleManager_1_11.packetTitle != null) {
|
||||||
try {
|
try {
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(),
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
"playerConnection").get(handle);
|
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(),
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
"sendPacket");
|
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
Object serialized = nmsChatSerializer.getConstructor(
|
titleColor + ChatColor.translateAlternateColorCodes('&', this.title));
|
||||||
String.class)
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
.newInstance(titleColor +
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
.newInstance(actions[0], serialized);
|
||||||
this.title));
|
|
||||||
Object packet = TitleManager_1_11.packetTitle
|
|
||||||
.getConstructor(
|
|
||||||
new Class[]{TitleManager_1_11.packetActions,
|
|
||||||
chatBaseComponent}).newInstance(
|
|
||||||
actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -331,16 +275,11 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Object serialized = nmsChatSerializer.getConstructor(
|
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
String.class)
|
subtitleColor + ChatColor.translateAlternateColorCodes('&', this.subtitle));
|
||||||
.newInstance(subtitleColor +
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||||
this.subtitle));
|
.newInstance(actions[1], serialized);
|
||||||
Object packet = TitleManager_1_11.packetTitle
|
|
||||||
.getConstructor(
|
|
||||||
new Class[]{TitleManager_1_11.packetActions,
|
|
||||||
chatBaseComponent}).newInstance(
|
|
||||||
actions[1], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -368,8 +307,8 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
chatBaseComponent).newInstance(actions[4], null);
|
.newInstance(actions[4], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -387,8 +326,8 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
chatBaseComponent).newInstance(actions[5], null);
|
.newInstance(actions[5], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -396,8 +335,7 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES
|
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||||
.get(clazz) : clazz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||||
@ -408,15 +346,6 @@ public class TitleManager_1_11 {
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
|
||||||
if (a.length != o.length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < a.length; i++)
|
|
||||||
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getHandle(Player player) {
|
private Object getHandle(Player player) {
|
||||||
try {
|
try {
|
||||||
return methodPlayerGetHandle.invoke(player);
|
return methodPlayerGetHandle.invoke(player);
|
||||||
@ -426,8 +355,7 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getMethod(String name, Class<?> clazz,
|
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||||
Class<?>... paramTypes) {
|
|
||||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||||
for (Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||||
@ -465,7 +393,6 @@ public class TitleManager_1_11 {
|
|||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Field getField(Class<?> clazz, String name) {
|
private Field getField(Class<?> clazz, String name) {
|
||||||
try {
|
try {
|
||||||
Field field = clazz.getDeclaredField(name);
|
Field field = clazz.getDeclaredField(name);
|
||||||
@ -479,8 +406,7 @@ public class TitleManager_1_11 {
|
|||||||
|
|
||||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (Method m : clazz.getMethods())
|
for (Method m : clazz.getMethods())
|
||||||
if (m.getName().equals(name)
|
if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args,
|
||||||
&& (args.length == 0 || ClassListEqual(args,
|
|
||||||
m.getParameterTypes()))) {
|
m.getParameterTypes()))) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m;
|
return m;
|
||||||
@ -504,22 +430,67 @@ public class TitleManager_1_11 {
|
|||||||
return titleColor;
|
return titleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the title color
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setTitleColor(ChatColor color) {
|
||||||
|
this.titleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public ChatColor getSubtitleColor() {
|
public ChatColor getSubtitleColor() {
|
||||||
return subtitleColor;
|
return subtitleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subtitle color
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setSubtitleColor(ChatColor color) {
|
||||||
|
this.subtitleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public int getFadeInTime() {
|
public int getFadeInTime() {
|
||||||
return fadeInTime;
|
return fadeInTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade in time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeInTime(int time) {
|
||||||
|
this.fadeInTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public int getFadeOutTime() {
|
public int getFadeOutTime() {
|
||||||
return fadeOutTime;
|
return fadeOutTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade out time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeOutTime(int time) {
|
||||||
|
this.fadeOutTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStayTime() {
|
public int getStayTime() {
|
||||||
return stayTime;
|
return stayTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title stay time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setStayTime(int time) {
|
||||||
|
this.stayTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTicks() {
|
public boolean isTicks() {
|
||||||
return ticks;
|
return ticks;
|
||||||
}
|
}
|
||||||
|
@ -15,18 +15,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BukkitChatManager extends ChatManager<FancyMessage> {
|
public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||||
|
|
||||||
@Override
|
@Override public FancyMessage builder() {
|
||||||
public FancyMessage builder() {
|
|
||||||
return new FancyMessage("");
|
return new FancyMessage("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void color(PlotMessage message, String color) {
|
||||||
public void color(PlotMessage message, String color) {
|
|
||||||
message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
||||||
public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
|
||||||
List<FancyMessage> lines = new ArrayList<>();
|
List<FancyMessage> lines = new ArrayList<>();
|
||||||
for (PlotMessage tooltip : tooltips) {
|
for (PlotMessage tooltip : tooltips) {
|
||||||
lines.add(tooltip.$(this));
|
lines.add(tooltip.$(this));
|
||||||
@ -34,18 +31,15 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
|||||||
message.$(this).formattedTooltip(lines);
|
message.$(this).formattedTooltip(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void command(PlotMessage message, String command) {
|
||||||
public void command(PlotMessage message, String command) {
|
|
||||||
message.$(this).command(command);
|
message.$(this).command(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void text(PlotMessage message, String text) {
|
||||||
public void text(PlotMessage message, String text) {
|
|
||||||
message.$(this).then(ChatColor.stripColor(text));
|
message.$(this).then(ChatColor.stripColor(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void send(PlotMessage plotMessage, PlotPlayer player) {
|
||||||
public void send(PlotMessage plotMessage, PlotPlayer player) {
|
|
||||||
if (player instanceof ConsolePlayer || !Settings.Chat.INTERACTIVE) {
|
if (player instanceof ConsolePlayer || !Settings.Chat.INTERACTIVE) {
|
||||||
player.sendMessage(plotMessage.$(this).toOldMessageFormat());
|
player.sendMessage(plotMessage.$(this).toOldMessageFormat());
|
||||||
} else {
|
} else {
|
||||||
@ -53,8 +47,7 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void suggest(PlotMessage plotMessage, String command) {
|
||||||
public void suggest(PlotMessage plotMessage, String command) {
|
|
||||||
plotMessage.$(this).suggest(command);
|
plotMessage.$(this).suggest(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,61 +2,23 @@ package com.plotsquared.bukkit.util;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
|
||||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import com.plotsquared.bukkit.object.entity.EntityWrapper;
|
import com.plotsquared.bukkit.object.entity.EntityWrapper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.DyeColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Note;
|
|
||||||
import org.bukkit.SkullType;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Banner;
|
|
||||||
import org.bukkit.block.Beacon;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.BrewingStand;
|
|
||||||
import org.bukkit.block.CommandBlock;
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
|
||||||
import org.bukkit.block.Dispenser;
|
|
||||||
import org.bukkit.block.Dropper;
|
|
||||||
import org.bukkit.block.Furnace;
|
|
||||||
import org.bukkit.block.Hopper;
|
|
||||||
import org.bukkit.block.Jukebox;
|
|
||||||
import org.bukkit.block.NoteBlock;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.block.Skull;
|
|
||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.Creature;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class BukkitChunkManager extends ChunkManager {
|
public class BukkitChunkManager extends ChunkManager {
|
||||||
|
|
||||||
@ -73,7 +35,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2, RegionWrapper r1, RegionWrapper r2) {
|
public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2,
|
||||||
|
RegionWrapper r1, RegionWrapper r2) {
|
||||||
ContentMap map = new ContentMap();
|
ContentMap map = new ContentMap();
|
||||||
int relX = r2.minX - r1.minX;
|
int relX = r2.minX - r1.minX;
|
||||||
int relZ = r2.minZ - r1.minZ;
|
int relZ = r2.minZ - r1.minZ;
|
||||||
@ -127,8 +90,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Set<ChunkLoc> getChunkChunks(String world) {
|
||||||
public Set<ChunkLoc> getChunkChunks(String world) {
|
|
||||||
Set<ChunkLoc> chunks = super.getChunkChunks(world);
|
Set<ChunkLoc> chunks = super.getChunkChunks(world);
|
||||||
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
||||||
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||||
@ -139,13 +101,15 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean copyRegion(Location pos1, Location pos2, Location newPos,
|
||||||
public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) {
|
final Runnable whenDone) {
|
||||||
final int relX = newPos.getX() - pos1.getX();
|
final int relX = newPos.getX() - pos1.getX();
|
||||||
final int relZ = newPos.getZ() - pos1.getZ();
|
final int relZ = newPos.getZ() - pos1.getZ();
|
||||||
Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
|
Location pos4 =
|
||||||
|
new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
|
||||||
|
|
||||||
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
final RegionWrapper region =
|
||||||
|
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||||
final String newWorldName = newWorld.getName();
|
final String newWorldName = newWorld.getName();
|
||||||
@ -153,8 +117,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
final ContentMap map = new ContentMap();
|
final ContentMap map = new ContentMap();
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
||||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||||
@Override
|
@Override public void run(int[] value) {
|
||||||
public void run(int[] value) {
|
|
||||||
int bx = value[2];
|
int bx = value[2];
|
||||||
int bz = value[3];
|
int bz = value[3];
|
||||||
int tx = value[4];
|
int tx = value[4];
|
||||||
@ -171,8 +134,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
|
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
|
||||||
PlotLoc loc = entry.getKey();
|
PlotLoc loc = entry.getKey();
|
||||||
PlotBlock[] blocks = entry.getValue();
|
PlotBlock[] blocks = entry.getValue();
|
||||||
@ -185,8 +147,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
map.restoreBlocks(newWorld, 0, 0);
|
map.restoreBlocks(newWorld, 0, 0);
|
||||||
map.restoreEntities(newWorld, relX, relZ);
|
map.restoreEntities(newWorld, relX, relZ);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -197,8 +158,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final boolean ignoreAugment, final Runnable whenDone) {
|
final boolean ignoreAugment, final Runnable whenDone) {
|
||||||
final String world = pos1.getWorld();
|
final String world = pos1.getWorld();
|
||||||
|
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
@ -219,8 +180,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
||||||
final ChunkLoc chunk = chunks.remove(0);
|
final ChunkLoc chunk = chunks.remove(0);
|
||||||
@ -235,11 +195,11 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||||
RegionWrapper currentPlotClear = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
RegionWrapper currentPlotClear =
|
||||||
|
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||||
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
queue.regenChunkSafe(chunk.x, chunk.z);
|
queue.regenChunkSafe(chunk.x, chunk.z);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -306,11 +266,9 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||||
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||||
@Override
|
@Override public void run(ScopedLocalBlockQueue value) {
|
||||||
public void run(ScopedLocalBlockQueue value) {
|
|
||||||
Location min = value.getMin();
|
Location min = value.getMin();
|
||||||
int bx = min.getX();
|
int bx = min.getX();
|
||||||
int bz = min.getZ();
|
int bz = min.getZ();
|
||||||
@ -319,7 +277,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
PlotLoc loc = new PlotLoc(bx + x, bz + z);
|
PlotLoc loc = new PlotLoc(bx + x, bz + z);
|
||||||
PlotBlock[] ids = map.allBlocks.get(loc);
|
PlotBlock[] ids = map.allBlocks.get(loc);
|
||||||
if (ids != null) {
|
if (ids != null) {
|
||||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
for (int y = 0;
|
||||||
|
y < Math.min(128, ids.length); y++) {
|
||||||
PlotBlock id = ids[y];
|
PlotBlock id = ids[y];
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
value.setBlock(x, y, z, id);
|
value.setBlock(x, y, z, id);
|
||||||
@ -327,7 +286,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
value.setBlock(x, y, z, 0, (byte) 0);
|
value.setBlock(x, y, z, 0, (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
for (int y = Math.min(128, ids.length);
|
||||||
|
y < ids.length; y++) {
|
||||||
PlotBlock id = ids[y];
|
PlotBlock id = ids[y];
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
value.setBlock(x, y, z, id);
|
value.setBlock(x, y, z, id);
|
||||||
@ -353,8 +313,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void clearAllEntities(Location pos1, Location pos2) {
|
||||||
public void clearAllEntities(Location pos1, Location pos2) {
|
|
||||||
String world = pos1.getWorld();
|
String world = pos1.getWorld();
|
||||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||||
int bx = pos1.getX();
|
int bx = pos1.getX();
|
||||||
@ -364,26 +323,24 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
if (!(entity instanceof Player)) {
|
if (!(entity instanceof Player)) {
|
||||||
org.bukkit.Location location = entity.getLocation();
|
org.bukkit.Location location = entity.getLocation();
|
||||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz && location.getZ() <= tz) {
|
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz
|
||||||
|
&& location.getZ() <= tz) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||||
public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
|
||||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override
|
||||||
@Override
|
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
|
||||||
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe) {
|
final boolean safe) {
|
||||||
if (!PS.get().isMainThread(Thread.currentThread())) {
|
if (!PS.get().isMainThread(Thread.currentThread())) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override public void run() {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -392,10 +349,12 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void swap(Location bot1, Location top1, Location bot2, Location top2,
|
||||||
public void swap(Location bot1, Location top1, Location bot2, Location top2, final Runnable whenDone) {
|
final Runnable whenDone) {
|
||||||
RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
RegionWrapper region1 =
|
||||||
RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
||||||
|
RegionWrapper region2 =
|
||||||
|
new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
||||||
final World world1 = Bukkit.getWorld(bot1.getWorld());
|
final World world1 = Bukkit.getWorld(bot1.getWorld());
|
||||||
World world2 = Bukkit.getWorld(bot2.getWorld());
|
World world2 = Bukkit.getWorld(bot2.getWorld());
|
||||||
|
|
||||||
@ -412,8 +371,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (ContentMap map : maps) {
|
for (ContentMap map : maps) {
|
||||||
map.restoreBlocks(world1, 0, 0);
|
map.restoreBlocks(world1, 0, 0);
|
||||||
map.restoreEntities(world1, 0, 0);
|
map.restoreEntities(world1, 0, 0);
|
||||||
@ -423,10 +381,10 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int[] countEntities(Plot plot) {
|
||||||
public int[] countEntities(Plot plot) {
|
|
||||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
|
||||||
|
< 1000)) {
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
PlotArea area = plot.getArea();
|
PlotArea area = plot.getArea();
|
||||||
@ -705,7 +663,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) {
|
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ,
|
||||||
|
boolean delete) {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
Location loc = BukkitUtil.getLocation(entity);
|
Location loc = BukkitUtil.getLocation(entity);
|
||||||
int x = loc.getX();
|
int x = loc.getX();
|
||||||
@ -743,26 +702,30 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
public void restoreBlocks(World world, int xOffset, int zOffset) {
|
public void restoreBlocks(World world, int xOffset, int zOffset) {
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof InventoryHolder) {
|
if (state instanceof InventoryHolder) {
|
||||||
InventoryHolder chest = (InventoryHolder) state;
|
InventoryHolder chest = (InventoryHolder) state;
|
||||||
chest.getInventory().setContents(blockLocEntry.getValue());
|
chest.getInventory().setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, String[]> blockLocEntry : this.signContents.entrySet()) {
|
for (Entry<BlockLoc, String[]> blockLocEntry : this.signContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Sign) {
|
if (state instanceof Sign) {
|
||||||
Sign sign = (Sign) state;
|
Sign sign = (Sign) state;
|
||||||
@ -773,95 +736,105 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug(
|
PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (
|
||||||
"&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
.getKey().y
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
+ ',' + (
|
|
||||||
blockLocEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException ignored) {
|
} catch (IndexOutOfBoundsException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (
|
||||||
+ ',' + (
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
blockLocEntry.getKey().z + zOffset));
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dispenserContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dispenserContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Dispenser) {
|
if (state instanceof Dispenser) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dropperContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dropperContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Dropper) {
|
if (state instanceof Dropper) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.beaconContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.beaconContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Beacon) {
|
if (state instanceof Beacon) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Material> blockLocMaterialEntry : this.jukeboxDisc.entrySet()) {
|
for (Entry<BlockLoc, Material> blockLocMaterialEntry : this.jukeboxDisc.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset,
|
||||||
world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().y,
|
||||||
.getKey().z + zOffset);
|
blockLocMaterialEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Jukebox) {
|
if (state instanceof Jukebox) {
|
||||||
((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue());
|
((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (
|
||||||
+ blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().x + xOffset) + ','
|
||||||
.getKey().y + ',' + (
|
+ blockLocMaterialEntry.getKey().y + ',' + (
|
||||||
blockLocMaterialEntry.getKey().z + zOffset));
|
blockLocMaterialEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (
|
||||||
+ blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().x + xOffset) + ',' + blockLocMaterialEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocMaterialEntry.getKey().z + zOffset));
|
||||||
blockLocMaterialEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Object[]> blockLocEntry : this.skullData.entrySet()) {
|
for (Entry<BlockLoc, Object[]> blockLocEntry : this.skullData.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Skull) {
|
if (state instanceof Skull) {
|
||||||
Object[] data = blockLocEntry.getValue();
|
Object[] data = blockLocEntry.getValue();
|
||||||
@ -872,193 +845,210 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
((Skull) state).setSkullType((SkullType) data[3]);
|
((Skull) state).setSkullType((SkullType) data[3]);
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to restore skull: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.hopperContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.hopperContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Hopper) {
|
if (state instanceof Hopper) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Note> blockLocNoteEntry : this.noteBlockContents.entrySet()) {
|
for (Entry<BlockLoc, Note> blockLocNoteEntry : this.noteBlockContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocNoteEntry.getKey().x + xOffset,
|
||||||
blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset);
|
blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof NoteBlock) {
|
if (state instanceof NoteBlock) {
|
||||||
((NoteBlock) state).setNote(blockLocNoteEntry.getValue());
|
((NoteBlock) state).setNote(blockLocNoteEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (
|
||||||
+ blockLocNoteEntry
|
blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocNoteEntry.getKey().z + zOffset));
|
||||||
blockLocNoteEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (
|
||||||
+ blockLocNoteEntry
|
blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry.getKey().y
|
||||||
.getKey().y + ',' + (
|
+ ',' + (blockLocNoteEntry.getKey().z + zOffset));
|
||||||
blockLocNoteEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Short> blockLocShortEntry : this.brewTime.entrySet()) {
|
for (Entry<BlockLoc, Short> blockLocShortEntry : this.brewTime.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocShortEntry.getKey().x + xOffset,
|
||||||
blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset);
|
blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof BrewingStand) {
|
if (state instanceof BrewingStand) {
|
||||||
((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue());
|
((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue());
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (
|
||||||
+ blockLocShortEntry
|
blockLocShortEntry.getKey().x + xOffset) + ',' + blockLocShortEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
||||||
blockLocShortEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (
|
||||||
+ blockLocShortEntry.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
blockLocShortEntry.getKey().x + xOffset) + ',' + blockLocShortEntry
|
||||||
|
.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, EntityType> blockLocEntityTypeEntry : this.spawnerData.entrySet()) {
|
for (Entry<BlockLoc, EntityType> blockLocEntityTypeEntry : this.spawnerData
|
||||||
|
.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset,
|
||||||
world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry
|
blockLocEntityTypeEntry.getKey().y,
|
||||||
.getKey().z + zOffset);
|
blockLocEntityTypeEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof CreatureSpawner) {
|
if (state instanceof CreatureSpawner) {
|
||||||
((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue());
|
((CreatureSpawner) state)
|
||||||
|
.setSpawnedType(blockLocEntityTypeEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (
|
||||||
+ blockLocEntityTypeEntry
|
blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
||||||
.getKey().y + ',' + (
|
+ blockLocEntityTypeEntry.getKey().y + ',' + (
|
||||||
blockLocEntityTypeEntry.getKey().z + zOffset));
|
blockLocEntityTypeEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (
|
||||||
+ blockLocEntityTypeEntry.getKey().y + ',' + (blockLocEntityTypeEntry.getKey().z + zOffset));
|
blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
||||||
|
+ blockLocEntityTypeEntry.getKey().y + ',' + (
|
||||||
|
blockLocEntityTypeEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, String> blockLocStringEntry : this.cmdData.entrySet()) {
|
for (Entry<BlockLoc, String> blockLocStringEntry : this.cmdData.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocStringEntry.getKey().x + xOffset,
|
||||||
blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset);
|
blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof CommandBlock) {
|
if (state instanceof CommandBlock) {
|
||||||
((CommandBlock) state).setCommand(blockLocStringEntry.getValue());
|
((CommandBlock) state).setCommand(blockLocStringEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore command block: " + (
|
||||||
+ blockLocStringEntry
|
blockLocStringEntry.getKey().x + xOffset) + ',' + blockLocStringEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocStringEntry.getKey().z + zOffset));
|
||||||
blockLocStringEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (
|
||||||
+ blockLocStringEntry
|
blockLocStringEntry.getKey().x + xOffset) + ',' + blockLocStringEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocStringEntry.getKey().z + zOffset));
|
||||||
blockLocStringEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.brewingStandContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.brewingStandContents
|
||||||
|
.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof BrewingStand) {
|
if (state instanceof BrewingStand) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (
|
||||||
+ blockLocEntry
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
.getKey().y + ',' + (
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
blockLocEntry.getKey().z
|
|
||||||
+ zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (
|
||||||
+ blockLocEntry.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Short[]> blockLocEntry : this.furnaceTime.entrySet()) {
|
for (Entry<BlockLoc, Short[]> blockLocEntry : this.furnaceTime.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Furnace) {
|
if (state instanceof Furnace) {
|
||||||
Short[] time = blockLocEntry.getValue();
|
Short[] time = blockLocEntry.getValue();
|
||||||
((Furnace) state).setBurnTime(time[0]);
|
((Furnace) state).setBurnTime(time[0]);
|
||||||
((Furnace) state).setCookTime(time[1]);
|
((Furnace) state).setCookTime(time[1]);
|
||||||
} else {
|
} else {
|
||||||
PS.debug(
|
PS.debug("&c[WARN] Plot clear failed to restore furnace cooking: " + (
|
||||||
"&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug(
|
PS.debug("&c[WARN] Plot clear failed to restore furnace cooking (e): " + (
|
||||||
"&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.furnaceContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.furnaceContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Furnace) {
|
if (state instanceof Furnace) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, DyeColor> blockLocByteEntry : this.bannerBase.entrySet()) {
|
for (Entry<BlockLoc, DyeColor> blockLocByteEntry : this.bannerBase.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocByteEntry.getKey().x + xOffset,
|
||||||
blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset);
|
blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Banner) {
|
if (state instanceof Banner) {
|
||||||
Banner banner = (Banner) state;
|
Banner banner = (Banner) state;
|
||||||
DyeColor base = blockLocByteEntry.getValue();
|
DyeColor base = blockLocByteEntry.getValue();
|
||||||
List<Pattern> patterns = this.bannerPatterns.get(blockLocByteEntry.getKey());
|
List<Pattern> patterns =
|
||||||
|
this.bannerPatterns.get(blockLocByteEntry.getKey());
|
||||||
banner.setBaseColor(base);
|
banner.setBaseColor(base);
|
||||||
banner.setPatterns(patterns);
|
banner.setPatterns(patterns);
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (
|
||||||
+ blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
blockLocByteEntry.getKey().x + xOffset) + ',' + blockLocByteEntry
|
||||||
|
.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + ','
|
PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (
|
||||||
+ blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
blockLocByteEntry.getKey().x + xOffset) + ',' + blockLocByteEntry.getKey().y
|
||||||
|
+ ',' + (blockLocByteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) {
|
public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ,
|
||||||
|
boolean storeNormal) {
|
||||||
maxY = Math.min(255, maxY);
|
maxY = Math.min(255, maxY);
|
||||||
PlotBlock[] ids;
|
PlotBlock[] ids;
|
||||||
if (storeNormal) {
|
if (storeNormal) {
|
||||||
@ -1082,7 +1072,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ);
|
BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ);
|
||||||
if (block.getState() instanceof InventoryHolder) {
|
if (block.getState() instanceof InventoryHolder) {
|
||||||
InventoryHolder inventoryHolder = (InventoryHolder) block.getState();
|
InventoryHolder inventoryHolder = (InventoryHolder) block.getState();
|
||||||
ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone();
|
ItemStack[] inventory =
|
||||||
|
inventoryHolder.getInventory().getContents().clone();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case CHEST:
|
case CHEST:
|
||||||
this.chestContents.put(bl, inventory);
|
this.chestContents.put(bl, inventory);
|
||||||
@ -1105,7 +1096,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
this.brewTime.put(bl, time);
|
this.brewTime.put(bl, time);
|
||||||
}
|
}
|
||||||
ItemStack[] invBre = brewingStand.getInventory().getContents().clone();
|
ItemStack[] invBre =
|
||||||
|
brewingStand.getInventory().getContents().clone();
|
||||||
this.brewingStandContents.put(bl, invBre);
|
this.brewingStandContents.put(bl, invBre);
|
||||||
break;
|
break;
|
||||||
case FURNACE:
|
case FURNACE:
|
||||||
@ -1113,7 +1105,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
Furnace furnace = (Furnace) inventoryHolder;
|
Furnace furnace = (Furnace) inventoryHolder;
|
||||||
short burn = furnace.getBurnTime();
|
short burn = furnace.getBurnTime();
|
||||||
short cook = furnace.getCookTime();
|
short cook = furnace.getCookTime();
|
||||||
ItemStack[] invFur = furnace.getInventory().getContents().clone();
|
ItemStack[] invFur =
|
||||||
|
furnace.getInventory().getContents().clone();
|
||||||
this.furnaceContents.put(bl, invFur);
|
this.furnaceContents.put(bl, invFur);
|
||||||
if (cook != 0) {
|
if (cook != 0) {
|
||||||
this.furnaceTime.put(bl, new Short[] {burn, cook});
|
this.furnaceTime.put(bl, new Short[] {burn, cook});
|
||||||
@ -1144,7 +1137,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
} else if (block.getState() instanceof Skull) {
|
} else if (block.getState() instanceof Skull) {
|
||||||
Skull skull = (Skull) block.getState();
|
Skull skull = (Skull) block.getState();
|
||||||
this.skullData.put(bl, new Object[]{skull.hasOwner(), skull.getOwner(), skull.getRotation(), skull.getSkullType()});
|
this.skullData.put(bl, new Object[] {skull.hasOwner(), skull.getOwner(),
|
||||||
|
skull.getRotation(), skull.getSkullType()});
|
||||||
} else if (block.getState() instanceof Banner) {
|
} else if (block.getState() instanceof Banner) {
|
||||||
Banner banner = (Banner) block.getState();
|
Banner banner = (Banner) block.getState();
|
||||||
DyeColor base = banner.getBaseColor();
|
DyeColor base = banner.getBaseColor();
|
||||||
|
@ -4,13 +4,7 @@ import com.intellectualcrafters.plot.commands.MainCommand;
|
|||||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.commands.DebugUUID;
|
import com.plotsquared.bukkit.commands.DebugUUID;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.command.ProxiedCommandSender;
|
|
||||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -25,11 +19,13 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
|
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
||||||
|
String[] args) {
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
||||||
}
|
}
|
||||||
if (commandSender instanceof ConsoleCommandSender || commandSender instanceof ProxiedCommandSender
|
if (commandSender instanceof ConsoleCommandSender
|
||||||
|
|| commandSender instanceof ProxiedCommandSender
|
||||||
|| commandSender instanceof RemoteConsoleCommandSender) {
|
|| commandSender instanceof RemoteConsoleCommandSender) {
|
||||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
||||||
}
|
}
|
||||||
@ -37,7 +33,8 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s,
|
||||||
|
String[] args) {
|
||||||
if (!(commandSender instanceof Player)) {
|
if (!(commandSender instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupPermissions() {
|
private boolean setupPermissions() {
|
||||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
|
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
this.perms = permissionProvider.getProvider();
|
this.perms = permissionProvider.getProvider();
|
||||||
}
|
}
|
||||||
@ -35,15 +36,15 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> economyProvider =
|
||||||
|
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
this.econ = economyProvider.getProvider();
|
this.econ = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
return this.econ != null;
|
return this.econ != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public double getMoney(PlotPlayer player) {
|
||||||
public double getMoney(PlotPlayer player) {
|
|
||||||
double bal = super.getMoney(player);
|
double bal = super.getMoney(player);
|
||||||
if (Double.isNaN(bal)) {
|
if (Double.isNaN(bal)) {
|
||||||
return this.econ.getBalance(((BukkitPlayer) player).player);
|
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||||
@ -51,28 +52,23 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
return bal;
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void withdrawMoney(PlotPlayer player, double amount) {
|
||||||
public void withdrawMoney(PlotPlayer player, double amount) {
|
|
||||||
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void depositMoney(PlotPlayer player, double amount) {
|
||||||
public void depositMoney(PlotPlayer player, double amount) {
|
|
||||||
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
|
||||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean hasPermission(String world, String player, String perm) {
|
||||||
public boolean hasPermission(String world, String player, String perm) {
|
|
||||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public double getBalance(PlotPlayer player) {
|
||||||
public double getBalance(PlotPlayer player) {
|
|
||||||
return this.econ.getBalance(player.getName());
|
return this.econ.getBalance(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +1,9 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.Rating;
|
|
||||||
import com.intellectualcrafters.plot.util.EventUtil;
|
import com.intellectualcrafters.plot.util.EventUtil;
|
||||||
import com.plotsquared.bukkit.events.ClusterFlagRemoveEvent;
|
import com.plotsquared.bukkit.events.*;
|
||||||
import com.plotsquared.bukkit.events.PlayerClaimPlotEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerPlotDeniedEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerPlotHelperEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerPlotTrustedEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerTeleportToPlotEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotClearEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotComponentSetEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotDeleteEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotFlagAddEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotFlagRemoveEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotMergeEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotRateEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlotUnlinkEvent;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -48,83 +27,67 @@ public class BukkitEventUtil extends EventUtil {
|
|||||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
||||||
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
|
||||||
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
||||||
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
|
||||||
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callComponentSet(Plot plot, String component) {
|
||||||
public boolean callComponentSet(Plot plot, String component) {
|
|
||||||
return callEvent(new PlotComponentSetEvent(plot, component));
|
return callEvent(new PlotComponentSetEvent(plot, component));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callClear(Plot plot) {
|
||||||
public boolean callClear(Plot plot) {
|
|
||||||
return callEvent(new PlotClearEvent(plot));
|
return callEvent(new PlotClearEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callDelete(Plot plot) {
|
||||||
public void callDelete(Plot plot) {
|
|
||||||
callEvent(new PlotDeleteEvent(plot));
|
callEvent(new PlotDeleteEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||||
public boolean callFlagAdd(Flag flag, Plot plot) {
|
|
||||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
||||||
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
|
||||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
|
||||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
|
||||||
public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
|
|
||||||
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callEntry(PlotPlayer player, Plot plot) {
|
||||||
public void callEntry(PlotPlayer player, Plot plot) {
|
|
||||||
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callLeave(PlotPlayer player, Plot plot) {
|
||||||
public void callLeave(PlotPlayer player, Plot plot) {
|
|
||||||
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||||
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
|
||||||
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||||
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
|
||||||
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||||
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
|
||||||
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
||||||
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
|
||||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||||
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
|
||||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return event.getRating();
|
return event.getRating();
|
||||||
|
@ -26,8 +26,8 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class BukkitHybridUtils extends HybridUtils {
|
public class BukkitHybridUtils extends HybridUtils {
|
||||||
|
|
||||||
@Override
|
@Override public void analyzeRegion(final String world, final RegionWrapper region,
|
||||||
public void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone) {
|
final RunnableVal<PlotAnalysis> whenDone) {
|
||||||
// int diff, int variety, int vertices, int rotation, int height_sd
|
// int diff, int variety, int vertices, int rotation, int height_sd
|
||||||
/*
|
/*
|
||||||
* diff: compare to base by looping through all blocks
|
* diff: compare to base by looping through all blocks
|
||||||
@ -41,8 +41,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
final ChunkGenerator gen = worldObj.getGenerator();
|
final ChunkGenerator gen = worldObj.getGenerator();
|
||||||
@ -50,12 +49,10 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
||||||
@Override
|
@Override public void setBiome(int a, int b, Biome c) {
|
||||||
public void setBiome(int a, int b, Biome c) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Biome getBiome(int a, int b) {
|
||||||
public Biome getBiome(int a, int b) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -82,15 +79,14 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
final short[][][] newBlocks = new short[256][width][length];
|
final short[][][] newBlocks = new short[256][width][length];
|
||||||
|
|
||||||
final Runnable run = new Runnable() {
|
final Runnable run = new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
||||||
@Override
|
@Override public void run(int[] value) {
|
||||||
public void run(int[] value) {
|
|
||||||
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
||||||
int X = value[0];
|
int X = value[0];
|
||||||
int Z = value[1];
|
int Z = value[1];
|
||||||
short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
short[][] result =
|
||||||
|
gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
||||||
int xb = (X << 4) - bx;
|
int xb = (X << 4) - bx;
|
||||||
int zb = (Z << 4) - bz;
|
int zb = (Z << 4) - bz;
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
@ -125,11 +121,9 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
int size = width * length;
|
int size = width * length;
|
||||||
int[] changes = new int[size];
|
int[] changes = new int[size];
|
||||||
int[] faces = new int[size];
|
int[] faces = new int[size];
|
||||||
@ -151,7 +145,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
} else {
|
} else {
|
||||||
// check vertices
|
// check vertices
|
||||||
// modifications_adjacent
|
// modifications_adjacent
|
||||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
if (x > 0 && z > 0 && y > 0 && x < width - 1
|
||||||
|
&& z < length - 1 && y < 255) {
|
||||||
if (newBlocks[y - 1][x][z] == 0) {
|
if (newBlocks[y - 1][x][z] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
@ -172,12 +167,15 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Material material = Material.getMaterial(now);
|
Material material =
|
||||||
|
Material.getMaterial(now);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
Class<? extends MaterialData> md = material.getData();
|
Class<? extends MaterialData> md =
|
||||||
|
material.getData();
|
||||||
if (md.equals(Directional.class)) {
|
if (md.equals(Directional.class)) {
|
||||||
data[i] += 8;
|
data[i] += 8;
|
||||||
} else if (!md.equals(MaterialData.class)) {
|
} else if (!md
|
||||||
|
.equals(MaterialData.class)) {
|
||||||
data[i]++;
|
data[i]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,11 +197,14 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
analysis.air = (int) (MathMan.getMean(air) * 100);
|
analysis.air = (int) (MathMan.getMean(air) * 100);
|
||||||
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
||||||
|
|
||||||
analysis.changes_sd = (int) MathMan.getSD(changes, analysis.changes);
|
analysis.changes_sd =
|
||||||
analysis.faces_sd = (int) MathMan.getSD(faces, analysis.faces);
|
(int) MathMan.getSD(changes, analysis.changes);
|
||||||
|
analysis.faces_sd =
|
||||||
|
(int) MathMan.getSD(faces, analysis.faces);
|
||||||
analysis.data_sd = (int) MathMan.getSD(data, analysis.data);
|
analysis.data_sd = (int) MathMan.getSD(data, analysis.data);
|
||||||
analysis.air_sd = (int) MathMan.getSD(air, analysis.air);
|
analysis.air_sd = (int) MathMan.getSD(air, analysis.air);
|
||||||
analysis.variety_sd = (int) MathMan.getSD(variety, analysis.variety);
|
analysis.variety_sd =
|
||||||
|
(int) MathMan.getSD(variety, analysis.variety);
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
whenDone.value = analysis;
|
whenDone.value = analysis;
|
||||||
@ -219,8 +220,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
||||||
|
|
||||||
@Override
|
@Override public void run(int[] value) {
|
||||||
public void run(int[] value) {
|
|
||||||
int X = value[0];
|
int X = value[0];
|
||||||
int Z = value[1];
|
int Z = value[1];
|
||||||
worldObj.loadChunk(X, Z);
|
worldObj.loadChunk(X, Z);
|
||||||
@ -269,8 +269,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
worldObj.unloadChunkRequest(X, Z, true);
|
worldObj.unloadChunkRequest(X, Z, true);
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
TaskManager.runTaskAsync(run);
|
TaskManager.runTaskAsync(run);
|
||||||
}
|
}
|
||||||
}, 5);
|
}, 5);
|
||||||
|
@ -45,8 +45,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void open(PlotInventory inv) {
|
||||||
public void open(PlotInventory inv) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||||
PlotItemStack[] items = inv.getItems();
|
PlotItemStack[] items = inv.getItems();
|
||||||
@ -60,8 +59,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
bp.player.openInventory(inventory);
|
bp.player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void close(PlotInventory inv) {
|
||||||
public void close(PlotInventory inv) {
|
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -70,8 +68,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
bp.player.closeInventory();
|
bp.player.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
@ -103,8 +100,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
return new PlotItemStack(id, data, amount, name, lore);
|
return new PlotItemStack(id, data, amount, name, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
||||||
public PlotItemStack[] getItems(PlotPlayer player) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) player;
|
BukkitPlayer bp = (BukkitPlayer) player;
|
||||||
PlayerInventory inv = bp.player.getInventory();
|
PlayerInventory inv = bp.player.getInventory();
|
||||||
PlotItemStack[] items = new PlotItemStack[36];
|
PlotItemStack[] items = new PlotItemStack[36];
|
||||||
@ -114,13 +110,13 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOpen(PlotInventory inv) {
|
||||||
public boolean isOpen(PlotInventory inv) {
|
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING && opened.getTitle() == null;
|
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING
|
||||||
|
&& opened.getTitle() == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
import com.intellectualcrafters.jnbt.*;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
|
||||||
import com.intellectualcrafters.jnbt.IntTag;
|
|
||||||
import com.intellectualcrafters.jnbt.ListTag;
|
|
||||||
import com.intellectualcrafters.jnbt.ShortTag;
|
|
||||||
import com.intellectualcrafters.jnbt.StringTag;
|
|
||||||
import com.intellectualcrafters.jnbt.Tag;
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||||
@ -22,24 +16,18 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler.
|
* Schematic Handler.
|
||||||
*/
|
*/
|
||||||
public class BukkitSchematicHandler extends SchematicHandler {
|
public class BukkitSchematicHandler extends SchematicHandler {
|
||||||
|
|
||||||
@Override
|
@Override public void getCompoundTag(final String world, final Set<RegionWrapper> regions,
|
||||||
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
|
final RunnableVal<CompoundTag> whenDone) {
|
||||||
// async
|
// async
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
// Main positions
|
// Main positions
|
||||||
Location[] corners = MainUtil.getCorners(world, regions);
|
Location[] corners = MainUtil.getCorners(world, regions);
|
||||||
final Location bot = corners[0];
|
final Location bot = corners[0];
|
||||||
@ -67,16 +55,18 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
// Queue
|
// Queue
|
||||||
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (queue.isEmpty()) {
|
if (queue.isEmpty()) {
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
schematic.put("Entities",
|
||||||
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
|
new ListTag("Entities", CompoundTag.class,
|
||||||
|
new ArrayList<Tag>()));
|
||||||
|
schematic.put("TileEntities",
|
||||||
|
new ListTag("TileEntities", CompoundTag.class,
|
||||||
|
tileEntities));
|
||||||
whenDone.value = new CompoundTag("Schematic", schematic);
|
whenDone.value = new CompoundTag("Schematic", schematic);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
System.gc();
|
System.gc();
|
||||||
@ -111,10 +101,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
// Main thread
|
// Main thread
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 20) {
|
while (!chunks.isEmpty()
|
||||||
|
&& System.currentTimeMillis() - start < 20) {
|
||||||
// save schematics
|
// save schematics
|
||||||
ChunkLoc chunk = chunks.remove(0);
|
ChunkLoc chunk = chunks.remove(0);
|
||||||
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||||
@ -259,15 +249,20 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
// TODO implement fully
|
// TODO implement fully
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
StateWrapper wrapper = new StateWrapper(state);
|
StateWrapper wrapper =
|
||||||
|
new StateWrapper(state);
|
||||||
CompoundTag rawTag = wrapper.getTag();
|
CompoundTag rawTag = wrapper.getTag();
|
||||||
if (rawTag != null) {
|
if (rawTag != null) {
|
||||||
Map<String, Tag> values = new HashMap<>(rawTag.getValue());
|
Map<String, Tag> values =
|
||||||
values.put("id", new StringTag("id", wrapper.getId()));
|
new HashMap<>(
|
||||||
|
rawTag.getValue());
|
||||||
|
values.put("id", new StringTag("id",
|
||||||
|
wrapper.getId()));
|
||||||
values.put("x", new IntTag("x", x));
|
values.put("x", new IntTag("x", x));
|
||||||
values.put("y", new IntTag("y", y));
|
values.put("y", new IntTag("y", y));
|
||||||
values.put("z", new IntTag("z", z));
|
values.put("z", new IntTag("z", z));
|
||||||
CompoundTag tileEntityTag = new CompoundTag(values);
|
CompoundTag tileEntityTag =
|
||||||
|
new CompoundTag(values);
|
||||||
tileEntities.add(tileEntityTag);
|
tileEntities.add(tileEntityTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,25 +9,21 @@ import com.intellectualcrafters.plot.object.PlotArea;
|
|||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
import com.intellectualcrafters.plot.object.SetupObject;
|
||||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.World.Environment;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.WorldType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class BukkitSetupUtils extends SetupUtils {
|
public class BukkitSetupUtils extends SetupUtils {
|
||||||
|
|
||||||
@Override
|
@Override public void updateGenerators() {
|
||||||
public void updateGenerators() {
|
|
||||||
if (!SetupUtils.generators.isEmpty()) {
|
if (!SetupUtils.generators.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,8 +50,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void unload(String worldName, boolean save) {
|
||||||
public void unload(String worldName, boolean save) {
|
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return;
|
return;
|
||||||
@ -76,8 +71,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
Bukkit.unloadWorld(world, false);
|
Bukkit.unloadWorld(world, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String setupWorld(SetupObject object) {
|
||||||
public String setupWorld(SetupObject object) {
|
|
||||||
SetupUtils.manager.updateGenerators();
|
SetupUtils.manager.updateGenerators();
|
||||||
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
||||||
String world = object.world;
|
String world = object.world;
|
||||||
@ -89,13 +83,15 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PS.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PS.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PS.get().worlds.getConfigurationSection(worldPath);
|
||||||
String areaName = object.id + "-" + object.min + "-" + object.max;
|
String areaName = object.id + "-" + object.min + "-" + object.max;
|
||||||
String areaPath = "areas." + areaName;
|
String areaPath = "areas." + areaName;
|
||||||
if (!worldSection.contains(areaPath)) {
|
if (!worldSection.contains(areaPath)) {
|
||||||
worldSection.createSection(areaPath);
|
worldSection.createSection(areaPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
ConfigurationSection areaSection =
|
||||||
|
worldSection.getConfigurationSection(areaPath);
|
||||||
HashMap<String, Object> options = new HashMap<>();
|
HashMap<String, Object> options = new HashMap<>();
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
options.put(step.getConstant(), step.getValue());
|
options.put(step.getConstant(), step.getValue());
|
||||||
@ -103,7 +99,8 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
options.put("generator.type", object.type);
|
options.put("generator.type", object.type);
|
||||||
options.put("generator.terrain", object.terrain);
|
options.put("generator.terrain", object.terrain);
|
||||||
options.put("generator.plugin", object.plotManager);
|
options.put("generator.plugin", object.plotManager);
|
||||||
if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) {
|
if (object.setupGenerator != null && !object.setupGenerator
|
||||||
|
.equals(object.plotManager)) {
|
||||||
options.put("generator.init", object.setupGenerator);
|
options.put("generator.init", object.setupGenerator);
|
||||||
}
|
}
|
||||||
for (Entry<String, Object> entry : options.entrySet()) {
|
for (Entry<String, Object> entry : options.entrySet()) {
|
||||||
@ -129,15 +126,18 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PS.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PS.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PS.get().worlds.getConfigurationSection(worldPath);
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.type", object.type);
|
PS.get().worlds.set("worlds." + world + ".generator.type", object.type);
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.terrain", object.terrain);
|
PS.get().worlds.set("worlds." + world + ".generator.terrain", object.terrain);
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager);
|
PS.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager);
|
||||||
if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) {
|
if (object.setupGenerator != null && !object.setupGenerator
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.init", object.setupGenerator);
|
.equals(object.plotManager)) {
|
||||||
|
PS.get().worlds
|
||||||
|
.set("worlds." + world + ".generator.init", object.setupGenerator);
|
||||||
}
|
}
|
||||||
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
|
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
|
||||||
if (gen != null && gen.isFull()) {
|
if (gen != null && gen.isFull()) {
|
||||||
@ -150,7 +150,8 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PS.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PS.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PS.get().worlds.getConfigurationSection(worldPath);
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
@ -164,17 +165,19 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (object.setupGenerator != null) {
|
if (object.setupGenerator != null) {
|
||||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||||
.isEnabled()) {
|
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
Bukkit.getServer()
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
.dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator);
|
"mv create " + world + " normal -g " + object.setupGenerator);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator);
|
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw create " + world + " plugin:" + object.setupGenerator);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
@ -187,20 +190,24 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
Bukkit.createWorld(wc);
|
Bukkit.createWorld(wc);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
} else {
|
} else {
|
||||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||||
.isEnabled()) {
|
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv create " + world + " normal");
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
World bw = Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
|
World bw =
|
||||||
|
Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
|
||||||
}
|
}
|
||||||
return object.world;
|
return object.world;
|
||||||
}
|
}
|
||||||
@ -219,8 +226,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getGenerator(PlotArea plotArea) {
|
||||||
public String getGenerator(PlotArea plotArea) {
|
|
||||||
if (SetupUtils.generators.isEmpty()) {
|
if (SetupUtils.generators.isEmpty()) {
|
||||||
updateGenerators();
|
updateGenerators();
|
||||||
}
|
}
|
||||||
|
@ -12,39 +12,37 @@ public class BukkitTaskManager extends TaskManager {
|
|||||||
this.bukkitMain = bukkitMain;
|
this.bukkitMain = bukkitMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int taskRepeat(Runnable runnable, int interval) {
|
||||||
public int taskRepeat(Runnable runnable, int interval) {
|
return this.bukkitMain.getServer().getScheduler()
|
||||||
return this.bukkitMain.getServer().getScheduler().scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
.scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override
|
||||||
@Override
|
|
||||||
public int taskRepeatAsync(Runnable runnable, int interval) {
|
public int taskRepeatAsync(Runnable runnable, int interval) {
|
||||||
return this.bukkitMain.getServer().getScheduler().scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
return this.bukkitMain.getServer().getScheduler()
|
||||||
|
.scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void taskAsync(Runnable runnable) {
|
||||||
public void taskAsync(Runnable runnable) {
|
this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable)
|
||||||
this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable).getTaskId();
|
.getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void task(Runnable runnable) {
|
||||||
public void task(Runnable runnable) {
|
|
||||||
this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
|
this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void taskLater(Runnable runnable, int delay) {
|
||||||
public void taskLater(Runnable runnable, int delay) {
|
this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay)
|
||||||
this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay).getTaskId();
|
.getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void taskLaterAsync(Runnable runnable, int delay) {
|
||||||
public void taskLaterAsync(Runnable runnable, int delay) {
|
this.bukkitMain.getServer().getScheduler()
|
||||||
this.bukkitMain.getServer().getScheduler().runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
|
.runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void cancelTask(int task) {
|
||||||
public void cancelTask(int task) {
|
|
||||||
if (task != -1) {
|
if (task != -1) {
|
||||||
Bukkit.getScheduler().cancelTask(task);
|
Bukkit.getScheduler().cancelTask(task);
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,6 @@ import com.intellectualcrafters.plot.util.StringComparison;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -26,12 +23,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.*;
|
||||||
import org.bukkit.material.Sandstone;
|
|
||||||
import org.bukkit.material.Step;
|
import java.util.ArrayList;
|
||||||
import org.bukkit.material.Tree;
|
import java.util.Arrays;
|
||||||
import org.bukkit.material.WoodenStep;
|
import java.util.List;
|
||||||
import org.bukkit.material.Wool;
|
|
||||||
|
|
||||||
public class BukkitUtil extends WorldUtil {
|
public class BukkitUtil extends WorldUtil {
|
||||||
|
|
||||||
@ -71,12 +67,13 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocation(org.bukkit.Location location) {
|
public static Location getLocation(org.bukkit.Location location) {
|
||||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||||
MathMan.roundInt(location.getZ()));
|
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.bukkit.Location getLocation(Location location) {
|
public static org.bukkit.Location getLocation(Location location) {
|
||||||
return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ());
|
return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(),
|
||||||
|
location.getY(), location.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static World getWorld(String string) {
|
public static World getWorld(String string) {
|
||||||
@ -95,37 +92,40 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
public static Location getLocation(Entity entity) {
|
public static Location getLocation(Entity entity) {
|
||||||
org.bukkit.Location location = entity.getLocation();
|
org.bukkit.Location location = entity.getLocation();
|
||||||
String world = location.getWorld().getName();
|
String world = location.getWorld().getName();
|
||||||
return new Location(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
return new Location(world, location.getBlockX(), location.getBlockY(),
|
||||||
|
location.getBlockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocationFull(Entity entity) {
|
public static Location getLocationFull(Entity entity) {
|
||||||
org.bukkit.Location location = entity.getLocation();
|
org.bukkit.Location location = entity.getLocation();
|
||||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()),
|
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||||
location.getYaw(), location.getPitch());
|
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||||
|
location.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isWorld(String worldName) {
|
||||||
public boolean isWorld(String worldName) {
|
|
||||||
return getWorld(worldName) != null;
|
return getWorld(worldName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getBiome(String world, int x, int z) {
|
||||||
public String getBiome(String world, int x, int z) {
|
|
||||||
return getWorld(world).getBiome(x, z).name();
|
return getWorld(world).getBiome(x, z).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setSign(String worldName, int x, int y, int z, String[] lines) {
|
||||||
public void setSign(String worldName, int x, int y, int z, String[] lines) {
|
|
||||||
World world = getWorld(worldName);
|
World world = getWorld(worldName);
|
||||||
Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
// block.setType(Material.AIR);
|
// block.setType(Material.AIR);
|
||||||
Material type = block.getType();
|
Material type = block.getType();
|
||||||
if (type != Material.SIGN && type != Material.SIGN_POST) {
|
if (type != Material.SIGN && type != Material.SIGN_POST) {
|
||||||
int data = 2;
|
int data = 2;
|
||||||
if (world.getBlockAt(x, y, z + 1).getType().isSolid()) data = 2;
|
if (world.getBlockAt(x, y, z + 1).getType().isSolid())
|
||||||
else if (world.getBlockAt(x + 1, y, z).getType().isSolid()) data = 4;
|
data = 2;
|
||||||
else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) data = 3;
|
else if (world.getBlockAt(x + 1, y, z).getType().isSolid())
|
||||||
else if (world.getBlockAt(x - 1, y, z).getType().isSolid()) data = 5;
|
data = 4;
|
||||||
|
else if (world.getBlockAt(x, y, z - 1).getType().isSolid())
|
||||||
|
data = 3;
|
||||||
|
else if (world.getBlockAt(x - 1, y, z).getType().isSolid())
|
||||||
|
data = 5;
|
||||||
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) data, false);
|
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) data, false);
|
||||||
}
|
}
|
||||||
BlockState blockstate = block.getState();
|
BlockState blockstate = block.getState();
|
||||||
@ -138,9 +138,9 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String[] getSign(Location location) {
|
||||||
public String[] getSign(Location location) {
|
Block block = getWorld(location.getWorld())
|
||||||
Block block = getWorld(location.getWorld()).getBlockAt(location.getX(), location.getY(), location.getZ());
|
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
if (block.getState() instanceof Sign) {
|
if (block.getState() instanceof Sign) {
|
||||||
Sign sign = (Sign) block.getState();
|
Sign sign = (Sign) block.getState();
|
||||||
@ -150,35 +150,31 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getSpawn(PlotPlayer player) {
|
||||||
public Location getSpawn(PlotPlayer player) {
|
|
||||||
return getLocation(((BukkitPlayer) player).player.getBedSpawnLocation());
|
return getLocation(((BukkitPlayer) player).player.getBedSpawnLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getSpawn(String world) {
|
||||||
public Location getSpawn(String world) {
|
|
||||||
org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||||
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||||
|
temp.getYaw(), temp.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setSpawn(Location location) {
|
||||||
public void setSpawn(Location location) {
|
|
||||||
World world = getWorld(location.getWorld());
|
World world = getWorld(location.getWorld());
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void saveWorld(String worldName) {
|
||||||
public void saveWorld(String worldName) {
|
|
||||||
World world = getWorld(worldName);
|
World world = getWorld(worldName);
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
world.save();
|
world.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getHighestBlock(String world, int x, int z) {
|
||||||
public int getHighestBlock(String world, int x, int z) {
|
|
||||||
World bukkitWorld = getWorld(world);
|
World bukkitWorld = getWorld(world);
|
||||||
// Skip top and bottom block
|
// Skip top and bottom block
|
||||||
int air = 1;
|
int air = 1;
|
||||||
@ -187,7 +183,8 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
if (block != null) {
|
if (block != null) {
|
||||||
Material type = block.getType();
|
Material type = block.getType();
|
||||||
if (type.isSolid()) {
|
if (type.isSolid()) {
|
||||||
if (air > 1) return y;
|
if (air > 1)
|
||||||
|
return y;
|
||||||
air = 0;
|
air = 0;
|
||||||
} else {
|
} else {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -204,8 +201,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return bukkitWorld.getMaxHeight() - 1;
|
return bukkitWorld.getMaxHeight() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getBiomeFromString(String biomeString) {
|
||||||
public int getBiomeFromString(String biomeString) {
|
|
||||||
try {
|
try {
|
||||||
Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
||||||
return Arrays.asList(Biome.values()).indexOf(biome);
|
return Arrays.asList(Biome.values()).indexOf(biome);
|
||||||
@ -214,8 +210,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String[] getBiomeList() {
|
||||||
public String[] getBiomeList() {
|
|
||||||
Biome[] biomes = Biome.values();
|
Biome[] biomes = Biome.values();
|
||||||
String[] list = new String[biomes.length];
|
String[] list = new String[biomes.length];
|
||||||
for (int i = 0; i < biomes.length; i++) {
|
for (int i = 0; i < biomes.length; i++) {
|
||||||
@ -224,8 +219,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean addItems(String worldName, PlotItem items) {
|
||||||
public boolean addItems(String worldName, PlotItem items) {
|
|
||||||
World world = getWorld(worldName);
|
World world = getWorld(worldName);
|
||||||
Block block = world.getBlockAt(items.x, items.y, items.z);
|
Block block = world.getBlockAt(items.x, items.y, items.z);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
@ -245,18 +239,15 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isBlockSolid(PlotBlock block) {
|
||||||
public boolean isBlockSolid(PlotBlock block) {
|
|
||||||
try {
|
try {
|
||||||
Material material = Material.getMaterial(block.id);
|
Material material = Material.getMaterial(block.id);
|
||||||
if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
|
if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
|
||||||
Class<? extends MaterialData> data = material.getData();
|
Class<? extends MaterialData> data = material.getData();
|
||||||
if (data.equals(MaterialData.class) && !material.isTransparent() && material.isOccluding()
|
if (data.equals(MaterialData.class) && !material.isTransparent() && material
|
||||||
|| data.equals(Tree.class)
|
.isOccluding() || data.equals(Tree.class) || data.equals(Sandstone.class)
|
||||||
|| data.equals(Sandstone.class)
|
|| data.equals(Wool.class) || data.equals(Step.class) || data
|
||||||
|| data.equals(Wool.class)
|
.equals(WoodenStep.class)) {
|
||||||
|| data.equals(Step.class)
|
|
||||||
|| data.equals(WoodenStep.class)) {
|
|
||||||
switch (material) {
|
switch (material) {
|
||||||
case NOTE_BLOCK:
|
case NOTE_BLOCK:
|
||||||
case MOB_SPAWNER:
|
case MOB_SPAWNER:
|
||||||
@ -272,8 +263,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getClosestMatchingName(PlotBlock block) {
|
||||||
public String getClosestMatchingName(PlotBlock block) {
|
|
||||||
try {
|
try {
|
||||||
return Material.getMaterial(block.id).name();
|
return Material.getMaterial(block.id).name();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
@ -281,12 +271,13 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
|
||||||
try {
|
try {
|
||||||
Material material = Material.valueOf(name.toUpperCase());
|
Material material = Material.valueOf(name.toUpperCase());
|
||||||
return new StringComparison<PlotBlock>().new ComparisonResult(0, PlotBlock.get((short) material.getId(), (byte) 0));
|
return new StringComparison<PlotBlock>().new ComparisonResult(0,
|
||||||
} catch (IllegalArgumentException ignored) {}
|
PlotBlock.get((short) material.getId(), (byte) 0));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
byte data;
|
byte data;
|
||||||
String[] split = name.split(":");
|
String[] split = name.split(":");
|
||||||
@ -302,7 +293,8 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
id = Short.parseShort(split[0]);
|
id = Short.parseShort(split[0]);
|
||||||
match = 0;
|
match = 0;
|
||||||
} else {
|
} else {
|
||||||
StringComparison<Material>.ComparisonResult comparison = new StringComparison<>(name, Material.values()).getBestMatchAdvanced();
|
StringComparison<Material>.ComparisonResult comparison =
|
||||||
|
new StringComparison<>(name, Material.values()).getBestMatchAdvanced();
|
||||||
match = comparison.match;
|
match = comparison.match;
|
||||||
id = (short) comparison.best.getId();
|
id = (short) comparison.best.getId();
|
||||||
}
|
}
|
||||||
@ -310,12 +302,12 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
StringComparison<PlotBlock> outer = new StringComparison<>();
|
StringComparison<PlotBlock> outer = new StringComparison<>();
|
||||||
return outer.new ComparisonResult(match, block);
|
return outer.new ComparisonResult(match, block);
|
||||||
|
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setBiomes(String worldName, RegionWrapper region, String biomeString) {
|
||||||
public void setBiomes(String worldName, RegionWrapper region, String biomeString) {
|
|
||||||
World world = getWorld(worldName);
|
World world = getWorld(worldName);
|
||||||
Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
||||||
for (int x = region.minX; x <= region.maxX; x++) {
|
for (int x = region.minX; x <= region.maxX; x++) {
|
||||||
@ -325,8 +317,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getBlock(Location location) {
|
||||||
public PlotBlock getBlock(Location location) {
|
|
||||||
World world = getWorld(location.getWorld());
|
World world = getWorld(location.getWorld());
|
||||||
Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
@ -335,8 +326,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return PlotBlock.get((short) block.getTypeId(), block.getData());
|
return PlotBlock.get((short) block.getTypeId(), block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getMainWorld() {
|
||||||
public String getMainWorld() {
|
|
||||||
return Bukkit.getWorlds().get(0).getName();
|
return Bukkit.getWorlds().get(0).getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@ -22,19 +17,33 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
|
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
|
||||||
/** The current revision number. */
|
/**
|
||||||
|
* The current revision number.
|
||||||
|
*/
|
||||||
private static final int REVISION = 7;
|
private static final int REVISION = 7;
|
||||||
/** The base url of the metrics domain.*/
|
/**
|
||||||
|
* The base url of the metrics domain.
|
||||||
|
*/
|
||||||
private static final String BASE_URL = "http://report.mcstats.org";
|
private static final String BASE_URL = "http://report.mcstats.org";
|
||||||
/** The url used to report a server's status. */
|
/**
|
||||||
|
* The url used to report a server's status.
|
||||||
|
*/
|
||||||
private static final String REPORT_URL = "/plugin/%s";
|
private static final String REPORT_URL = "/plugin/%s";
|
||||||
/** Interval of time to ping (in minutes). */
|
/**
|
||||||
|
* Interval of time to ping (in minutes).
|
||||||
|
*/
|
||||||
private static final int PING_INTERVAL = 15;
|
private static final int PING_INTERVAL = 15;
|
||||||
/** The plugin this metrics submits for. */
|
/**
|
||||||
|
* The plugin this metrics submits for.
|
||||||
|
*/
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
/** Unique server id. */
|
/**
|
||||||
|
* Unique server id.
|
||||||
|
*/
|
||||||
private final String guid;
|
private final String guid;
|
||||||
/** The scheduled task. */
|
/**
|
||||||
|
* The scheduled task.
|
||||||
|
*/
|
||||||
private volatile BukkitTask task = null;
|
private volatile BukkitTask task = null;
|
||||||
|
|
||||||
public Metrics(Plugin plugin) {
|
public Metrics(Plugin plugin) {
|
||||||
@ -46,7 +55,6 @@ public class Metrics {
|
|||||||
* GZip compress a string of bytes.
|
* GZip compress a string of bytes.
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
*
|
|
||||||
* @return byte[] the file as a byte array
|
* @return byte[] the file as a byte array
|
||||||
*/
|
*/
|
||||||
public static byte[] gzip(String input) {
|
public static byte[] gzip(String input) {
|
||||||
@ -61,7 +69,8 @@ public class Metrics {
|
|||||||
if (gzos != null) {
|
if (gzos != null) {
|
||||||
try {
|
try {
|
||||||
gzos.close();
|
gzos.close();
|
||||||
} catch (IOException ignore) {}
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
@ -73,7 +82,6 @@ public class Metrics {
|
|||||||
* @param json
|
* @param json
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private static void appendJSONPair(StringBuilder json, String key, String value) {
|
private static void appendJSONPair(StringBuilder json, String key, String value) {
|
||||||
boolean isValueNumeric = false;
|
boolean isValueNumeric = false;
|
||||||
@ -101,7 +109,6 @@ public class Metrics {
|
|||||||
* Escape a string to create a valid JSON string
|
* Escape a string to create a valid JSON string
|
||||||
*
|
*
|
||||||
* @param text
|
* @param text
|
||||||
*
|
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private static String escapeJSON(String text) {
|
private static String escapeJSON(String text) {
|
||||||
@ -145,7 +152,6 @@ public class Metrics {
|
|||||||
* Encode text as UTF-8
|
* Encode text as UTF-8
|
||||||
*
|
*
|
||||||
* @param text the text to encode
|
* @param text the text to encode
|
||||||
*
|
|
||||||
* @return the encoded text, as UTF-8
|
* @return the encoded text, as UTF-8
|
||||||
*/
|
*/
|
||||||
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
||||||
@ -165,11 +171,11 @@ public class Metrics {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Begin hitting the server with glorious data
|
// Begin hitting the server with glorious data
|
||||||
this.task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
|
this.task = this.plugin.getServer().getScheduler()
|
||||||
|
.runTaskTimerAsynchronously(this.plugin, new Runnable() {
|
||||||
private boolean firstPost = true;
|
private boolean firstPost = true;
|
||||||
|
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
postPlugin(!this.firstPost);
|
postPlugin(!this.firstPost);
|
||||||
// After the first post we set firstPost to
|
// After the first post we set firstPost to
|
||||||
@ -196,10 +202,15 @@ public class Metrics {
|
|||||||
String serverVersion = Bukkit.getVersion();
|
String serverVersion = Bukkit.getVersion();
|
||||||
int playersOnline = 0;
|
int playersOnline = 0;
|
||||||
try {
|
try {
|
||||||
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) {
|
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType()
|
||||||
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).size();
|
== Collection.class) {
|
||||||
|
playersOnline =
|
||||||
|
((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0])
|
||||||
|
.invoke(null)).size();
|
||||||
} else {
|
} else {
|
||||||
playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).length;
|
playersOnline =
|
||||||
|
((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0])
|
||||||
|
.invoke(null)).length;
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -256,7 +267,8 @@ public class Metrics {
|
|||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
String response;
|
String response;
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(connection.getInputStream()))) {
|
||||||
response = reader.readLine();
|
response = reader.readLine();
|
||||||
}
|
}
|
||||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||||
@ -267,6 +279,7 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
throw new IOException(response);
|
throw new IOException(response);
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,36 +8,18 @@ import com.google.common.collect.MapMaker;
|
|||||||
import com.google.common.io.ByteSink;
|
import com.google.common.io.ByteSink;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.primitives.Primitives;
|
import com.google.common.primitives.Primitives;
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.AbstractList;
|
|
||||||
import java.util.AbstractMap;
|
|
||||||
import java.util.AbstractSet;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class NbtFactory {
|
public class NbtFactory {
|
||||||
|
|
||||||
// Convert between NBT type and the equivalent class in java
|
// Convert between NBT type and the equivalent class in java
|
||||||
@ -77,10 +59,12 @@ public class NbtFactory {
|
|||||||
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
||||||
|
|
||||||
// Prepare NBT
|
// Prepare NBT
|
||||||
this.COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
this.COMPOUND_CLASS =
|
||||||
|
getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
||||||
this.BASE_CLASS = loader.loadClass(craftpackageName + ".NBTBase");
|
this.BASE_CLASS = loader.loadClass(craftpackageName + ".NBTBase");
|
||||||
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
||||||
this.NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
this.NBT_CREATE_TAG =
|
||||||
|
getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
||||||
|
|
||||||
// Prepare CraftItemStack
|
// Prepare CraftItemStack
|
||||||
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
||||||
@ -92,11 +76,14 @@ public class NbtFactory {
|
|||||||
initializeNMS(loader, nmsPackage);
|
initializeNMS(loader, nmsPackage);
|
||||||
|
|
||||||
if (this.READ_LIMITER_CLASS != null) {
|
if (this.READ_LIMITER_CLASS != null) {
|
||||||
this.LOAD_COMPOUND = new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
this.LOAD_COMPOUND =
|
||||||
|
new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
||||||
} else {
|
} else {
|
||||||
this.LOAD_COMPOUND = new LoadMethodWorldUpdate(this.STREAM_TOOLS);
|
this.LOAD_COMPOUND = new LoadMethodWorldUpdate(this.STREAM_TOOLS);
|
||||||
}
|
}
|
||||||
this.SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, this.STREAM_TOOLS, null, this.BASE_CLASS, DataOutput.class);
|
this.SAVE_COMPOUND =
|
||||||
|
getMethod(Modifier.STATIC, 0, this.STREAM_TOOLS, null, this.BASE_CLASS,
|
||||||
|
DataOutput.class);
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new IllegalStateException("Unable to find offline player.", e);
|
throw new IllegalStateException("Unable to find offline player.", e);
|
||||||
@ -106,6 +93,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve or construct a shared NBT factory.
|
* Retrieve or construct a shared NBT factory.
|
||||||
|
*
|
||||||
* @return The factory.
|
* @return The factory.
|
||||||
*/
|
*/
|
||||||
private static NbtFactory get() {
|
private static NbtFactory get() {
|
||||||
@ -117,6 +105,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT list of an unspecified type.
|
* Construct a new NBT list of an unspecified type.
|
||||||
|
*
|
||||||
* @return The NBT list.
|
* @return The NBT list.
|
||||||
*/
|
*/
|
||||||
public static NbtList createList(Object... content) {
|
public static NbtList createList(Object... content) {
|
||||||
@ -125,6 +114,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT list of an unspecified type.
|
* Construct a new NBT list of an unspecified type.
|
||||||
|
*
|
||||||
* @return The NBT list.
|
* @return The NBT list.
|
||||||
*/
|
*/
|
||||||
public static NbtList createList(Iterable<? extends Object> iterable) {
|
public static NbtList createList(Iterable<? extends Object> iterable) {
|
||||||
@ -148,6 +138,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT wrapper from a list.
|
* Construct a new NBT wrapper from a list.
|
||||||
|
*
|
||||||
* @param nmsList - the NBT list.
|
* @param nmsList - the NBT list.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
@ -163,7 +154,8 @@ public class NbtFactory {
|
|||||||
* @return The decoded NBT compound.
|
* @return The decoded NBT compound.
|
||||||
* @throws IOException If anything went wrong.
|
* @throws IOException If anything went wrong.
|
||||||
*/
|
*/
|
||||||
public static NbtCompound fromStream(InputStream input, StreamOptions option) throws IOException {
|
public static NbtCompound fromStream(InputStream input, StreamOptions option)
|
||||||
|
throws IOException {
|
||||||
DataInputStream data = null;
|
DataInputStream data = null;
|
||||||
boolean suppress = true;
|
boolean suppress = true;
|
||||||
|
|
||||||
@ -195,14 +187,16 @@ public class NbtFactory {
|
|||||||
* @param option - whether or not to compress the output.
|
* @param option - whether or not to compress the output.
|
||||||
* @throws IOException If anything went wrong.
|
* @throws IOException If anything went wrong.
|
||||||
*/
|
*/
|
||||||
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option) throws IOException {
|
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option)
|
||||||
|
throws IOException {
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
DataOutputStream data = null;
|
DataOutputStream data = null;
|
||||||
boolean suppress = true;
|
boolean suppress = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
output = stream.openStream();
|
output = stream.openStream();
|
||||||
data = new DataOutputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
|
data = new DataOutputStream(
|
||||||
|
option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
|
||||||
|
|
||||||
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
|
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
|
||||||
suppress = false;
|
suppress = false;
|
||||||
@ -218,6 +212,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT wrapper from a compound.
|
* Construct a new NBT wrapper from a compound.
|
||||||
|
*
|
||||||
* @param nmsCompound - the NBT compound.
|
* @param nmsCompound - the NBT compound.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
@ -228,6 +223,7 @@ public class NbtFactory {
|
|||||||
/**
|
/**
|
||||||
* Set the NBT compound tag of a given item stack.
|
* Set the NBT compound tag of a given item stack.
|
||||||
* <p>
|
* <p>
|
||||||
|
*
|
||||||
* @param stack - the item stack, cannot be air.
|
* @param stack - the item stack, cannot be air.
|
||||||
* @param compound - the new NBT compound, or NULL to remove it.
|
* @param compound - the new NBT compound, or NULL to remove it.
|
||||||
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
|
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
|
||||||
@ -246,6 +242,7 @@ public class NbtFactory {
|
|||||||
* material, damage value or count.
|
* material, damage value or count.
|
||||||
* <p>
|
* <p>
|
||||||
* The item stack must be a wrapper for a CraftItemStack.
|
* The item stack must be a wrapper for a CraftItemStack.
|
||||||
|
*
|
||||||
* @param stack - the item stack.
|
* @param stack - the item stack.
|
||||||
* @return A wrapper for its NBT tag.
|
* @return A wrapper for its NBT tag.
|
||||||
*/
|
*/
|
||||||
@ -265,6 +262,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a CraftItemStack version of the stack.
|
* Retrieve a CraftItemStack version of the stack.
|
||||||
|
*
|
||||||
* @param stack - the stack to convert.
|
* @param stack - the stack to convert.
|
||||||
* @return The CraftItemStack version.
|
* @return The CraftItemStack version.
|
||||||
*/
|
*/
|
||||||
@ -279,12 +277,14 @@ public class NbtFactory {
|
|||||||
caller.setAccessible(true);
|
caller.setAccessible(true);
|
||||||
return (ItemStack) caller.newInstance(stack);
|
return (ItemStack) caller.newInstance(stack);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
throw new IllegalStateException("Unable to convert " + stack + " + to a CraftItemStack.");
|
throw new IllegalStateException(
|
||||||
|
"Unable to convert " + stack + " + to a CraftItemStack.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that the given stack can store arbitrary NBT information.
|
* Ensure that the given stack can store arbitrary NBT information.
|
||||||
|
*
|
||||||
* @param stack - the stack to check.
|
* @param stack - the stack to check.
|
||||||
*/
|
*/
|
||||||
private static void checkItemStack(ItemStack stack) {
|
private static void checkItemStack(ItemStack stack) {
|
||||||
@ -295,12 +295,14 @@ public class NbtFactory {
|
|||||||
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
|
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
|
||||||
}
|
}
|
||||||
if (stack.getType() == Material.AIR) {
|
if (stack.getType() == Material.AIR) {
|
||||||
throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information.");
|
throw new IllegalArgumentException(
|
||||||
|
"ItemStacks representing air cannot store NMS information.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke a method on the given target instance using the provided parameters.
|
* Invoke a method on the given target instance using the provided parameters.
|
||||||
|
*
|
||||||
* @param method - the method to invoke.
|
* @param method - the method to invoke.
|
||||||
* @param target - the target.
|
* @param target - the target.
|
||||||
* @param params - the parameters to supply.
|
* @param params - the parameters to supply.
|
||||||
@ -332,6 +334,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for the first publicly and privately defined method of the given name and parameter count.
|
* Search for the first publicly and privately defined method of the given name and parameter count.
|
||||||
|
*
|
||||||
* @param requireMod - modifiers that are required.
|
* @param requireMod - modifiers that are required.
|
||||||
* @param bannedMod - modifiers that are banned.
|
* @param bannedMod - modifiers that are banned.
|
||||||
* @param clazz - a class to start with.
|
* @param clazz - a class to start with.
|
||||||
@ -340,14 +343,14 @@ public class NbtFactory {
|
|||||||
* @return The first method by this name.
|
* @return The first method by this name.
|
||||||
* @throws IllegalStateException If we cannot find this method.
|
* @throws IllegalStateException If we cannot find this method.
|
||||||
*/
|
*/
|
||||||
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName,
|
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz,
|
||||||
Class<?>... params) {
|
String methodName, Class<?>... params) {
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
// Limitation: Doesn't handle overloads
|
// Limitation: Doesn't handle overloads
|
||||||
if (((method.getModifiers() & requireMod) == requireMod)
|
if (((method.getModifiers() & requireMod) == requireMod) && (
|
||||||
&& ((method.getModifiers() & bannedMod) == 0)
|
(method.getModifiers() & bannedMod) == 0) && ((methodName == null) || method
|
||||||
&& ((methodName == null) || method.getName().equals(methodName))
|
.getName().equals(methodName)) && Arrays
|
||||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
.equals(method.getParameterTypes(), params)) {
|
||||||
|
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return method;
|
return method;
|
||||||
@ -357,11 +360,13 @@ public class NbtFactory {
|
|||||||
if (clazz.getSuperclass() != null) {
|
if (clazz.getSuperclass() != null) {
|
||||||
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
|
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
|
||||||
}
|
}
|
||||||
throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
|
throw new IllegalStateException(
|
||||||
|
String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for the first publicly and privately defined field of the given name.
|
* Search for the first publicly and privately defined field of the given name.
|
||||||
|
*
|
||||||
* @param instance - an instance of the class with the field.
|
* @param instance - an instance of the class with the field.
|
||||||
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
|
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
|
||||||
* @param fieldName - the field name.
|
* @param fieldName - the field name.
|
||||||
@ -390,7 +395,8 @@ public class NbtFactory {
|
|||||||
try {
|
try {
|
||||||
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
||||||
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
||||||
} catch (ClassNotFoundException ignored) {}
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageName() {
|
private String getPackageName() {
|
||||||
@ -406,22 +412,23 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCraftPackageName() {
|
private String getCraftPackageName() {
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
String version =
|
||||||
|
Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
return "net.minecraft.server." + version;
|
return "net.minecraft.server." + version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") private Map<String, Object> getDataMap(Object handle) {
|
||||||
private Map<String, Object> getDataMap(Object handle) {
|
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle),
|
||||||
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle), handle);
|
handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") private List<Object> getDataList(Object handle) {
|
||||||
private List<Object> getDataList(Object handle) {
|
|
||||||
return (List<Object>) getFieldValue(getDataField(NbtType.TAG_LIST, handle), handle);
|
return (List<Object>) getFieldValue(getDataField(NbtType.TAG_LIST, handle), handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert wrapped List and Map objects into their respective NBT counterparts.
|
* Convert wrapped List and Map objects into their respective NBT counterparts.
|
||||||
|
*
|
||||||
* @param value - the value of the element to create. Can be a List or a Map.
|
* @param value - the value of the element to create. Can be a List or a Map.
|
||||||
* @return The NBT element.
|
* @return The NBT element.
|
||||||
*/
|
*/
|
||||||
@ -444,6 +451,7 @@ public class NbtFactory {
|
|||||||
/**
|
/**
|
||||||
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
|
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
|
||||||
* <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
|
* <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
|
||||||
|
*
|
||||||
* @param nms - the NBT element.
|
* @param nms - the NBT element.
|
||||||
* @return The wrapper equivalent.
|
* @return The wrapper equivalent.
|
||||||
*/
|
*/
|
||||||
@ -470,6 +478,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NMS NBT tag initialized with the given value.
|
* Construct a new NMS NBT tag initialized with the given value.
|
||||||
|
*
|
||||||
* @param type - the NBT type.
|
* @param type - the NBT type.
|
||||||
* @param value - the value, or NULL to keep the original value.
|
* @param value - the value, or NULL to keep the original value.
|
||||||
* @return The created tag.
|
* @return The created tag.
|
||||||
@ -485,6 +494,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the field where the NBT class stores its value.
|
* Retrieve the field where the NBT class stores its value.
|
||||||
|
*
|
||||||
* @param type - the NBT type.
|
* @param type - the NBT type.
|
||||||
* @param nms - the NBT class instance.
|
* @param nms - the NBT class instance.
|
||||||
* @return The corresponding field.
|
* @return The corresponding field.
|
||||||
@ -498,6 +508,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the NBT type from a given NMS NBT tag.
|
* Retrieve the NBT type from a given NMS NBT tag.
|
||||||
|
*
|
||||||
* @param nms - the native NBT tag.
|
* @param nms - the native NBT tag.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
@ -508,40 +519,38 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the nearest NBT type for a given primitive type.
|
* Retrieve the nearest NBT type for a given primitive type.
|
||||||
|
*
|
||||||
* @param primitive - the primitive type.
|
* @param primitive - the primitive type.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
private NbtType getPrimitiveType(Object primitive) {
|
private NbtType getPrimitiveType(Object primitive) {
|
||||||
NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
NbtType type =
|
||||||
|
NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
||||||
|
|
||||||
// Display the illegal value at least
|
// Display the illegal value at least
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new IllegalArgumentException(String.format("Illegal type: %s (%s)", primitive.getClass(), primitive));
|
throw new IllegalArgumentException(
|
||||||
|
String.format("Illegal type: %s (%s)", primitive.getClass(), primitive));
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not to enable stream compression.
|
* Whether or not to enable stream compression.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public enum StreamOptions {
|
public enum StreamOptions {
|
||||||
NO_COMPRESSION, GZIP_COMPRESSION,
|
NO_COMPRESSION, GZIP_COMPRESSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum NbtType {
|
private enum NbtType {
|
||||||
TAG_END(0, Void.class),
|
TAG_END(0, Void.class), TAG_BYTE(1, byte.class), TAG_SHORT(2, short.class), TAG_INT(3,
|
||||||
TAG_BYTE(1, byte.class),
|
int.class), TAG_LONG(4, long.class), TAG_FLOAT(5, float.class), TAG_DOUBLE(6,
|
||||||
TAG_SHORT(2, short.class),
|
double.class), TAG_BYTE_ARRAY(7, byte[].class), TAG_INT_ARRAY(11,
|
||||||
TAG_INT(3, int.class),
|
int[].class), TAG_STRING(8, String.class), TAG_LIST(9, List.class), TAG_COMPOUND(10,
|
||||||
TAG_LONG(4, long.class),
|
Map.class);
|
||||||
TAG_FLOAT(5, float.class),
|
|
||||||
TAG_DOUBLE(6, double.class),
|
|
||||||
TAG_BYTE_ARRAY(7, byte[].class),
|
|
||||||
TAG_INT_ARRAY(11, int[].class),
|
|
||||||
TAG_STRING(8, String.class),
|
|
||||||
TAG_LIST(9, List.class),
|
|
||||||
TAG_COMPOUND(10, Map.class);
|
|
||||||
|
|
||||||
// Unique NBT type
|
// Unique NBT type
|
||||||
public final int id;
|
public final int id;
|
||||||
@ -563,21 +572,26 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object that provides a view of a native NMS class.
|
* Represents an object that provides a view of a native NMS class.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public interface Wrapper {
|
public interface Wrapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the underlying native NBT tag.
|
* Retrieve the underlying native NBT tag.
|
||||||
|
*
|
||||||
* @return The underlying NBT.
|
* @return The underlying NBT.
|
||||||
*/
|
*/
|
||||||
Object getHandle();
|
Object getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a method for loading an NBT compound.
|
* Represents a method for loading an NBT compound.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private static abstract class LoadCompoundMethod {
|
private static abstract class LoadCompoundMethod {
|
||||||
@ -591,12 +605,14 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from a given stream.
|
* Load an NBT compound from a given stream.
|
||||||
|
*
|
||||||
* @param input - the input stream.
|
* @param input - the input stream.
|
||||||
* @return The loaded NBT compound.
|
* @return The loaded NBT compound.
|
||||||
*/
|
*/
|
||||||
public abstract Object loadNbt(DataInput input);
|
public abstract Object loadNbt(DataInput input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.2 - 1.7.5
|
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.2 - 1.7.5
|
||||||
*/
|
*/
|
||||||
@ -606,12 +622,12 @@ public class NbtFactory {
|
|||||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object loadNbt(DataInput input) {
|
||||||
public Object loadNbt(DataInput input) {
|
|
||||||
return invokeMethod(this.staticMethod, null, input);
|
return invokeMethod(this.staticMethod, null, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.8
|
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.8
|
||||||
*/
|
*/
|
||||||
@ -620,7 +636,8 @@ public class NbtFactory {
|
|||||||
private Object readLimiter;
|
private Object readLimiter;
|
||||||
|
|
||||||
LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
|
LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
|
||||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
|
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class,
|
||||||
|
readLimiterClass));
|
||||||
|
|
||||||
// Find the unlimited read limiter
|
// Find the unlimited read limiter
|
||||||
for (Field field : readLimiterClass.getDeclaredFields()) {
|
for (Field field : readLimiterClass.getDeclaredFields()) {
|
||||||
@ -634,12 +651,12 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object loadNbt(DataInput input) {
|
||||||
public Object loadNbt(DataInput input) {
|
|
||||||
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a root NBT compound.
|
* Represents a root NBT compound.
|
||||||
* <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
|
* <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
|
||||||
@ -655,6 +672,7 @@ public class NbtFactory {
|
|||||||
* <li>{@link NbtFactory#createCompound()}</li>
|
* <li>{@link NbtFactory#createCompound()}</li>
|
||||||
* <li>{@link NbtFactory#fromCompound(Object)}</li>
|
* <li>{@link NbtFactory#fromCompound(Object)}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public final class NbtCompound extends ConvertedMap {
|
public final class NbtCompound extends ConvertedMap {
|
||||||
@ -702,6 +720,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list by the given name.
|
* Retrieve the list by the given name.
|
||||||
|
*
|
||||||
* @param key - the name of the list.
|
* @param key - the name of the list.
|
||||||
* @param createNew - whether or not to create a new list if its missing.
|
* @param createNew - whether or not to create a new list if its missing.
|
||||||
* @return An existing list, a new list or NULL.
|
* @return An existing list, a new list or NULL.
|
||||||
@ -717,6 +736,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the map by the given name.
|
* Retrieve the map by the given name.
|
||||||
|
*
|
||||||
* @param key - the name of the map.
|
* @param key - the name of the map.
|
||||||
* @param createNew - whether or not to create a new map if its missing.
|
* @param createNew - whether or not to create a new map if its missing.
|
||||||
* @return An existing map, a new map or NULL.
|
* @return An existing map, a new map or NULL.
|
||||||
@ -732,6 +752,7 @@ public class NbtFactory {
|
|||||||
* <p>
|
* <p>
|
||||||
* Every element of the path (except the end) are assumed to be compounds, and will
|
* Every element of the path (except the end) are assumed to be compounds, and will
|
||||||
* be created if they are missing.
|
* be created if they are missing.
|
||||||
|
*
|
||||||
* @param path - the path to the entry.
|
* @param path - the path to the entry.
|
||||||
* @param value - the new value of this entry.
|
* @param value - the new value of this entry.
|
||||||
* @return This compound, for chaining.
|
* @return This compound, for chaining.
|
||||||
@ -749,11 +770,11 @@ public class NbtFactory {
|
|||||||
* <p>
|
* <p>
|
||||||
* Every element of the path (except the end) are assumed to be compounds. The
|
* Every element of the path (except the end) are assumed to be compounds. The
|
||||||
* retrieval operation will be cancelled if any of them are missing.
|
* retrieval operation will be cancelled if any of them are missing.
|
||||||
|
*
|
||||||
* @param path - path to the entry.
|
* @param path - path to the entry.
|
||||||
* @return The value, or NULL if not found.
|
* @return The value, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") public <T> T getPath(String path) {
|
||||||
public <T> T getPath(String path) {
|
|
||||||
List<String> entries = getPathElements(path);
|
List<String> entries = getPathElements(path);
|
||||||
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
||||||
|
|
||||||
@ -765,6 +786,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the content of a NBT compound to a stream.
|
* Save the content of a NBT compound to a stream.
|
||||||
|
*
|
||||||
* @param stream - the output stream.
|
* @param stream - the output stream.
|
||||||
* @param option - whether or not to compress the output.
|
* @param option - whether or not to compress the output.
|
||||||
* @throws IOException If anything went wrong.
|
* @throws IOException If anything went wrong.
|
||||||
@ -775,6 +797,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a map from a given path.
|
* Retrieve a map from a given path.
|
||||||
|
*
|
||||||
* @param path - path of compounds to look up.
|
* @param path - path of compounds to look up.
|
||||||
* @param createNew - whether or not to create new compounds on the way.
|
* @param createNew - whether or not to create new compounds on the way.
|
||||||
* @return The map at this location.
|
* @return The map at this location.
|
||||||
@ -798,6 +821,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Split the path into separate elements.
|
* Split the path into separate elements.
|
||||||
|
*
|
||||||
* @param path - the path to split.
|
* @param path - the path to split.
|
||||||
* @return The elements.
|
* @return The elements.
|
||||||
*/
|
*/
|
||||||
@ -806,6 +830,7 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a root NBT list.
|
* Represents a root NBT list.
|
||||||
* See also:
|
* See also:
|
||||||
@ -813,6 +838,7 @@ public class NbtFactory {
|
|||||||
* <li>{@link NbtFactory#createList(Iterable)}}</li>
|
* <li>{@link NbtFactory#createList(Iterable)}}</li>
|
||||||
* <li>{@link NbtFactory#fromList(Object)}</li>
|
* <li>{@link NbtFactory#fromList(Object)}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public final class NbtList extends ConvertedList {
|
public final class NbtList extends ConvertedList {
|
||||||
@ -822,8 +848,10 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a class for caching wrappers.
|
* Represents a class for caching wrappers.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private final class CachedNativeWrapper {
|
private final class CachedNativeWrapper {
|
||||||
@ -846,9 +874,11 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a map that wraps another map and automatically
|
* Represents a map that wraps another map and automatically
|
||||||
* converts entries of its type and another exposed type.
|
* converts entries of its type and another exposed type.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private class ConvertedMap extends AbstractMap<String, Object> implements Wrapper {
|
private class ConvertedMap extends AbstractMap<String, Object> implements Wrapper {
|
||||||
@ -873,32 +903,26 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modification
|
// Modification
|
||||||
@Override
|
@Override public Object put(String key, Object value) {
|
||||||
public Object put(String key, Object value) {
|
|
||||||
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Performance
|
// Performance
|
||||||
@Override
|
@Override public Object get(Object key) {
|
||||||
public Object get(Object key) {
|
|
||||||
return wrapOutgoing(this.original.get(key));
|
return wrapOutgoing(this.original.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object remove(Object key) {
|
||||||
public Object remove(Object key) {
|
|
||||||
return wrapOutgoing(this.original.remove(key));
|
return wrapOutgoing(this.original.remove(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean containsKey(Object key) {
|
||||||
public boolean containsKey(Object key) {
|
|
||||||
return this.original.containsKey(key);
|
return this.original.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Set<Entry<String, Object>> entrySet() {
|
||||||
public Set<Entry<String, Object>> entrySet() {
|
|
||||||
return new AbstractSet<Entry<String, Object>>() {
|
return new AbstractSet<Entry<String, Object>>() {
|
||||||
@Override
|
@Override public boolean add(Entry<String, Object> e) {
|
||||||
public boolean add(Entry<String, Object> e) {
|
|
||||||
String key = e.getKey();
|
String key = e.getKey();
|
||||||
Object value = e.getValue();
|
Object value = e.getValue();
|
||||||
|
|
||||||
@ -906,13 +930,11 @@ public class NbtFactory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int size() {
|
||||||
public int size() {
|
|
||||||
return ConvertedMap.this.original.size();
|
return ConvertedMap.this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Iterator<Entry<String, Object>> iterator() {
|
||||||
public Iterator<Entry<String, Object>> iterator() {
|
|
||||||
return ConvertedMap.this.iterator();
|
return ConvertedMap.this.iterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -922,34 +944,33 @@ public class NbtFactory {
|
|||||||
final Iterator<Entry<String, Object>> proxy = this.original.entrySet().iterator();
|
final Iterator<Entry<String, Object>> proxy = this.original.entrySet().iterator();
|
||||||
|
|
||||||
return new Iterator<Entry<String, Object>>() {
|
return new Iterator<Entry<String, Object>>() {
|
||||||
@Override
|
@Override public boolean hasNext() {
|
||||||
public boolean hasNext() {
|
|
||||||
return proxy.hasNext();
|
return proxy.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Entry<String, Object> next() {
|
||||||
public Entry<String, Object> next() {
|
|
||||||
Entry<String, Object> entry = proxy.next();
|
Entry<String, Object> entry = proxy.next();
|
||||||
|
|
||||||
return new SimpleEntry<String, Object>(entry.getKey(), wrapOutgoing(entry.getValue()));
|
return new SimpleEntry<String, Object>(entry.getKey(),
|
||||||
|
wrapOutgoing(entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void remove() {
|
||||||
public void remove() {
|
|
||||||
proxy.remove();
|
proxy.remove();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object getHandle() {
|
||||||
public Object getHandle() {
|
|
||||||
return this.handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a list that wraps another list and converts elements
|
* Represents a list that wraps another list and converts elements
|
||||||
* of its type and another exposed type.
|
* of its type and another exposed type.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private class ConvertedList extends AbstractList<Object> implements Wrapper {
|
private class ConvertedList extends AbstractList<Object> implements Wrapper {
|
||||||
@ -975,44 +996,38 @@ public class NbtFactory {
|
|||||||
return unwrapValue(wrapped);
|
return unwrapValue(wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object get(int index) {
|
||||||
public Object get(int index) {
|
|
||||||
return wrapOutgoing(this.original.get(index));
|
return wrapOutgoing(this.original.get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int size() {
|
||||||
public int size() {
|
|
||||||
return this.original.size();
|
return this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object set(int index, Object element) {
|
||||||
public Object set(int index, Object element) {
|
|
||||||
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void add(int index, Object element) {
|
||||||
public void add(int index, Object element) {
|
|
||||||
Object nbt = unwrapIncoming(element);
|
Object nbt = unwrapIncoming(element);
|
||||||
|
|
||||||
// Set the list type if its the first element
|
// Set the list type if its the first element
|
||||||
if (size() == 0) {
|
if (size() == 0) {
|
||||||
setFieldValue(NbtFactory.this.NBT_LIST_TYPE, this.handle, (byte) getNbtType(nbt).id);
|
setFieldValue(NbtFactory.this.NBT_LIST_TYPE, this.handle,
|
||||||
|
(byte) getNbtType(nbt).id);
|
||||||
}
|
}
|
||||||
this.original.add(index, nbt);
|
this.original.add(index, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object remove(int index) {
|
||||||
public Object remove(int index) {
|
|
||||||
return wrapOutgoing(this.original.remove(index));
|
return wrapOutgoing(this.original.remove(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean remove(Object o) {
|
||||||
public boolean remove(Object o) {
|
|
||||||
return this.original.remove(unwrapIncoming(o));
|
return this.original.remove(unwrapIncoming(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object getHandle() {
|
||||||
public Object getHandle() {
|
|
||||||
return this.handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callConstructor;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callMethod;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getCbClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getNmsClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getUtilClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeConstructor;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeMethod;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -17,6 +9,8 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.*;
|
||||||
|
|
||||||
public class OfflinePlayerUtil {
|
public class OfflinePlayerUtil {
|
||||||
|
|
||||||
public static Player loadPlayer(String name) {
|
public static Player loadPlayer(String name) {
|
||||||
@ -43,10 +37,12 @@ public class OfflinePlayerUtil {
|
|||||||
Object worldServer = getWorldServer();
|
Object worldServer = getWorldServer();
|
||||||
Object profile = newGameProfile(id, name);
|
Object profile = newGameProfile(id, name);
|
||||||
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||||
Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
Constructor entityPlayerConstructor =
|
||||||
getUtilClass("com.mojang.authlib.GameProfile"),
|
makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"),
|
||||||
|
getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"),
|
||||||
getNmsClass("PlayerInteractManager"));
|
getNmsClass("PlayerInteractManager"));
|
||||||
Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
Object entityPlayer =
|
||||||
|
callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||||
return (Player) getBukkitEntity(entityPlayer);
|
return (Player) getBukkitEntity(entityPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +51,8 @@ public class OfflinePlayerUtil {
|
|||||||
if (gameProfileClass == null) { //Before uuids
|
if (gameProfileClass == null) { //Before uuids
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
Constructor gameProfileConstructor = makeConstructor(gameProfileClass, UUID.class, String.class);
|
Constructor gameProfileConstructor =
|
||||||
|
makeConstructor(gameProfileClass, UUID.class, String.class);
|
||||||
if (gameProfileConstructor == null) { //Version has string constructor
|
if (gameProfileConstructor == null) { //Version has string constructor
|
||||||
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
||||||
return callConstructor(gameProfileConstructor, id.toString(), name);
|
return callConstructor(gameProfileConstructor, id.toString(), name);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
@ -25,6 +23,8 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility that can be used to send chunks, rather than using bukkit code
|
* An utility that can be used to send chunks, rather than using bukkit code
|
||||||
* to do so (uses heavy NMS).
|
* to do so (uses heavy NMS).
|
||||||
@ -55,9 +55,11 @@ public class SendChunk {
|
|||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
|
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
tempMapChunk = classMapChunk
|
||||||
|
.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {
|
||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),boolean.class, int.class, int.class);
|
tempMapChunk = classMapChunk
|
||||||
|
.getConstructor(classChunk.getRealClass(), boolean.class, int.class, int.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.mapChunk = tempMapChunk;
|
this.mapChunk = tempMapChunk;
|
||||||
@ -119,7 +121,8 @@ public class SendChunk {
|
|||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
|
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
|
||||||
try {
|
try {
|
||||||
packet = this.mapChunk.create(c, 65535);
|
packet = this.mapChunk.create(c, 65535);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
packet = this.mapChunk.create(c, true, 65535);
|
packet = this.mapChunk.create(c, true, 65535);
|
||||||
@ -139,13 +142,13 @@ public class SendChunk {
|
|||||||
}
|
}
|
||||||
for (final Chunk chunk : chunks) {
|
for (final Chunk chunk : chunks) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
String worldName = chunk.getWorld().getName();
|
String worldName = chunk.getWorld().getName();
|
||||||
PS.debug("$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + chunk.getZ());
|
PS.debug("$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";"
|
||||||
|
+ chunk.getZ());
|
||||||
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
PS.debug("$3 - $4" + worldName + "/level.dat or " + worldName
|
PS.debug("$3 - $4" + worldName + "/level.dat or " + worldName
|
||||||
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
||||||
|
@ -4,34 +4,35 @@ import com.intellectualcrafters.plot.object.PlotBlock;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||||
|
|
||||||
|
private Field fieldNeighbors;
|
||||||
|
private Method chunkGetHandle;
|
||||||
|
|
||||||
public BukkitLocalQueue(String world) {
|
public BukkitLocalQueue(String world) {
|
||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public LocalChunk<T> getLocalChunk(int x, int z) {
|
||||||
public LocalChunk<T> getLocalChunk(int x, int z) {
|
|
||||||
return (LocalChunk<T>) new BasicLocalChunk(this, x, z) {
|
return (LocalChunk<T>) new BasicLocalChunk(this, x, z) {
|
||||||
// Custom stuff?
|
// Custom stuff?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void optimize() {
|
||||||
public void optimize() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||||
public PlotBlock getBlock(int x, int y, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
Block block = worldObj.getBlockAt(x, y, z);
|
Block block = worldObj.getBlockAt(x, y, z);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
@ -44,25 +45,21 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
return PlotBlock.get(id, block.getData());
|
return PlotBlock.get(id, block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void refreshChunk(int x, int z) {
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
worldObj.refreshChunk(x, z);
|
worldObj.refreshChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void regenChunk(int x, int z) {
|
||||||
public final void regenChunk(int x, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
worldObj.regenerateChunk(x, z);
|
worldObj.regenerateChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setComponents(LocalChunk<T> lc) {
|
||||||
public final void setComponents(LocalChunk<T> lc) {
|
|
||||||
setBlocks(lc);
|
setBlocks(lc);
|
||||||
setBiomes(lc);
|
setBiomes(lc);
|
||||||
}
|
}
|
||||||
@ -129,13 +126,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field fieldNeighbors;
|
|
||||||
private Method chunkGetHandle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
|
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
|
||||||
* - Could have been achieved without reflection by force unloading specific chunks
|
* - Could have been achieved without reflection by force unloading specific chunks
|
||||||
* - Much faster just setting the variable manually though
|
* - Much faster just setting the variable manually though
|
||||||
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -153,7 +148,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
Object value = fieldNeighbors.get(nmsChunk);
|
Object value = fieldNeighbors.get(nmsChunk);
|
||||||
fieldNeighbors.set(nmsChunk, 0);
|
fieldNeighbors.set(nmsChunk, 0);
|
||||||
return new Object[] {nmsChunk, value};
|
return new Object[] {nmsChunk, value};
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +177,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
if (disableResult != null) {
|
if (disableResult != null) {
|
||||||
try {
|
try {
|
||||||
fieldNeighbors.set(disableResult[0], 0x739C0);
|
fieldNeighbors.set(disableResult[0], 0x739C0);
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,16 +6,11 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.bukkit.util.SendChunk;
|
import com.plotsquared.bukkit.util.SendChunk;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -36,24 +31,26 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
|
|
||||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||||
|
|
||||||
public BukkitLocalQueue_1_7(String world) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
public BukkitLocalQueue_1_7(String world)
|
||||||
|
throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
||||||
super(world);
|
super(world);
|
||||||
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||||
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||||
this.methodA = this.classChunk.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class);
|
this.methodA = this.classChunk
|
||||||
|
.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class);
|
||||||
this.methodGetById = this.classBlock.getMethod("getById", int.class);
|
this.methodGetById = this.classBlock.getMethod("getById", int.class);
|
||||||
this.methodGetHandleChunk = this.classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = this.classCraftChunk.getMethod("getHandle");
|
||||||
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||||
this.sendChunk = new SendChunk();
|
this.sendChunk = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (BukkitLocalQueue_1_7.this.toUpdate.isEmpty()) {
|
if (BukkitLocalQueue_1_7.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
Iterator<Map.Entry<ChunkWrapper, Chunk>> i = BukkitLocalQueue_1_7.this.toUpdate.entrySet().iterator();
|
Iterator<Map.Entry<ChunkWrapper, Chunk>> i =
|
||||||
|
BukkitLocalQueue_1_7.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && (count < 128)) {
|
while (i.hasNext() && (count < 128)) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -88,14 +85,12 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
||||||
this.methodInitLighting.of(c).call();
|
this.methodInitLighting.of(c).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setBlocks(LocalChunk<PlotBlock[]> lc) {
|
||||||
public void setBlocks(LocalChunk<PlotBlock[]> lc) {
|
|
||||||
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
@ -128,8 +123,7 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
fixChunkLighting(lc.getX(), lc.getZ());
|
fixChunkLighting(lc.getX(), lc.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void refreshChunk(int x, int z) {
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.util.block;
|
package com.plotsquared.bukkit.util.block;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkWrapper;
|
import com.intellectualcrafters.plot.object.ChunkWrapper;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@ -10,17 +8,15 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
|||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.bukkit.util.SendChunk;
|
import com.plotsquared.bukkit.util.SendChunk;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
||||||
|
|
||||||
private final ReflectionUtils.RefMethod methodInitLighting;
|
private final ReflectionUtils.RefMethod methodInitLighting;
|
||||||
@ -39,26 +35,29 @@ public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
private final SendChunk sendChunk;
|
private final SendChunk sendChunk;
|
||||||
private final RefMethod methodGetHandleChunk;
|
private final RefMethod methodGetHandleChunk;
|
||||||
|
|
||||||
public BukkitLocalQueue_1_8(String world) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
public BukkitLocalQueue_1_8(String world)
|
||||||
|
throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
||||||
super(world);
|
super(world);
|
||||||
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||||
this.constructorBlockPosition = this.classBlockPosition.getConstructor(int.class, int.class, int.class);
|
this.constructorBlockPosition =
|
||||||
|
this.classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||||
this.methodGetByCombinedId = this.classBlock.getMethod("getByCombinedId", int.class);
|
this.methodGetByCombinedId = this.classBlock.getMethod("getByCombinedId", int.class);
|
||||||
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||||
this.methodA = this.classChunk.getMethod("a", this.classBlockPosition, this.classIBlockData);
|
this.methodA =
|
||||||
|
this.classChunk.getMethod("a", this.classBlockPosition, this.classIBlockData);
|
||||||
this.sendChunk = new SendChunk();
|
this.sendChunk = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (BukkitLocalQueue_1_8.this.toUpdate.isEmpty()) {
|
if (BukkitLocalQueue_1_8.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
Iterator<Map.Entry<ChunkWrapper, Chunk>> i = BukkitLocalQueue_1_8.this.toUpdate.entrySet().iterator();
|
Iterator<Map.Entry<ChunkWrapper, Chunk>> i =
|
||||||
|
BukkitLocalQueue_1_8.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && count < 128) {
|
while (i.hasNext() && count < 128) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -73,14 +72,12 @@ public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
||||||
this.methodInitLighting.of(c).call();
|
this.methodInitLighting.of(c).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setBlocks(LocalChunk<PlotBlock[]> lc) {
|
||||||
public void setBlocks(LocalChunk<PlotBlock[]> lc) {
|
|
||||||
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
@ -100,7 +97,8 @@ public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
int z = MainUtil.z_loc[i][j];
|
int z = MainUtil.z_loc[i][j];
|
||||||
PlotBlock newBlock = result2[j];
|
PlotBlock newBlock = result2[j];
|
||||||
if (newBlock == null) continue;
|
if (newBlock == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (newBlock.id == -1) {
|
if (newBlock.id == -1) {
|
||||||
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
||||||
@ -309,7 +307,8 @@ public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Object combined = this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
Object combined =
|
||||||
|
this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
||||||
this.methodA.of(c).call(pos, combined);
|
this.methodA.of(c).call(pos, combined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,8 +335,7 @@ public class BukkitLocalQueue_1_8 extends BukkitLocalQueue<PlotBlock[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void refreshChunk(int x, int z) {
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,14 @@ import com.intellectualcrafters.plot.util.ReflectionUtils;
|
|||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
||||||
import com.plotsquared.bukkit.util.SendChunk;
|
import com.plotsquared.bukkit.util.SendChunk;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -43,7 +37,8 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
private final ReflectionUtils.RefMethod methodGetWorld;
|
private final ReflectionUtils.RefMethod methodGetWorld;
|
||||||
private final ReflectionUtils.RefField tileEntityListTick;
|
private final ReflectionUtils.RefField tileEntityListTick;
|
||||||
|
|
||||||
public BukkitLocalQueue_1_8_3(String world) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
public BukkitLocalQueue_1_8_3(String world)
|
||||||
|
throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
||||||
super(world);
|
super(world);
|
||||||
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||||
@ -51,7 +46,8 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
ReflectionUtils.RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
ReflectionUtils.RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||||
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
this.classBlockPositionConstructor =
|
||||||
|
classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||||
ReflectionUtils.RefClass classWorld = getRefClass("{nms}.World");
|
ReflectionUtils.RefClass classWorld = getRefClass("{nms}.World");
|
||||||
this.methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
this.methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
||||||
this.fieldSections = classChunk.getField("sections");
|
this.fieldSections = classChunk.getField("sections");
|
||||||
@ -59,20 +55,21 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
ReflectionUtils.RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
ReflectionUtils.RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||||
this.methodGetIdArray = classChunkSection.getMethod("getIdArray");
|
this.methodGetIdArray = classChunkSection.getMethod("getIdArray");
|
||||||
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||||
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
this.classChunkSectionConstructor =
|
||||||
|
classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||||
this.tileEntityListTick = classWorld.getField("tileEntityList");
|
this.tileEntityListTick = classWorld.getField("tileEntityList");
|
||||||
this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle");
|
this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle");
|
||||||
this.methodGetWorld = classChunk.getMethod("getWorld");
|
this.methodGetWorld = classChunk.getMethod("getWorld");
|
||||||
this.sendChunk = new SendChunk();
|
this.sendChunk = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (BukkitLocalQueue_1_8_3.this.toUpdate.isEmpty()) {
|
if (BukkitLocalQueue_1_8_3.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
Iterator<Map.Entry<ChunkWrapper, Chunk>> i = BukkitLocalQueue_1_8_3.this.toUpdate.entrySet().iterator();
|
Iterator<Map.Entry<ChunkWrapper, Chunk>> i =
|
||||||
|
BukkitLocalQueue_1_8_3.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && count < 128) {
|
while (i.hasNext() && count < 128) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -87,11 +84,290 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public LocalChunk<char[]> getLocalChunk(int x, int z) {
|
||||||
public LocalChunk<char[]> getLocalChunk(int x, int z) {
|
|
||||||
return new CharLocalChunk_1_8_3(this, x, z);
|
return new CharLocalChunk_1_8_3(this, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void setBlocks(LocalChunk lc) {
|
||||||
|
CharLocalChunk_1_8_3 fs = (CharLocalChunk_1_8_3) lc;
|
||||||
|
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
||||||
|
chunk.load(true);
|
||||||
|
World world = chunk.getWorld();
|
||||||
|
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), lc.getX(), lc.getZ());
|
||||||
|
if (!this.toUpdate.containsKey(wrapper)) {
|
||||||
|
this.toUpdate.put(wrapper, chunk);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boolean flag = world.getEnvironment() == World.Environment.NORMAL;
|
||||||
|
|
||||||
|
// Sections
|
||||||
|
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||||
|
Object c = getHandle.invoke(chunk);
|
||||||
|
Object w = this.methodGetWorld.of(c).call();
|
||||||
|
Class<?> clazz = c.getClass();
|
||||||
|
Field sections1 = clazz.getDeclaredField("sections");
|
||||||
|
sections1.setAccessible(true);
|
||||||
|
Field tileEntities = clazz.getDeclaredField("tileEntities");
|
||||||
|
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||||
|
Object[] sections = (Object[]) sections1.get(c);
|
||||||
|
Map<?, ?> tiles = (Map<?, ?>) tileEntities.get(c);
|
||||||
|
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
||||||
|
|
||||||
|
Method getX = null;
|
||||||
|
Method getY = null;
|
||||||
|
Method getZ = null;
|
||||||
|
|
||||||
|
// Trim tiles
|
||||||
|
boolean removed = false;
|
||||||
|
Set<Map.Entry<?, ?>> entrySet = (Set<Map.Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||||
|
Iterator<Map.Entry<?, ?>> iterator = entrySet.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<?, ?> tile = iterator.next();
|
||||||
|
Object pos = tile.getKey();
|
||||||
|
if (getX == null) {
|
||||||
|
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||||
|
getX = clazz2.getDeclaredMethod("getX");
|
||||||
|
getY = clazz2.getDeclaredMethod("getY");
|
||||||
|
getZ = clazz2.getDeclaredMethod("getZ");
|
||||||
|
}
|
||||||
|
int lx = (int) getX.invoke(pos) & 15;
|
||||||
|
int ly = (int) getY.invoke(pos);
|
||||||
|
int lz = (int) getZ.invoke(pos) & 15;
|
||||||
|
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||||
|
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||||
|
char[] array = fs.getIdArray(j);
|
||||||
|
if (array == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (array[k] != 0) {
|
||||||
|
removed = true;
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removed) {
|
||||||
|
((Collection) this.tileEntityListTick.of(w).get()).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim entities
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
if ((entities[i] != null) && (fs.getCount(i) >= 4096)) {
|
||||||
|
entities[i].clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Efficiently merge sections
|
||||||
|
for (int j = 0; j < sections.length; j++) {
|
||||||
|
if (fs.getCount(j) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char[] newArray = fs.getIdArray(j);
|
||||||
|
if (newArray == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object section = sections[j];
|
||||||
|
if ((section == null) || (fs.getCount(j) >= 4096)) {
|
||||||
|
section = sections[j] = newChunkSection(j << 4, flag, newArray);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char[] currentArray = getIdArray(section);
|
||||||
|
boolean fill = true;
|
||||||
|
for (int k = 0; k < newArray.length; k++) {
|
||||||
|
char n = newArray[k];
|
||||||
|
switch (n) {
|
||||||
|
case 0:
|
||||||
|
fill = false;
|
||||||
|
continue;
|
||||||
|
case 1:
|
||||||
|
fill = false;
|
||||||
|
currentArray[k] = 0;
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
currentArray[k] = n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fill) {
|
||||||
|
fs.setCount(j, Short.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Clear
|
||||||
|
} catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
fixLighting(chunk, fs, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object newChunkSection(int i, boolean flag, char[] ids)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] getIdArray(Object obj) {
|
||||||
|
return (char[]) this.methodGetIdArray.of(obj).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
|
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
||||||
|
this.methodInitLighting.of(c).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean fixLighting(Chunk chunk, CharLocalChunk_1_8_3 bc, boolean fixAll) {
|
||||||
|
try {
|
||||||
|
if (!chunk.isLoaded()) {
|
||||||
|
chunk.load(false);
|
||||||
|
} else {
|
||||||
|
chunk.unload(true, false);
|
||||||
|
chunk.load(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize lighting
|
||||||
|
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||||
|
|
||||||
|
if (fixAll && !(boolean) this.methodAreNeighborsLoaded.of(c).call(1)) {
|
||||||
|
World world = chunk.getWorld();
|
||||||
|
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ());
|
||||||
|
for (int x = wrapper.x - 1; x <= wrapper.x + 1; x++) {
|
||||||
|
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
|
||||||
|
if (x != 0 && z != 0) {
|
||||||
|
Chunk other = world.getChunkAt(x, z);
|
||||||
|
while (!other.isLoaded()) {
|
||||||
|
other.load(true);
|
||||||
|
}
|
||||||
|
ChunkManager.manager.loadChunk(wrapper.world, new ChunkLoc(x, z), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
this.methodInitLighting.of(c).call();
|
||||||
|
|
||||||
|
if (bc.getTotalRelight() == 0 && !fixAll) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||||
|
Object w = this.fieldWorld.of(c).get();
|
||||||
|
|
||||||
|
int X = chunk.getX() << 4;
|
||||||
|
int Z = chunk.getZ() << 4;
|
||||||
|
|
||||||
|
ReflectionUtils.RefMethod.RefExecutor relight = this.methodX.of(w);
|
||||||
|
for (int j = 0; j < sections.length; j++) {
|
||||||
|
Object section = sections[j];
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (
|
||||||
|
bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char[] array = getIdArray(section);
|
||||||
|
int l = PseudoRandom.random.random(2);
|
||||||
|
for (int k = 0; k < array.length; k++) {
|
||||||
|
int i = array[k];
|
||||||
|
if (i < 16) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
short id = (short) (i >> 4);
|
||||||
|
switch (id) { // Lighting
|
||||||
|
default:
|
||||||
|
if (!fixAll) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((k & 1) == l) {
|
||||||
|
l = 1 - l;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case 10:
|
||||||
|
case 11:
|
||||||
|
case 39:
|
||||||
|
case 40:
|
||||||
|
case 50:
|
||||||
|
case 51:
|
||||||
|
case 62:
|
||||||
|
case 74:
|
||||||
|
case 76:
|
||||||
|
case 89:
|
||||||
|
case 122:
|
||||||
|
case 124:
|
||||||
|
case 130:
|
||||||
|
case 138:
|
||||||
|
case 169:
|
||||||
|
int x = MainUtil.x_loc[j][k];
|
||||||
|
int y = MainUtil.y_loc[j][k];
|
||||||
|
int z = MainUtil.z_loc[j][k];
|
||||||
|
if (isSurrounded(sections, x, y, z)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||||
|
relight.call(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSurrounded(Object[] sections, int x, int y, int z) {
|
||||||
|
return isSolid(getId(sections, x, y + 1, z)) && isSolid(getId(sections, x + 1, y - 1, z))
|
||||||
|
&& isSolid(getId(sections, x - 1, y, z)) && isSolid(getId(sections, x, y, z + 1))
|
||||||
|
&& isSolid(getId(sections, x, y, z - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSolid(int i) {
|
||||||
|
return i != 0 && Material.getMaterial(i).isOccluding();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(Object[] sections, int x, int y, int z) {
|
||||||
|
if (x < 0 || x > 15 || z < 0 || z > 15) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (y < 0 || y > 255) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
|
Object section = sections[i];
|
||||||
|
if (section == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char[] array = getIdArray(section);
|
||||||
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
|
return array[j] >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Collection<Chunk> chunks) {
|
||||||
|
if (chunks.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!MainUtil.canSendChunk) {
|
||||||
|
for (Chunk chunk : chunks) {
|
||||||
|
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
|
chunk.unload(true, false);
|
||||||
|
chunk.load();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.sendChunk.sendChunk(chunks);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
MainUtil.canSendChunk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void refreshChunk(int x, int z) {
|
||||||
|
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class CharLocalChunk_1_8_3 extends CharLocalChunk {
|
public class CharLocalChunk_1_8_3 extends CharLocalChunk {
|
||||||
public short[] count;
|
public short[] count;
|
||||||
public short[] air;
|
public short[] air;
|
||||||
@ -104,8 +380,7 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
this.relight = new short[16];
|
this.relight = new short[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setBlock(int x, int y, int z, int id, int data) {
|
||||||
public void setBlock(int x, int y, int z, int id, int data) {
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
char[] vs = this.blocks[i];
|
char[] vs = this.blocks[i];
|
||||||
@ -252,286 +527,4 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlocks(LocalChunk lc) {
|
|
||||||
CharLocalChunk_1_8_3 fs = (CharLocalChunk_1_8_3) lc;
|
|
||||||
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
|
||||||
chunk.load(true);
|
|
||||||
World world = chunk.getWorld();
|
|
||||||
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), lc.getX(), lc.getZ());
|
|
||||||
if (!this.toUpdate.containsKey(wrapper)) {
|
|
||||||
this.toUpdate.put(wrapper, chunk);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
boolean flag = world.getEnvironment() == World.Environment.NORMAL;
|
|
||||||
|
|
||||||
// Sections
|
|
||||||
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
|
||||||
Object c = getHandle.invoke(chunk);
|
|
||||||
Object w = this.methodGetWorld.of(c).call();
|
|
||||||
Class<?> clazz = c.getClass();
|
|
||||||
Field sections1 = clazz.getDeclaredField("sections");
|
|
||||||
sections1.setAccessible(true);
|
|
||||||
Field tileEntities = clazz.getDeclaredField("tileEntities");
|
|
||||||
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
|
||||||
Object[] sections = (Object[]) sections1.get(c);
|
|
||||||
Map<?, ?> tiles = (Map<?, ?>) tileEntities.get(c);
|
|
||||||
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
|
||||||
|
|
||||||
Method getX = null;
|
|
||||||
Method getY = null;
|
|
||||||
Method getZ = null;
|
|
||||||
|
|
||||||
// Trim tiles
|
|
||||||
boolean removed = false;
|
|
||||||
Set<Map.Entry<?, ?>> entrySet = (Set<Map.Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
|
||||||
Iterator<Map.Entry<?, ?>> iterator = entrySet.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Map.Entry<?, ?> tile = iterator.next();
|
|
||||||
Object pos = tile.getKey();
|
|
||||||
if (getX == null) {
|
|
||||||
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
|
||||||
getX = clazz2.getDeclaredMethod("getX");
|
|
||||||
getY = clazz2.getDeclaredMethod("getY");
|
|
||||||
getZ = clazz2.getDeclaredMethod("getZ");
|
|
||||||
}
|
|
||||||
int lx = (int) getX.invoke(pos) & 15;
|
|
||||||
int ly = (int) getY.invoke(pos);
|
|
||||||
int lz = (int) getZ.invoke(pos) & 15;
|
|
||||||
int j = MainUtil.CACHE_I[ly][lx][lz];
|
|
||||||
int k = MainUtil.CACHE_J[ly][lx][lz];
|
|
||||||
char[] array = fs.getIdArray(j);
|
|
||||||
if (array == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (array[k] != 0) {
|
|
||||||
removed = true;
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removed) {
|
|
||||||
((Collection) this.tileEntityListTick.of(w).get()).clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trim entities
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
if ((entities[i] != null) && (fs.getCount(i) >= 4096)) {
|
|
||||||
entities[i].clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Efficiently merge sections
|
|
||||||
for (int j = 0; j < sections.length; j++) {
|
|
||||||
if (fs.getCount(j) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char[] newArray = fs.getIdArray(j);
|
|
||||||
if (newArray == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object section = sections[j];
|
|
||||||
if ((section == null) || (fs.getCount(j) >= 4096)) {
|
|
||||||
section = sections[j] = newChunkSection(j << 4, flag, newArray);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char[] currentArray = getIdArray(section);
|
|
||||||
boolean fill = true;
|
|
||||||
for (int k = 0; k < newArray.length; k++) {
|
|
||||||
char n = newArray[k];
|
|
||||||
switch (n) {
|
|
||||||
case 0:
|
|
||||||
fill = false;
|
|
||||||
continue;
|
|
||||||
case 1:
|
|
||||||
fill = false;
|
|
||||||
currentArray[k] = 0;
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
currentArray[k] = n;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fill) {
|
|
||||||
fs.setCount(j, Short.MAX_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Clear
|
|
||||||
} catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
fixLighting(chunk, fs, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object newChunkSection(int i, boolean flag, char[] ids) throws ReflectiveOperationException {
|
|
||||||
return this.classChunkSectionConstructor.create(i, flag, ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
public char[] getIdArray(Object obj) {
|
|
||||||
return (char[]) this.methodGetIdArray.of(obj).call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
|
||||||
this.methodInitLighting.of(c).call();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean fixLighting(Chunk chunk, CharLocalChunk_1_8_3 bc, boolean fixAll) {
|
|
||||||
try {
|
|
||||||
if (!chunk.isLoaded()) {
|
|
||||||
chunk.load(false);
|
|
||||||
} else {
|
|
||||||
chunk.unload(true, false);
|
|
||||||
chunk.load(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize lighting
|
|
||||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
|
||||||
|
|
||||||
if (fixAll && !(boolean) this.methodAreNeighborsLoaded.of(c).call(1)) {
|
|
||||||
World world = chunk.getWorld();
|
|
||||||
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ());
|
|
||||||
for (int x = wrapper.x - 1; x <= wrapper.x + 1; x++) {
|
|
||||||
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
|
|
||||||
if (x != 0 && z != 0) {
|
|
||||||
Chunk other = world.getChunkAt(x, z);
|
|
||||||
while (!other.isLoaded()) {
|
|
||||||
other.load(true);
|
|
||||||
}
|
|
||||||
ChunkManager.manager.loadChunk(wrapper.world, new ChunkLoc(x, z), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
this.methodInitLighting.of(c).call();
|
|
||||||
|
|
||||||
if (bc.getTotalRelight() == 0 && !fixAll) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
|
||||||
Object w = this.fieldWorld.of(c).get();
|
|
||||||
|
|
||||||
int X = chunk.getX() << 4;
|
|
||||||
int Z = chunk.getZ() << 4;
|
|
||||||
|
|
||||||
ReflectionUtils.RefMethod.RefExecutor relight = this.methodX.of(w);
|
|
||||||
for (int j = 0; j < sections.length; j++) {
|
|
||||||
Object section = sections[j];
|
|
||||||
if (section == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char[] array = getIdArray(section);
|
|
||||||
int l = PseudoRandom.random.random(2);
|
|
||||||
for (int k = 0; k < array.length; k++) {
|
|
||||||
int i = array[k];
|
|
||||||
if (i < 16) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
short id = (short) (i >> 4);
|
|
||||||
switch (id) { // Lighting
|
|
||||||
default:
|
|
||||||
if (!fixAll) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((k & 1) == l) {
|
|
||||||
l = 1 - l;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
case 10:
|
|
||||||
case 11:
|
|
||||||
case 39:
|
|
||||||
case 40:
|
|
||||||
case 50:
|
|
||||||
case 51:
|
|
||||||
case 62:
|
|
||||||
case 74:
|
|
||||||
case 76:
|
|
||||||
case 89:
|
|
||||||
case 122:
|
|
||||||
case 124:
|
|
||||||
case 130:
|
|
||||||
case 138:
|
|
||||||
case 169:
|
|
||||||
int x = MainUtil.x_loc[j][k];
|
|
||||||
int y = MainUtil.y_loc[j][k];
|
|
||||||
int z = MainUtil.z_loc[j][k];
|
|
||||||
if (isSurrounded(sections, x, y, z)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
|
||||||
relight.call(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSurrounded(Object[] sections, int x, int y, int z) {
|
|
||||||
return isSolid(getId(sections, x, y + 1, z))
|
|
||||||
&& isSolid(getId(sections, x + 1, y - 1, z))
|
|
||||||
&& isSolid(getId(sections, x - 1, y, z))
|
|
||||||
&& isSolid(getId(sections, x, y, z + 1))
|
|
||||||
&& isSolid(getId(sections, x, y, z - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSolid(int i) {
|
|
||||||
return i != 0 && Material.getMaterial(i).isOccluding();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(Object[] sections, int x, int y, int z) {
|
|
||||||
if (x < 0 || x > 15 || z < 0 || z > 15) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (y < 0 || y > 255) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
|
||||||
Object section = sections[i];
|
|
||||||
if (section == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char[] array = getIdArray(section);
|
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
|
||||||
return array[j] >> 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(Collection<Chunk> chunks) {
|
|
||||||
if (chunks.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!MainUtil.canSendChunk) {
|
|
||||||
for (Chunk chunk : chunks) {
|
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
|
||||||
chunk.unload(true, false);
|
|
||||||
chunk.load();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
this.sendChunk.sendChunk(chunks);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
MainUtil.canSendChunk = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
update(Arrays.asList(Bukkit.getWorld(getWorld()).getChunkAt(x, z)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,13 @@ import com.intellectualcrafters.plot.object.PseudoRandom;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||||
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -40,14 +36,16 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
|
|||||||
|
|
||||||
private final ReflectionUtils.RefField tileEntityListTick;
|
private final ReflectionUtils.RefField tileEntityListTick;
|
||||||
|
|
||||||
public BukkitLocalQueue_1_9(String world) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
public BukkitLocalQueue_1_9(String world)
|
||||||
|
throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException {
|
||||||
super(world);
|
super(world);
|
||||||
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
ReflectionUtils.RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
ReflectionUtils.RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||||
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
this.classBlockPositionConstructor =
|
||||||
|
classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||||
ReflectionUtils.RefClass classWorld = getRefClass("{nms}.World");
|
ReflectionUtils.RefClass classWorld = getRefClass("{nms}.World");
|
||||||
this.tileEntityListTick = classWorld.getField("tileEntityListTick");
|
this.tileEntityListTick = classWorld.getField("tileEntityListTick");
|
||||||
this.methodGetWorld = classChunk.getMethod("getWorld");
|
this.methodGetWorld = classChunk.getMethod("getWorld");
|
||||||
@ -56,23 +54,284 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
|
|||||||
this.fieldWorld = classChunk.getField("world");
|
this.fieldWorld = classChunk.getField("world");
|
||||||
ReflectionUtils.RefClass classBlock = getRefClass("{nms}.Block");
|
ReflectionUtils.RefClass classBlock = getRefClass("{nms}.Block");
|
||||||
ReflectionUtils.RefClass classIBlockData = getRefClass("{nms}.IBlockData");
|
ReflectionUtils.RefClass classIBlockData = getRefClass("{nms}.IBlockData");
|
||||||
this.methodGetCombinedId = classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
this.methodGetCombinedId =
|
||||||
|
classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
||||||
this.methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
this.methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
||||||
ReflectionUtils.RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
ReflectionUtils.RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||||
this.methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
this.methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
||||||
this.methodGetType = classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
this.methodGetType =
|
||||||
this.methodSetType = classChunkSection.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
||||||
|
this.methodSetType = classChunkSection
|
||||||
|
.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
||||||
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||||
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
this.classChunkSectionConstructor =
|
||||||
|
classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||||
this.air = this.methodGetByCombinedId.call(0);
|
this.air = this.methodGetByCombinedId.call(0);
|
||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public LocalChunk<char[]> getLocalChunk(int x, int z) {
|
||||||
public LocalChunk<char[]> getLocalChunk(int x, int z) {
|
|
||||||
return new CharLocalChunk_1_8_3(this, x, z);
|
return new CharLocalChunk_1_8_3(this, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void setBlocks(LocalChunk lc) {
|
||||||
|
CharLocalChunk_1_8_3 fs = (CharLocalChunk_1_8_3) lc;
|
||||||
|
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
||||||
|
chunk.load(true);
|
||||||
|
World world = chunk.getWorld();
|
||||||
|
try {
|
||||||
|
boolean flag = world.getEnvironment() == World.Environment.NORMAL;
|
||||||
|
|
||||||
|
// Sections
|
||||||
|
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||||
|
Object c = getHandle.invoke(chunk);
|
||||||
|
Object w = this.methodGetWorld.of(c).call();
|
||||||
|
Class<? extends Object> clazz = c.getClass();
|
||||||
|
Field sf = clazz.getDeclaredField("sections");
|
||||||
|
sf.setAccessible(true);
|
||||||
|
Field tf = clazz.getDeclaredField("tileEntities");
|
||||||
|
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||||
|
Object[] sections = (Object[]) sf.get(c);
|
||||||
|
Map<?, ?> tiles = (Map<?, ?>) tf.get(c);
|
||||||
|
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
||||||
|
|
||||||
|
Method xm = null;
|
||||||
|
Method ym = null;
|
||||||
|
Method zm = null;
|
||||||
|
// Trim tiles
|
||||||
|
Collection tickList = ((Collection) this.tileEntityListTick.of(w).get());
|
||||||
|
Set<Map.Entry<?, ?>> entrySet = (Set<Map.Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||||
|
Iterator<Map.Entry<?, ?>> iterator = entrySet.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<?, ?> tile = iterator.next();
|
||||||
|
Object pos = tile.getKey();
|
||||||
|
if (xm == null) {
|
||||||
|
Class<?> clazz2 = pos.getClass().getSuperclass();
|
||||||
|
xm = clazz2.getDeclaredMethod("getX");
|
||||||
|
ym = clazz2.getDeclaredMethod("getY");
|
||||||
|
zm = clazz2.getDeclaredMethod("getZ");
|
||||||
|
}
|
||||||
|
int lx = (int) xm.invoke(pos) & 15;
|
||||||
|
int ly = (int) ym.invoke(pos);
|
||||||
|
int lz = (int) zm.invoke(pos) & 15;
|
||||||
|
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||||
|
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||||
|
char[] array = fs.getIdArray(j);
|
||||||
|
if (array == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (array[k] != 0) {
|
||||||
|
tickList.remove(tile.getValue());
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim entities
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
if (entities[i] != null && fs.getCount(i) >= 4096) {
|
||||||
|
entities[i].clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Efficiently merge sections
|
||||||
|
for (int j = 0; j < sections.length; j++) {
|
||||||
|
if (fs.getCount(j) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char[] newArray = fs.getIdArray(j);
|
||||||
|
if (newArray == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object section = sections[j];
|
||||||
|
if (section == null || fs.getCount(j) >= 4096) {
|
||||||
|
section = sections[j] = newChunkSection(j << 4, flag, fs.getIdArray(j));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object currentArray = getBlocks(section);
|
||||||
|
ReflectionUtils.RefMethod.RefExecutor setType = this.methodSetType.of(section);
|
||||||
|
boolean fill = true;
|
||||||
|
for (int k = 0; k < newArray.length; k++) {
|
||||||
|
char n = newArray[k];
|
||||||
|
switch (n) {
|
||||||
|
case 0:
|
||||||
|
fill = false;
|
||||||
|
continue;
|
||||||
|
case 1: {
|
||||||
|
fill = false;
|
||||||
|
int x = MainUtil.x_loc[j][k];
|
||||||
|
int y = MainUtil.y_loc[j][k];
|
||||||
|
int z = MainUtil.z_loc[j][k];
|
||||||
|
setType.call(x, y & 15, z, this.air);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
int x = MainUtil.x_loc[j][k];
|
||||||
|
int y = MainUtil.y_loc[j][k];
|
||||||
|
int z = MainUtil.z_loc[j][k];
|
||||||
|
int id = n >> 4;
|
||||||
|
int data = n & 15;
|
||||||
|
Object iBlock =
|
||||||
|
this.methodGetByCombinedId.call((int) (id & 0xFFF) + (data << 12));
|
||||||
|
setType.call(x, y & 15, z, iBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fill) {
|
||||||
|
fs.setCount(j, Short.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Clear
|
||||||
|
} catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
fixLighting(chunk, fs, true);
|
||||||
|
refreshChunk(fs.getX(), fs.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object newChunkSection(int i, boolean flag, char[] ids)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getBlocks(Object obj) {
|
||||||
|
return this.methodGetBlocks.of(obj).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
|
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
||||||
|
this.methodInitLighting.of(c).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean fixLighting(Chunk chunk, CharLocalChunk_1_8_3 bc, boolean fixAll) {
|
||||||
|
try {
|
||||||
|
if (!chunk.isLoaded()) {
|
||||||
|
chunk.load(false);
|
||||||
|
} else {
|
||||||
|
chunk.unload(true, false);
|
||||||
|
chunk.load(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize lighting
|
||||||
|
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||||
|
|
||||||
|
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), bc.getX(), bc.getZ());
|
||||||
|
Object[] result = disableLighting(chunk);
|
||||||
|
enableLighting(result);
|
||||||
|
|
||||||
|
this.methodInitLighting.of(c).call();
|
||||||
|
|
||||||
|
if (bc.getTotalRelight() != 0 || fixAll) {
|
||||||
|
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||||
|
Object w = this.fieldWorld.of(c).get();
|
||||||
|
|
||||||
|
int X = chunk.getX() << 4;
|
||||||
|
int Z = chunk.getZ() << 4;
|
||||||
|
ReflectionUtils.RefMethod.RefExecutor relight = this.methodW.of(w);
|
||||||
|
for (int j = 0; j < sections.length; j++) {
|
||||||
|
Object section = sections[j];
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0
|
||||||
|
|| bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char[] array = bc.getIdArray(j);
|
||||||
|
if (array != null) {
|
||||||
|
int l = PseudoRandom.random.random(2);
|
||||||
|
for (int k = 0; k < array.length; k++) {
|
||||||
|
int i = array[k];
|
||||||
|
if (i < 16) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
short id = (short) (i >> 4);
|
||||||
|
switch (id) { // Lighting
|
||||||
|
default:
|
||||||
|
if (!fixAll) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((k & 1) == l) {
|
||||||
|
l = 1 - l;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case 10:
|
||||||
|
case 11:
|
||||||
|
case 39:
|
||||||
|
case 40:
|
||||||
|
case 50:
|
||||||
|
case 51:
|
||||||
|
case 62:
|
||||||
|
case 74:
|
||||||
|
case 76:
|
||||||
|
case 89:
|
||||||
|
case 122:
|
||||||
|
case 124:
|
||||||
|
case 130:
|
||||||
|
case 138:
|
||||||
|
case 169:
|
||||||
|
int x = MainUtil.x_loc[j][k];
|
||||||
|
int y = MainUtil.y_loc[j][k];
|
||||||
|
int z = MainUtil.z_loc[j][k];
|
||||||
|
if (isSurrounded(bc.blocks, x, y, z)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object pos =
|
||||||
|
this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||||
|
relight.call(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetLighting(result);
|
||||||
|
return true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void refreshChunk(int x, int z) {
|
||||||
|
getBukkitWorld().refreshChunk(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSurrounded(char[][] sections, int x, int y, int z) {
|
||||||
|
return isSolid(getId(sections, x, y + 1, z)) && isSolid(getId(sections, x + 1, y - 1, z))
|
||||||
|
&& isSolid(getId(sections, x - 1, y, z)) && isSolid(getId(sections, x, y, z + 1))
|
||||||
|
&& isSolid(getId(sections, x, y, z - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSolid(int i) {
|
||||||
|
if (i != 0) {
|
||||||
|
Material material = Material.getMaterial(i);
|
||||||
|
return material != null && Material.getMaterial(i).isOccluding();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(char[] section, int x, int y, int z) {
|
||||||
|
if (section == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
|
return section[j] >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(char[][] sections, int x, int y, int z) {
|
||||||
|
if (x < 0 || x > 15 || z < 0 || z > 15) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (y < 0 || y > 255) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
|
char[] section = sections[i];
|
||||||
|
if (section == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return getId(section, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class CharLocalChunk_1_8_3 extends CharLocalChunk {
|
public class CharLocalChunk_1_8_3 extends CharLocalChunk {
|
||||||
public short[] count;
|
public short[] count;
|
||||||
public short[] air;
|
public short[] air;
|
||||||
@ -85,8 +344,7 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
|
|||||||
this.relight = new short[16];
|
this.relight = new short[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setBlock(int x, int y, int z, int id, int data) {
|
||||||
public void setBlock(int x, int y, int z, int id, int data) {
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
char[] vs = this.blocks[i];
|
char[] vs = this.blocks[i];
|
||||||
@ -233,262 +491,4 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlocks(LocalChunk lc) {
|
|
||||||
CharLocalChunk_1_8_3 fs = (CharLocalChunk_1_8_3) lc;
|
|
||||||
Chunk chunk = getChunk(lc.getX(), lc.getZ());
|
|
||||||
chunk.load(true);
|
|
||||||
World world = chunk.getWorld();
|
|
||||||
try {
|
|
||||||
boolean flag = world.getEnvironment() == World.Environment.NORMAL;
|
|
||||||
|
|
||||||
// Sections
|
|
||||||
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
|
||||||
Object c = getHandle.invoke(chunk);
|
|
||||||
Object w = this.methodGetWorld.of(c).call();
|
|
||||||
Class<? extends Object> clazz = c.getClass();
|
|
||||||
Field sf = clazz.getDeclaredField("sections");
|
|
||||||
sf.setAccessible(true);
|
|
||||||
Field tf = clazz.getDeclaredField("tileEntities");
|
|
||||||
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
|
||||||
Object[] sections = (Object[]) sf.get(c);
|
|
||||||
Map<?, ?> tiles = (Map<?, ?>) tf.get(c);
|
|
||||||
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
|
||||||
|
|
||||||
Method xm = null;
|
|
||||||
Method ym = null;
|
|
||||||
Method zm = null;
|
|
||||||
// Trim tiles
|
|
||||||
Collection tickList = ((Collection) this.tileEntityListTick.of(w).get());
|
|
||||||
Set<Map.Entry<?, ?>> entrySet = (Set<Map.Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
|
||||||
Iterator<Map.Entry<?, ?>> iterator = entrySet.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Map.Entry<?, ?> tile = iterator.next();
|
|
||||||
Object pos = tile.getKey();
|
|
||||||
if (xm == null) {
|
|
||||||
Class<?> clazz2 = pos.getClass().getSuperclass();
|
|
||||||
xm = clazz2.getDeclaredMethod("getX");
|
|
||||||
ym = clazz2.getDeclaredMethod("getY");
|
|
||||||
zm = clazz2.getDeclaredMethod("getZ");
|
|
||||||
}
|
|
||||||
int lx = (int) xm.invoke(pos) & 15;
|
|
||||||
int ly = (int) ym.invoke(pos);
|
|
||||||
int lz = (int) zm.invoke(pos) & 15;
|
|
||||||
int j = MainUtil.CACHE_I[ly][lx][lz];
|
|
||||||
int k = MainUtil.CACHE_J[ly][lx][lz];
|
|
||||||
char[] array = fs.getIdArray(j);
|
|
||||||
if (array == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (array[k] != 0) {
|
|
||||||
tickList.remove(tile.getValue());
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trim entities
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
if (entities[i] != null && fs.getCount(i) >= 4096) {
|
|
||||||
entities[i].clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Efficiently merge sections
|
|
||||||
for (int j = 0; j < sections.length; j++) {
|
|
||||||
if (fs.getCount(j) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char[] newArray = fs.getIdArray(j);
|
|
||||||
if (newArray == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object section = sections[j];
|
|
||||||
if (section == null || fs.getCount(j) >= 4096) {
|
|
||||||
section = sections[j] = newChunkSection(j << 4, flag, fs.getIdArray(j));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object currentArray = getBlocks(section);
|
|
||||||
ReflectionUtils.RefMethod.RefExecutor setType = this.methodSetType.of(section);
|
|
||||||
boolean fill = true;
|
|
||||||
for (int k = 0; k < newArray.length; k++) {
|
|
||||||
char n = newArray[k];
|
|
||||||
switch (n) {
|
|
||||||
case 0:
|
|
||||||
fill = false;
|
|
||||||
continue;
|
|
||||||
case 1: {
|
|
||||||
fill = false;
|
|
||||||
int x = MainUtil.x_loc[j][k];
|
|
||||||
int y = MainUtil.y_loc[j][k];
|
|
||||||
int z = MainUtil.z_loc[j][k];
|
|
||||||
setType.call(x, y & 15, z, this.air);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
int x = MainUtil.x_loc[j][k];
|
|
||||||
int y = MainUtil.y_loc[j][k];
|
|
||||||
int z = MainUtil.z_loc[j][k];
|
|
||||||
int id = n >> 4;
|
|
||||||
int data = n & 15;
|
|
||||||
Object iBlock = this.methodGetByCombinedId.call((int) (id & 0xFFF) + (data << 12));
|
|
||||||
setType.call(x, y & 15, z, iBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fill) {
|
|
||||||
fs.setCount(j, Short.MAX_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Clear
|
|
||||||
} catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
fixLighting(chunk, fs, true);
|
|
||||||
refreshChunk(fs.getX(), fs.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object newChunkSection(int i, boolean flag, char[] ids) throws ReflectiveOperationException {
|
|
||||||
return this.classChunkSectionConstructor.create(i, flag, ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getBlocks(Object obj) {
|
|
||||||
return this.methodGetBlocks.of(obj).call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
|
|
||||||
this.methodInitLighting.of(c).call();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean fixLighting(Chunk chunk, CharLocalChunk_1_8_3 bc, boolean fixAll) {
|
|
||||||
try {
|
|
||||||
if (!chunk.isLoaded()) {
|
|
||||||
chunk.load(false);
|
|
||||||
} else {
|
|
||||||
chunk.unload(true, false);
|
|
||||||
chunk.load(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize lighting
|
|
||||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
|
||||||
|
|
||||||
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), bc.getX(), bc.getZ());
|
|
||||||
Object[] result = disableLighting(chunk);
|
|
||||||
enableLighting(result);
|
|
||||||
|
|
||||||
this.methodInitLighting.of(c).call();
|
|
||||||
|
|
||||||
if (bc.getTotalRelight() != 0 || fixAll) {
|
|
||||||
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
|
||||||
Object w = this.fieldWorld.of(c).get();
|
|
||||||
|
|
||||||
int X = chunk.getX() << 4;
|
|
||||||
int Z = chunk.getZ() << 4;
|
|
||||||
ReflectionUtils.RefMethod.RefExecutor relight = this.methodW.of(w);
|
|
||||||
for (int j = 0; j < sections.length; j++) {
|
|
||||||
Object section = sections[j];
|
|
||||||
if (section == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char[] array = bc.getIdArray(j);
|
|
||||||
if (array != null) {
|
|
||||||
int l = PseudoRandom.random.random(2);
|
|
||||||
for (int k = 0; k < array.length; k++) {
|
|
||||||
int i = array[k];
|
|
||||||
if (i < 16) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
short id = (short) (i >> 4);
|
|
||||||
switch (id) { // Lighting
|
|
||||||
default:
|
|
||||||
if (!fixAll) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((k & 1) == l) {
|
|
||||||
l = 1 - l;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
case 10:
|
|
||||||
case 11:
|
|
||||||
case 39:
|
|
||||||
case 40:
|
|
||||||
case 50:
|
|
||||||
case 51:
|
|
||||||
case 62:
|
|
||||||
case 74:
|
|
||||||
case 76:
|
|
||||||
case 89:
|
|
||||||
case 122:
|
|
||||||
case 124:
|
|
||||||
case 130:
|
|
||||||
case 138:
|
|
||||||
case 169:
|
|
||||||
int x = MainUtil.x_loc[j][k];
|
|
||||||
int y = MainUtil.y_loc[j][k];
|
|
||||||
int z = MainUtil.z_loc[j][k];
|
|
||||||
if (isSurrounded(bc.blocks, x, y, z)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
|
||||||
relight.call(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resetLighting(result);
|
|
||||||
return true;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
getBukkitWorld().refreshChunk(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSurrounded(char[][] sections, int x, int y, int z) {
|
|
||||||
return isSolid(getId(sections, x, y + 1, z))
|
|
||||||
&& isSolid(getId(sections, x + 1, y - 1, z))
|
|
||||||
&& isSolid(getId(sections, x - 1, y, z))
|
|
||||||
&& isSolid(getId(sections, x, y, z + 1))
|
|
||||||
&& isSolid(getId(sections, x, y, z - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSolid(int i) {
|
|
||||||
if (i != 0) {
|
|
||||||
Material material = Material.getMaterial(i);
|
|
||||||
return material != null && Material.getMaterial(i).isOccluding();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(char[] section, int x, int y, int z) {
|
|
||||||
if (section == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
|
||||||
return section[j] >> 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(char[][] sections, int x, int y, int z) {
|
|
||||||
if (x < 0 || x > 15 || z < 0 || z > 15) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (y < 0 || y > 255) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
|
||||||
char[] section = sections[i];
|
|
||||||
if (section == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return getId(section, x, y, z);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.object.PlotBlock;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import java.util.Arrays;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -15,6 +14,8 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
|||||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class GenChunk extends ScopedLocalBlockQueue {
|
public class GenChunk extends ScopedLocalBlockQueue {
|
||||||
|
|
||||||
public final Biome[] biomes;
|
public final Biome[] biomes;
|
||||||
@ -37,13 +38,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChunk(ChunkWrapper wrap) {
|
|
||||||
chunk = null;
|
|
||||||
world = wrap.world;
|
|
||||||
cx = wrap.x;
|
|
||||||
cz = wrap.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
World worldObj = BukkitUtil.getWorld(world);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
@ -54,6 +48,13 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChunk(ChunkWrapper wrap) {
|
||||||
|
chunk = null;
|
||||||
|
world = wrap.world;
|
||||||
|
cx = wrap.x;
|
||||||
|
cz = wrap.z;
|
||||||
|
}
|
||||||
|
|
||||||
public ChunkWrapper getChunkWrapper() {
|
public ChunkWrapper getChunkWrapper() {
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
return new ChunkWrapper(world, cx, cz);
|
return new ChunkWrapper(world, cx, cz);
|
||||||
@ -61,8 +62,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fillBiome(String biomeName) {
|
||||||
public void fillBiome(String biomeName) {
|
|
||||||
if (grid == null) {
|
if (grid == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,9 +74,9 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
|
||||||
public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
|
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0
|
||||||
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
|
&& pos2.getX() == 15 && pos2.getZ() == 15) {
|
||||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||||
int layer = y >> 4;
|
int layer = y >> 4;
|
||||||
short[] data = result[layer];
|
short[] data = result[layer];
|
||||||
@ -92,8 +92,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean setBiome(int x, int z, String biome) {
|
||||||
public boolean setBiome(int x, int z, String biome) {
|
|
||||||
return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));
|
return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +112,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
|
||||||
public boolean setBlock(int x, int y, int z, int id, int data) {
|
|
||||||
if (this.result == null) {
|
if (this.result == null) {
|
||||||
this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data));
|
this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data));
|
||||||
return true;
|
return true;
|
||||||
@ -136,8 +134,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||||
public PlotBlock getBlock(int x, int y, int z) {
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
MaterialData md = cd.getTypeAndData(x, y, z);
|
MaterialData md = cd.getTypeAndData(x, y, z);
|
||||||
@ -167,23 +164,21 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return chunk == null ? cz : chunk.getZ();
|
return chunk == null ? cz : chunk.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getWorld() {
|
||||||
public String getWorld() {
|
|
||||||
return chunk == null ? world : chunk.getWorld().getName();
|
return chunk == null ? world : chunk.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getMax() {
|
||||||
public Location getMax() {
|
|
||||||
return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getMin() {
|
||||||
public Location getMin() {
|
|
||||||
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
|
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenChunk clone() {
|
public GenChunk clone() {
|
||||||
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
|
GenChunk toReturn =
|
||||||
|
new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
|
||||||
if (this.result != null) {
|
if (this.result != null) {
|
||||||
for (int i = 0; i < this.result.length; i++) {
|
for (int i = 0; i < this.result.length; i++) {
|
||||||
short[] matrix = this.result[i];
|
short[] matrix = this.result[i];
|
||||||
|
@ -5,8 +5,7 @@ import java.io.FilenameFilter;
|
|||||||
|
|
||||||
public class DatFileFilter implements FilenameFilter {
|
public class DatFileFilter implements FilenameFilter {
|
||||||
|
|
||||||
@Override
|
@Override public boolean accept(File dir, String name) {
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith(".dat");
|
return name.endsWith(".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,23 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class DefaultUUIDWrapper extends UUIDWrapper {
|
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
public UUID getUUID(PlotPlayer player) {
|
|
||||||
return ((BukkitPlayer) player).player.getUniqueId();
|
return ((BukkitPlayer) player).player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
public UUID getUUID(OfflinePlotPlayer player) {
|
|
||||||
return player.getUUID();
|
return player.getUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(String name) {
|
||||||
public UUID getUUID(String name) {
|
|
||||||
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
|
||||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
for (int i = 0; i < ops.length; i++) {
|
for (int i = 0; i < ops.length; i++) {
|
||||||
@ -42,8 +37,7 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
|||||||
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.util.NbtFactory;
|
import com.plotsquared.bukkit.util.NbtFactory;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -24,9 +27,6 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
@ -34,8 +34,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
super(wrapper);
|
super(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean startCaching(Runnable whenDone) {
|
||||||
public boolean startCaching(Runnable whenDone) {
|
|
||||||
return super.startCaching(whenDone) && cache(whenDone);
|
return super.startCaching(whenDone) && cache(whenDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +48,13 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
world = worlds.get(0).getName();
|
world = worlds.get(0).getName();
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
||||||
File uuidFile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
File uuidFile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (uuidFile.exists()) {
|
if (uuidFile.exists()) {
|
||||||
try {
|
try {
|
||||||
List<String> lines = Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
|
List<String> lines =
|
||||||
|
Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
try {
|
try {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
@ -65,7 +64,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
String name = split[0];
|
String name = split[0];
|
||||||
if (name.isEmpty() || (name.length() > 16) || !StringMan.isAlphanumericUnd(name)) {
|
if (name.isEmpty() || (name.length() > 16) || !StringMan
|
||||||
|
.isAlphanumericUnd(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
@ -81,11 +81,13 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd =
|
||||||
|
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
||||||
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||||
PS.debug("&aFast mode UUID caching enabled!");
|
PS.debug("&aFast mode UUID caching enabled!");
|
||||||
File playerDataFolder = new File(container, world + File.separator + "playerdata");
|
File playerDataFolder =
|
||||||
|
new File(container, world + File.separator + "playerdata");
|
||||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||||
boolean check = all.isEmpty();
|
boolean check = all.isEmpty();
|
||||||
if (dat != null) {
|
if (dat != null) {
|
||||||
@ -95,11 +97,15 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if (check || all.remove(uuid)) {
|
if (check || all.remove(uuid)) {
|
||||||
File file = new File(playerDataFolder, current);
|
File file = new File(playerDataFolder, current);
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory
|
||||||
|
.fromStream(new FileInputStream(file),
|
||||||
|
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
if (!compound.containsKey("bukkit")) {
|
if (!compound.containsKey("bukkit")) {
|
||||||
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
|
PS.debug("ERROR: Player data (" + uuid.toString()
|
||||||
|
+ ".dat) does not contain the the key \"bukkit\"");
|
||||||
} else {
|
} else {
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit =
|
||||||
|
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
long first = (long) bukkit.get("firstPlayed");
|
long first = (long) bukkit.get("firstPlayed");
|
||||||
@ -123,7 +129,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
PS.debug("Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
PS.debug("Failed to cache: " + all.size()
|
||||||
|
+ " uuids - slowly processing all files");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashSet<String> worlds = Sets.newHashSet(world, "world");
|
HashSet<String> worlds = Sets.newHashSet(world, "world");
|
||||||
@ -132,7 +139,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
File playerDataFolder = null;
|
File playerDataFolder = null;
|
||||||
for (String worldName : worlds) {
|
for (String worldName : worlds) {
|
||||||
// Getting UUIDs
|
// Getting UUIDs
|
||||||
playerDataFolder = new File(container, worldName + File.separator + "playerdata");
|
playerDataFolder =
|
||||||
|
new File(container, worldName + File.separator + "playerdata");
|
||||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||||
if ((dat != null) && (dat.length != 0)) {
|
if ((dat != null) && (dat.length != 0)) {
|
||||||
for (String current : dat) {
|
for (String current : dat) {
|
||||||
@ -158,22 +166,28 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
try {
|
try {
|
||||||
File file = new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
|
File file =
|
||||||
|
new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory
|
||||||
|
.fromStream(new FileInputStream(file),
|
||||||
|
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
if (!compound.containsKey("bukkit")) {
|
if (!compound.containsKey("bukkit")) {
|
||||||
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
|
PS.debug("ERROR: Player data (" + uuid.toString()
|
||||||
|
+ ".dat) does not contain the the key \"bukkit\"");
|
||||||
} else {
|
} else {
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit =
|
||||||
|
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
StringWrapper wrap = new StringWrapper(name);
|
StringWrapper wrap = new StringWrapper(name);
|
||||||
if (!toAdd.containsKey(wrap)) {
|
if (!toAdd.containsKey(wrap)) {
|
||||||
long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
long first = (long) bukkit.get("firstPlayed");
|
long first = (long) bukkit.get("firstPlayed");
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase().equals(name)) {
|
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
|
||||||
|
.equals(name)) {
|
||||||
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
} else {
|
} else {
|
||||||
long most = (long) compound.get("UUIDMost");
|
long most = (long) compound.get("UUIDMost");
|
||||||
@ -199,7 +213,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getUUIDMap().isEmpty()) {
|
if (getUUIDMap().isEmpty()) {
|
||||||
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper.getOfflinePlayers()) {
|
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper
|
||||||
|
.getOfflinePlayers()) {
|
||||||
long last = op.getLastPlayed();
|
long last = op.getLastPlayed();
|
||||||
if (last != 0) {
|
if (last != 0) {
|
||||||
String name = op.getName();
|
String name = op.getName();
|
||||||
@ -223,11 +238,9 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
TaskManager.runTask(ifFetch);
|
TaskManager.runTask(ifFetch);
|
||||||
}
|
}
|
||||||
|
@ -9,24 +9,24 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
public UUID getUUID(PlotPlayer player) {
|
return UUID.nameUUIDFromBytes(
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
public UUID getUUID(OfflinePlotPlayer player) {
|
return UUID.nameUUIDFromBytes(
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(OfflinePlayer player) {
|
||||||
public UUID getUUID(OfflinePlayer player) {
|
return UUID.nameUUIDFromBytes(
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(String name) {
|
||||||
public UUID getUUID(String name) {
|
return UUID
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,22 +32,22 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
public UUID getUUID(PlotPlayer player) {
|
return UUID
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
public UUID getUUID(OfflinePlotPlayer player) {
|
return UUID
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID(OfflinePlayer player) {
|
public UUID getUUID(OfflinePlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
return UUID
|
||||||
|
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
|
||||||
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||||
String name = null;
|
String name = null;
|
||||||
if (map.containsKey(uuid)) {
|
if (map.containsKey(uuid)) {
|
||||||
@ -77,7 +77,8 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
if (players instanceof Player[]) {
|
if (players instanceof Player[]) {
|
||||||
return (Player[]) players;
|
return (Player[]) players;
|
||||||
} else {
|
} else {
|
||||||
@SuppressWarnings("unchecked") Collection<? extends Player> p = (Collection<? extends Player>) players;
|
@SuppressWarnings("unchecked") Collection<? extends Player> p =
|
||||||
|
(Collection<? extends Player>) players;
|
||||||
return p.toArray(new Player[p.size()]);
|
return p.toArray(new Player[p.size()]);
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
||||||
@ -88,13 +89,11 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(String name) {
|
||||||
public UUID getUUID(String name) {
|
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
|
||||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
for (int i = 0; i < ops.length; i++) {
|
for (int i = 0; i < ops.length; i++) {
|
||||||
@ -103,8 +102,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,11 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -26,15 +31,12 @@ import java.util.ArrayDeque;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
final int MAX_REQUESTS = 500;
|
final int MAX_REQUESTS = 500;
|
||||||
private final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
private final String PROFILE_URL =
|
||||||
|
"https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
private final int INTERVAL = 12000;
|
private final int INTERVAL = 12000;
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
private final JSONParser jsonParser = new JSONParser();
|
||||||
private final SQLite sqlite;
|
private final SQLite sqlite;
|
||||||
@ -64,20 +66,21 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean startCaching(final Runnable whenDone) {
|
||||||
public boolean startCaching(final Runnable whenDone) {
|
|
||||||
if (!super.startCaching(whenDone)) {
|
if (!super.startCaching(whenDone)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd =
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
|
try (PreparedStatement statement = getConnection()
|
||||||
|
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||||
ResultSet resultSet = statement.executeQuery()) {
|
ResultSet resultSet = statement.executeQuery()) {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
StringWrapper username = new StringWrapper(resultSet.getString("username"));
|
StringWrapper username =
|
||||||
|
new StringWrapper(resultSet.getString("username"));
|
||||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||||
toAdd.put(new StringWrapper(username.value), uuid);
|
toAdd.put(new StringWrapper(username.value), uuid);
|
||||||
}
|
}
|
||||||
@ -96,10 +99,10 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
FileUUIDHandler fileHandler =
|
||||||
|
new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
||||||
fileHandler.startCaching(new Runnable() {
|
fileHandler.startCaching(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
// If the file based UUID handler didn't cache it, then we can't cache offline mode
|
// If the file based UUID handler didn't cache it, then we can't cache offline mode
|
||||||
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
|
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
@ -110,18 +113,24 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
while (!toFetch.isEmpty()) {
|
while (!toFetch.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
for (int i = 0;
|
||||||
|
i < Math.min(500, toFetch.size()); i++) {
|
||||||
UUID uuid = toFetch.pop();
|
UUID uuid = toFetch.pop();
|
||||||
HttpURLConnection connection =
|
HttpURLConnection connection =
|
||||||
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
(HttpURLConnection) new URL(
|
||||||
|
SQLUUIDHandler.this.PROFILE_URL + uuid
|
||||||
|
.toString().replace("-", ""))
|
||||||
.openConnection();
|
.openConnection();
|
||||||
try (InputStream con = connection.getInputStream()) {
|
try (InputStream con = connection
|
||||||
InputStreamReader reader = new InputStreamReader(con);
|
.getInputStream()) {
|
||||||
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
|
InputStreamReader reader =
|
||||||
|
new InputStreamReader(con);
|
||||||
|
JSONObject response =
|
||||||
|
(JSONObject) SQLUUIDHandler.this.jsonParser
|
||||||
|
.parse(reader);
|
||||||
String name = (String) response.get("name");
|
String name = (String) response.get("name");
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
add(new StringWrapper(name), uuid);
|
add(new StringWrapper(name), uuid);
|
||||||
@ -130,7 +139,8 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
PS.debug("Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
PS.debug(
|
||||||
|
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(INTERVAL * 50);
|
Thread.sleep(INTERVAL * 50);
|
||||||
@ -155,15 +165,14 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
PS.debug(C.PREFIX + "UUID for '" + name
|
||||||
PS.debug(C.PREFIX + "UUID for '" + name + "' was null. We'll cache this from the Mojang servers!");
|
+ "' was null. We'll cache this from the Mojang servers!");
|
||||||
if (ifFetch == null) {
|
if (ifFetch == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
@ -177,13 +186,14 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
stream.write(body.getBytes());
|
stream.write(body.getBytes());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
stream.close();
|
stream.close();
|
||||||
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser
|
||||||
|
.parse(new InputStreamReader(connection.getInputStream()));
|
||||||
JSONObject jsonProfile = (JSONObject) array.get(0);
|
JSONObject jsonProfile = (JSONObject) array.get(0);
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = (String) jsonProfile.get("id");
|
||||||
String name = (String) jsonProfile.get("name");
|
String name = (String) jsonProfile.get("name");
|
||||||
ifFetch.value = UUID.fromString(
|
ifFetch.value = UUID.fromString(
|
||||||
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16) + '-' + id.substring(16, 20) + '-' + id
|
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
|
||||||
.substring(20, 32));
|
+ '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -192,8 +202,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void handleShutdown() {
|
||||||
public void handleShutdown() {
|
|
||||||
super.handleShutdown();
|
super.handleShutdown();
|
||||||
try {
|
try {
|
||||||
getConnection().close();
|
getConnection().close();
|
||||||
@ -202,14 +211,13 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean add(final StringWrapper name, final UUID uuid) {
|
||||||
public boolean add(final StringWrapper name, final UUID uuid) {
|
|
||||||
// Ignoring duplicates
|
// Ignoring duplicates
|
||||||
if (super.add(name, uuid)) {
|
if (super.add(name, uuid)) {
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
try (PreparedStatement statement = getConnection().prepareStatement(
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
"REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.setString(2, name.toString());
|
statement.setString(2, name.toString());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
@ -227,13 +235,12 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
/**
|
/**
|
||||||
* This is useful for name changes
|
* This is useful for name changes
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public void rename(final UUID uuid, final StringWrapper name) {
|
||||||
public void rename(final UUID uuid, final StringWrapper name) {
|
|
||||||
super.rename(uuid, name);
|
super.rename(uuid, name);
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
try (PreparedStatement statement = getConnection()
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
.prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
||||||
statement.setString(1, name.value);
|
statement.setString(1, name.value);
|
||||||
statement.setString(2, uuid.toString());
|
statement.setString(2, uuid.toString());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
@ -8,11 +8,11 @@ import java.util.Map;
|
|||||||
public interface Configuration extends ConfigurationSection {
|
public interface Configuration extends ConfigurationSection {
|
||||||
/**
|
/**
|
||||||
* Sets the default value of the given path as provided.
|
* Sets the default value of the given path as provided.
|
||||||
*
|
* <p>
|
||||||
* <p>If no source {@link Configuration} was provided as a default
|
* <p>If no source {@link Configuration} was provided as a default
|
||||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||||
* hold the new default value.</p>
|
* hold the new default value.</p>
|
||||||
*
|
* <p>
|
||||||
* <p>If value is null, the value will be removed from the default
|
* <p>If value is null, the value will be removed from the default
|
||||||
* Configuration source.</p>
|
* Configuration source.</p>
|
||||||
*
|
*
|
||||||
@ -24,7 +24,7 @@ public interface Configuration extends ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default values of the given paths as provided.
|
* Sets the default values of the given paths as provided.
|
||||||
*
|
* <p>
|
||||||
* <p>If no source {@link Configuration} was provided as a default
|
* <p>If no source {@link Configuration} was provided as a default
|
||||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||||
* hold the new default values.</p>
|
* hold the new default values.</p>
|
||||||
@ -36,11 +36,11 @@ public interface Configuration extends ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default values of the given paths as provided.
|
* Sets the default values of the given paths as provided.
|
||||||
*
|
* <p>
|
||||||
* <p>If no source {@link Configuration} was provided as a default
|
* <p>If no source {@link Configuration} was provided as a default
|
||||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||||
* hold the new default value.</p>
|
* hold the new default value.</p>
|
||||||
*
|
* <p>
|
||||||
* <p>This method will not hold a reference to the specified Configuration,
|
* <p>This method will not hold a reference to the specified Configuration,
|
||||||
* nor will it automatically update if that Configuration ever changes. If
|
* nor will it automatically update if that Configuration ever changes. If
|
||||||
* you check this, you should set the default source with {@link
|
* you check this, you should set the default source with {@link
|
||||||
@ -53,7 +53,7 @@ public interface Configuration extends ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source {@link Configuration} for this configuration.
|
* Gets the source {@link Configuration} for this configuration.
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* If no configuration source was set, but default values were added, then
|
* If no configuration source was set, but default values were added, then
|
||||||
* a {@link MemoryConfiguration} will be returned. If no source was set
|
* a {@link MemoryConfiguration} will be returned. If no source was set
|
||||||
@ -65,7 +65,7 @@ public interface Configuration extends ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the source of all default values for this {@link Configuration}.
|
* Sets the source of all default values for this {@link Configuration}.
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* If a previous source was set, or previous default values were defined,
|
* If a previous source was set, or previous default values were defined,
|
||||||
* then they will not be copied to the new source.</p>
|
* then they will not be copied to the new source.</p>
|
||||||
@ -77,7 +77,7 @@ public interface Configuration extends ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link ConfigurationOptions} for this {@link Configuration}.
|
* Gets the {@link ConfigurationOptions} for this {@link Configuration}.
|
||||||
*
|
* <p>
|
||||||
* <p>All setters through this method are chainable.</p>
|
* <p>All setters through this method are chainable.</p>
|
||||||
*
|
*
|
||||||
* @return Options for this configuration
|
* @return Options for this configuration
|
||||||
|
@ -25,7 +25,7 @@ class ConfigurationOptions {
|
|||||||
/**
|
/**
|
||||||
* Gets the char that will be used to separate {@link
|
* Gets the char that will be used to separate {@link
|
||||||
* ConfigurationSection}s.
|
* ConfigurationSection}s.
|
||||||
*
|
* <p>
|
||||||
* <p>This value does not affect how the {@link Configuration} is stored,
|
* <p>This value does not affect how the {@link Configuration} is stored,
|
||||||
* only in how you access the data. The default value is '.'.
|
* only in how you access the data. The default value is '.'.
|
||||||
*
|
*
|
||||||
@ -38,7 +38,7 @@ class ConfigurationOptions {
|
|||||||
/**
|
/**
|
||||||
* Sets the char that will be used to separate {@link
|
* Sets the char that will be used to separate {@link
|
||||||
* ConfigurationSection}s.
|
* ConfigurationSection}s.
|
||||||
*
|
* <p>
|
||||||
* <p>This value does not affect how the {@link Configuration} is stored,
|
* <p>This value does not affect how the {@link Configuration} is stored,
|
||||||
* only in how you access the data. The default value is '.'.
|
* only in how you access the data. The default value is '.'.
|
||||||
*
|
*
|
||||||
@ -53,7 +53,7 @@ class ConfigurationOptions {
|
|||||||
/**
|
/**
|
||||||
* Checks if the {@link Configuration} should copy values from its default
|
* Checks if the {@link Configuration} should copy values from its default
|
||||||
* {@link Configuration} directly.
|
* {@link Configuration} directly.
|
||||||
*
|
* <p>
|
||||||
* <p>If this is true, all values in the default Configuration will be
|
* <p>If this is true, all values in the default Configuration will be
|
||||||
* directly copied, making it impossible to distinguish between values
|
* directly copied, making it impossible to distinguish between values
|
||||||
* that were set and values that are provided by default. As a result,
|
* that were set and values that are provided by default. As a result,
|
||||||
@ -71,7 +71,7 @@ class ConfigurationOptions {
|
|||||||
/**
|
/**
|
||||||
* Sets if the {@link Configuration} should copy values from its default
|
* Sets if the {@link Configuration} should copy values from its default
|
||||||
* {@link Configuration} directly.
|
* {@link Configuration} directly.
|
||||||
*
|
* <p>
|
||||||
* <p>If this is true, all values in the default Configuration will be
|
* <p>If this is true, all values in the default Configuration will be
|
||||||
* directly copied, making it impossible to distinguish between values
|
* directly copied, making it impossible to distinguish between values
|
||||||
* that were set and values that are provided by default. As a result,
|
* that were set and values that are provided by default. As a result,
|
||||||
|
@ -11,11 +11,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a set containing all keys in this section.
|
* Gets a set containing all keys in this section.
|
||||||
*
|
* <p>
|
||||||
* <p>If deep is set to true, then this will contain all the keys within any
|
* <p>If deep is set to true, then this will contain all the keys within any
|
||||||
* child {@link ConfigurationSection}s (and their children, etc). These
|
* child {@link ConfigurationSection}s (and their children, etc). These
|
||||||
* will be in a valid path notation for you to use.
|
* will be in a valid path notation for you to use.
|
||||||
*
|
* <p>
|
||||||
* <p>If deep is set to false, then this will contain only the keys of any
|
* <p>If deep is set to false, then this will contain only the keys of any
|
||||||
* direct children, and not their own children.
|
* direct children, and not their own children.
|
||||||
*
|
*
|
||||||
@ -27,11 +27,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a Map containing all keys and their values for this section.
|
* Gets a Map containing all keys and their values for this section.
|
||||||
*
|
* <p>
|
||||||
* <p>If deep is set to true, then this will contain all the keys and values
|
* <p>If deep is set to true, then this will contain all the keys and values
|
||||||
* within any child {@link ConfigurationSection}s (and their children,
|
* within any child {@link ConfigurationSection}s (and their children,
|
||||||
* etc). These keys will be in a valid path notation for you to use.
|
* etc). These keys will be in a valid path notation for you to use.
|
||||||
*
|
* <p>
|
||||||
* <p>If deep is set to false, then this will contain only the keys and
|
* <p>If deep is set to false, then this will contain only the keys and
|
||||||
* values of any direct children, and not their own children.
|
* values of any direct children, and not their own children.
|
||||||
*
|
*
|
||||||
@ -43,7 +43,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this {@link ConfigurationSection} contains the given path.
|
* Checks if this {@link ConfigurationSection} contains the given path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the value for the requested path does not exist but a default value
|
* <p>If the value for the requested path does not exist but a default value
|
||||||
* has been specified, this will return true.
|
* has been specified, this will return true.
|
||||||
*
|
*
|
||||||
@ -57,7 +57,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Checks if this {@link ConfigurationSection} has a value set for the
|
* Checks if this {@link ConfigurationSection} has a value set for the
|
||||||
* given path.
|
* given path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the value for the requested path does not exist but a default value
|
* <p>If the value for the requested path does not exist but a default value
|
||||||
* has been specified, this will still return false.
|
* has been specified, this will still return false.
|
||||||
*
|
*
|
||||||
@ -71,14 +71,14 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the path of this {@link ConfigurationSection} from its root {@link
|
* Gets the path of this {@link ConfigurationSection} from its root {@link
|
||||||
* Configuration}.
|
* Configuration}.
|
||||||
*
|
* <p>
|
||||||
* <p>For any {@link Configuration} themselves, this will return an empty
|
* <p>For any {@link Configuration} themselves, this will return an empty
|
||||||
* string.
|
* string.
|
||||||
*
|
* <p>
|
||||||
* <p>If the section is no longer contained within its root for any reason,
|
* <p>If the section is no longer contained within its root for any reason,
|
||||||
* such as being replaced with a different value,
|
* such as being replaced with a different value,
|
||||||
* this may return {@code null}.
|
* this may return {@code null}.
|
||||||
*
|
* <p>
|
||||||
* <p>To retrieve the single name of this section, that is, the final part
|
* <p>To retrieve the single name of this section, that is, the final part
|
||||||
* of the path returned by this method, you may use {@link #getName()}.
|
* of the path returned by this method, you may use {@link #getName()}.
|
||||||
*
|
*
|
||||||
@ -89,7 +89,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the name of this individual {@link ConfigurationSection}, in the
|
* Gets the name of this individual {@link ConfigurationSection}, in the
|
||||||
* path.
|
* path.
|
||||||
*
|
* <p>
|
||||||
* <p>This will always be the final part of {@link #getCurrentPath()}, unless
|
* <p>This will always be the final part of {@link #getCurrentPath()}, unless
|
||||||
* the section is orphaned.
|
* the section is orphaned.
|
||||||
*
|
*
|
||||||
@ -100,10 +100,10 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the root {@link Configuration} that contains this {@link
|
* Gets the root {@link Configuration} that contains this {@link
|
||||||
* ConfigurationSection}
|
* ConfigurationSection}
|
||||||
*
|
* <p>
|
||||||
* <p>For any {@link Configuration} themselves, this will return its own
|
* <p>For any {@link Configuration} themselves, this will return its own
|
||||||
* object.
|
* object.
|
||||||
*
|
* <p>
|
||||||
* <p>If the section is no longer contained within its root for any reason,
|
* <p>If the section is no longer contained within its root for any reason,
|
||||||
* such as being replaced with a different value,
|
* such as being replaced with a different value,
|
||||||
* this may return {@code null}.
|
* this may return {@code null}.
|
||||||
@ -115,10 +115,10 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the parent {@link ConfigurationSection} that directly contains
|
* Gets the parent {@link ConfigurationSection} that directly contains
|
||||||
* this {@link ConfigurationSection}.
|
* this {@link ConfigurationSection}.
|
||||||
*
|
* <p>
|
||||||
* <p>For any {@link Configuration} themselves, this will return
|
* <p>For any {@link Configuration} themselves, this will return
|
||||||
* {@code null}.
|
* {@code null}.
|
||||||
*
|
* <p>
|
||||||
* <p>If the section is no longer contained within its parent for any
|
* <p>If the section is no longer contained within its parent for any
|
||||||
* reason, such as being replaced with a different value, this may
|
* reason, such as being replaced with a different value, this may
|
||||||
* return {@code null}.
|
* return {@code null}.
|
||||||
@ -129,7 +129,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested Object by path.
|
* Gets the requested Object by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the Object does not exist but a default value has been specified,
|
* <p>If the Object does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the Object does not exist and no
|
* this will return the default value. If the Object does not exist and no
|
||||||
* default value was specified, this will return {@code null}.
|
* default value was specified, this will return {@code null}.
|
||||||
@ -142,7 +142,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested Object by path, returning a default value if not
|
* Gets the requested Object by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the Object does not exist then the specified default value will
|
* <p>If the Object does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -155,10 +155,10 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the specified path to the given value.
|
* Sets the specified path to the given value.
|
||||||
*
|
* <p>
|
||||||
* <p>If value is {@code null}, the entry will be removed. Any
|
* <p>If value is {@code null}, the entry will be removed. Any
|
||||||
* existing entry will be replaced, regardless of what the new value is.
|
* existing entry will be replaced, regardless of what the new value is.
|
||||||
*
|
* <p>
|
||||||
* <p>Some implementations may have limitations on what you may store. See
|
* <p>Some implementations may have limitations on what you may store. See
|
||||||
* their individual javadoc for details. No implementations should allow
|
* their individual javadoc for details. No implementations should allow
|
||||||
* you to store {@link Configuration}s or {@link ConfigurationSection}s,
|
* you to store {@link Configuration}s or {@link ConfigurationSection}s,
|
||||||
@ -171,7 +171,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty {@link ConfigurationSection} at the specified path.
|
* Creates an empty {@link ConfigurationSection} at the specified path.
|
||||||
*
|
* <p>
|
||||||
* <p>Any value that was previously set at this path will be overwritten. If
|
* <p>Any value that was previously set at this path will be overwritten. If
|
||||||
* the previous value was itself a {@link ConfigurationSection}, it will
|
* the previous value was itself a {@link ConfigurationSection}, it will
|
||||||
* be orphaned.
|
* be orphaned.
|
||||||
@ -184,7 +184,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Creates a {@link ConfigurationSection} at the specified path, with
|
* Creates a {@link ConfigurationSection} at the specified path, with
|
||||||
* specified values.
|
* specified values.
|
||||||
*
|
* <p>
|
||||||
* <p>Any value that was previously set at this path will be overwritten. If
|
* <p>Any value that was previously set at this path will be overwritten. If
|
||||||
* the previous value was itself a {@link ConfigurationSection}, it will
|
* the previous value was itself a {@link ConfigurationSection}, it will
|
||||||
* be orphaned.
|
* be orphaned.
|
||||||
@ -199,7 +199,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested String by path.
|
* Gets the requested String by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the String does not exist but a default value has been specified,
|
* <p>If the String does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the String does not exist and no
|
* this will return the default value. If the String does not exist and no
|
||||||
* default value was specified, this will return {@code null}.
|
* default value was specified, this will return {@code null}.
|
||||||
@ -212,7 +212,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested String by path, returning a default value if not
|
* Gets the requested String by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the String does not exist then the specified default value will
|
* <p>If the String does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -226,7 +226,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a String.
|
* Checks if the specified path is a String.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a String, this will return false. If
|
* <p>If the path exists but is not a String, this will return false. If
|
||||||
* the path does not exist, this will return false. If the path does not
|
* the path does not exist, this will return false. If the path does not
|
||||||
* exist but a default value has been specified, this will check if that
|
* exist but a default value has been specified, this will check if that
|
||||||
@ -239,7 +239,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested int by path.
|
* Gets the requested int by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the int does not exist but a default value has been specified, this
|
* <p>If the int does not exist but a default value has been specified, this
|
||||||
* will return the default value. If the int does not exist and no default
|
* will return the default value. If the int does not exist and no default
|
||||||
* value was specified, this will return 0.
|
* value was specified, this will return 0.
|
||||||
@ -251,7 +251,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested int by path, returning a default value if not found.
|
* Gets the requested int by path, returning a default value if not found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the int does not exist then the specified default value will
|
* <p>If the int does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -265,7 +265,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is an int.
|
* Checks if the specified path is an int.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a int, this will return false. If the
|
* <p>If the path exists but is not a int, this will return false. If the
|
||||||
* path does not exist, this will return false. If the path does not exist
|
* path does not exist, this will return false. If the path does not exist
|
||||||
* but a default value has been specified, this will check if that default
|
* but a default value has been specified, this will check if that default
|
||||||
@ -278,7 +278,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested boolean by path.
|
* Gets the requested boolean by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the boolean does not exist but a default value has been specified,
|
* <p>If the boolean does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the boolean does not exist and
|
* this will return the default value. If the boolean does not exist and
|
||||||
* no default value was specified, this will return false.
|
* no default value was specified, this will return false.
|
||||||
@ -291,7 +291,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested boolean by path, returning a default value if not
|
* Gets the requested boolean by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the boolean does not exist then the specified default value will
|
* <p>If the boolean does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -305,7 +305,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a boolean.
|
* Checks if the specified path is a boolean.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a boolean, this will return false. If the
|
* <p>If the path exists but is not a boolean, this will return false. If the
|
||||||
* path does not exist, this will return false. If the path does not exist
|
* path does not exist, this will return false. If the path does not exist
|
||||||
* but a default value has been specified, this will check if that default
|
* but a default value has been specified, this will check if that default
|
||||||
@ -318,7 +318,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested double by path.
|
* Gets the requested double by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the double does not exist but a default value has been specified,
|
* <p>If the double does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the double does not exist and no
|
* this will return the default value. If the double does not exist and no
|
||||||
* default value was specified, this will return 0.
|
* default value was specified, this will return 0.
|
||||||
@ -331,7 +331,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested double by path, returning a default value if not
|
* Gets the requested double by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the double does not exist then the specified default value will
|
* <p>If the double does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -345,7 +345,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a double.
|
* Checks if the specified path is a double.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a double, this will return false. If the
|
* <p>If the path exists but is not a double, this will return false. If the
|
||||||
* path does not exist, this will return false. If the path does not exist
|
* path does not exist, this will return false. If the path does not exist
|
||||||
* but a default value has been specified, this will check if that default
|
* but a default value has been specified, this will check if that default
|
||||||
@ -358,7 +358,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested long by path.
|
* Gets the requested long by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the long does not exist but a default value has been specified, this
|
* <p>If the long does not exist but a default value has been specified, this
|
||||||
* will return the default value. If the long does not exist and no
|
* will return the default value. If the long does not exist and no
|
||||||
* default value was specified, this will return 0.
|
* default value was specified, this will return 0.
|
||||||
@ -371,7 +371,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested long by path, returning a default value if not
|
* Gets the requested long by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the long does not exist then the specified default value will
|
* <p>If the long does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -385,7 +385,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a long.
|
* Checks if the specified path is a long.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a long, this will return false. If the
|
* <p>If the path exists but is not a long, this will return false. If the
|
||||||
* path does not exist, this will return false. If the path does not exist
|
* path does not exist, this will return false. If the path does not exist
|
||||||
* but a default value has been specified, this will check if that default
|
* but a default value has been specified, this will check if that default
|
||||||
@ -400,7 +400,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List by path.
|
* Gets the requested List by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified, this
|
* <p>If the List does not exist but a default value has been specified, this
|
||||||
* will return the default value. If the List does not exist and no
|
* will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return null.
|
* default value was specified, this will return null.
|
||||||
@ -413,7 +413,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the requested List by path, returning a default value if not
|
* Gets the requested List by path, returning a default value if not
|
||||||
* found.
|
* found.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist then the specified default value will
|
* <p>If the List does not exist then the specified default value will
|
||||||
* returned regardless of if a default has been identified in the root
|
* returned regardless of if a default has been identified in the root
|
||||||
* {@link Configuration}.
|
* {@link Configuration}.
|
||||||
@ -427,7 +427,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a List.
|
* Checks if the specified path is a List.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a List, this will return false. If the
|
* <p>If the path exists but is not a List, this will return false. If the
|
||||||
* path does not exist, this will return false. If the path does not exist
|
* path does not exist, this will return false. If the path does not exist
|
||||||
* but a default value has been specified, this will check if that default
|
* but a default value has been specified, this will check if that default
|
||||||
@ -440,11 +440,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of String by path.
|
* Gets the requested List of String by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a String if possible,
|
* <p>This method will attempt to cast any values into a String if possible,
|
||||||
* but may miss any values out if they are not compatible.
|
* but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -455,11 +455,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Integer by path.
|
* Gets the requested List of Integer by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Integer if
|
* <p>This method will attempt to cast any values into a Integer if
|
||||||
* possible, but may miss any values out if they are not compatible.
|
* possible, but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -470,11 +470,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Boolean by path.
|
* Gets the requested List of Boolean by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Boolean if
|
* <p>This method will attempt to cast any values into a Boolean if
|
||||||
* possible, but may miss any values out if they are not compatible.
|
* possible, but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -485,11 +485,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Double by path.
|
* Gets the requested List of Double by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Double if possible,
|
* <p>This method will attempt to cast any values into a Double if possible,
|
||||||
* but may miss any values out if they are not compatible.
|
* but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -500,11 +500,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Float by path.
|
* Gets the requested List of Float by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Float if possible,
|
* <p>This method will attempt to cast any values into a Float if possible,
|
||||||
* but may miss any values out if they are not compatible.
|
* but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -515,11 +515,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Long by path.
|
* Gets the requested List of Long by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Long if possible,
|
* <p>This method will attempt to cast any values into a Long if possible,
|
||||||
* but may miss any values out if they are not compatible.
|
* but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -530,11 +530,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Byte by path.
|
* Gets the requested List of Byte by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Byte if possible,
|
* <p>This method will attempt to cast any values into a Byte if possible,
|
||||||
* but may miss any values out if they are not compatible.
|
* but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -545,11 +545,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Character by path.
|
* Gets the requested List of Character by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Character if
|
* <p>This method will attempt to cast any values into a Character if
|
||||||
* possible, but may miss any values out if they are not compatible.
|
* possible, but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -560,11 +560,11 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Short by path.
|
* Gets the requested List of Short by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will attempt to cast any values into a Short if
|
* <p>This method will attempt to cast any values into a Short if
|
||||||
* possible, but may miss any values out if they are not compatible.
|
* possible, but may miss any values out if they are not compatible.
|
||||||
*
|
*
|
||||||
@ -575,7 +575,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested List of Maps by path.
|
* Gets the requested List of Maps by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the List does not exist but a default value has been specified,
|
* <p>If the List does not exist but a default value has been specified,
|
||||||
* this will return the default value. If the List does not exist and no
|
* this will return the default value. If the List does not exist and no
|
||||||
* default value was specified, this will return an empty List.
|
* default value was specified, this will return an empty List.
|
||||||
@ -589,7 +589,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the requested ConfigurationSection by path.
|
* Gets the requested ConfigurationSection by path.
|
||||||
*
|
* <p>
|
||||||
* <p>If the ConfigurationSection does not exist but a default value has
|
* <p>If the ConfigurationSection does not exist but a default value has
|
||||||
* been specified, this will return the default value. If the
|
* been specified, this will return the default value. If the
|
||||||
* ConfigurationSection does not exist and no default value was specified,
|
* ConfigurationSection does not exist and no default value was specified,
|
||||||
@ -602,7 +602,7 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified path is a ConfigurationSection.
|
* Checks if the specified path is a ConfigurationSection.
|
||||||
*
|
* <p>
|
||||||
* <p>If the path exists but is not a ConfigurationSection, this will return
|
* <p>If the path exists but is not a ConfigurationSection, this will return
|
||||||
* false. If the path does not exist, this will return false. If the path
|
* false. If the path does not exist, this will return false. If the path
|
||||||
* does not exist but a default value has been specified, this will check
|
* does not exist but a default value has been specified, this will check
|
||||||
@ -617,7 +617,7 @@ public interface ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Gets the equivalent {@link ConfigurationSection} from the default
|
* Gets the equivalent {@link ConfigurationSection} from the default
|
||||||
* {@link Configuration} defined in {@link #getRoot()}.
|
* {@link Configuration} defined in {@link #getRoot()}.
|
||||||
*
|
* <p>
|
||||||
* <p>If the root contains no defaults, or the defaults doesn't contain a
|
* <p>If the root contains no defaults, or the defaults doesn't contain a
|
||||||
* value for this path, or the value at this path is not a {@link
|
* value for this path, or the value at this path is not a {@link
|
||||||
* ConfigurationSection} then this will return {@code null}.
|
* ConfigurationSection} then this will return {@code null}.
|
||||||
@ -628,14 +628,14 @@ public interface ConfigurationSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default value in the root at the given path as provided.
|
* Sets the default value in the root at the given path as provided.
|
||||||
*
|
* <p>
|
||||||
* <p>If no source {@link Configuration} was provided as a default
|
* <p>If no source {@link Configuration} was provided as a default
|
||||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||||
* hold the new default value.
|
* hold the new default value.
|
||||||
*
|
* <p>
|
||||||
* <p>If value is {@code null}, the value will be removed from the
|
* <p>If value is {@code null}, the value will be removed from the
|
||||||
* default Configuration source.
|
* default Configuration source.
|
||||||
*
|
* <p>
|
||||||
* <p>If the value as returned by {@link #getDefaultSection()} is
|
* <p>If the value as returned by {@link #getDefaultSection()} is
|
||||||
* {@code null}, then this will create a new section at the path,
|
* {@code null}, then this will create a new section at the path,
|
||||||
* replacing anything that may have existed there previously.
|
* replacing anything that may have existed there previously.
|
||||||
|
@ -3,14 +3,14 @@ package com.intellectualcrafters.configuration;
|
|||||||
/**
|
/**
|
||||||
* Exception thrown when attempting to load an invalid {@link Configuration}.
|
* Exception thrown when attempting to load an invalid {@link Configuration}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial") public class InvalidConfigurationException extends Exception {
|
||||||
public class InvalidConfigurationException extends Exception {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of InvalidConfigurationException without a
|
* Creates a new instance of InvalidConfigurationException without a
|
||||||
* message or cause.
|
* message or cause.
|
||||||
*/
|
*/
|
||||||
public InvalidConfigurationException() {}
|
public InvalidConfigurationException() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of InvalidConfigurationException with the
|
* Constructs an instance of InvalidConfigurationException with the
|
||||||
|
@ -14,7 +14,8 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
/**
|
/**
|
||||||
* Creates an empty {@link MemoryConfiguration} with no default values.
|
* Creates an empty {@link MemoryConfiguration} with no default values.
|
||||||
*/
|
*/
|
||||||
public MemoryConfiguration() {}
|
public MemoryConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
||||||
@ -27,8 +28,7 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void addDefault(String path, Object value) {
|
||||||
public void addDefault(String path, Object value) {
|
|
||||||
if (this.defaults == null) {
|
if (this.defaults == null) {
|
||||||
this.defaults = new MemoryConfiguration();
|
this.defaults = new MemoryConfiguration();
|
||||||
}
|
}
|
||||||
@ -36,25 +36,21 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
this.defaults.set(path, value);
|
this.defaults.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void addDefaults(Map<String, Object> defaults) {
|
||||||
public void addDefaults(Map<String, Object> defaults) {
|
|
||||||
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
|
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
|
||||||
addDefault(entry.getKey(), entry.getValue());
|
addDefault(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void addDefaults(Configuration defaults) {
|
||||||
public void addDefaults(Configuration defaults) {
|
|
||||||
addDefaults(defaults.getValues(true));
|
addDefaults(defaults.getValues(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Configuration getDefaults() {
|
||||||
public Configuration getDefaults() {
|
|
||||||
return this.defaults;
|
return this.defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setDefaults(Configuration defaults) {
|
||||||
public void setDefaults(Configuration defaults) {
|
|
||||||
if (defaults == null) {
|
if (defaults == null) {
|
||||||
throw new NullPointerException("Defaults may not be null");
|
throw new NullPointerException("Defaults may not be null");
|
||||||
}
|
}
|
||||||
@ -62,13 +58,11 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection getParent() {
|
||||||
public ConfigurationSection getParent() {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public MemoryConfigurationOptions options() {
|
||||||
public MemoryConfigurationOptions options() {
|
|
||||||
if (this.options == null) {
|
if (this.options == null) {
|
||||||
this.options = new MemoryConfigurationOptions(this);
|
this.options = new MemoryConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,16 @@ public class MemoryConfigurationOptions extends ConfigurationOptions {
|
|||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public MemoryConfiguration configuration() {
|
||||||
public MemoryConfiguration configuration() {
|
|
||||||
return (MemoryConfiguration) super.configuration();
|
return (MemoryConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public MemoryConfigurationOptions copyDefaults(boolean value) {
|
||||||
public MemoryConfigurationOptions copyDefaults(boolean value) {
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public MemoryConfigurationOptions pathSeparator(char value) {
|
||||||
public MemoryConfigurationOptions pathSeparator(char value) {
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package com.intellectualcrafters.configuration;
|
package com.intellectualcrafters.configuration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type of {@link ConfigurationSection} that is stored in memory.
|
* A type of {@link ConfigurationSection} that is stored in memory.
|
||||||
@ -21,7 +16,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Creates an empty MemorySection for use as a root {@link Configuration}
|
* Creates an empty MemorySection for use as a root {@link Configuration}
|
||||||
* section.
|
* section.
|
||||||
*
|
* <p>
|
||||||
* <p>Note that calling this without being yourself a {@link Configuration}
|
* <p>Note that calling this without being yourself a {@link Configuration}
|
||||||
* will throw an exception!
|
* will throw an exception!
|
||||||
*
|
*
|
||||||
@ -30,7 +25,8 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
*/
|
*/
|
||||||
protected MemorySection() {
|
protected MemorySection() {
|
||||||
if (!(this instanceof Configuration)) {
|
if (!(this instanceof Configuration)) {
|
||||||
throw new IllegalStateException("Cannot construct a root MemorySection when not a Configuration");
|
throw new IllegalStateException(
|
||||||
|
"Cannot construct a root MemorySection when not a Configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.path = "";
|
this.path = "";
|
||||||
@ -117,7 +113,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Creates a full path to the given {@link ConfigurationSection} from its
|
* Creates a full path to the given {@link ConfigurationSection} from its
|
||||||
* root {@link Configuration}.
|
* root {@link Configuration}.
|
||||||
*
|
* <p>
|
||||||
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
||||||
* only {@link MemorySection}.
|
* only {@link MemorySection}.
|
||||||
*
|
*
|
||||||
@ -132,7 +128,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
/**
|
/**
|
||||||
* Creates a relative path to the given {@link ConfigurationSection} from
|
* Creates a relative path to the given {@link ConfigurationSection} from
|
||||||
* the given relative section.
|
* the given relative section.
|
||||||
*
|
* <p>
|
||||||
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
||||||
* only {@link MemorySection}.
|
* only {@link MemorySection}.
|
||||||
*
|
*
|
||||||
@ -141,7 +137,8 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
* @param relativeTo Section to create the path relative to.
|
* @param relativeTo Section to create the path relative to.
|
||||||
* @return Full path of the section from its root.
|
* @return Full path of the section from its root.
|
||||||
*/
|
*/
|
||||||
public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
|
public static String createPath(ConfigurationSection section, String key,
|
||||||
|
ConfigurationSection relativeTo) {
|
||||||
Configuration root = section.getRoot();
|
Configuration root = section.getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
throw new IllegalStateException("Cannot create path without a root");
|
throw new IllegalStateException("Cannot create path without a root");
|
||||||
@ -149,7 +146,8 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
char separator = root.options().pathSeparator();
|
char separator = root.options().pathSeparator();
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent()) {
|
for (ConfigurationSection parent = section;
|
||||||
|
(parent != null) && (parent != relativeTo); parent = parent.getParent()) {
|
||||||
if (builder.length() > 0) {
|
if (builder.length() > 0) {
|
||||||
builder.insert(0, separator);
|
builder.insert(0, separator);
|
||||||
}
|
}
|
||||||
@ -168,8 +166,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Set<String> getKeys(boolean deep) {
|
||||||
public Set<String> getKeys(boolean deep) {
|
|
||||||
Set<String> result = new LinkedHashSet<>();
|
Set<String> result = new LinkedHashSet<>();
|
||||||
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
@ -186,8 +183,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Map<String, Object> getValues(boolean deep) {
|
||||||
public Map<String, Object> getValues(boolean deep) {
|
|
||||||
Map<String, Object> result = new LinkedHashMap<>();
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
@ -204,13 +200,11 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean contains(String path) {
|
||||||
public boolean contains(String path) {
|
|
||||||
return get(path) != null;
|
return get(path) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isSet(String path) {
|
||||||
public boolean isSet(String path) {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -221,40 +215,35 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return get(path, null) != null;
|
return get(path, null) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getCurrentPath() {
|
||||||
public String getCurrentPath() {
|
|
||||||
return this.fullPath;
|
return this.fullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Configuration getRoot() {
|
||||||
public Configuration getRoot() {
|
|
||||||
return this.root;
|
return this.root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection getParent() {
|
||||||
public ConfigurationSection getParent() {
|
|
||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void addDefault(String path, Object value) {
|
||||||
public void addDefault(String path, Object value) {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
throw new IllegalStateException("Cannot add default without root");
|
throw new IllegalStateException("Cannot add default without root");
|
||||||
}
|
}
|
||||||
if (root == this) {
|
if (root == this) {
|
||||||
throw new UnsupportedOperationException("Unsupported addDefault(String, Object) implementation");
|
throw new UnsupportedOperationException(
|
||||||
|
"Unsupported addDefault(String, Object) implementation");
|
||||||
}
|
}
|
||||||
root.addDefault(createPath(this, path), value);
|
root.addDefault(createPath(this, path), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection getDefaultSection() {
|
||||||
public ConfigurationSection getDefaultSection() {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
Configuration defaults = root == null ? null : root.getDefaults();
|
Configuration defaults = root == null ? null : root.getDefaults();
|
||||||
|
|
||||||
@ -267,8 +256,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void set(String path, Object value) {
|
||||||
public void set(String path, Object value) {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
throw new IllegalStateException("Cannot use section without a root");
|
throw new IllegalStateException("Cannot use section without a root");
|
||||||
@ -302,13 +290,11 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object get(String path) {
|
||||||
public Object get(String path) {
|
|
||||||
return get(path, getDefault(path));
|
return get(path, getDefault(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object get(String path, Object defaultValue) {
|
||||||
public Object get(String path, Object defaultValue) {
|
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
throw new NullPointerException("Path cannot be null");
|
throw new NullPointerException("Path cannot be null");
|
||||||
}
|
}
|
||||||
@ -347,8 +333,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return section.get(key, defaultValue);
|
return section.get(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection createSection(String path) {
|
||||||
public ConfigurationSection createSection(String path) {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
throw new IllegalStateException("Cannot create section without a root");
|
throw new IllegalStateException("Cannot create section without a root");
|
||||||
@ -379,8 +364,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return section.createSection(key);
|
return section.createSection(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection createSection(String path, Map<?, ?> map) {
|
||||||
public ConfigurationSection createSection(String path, Map<?, ?> map) {
|
|
||||||
ConfigurationSection section = createSection(path);
|
ConfigurationSection section = createSection(path);
|
||||||
|
|
||||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
@ -395,14 +379,12 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
@Override
|
@Override public String getString(String path) {
|
||||||
public String getString(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
return getString(path, def != null ? def.toString() : null);
|
return getString(path, def != null ? def.toString() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getString(String path, String def) {
|
||||||
public String getString(String path, String def) {
|
|
||||||
Object val = get(path, def);
|
Object val = get(path, def);
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
return val.toString();
|
return val.toString();
|
||||||
@ -411,32 +393,27 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isString(String path) {
|
||||||
public boolean isString(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof String;
|
return val instanceof String;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getInt(String path) {
|
||||||
public int getInt(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
return getInt(path, toInt(def, 0));
|
return getInt(path, toInt(def, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getInt(String path, int def) {
|
||||||
public int getInt(String path, int def) {
|
|
||||||
Object val = get(path, def);
|
Object val = get(path, def);
|
||||||
return toInt(val, def);
|
return toInt(val, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isInt(String path) {
|
||||||
public boolean isInt(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof Integer;
|
return val instanceof Integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean getBoolean(String path) {
|
||||||
public boolean getBoolean(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
if (def instanceof Boolean) {
|
if (def instanceof Boolean) {
|
||||||
return getBoolean(path, (Boolean) def);
|
return getBoolean(path, (Boolean) def);
|
||||||
@ -445,8 +422,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean getBoolean(String path, boolean defaultValue) {
|
||||||
public boolean getBoolean(String path, boolean defaultValue) {
|
|
||||||
Object val = get(path, defaultValue);
|
Object val = get(path, defaultValue);
|
||||||
if (val instanceof Boolean) {
|
if (val instanceof Boolean) {
|
||||||
return (Boolean) val;
|
return (Boolean) val;
|
||||||
@ -455,69 +431,58 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isBoolean(String path) {
|
||||||
public boolean isBoolean(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof Boolean;
|
return val instanceof Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public double getDouble(String path) {
|
||||||
public double getDouble(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
return getDouble(path, toDouble(def, 0));
|
return getDouble(path, toDouble(def, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public double getDouble(String path, double defaultValue) {
|
||||||
public double getDouble(String path, double defaultValue) {
|
|
||||||
Object val = get(path, defaultValue);
|
Object val = get(path, defaultValue);
|
||||||
return toDouble(val, defaultValue);
|
return toDouble(val, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isDouble(String path) {
|
||||||
public boolean isDouble(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof Double;
|
return val instanceof Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public long getLong(String path) {
|
||||||
public long getLong(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
return getLong(path, toLong(def, 0));
|
return getLong(path, toLong(def, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public long getLong(String path, long def) {
|
||||||
public long getLong(String path, long def) {
|
|
||||||
Object val = get(path, def);
|
Object val = get(path, def);
|
||||||
return toLong(val, def);
|
return toLong(val, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isLong(String path) {
|
||||||
public boolean isLong(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof Long;
|
return val instanceof Long;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Java
|
// Java
|
||||||
@Override
|
@Override public List<?> getList(String path) {
|
||||||
public List<?> getList(String path) {
|
|
||||||
Object def = getDefault(path);
|
Object def = getDefault(path);
|
||||||
return getList(path, def instanceof List ? (List<?>) def : null);
|
return getList(path, def instanceof List ? (List<?>) def : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<?> getList(String path, List<?> def) {
|
||||||
public List<?> getList(String path, List<?> def) {
|
|
||||||
Object val = get(path, def);
|
Object val = get(path, def);
|
||||||
return (List<?>) ((val instanceof List) ? val : def);
|
return (List<?>) ((val instanceof List) ? val : def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isList(String path) {
|
||||||
public boolean isList(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof List;
|
return val instanceof List;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<String> getStringList(String path) {
|
||||||
public List<String> getStringList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
@ -535,8 +500,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Integer> getIntegerList(String path) {
|
||||||
public List<Integer> getIntegerList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
@ -559,8 +523,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Boolean> getBooleanList(String path) {
|
||||||
public List<Boolean> getBooleanList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Boolean> result = new ArrayList<>();
|
List<Boolean> result = new ArrayList<>();
|
||||||
@ -580,8 +543,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Double> getDoubleList(String path) {
|
||||||
public List<Double> getDoubleList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Double> result = new ArrayList<>();
|
List<Double> result = new ArrayList<>();
|
||||||
@ -604,8 +566,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Float> getFloatList(String path) {
|
||||||
public List<Float> getFloatList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Float> result = new ArrayList<>();
|
List<Float> result = new ArrayList<>();
|
||||||
@ -628,8 +589,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Long> getLongList(String path) {
|
||||||
public List<Long> getLongList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Long> result = new ArrayList<>();
|
List<Long> result = new ArrayList<>();
|
||||||
@ -652,8 +612,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Byte> getByteList(String path) {
|
||||||
public List<Byte> getByteList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Byte> result = new ArrayList<>();
|
List<Byte> result = new ArrayList<>();
|
||||||
@ -676,8 +635,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Character> getCharacterList(String path) {
|
||||||
public List<Character> getCharacterList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Character> result = new ArrayList<>();
|
List<Character> result = new ArrayList<>();
|
||||||
@ -699,8 +657,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Short> getShortList(String path) {
|
||||||
public List<Short> getShortList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
|
|
||||||
List<Short> result = new ArrayList<>();
|
List<Short> result = new ArrayList<>();
|
||||||
@ -723,8 +680,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Map<?, ?>> getMapList(String path) {
|
||||||
public List<Map<?, ?>> getMapList(String path) {
|
|
||||||
List<?> list = getList(path);
|
List<?> list = getList(path);
|
||||||
List<Map<?, ?>> result = new ArrayList<>();
|
List<Map<?, ?>> result = new ArrayList<>();
|
||||||
|
|
||||||
@ -737,8 +693,7 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ConfigurationSection getConfigurationSection(String path) {
|
||||||
public ConfigurationSection getConfigurationSection(String path) {
|
|
||||||
Object val = get(path, null);
|
Object val = get(path, null);
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null;
|
return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null;
|
||||||
@ -748,21 +703,15 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
return (val instanceof ConfigurationSection) ? createSection(path) : null;
|
return (val instanceof ConfigurationSection) ? createSection(path) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isConfigurationSection(String path) {
|
||||||
public boolean isConfigurationSection(String path) {
|
|
||||||
Object val = get(path);
|
Object val = get(path);
|
||||||
return val instanceof ConfigurationSection;
|
return val instanceof ConfigurationSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isPrimitiveWrapper(Object input) {
|
protected boolean isPrimitiveWrapper(Object input) {
|
||||||
return (input instanceof Integer)
|
return (input instanceof Integer) || (input instanceof Boolean)
|
||||||
|| (input instanceof Boolean)
|
|| (input instanceof Character) || (input instanceof Byte) || (input instanceof Short)
|
||||||
|| (input instanceof Character)
|
|| (input instanceof Double) || (input instanceof Long) || (input instanceof Float);
|
||||||
|| (input instanceof Byte)
|
|
||||||
|| (input instanceof Short)
|
|
||||||
|| (input instanceof Double)
|
|
||||||
|| (input instanceof Long)
|
|
||||||
|| (input instanceof Float);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object getDefault(String path) {
|
protected Object getDefault(String path) {
|
||||||
@ -792,7 +741,8 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section, boolean deep) {
|
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section,
|
||||||
|
boolean deep) {
|
||||||
if (section instanceof MemorySection) {
|
if (section instanceof MemorySection) {
|
||||||
MemorySection sec = (MemorySection) section;
|
MemorySection sec = (MemorySection) section;
|
||||||
|
|
||||||
@ -814,13 +764,14 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
Configuration root = getRoot();
|
Configuration root = getRoot();
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + null + "']";
|
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + null
|
||||||
|
+ "']";
|
||||||
} else {
|
} else {
|
||||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + root.getClass().getSimpleName() + "']";
|
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + root
|
||||||
|
.getClass().getSimpleName() + "']";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,7 @@ import com.intellectualcrafters.configuration.Configuration;
|
|||||||
import com.intellectualcrafters.configuration.InvalidConfigurationException;
|
import com.intellectualcrafters.configuration.InvalidConfigurationException;
|
||||||
import com.intellectualcrafters.configuration.MemoryConfiguration;
|
import com.intellectualcrafters.configuration.MemoryConfiguration;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +16,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
/**
|
/**
|
||||||
* Creates an empty {@link FileConfiguration} with no default values.
|
* Creates an empty {@link FileConfiguration} with no default values.
|
||||||
*/
|
*/
|
||||||
FileConfiguration() {}
|
FileConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty {@link FileConfiguration} using the specified {@link
|
* Creates an empty {@link FileConfiguration} using the specified {@link
|
||||||
@ -39,11 +31,11 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves this {@link FileConfiguration} to the specified location.
|
* Saves this {@link FileConfiguration} to the specified location.
|
||||||
*
|
* <p>
|
||||||
* <p>If the file does not exist, it will be created. If already exists, it
|
* <p>If the file does not exist, it will be created. If already exists, it
|
||||||
* will be overwritten. If it cannot be overwritten or created, an
|
* will be overwritten. If it cannot be overwritten or created, an
|
||||||
* exception will be thrown.
|
* exception will be thrown.
|
||||||
*
|
* <p>
|
||||||
* <p>This method will save using the system default encoding, or possibly
|
* <p>This method will save using the system default encoding, or possibly
|
||||||
* using UTF8.
|
* using UTF8.
|
||||||
*
|
*
|
||||||
@ -59,7 +51,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
|
|
||||||
String data = saveToString();
|
String data = saveToString();
|
||||||
|
|
||||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file),
|
||||||
|
StandardCharsets.UTF_8)) {
|
||||||
writer.write(data);
|
writer.write(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,11 +66,11 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads this {@link FileConfiguration} from the specified location.
|
* Loads this {@link FileConfiguration} from the specified location.
|
||||||
*
|
* <p>
|
||||||
* <p>All the values contained within this configuration will be removed,
|
* <p>All the values contained within this configuration will be removed,
|
||||||
* leaving only settings and defaults, and the new values will be loaded
|
* leaving only settings and defaults, and the new values will be loaded
|
||||||
* from the given file.
|
* from the given file.
|
||||||
*
|
* <p>
|
||||||
* <p>If the file cannot be loaded for any reason, an exception will be
|
* <p>If the file cannot be loaded for any reason, an exception will be
|
||||||
* thrown.
|
* thrown.
|
||||||
*
|
*
|
||||||
@ -98,7 +91,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads this {@link FileConfiguration} from the specified reader.
|
* Loads this {@link FileConfiguration} from the specified reader.
|
||||||
*
|
* <p>
|
||||||
* <p>All the values contained within this configuration will be removed,
|
* <p>All the values contained within this configuration will be removed,
|
||||||
* leaving only settings and defaults, and the new values will be loaded
|
* leaving only settings and defaults, and the new values will be loaded
|
||||||
* from the given stream.
|
* from the given stream.
|
||||||
@ -112,7 +105,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) {
|
try (BufferedReader input = reader instanceof BufferedReader ?
|
||||||
|
(BufferedReader) reader :
|
||||||
|
new BufferedReader(reader)) {
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = input.readLine()) != null) {
|
while ((line = input.readLine()) != null) {
|
||||||
@ -127,11 +122,11 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
/**
|
/**
|
||||||
* Loads this {@link FileConfiguration} from the specified string, as
|
* Loads this {@link FileConfiguration} from the specified string, as
|
||||||
* opposed to from file.
|
* opposed to from file.
|
||||||
*
|
* <p>
|
||||||
* <p>All the values contained within this configuration will be removed,
|
* <p>All the values contained within this configuration will be removed,
|
||||||
* leaving only settings and defaults, and the new values will be loaded
|
* leaving only settings and defaults, and the new values will be loaded
|
||||||
* from the given string.
|
* from the given string.
|
||||||
*
|
* <p>
|
||||||
* <p>If the string is invalid in any way, an exception will be thrown.
|
* <p>If the string is invalid in any way, an exception will be thrown.
|
||||||
*
|
*
|
||||||
* @param contents Contents of a Configuration to load.
|
* @param contents Contents of a Configuration to load.
|
||||||
@ -143,7 +138,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
/**
|
/**
|
||||||
* Compiles the header for this {@link FileConfiguration} and returns the
|
* Compiles the header for this {@link FileConfiguration} and returns the
|
||||||
* result.
|
* result.
|
||||||
*
|
* <p>
|
||||||
* <p>This will use the header from {@link #options()} -> {@link
|
* <p>This will use the header from {@link #options()} -> {@link
|
||||||
* FileConfigurationOptions#header()}, respecting the rules of {@link
|
* FileConfigurationOptions#header()}, respecting the rules of {@link
|
||||||
* FileConfigurationOptions#copyHeader()} if set.
|
* FileConfigurationOptions#copyHeader()} if set.
|
||||||
@ -152,8 +147,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
*/
|
*/
|
||||||
protected abstract String buildHeader();
|
protected abstract String buildHeader();
|
||||||
|
|
||||||
@Override
|
@Override public FileConfigurationOptions options() {
|
||||||
public FileConfigurationOptions options() {
|
|
||||||
if (this.options == null) {
|
if (this.options == null) {
|
||||||
this.options = new FileConfigurationOptions(this);
|
this.options = new FileConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
@ -16,32 +16,29 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
|||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public FileConfiguration configuration() {
|
||||||
public FileConfiguration configuration() {
|
|
||||||
return (FileConfiguration) super.configuration();
|
return (FileConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public FileConfigurationOptions copyDefaults(boolean value) {
|
||||||
public FileConfigurationOptions copyDefaults(boolean value) {
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public FileConfigurationOptions pathSeparator(char value) {
|
||||||
public FileConfigurationOptions pathSeparator(char value) {
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the header that will be applied to the top of the saved output.
|
* Gets the header that will be applied to the top of the saved output.
|
||||||
*
|
* <p>
|
||||||
* <p>This header will be commented out and applied directly at the top of
|
* <p>This header will be commented out and applied directly at the top of
|
||||||
* the generated output of the {@link FileConfiguration}. It is not
|
* the generated output of the {@link FileConfiguration}. It is not
|
||||||
* required to include a newline at the end of the header as it will
|
* required to include a newline at the end of the header as it will
|
||||||
* automatically be applied, but you may include one if you wish for extra
|
* automatically be applied, but you may include one if you wish for extra
|
||||||
* spacing.
|
* spacing.
|
||||||
*
|
* <p>
|
||||||
* <p>{@code null} is a valid value which will indicate that no header]
|
* <p>{@code null} is a valid value which will indicate that no header]
|
||||||
* is to be applied. The default value is {@code null}.
|
* is to be applied. The default value is {@code null}.
|
||||||
*
|
*
|
||||||
@ -53,13 +50,13 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the header that will be applied to the top of the saved output.
|
* Sets the header that will be applied to the top of the saved output.
|
||||||
*
|
* <p>
|
||||||
* <p>This header will be commented out and applied directly at the top of
|
* <p>This header will be commented out and applied directly at the top of
|
||||||
* the generated output of the {@link FileConfiguration}. It is not
|
* the generated output of the {@link FileConfiguration}. It is not
|
||||||
* required to include a newline at the end of the header as it will
|
* required to include a newline at the end of the header as it will
|
||||||
* automatically be applied, but you may include one if you wish for extra
|
* automatically be applied, but you may include one if you wish for extra
|
||||||
* spacing.
|
* spacing.
|
||||||
*
|
* <p>
|
||||||
* <p>{@code null} is a valid value which will indicate that no header
|
* <p>{@code null} is a valid value which will indicate that no header
|
||||||
* is to be applied.
|
* is to be applied.
|
||||||
*
|
*
|
||||||
@ -73,17 +70,17 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not the header should be copied from a default source.
|
* Gets whether or not the header should be copied from a default source.
|
||||||
*
|
* <p>
|
||||||
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
||||||
* {@link FileConfiguration#setDefaults(Configuration)}
|
* {@link FileConfiguration#setDefaults(Configuration)}
|
||||||
* then upon saving it will use the header from that config, instead of
|
* then upon saving it will use the header from that config, instead of
|
||||||
* the one provided here.
|
* the one provided here.
|
||||||
*
|
* <p>
|
||||||
* <p>If no default is set on the configuration, or the default is not of
|
* <p>If no default is set on the configuration, or the default is not of
|
||||||
* type FileConfiguration, or that config has no header ({@link #header()}
|
* type FileConfiguration, or that config has no header ({@link #header()}
|
||||||
* returns null) then the header specified in this configuration will be
|
* returns null) then the header specified in this configuration will be
|
||||||
* used.
|
* used.
|
||||||
*
|
* <p>
|
||||||
* <p>Defaults to true.
|
* <p>Defaults to true.
|
||||||
*
|
*
|
||||||
* @return Whether or not to copy the header
|
* @return Whether or not to copy the header
|
||||||
@ -94,17 +91,17 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not the header should be copied from a default source.
|
* Sets whether or not the header should be copied from a default source.
|
||||||
*
|
* <p>
|
||||||
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
||||||
* {@link FileConfiguration#setDefaults(Configuration)}
|
* {@link FileConfiguration#setDefaults(Configuration)}
|
||||||
* then upon saving it will use the header from that config, instead of
|
* then upon saving it will use the header from that config, instead of
|
||||||
* the one provided here.
|
* the one provided here.
|
||||||
*
|
* <p>
|
||||||
* <p>If no default is set on the configuration, or the default is not of
|
* <p>If no default is set on the configuration, or the default is not of
|
||||||
* type FileConfiguration, or that config has no header ({@link #header()}
|
* type FileConfiguration, or that config has no header ({@link #header()}
|
||||||
* returns null) then the header specified in this configuration will be
|
* returns null) then the header specified in this configuration will be
|
||||||
* used.
|
* used.
|
||||||
*
|
* <p>
|
||||||
* <p>Defaults to true.
|
* <p>Defaults to true.
|
||||||
*
|
*
|
||||||
* @param value Whether or not to copy the header
|
* @param value Whether or not to copy the header
|
||||||
|
@ -28,11 +28,11 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link YamlConfiguration}, loading from the given file.
|
* Creates a new {@link YamlConfiguration}, loading from the given file.
|
||||||
*
|
* <p>
|
||||||
* <p>Any errors loading the Configuration will be logged and then ignored.
|
* <p>Any errors loading the Configuration will be logged and then ignored.
|
||||||
* If the specified input is not a valid config, a blank config will be
|
* If the specified input is not a valid config, a blank config will be
|
||||||
* returned.
|
* returned.
|
||||||
*
|
* <p>
|
||||||
* <p>The encoding used may follow the system dependent default.
|
* <p>The encoding used may follow the system dependent default.
|
||||||
*
|
*
|
||||||
* @param file Input file
|
* @param file Input file
|
||||||
@ -64,8 +64,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String saveToString() {
|
||||||
public String saveToString() {
|
|
||||||
yamlOptions.setIndent(options().indent());
|
yamlOptions.setIndent(options().indent());
|
||||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
@ -80,8 +79,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
return header + dump;
|
return header + dump;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
|
||||||
|
|
||||||
Map<?, ?> input;
|
Map<?, ?> input;
|
||||||
try {
|
try {
|
||||||
@ -144,8 +142,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected String buildHeader() {
|
||||||
protected String buildHeader() {
|
|
||||||
String header = options().header();
|
String header = options().header();
|
||||||
|
|
||||||
if (options().copyHeader()) {
|
if (options().copyHeader()) {
|
||||||
@ -182,8 +179,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfigurationOptions options() {
|
||||||
public YamlConfigurationOptions options() {
|
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = new YamlConfigurationOptions(this);
|
options = new YamlConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
@ -11,38 +11,33 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
|||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfiguration configuration() {
|
||||||
public YamlConfiguration configuration() {
|
|
||||||
return (YamlConfiguration) super.configuration();
|
return (YamlConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfigurationOptions copyDefaults(boolean value) {
|
||||||
public YamlConfigurationOptions copyDefaults(boolean value) {
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfigurationOptions pathSeparator(char value) {
|
||||||
public YamlConfigurationOptions pathSeparator(char value) {
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfigurationOptions header(String value) {
|
||||||
public YamlConfigurationOptions header(String value) {
|
|
||||||
super.header(value);
|
super.header(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public YamlConfigurationOptions copyHeader(boolean value) {
|
||||||
public YamlConfigurationOptions copyHeader(boolean value) {
|
|
||||||
super.copyHeader(value);
|
super.copyHeader(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets how much spaces should be used to indent each line.
|
* Gets how much spaces should be used to indent each line.
|
||||||
*
|
* <p>
|
||||||
* <p>The minimum value this may be is 2, and the maximum is 9.
|
* <p>The minimum value this may be is 2, and the maximum is 9.
|
||||||
*
|
*
|
||||||
* @return How much to indent by
|
* @return How much to indent by
|
||||||
@ -53,7 +48,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets how much spaces should be used to indent each line.
|
* Sets how much spaces should be used to indent each line.
|
||||||
*
|
* <p>
|
||||||
* <p>The minimum value this may be is 2, and the maximum is 9.
|
* <p>The minimum value this may be is 2, and the maximum is 9.
|
||||||
*
|
*
|
||||||
* @param value New indent
|
* @param value New indent
|
||||||
|
@ -16,8 +16,7 @@ public class YamlConstructor extends SafeConstructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ConstructCustomObject extends ConstructYamlMap {
|
private class ConstructCustomObject extends ConstructYamlMap {
|
||||||
@Override
|
@Override public Object construct(final Node node) {
|
||||||
public Object construct(final Node node) {
|
|
||||||
if (node.isTwoStepsConstruction()) {
|
if (node.isTwoStepsConstruction()) {
|
||||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||||
}
|
}
|
||||||
@ -40,8 +39,7 @@ public class YamlConstructor extends SafeConstructor {
|
|||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void construct2ndStep(final Node node, final Object object) {
|
||||||
public void construct2ndStep(final Node node, final Object object) {
|
|
||||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,24 +13,25 @@ class YamlRepresenter extends Representer {
|
|||||||
|
|
||||||
YamlRepresenter() {
|
YamlRepresenter() {
|
||||||
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
||||||
this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
this.multiRepresenters
|
||||||
|
.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepresentConfigurationSection extends RepresentMap {
|
private class RepresentConfigurationSection extends RepresentMap {
|
||||||
|
|
||||||
@Override
|
@Override public Node representData(Object data) {
|
||||||
public Node representData(Object data) {
|
|
||||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class RepresentConfigurationSerializable extends RepresentMap {
|
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||||
|
|
||||||
@Override
|
@Override public Node representData(Object data) {
|
||||||
public Node representData(Object data) {
|
|
||||||
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
||||||
Map<String, Object> values = new LinkedHashMap<>();
|
Map<String, Object> values = new LinkedHashMap<>();
|
||||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
|
||||||
|
ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||||
values.putAll(serializable.serialize());
|
values.putAll(serializable.serialize());
|
||||||
|
|
||||||
return super.representData(values);
|
return super.representData(values);
|
||||||
|
@ -24,7 +24,7 @@ public interface ConfigurationSerializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Map representation of this class.
|
* Creates a Map representation of this class.
|
||||||
*
|
* <p>
|
||||||
* <p>This class must provide a method to restore this class, as defined in
|
* <p>This class must provide a method to restore this class, as defined in
|
||||||
* the {@link ConfigurationSerializable} interface javadoc.
|
* the {@link ConfigurationSerializable} interface javadoc.
|
||||||
*
|
*
|
||||||
|
@ -17,7 +17,8 @@ import java.util.logging.Logger;
|
|||||||
public class ConfigurationSerialization {
|
public class ConfigurationSerialization {
|
||||||
|
|
||||||
public static final String SERIALIZED_TYPE_KEY = "==";
|
public static final String SERIALIZED_TYPE_KEY = "==";
|
||||||
private static final Map<String, Class<? extends ConfigurationSerializable>> aliases = new HashMap<>();
|
private static final Map<String, Class<? extends ConfigurationSerializable>> aliases =
|
||||||
|
new HashMap<>();
|
||||||
private final Class<? extends ConfigurationSerializable> clazz;
|
private final Class<? extends ConfigurationSerializable> clazz;
|
||||||
|
|
||||||
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {
|
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {
|
||||||
@ -27,11 +28,11 @@ public class ConfigurationSerialization {
|
|||||||
/**
|
/**
|
||||||
* Attempts to deserialize the given arguments into a new instance of the
|
* Attempts to deserialize the given arguments into a new instance of the
|
||||||
* given class.
|
* given class.
|
||||||
*
|
* <p>
|
||||||
* <p>The class must implement {@link ConfigurationSerializable}, including
|
* <p>The class must implement {@link ConfigurationSerializable}, including
|
||||||
* the extra methods as specified in the javadoc of
|
* the extra methods as specified in the javadoc of
|
||||||
* ConfigurationSerializable.</p>
|
* ConfigurationSerializable.</p>
|
||||||
*
|
* <p>
|
||||||
* <p>If a new instance could not be made, an example being the class not
|
* <p>If a new instance could not be made, an example being the class not
|
||||||
* fully implementing the interface, null will be returned.</p>
|
* fully implementing the interface, null will be returned.</p>
|
||||||
*
|
*
|
||||||
@ -39,19 +40,20 @@ public class ConfigurationSerialization {
|
|||||||
* @param clazz Class to deserialize into
|
* @param clazz Class to deserialize into
|
||||||
* @return New instance of the specified class
|
* @return New instance of the specified class
|
||||||
*/
|
*/
|
||||||
public static ConfigurationSerializable deserializeObject(Map<String, ?> args, Class<? extends ConfigurationSerializable> clazz) {
|
public static ConfigurationSerializable deserializeObject(Map<String, ?> args,
|
||||||
|
Class<? extends ConfigurationSerializable> clazz) {
|
||||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to deserialize the given arguments into a new instance of the
|
* Attempts to deserialize the given arguments into a new instance of the
|
||||||
*
|
* <p>
|
||||||
* given class.
|
* given class.
|
||||||
* <p>
|
* <p>
|
||||||
* The class must implement {@link ConfigurationSerializable}, including
|
* The class must implement {@link ConfigurationSerializable}, including
|
||||||
* the extra methods as specified in the javadoc of
|
* the extra methods as specified in the javadoc of
|
||||||
* ConfigurationSerializable.</p>
|
* ConfigurationSerializable.</p>
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* If a new instance could not be made, an example being the class not
|
* If a new instance could not be made, an example being the class not
|
||||||
* fully implementing the interface, null will be returned.</p>
|
* fully implementing the interface, null will be returned.</p>
|
||||||
@ -71,14 +73,16 @@ public class ConfigurationSerialization {
|
|||||||
}
|
}
|
||||||
clazz = getClassByAlias(alias);
|
clazz = getClassByAlias(alias);
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')");
|
throw new IllegalArgumentException(
|
||||||
|
"Specified class does not exist ('" + alias + "')");
|
||||||
}
|
}
|
||||||
} catch (ClassCastException ex) {
|
} catch (ClassCastException ex) {
|
||||||
ex.fillInStackTrace();
|
ex.fillInStackTrace();
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
|
throw new IllegalArgumentException(
|
||||||
|
"Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||||
@ -107,7 +111,8 @@ public class ConfigurationSerialization {
|
|||||||
* @param alias Alias to register as
|
* @param alias Alias to register as
|
||||||
* @see SerializableAs
|
* @see SerializableAs
|
||||||
*/
|
*/
|
||||||
public static void registerClass(Class<? extends ConfigurationSerializable> clazz, String alias) {
|
public static void registerClass(Class<? extends ConfigurationSerializable> clazz,
|
||||||
|
String alias) {
|
||||||
aliases.put(alias, clazz);
|
aliases.put(alias, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +132,8 @@ public class ConfigurationSerialization {
|
|||||||
* @param clazz Class to unregister
|
* @param clazz Class to unregister
|
||||||
*/
|
*/
|
||||||
public static void unregisterClass(Class<? extends ConfigurationSerializable> clazz) {
|
public static void unregisterClass(Class<? extends ConfigurationSerializable> clazz) {
|
||||||
while (aliases.values().remove(clazz)) {}
|
while (aliases.values().remove(clazz)) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,17 +201,19 @@ public class ConfigurationSerialization {
|
|||||||
|
|
||||||
protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, ?> args) {
|
protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, ?> args) {
|
||||||
try {
|
try {
|
||||||
ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
|
ConfigurationSerializable result =
|
||||||
|
(ConfigurationSerializable) method.invoke(null, args);
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||||
"Could not call method '" + method.toString() + "' of " + this.clazz + " for deserialization: method returned null");
|
"Could not call method '" + method.toString() + "' of " + this.clazz
|
||||||
|
+ " for deserialization: method returned null");
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) {
|
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) {
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName())
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||||
.log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + this.clazz
|
"Could not call method '" + method.toString() + "' of " + this.clazz
|
||||||
+ " for deserialization",
|
+ " for deserialization",
|
||||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||||
}
|
}
|
||||||
@ -213,12 +221,13 @@ public class ConfigurationSerialization {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
|
protected ConfigurationSerializable deserializeViaCtor(
|
||||||
|
Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
|
||||||
try {
|
try {
|
||||||
return ctor.newInstance(args);
|
return ctor.newInstance(args);
|
||||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName())
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||||
.log(Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + this.clazz
|
"Could not call constructor '" + ctor.toString() + "' of " + this.clazz
|
||||||
+ " for deserialization",
|
+ " for deserialization",
|
||||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ import java.lang.annotation.Target;
|
|||||||
* Applies to a {@link ConfigurationSerializable} that will delegate all
|
* Applies to a {@link ConfigurationSerializable} that will delegate all
|
||||||
* deserialization to another {@link ConfigurationSerializable}.
|
* deserialization to another {@link ConfigurationSerializable}.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE)
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface DelegateDeserialization {
|
public @interface DelegateDeserialization {
|
||||||
/**
|
/**
|
||||||
* Which class should be used as a delegate for this classes
|
* Which class should be used as a delegate for this classes
|
||||||
|
@ -19,9 +19,7 @@ import java.lang.annotation.Target;
|
|||||||
*
|
*
|
||||||
* @see ConfigurationSerialization#registerClass(Class, String)
|
* @see ConfigurationSerialization#registerClass(Class, String)
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface SerializableAs {
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface SerializableAs {
|
|
||||||
/**
|
/**
|
||||||
* This is the name your class will be stored and retrieved as.
|
* This is the name your class will be stored and retrieved as.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -27,13 +27,11 @@ public final class ByteArrayTag extends Tag {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public byte[] getValue() {
|
||||||
public byte[] getValue() {
|
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
StringBuilder hex = new StringBuilder();
|
StringBuilder hex = new StringBuilder();
|
||||||
for (byte b : this.value) {
|
for (byte b : this.value) {
|
||||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||||
|
@ -27,13 +27,11 @@ public final class ByteTag extends Tag {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Byte getValue() {
|
||||||
public Byte getValue() {
|
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if (name != null && !name.isEmpty()) {
|
if (name != null && !name.isEmpty()) {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user