mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-04 15:38:00 +01:00
Automated code cleanup.
Removes spaces, adds {} to if statements, etc.
This commit is contained in:
parent
98b49ea37a
commit
c916bbf827
@ -50,9 +50,9 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
// Save the default config from config.yml
|
// Save the default config from config.yml
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
setInstance(this);
|
setInstance(this);
|
||||||
|
|
||||||
settings = new Settings();
|
settings = new Settings();
|
||||||
// Load settings from config.yml. This will check if there are any issues with it too.
|
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||||
try {
|
try {
|
||||||
//settings.saveSettings();
|
//settings.saveSettings();
|
||||||
settings = settings.loadSettings();
|
settings = settings.loadSettings();
|
||||||
@ -88,7 +88,7 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
islandWorldManager = new IslandWorld(plugin);
|
islandWorldManager = new IslandWorld(plugin);
|
||||||
|
|
||||||
getServer().getScheduler().runTask(plugin, () -> {
|
getServer().getScheduler().runTask(plugin, () -> {
|
||||||
|
|
||||||
// Load Flags
|
// Load Flags
|
||||||
flagsManager = new FlagsManager(plugin);
|
flagsManager = new FlagsManager(plugin);
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
private static void setInstance(BSkyBlock plugin) {
|
private static void setInstance(BSkyBlock plugin) {
|
||||||
BSkyBlock.plugin = plugin;
|
BSkyBlock.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BSkyBlock getInstance() {
|
public static BSkyBlock getInstance() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class Constants {
|
|||||||
public static final String ISLANDCOMMAND = "ai";
|
public static final String ISLANDCOMMAND = "ai";
|
||||||
// Admin command
|
// Admin command
|
||||||
public static final String ADMINCOMMAND = "acid";
|
public static final String ADMINCOMMAND = "acid";
|
||||||
*/
|
*/
|
||||||
public static final GameType GAMETYPE = GameType.BSKYBLOCK;
|
public static final GameType GAMETYPE = GameType.BSKYBLOCK;
|
||||||
// Permission prefix
|
// Permission prefix
|
||||||
public static final String PERMPREFIX = "bskyblock.";
|
public static final String PERMPREFIX = "bskyblock.";
|
||||||
|
@ -30,7 +30,7 @@ import org.json.simple.JSONObject;
|
|||||||
* bStats collects some data for plugin authors.
|
* bStats collects some data for plugin authors.
|
||||||
*
|
*
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
* Check out https://bStats.org/ to learn more about bStats!
|
||||||
*
|
*
|
||||||
* @author BtoBastian
|
* @author BtoBastian
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -96,7 +96,7 @@ public class Metrics {
|
|||||||
"To honor their work, you should not disable it.\n" +
|
"To honor their work, you should not disable it.\n" +
|
||||||
"This has nearly no effect on the server performance!\n" +
|
"This has nearly no effect on the server performance!\n" +
|
||||||
"Check out https://bStats.org/ to learn more :)"
|
"Check out https://bStats.org/ to learn more :)"
|
||||||
).copyDefaults(true);
|
).copyDefaults(true);
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
@ -150,12 +150,7 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
submitData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, 1000*60*5L, 1000*60*30L);
|
}, 1000*60*5L, 1000*60*30L);
|
||||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||||
@ -250,17 +245,14 @@ public class Metrics {
|
|||||||
data.put("plugins", pluginData);
|
data.put("plugins", pluginData);
|
||||||
|
|
||||||
// Create a new thread for the connection to the bStats server
|
// Create a new thread for the connection to the bStats server
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
// Send the data
|
||||||
try {
|
sendData(data);
|
||||||
// Send the data
|
} catch (Exception e) {
|
||||||
sendData(data);
|
// Something went wrong! :(
|
||||||
} catch (Exception e) {
|
if (logFailedRequests) {
|
||||||
// Something went wrong! :(
|
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -283,7 +275,9 @@ public class Metrics {
|
|||||||
|
|
||||||
// Compress the data to save bandwidth
|
// Compress the data to save bandwidth
|
||||||
byte[] compressedData = compress(data.toString());
|
byte[] compressedData = compress(data.toString());
|
||||||
if (compressedData == null) throw new Exception();
|
if (compressedData == null) {
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
// Add headers
|
// Add headers
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
|
@ -155,7 +155,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
// Reset
|
// Reset
|
||||||
@ConfigEntry(path = "island.reset.reset-limit")
|
@ConfigEntry(path = "island.reset.reset-limit")
|
||||||
private int resetLimit = -1;
|
private int resetLimit = -1;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.require-confirmation.reset")
|
@ConfigEntry(path = "island.require-confirmation.reset")
|
||||||
private boolean resetConfirmation = true;
|
private boolean resetConfirmation = true;
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
|
|
||||||
@ConfigEntry(path = "island.reset.leavers-lose-reset")
|
@ConfigEntry(path = "island.reset.leavers-lose-reset")
|
||||||
private boolean leaversLoseReset = false;
|
private boolean leaversLoseReset = false;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.reset.kicked-keep-inventory")
|
@ConfigEntry(path = "island.reset.kicked-keep-inventory")
|
||||||
private boolean kickedKeepInventory = false;
|
private boolean kickedKeepInventory = false;
|
||||||
|
|
||||||
@ -173,16 +173,16 @@ public class Settings implements ISettings<Settings> {
|
|||||||
private boolean removeMobsOnLogin = false;
|
private boolean removeMobsOnLogin = false;
|
||||||
@ConfigEntry(path = "island.remove-mobs.on-island")
|
@ConfigEntry(path = "island.remove-mobs.on-island")
|
||||||
private boolean removeMobsOnIsland = false;
|
private boolean removeMobsOnIsland = false;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.remove-mobs.whitelist")
|
@ConfigEntry(path = "island.remove-mobs.whitelist")
|
||||||
private List<String> removeMobsWhitelist = new ArrayList<>();
|
private List<String> removeMobsWhitelist = new ArrayList<>();
|
||||||
|
|
||||||
@ConfigEntry(path = "island.make-island-if-none")
|
@ConfigEntry(path = "island.make-island-if-none")
|
||||||
private boolean makeIslandIfNone = false;
|
private boolean makeIslandIfNone = false;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.immediate-teleport-on-island")
|
@ConfigEntry(path = "island.immediate-teleport-on-island")
|
||||||
private boolean immediateTeleportOnIsland = false;
|
private boolean immediateTeleportOnIsland = false;
|
||||||
|
|
||||||
private boolean respawnOnIsland = true;
|
private boolean respawnOnIsland = true;
|
||||||
|
|
||||||
// Deaths
|
// Deaths
|
||||||
@ -191,7 +191,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
|
|
||||||
@ConfigEntry(path = "island.deaths.sum-team")
|
@ConfigEntry(path = "island.deaths.sum-team")
|
||||||
private boolean deathsSumTeam = false;
|
private boolean deathsSumTeam = false;
|
||||||
|
|
||||||
// Ranks
|
// Ranks
|
||||||
@ConfigEntry(path = "island.customranks")
|
@ConfigEntry(path = "island.customranks")
|
||||||
private Map<String, Integer> customRanks = new HashMap<>();
|
private Map<String, Integer> customRanks = new HashMap<>();
|
||||||
@ -250,10 +250,10 @@ public class Settings implements ISettings<Settings> {
|
|||||||
|
|
||||||
/* SCHEMATICS */
|
/* SCHEMATICS */
|
||||||
private List<String> companionNames = new ArrayList<>();
|
private List<String> companionNames = new ArrayList<>();
|
||||||
|
|
||||||
@ConfigEntry(path = "island.chest-items")
|
@ConfigEntry(path = "island.chest-items")
|
||||||
private List<ItemStack> chestItems = new ArrayList<>();
|
private List<ItemStack> chestItems = new ArrayList<>();
|
||||||
|
|
||||||
private EntityType companionType = EntityType.COW;
|
private EntityType companionType = EntityType.COW;
|
||||||
|
|
||||||
private boolean useOwnGenerator;
|
private boolean useOwnGenerator;
|
||||||
@ -267,13 +267,13 @@ public class Settings implements ISettings<Settings> {
|
|||||||
|
|
||||||
@ConfigEntry(path = "island.require-confirmation.kick-wait")
|
@ConfigEntry(path = "island.require-confirmation.kick-wait")
|
||||||
private long kickWait = 300;
|
private long kickWait = 300;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.require-confirmation.leave")
|
@ConfigEntry(path = "island.require-confirmation.leave")
|
||||||
private boolean leaveConfirmation = true;
|
private boolean leaveConfirmation = true;
|
||||||
|
|
||||||
@ConfigEntry(path = "island.require-confirmation.leave-wait")
|
@ConfigEntry(path = "island.require-confirmation.leave-wait")
|
||||||
private long leaveWait = 300;
|
private long leaveWait = 300;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the acidDamage
|
* @return the acidDamage
|
||||||
@ -540,6 +540,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
/**
|
/**
|
||||||
* @return the uniqueId
|
* @return the uniqueId
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getUniqueId() {
|
public String getUniqueId() {
|
||||||
return uniqueId;
|
return uniqueId;
|
||||||
}
|
}
|
||||||
@ -1137,7 +1138,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
public void setRemoveMobsOnIsland(boolean removeMobsOnIsland) {
|
public void setRemoveMobsOnIsland(boolean removeMobsOnIsland) {
|
||||||
this.removeMobsOnIsland = removeMobsOnIsland;
|
this.removeMobsOnIsland = removeMobsOnIsland;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param removeMobsOnLogin the removeMobsOnLogin to set
|
* @param removeMobsOnLogin the removeMobsOnLogin to set
|
||||||
*/
|
*/
|
||||||
@ -1207,6 +1208,7 @@ public class Settings implements ISettings<Settings> {
|
|||||||
/**
|
/**
|
||||||
* @param uniqueId the uniqueId to set
|
* @param uniqueId the uniqueId to set
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setUniqueId(String uniqueId) {
|
public void setUniqueId(String uniqueId) {
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
@ -1240,6 +1242,6 @@ public class Settings implements ISettings<Settings> {
|
|||||||
public void setFakePlayers(Set<String> fakePlayers) {
|
public void setFakePlayers(Set<String> fakePlayers) {
|
||||||
this.fakePlayers = fakePlayers;
|
this.fakePlayers = fakePlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -16,8 +16,8 @@ import org.bukkit.event.Listener;
|
|||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add-on class for BSkyBlock. Extend this to create an add-on.
|
* Add-on class for BSkyBlock. Extend this to create an add-on. The operation
|
||||||
* The operation and methods are very similar to Bukkit's JavaPlugin.
|
* and methods are very similar to Bukkit's JavaPlugin.
|
||||||
*
|
*
|
||||||
* @author tastybento, ComminQ_Q
|
* @author tastybento, ComminQ_Q
|
||||||
*/
|
*/
|
||||||
@ -32,10 +32,10 @@ public abstract class Addon implements AddonInterface {
|
|||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
public Addon() {
|
public Addon() {
|
||||||
this.enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BSkyBlock getBSkyBlock(){
|
public BSkyBlock getBSkyBlock() {
|
||||||
return BSkyBlock.getInstance();
|
return BSkyBlock.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +77,7 @@ public abstract class Addon implements AddonInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to obtain the server
|
* Convenience method to obtain the server
|
||||||
|
*
|
||||||
* @return the server object
|
* @return the server object
|
||||||
*/
|
*/
|
||||||
public Server getServer() {
|
public Server getServer() {
|
||||||
@ -89,6 +90,7 @@ public abstract class Addon implements AddonInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a YAML file
|
* Load a YAML file
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @return Yaml File configuration
|
* @return Yaml File configuration
|
||||||
*/
|
*/
|
||||||
@ -109,9 +111,10 @@ public abstract class Addon implements AddonInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a listener for this addon
|
* Register a listener for this addon
|
||||||
|
*
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
public void registerListener(Listener listener){
|
public void registerListener(Listener listener) {
|
||||||
BSkyBlock.getInstance().getServer().getPluginManager().registerEvents(listener, BSkyBlock.getInstance());
|
BSkyBlock.getInstance().getServer().getPluginManager().registerEvents(listener, BSkyBlock.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,15 +123,15 @@ public abstract class Addon implements AddonInterface {
|
|||||||
*/
|
*/
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
try {
|
try {
|
||||||
this.config.save(new File(dataFolder, ADDON_CONFIG_FILENAME));
|
config.save(new File(dataFolder, ADDON_CONFIG_FILENAME));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().severe("Could not save config!");
|
Bukkit.getLogger().severe("Could not save config!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the addon's config.yml file to the addon's data folder and loads it.
|
* Saves the addon's config.yml file to the addon's data folder and loads it. If
|
||||||
* If the file exists already, it will not be replaced.
|
* the file exists already, it will not be replaced.
|
||||||
*/
|
*/
|
||||||
public void saveDefaultConfig() {
|
public void saveDefaultConfig() {
|
||||||
saveResource(ADDON_CONFIG_FILENAME, false);
|
saveResource(ADDON_CONFIG_FILENAME, false);
|
||||||
@ -136,20 +139,30 @@ public abstract class Addon implements AddonInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a resource contained in this add-on's jar file to the addon's data folder.
|
* Saves a resource contained in this add-on's jar file to the addon's data
|
||||||
* @param resourcePath in jar file
|
* folder.
|
||||||
* @param replace - if true, will overwrite previous file
|
*
|
||||||
|
* @param resourcePath
|
||||||
|
* in jar file
|
||||||
|
* @param replace
|
||||||
|
* - if true, will overwrite previous file
|
||||||
*/
|
*/
|
||||||
public void saveResource(String resourcePath, boolean replace) {
|
public void saveResource(String resourcePath, boolean replace) {
|
||||||
saveResource(resourcePath, dataFolder, replace, false);
|
saveResource(resourcePath, dataFolder, replace, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a resource contained in this add-on's jar file to the destination folder.
|
* Saves a resource contained in this add-on's jar file to the destination
|
||||||
* @param jarResource in jar file
|
* folder.
|
||||||
* @param destinationFolder on file system
|
*
|
||||||
* @param replace - if true, will overwrite previous file
|
* @param jarResource
|
||||||
* @param noPath - if true, the resource's path will be ignored when saving
|
* in jar file
|
||||||
|
* @param destinationFolder
|
||||||
|
* on file system
|
||||||
|
* @param replace
|
||||||
|
* - if true, will overwrite previous file
|
||||||
|
* @param noPath
|
||||||
|
* - if true, the resource's path will be ignored when saving
|
||||||
*/
|
*/
|
||||||
public void saveResource(String jarResource, File destinationFolder, boolean replace, boolean noPath) {
|
public void saveResource(String jarResource, File destinationFolder, boolean replace, boolean noPath) {
|
||||||
if (jarResource == null || jarResource.equals("")) {
|
if (jarResource == null || jarResource.equals("")) {
|
||||||
@ -162,7 +175,8 @@ public abstract class Addon implements AddonInterface {
|
|||||||
if (jarConfig != null) {
|
if (jarConfig != null) {
|
||||||
try (InputStream in = jar.getInputStream(jarConfig)) {
|
try (InputStream in = jar.getInputStream(jarConfig)) {
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
throw new IllegalArgumentException("The embedded resource '" + jarResource + "' cannot be found in " + jar.getName());
|
throw new IllegalArgumentException(
|
||||||
|
"The embedded resource '" + jarResource + "' cannot be found in " + jar.getName());
|
||||||
}
|
}
|
||||||
// There are two options, use the path of the resource or not
|
// There are two options, use the path of the resource or not
|
||||||
File outFile = new File(destinationFolder, jarResource);
|
File outFile = new File(destinationFolder, jarResource);
|
||||||
@ -181,36 +195,42 @@ public abstract class Addon implements AddonInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().severe("Could not save from jar file. From " + jarResource + " to " + destinationFolder.getAbsolutePath());
|
Bukkit.getLogger().severe(
|
||||||
|
"Could not save from jar file. From " + jarResource + " to " + destinationFolder.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the file that contains this addon
|
* Set the file that contains this addon
|
||||||
* @param f the file to set
|
*
|
||||||
|
* @param f
|
||||||
|
* the file to set
|
||||||
*/
|
*/
|
||||||
public void setAddonFile(File f) {
|
public void setAddonFile(File f) {
|
||||||
this.file = f;
|
file = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this addon's data folder
|
* Set this addon's data folder
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
public void setDataFolder(File file) {
|
public void setDataFolder(File file) {
|
||||||
this.dataFolder = file;
|
dataFolder = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this addons description
|
* Set this addons description
|
||||||
|
*
|
||||||
* @param desc
|
* @param desc
|
||||||
*/
|
*/
|
||||||
public void setDescription(AddonDescription desc){
|
public void setDescription(AddonDescription desc) {
|
||||||
this.description = desc;
|
description = desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether this addon is enabled or not
|
* Set whether this addon is enabled or not
|
||||||
|
*
|
||||||
* @param enabled
|
* @param enabled
|
||||||
*/
|
*/
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
|
@ -20,57 +20,57 @@ import us.tastybento.bskyblock.managers.AddonsManager;
|
|||||||
*/
|
*/
|
||||||
public class AddonClassLoader extends URLClassLoader {
|
public class AddonClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
|
private final Map<String, Class<?>> classes = new HashMap<>();
|
||||||
private Addon addon;
|
private Addon addon;
|
||||||
private AddonsManager loader;
|
private AddonsManager loader;
|
||||||
|
|
||||||
public AddonClassLoader(AddonsManager addonsManager, Map<String, String>data, File path, ClassLoader parent)
|
public AddonClassLoader(AddonsManager addonsManager, Map<String, String>data, File path, ClassLoader parent)
|
||||||
throws InvalidAddonInheritException,
|
throws InvalidAddonInheritException,
|
||||||
MalformedURLException,
|
MalformedURLException,
|
||||||
InvalidAddonFormatException,
|
InvalidAddonFormatException,
|
||||||
InvalidDescriptionException,
|
InvalidDescriptionException,
|
||||||
InstantiationException,
|
InstantiationException,
|
||||||
IllegalAccessException {
|
IllegalAccessException {
|
||||||
super(new URL[]{path.toURI().toURL()}, parent);
|
super(new URL[]{path.toURI().toURL()}, parent);
|
||||||
|
|
||||||
this.loader = addonsManager;
|
loader = addonsManager;
|
||||||
|
|
||||||
Class<?> javaClass = null;
|
Class<?> javaClass = null;
|
||||||
try {
|
try {
|
||||||
//Bukkit.getLogger().info("data " + data.get("main"));
|
//Bukkit.getLogger().info("data " + data.get("main"));
|
||||||
/*
|
/*
|
||||||
for (Entry<String, String> en : data.entrySet()) {
|
for (Entry<String, String> en : data.entrySet()) {
|
||||||
Bukkit.getLogger().info(en.getKey() + " => " + en.getValue());
|
Bukkit.getLogger().info(en.getKey() + " => " + en.getValue());
|
||||||
}*/
|
}*/
|
||||||
javaClass = Class.forName(data.get("main"), true, this);
|
javaClass = Class.forName(data.get("main"), true, this);
|
||||||
if(data.get("main").contains("us.tastybento")){
|
if(data.get("main").contains("us.tastybento")){
|
||||||
throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'");
|
throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'");
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
BSkyBlock.getInstance().getLogger().severe("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "'");
|
BSkyBlock.getInstance().getLogger().severe("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "'");
|
||||||
throw new InvalidDescriptionException("Invalid addon.yml");
|
throw new InvalidDescriptionException("Invalid addon.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<? extends Addon> addonClass;
|
Class<? extends Addon> addonClass;
|
||||||
try{
|
try{
|
||||||
addonClass = javaClass.asSubclass(Addon.class);
|
addonClass = javaClass.asSubclass(Addon.class);
|
||||||
} catch(ClassCastException e){
|
} catch(ClassCastException e){
|
||||||
throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'");
|
throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addon = addonClass.newInstance();
|
addon = addonClass.newInstance();
|
||||||
addon.setDescription(this.asDescription(data));
|
addon.setDescription(asDescription(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AddonDescription asDescription(Map<String, String> data){
|
private AddonDescription asDescription(Map<String, String> data){
|
||||||
String[] authors = data.get("authors").split("\\,");
|
String[] authors = data.get("authors").split("\\,");
|
||||||
|
|
||||||
return new AddonDescriptionBuilder(data.get("name"))
|
return new AddonDescriptionBuilder(data.get("name"))
|
||||||
.withVersion(data.get("version"))
|
.withVersion(data.get("version"))
|
||||||
.withAuthor(authors).build();
|
.withAuthor(authors).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.net.URLClassLoader#findClass(java.lang.String)
|
* @see java.net.URLClassLoader#findClass(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@ -118,5 +118,5 @@ public class AddonClassLoader extends URLClassLoader {
|
|||||||
public Addon getAddon() {
|
public Addon getAddon() {
|
||||||
return addon;
|
return addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public final class AddonDescription {
|
|||||||
private List<String> authors;
|
private List<String> authors;
|
||||||
|
|
||||||
public AddonDescription() {}
|
public AddonDescription() {}
|
||||||
|
|
||||||
public AddonDescription(String main, String name, String version, String description, List<String> authors) {
|
public AddonDescription(String main, String name, String version, String description, List<String> authors) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -78,34 +78,34 @@ public final class AddonDescription {
|
|||||||
public List<String> getAuthors() {
|
public List<String> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AddonDescriptionBuilder{
|
public static class AddonDescriptionBuilder{
|
||||||
|
|
||||||
private AddonDescription description;
|
private AddonDescription description;
|
||||||
|
|
||||||
public AddonDescriptionBuilder(String name){
|
public AddonDescriptionBuilder(String name){
|
||||||
description = new AddonDescription();
|
description = new AddonDescription();
|
||||||
description.setName(name);
|
description.setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddonDescriptionBuilder withAuthor(String... authors){
|
public AddonDescriptionBuilder withAuthor(String... authors){
|
||||||
this.description.setAuthors(Arrays.asList(authors));
|
description.setAuthors(Arrays.asList(authors));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddonDescriptionBuilder withDescription(String desc){
|
public AddonDescriptionBuilder withDescription(String desc){
|
||||||
this.description.setDescription(desc);
|
description.setDescription(desc);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddonDescriptionBuilder withVersion(String version){
|
public AddonDescriptionBuilder withVersion(String version){
|
||||||
this.description.setVersion(version);
|
description.setVersion(version);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddonDescription build(){
|
public AddonDescription build(){
|
||||||
return this.description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package us.tastybento.bskyblock.api.addons.exception;
|
|||||||
|
|
||||||
public abstract class AddonException extends Exception {
|
public abstract class AddonException extends Exception {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 4203162022348693854L;
|
private static final long serialVersionUID = 4203162022348693854L;
|
||||||
|
|
||||||
|
public AddonException(String errorMessage){
|
||||||
|
super("AddonException : " + errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
public AddonException(String errorMessage){
|
|
||||||
super("AddonException : " + errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,25 +6,25 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class InvalidAddonFormatException extends AddonException {
|
public class InvalidAddonFormatException extends AddonException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 7741502900847049986L;
|
private static final long serialVersionUID = 7741502900847049986L;
|
||||||
|
|
||||||
public InvalidAddonFormatException(String errorMessage) {
|
public InvalidAddonFormatException(String errorMessage) {
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void printStackTrace(){
|
public void printStackTrace(){
|
||||||
super.printStackTrace();
|
super.printStackTrace();
|
||||||
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, " Basic format : (addon.yml)");
|
Bukkit.getLogger().log(Level.WARNING, " Basic format : (addon.yml)");
|
||||||
Bukkit.getLogger().log(Level.WARNING, " main: path.to.your.MainClass");
|
Bukkit.getLogger().log(Level.WARNING, " main: path.to.your.MainClass");
|
||||||
Bukkit.getLogger().log(Level.WARNING, " name: <NameOfYourModule>");
|
Bukkit.getLogger().log(Level.WARNING, " name: <NameOfYourModule>");
|
||||||
Bukkit.getLogger().log(Level.WARNING, " authors: <AuthorA> | <AuthorA, AuthorB>");
|
Bukkit.getLogger().log(Level.WARNING, " authors: <AuthorA> | <AuthorA, AuthorB>");
|
||||||
Bukkit.getLogger().log(Level.WARNING, " version: YourVersion");
|
Bukkit.getLogger().log(Level.WARNING, " version: YourVersion");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package us.tastybento.bskyblock.api.addons.exception;
|
|||||||
|
|
||||||
public class InvalidAddonInheritException extends AddonException {
|
public class InvalidAddonInheritException extends AddonException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -5847358994397613244L;
|
private static final long serialVersionUID = -5847358994397613244L;
|
||||||
|
|
||||||
public InvalidAddonInheritException(String errorMessage) {
|
public InvalidAddonInheritException(String errorMessage) {
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,14 +71,14 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
*/
|
*/
|
||||||
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
|
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
|
||||||
super(label);
|
super(label);
|
||||||
this.setAliases(new ArrayList<>(Arrays.asList(string)));
|
setAliases(new ArrayList<>(Arrays.asList(string)));
|
||||||
this.parent = null;
|
parent = null;
|
||||||
setUsage("");
|
setUsage("");
|
||||||
this.subCommandLevel = 0; // Top level
|
subCommandLevel = 0; // Top level
|
||||||
this.subCommands = new LinkedHashMap<>();
|
subCommands = new LinkedHashMap<>();
|
||||||
this.subCommandAliases = new LinkedHashMap<>();
|
subCommandAliases = new LinkedHashMap<>();
|
||||||
this.setup();
|
setup();
|
||||||
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
|
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||||
new DefaultHelpCommand(this);
|
new DefaultHelpCommand(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,20 +93,20 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
|
public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
|
||||||
super(label);
|
super(label);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.subCommandLevel = parent.getLevel() + 1;
|
subCommandLevel = parent.getLevel() + 1;
|
||||||
// Add this sub-command to the parent
|
// Add this sub-command to the parent
|
||||||
parent.getSubCommands().put(label, this);
|
parent.getSubCommands().put(label, this);
|
||||||
this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
||||||
this.subCommands = new LinkedHashMap<>();
|
subCommands = new LinkedHashMap<>();
|
||||||
this.subCommandAliases = new LinkedHashMap<>();
|
subCommandAliases = new LinkedHashMap<>();
|
||||||
// Add aliases to the parent for this command
|
// Add aliases to the parent for this command
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
parent.subCommandAliases.put(alias, this);
|
parent.subCommandAliases.put(alias, this);
|
||||||
}
|
}
|
||||||
setUsage("");
|
setUsage("");
|
||||||
this.setup();
|
setup();
|
||||||
// If this command does not define its own help class, then use the default help command
|
// If this command does not define its own help class, then use the default help command
|
||||||
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
|
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||||
new DefaultHelpCommand(this);
|
new DefaultHelpCommand(this);
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -124,25 +124,25 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info("DEBUG: top level command registering..." + label);
|
Bukkit.getLogger().info("DEBUG: top level command registering..." + label);
|
||||||
}
|
}
|
||||||
this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
||||||
this.parent = null;
|
parent = null;
|
||||||
setUsage("");
|
setUsage("");
|
||||||
this.subCommandLevel = 0; // Top level
|
subCommandLevel = 0; // Top level
|
||||||
this.subCommands = new LinkedHashMap<>();
|
subCommands = new LinkedHashMap<>();
|
||||||
this.subCommandAliases = new LinkedHashMap<>();
|
subCommandAliases = new LinkedHashMap<>();
|
||||||
// Register command if it is not already registered
|
// Register command if it is not already registered
|
||||||
if (getPlugin().getCommand(label) == null) {
|
if (getPlugin().getCommand(label) == null) {
|
||||||
getPlugin().getCommandsManager().registerCommand(this);
|
getPlugin().getCommandsManager().registerCommand(this);
|
||||||
}
|
}
|
||||||
this.setup();
|
setup();
|
||||||
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
|
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||||
new DefaultHelpCommand(this);
|
new DefaultHelpCommand(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method deals with the command execution. It traverses the tree of
|
* This method deals with the command execution. It traverses the tree of
|
||||||
* subcommands until it finds the right object and then runs execute on it.
|
* subcommands until it finds the right object and then runs execute on it.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -189,17 +189,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
private CompositeCommand getCommandFromArgs(String[] args) {
|
private CompositeCommand getCommandFromArgs(String[] args) {
|
||||||
CompositeCommand subCommand = this;
|
CompositeCommand subCommand = this;
|
||||||
// Run through any arguments
|
// Run through any arguments
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (String arg : args) {
|
||||||
// get the subcommand corresponding to the arg
|
// get the subcommand corresponding to the arg
|
||||||
if (subCommand.hasSubCommmands()) {
|
if (subCommand.hasSubCommmands()) {
|
||||||
Optional<CompositeCommand> sub = subCommand.getSubCommand(args[i]);
|
Optional<CompositeCommand> sub = subCommand.getSubCommand(arg);
|
||||||
if (!sub.isPresent()) {
|
if (!sub.isPresent()) {
|
||||||
return subCommand;
|
return subCommand;
|
||||||
}
|
}
|
||||||
// Step down one
|
// Step down one
|
||||||
subCommand = sub.orElse(subCommand);
|
subCommand = sub.orElse(subCommand);
|
||||||
// Set the label
|
// Set the label
|
||||||
subCommand.setLabel(args[i]);
|
subCommand.setLabel(arg);
|
||||||
} else {
|
} else {
|
||||||
// We are at the end of the walk
|
// We are at the end of the walk
|
||||||
return subCommand;
|
return subCommand;
|
||||||
@ -254,7 +254,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return this.permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,14 +292,18 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info("DEBUG: " + entry.getKey());
|
Bukkit.getLogger().info("DEBUG: " + entry.getKey());
|
||||||
}
|
}
|
||||||
if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommands.get(label));
|
if (entry.getKey().equalsIgnoreCase(label)) {
|
||||||
|
return Optional.of(subCommands.get(label));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Try aliases
|
// Try aliases
|
||||||
for (Map.Entry<String, CompositeCommand> entry : subCommandAliases.entrySet()) {
|
for (Map.Entry<String, CompositeCommand> entry : subCommandAliases.entrySet()) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info("DEBUG: alias " + entry.getKey());
|
Bukkit.getLogger().info("DEBUG: alias " + entry.getKey());
|
||||||
}
|
}
|
||||||
if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommandAliases.get(label));
|
if (entry.getKey().equalsIgnoreCase(label)) {
|
||||||
|
return Optional.of(subCommandAliases.get(label));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@ -396,8 +400,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
@Override
|
@Override
|
||||||
public Command setUsage(String usage) {
|
public Command setUsage(String usage) {
|
||||||
// Go up the chain
|
// Go up the chain
|
||||||
CompositeCommand parent = this.getParent();
|
CompositeCommand parent = getParent();
|
||||||
this.usage = this.getLabel() + " " + usage;
|
this.usage = getLabel() + " " + usage;
|
||||||
while (parent != null) {
|
while (parent != null) {
|
||||||
this.usage = parent.getLabel() + " " + this.usage;
|
this.usage = parent.getLabel() + " " + this.usage;
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
@ -428,7 +432,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
// Add any tab completion from the subcommand
|
// Add any tab completion from the subcommand
|
||||||
options.addAll(cmd.tabComplete(User.getInstance(sender), alias, new LinkedList<String>(Arrays.asList(args))).orElse(new ArrayList<>()));
|
options.addAll(cmd.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElse(new ArrayList<>()));
|
||||||
// Add any sub-commands automatically
|
// Add any sub-commands automatically
|
||||||
if (cmd.hasSubCommmands()) {
|
if (cmd.hasSubCommmands()) {
|
||||||
// Check if subcommands are visible to this sender
|
// Check if subcommands are visible to this sender
|
||||||
|
@ -28,8 +28,8 @@ public class DefaultHelpCommand extends CompositeCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
// Set the usage to what the parent's command is
|
// Set the usage to what the parent's command is
|
||||||
this.setParameters(parent.getParameters());
|
setParameters(parent.getParameters());
|
||||||
this.setDescription(parent.getDescription());
|
setDescription(parent.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,8 +44,9 @@ public class User {
|
|||||||
* @return user
|
* @return user
|
||||||
*/
|
*/
|
||||||
public static User getInstance(Player player) {
|
public static User getInstance(Player player) {
|
||||||
if (player == null)
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
if (users.containsKey(player.getUniqueId())) {
|
if (users.containsKey(player.getUniqueId())) {
|
||||||
return users.get(player.getUniqueId());
|
return users.get(player.getUniqueId());
|
||||||
}
|
}
|
||||||
@ -80,22 +81,22 @@ public class User {
|
|||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
|
|
||||||
private User(CommandSender sender) {
|
private User(CommandSender sender) {
|
||||||
this.player = null;
|
player = null;
|
||||||
this.playerUUID = null;
|
playerUUID = null;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
private User(Player player) {
|
private User(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.sender = player;
|
sender = player;
|
||||||
this.playerUUID = player.getUniqueId();
|
playerUUID = player.getUniqueId();
|
||||||
users.put(player.getUniqueId(), this);
|
users.put(player.getUniqueId(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private User(UUID playerUUID) {
|
private User(UUID playerUUID) {
|
||||||
this.player = Bukkit.getPlayer(playerUUID);
|
player = Bukkit.getPlayer(playerUUID);
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = playerUUID;
|
||||||
this.sender = null;
|
sender = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||||
@ -160,7 +161,9 @@ public class User {
|
|||||||
String translation = plugin.getLocalesManager().get(this, reference);
|
String translation = plugin.getLocalesManager().get(this, reference);
|
||||||
|
|
||||||
// If no translation has been found, return the reference for debug purposes.
|
// If no translation has been found, return the reference for debug purposes.
|
||||||
if (translation == null) return reference;
|
if (translation == null) {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
// Then replace variables
|
// Then replace variables
|
||||||
if (variables.length > 1) {
|
if (variables.length > 1) {
|
||||||
@ -168,7 +171,7 @@ public class User {
|
|||||||
translation = translation.replace(variables[i], variables[i+1]);
|
translation = translation.replace(variables[i], variables[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', translation);
|
return ChatColor.translateAlternateColorCodes('&', translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +185,7 @@ public class User {
|
|||||||
String translation = getTranslation(reference, variables);
|
String translation = getTranslation(reference, variables);
|
||||||
return translation.equals(reference) ? "" : translation;
|
return translation.equals(reference) ? "" : translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to sender if message is not empty. Does not include color codes or spaces.
|
* Send a message to sender if message is not empty. Does not include color codes or spaces.
|
||||||
* @param reference - language file reference
|
* @param reference - language file reference
|
||||||
@ -199,7 +202,7 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to sender without any modification (colors, multi-lines, placeholders).
|
* Sends a message to sender without any modification (colors, multi-lines, placeholders).
|
||||||
* Should only be used for debug purposes.
|
* Should only be used for debug purposes.
|
||||||
@ -244,23 +247,24 @@ public class User {
|
|||||||
public void closeInventory() {
|
public void closeInventory() {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user's locale
|
* Get the user's locale
|
||||||
* @return Locale
|
* @return Locale
|
||||||
*/
|
*/
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty())
|
if (!plugin.getPlayers().getLocale(playerUUID).isEmpty()) {
|
||||||
return Locale.forLanguageTag(plugin.getPlayers().getLocale(this.playerUUID));
|
return Locale.forLanguageTag(plugin.getPlayers().getLocale(playerUUID));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage());
|
return Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void updateInventory() {
|
public void updateInventory() {
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,5 @@ public @interface ConfigEntry {
|
|||||||
boolean experimental() default false;
|
boolean experimental() default false;
|
||||||
boolean needsReset() default false;
|
boolean needsReset() default false;
|
||||||
GameType specificTo() default GameType.BOTH;
|
GameType specificTo() default GameType.BOTH;
|
||||||
|
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ public interface ISettings<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default void saveBackup() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
|
default void saveBackup() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
|
||||||
// Save backup
|
// Save backup
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
AbstractDatabaseHandler<T> backupHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(getInstance().getClass());
|
AbstractDatabaseHandler<T> backupHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(getInstance().getClass());
|
||||||
backupHandler.saveObject(getInstance());
|
backupHandler.saveObject(getInstance());
|
||||||
@ -41,11 +41,11 @@ public interface ISettings<T> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default T loadSettings() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException {
|
default T loadSettings() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException {
|
||||||
// See if this settings object already exists in the database
|
// See if this settings object already exists in the database
|
||||||
AbstractDatabaseHandler<T> dbhandler = (AbstractDatabaseHandler<T>) BSBDatabase.getDatabase().getHandler(this.getClass());
|
AbstractDatabaseHandler<T> dbhandler = (AbstractDatabaseHandler<T>) BSBDatabase.getDatabase().getHandler(getClass());
|
||||||
T dbConfig = null;
|
T dbConfig = null;
|
||||||
if (dbhandler.objectExits(this.getUniqueId())) {
|
if (dbhandler.objectExits(this.getUniqueId())) {
|
||||||
// Load it
|
// Load it
|
||||||
dbConfig = dbhandler.loadObject(getUniqueId());
|
dbConfig = dbhandler.loadObject(getUniqueId());
|
||||||
}
|
}
|
||||||
// Get the handler
|
// Get the handler
|
||||||
AbstractDatabaseHandler<T> configHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(getInstance().getClass());
|
AbstractDatabaseHandler<T> configHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(getInstance().getClass());
|
||||||
|
@ -23,11 +23,11 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable {
|
|||||||
public IslandBaseEvent(Island island) {
|
public IslandBaseEvent(Island island) {
|
||||||
super();
|
super();
|
||||||
this.island = island;
|
this.island = island;
|
||||||
this.playerUUID = island == null ? null : island.getOwner();
|
playerUUID = island == null ? null : island.getOwner();
|
||||||
this.admin = false;
|
admin = false;
|
||||||
this.location = island == null ? null : island.getCenter();
|
location = island == null ? null : island.getCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param island
|
* @param island
|
||||||
* @param playerUUID
|
* @param playerUUID
|
||||||
@ -46,14 +46,14 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable {
|
|||||||
* @return the island involved in this event
|
* @return the island involved in this event
|
||||||
*/
|
*/
|
||||||
public Island getIsland(){
|
public Island getIsland(){
|
||||||
return this.island;
|
return island;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the owner of the island
|
* @return the owner of the island
|
||||||
*/
|
*/
|
||||||
public UUID getOwner() {
|
public UUID getOwner() {
|
||||||
return this.getOwner();
|
return getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +84,6 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
cancelled = cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
|
|||||||
public abstract class PremadeEvent extends Event {
|
public abstract class PremadeEvent extends Event {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -57,14 +57,14 @@ public class AddonEvent {
|
|||||||
|
|
||||||
public AddonBaseEvent build() {
|
public AddonBaseEvent build() {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case ENABLE:
|
case ENABLE:
|
||||||
return new AddonEnableEvent(addon);
|
return new AddonEnableEvent(addon);
|
||||||
case DISABLE:
|
case DISABLE:
|
||||||
return new AddonDisableEvent(addon);
|
return new AddonDisableEvent(addon);
|
||||||
case LOAD:
|
case LOAD:
|
||||||
return new AddonLoadEvent(addon);
|
return new AddonLoadEvent(addon);
|
||||||
default:
|
default:
|
||||||
return new AddonGeneralEvent(addon);
|
return new AddonGeneralEvent(addon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class CommandEvent extends PremadeEvent implements Cancellable {
|
|||||||
private final Command command;
|
private final Command command;
|
||||||
private final String label;
|
private final String label;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
private CommandEvent(CommandSender sender, Command command, String label, String[] args) {
|
private CommandEvent(CommandSender sender, Command command, String label, String[] args) {
|
||||||
super();
|
super();
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
@ -32,14 +32,14 @@ public class CommandEvent extends PremadeEvent implements Cancellable {
|
|||||||
public static CommandEventBuilder builder() {
|
public static CommandEventBuilder builder() {
|
||||||
return new CommandEventBuilder();
|
return new CommandEventBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CommandEventBuilder {
|
public static class CommandEventBuilder {
|
||||||
// Here field are NOT final. They are just used for the building.
|
// Here field are NOT final. They are just used for the building.
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
private Command command;
|
private Command command;
|
||||||
private String label;
|
private String label;
|
||||||
private String[] args;
|
private String[] args;
|
||||||
|
|
||||||
public CommandEventBuilder setSender(CommandSender sender) {
|
public CommandEventBuilder setSender(CommandSender sender) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
return this;
|
return this;
|
||||||
@ -63,7 +63,7 @@ public class CommandEvent extends PremadeEvent implements Cancellable {
|
|||||||
public CommandEvent build() {
|
public CommandEvent build() {
|
||||||
return new CommandEvent(sender, command, label, args);
|
return new CommandEvent(sender, command, label, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandSender getSender() {
|
public CommandSender getSender() {
|
||||||
@ -89,6 +89,6 @@ public class CommandEvent extends PremadeEvent implements Cancellable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean arg0) {
|
public void setCancelled(boolean arg0) {
|
||||||
cancelled = arg0;
|
cancelled = arg0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ public class FlagChangeEvent extends IslandBaseEvent {
|
|||||||
* @return the edited flag
|
* @return the edited flag
|
||||||
*/
|
*/
|
||||||
public Flag getFlag() {
|
public Flag getFlag() {
|
||||||
return this.editedFlag;
|
return editedFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return enabled/disabled
|
* @return enabled/disabled
|
||||||
*/
|
*/
|
||||||
public boolean getSetTo() {
|
public boolean getSetTo() {
|
||||||
return this.setTo;
|
return setTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,10 @@ public class IslandEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IslandEventBuilder location(Location center) {
|
public IslandEventBuilder location(Location center) {
|
||||||
this.location = center;
|
location = center;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IslandBaseEvent build() {
|
public IslandBaseEvent build() {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
@ -194,7 +194,7 @@ public class IslandEvent {
|
|||||||
BSkyBlock.getInstance().getServer().getPluginManager().callEvent(general);
|
BSkyBlock.getInstance().getServer().getPluginManager().callEvent(general);
|
||||||
return general;
|
return general;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable {
|
|||||||
/**
|
/**
|
||||||
* Called to create the event
|
* Called to create the event
|
||||||
* @param user - the UUID of the player who launched the purge, may be null if purge is launched using the console.
|
* @param user - the UUID of the player who launched the purge, may be null if purge is launched using the console.
|
||||||
* @param islandsList - the list of islands to remove, based on their leader's UUID
|
* @param islandsList - the list of islands to remove, based on their leader's UUID
|
||||||
*/
|
*/
|
||||||
public PurgeStartEvent(UUID user, List<UUID> islandsList) {
|
public PurgeStartEvent(UUID user, List<UUID> islandsList) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
@ -35,14 +35,14 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable {
|
|||||||
* @return the user who launched the purge, may be null if purge is launched using the console.
|
* @return the user who launched the purge, may be null if purge is launched using the console.
|
||||||
*/
|
*/
|
||||||
public UUID getUser( ){
|
public UUID getUser( ){
|
||||||
return this.user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list of islands to remove, based on their leader's UUID
|
* @return the list of islands to remove, based on their leader's UUID
|
||||||
*/
|
*/
|
||||||
public List<UUID> getIslandsList() {
|
public List<UUID> getIslandsList() {
|
||||||
return this.islandsList;
|
return islandsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +50,9 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable {
|
|||||||
* @param - the owner's UUID from the island to remove
|
* @param - the owner's UUID from the island to remove
|
||||||
*/
|
*/
|
||||||
public void add(UUID islandOwner) {
|
public void add(UUID islandOwner) {
|
||||||
if(!this.islandsList.contains(islandOwner)) islandsList.add(islandOwner);
|
if(!islandsList.contains(islandOwner)) {
|
||||||
|
islandsList.add(islandOwner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +60,9 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable {
|
|||||||
* @param - the owner's UUID from the island to remove
|
* @param - the owner's UUID from the island to remove
|
||||||
*/
|
*/
|
||||||
public void remove(UUID islandOwner) {
|
public void remove(UUID islandOwner) {
|
||||||
if(this.islandsList.contains(islandOwner)) islandsList.remove(islandOwner);
|
if(islandsList.contains(islandOwner)) {
|
||||||
|
islandsList.remove(islandOwner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,6 +80,6 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
cancelled = cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,10 +134,10 @@ public class TeamEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TeamEventBuilder location(Location center) {
|
public TeamEventBuilder location(Location center) {
|
||||||
this.location = center;
|
location = center;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IslandBaseEvent build() {
|
public IslandBaseEvent build() {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case JOIN:
|
case JOIN:
|
||||||
|
@ -12,15 +12,15 @@ public class Flag implements Comparable<Flag> {
|
|||||||
PROTECTION,
|
PROTECTION,
|
||||||
SETTING
|
SETTING
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final PanelItem icon;
|
private final PanelItem icon;
|
||||||
private final Listener listener;
|
private final Listener listener;
|
||||||
private final FlagType type;
|
private final FlagType type;
|
||||||
private boolean defaultSetting;
|
private boolean defaultSetting;
|
||||||
|
|
||||||
public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
|
public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
|
||||||
this.id = id2;
|
id = id2;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -17,7 +17,7 @@ public class FlagBuilder {
|
|||||||
private FlagType type = FlagType.PROTECTION;
|
private FlagType type = FlagType.PROTECTION;
|
||||||
|
|
||||||
public FlagBuilder id(String string) {
|
public FlagBuilder id(String string) {
|
||||||
this.id = string;
|
id = string;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,17 +42,17 @@ public class FlagBuilder {
|
|||||||
public Flag build() {
|
public Flag build() {
|
||||||
return new Flag(id, icon, listener, defaultSetting, type);
|
return new Flag(id, icon, listener, defaultSetting, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default setting for this flag in the world
|
* Sets the default setting for this flag in the world
|
||||||
* @param setting
|
* @param setting
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public FlagBuilder allowedByDefault(boolean setting) {
|
public FlagBuilder allowedByDefault(boolean setting) {
|
||||||
this.defaultSetting = setting;
|
defaultSetting = setting;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the type of this flag
|
* Set the type of this flag
|
||||||
* @param type {@link FlagType}
|
* @param type {@link FlagType}
|
||||||
@ -69,7 +69,7 @@ public class FlagBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public FlagBuilder id(Enum<?> flag) {
|
public FlagBuilder id(Enum<?> flag) {
|
||||||
this.id = flag.name();
|
id = flag.name();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class BSBLocale {
|
|||||||
|
|
||||||
public BSBLocale(Locale locale, File file) {
|
public BSBLocale(Locale locale, File file) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.config = YamlConfiguration.loadConfiguration(file);
|
config = YamlConfiguration.loadConfiguration(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +35,9 @@ public class BSBLocale {
|
|||||||
* @return the locale language
|
* @return the locale language
|
||||||
*/
|
*/
|
||||||
public String getLanguage(){
|
public String getLanguage(){
|
||||||
if(locale == null) return "unknown";
|
if(locale == null) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
return locale.getDisplayLanguage();
|
return locale.getDisplayLanguage();
|
||||||
}
|
}
|
||||||
@ -45,7 +47,9 @@ public class BSBLocale {
|
|||||||
* @return the locale country
|
* @return the locale country
|
||||||
*/
|
*/
|
||||||
public String getCountry(){
|
public String getCountry(){
|
||||||
if(locale == null) return "unknown";
|
if(locale == null) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
return locale.getDisplayCountry();
|
return locale.getDisplayCountry();
|
||||||
}
|
}
|
||||||
@ -55,7 +59,7 @@ public class BSBLocale {
|
|||||||
* @return the locale language tag
|
* @return the locale language tag
|
||||||
*/
|
*/
|
||||||
public String toLanguageTag(){
|
public String toLanguageTag(){
|
||||||
return this.locale.toLanguageTag();
|
return locale.toLanguageTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,7 @@ public class Panel {
|
|||||||
// If size is undefined (0) then use the number of items
|
// If size is undefined (0) then use the number of items
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
size = items.keySet().size();
|
size = items.keySet().size();
|
||||||
}
|
}
|
||||||
// Create panel
|
// Create panel
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
// Make sure size is a multiple of 9
|
// Make sure size is a multiple of 9
|
||||||
|
@ -30,11 +30,11 @@ public class PanelItem {
|
|||||||
meta = icon.getItemMeta();
|
meta = icon.getItemMeta();
|
||||||
|
|
||||||
this.clickHandler = clickHandler;
|
this.clickHandler = clickHandler;
|
||||||
|
|
||||||
// Create the final item
|
// Create the final item
|
||||||
this.setName(name);
|
setName(name);
|
||||||
this.setDescription(description);
|
setDescription(description);
|
||||||
this.setGlow(glow);
|
setGlow(glow);
|
||||||
|
|
||||||
// Set flags to neaten up the view
|
// Set flags to neaten up the view
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||||
@ -78,10 +78,11 @@ public class PanelItem {
|
|||||||
|
|
||||||
public void setGlow(boolean glow) {
|
public void setGlow(boolean glow) {
|
||||||
this.glow = glow;
|
this.glow = glow;
|
||||||
if (glow)
|
if (glow) {
|
||||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, true);
|
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, true);
|
||||||
else
|
} else {
|
||||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, false);
|
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +11,7 @@ public interface PanelListener {
|
|||||||
* This is called when the panel is first setup
|
* This is called when the panel is first setup
|
||||||
*/
|
*/
|
||||||
void setup();
|
void setup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the panel is clicked
|
* Called when the panel is clicked
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -27,27 +27,27 @@ public class PanelBuilder {
|
|||||||
* @return PanelBuilder
|
* @return PanelBuilder
|
||||||
*/
|
*/
|
||||||
public PanelBuilder addItem(int slot, PanelItem item) {
|
public PanelBuilder addItem(int slot, PanelItem item) {
|
||||||
this.items.put(slot, item);
|
items.put(slot, item);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int nextSlot() {
|
public int nextSlot() {
|
||||||
if (this.items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return items.lastEntry().getKey() + 1;
|
return items.lastEntry().getKey() + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a slot is occupied in the panel or not
|
* Checks if a slot is occupied in the panel or not
|
||||||
* @param slot to check
|
* @param slot to check
|
||||||
* @return true or false
|
* @return true or false
|
||||||
*/
|
*/
|
||||||
public boolean slotOccupied(int slot) {
|
public boolean slotOccupied(int slot) {
|
||||||
return this.items.containsKey(slot);
|
return items.containsKey(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the panel
|
* Build the panel
|
||||||
* @return Panel
|
* @return Panel
|
||||||
@ -63,9 +63,9 @@ public class PanelBuilder {
|
|||||||
*/
|
*/
|
||||||
public PanelBuilder addItem(PanelItem item) {
|
public PanelBuilder addItem(PanelItem item) {
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
this.items.put(0, item);
|
items.put(0, item);
|
||||||
} else {
|
} else {
|
||||||
this.items.put(items.lastEntry().getKey() + 1, item);
|
items.put(items.lastEntry().getKey() + 1, item);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ public class PanelItemBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PanelItemBuilder name(String name) {
|
public PanelItemBuilder name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PanelItemBuilder description(List<String> description) {
|
public PanelItemBuilder description(List<String> description) {
|
||||||
@ -47,7 +47,7 @@ public class PanelItemBuilder {
|
|||||||
this.description.add(description);
|
this.description.add(description);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PanelItemBuilder glow(boolean glow) {
|
public PanelItemBuilder glow(boolean glow) {
|
||||||
this.glow = glow;
|
this.glow = glow;
|
||||||
return this;
|
return this;
|
||||||
@ -59,8 +59,9 @@ public class PanelItemBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PanelItem build() {
|
public PanelItem build() {
|
||||||
if (icon == null)
|
if (icon == null) {
|
||||||
Bukkit.getLogger().info("DEBUG: icon is null");
|
Bukkit.getLogger().info("DEBUG: icon is null");
|
||||||
|
}
|
||||||
return new PanelItem(icon, name, description, glow, clickHandler);
|
return new PanelItem(icon, name, description, glow, clickHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ public class AdminCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "admin.*");
|
setPermission(Constants.PERMPREFIX + "admin.*");
|
||||||
this.setOnlyPlayer(false);
|
setOnlyPlayer(false);
|
||||||
this.setDescription("admin.help.description");
|
setDescription("admin.help.description");
|
||||||
new AdminVersionCommand(this);
|
new AdminVersionCommand(this);
|
||||||
new AdminReloadCommand(this);
|
new AdminReloadCommand(this);
|
||||||
new AdminTeleportCommand(this);
|
new AdminTeleportCommand(this);
|
||||||
|
@ -27,10 +27,10 @@ public class IslandCommand extends CompositeCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setDescription("commands.island.help.description");
|
setDescription("commands.island.help.description");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
// Permission
|
// Permission
|
||||||
this.setPermission(Constants.PERMPREFIX + "island");
|
setPermission(Constants.PERMPREFIX + "island");
|
||||||
// Set up subcommands
|
// Set up subcommands
|
||||||
new IslandAboutCommand(this);
|
new IslandAboutCommand(this);
|
||||||
new IslandCreateCommand(this);
|
new IslandCreateCommand(this);
|
||||||
@ -47,19 +47,19 @@ public class IslandCommand extends CompositeCommand {
|
|||||||
public boolean execute(User user, List<String> args) {
|
public boolean execute(User user, List<String> args) {
|
||||||
// If this player does not have an island, create one
|
// If this player does not have an island, create one
|
||||||
if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) {
|
if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) {
|
||||||
Optional<CompositeCommand> subCreate = this.getSubCommand("create");
|
Optional<CompositeCommand> subCreate = getSubCommand("create");
|
||||||
if (subCreate.isPresent()) {
|
if (subCreate.isPresent()) {
|
||||||
subCreate.get().execute(user, new ArrayList<>());
|
subCreate.get().execute(user, new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Optional<CompositeCommand> go = this.getSubCommand("go");
|
Optional<CompositeCommand> go = getSubCommand("go");
|
||||||
// Otherwise, currently, just go home
|
// Otherwise, currently, just go home
|
||||||
if (go.isPresent()) {
|
if (go.isPresent()) {
|
||||||
go.get().execute(user, new ArrayList<>());
|
go.get().execute(user, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.admin;
|
package us.tastybento.bskyblock.commands.admin;
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "admin.tp");
|
setPermission(Constants.PERMPREFIX + "admin.tp");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.admin.tp.description");
|
setDescription("commands.admin.tp.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,7 +29,7 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.admin.tp.help");
|
user.sendMessage("commands.admin.tp.help");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert name to a UUID
|
// Convert name to a UUID
|
||||||
final UUID targetUUID = getPlayers().getUUID(args.get(0));
|
final UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||||
if (targetUUID == null) {
|
if (targetUUID == null) {
|
||||||
@ -38,10 +38,10 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
} else {
|
} else {
|
||||||
if (getPlayers().hasIsland(targetUUID) || getPlayers().inTeam(targetUUID)) {
|
if (getPlayers().hasIsland(targetUUID) || getPlayers().inTeam(targetUUID)) {
|
||||||
Location warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getIslandWorld());
|
Location warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getIslandWorld());
|
||||||
if (this.getLabel().equals("tpnether")) {
|
if (getLabel().equals("tpnether")) {
|
||||||
warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld());
|
warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld());
|
||||||
} else if (this.getLabel().equals("tpend")) {
|
} else if (getLabel().equals("tpend")) {
|
||||||
warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getEndWorld());
|
warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getEndWorld());
|
||||||
}
|
}
|
||||||
// Other wise, go to a safe spot
|
// Other wise, go to a safe spot
|
||||||
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
||||||
|
@ -15,7 +15,7 @@ public class AdminVersionCommand extends CompositeCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
// Permission
|
// Permission
|
||||||
this.setPermission(Constants.PERMPREFIX + "admin.version");
|
setPermission(Constants.PERMPREFIX + "admin.version");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,25 +11,25 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
* This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command.
|
* This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command.
|
||||||
* The number of homes can change depending on the player's permissions and config.yml settings.
|
* The number of homes can change depending on the player's permissions and config.yml settings.
|
||||||
* This is an example of a custom help as much as anything.
|
* This is an example of a custom help as much as anything.
|
||||||
*
|
*
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
||||||
|
|
||||||
public CustomIslandMultiHomeHelp(CompositeCommand parent) {
|
public CustomIslandMultiHomeHelp(CompositeCommand parent) {
|
||||||
super(parent, "help");
|
super(parent, "help");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
// Inherit parameters from the respective parent class - in this case, only /island go and /island sethome
|
// Inherit parameters from the respective parent class - in this case, only /island go and /island sethome
|
||||||
this.setParameters(parent.getParameters());
|
setParameters(parent.getParameters());
|
||||||
this.setDescription(parent.getDescription());
|
setDescription(parent.getDescription());
|
||||||
this.setPermission(parent.getPermission());
|
setPermission(parent.getPermission());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, List<String> args) {
|
public boolean execute(User user, List<String> args) {
|
||||||
// This will only be shown if it is for a player
|
// This will only be shown if it is for a player
|
||||||
@ -56,6 +56,6 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ public class IslandAboutCommand extends CompositeCommand {
|
|||||||
public IslandAboutCommand(CompositeCommand islandCommand) {
|
public IslandAboutCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "about", "ab");
|
super(islandCommand, "about", "ab");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setDescription("commands.island.about.description");
|
setDescription("commands.island.about.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, List<String> args) {
|
public boolean execute(User user, List<String> args) {
|
||||||
user.sendRawMessage("About " + BSkyBlock.getInstance().getDescription().getName() + " v" + BSkyBlock.getInstance().getDescription().getVersion() + ":");
|
user.sendRawMessage("About " + BSkyBlock.getInstance().getDescription().getName() + " v" + BSkyBlock.getInstance().getDescription().getVersion() + ":");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.island;
|
package us.tastybento.bskyblock.commands.island;
|
||||||
|
|
||||||
@ -23,12 +23,12 @@ public class IslandCreateCommand extends CompositeCommand {
|
|||||||
public IslandCreateCommand(IslandCommand islandCommand) {
|
public IslandCreateCommand(IslandCommand islandCommand) {
|
||||||
super(islandCommand, "create", "auto");
|
super(islandCommand, "create", "auto");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.create");
|
setPermission(Constants.PERMPREFIX + "island.create");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.create.description");
|
setDescription("commands.island.create.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -41,7 +41,7 @@ public class IslandCreateCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getPlayers().inTeam(user.getUniqueId())) {
|
if (getPlayers().inTeam(user.getUniqueId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.island.create.creating-island");
|
user.sendMessage("commands.island.create.creating-island");
|
||||||
createIsland(user);
|
createIsland(user);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.island;
|
package us.tastybento.bskyblock.commands.island;
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ public class IslandGoCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.home");
|
setPermission(Constants.PERMPREFIX + "island.home");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.go.description");
|
setDescription("commands.island.go.description");
|
||||||
new CustomIslandMultiHomeHelp(this);
|
new CustomIslandMultiHomeHelp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ public class IslandResetCommand extends CompositeCommand {
|
|||||||
public IslandResetCommand(CompositeCommand islandCommand) {
|
public IslandResetCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "reset", "restart");
|
super(islandCommand, "reset", "restart");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.create");
|
setPermission(Constants.PERMPREFIX + "island.create");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.reset.description");
|
setDescription("commands.island.reset.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,7 +36,7 @@ public class IslandResetCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
if (!getIslands().isOwner(user.getUniqueId())) {
|
if (!getIslands().isOwner(user.getUniqueId())) {
|
||||||
user.sendMessage("general.errors.not-leader");
|
user.sendMessage("general.errors.not-leader");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getPlugin().getPlayers().inTeam(user.getUniqueId())) {
|
if (getPlugin().getPlayers().inTeam(user.getUniqueId())) {
|
||||||
user.sendMessage("commands.island.reset.must-remove-members");
|
user.sendMessage("commands.island.reset.must-remove-members");
|
||||||
@ -46,15 +46,18 @@ public class IslandResetCommand extends CompositeCommand {
|
|||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
// Get the player's old island
|
// Get the player's old island
|
||||||
Island oldIsland = getIslands().getIsland(player.getUniqueId());
|
Island oldIsland = getIslands().getIsland(player.getUniqueId());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
|
getPlugin().getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
|
||||||
|
}
|
||||||
// Remove them from this island (it still exists and will be deleted later)
|
// Remove them from this island (it still exists and will be deleted later)
|
||||||
getIslands().removePlayer(player.getUniqueId());
|
getIslands().removePlayer(player.getUniqueId());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
|
getPlugin().getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
|
||||||
|
}
|
||||||
// Create new island and then delete the old one
|
// Create new island and then delete the old one
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: making new island ");
|
getPlugin().getLogger().info("DEBUG: making new island ");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
NewIsland.builder(getPlugin())
|
NewIsland.builder(getPlugin())
|
||||||
.player(player)
|
.player(player)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.island;
|
package us.tastybento.bskyblock.commands.island;
|
||||||
|
|
||||||
@ -19,12 +19,12 @@ public class IslandResetnameCommand extends CompositeCommand {
|
|||||||
public IslandResetnameCommand(CompositeCommand islandCommand) {
|
public IslandResetnameCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "resetname");
|
super(islandCommand, "resetname");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.name");
|
setPermission(Constants.PERMPREFIX + "island.name");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.resetname.description");
|
setDescription("commands.island.resetname.description");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.sethome");
|
setPermission(Constants.PERMPREFIX + "island.sethome");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.sethome.description");
|
setDescription("commands.island.sethome.description");
|
||||||
new CustomIslandMultiHomeHelp(this);
|
new CustomIslandMultiHomeHelp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
if (!getPlugin().getIslands().playerIsOnIsland(user)) {
|
if (!getPlugin().getIslands().playerIsOnIsland(user)) {
|
||||||
user.sendMessage("commands.island.sethome.must-be-on-your-island");
|
user.sendMessage("commands.island.sethome.must-be-on-your-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
// island sethome
|
// island sethome
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.island;
|
package us.tastybento.bskyblock.commands.island;
|
||||||
|
|
||||||
@ -23,13 +23,13 @@ public class IslandSetnameCommand extends CompositeCommand {
|
|||||||
public IslandSetnameCommand(CompositeCommand islandCommand) {
|
public IslandSetnameCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "setname");
|
super(islandCommand, "setname");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.name");
|
setPermission(Constants.PERMPREFIX + "island.name");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setParameters("commands.island.setname.parameters");
|
setParameters("commands.island.setname.parameters");
|
||||||
this.setDescription("commands.island.setname.description");
|
setDescription("commands.island.setname.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -69,9 +69,11 @@ public class IslandSetnameCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the name
|
// Set the name
|
||||||
if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format"))
|
if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format")) {
|
||||||
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
|
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
|
||||||
else getIslands().getIsland(playerUUID).setName(name);
|
} else {
|
||||||
|
getIslands().getIsland(playerUUID).setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,21 +20,21 @@ import us.tastybento.bskyblock.api.commands.User;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractIslandTeamCommand extends CompositeCommand {
|
public abstract class AbstractIslandTeamCommand extends CompositeCommand {
|
||||||
|
|
||||||
protected final static boolean DEBUG = false;
|
protected final static boolean DEBUG = false;
|
||||||
protected static BiMap<UUID, UUID> inviteList = HashBiMap.create();
|
protected static BiMap<UUID, UUID> inviteList = HashBiMap.create();
|
||||||
// The time a player has to wait until they can reset their island again
|
// The time a player has to wait until they can reset their island again
|
||||||
protected static HashMap<UUID, Long> resetWaitTime = new HashMap<>();
|
protected static HashMap<UUID, Long> resetWaitTime = new HashMap<>();
|
||||||
protected static Set<UUID> leavingPlayers = new HashSet<>();
|
protected static Set<UUID> leavingPlayers = new HashSet<>();
|
||||||
protected static Set<UUID> kickingPlayers = new HashSet<>();
|
protected static Set<UUID> kickingPlayers = new HashSet<>();
|
||||||
|
|
||||||
// TODO: It would be good if these could be auto-provided
|
// TODO: It would be good if these could be auto-provided
|
||||||
protected User user;
|
protected User user;
|
||||||
|
|
||||||
public AbstractIslandTeamCommand(CompositeCommand command, String label, String... aliases) {
|
public AbstractIslandTeamCommand(CompositeCommand command, String label, String... aliases) {
|
||||||
super(command, label,aliases);
|
super(command, label,aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a timeout for player into the Hashmap resetWaitTime
|
* Sets a timeout for player into the Hashmap resetWaitTime
|
||||||
*
|
*
|
||||||
|
@ -23,9 +23,9 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.team.description");
|
setDescription("commands.island.team.description");
|
||||||
|
|
||||||
new IslandTeamInviteCommand(this);
|
new IslandTeamInviteCommand(this);
|
||||||
new IslandTeamLeaveCommand(this);
|
new IslandTeamLeaveCommand(this);
|
||||||
@ -36,17 +36,20 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, List<String> args) {
|
public boolean execute(User user, List<String> args) {
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: executing team command for " + playerUUID);
|
getPlugin().getLogger().info("DEBUG: executing team command for " + playerUUID);
|
||||||
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(playerUUID))
|
.getIsland(playerUUID))
|
||||||
.reason(TeamEvent.Reason.INFO)
|
.reason(TeamEvent.Reason.INFO)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return true;
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UUID teamLeaderUUID = getTeamLeader(user);
|
UUID teamLeaderUUID = getTeamLeader(user);
|
||||||
Set<UUID> teamMembers = getMembers(user);
|
Set<UUID> teamMembers = getMembers(user);
|
||||||
if (teamLeaderUUID.equals(playerUUID)) {
|
if (teamLeaderUUID.equals(playerUUID)) {
|
||||||
@ -69,9 +72,11 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do some sanity checking
|
// Do some sanity checking
|
||||||
if (maxSize < 1) maxSize = 1;
|
if (maxSize < 1) {
|
||||||
|
maxSize = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teamMembers.size() < maxSize) {
|
if (teamMembers.size() < maxSize) {
|
||||||
user.sendMessage("commands.island.team.invite.you-can-invite", "[number]", String.valueOf(maxSize - teamMembers.size()));
|
user.sendMessage("commands.island.team.invite.you-can-invite", "[number]", String.valueOf(maxSize - teamMembers.size()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,22 +18,23 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
|||||||
public IslandTeamInviteAcceptCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
public IslandTeamInviteAcceptCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
||||||
super(islandTeamInviteCommand, "accept");
|
super(islandTeamInviteCommand, "accept");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.team.invite.accept.description");
|
setDescription("commands.island.team.invite.accept.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, List<String> args) {
|
public boolean execute(User user, List<String> args) {
|
||||||
|
|
||||||
Bukkit.getLogger().info("DEBUG: accept - " + inviteList.toString());
|
Bukkit.getLogger().info("DEBUG: accept - " + inviteList.toString());
|
||||||
|
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
if(!inviteList.containsKey(playerUUID))
|
if(!inviteList.containsKey(playerUUID)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
// Check if player has been invited
|
// Check if player has been invited
|
||||||
if (!inviteList.containsKey(playerUUID)) {
|
if (!inviteList.containsKey(playerUUID)) {
|
||||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||||
@ -51,20 +52,24 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
|||||||
inviteList.remove(playerUUID);
|
inviteList.remove(playerUUID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: Invite is valid");
|
getPlugin().getLogger().info("DEBUG: Invite is valid");
|
||||||
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(prospectiveTeamLeaderUUID))
|
.getIsland(prospectiveTeamLeaderUUID))
|
||||||
.reason(TeamEvent.Reason.JOIN)
|
.reason(TeamEvent.Reason.JOIN)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return true;
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Remove the invite
|
// Remove the invite
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: Removing player from invite list");
|
getPlugin().getLogger().info("DEBUG: Removing player from invite list");
|
||||||
|
}
|
||||||
inviteList.remove(playerUUID);
|
inviteList.remove(playerUUID);
|
||||||
// Put player into Spectator mode
|
// Put player into Spectator mode
|
||||||
user.setGameMode(GameMode.SPECTATOR);
|
user.setGameMode(GameMode.SPECTATOR);
|
||||||
@ -100,8 +105,9 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
|||||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());
|
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());
|
||||||
}
|
}
|
||||||
getIslands().save(false);
|
getIslands().save(false);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMemberSet().toString());
|
getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMemberSet().toString());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.team.invite.description");
|
setDescription("commands.island.team.invite.description");
|
||||||
|
|
||||||
new IslandTeamInviteAcceptCommand(this);
|
new IslandTeamInviteAcceptCommand(this);
|
||||||
new IslandTeamInviteRejectCommand(this);
|
new IslandTeamInviteRejectCommand(this);
|
||||||
@ -106,7 +106,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do some sanity checking
|
// Do some sanity checking
|
||||||
if (maxSize < 1) maxSize = 1;
|
if (maxSize < 1) {
|
||||||
|
maxSize = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (teamMembers.size() < maxSize) {
|
if (teamMembers.size() < maxSize) {
|
||||||
// If that player already has an invite out then retract it.
|
// If that player already has an invite out then retract it.
|
||||||
@ -122,7 +124,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
|||||||
.involvedPlayer(invitedPlayerUUID)
|
.involvedPlayer(invitedPlayerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return true;
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Put the invited player (key) onto the list with inviter (value)
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||||
inviteList.put(invitedPlayerUUID, playerUUID);
|
inviteList.put(invitedPlayerUUID, playerUUID);
|
||||||
|
@ -13,12 +13,12 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
|
|||||||
public IslandTeamInviteRejectCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
public IslandTeamInviteRejectCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
||||||
super(islandTeamInviteCommand, "reject");
|
super(islandTeamInviteCommand, "reject");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.team.invite.reject.description");
|
setDescription("commands.island.team.invite.reject.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,12 +29,14 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
|
|||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(inviteList.get(playerUUID)))
|
.getIsland(inviteList.get(playerUUID)))
|
||||||
.reason(TeamEvent.Reason.REJECT)
|
.reason(TeamEvent.Reason.REJECT)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return false;
|
if (event.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove this player from the global invite list
|
// Remove this player from the global invite list
|
||||||
inviteList.remove(user.getUniqueId());
|
inviteList.remove(user.getUniqueId());
|
||||||
|
@ -20,10 +20,10 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setParameters("commands.island.team.kick.parameters");
|
setParameters("commands.island.team.kick.parameters");
|
||||||
this.setDescription("commands.island.team.kick.description");
|
setDescription("commands.island.team.kick.description");
|
||||||
kickSet = new HashSet<>();
|
kickSet = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,11 +46,11 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
|||||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||||
if (targetUUID == null) {
|
if (targetUUID == null) {
|
||||||
user.sendMessage("general.errors.unknown-player");
|
user.sendMessage("general.errors.unknown-player");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!getIslands().getMembers(user.getUniqueId()).contains(targetUUID)) {
|
if (!getIslands().getMembers(user.getUniqueId()).contains(targetUUID)) {
|
||||||
user.sendMessage("general.errors.not-in-team");
|
user.sendMessage("general.errors.not-in-team");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) {
|
if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) {
|
||||||
kickSet.remove(targetUUID);
|
kickSet.remove(targetUUID);
|
||||||
|
@ -20,9 +20,9 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setDescription("commands.island.team.leave.description");
|
setDescription("commands.island.team.leave.description");
|
||||||
leaveSet = new HashSet<>();
|
leaveSet = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
|
|||||||
public IslandTeamPromoteCommand(IslandTeamCommand islandTeamCommand) {
|
public IslandTeamPromoteCommand(IslandTeamCommand islandTeamCommand) {
|
||||||
super(islandTeamCommand, "promote");
|
super(islandTeamCommand, "promote");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setParameters("commands.island.team.promote.parameters");
|
setParameters("commands.island.team.promote.parameters");
|
||||||
this.setDescription("commands.island.team.promote.description");
|
setDescription("commands.island.team.promote.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,13 +21,13 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
|
|||||||
public IslandTeamSetownerCommand(IslandTeamCommand islandTeamCommand) {
|
public IslandTeamSetownerCommand(IslandTeamCommand islandTeamCommand) {
|
||||||
super(islandTeamCommand, "setleader");
|
super(islandTeamCommand, "setleader");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Constants.PERMPREFIX + "island.team");
|
setPermission(Constants.PERMPREFIX + "island.team");
|
||||||
this.setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
this.setParameters("commands.island.team.setowner.parameters");
|
setParameters("commands.island.team.setowner.parameters");
|
||||||
this.setDescription("commands.island.team.setowner.description");
|
setDescription("commands.island.team.setowner.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,7 +75,9 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return false;
|
if (event.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// target is the new leader
|
// target is the new leader
|
||||||
getIslands().getIsland(playerUUID).setOwner(targetUUID);
|
getIslands().getIsland(playerUUID).setOwner(targetUUID);
|
||||||
|
@ -14,7 +14,9 @@ public abstract class BSBDatabase {
|
|||||||
*/
|
*/
|
||||||
public static BSBDatabase getDatabase(){
|
public static BSBDatabase getDatabase(){
|
||||||
for(DatabaseType type : DatabaseType.values()){
|
for(DatabaseType type : DatabaseType.values()){
|
||||||
if(type == BSkyBlock.getInstance().getSettings().getDatabaseType()) return type.database;
|
if(type == BSkyBlock.getInstance().getSettings().getDatabaseType()) {
|
||||||
|
return type.database;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return DatabaseType.FLATFILE.database;
|
return DatabaseType.FLATFILE.database;
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,11 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a YAML file and if it does not exist it is looked for in the JAR
|
* Loads a YAML file and if it does not exist it is looked for in the JAR
|
||||||
*
|
*
|
||||||
* @param fileName
|
* @param fileName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public YamlConfiguration loadYamlFile(String tableName, String fileName) {
|
public YamlConfiguration loadYamlFile(String tableName, String fileName) {
|
||||||
if (!fileName.endsWith(".yml")) {
|
if (!fileName.endsWith(".yml")) {
|
||||||
fileName = fileName + ".yml";
|
fileName = fileName + ".yml";
|
||||||
@ -77,7 +78,7 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a YAML file
|
* Saves a YAML file
|
||||||
*
|
*
|
||||||
* @param yamlConfig
|
* @param yamlConfig
|
||||||
* @param fileName
|
* @param fileName
|
||||||
*/
|
*/
|
||||||
|
@ -109,16 +109,13 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException {
|
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException {
|
||||||
List<T> list = new ArrayList<T>();
|
List<T> list = new ArrayList<>();
|
||||||
FilenameFilter ymlFilter = new FilenameFilter() {
|
FilenameFilter ymlFilter = (dir, name) -> {
|
||||||
@Override
|
String lowercaseName = name.toLowerCase();
|
||||||
public boolean accept(File dir, String name) {
|
if (lowercaseName.endsWith(".yml")) {
|
||||||
String lowercaseName = name.toLowerCase();
|
return true;
|
||||||
if (lowercaseName.endsWith(".yml")) {
|
} else {
|
||||||
return true;
|
return false;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String path = dataObject.getSimpleName();
|
String path = dataObject.getSimpleName();
|
||||||
@ -166,27 +163,30 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
||||||
// Get the write method
|
// Get the write method
|
||||||
Method method = propertyDescriptor.getWriteMethod();
|
Method method = propertyDescriptor.getWriteMethod();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: " + field.getName() + ": " + propertyDescriptor.getPropertyType().getTypeName());
|
plugin.getLogger().info("DEBUG: " + field.getName() + ": " + propertyDescriptor.getPropertyType().getTypeName());
|
||||||
|
}
|
||||||
String storageLocation = field.getName();
|
String storageLocation = field.getName();
|
||||||
// Check if there is an annotation on the field
|
// Check if there is an annotation on the field
|
||||||
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
||||||
// If there is a config annotation then do something
|
// If there is a config annotation then do something
|
||||||
if (configEntry != null) {
|
if (configEntry != null) {
|
||||||
if (!configEntry.path().isEmpty()) {
|
if (!configEntry.path().isEmpty()) {
|
||||||
storageLocation = configEntry.path();
|
storageLocation = configEntry.path();
|
||||||
}
|
}
|
||||||
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
|
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info(field.getName() + " not applicable to this game type");
|
Bukkit.getLogger().info(field.getName() + " not applicable to this game type");
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// TODO: Add handling of other ConfigEntry elements
|
// TODO: Add handling of other ConfigEntry elements
|
||||||
}
|
}
|
||||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: there is an adapter");
|
plugin.getLogger().info("DEBUG: there is an adapter");
|
||||||
|
}
|
||||||
// A conversion adapter has been defined
|
// A conversion adapter has been defined
|
||||||
Object value = config.get(storageLocation);
|
Object value = config.get(storageLocation);
|
||||||
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
|
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
|
||||||
@ -199,7 +199,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
|
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
|
||||||
}
|
}
|
||||||
// We are done here
|
// We are done here
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look in the YAML Config to see if this field exists (it should)
|
// Look in the YAML Config to see if this field exists (it should)
|
||||||
@ -216,10 +216,11 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// collectionTypes should be 2 long
|
// collectionTypes should be 2 long
|
||||||
Type keyType = collectionTypes.get(0);
|
Type keyType = collectionTypes.get(0);
|
||||||
Type valueType = collectionTypes.get(1);
|
Type valueType = collectionTypes.get(1);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: is Map or HashMap<" + keyType.getTypeName() + ", " + valueType.getTypeName() + ">");
|
plugin.getLogger().info("DEBUG: is Map or HashMap<" + keyType.getTypeName() + ", " + valueType.getTypeName() + ">");
|
||||||
|
}
|
||||||
// TODO: this may not work with all keys. Further serialization may be required.
|
// TODO: this may not work with all keys. Further serialization may be required.
|
||||||
Map<Object,Object> value = new HashMap<Object, Object>();
|
Map<Object,Object> value = new HashMap<>();
|
||||||
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
|
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
|
||||||
// Keys cannot be null - skip if they exist
|
// Keys cannot be null - skip if they exist
|
||||||
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
|
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
|
||||||
@ -240,49 +241,52 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName());
|
plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName());
|
||||||
plugin.getLogger().info("DEBUG: adding a set");
|
plugin.getLogger().info("DEBUG: adding a set");
|
||||||
}
|
}
|
||||||
// Loop through the collection resultset
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be only 1 long
|
// collectionTypes should be only 1 long
|
||||||
Type setType = collectionTypes.get(0);
|
Type setType = collectionTypes.get(0);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: is HashSet<" + setType.getTypeName() + ">");
|
plugin.getLogger().info("DEBUG: is HashSet<" + setType.getTypeName() + ">");
|
||||||
Set<Object> value = new HashSet<Object>();
|
}
|
||||||
|
Set<Object> value = new HashSet<>();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
||||||
}
|
}
|
||||||
for (Object listValue: config.getList(storageLocation)) {
|
for (Object listValue: config.getList(storageLocation)) {
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
||||||
((Set<Object>) value).add(deserialize(listValue,Class.forName(setType.getTypeName())));
|
value.add(deserialize(listValue,Class.forName(setType.getTypeName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this may not work with all keys. Further serialization may be required.
|
// TODO: this may not work with all keys. Further serialization may be required.
|
||||||
//Set<Object> value = new HashSet((List<Object>) config.getList(storageLocation));
|
//Set<Object> value = new HashSet((List<Object>) config.getList(storageLocation));
|
||||||
method.invoke(instance, value);
|
method.invoke(instance, value);
|
||||||
} else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
} else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
//plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName());
|
//plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding a set");
|
plugin.getLogger().info("DEBUG: adding a set");
|
||||||
// Loop through the collection resultset
|
}
|
||||||
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be only 1 long
|
// collectionTypes should be only 1 long
|
||||||
Type setType = collectionTypes.get(0);
|
Type setType = collectionTypes.get(0);
|
||||||
List<Object> value = new ArrayList<Object>();
|
List<Object> value = new ArrayList<>();
|
||||||
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
//plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
//plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
||||||
for (Object listValue: config.getList(storageLocation)) {
|
for (Object listValue: config.getList(storageLocation)) {
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
||||||
((List<Object>) value).add(deserialize(listValue,Class.forName(setType.getTypeName())));
|
value.add(deserialize(listValue,Class.forName(setType.getTypeName())));
|
||||||
}
|
}
|
||||||
// TODO: this may not work with all keys. Further serialization may be required.
|
// TODO: this may not work with all keys. Further serialization may be required.
|
||||||
//Set<Object> value = new HashSet((List<Object>) config.getList(storageLocation));
|
//Set<Object> value = new HashSet((List<Object>) config.getList(storageLocation));
|
||||||
method.invoke(instance, value);
|
method.invoke(instance, value);
|
||||||
} else {
|
} else {
|
||||||
// Not a collection
|
// Not a collection
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: not a collection");
|
plugin.getLogger().info("DEBUG: not a collection");
|
||||||
|
}
|
||||||
Object value = config.get(storageLocation);
|
Object value = config.get(storageLocation);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: name = " + field.getName());
|
plugin.getLogger().info("DEBUG: name = " + field.getName());
|
||||||
@ -303,6 +307,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#saveConfig(java.lang.Object)
|
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#saveConfig(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void saveSettings(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException {
|
public void saveSettings(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException {
|
||||||
configFlag = true;
|
configFlag = true;
|
||||||
saveObject(instance);
|
saveObject(instance);
|
||||||
@ -337,7 +342,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run through all the fields in the class that is being stored. EVERY field must have a get and set method
|
// Run through all the fields in the class that is being stored. EVERY field must have a get and set method
|
||||||
fields:
|
fields:
|
||||||
for (Field field : dataObject.getDeclaredFields()) {
|
for (Field field : dataObject.getDeclaredFields()) {
|
||||||
|
|
||||||
// Get the property descriptor for this field
|
// Get the property descriptor for this field
|
||||||
@ -361,16 +366,17 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
if (!configEntry.path().isEmpty()) {
|
if (!configEntry.path().isEmpty()) {
|
||||||
storageLocation = configEntry.path();
|
storageLocation = configEntry.path();
|
||||||
}
|
}
|
||||||
// TODO: add in game-specific saving
|
// TODO: add in game-specific saving
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: there is an adapter");
|
plugin.getLogger().info("DEBUG: there is an adapter");
|
||||||
// A conversion adapter has been defined
|
}
|
||||||
|
// A conversion adapter has been defined
|
||||||
try {
|
try {
|
||||||
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
|
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
@ -384,7 +390,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Depending on the vale type, it'll need serializing differenty
|
// Depending on the vale type, it'll need serializing differenty
|
||||||
// Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class
|
// Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class
|
||||||
if (method.getName().equals("getUniqueId")) {
|
if (method.getName().equals("getUniqueId")) {
|
||||||
// If the object does not have a unique name assigned to it already, one is created at random
|
// If the object does not have a unique name assigned to it already, one is created at random
|
||||||
//plugin.getLogger().info("DEBUG: uniqueId = " + value);
|
//plugin.getLogger().info("DEBUG: uniqueId = " + value);
|
||||||
String id = (String)value;
|
String id = (String)value;
|
||||||
if (value == null || id.isEmpty()) {
|
if (value == null || id.isEmpty()) {
|
||||||
@ -393,15 +399,16 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
propertyDescriptor.getWriteMethod().invoke(instance, id);
|
propertyDescriptor.getWriteMethod().invoke(instance, id);
|
||||||
}
|
}
|
||||||
// Save the name for when the file is saved
|
// Save the name for when the file is saved
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty()) {
|
||||||
filename = id;
|
filename = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Collections need special serialization
|
// Collections need special serialization
|
||||||
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
// Maps need to have keys serialized
|
// Maps need to have keys serialized
|
||||||
//plugin.getLogger().info("DEBUG: Map for " + storageLocation);
|
//plugin.getLogger().info("DEBUG: Map for " + storageLocation);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
Map<Object, Object> result = new HashMap<Object, Object>();
|
Map<Object, Object> result = new HashMap<>();
|
||||||
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
||||||
// Serialize all key types
|
// Serialize all key types
|
||||||
// TODO: also need to serialize values?
|
// TODO: also need to serialize values?
|
||||||
@ -412,10 +419,11 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
// Sets need to be serialized as string lists
|
// Sets need to be serialized as string lists
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Set for " + storageLocation);
|
plugin.getLogger().info("DEBUG: Set for " + storageLocation);
|
||||||
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
List<Object> list = new ArrayList<Object>();
|
List<Object> list = new ArrayList<>();
|
||||||
for (Object object : (Set<Object>)value) {
|
for (Object object : (Set<Object>)value) {
|
||||||
list.add(serialize(object));
|
list.add(serialize(object));
|
||||||
}
|
}
|
||||||
@ -430,7 +438,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No uniqueId in class");
|
throw new IllegalArgumentException("No uniqueId in class");
|
||||||
}
|
}
|
||||||
databaseConnecter.saveYamlFile(config, path, filename);
|
databaseConnecter.saveYamlFile(config, path, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -463,15 +471,16 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getCanonicalName());
|
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getCanonicalName());
|
||||||
plugin.getLogger().info("DEBUG: value is " + value);
|
plugin.getLogger().info("DEBUG: value is " + value);
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
plugin.getLogger().info("DEBUG: value class is " + value.getClass().getCanonicalName());
|
plugin.getLogger().info("DEBUG: value class is " + value.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If value is already null, then it can be nothing else
|
// If value is already null, then it can be nothing else
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (value instanceof String && value.equals("null")) {
|
if (value instanceof String && value.equals("null")) {
|
||||||
// If the value is null as a string, return null
|
// If the value is null as a string, return null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Bukkit may have deserialized the object already
|
// Bukkit may have deserialized the object already
|
||||||
@ -480,7 +489,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
// Types that need to be deserialized
|
// Types that need to be deserialized
|
||||||
if (clazz.equals(Long.class) && value.getClass().equals(Integer.class)) {
|
if (clazz.equals(Long.class) && value.getClass().equals(Integer.class)) {
|
||||||
return new Long((Integer)value);
|
return new Long((Integer)value);
|
||||||
}
|
}
|
||||||
if (clazz.equals(UUID.class)) {
|
if (clazz.equals(UUID.class)) {
|
||||||
value = UUID.fromString((String)value);
|
value = UUID.fromString((String)value);
|
||||||
@ -522,7 +531,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
File dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
|
File dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
|
||||||
File tableFolder = new File(dataFolder, dataObject.getSimpleName());
|
File tableFolder = new File(dataFolder, dataObject.getSimpleName());
|
||||||
if (tableFolder.exists()) {
|
if (tableFolder.exists()) {
|
||||||
|
|
||||||
File file = new File(tableFolder, fileName);
|
File file = new File(tableFolder, fileName);
|
||||||
try {
|
try {
|
||||||
Files.delete(file.toPath());
|
Files.delete(file.toPath());
|
||||||
@ -537,7 +546,9 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
||||||
if (dbConfig == null) return loadObject(uniqueId);
|
if (dbConfig == null) {
|
||||||
|
return loadObject(uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: compare the loaded with the database copy
|
// TODO: compare the loaded with the database copy
|
||||||
|
|
||||||
|
@ -70,14 +70,16 @@ public class PlayersManager{
|
|||||||
* @param async - if true, save async
|
* @param async - if true, save async
|
||||||
*/
|
*/
|
||||||
public void save(boolean async){
|
public void save(boolean async){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving " + async);
|
plugin.getLogger().info("DEBUG: saving " + async);
|
||||||
|
}
|
||||||
Collection<Players> set = Collections.unmodifiableCollection(playerCache.values());
|
Collection<Players> set = Collections.unmodifiableCollection(playerCache.values());
|
||||||
if(async){
|
if(async){
|
||||||
Runnable save = () -> {
|
Runnable save = () -> {
|
||||||
for(Players player : set){
|
for(Players player : set){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
|
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
handler.saveObject(player);
|
handler.saveObject(player);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -88,8 +90,9 @@ public class PlayersManager{
|
|||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
|
||||||
} else {
|
} else {
|
||||||
for(Players player : set){
|
for(Players player : set){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
|
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
handler.saveObject(player);
|
handler.saveObject(player);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -121,33 +124,39 @@ public class PlayersManager{
|
|||||||
* @return the players object
|
* @return the players object
|
||||||
*/
|
*/
|
||||||
public Players addPlayer(final UUID playerUUID) {
|
public Players addPlayer(final UUID playerUUID) {
|
||||||
if (playerUUID == null)
|
if (playerUUID == null) {
|
||||||
return null;
|
return null;
|
||||||
if (DEBUG)
|
}
|
||||||
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding player " + playerUUID);
|
plugin.getLogger().info("DEBUG: adding player " + playerUUID);
|
||||||
|
}
|
||||||
if (!playerCache.containsKey(playerUUID)) {
|
if (!playerCache.containsKey(playerUUID)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: player not in cache");
|
plugin.getLogger().info("DEBUG: player not in cache");
|
||||||
|
}
|
||||||
Players player = null;
|
Players player = null;
|
||||||
// If the player is in the database, load it, otherwise create a new player
|
// If the player is in the database, load it, otherwise create a new player
|
||||||
if (handler.objectExits(playerUUID.toString())) {
|
if (handler.objectExits(playerUUID.toString())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: player in database");
|
plugin.getLogger().info("DEBUG: player in database");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
player = handler.loadObject(playerUUID.toString());
|
player = handler.loadObject(playerUUID.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().severe("Could not load player " + playerUUID + " " + e.getMessage());
|
plugin.getLogger().severe("Could not load player " + playerUUID + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: new player");
|
plugin.getLogger().info("DEBUG: new player");
|
||||||
|
}
|
||||||
player = new Players(plugin, playerUUID);
|
player = new Players(plugin, playerUUID);
|
||||||
}
|
}
|
||||||
playerCache.put(playerUUID, player);
|
playerCache.put(playerUUID, player);
|
||||||
return player;
|
return player;
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: known player");
|
plugin.getLogger().info("DEBUG: known player");
|
||||||
|
}
|
||||||
return playerCache.get(playerUUID);
|
return playerCache.get(playerUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,8 +340,9 @@ public class PlayersManager{
|
|||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public void setPlayerName(User user) {
|
public void setPlayerName(User user) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Setting player name to " + user.getName() + " for " + user.getUniqueId());
|
plugin.getLogger().info("DEBUG: Setting player name to " + user.getName() + " for " + user.getUniqueId());
|
||||||
|
}
|
||||||
addPlayer(user.getUniqueId());
|
addPlayer(user.getUniqueId());
|
||||||
playerCache.get(user.getUniqueId()).setPlayerName(user.getName());
|
playerCache.get(user.getUniqueId()).setPlayerName(user.getName());
|
||||||
}
|
}
|
||||||
@ -345,14 +355,16 @@ public class PlayersManager{
|
|||||||
* @return String - playerName
|
* @return String - playerName
|
||||||
*/
|
*/
|
||||||
public String getName(UUID playerUUID) {
|
public String getName(UUID playerUUID) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Geting player name");
|
plugin.getLogger().info("DEBUG: Geting player name");
|
||||||
|
}
|
||||||
if (playerUUID == null) {
|
if (playerUUID == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: name is " + playerCache.get(playerUUID).getPlayerName());
|
plugin.getLogger().info("DEBUG: name is " + playerCache.get(playerUUID).getPlayerName());
|
||||||
|
}
|
||||||
return playerCache.get(playerUUID).getPlayerName();
|
return playerCache.get(playerUUID).getPlayerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,8 +375,9 @@ public class PlayersManager{
|
|||||||
* @return UUID of owner of island
|
* @return UUID of owner of island
|
||||||
*/
|
*/
|
||||||
public UUID getPlayerFromIslandLocation(Location loc) {
|
public UUID getPlayerFromIslandLocation(Location loc) {
|
||||||
if (loc == null)
|
if (loc == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
// Look in the grid
|
// Look in the grid
|
||||||
Optional<Island> island = plugin.getIslands().getIslandAt(loc);
|
Optional<Island> island = plugin.getIslands().getIslandAt(loc);
|
||||||
return island.map(x->x.getOwner()).orElse(null);
|
return island.map(x->x.getOwner()).orElse(null);
|
||||||
@ -425,7 +438,9 @@ public class PlayersManager{
|
|||||||
*/
|
*/
|
||||||
public String getLocale(UUID playerUUID) {
|
public String getLocale(UUID playerUUID) {
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
if (playerUUID == null) return "";
|
if (playerUUID == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return playerCache.get(playerUUID).getLocale();
|
return playerCache.get(playerUUID).getLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,8 +593,9 @@ public class PlayersManager{
|
|||||||
if (playerCache.containsKey(playerUUID)) {
|
if (playerCache.containsKey(playerUUID)) {
|
||||||
final Players player = playerCache.get(playerUUID);
|
final Players player = playerCache.get(playerUUID);
|
||||||
try {
|
try {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving player by uuid " + player.getPlayerName() + " " + playerUUID + " saved");
|
plugin.getLogger().info("DEBUG: saving player by uuid " + player.getPlayerName() + " " + playerUUID + " saved");
|
||||||
|
}
|
||||||
handler.saveObject(player);
|
handler.saveObject(player);
|
||||||
|
|
||||||
} catch (IllegalAccessException | IllegalArgumentException
|
} catch (IllegalAccessException | IllegalArgumentException
|
||||||
@ -589,8 +605,9 @@ public class PlayersManager{
|
|||||||
plugin.getLogger().severe("Could not save player to database: " + playerUUID + " " + e.getMessage());
|
plugin.getLogger().severe("Could not save player to database: " + playerUUID + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: " + playerUUID + " is not in the cache to save");
|
plugin.getLogger().info("DEBUG: " + playerUUID + " is not in the cache to save");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,14 +43,17 @@ public class IslandCache {
|
|||||||
*/
|
*/
|
||||||
public void addIsland(Island island) {
|
public void addIsland(Island island) {
|
||||||
islandsByLocation.put(island.getCenter(), island);
|
islandsByLocation.put(island.getCenter(), island);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
||||||
|
}
|
||||||
islandsByUUID.put(island.getOwner(), island);
|
islandsByUUID.put(island.getOwner(), island);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members");
|
plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members");
|
||||||
|
}
|
||||||
for (UUID member: island.getMemberSet()) {
|
for (UUID member: island.getMemberSet()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: " + member);
|
plugin.getLogger().info("DEBUG: " + member);
|
||||||
|
}
|
||||||
islandsByUUID.put(member, island);
|
islandsByUUID.put(member, island);
|
||||||
}
|
}
|
||||||
addToGrid(island);
|
addToGrid(island);
|
||||||
@ -66,12 +69,14 @@ public class IslandCache {
|
|||||||
*/
|
*/
|
||||||
private void addToGrid(Island newIsland) {
|
private void addToGrid(Island newIsland) {
|
||||||
if (islandGrid.containsKey(newIsland.getMinX())) {
|
if (islandGrid.containsKey(newIsland.getMinX())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: min x is in the grid :" + newIsland.getMinX());
|
plugin.getLogger().info("DEBUG: min x is in the grid :" + newIsland.getMinX());
|
||||||
|
}
|
||||||
TreeMap<Integer, Island> zEntry = islandGrid.get(newIsland.getMinX());
|
TreeMap<Integer, Island> zEntry = islandGrid.get(newIsland.getMinX());
|
||||||
if (zEntry.containsKey(newIsland.getMinZ())) {
|
if (zEntry.containsKey(newIsland.getMinZ())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: min z is in the grid :" + newIsland.getMinZ());
|
plugin.getLogger().info("DEBUG: min z is in the grid :" + newIsland.getMinZ());
|
||||||
|
}
|
||||||
// Island already exists
|
// Island already exists
|
||||||
Island conflict = islandGrid.get(newIsland.getMinX()).get(newIsland.getMinZ());
|
Island conflict = islandGrid.get(newIsland.getMinX()).get(newIsland.getMinZ());
|
||||||
plugin.getLogger().warning("*** Duplicate or overlapping islands! ***");
|
plugin.getLogger().warning("*** Duplicate or overlapping islands! ***");
|
||||||
@ -94,17 +99,19 @@ public class IslandCache {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Add island
|
// Add island
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
|
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
|
||||||
|
}
|
||||||
zEntry.put(newIsland.getMinZ(), newIsland);
|
zEntry.put(newIsland.getMinZ(), newIsland);
|
||||||
islandGrid.put(newIsland.getMinX(), zEntry);
|
islandGrid.put(newIsland.getMinX(), zEntry);
|
||||||
// plugin.getLogger().info("Debug: " + newIsland.toString());
|
// plugin.getLogger().info("Debug: " + newIsland.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add island
|
// Add island
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
|
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
|
||||||
TreeMap<Integer, Island> zEntry = new TreeMap<Integer, Island>();
|
}
|
||||||
|
TreeMap<Integer, Island> zEntry = new TreeMap<>();
|
||||||
zEntry.put(newIsland.getMinZ(), newIsland);
|
zEntry.put(newIsland.getMinZ(), newIsland);
|
||||||
islandGrid.put(newIsland.getMinX(), zEntry);
|
islandGrid.put(newIsland.getMinX(), zEntry);
|
||||||
}
|
}
|
||||||
@ -117,8 +124,9 @@ public class IslandCache {
|
|||||||
|
|
||||||
public Island createIsland(Island island) {
|
public Island createIsland(Island island) {
|
||||||
islandsByLocation.put(island.getCenter(), island);
|
islandsByLocation.put(island.getCenter(), island);
|
||||||
if (island.getOwner() != null)
|
if (island.getOwner() != null) {
|
||||||
islandsByUUID.put(island.getOwner(), island);
|
islandsByUUID.put(island.getOwner(), island);
|
||||||
|
}
|
||||||
addToGrid(island);
|
addToGrid(island);
|
||||||
return island;
|
return island;
|
||||||
}
|
}
|
||||||
@ -137,12 +145,14 @@ public class IslandCache {
|
|||||||
* @param owner UUID
|
* @param owner UUID
|
||||||
*/
|
*/
|
||||||
public Island createIsland(Location location, UUID owner){
|
public Island createIsland(Location location, UUID owner){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
|
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
|
||||||
|
}
|
||||||
Island island = new Island(location, owner, plugin.getSettings().getIslandProtectionRange());
|
Island island = new Island(location, owner, plugin.getSettings().getIslandProtectionRange());
|
||||||
islandsByLocation.put(location, island);
|
islandsByLocation.put(location, island);
|
||||||
if (owner != null)
|
if (owner != null) {
|
||||||
islandsByUUID.put(owner, island);
|
islandsByUUID.put(owner, island);
|
||||||
|
}
|
||||||
addToGrid(island);
|
addToGrid(island);
|
||||||
return island;
|
return island;
|
||||||
}
|
}
|
||||||
@ -163,26 +173,31 @@ public class IslandCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove from grid
|
// Remove from grid
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: deleting island at " + island.getCenter());
|
plugin.getLogger().info("DEBUG: deleting island at " + island.getCenter());
|
||||||
|
}
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
int x = island.getMinX();
|
int x = island.getMinX();
|
||||||
int z = island.getMinZ();
|
int z = island.getMinZ();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: x = " + x + " z = " + z);
|
plugin.getLogger().info("DEBUG: x = " + x + " z = " + z);
|
||||||
|
}
|
||||||
if (islandGrid.containsKey(x)) {
|
if (islandGrid.containsKey(x)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: x found");
|
plugin.getLogger().info("DEBUG: x found");
|
||||||
|
}
|
||||||
TreeMap<Integer, Island> zEntry = islandGrid.get(x);
|
TreeMap<Integer, Island> zEntry = islandGrid.get(x);
|
||||||
if (zEntry.containsKey(z)) {
|
if (zEntry.containsKey(z)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: z found - deleting the island");
|
plugin.getLogger().info("DEBUG: z found - deleting the island");
|
||||||
|
}
|
||||||
// Island exists - delete it
|
// Island exists - delete it
|
||||||
zEntry.remove(z);
|
zEntry.remove(z);
|
||||||
islandGrid.put(x, zEntry);
|
islandGrid.put(x, zEntry);
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: could not find z");
|
plugin.getLogger().info("DEBUG: could not find z");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,12 +240,14 @@ public class IslandCache {
|
|||||||
// Check if in the island range
|
// Check if in the island range
|
||||||
Island island = ent.getValue();
|
Island island = ent.getValue();
|
||||||
if (island.inIslandSpace(x, z)) {
|
if (island.inIslandSpace(x, z)) {
|
||||||
if (DEBUG2)
|
if (DEBUG2) {
|
||||||
plugin.getLogger().info("DEBUG: In island space");
|
plugin.getLogger().info("DEBUG: In island space");
|
||||||
|
}
|
||||||
return island;
|
return island;
|
||||||
}
|
}
|
||||||
if (DEBUG2)
|
if (DEBUG2) {
|
||||||
plugin.getLogger().info("DEBUG: not in island space");
|
plugin.getLogger().info("DEBUG: not in island space");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -264,8 +281,9 @@ public class IslandCache {
|
|||||||
* @return Location of player's island or null if one does not exist
|
* @return Location of player's island or null if one does not exist
|
||||||
*/
|
*/
|
||||||
public Location getIslandLocation(UUID playerUUID) {
|
public Location getIslandLocation(UUID playerUUID) {
|
||||||
if (hasIsland(playerUUID))
|
if (hasIsland(playerUUID)) {
|
||||||
return getIsland(playerUUID).getCenter();
|
return getIsland(playerUUID).getCenter();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,14 +309,16 @@ public class IslandCache {
|
|||||||
|
|
||||||
public Set<UUID> getMembers(UUID playerUUID) {
|
public Set<UUID> getMembers(UUID playerUUID) {
|
||||||
Island island = islandsByUUID.get(playerUUID);
|
Island island = islandsByUUID.get(playerUUID);
|
||||||
if (island != null)
|
if (island != null) {
|
||||||
return new HashSet<UUID>(island.getMemberSet());
|
return new HashSet<>(island.getMemberSet());
|
||||||
return new HashSet<UUID>(0);
|
}
|
||||||
|
return new HashSet<>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getTeamLeader(UUID playerUUID) {
|
public UUID getTeamLeader(UUID playerUUID) {
|
||||||
if (islandsByUUID.containsKey(playerUUID))
|
if (islandsByUUID.containsKey(playerUUID)) {
|
||||||
return islandsByUUID.get(playerUUID).getOwner();
|
return islandsByUUID.get(playerUUID).getOwner();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,35 +338,41 @@ public class IslandCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (islandsByUUID.containsKey(playerUUID) && islandsByUUID.get(playerUUID).getOwner() != null) {
|
if (islandsByUUID.containsKey(playerUUID) && islandsByUUID.get(playerUUID).getOwner() != null) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: checking for equals");
|
plugin.getLogger().info("DEBUG: checking for equals");
|
||||||
|
}
|
||||||
if (islandsByUUID.get(playerUUID).getOwner().equals(playerUUID)) {
|
if (islandsByUUID.get(playerUUID).getOwner().equals(playerUUID)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: has island");
|
plugin.getLogger().info("DEBUG: has island");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: doesn't have island");
|
plugin.getLogger().info("DEBUG: doesn't have island");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePlayer(UUID playerUUID) {
|
public void removePlayer(UUID playerUUID) {
|
||||||
Island island = islandsByUUID.get(playerUUID);
|
Island island = islandsByUUID.get(playerUUID);
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: island found");
|
plugin.getLogger().info("DEBUG: island found");
|
||||||
|
}
|
||||||
if (island.getOwner() != null && island.getOwner().equals(playerUUID)) {
|
if (island.getOwner() != null && island.getOwner().equals(playerUUID)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: player is the owner of this island");
|
plugin.getLogger().info("DEBUG: player is the owner of this island");
|
||||||
|
}
|
||||||
// Clear ownership and members
|
// Clear ownership and members
|
||||||
island.getMemberSet().clear();
|
island.getMemberSet().clear();
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
}
|
}
|
||||||
island.getMemberSet().remove(playerUUID);
|
island.getMemberSet().remove(playerUUID);
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: removing reference to island by UUID");
|
plugin.getLogger().info("DEBUG: removing reference to island by UUID");
|
||||||
|
}
|
||||||
islandsByUUID.remove(playerUUID);
|
islandsByUUID.remove(playerUUID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ public class IslandsManager {
|
|||||||
if (maxYradius < height) {
|
if (maxYradius < height) {
|
||||||
maxYradius++;
|
maxYradius++;
|
||||||
}
|
}
|
||||||
//plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius +
|
//plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius +
|
||||||
// "," + maxXradius + "," + maxYradius + "," + maxZradius);
|
// "," + maxXradius + "," + maxYradius + "," + maxZradius);
|
||||||
} while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth
|
} while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth
|
||||||
|| maxYradius < height);
|
|| maxYradius < height);
|
||||||
@ -246,8 +246,9 @@ public class IslandsManager {
|
|||||||
* @param owner UUID
|
* @param owner UUID
|
||||||
*/
|
*/
|
||||||
public Island createIsland(Location location, UUID owner){
|
public Island createIsland(Location location, UUID owner){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
|
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
|
||||||
|
}
|
||||||
return islandCache.createIsland(new Island(location, owner, plugin.getSettings().getIslandProtectionRange()));
|
return islandCache.createIsland(new Island(location, owner, plugin.getSettings().getIslandProtectionRange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +258,9 @@ public class IslandsManager {
|
|||||||
* @param removeBlocks - if the island blocks should be removed or not
|
* @param removeBlocks - if the island blocks should be removed or not
|
||||||
*/
|
*/
|
||||||
public void deleteIsland(Island island, boolean removeBlocks) {
|
public void deleteIsland(Island island, boolean removeBlocks) {
|
||||||
if (island == null)
|
if (island == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// Set the owner of the island to no one.
|
// Set the owner of the island to no one.
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
island.setLocked(false);
|
island.setLocked(false);
|
||||||
@ -291,8 +293,9 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public void deleteIsland(final UUID player, boolean removeBlocks) {
|
public void deleteIsland(final UUID player, boolean removeBlocks) {
|
||||||
// Removes the island
|
// Removes the island
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: deleting player island");
|
plugin.getLogger().info("DEBUG: deleting player island");
|
||||||
|
}
|
||||||
//CoopPlay.getInstance().clearAllIslandCoops(player);
|
//CoopPlay.getInstance().clearAllIslandCoops(player);
|
||||||
//getWarpSignsListener().removeWarp(player);
|
//getWarpSignsListener().removeWarp(player);
|
||||||
final Island island = getIsland(player);
|
final Island island = getIsland(player);
|
||||||
@ -377,8 +380,9 @@ public class IslandsManager {
|
|||||||
* @return Location of player's island or null if one does not exist
|
* @return Location of player's island or null if one does not exist
|
||||||
*/
|
*/
|
||||||
public Location getIslandLocation(UUID playerUUID) {
|
public Location getIslandLocation(UUID playerUUID) {
|
||||||
if (hasIsland(playerUUID))
|
if (hasIsland(playerUUID)) {
|
||||||
return getIsland(playerUUID).getCenter();
|
return getIsland(playerUUID).getCenter();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,8 +443,9 @@ public class IslandsManager {
|
|||||||
l = plugin.getPlayers().getHomeLocation(playerUUID, number);
|
l = plugin.getPlayers().getHomeLocation(playerUUID, number);
|
||||||
}
|
}
|
||||||
// Check if it is safe
|
// Check if it is safe
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Home location " + l);
|
plugin.getLogger().info("DEBUG: Home location " + l);
|
||||||
|
}
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
if (isSafeLocation(l)) {
|
if (isSafeLocation(l)) {
|
||||||
return l;
|
return l;
|
||||||
@ -456,38 +461,45 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Home location either isn't safe, or does not exist so try the island");
|
plugin.getLogger().info("DEBUG: Home location either isn't safe, or does not exist so try the island");
|
||||||
|
}
|
||||||
// Home location either isn't safe, or does not exist so try the island
|
// Home location either isn't safe, or does not exist so try the island
|
||||||
// location
|
// location
|
||||||
if (plugin.getPlayers().inTeam(playerUUID)) {
|
if (plugin.getPlayers().inTeam(playerUUID)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG:player is in team");
|
plugin.getLogger().info("DEBUG:player is in team");
|
||||||
|
}
|
||||||
l = plugin.getIslands().getIslandLocation(playerUUID);
|
l = plugin.getIslands().getIslandLocation(playerUUID);
|
||||||
if (isSafeLocation(l)) {
|
if (isSafeLocation(l)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG:island loc is safe");
|
plugin.getLogger().info("DEBUG:island loc is safe");
|
||||||
|
}
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
||||||
return l;
|
return l;
|
||||||
} else {
|
} else {
|
||||||
// try team leader's home
|
// try team leader's home
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: trying leader's home");
|
plugin.getLogger().info("DEBUG: trying leader's home");
|
||||||
|
}
|
||||||
Location tlh = plugin.getPlayers().getHomeLocation(plugin.getIslands().getTeamLeader(playerUUID));
|
Location tlh = plugin.getPlayers().getHomeLocation(plugin.getIslands().getTeamLeader(playerUUID));
|
||||||
if (tlh != null) {
|
if (tlh != null) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: leader has a home");
|
plugin.getLogger().info("DEBUG: leader has a home");
|
||||||
|
}
|
||||||
if (isSafeLocation(tlh)) {
|
if (isSafeLocation(tlh)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: team leader's home is safe");
|
plugin.getLogger().info("DEBUG: team leader's home is safe");
|
||||||
|
}
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
|
||||||
return tlh;
|
return tlh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: player is not in team - trying island location");
|
plugin.getLogger().info("DEBUG: player is not in team - trying island location");
|
||||||
|
}
|
||||||
l = plugin.getIslands().getIslandLocation(playerUUID);
|
l = plugin.getIslands().getIslandLocation(playerUUID);
|
||||||
if (isSafeLocation(l)) {
|
if (isSafeLocation(l)) {
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
||||||
@ -498,28 +510,32 @@ public class IslandsManager {
|
|||||||
plugin.getLogger().warning(plugin.getPlayers().getName(playerUUID) + " player has no island!");
|
plugin.getLogger().warning(plugin.getPlayers().getName(playerUUID) + " player has no island!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: If these island locations are not safe, then we need to get creative");
|
plugin.getLogger().info("DEBUG: If these island locations are not safe, then we need to get creative");
|
||||||
|
}
|
||||||
// If these island locations are not safe, then we need to get creative
|
// If these island locations are not safe, then we need to get creative
|
||||||
// Try the default location
|
// Try the default location
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: try default location");
|
plugin.getLogger().info("DEBUG: try default location");
|
||||||
|
}
|
||||||
Location dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 2.5D, 0F, 30F);
|
Location dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 2.5D, 0F, 30F);
|
||||||
if (isSafeLocation(dl)) {
|
if (isSafeLocation(dl)) {
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, dl, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, dl, number);
|
||||||
return dl;
|
return dl;
|
||||||
}
|
}
|
||||||
// Try just above the bedrock
|
// Try just above the bedrock
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: above bedrock");
|
plugin.getLogger().info("DEBUG: above bedrock");
|
||||||
|
}
|
||||||
dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 0.5D, 0F, 30F);
|
dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 0.5D, 0F, 30F);
|
||||||
if (isSafeLocation(dl)) {
|
if (isSafeLocation(dl)) {
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, dl, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, dl, number);
|
||||||
return dl;
|
return dl;
|
||||||
}
|
}
|
||||||
// Try all the way up to the sky
|
// Try all the way up to the sky
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: try all the way to the sky");
|
plugin.getLogger().info("DEBUG: try all the way to the sky");
|
||||||
|
}
|
||||||
for (int y = l.getBlockY(); y < 255; y++) {
|
for (int y = l.getBlockY(); y < 255; y++) {
|
||||||
final Location n = new Location(l.getWorld(), l.getX() + 0.5D, y, l.getZ() + 0.5D);
|
final Location n = new Location(l.getWorld(), l.getX() + 0.5D, y, l.getZ() + 0.5D);
|
||||||
if (isSafeLocation(n)) {
|
if (isSafeLocation(n)) {
|
||||||
@ -527,8 +543,9 @@ public class IslandsManager {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: unsuccessful");
|
plugin.getLogger().info("DEBUG: unsuccessful");
|
||||||
|
}
|
||||||
// Unsuccessful
|
// Unsuccessful
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -542,8 +559,9 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public Location getSpawnPoint() {
|
public Location getSpawnPoint() {
|
||||||
//plugin.getLogger().info("DEBUG: getting spawn point : " + spawn.getSpawnPoint());
|
//plugin.getLogger().info("DEBUG: getting spawn point : " + spawn.getSpawnPoint());
|
||||||
if (spawn == null)
|
if (spawn == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return spawn.getSpawnPoint();
|
return spawn.getSpawnPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,11 +602,13 @@ public class IslandsManager {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void homeTeleport(final Player player, int number) {
|
public void homeTeleport(final Player player, int number) {
|
||||||
Location home;
|
Location home;
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("home teleport called for #" + number);
|
plugin.getLogger().info("home teleport called for #" + number);
|
||||||
|
}
|
||||||
home = getSafeHomeLocation(player.getUniqueId(), number);
|
home = getSafeHomeLocation(player.getUniqueId(), number);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("home get safe loc = " + home);
|
plugin.getLogger().info("home get safe loc = " + home);
|
||||||
|
}
|
||||||
// Check if the player is a passenger in a boat
|
// Check if the player is a passenger in a boat
|
||||||
if (player.isInsideVehicle()) {
|
if (player.isInsideVehicle()) {
|
||||||
Entity boat = player.getVehicle();
|
Entity boat = player.getVehicle();
|
||||||
@ -601,14 +621,16 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("Fixing home location using safe spot teleport");
|
plugin.getLogger().info("Fixing home location using safe spot teleport");
|
||||||
|
}
|
||||||
// Try to fix this teleport location and teleport the player if possible
|
// Try to fix this teleport location and teleport the player if possible
|
||||||
new SafeSpotTeleport(plugin, player, plugin.getPlayers().getHomeLocation(player.getUniqueId(), number), number);
|
new SafeSpotTeleport(plugin, player, plugin.getPlayers().getHomeLocation(player.getUniqueId(), number), number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
|
plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
|
||||||
|
}
|
||||||
//home.getChunk().load();
|
//home.getChunk().load();
|
||||||
player.teleport(home);
|
player.teleport(home);
|
||||||
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
||||||
@ -644,11 +666,13 @@ public class IslandsManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean isIsland(Location location){
|
public boolean isIsland(Location location){
|
||||||
if (location == null)
|
if (location == null) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
location = getClosestIsland(location);
|
location = getClosestIsland(location);
|
||||||
if (islandCache.contains(location))
|
if (islandCache.contains(location)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!plugin.getSettings().isUseOwnGenerator()) {
|
if (!plugin.getSettings().isUseOwnGenerator()) {
|
||||||
// Block check
|
// Block check
|
||||||
@ -662,7 +686,7 @@ public class IslandsManager {
|
|||||||
for (int x = -5; x <= 5; x++) {
|
for (int x = -5; x <= 5; x++) {
|
||||||
for (int y = 10; y <= 255; y++) {
|
for (int y = 10; y <= 255; y++) {
|
||||||
for (int z = -5; z <= 5; z++) {
|
for (int z = -5; z <= 5; z++) {
|
||||||
if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty()
|
if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty()
|
||||||
&& !location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isLiquid()) {
|
&& !location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isLiquid()) {
|
||||||
plugin.getLogger().info("Solid block found during long search - adding ");
|
plugin.getLogger().info("Solid block found during long search - adding ");
|
||||||
createIsland(location);
|
createIsland(location);
|
||||||
@ -677,14 +701,14 @@ public class IslandsManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns the coordinate of where an island should be on the grid.
|
* This returns the coordinate of where an island should be on the grid.
|
||||||
*
|
*
|
||||||
* @param location location to query
|
* @param location location to query
|
||||||
* @return Location of closest island
|
* @return Location of closest island
|
||||||
*/
|
*/
|
||||||
public Location getClosestIsland(Location location) {
|
public Location getClosestIsland(Location location) {
|
||||||
long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance())
|
long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance())
|
||||||
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset();
|
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset();
|
||||||
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance())
|
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance())
|
||||||
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset();
|
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset();
|
||||||
long y = plugin.getSettings().getIslandHeight();
|
long y = plugin.getSettings().getIslandHeight();
|
||||||
return new Location(location.getWorld(), x, y, z);
|
return new Location(location.getWorld(), x, y, z);
|
||||||
@ -708,18 +732,21 @@ public class IslandsManager {
|
|||||||
islandCache.clear();
|
islandCache.clear();
|
||||||
spawn = null;
|
spawn = null;
|
||||||
try {
|
try {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: loading grid");
|
plugin.getLogger().info("DEBUG: loading grid");
|
||||||
|
}
|
||||||
for (Island island : handler.loadObjects()) {
|
for (Island island : handler.loadObjects()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding island at "+ island.getCenter());
|
plugin.getLogger().info("DEBUG: adding island at "+ island.getCenter());
|
||||||
|
}
|
||||||
islandCache.addIsland(island);
|
islandCache.addIsland(island);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().severe("Could not load islands to cache! " + e.getMessage());
|
plugin.getLogger().severe("Could not load islands to cache! " + e.getMessage());
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: islands loaded");
|
plugin.getLogger().info("DEBUG: islands loaded");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -731,7 +758,7 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public boolean locationIsAtHome(UUID uuid, boolean coop, Location loc) {
|
public boolean locationIsAtHome(UUID uuid, boolean coop, Location loc) {
|
||||||
// Make a list of test locations and test them
|
// Make a list of test locations and test them
|
||||||
Set<Location> islandTestLocations = new HashSet<Location>();
|
Set<Location> islandTestLocations = new HashSet<>();
|
||||||
if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) {
|
if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) {
|
||||||
islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid));
|
islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid));
|
||||||
// If new Nether
|
// If new Nether
|
||||||
@ -800,7 +827,7 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
// Not in the grid, so do it the old way
|
// Not in the grid, so do it the old way
|
||||||
// Make a list of test locations and test them
|
// Make a list of test locations and test them
|
||||||
Set<Location> islandTestLocations = new HashSet<Location>();
|
Set<Location> islandTestLocations = new HashSet<>();
|
||||||
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
||||||
islandTestLocations.add(getIslandLocation(player.getUniqueId()));
|
islandTestLocations.add(getIslandLocation(player.getUniqueId()));
|
||||||
}
|
}
|
||||||
@ -829,7 +856,7 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void metrics_setCreatedCount(int count){
|
public void metrics_setCreatedCount(int count){
|
||||||
this.metrics_createdcount = count;
|
metrics_createdcount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -877,8 +904,9 @@ public class IslandsManager {
|
|||||||
* @param playerUUID
|
* @param playerUUID
|
||||||
*/
|
*/
|
||||||
public void removePlayer(UUID playerUUID) {
|
public void removePlayer(UUID playerUUID) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: removing player");
|
plugin.getLogger().info("DEBUG: removing player");
|
||||||
|
}
|
||||||
islandCache.removePlayer(playerUUID);
|
islandCache.removePlayer(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -920,13 +948,14 @@ public class IslandsManager {
|
|||||||
* @param async - if true, saving will be done async
|
* @param async - if true, saving will be done async
|
||||||
*/
|
*/
|
||||||
public void save(boolean async){
|
public void save(boolean async){
|
||||||
Collection<Island> collection = islandCache.getIslands();
|
Collection<Island> collection = islandCache.getIslands();
|
||||||
if(async){
|
if(async){
|
||||||
Runnable save = () -> {
|
Runnable save = () -> {
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(Island island : collection){
|
for(Island island : collection){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving island async " + index++);
|
plugin.getLogger().info("DEBUG: saving island async " + index++);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
handler.saveObject(island);
|
handler.saveObject(island);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -938,8 +967,9 @@ public class IslandsManager {
|
|||||||
} else {
|
} else {
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(Island island : collection){
|
for(Island island : collection){
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saving island " + index++);
|
plugin.getLogger().info("DEBUG: saving island " + index++);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
handler.saveObject(island);
|
handler.saveObject(island);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -967,8 +997,9 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
|
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
|
||||||
// Add player to new island
|
// Add player to new island
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Adding player to new island");
|
plugin.getLogger().info("DEBUG: Adding player to new island");
|
||||||
|
}
|
||||||
teamIsland.addMember(playerUUID);
|
teamIsland.addMember(playerUUID);
|
||||||
islandCache.addPlayer(playerUUID, teamIsland);
|
islandCache.addPlayer(playerUUID, teamIsland);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -990,8 +1021,9 @@ public class IslandsManager {
|
|||||||
* @param playerUUID
|
* @param playerUUID
|
||||||
*/
|
*/
|
||||||
public void setLeaveTeam(UUID playerUUID) {
|
public void setLeaveTeam(UUID playerUUID) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: leaving team");
|
plugin.getLogger().info("DEBUG: leaving team");
|
||||||
|
}
|
||||||
plugin.getPlayers().clearPlayerHomes(playerUUID);
|
plugin.getPlayers().clearPlayerHomes(playerUUID);
|
||||||
removePlayer(playerUUID);
|
removePlayer(playerUUID);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class NewIsland {
|
|||||||
|
|
||||||
private NewIsland(Island oldIsland, Player player, Reason reason) {
|
private NewIsland(Island oldIsland, Player player, Reason reason) {
|
||||||
super();
|
super();
|
||||||
this.plugin = BSkyBlock.getInstance();
|
plugin = BSkyBlock.getInstance();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
newIsland();
|
newIsland();
|
||||||
@ -47,7 +47,7 @@ public class NewIsland {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Start building a new island
|
* Start building a new island
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* @return New island builder object
|
* @return New island builder object
|
||||||
*/
|
*/
|
||||||
public static Builder builder(BSkyBlock plugin) {
|
public static Builder builder(BSkyBlock plugin) {
|
||||||
@ -93,8 +93,9 @@ public class NewIsland {
|
|||||||
* Makes an island.
|
* Makes an island.
|
||||||
*/
|
*/
|
||||||
public void newIsland() {
|
public void newIsland() {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: new island");
|
plugin.getLogger().info("DEBUG: new island");
|
||||||
|
}
|
||||||
//long time = System.nanoTime();
|
//long time = System.nanoTime();
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
/*
|
/*
|
||||||
@ -102,11 +103,13 @@ public class NewIsland {
|
|||||||
if (!plugin.getPlayers().hasIsland(playerUUID)) {
|
if (!plugin.getPlayers().hasIsland(playerUUID)) {
|
||||||
firstTime = true;
|
firstTime = true;
|
||||||
}*/
|
}*/
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: finding island location");
|
plugin.getLogger().info("DEBUG: finding island location");
|
||||||
|
}
|
||||||
Location next = getNextIsland(player.getUniqueId());
|
Location next = getNextIsland(player.getUniqueId());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: found " + next);
|
plugin.getLogger().info("DEBUG: found " + next);
|
||||||
|
}
|
||||||
|
|
||||||
// Add to the grid
|
// Add to the grid
|
||||||
island = plugin.getIslands().createIsland(next, playerUUID);
|
island = plugin.getIslands().createIsland(next, playerUUID);
|
||||||
@ -123,16 +126,18 @@ public class NewIsland {
|
|||||||
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
|
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
|
||||||
|
|
||||||
// Fire event
|
// Fire event
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: firing event");
|
plugin.getLogger().info("DEBUG: firing event");
|
||||||
|
}
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
IslandBaseEvent event = IslandEvent.builder()
|
||||||
.involvedPlayer(player.getUniqueId())
|
.involvedPlayer(player.getUniqueId())
|
||||||
.reason(reason)
|
.reason(reason)
|
||||||
.island(island)
|
.island(island)
|
||||||
.location(island.getCenter())
|
.location(island.getCenter())
|
||||||
.build();
|
.build();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: event cancelled status = " + event.isCancelled());
|
plugin.getLogger().info("DEBUG: event cancelled status = " + event.isCancelled());
|
||||||
|
}
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
// Create island
|
// Create island
|
||||||
new IslandBuilder(plugin, island)
|
new IslandBuilder(plugin, island)
|
||||||
@ -153,7 +158,7 @@ public class NewIsland {
|
|||||||
.setChestItems(plugin.getSettings().getChestItems())
|
.setChestItems(plugin.getSettings().getChestItems())
|
||||||
.setType(IslandType.END)
|
.setType(IslandType.END)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
// Teleport player to their island
|
// Teleport player to their island
|
||||||
plugin.getIslands().homeTeleport(player);
|
plugin.getIslands().homeTeleport(player);
|
||||||
// Fire exit event
|
// Fire exit event
|
||||||
@ -186,25 +191,30 @@ public class NewIsland {
|
|||||||
Location last = plugin.getIslands().getLast();
|
Location last = plugin.getIslands().getLast();
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
|
{
|
||||||
plugin.getLogger().info("DEBUG: last = " + last);
|
plugin.getLogger().info("DEBUG: last = " + last);
|
||||||
// Find the next free spot
|
// Find the next free spot
|
||||||
|
}
|
||||||
|
|
||||||
if (last == null) {
|
if (last == null) {
|
||||||
last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(),
|
last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(),
|
||||||
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ());
|
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ());
|
||||||
}
|
}
|
||||||
Location next = last.clone();
|
Location next = last.clone();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: last 2 = " + last);
|
plugin.getLogger().info("DEBUG: last 2 = " + last);
|
||||||
|
}
|
||||||
while (plugin.getIslands().isIsland(next)) {
|
while (plugin.getIslands().isIsland(next)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: getting next loc");
|
plugin.getLogger().info("DEBUG: getting next loc");
|
||||||
|
}
|
||||||
next = nextGridLocation(next);
|
next = nextGridLocation(next);
|
||||||
};
|
};
|
||||||
// Make the last next, last
|
// Make the last next, last
|
||||||
last = next.clone();
|
last = next.clone();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: last 3 = " + last);
|
plugin.getLogger().info("DEBUG: last 3 = " + last);
|
||||||
|
}
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
mySQLmapping.put(Location.class.getTypeName(), "VARCHAR(254)");
|
mySQLmapping.put(Location.class.getTypeName(), "VARCHAR(254)");
|
||||||
mySQLmapping.put(World.class.getTypeName(), "VARCHAR(254)");
|
mySQLmapping.put(World.class.getTypeName(), "VARCHAR(254)");
|
||||||
|
|
||||||
// Collections are stored as additional tables. The boolean indicates whether there
|
// Collections are stored as additional tables. The boolean indicates whether there
|
||||||
// is any data in it or not (maybe)
|
// is any data in it or not (maybe)
|
||||||
mySQLmapping.put(Set.class.getTypeName(), "BOOL");
|
mySQLmapping.put(Set.class.getTypeName(), "BOOL");
|
||||||
mySQLmapping.put(Map.class.getTypeName(), "BOOL");
|
mySQLmapping.put(Map.class.getTypeName(), "BOOL");
|
||||||
@ -97,7 +97,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the connection to the database and creation of the initial database schema (tables) for
|
* Handles the connection to the database and creation of the initial database schema (tables) for
|
||||||
* the class that will be stored.
|
* the class that will be stored.
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* @param type - the type of class to be stored in the database. Must inherit DataObject
|
* @param type - the type of class to be stored in the database. Must inherit DataObject
|
||||||
* @param databaseConnecter - authentication details for the database
|
* @param databaseConnecter - authentication details for the database
|
||||||
@ -163,8 +163,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//plugin.getLogger().info(setSql);
|
//plugin.getLogger().info(setSql);
|
||||||
// Execute the statement
|
// Execute the statement
|
||||||
try (PreparedStatement collections = connection.prepareStatement(setSql)) {
|
try (PreparedStatement collections = connection.prepareStatement(setSql)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collections prepared statement = " + collections.toString());
|
plugin.getLogger().info("DEBUG: collections prepared statement = " + collections.toString());
|
||||||
|
}
|
||||||
collections.executeUpdate();
|
collections.executeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,8 +183,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//plugin.getLogger().info("DEBUG: SQL string = " + sql);
|
//plugin.getLogger().info("DEBUG: SQL string = " + sql);
|
||||||
// Prepare and execute the database statements
|
// Prepare and execute the database statements
|
||||||
pstmt = connection.prepareStatement(sql);
|
pstmt = connection.prepareStatement(sql);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: pstmt = " + pstmt.toString());
|
plugin.getLogger().info("DEBUG: pstmt = " + pstmt.toString());
|
||||||
|
}
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().severe("Could not create database schema! " + e.getMessage());
|
plugin.getLogger().severe("Could not create database schema! " + e.getMessage());
|
||||||
@ -209,15 +211,17 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
/* Iterate the column-names */
|
/* Iterate the column-names */
|
||||||
for (Field f : dataObject.getDeclaredFields()) {
|
for (Field f : dataObject.getDeclaredFields()) {
|
||||||
if (first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
if (usePlaceHolders)
|
if (usePlaceHolders) {
|
||||||
sb.append("?");
|
sb.append("?");
|
||||||
else
|
} else {
|
||||||
sb.append("`" + f.getName() + "`");
|
sb.append("`" + f.getName() + "`");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -240,18 +244,21 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (String col : cols) {
|
for (String col : cols) {
|
||||||
// Add commas
|
// Add commas
|
||||||
if (first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
|
}
|
||||||
// this is used if the string is going to be used to insert something so the value will replace the ?
|
// this is used if the string is going to be used to insert something so the value will replace the ?
|
||||||
if (usePlaceHolders)
|
if (usePlaceHolders) {
|
||||||
sb.append("?");
|
sb.append("?");
|
||||||
else
|
} else {
|
||||||
sb.append(col);
|
sb.append(col);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection column string = " + sb.toString());
|
plugin.getLogger().info("DEBUG: collection column string = " + sb.toString());
|
||||||
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,8 +276,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
col += " " + en.getValue();
|
col += " " + en.getValue();
|
||||||
}
|
}
|
||||||
columns.add(col);
|
columns.add(col);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection columns = " + col);
|
plugin.getLogger().info("DEBUG: collection columns = " + col);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
@ -288,11 +296,11 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// In this way, we can deduce what type needs to be written at runtime.
|
// In this way, we can deduce what type needs to be written at runtime.
|
||||||
Type[] genericParameterTypes = method.getGenericParameterTypes();
|
Type[] genericParameterTypes = method.getGenericParameterTypes();
|
||||||
// There could be more than one argument, so step through them
|
// There could be more than one argument, so step through them
|
||||||
for (int i = 0; i < genericParameterTypes.length; i++) {
|
for (Type genericParameterType : genericParameterTypes) {
|
||||||
// If the argument is a parameter, then do something - this should always be true if the parameter is a collection
|
// If the argument is a parameter, then do something - this should always be true if the parameter is a collection
|
||||||
if (genericParameterTypes[i] instanceof ParameterizedType) {
|
if (genericParameterType instanceof ParameterizedType) {
|
||||||
// Get the actual type arguments of the parameter
|
// Get the actual type arguments of the parameter
|
||||||
Type[] parameters = ((ParameterizedType)genericParameterTypes[i]).getActualTypeArguments();
|
Type[] parameters = ((ParameterizedType)genericParameterType).getActualTypeArguments();
|
||||||
//parameters[0] contains java.lang.String for method like "method(List<String> value)"
|
//parameters[0] contains java.lang.String for method like "method(List<String> value)"
|
||||||
// Run through them one by one and create a SQL string
|
// Run through them one by one and create a SQL string
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -300,8 +308,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// This is a request for column names.
|
// This is a request for column names.
|
||||||
String setMapping = mySQLmapping.get(type.getTypeName());
|
String setMapping = mySQLmapping.get(type.getTypeName());
|
||||||
columns.put("`" + type.getTypeName() + "_" + index + "`", setMapping != null ? setMapping : "VARCHAR(254)");
|
columns.put("`" + type.getTypeName() + "_" + index + "`", setMapping != null ? setMapping : "VARCHAR(254)");
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection column = " + "`" + type.getTypeName() + "_" + index + "`" + setMapping);
|
plugin.getLogger().info("DEBUG: collection column = " + "`" + type.getTypeName() + "_" + index + "`" + setMapping);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Increment the index so each column has a unique name
|
// Increment the index so each column has a unique name
|
||||||
index++;
|
index++;
|
||||||
@ -381,8 +390,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: saveObject ");
|
plugin.getLogger().info("DEBUG: saveObject ");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Try to connect to the database
|
// Try to connect to the database
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
@ -400,37 +410,43 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
// Create the insertion
|
// Create the insertion
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: insert Query " + insertQuery);
|
plugin.getLogger().info("DEBUG: insert Query " + insertQuery);
|
||||||
|
}
|
||||||
// Run through the fields in the class using introspection
|
// Run through the fields in the class using introspection
|
||||||
for (Field field : dataObject.getDeclaredFields()) {
|
for (Field field : dataObject.getDeclaredFields()) {
|
||||||
// Get the field's property descriptor
|
// Get the field's property descriptor
|
||||||
propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
||||||
// Get the read method for this field
|
// Get the read method for this field
|
||||||
Method method = propertyDescriptor.getReadMethod();
|
Method method = propertyDescriptor.getReadMethod();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Field = " + field.getName() + "(" + propertyDescriptor.getPropertyType().getTypeName() + ")");
|
plugin.getLogger().info("DEBUG: Field = " + field.getName() + "(" + propertyDescriptor.getPropertyType().getTypeName() + ")");
|
||||||
|
}
|
||||||
//sql += "`" + field.getName() + "` " + mapping + ",";
|
//sql += "`" + field.getName() + "` " + mapping + ",";
|
||||||
// Invoke the read method to obtain the value from the class - this is the value we need to store in the database
|
// Invoke the read method to obtain the value from the class - this is the value we need to store in the database
|
||||||
Object value = method.invoke(instance);
|
Object value = method.invoke(instance);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: value = " + value);
|
plugin.getLogger().info("DEBUG: value = " + value);
|
||||||
|
}
|
||||||
// Adapter
|
// Adapter
|
||||||
// Check if there is an annotation on the field
|
// Check if there is an annotation on the field
|
||||||
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
||||||
// If there is a config annotation then do something
|
// If there is a config annotation then do something
|
||||||
if (configEntry != null) {
|
if (configEntry != null) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: there is a configEntry");
|
plugin.getLogger().info("DEBUG: there is a configEntry");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: there is an adapter");
|
plugin.getLogger().info("DEBUG: there is an adapter");
|
||||||
// A conversion adapter has been defined
|
}
|
||||||
|
// A conversion adapter has been defined
|
||||||
value = ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value);
|
value = ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: value now after deserialization = " + value);
|
plugin.getLogger().info("DEBUG: value now after deserialization = " + value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Create set and map table inserts if this is a Collection
|
// Create set and map table inserts if this is a Collection
|
||||||
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
||||||
@ -443,8 +459,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try (PreparedStatement collStatement = connection.prepareStatement(clearTableSql)) {
|
try (PreparedStatement collStatement = connection.prepareStatement(clearTableSql)) {
|
||||||
collStatement.setString(1, uniqueId);
|
collStatement.setString(1, uniqueId);
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString());
|
plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Insert into the table
|
// Insert into the table
|
||||||
String setSql = "INSERT INTO `" + dataObject.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
String setSql = "INSERT INTO `" + dataObject.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
||||||
@ -456,8 +473,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try (PreparedStatement collStatement = connection.prepareStatement(setSql)) {
|
try (PreparedStatement collStatement = connection.prepareStatement(setSql)) {
|
||||||
// Set the uniqueId
|
// Set the uniqueId
|
||||||
collStatement.setString(1, uniqueId);
|
collStatement.setString(1, uniqueId);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
||||||
|
}
|
||||||
// Do single dimension types (set and list)
|
// Do single dimension types (set and list)
|
||||||
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
||||||
propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
||||||
@ -474,8 +492,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//}
|
//}
|
||||||
// Set the value from ? to whatever it is
|
// Set the value from ? to whatever it is
|
||||||
collStatement.setObject(2, setValue);
|
collStatement.setObject(2, setValue);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
||||||
|
}
|
||||||
// Execute the SQL in the database
|
// Execute the SQL in the database
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
}
|
}
|
||||||
@ -486,22 +505,26 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
Iterator<?> it = collection.entrySet().iterator();
|
Iterator<?> it = collection.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<?,?> en = (Entry<?, ?>) it.next();
|
Entry<?,?> en = (Entry<?, ?>) it.next();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: entry ket = " + en.getKey());
|
plugin.getLogger().info("DEBUG: entry ket = " + en.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
// Get the key and serialize it
|
// Get the key and serialize it
|
||||||
Object key = serialize(en.getKey(), en.getKey().getClass());
|
Object key = serialize(en.getKey(), en.getKey().getClass());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: key class = " + en.getKey().getClass().getTypeName());
|
plugin.getLogger().info("DEBUG: key class = " + en.getKey().getClass().getTypeName());
|
||||||
|
}
|
||||||
// Get the value and serialize it
|
// Get the value and serialize it
|
||||||
Object mapValue = serialize(en.getValue(), en.getValue().getClass());
|
Object mapValue = serialize(en.getValue(), en.getValue().getClass());
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: mapValue = " + mapValue);
|
plugin.getLogger().info("DEBUG: mapValue = " + mapValue);
|
||||||
|
}
|
||||||
// Write the objects into prepared statement
|
// Write the objects into prepared statement
|
||||||
collStatement.setObject(1, key);
|
collStatement.setObject(1, key);
|
||||||
collStatement.setObject(2, mapValue);
|
collStatement.setObject(2, mapValue);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
||||||
|
}
|
||||||
// Write to database
|
// Write to database
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
}
|
}
|
||||||
@ -521,8 +544,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Add the statements to a batch
|
// Add the statements to a batch
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
// Execute
|
// Execute
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: prepared statement = " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: prepared statement = " + preparedStatement.toString());
|
||||||
|
}
|
||||||
preparedStatement.executeBatch();
|
preparedStatement.executeBatch();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@ -600,8 +624,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: selectQuery = " + selectQuery);
|
plugin.getLogger().info("DEBUG: selectQuery = " + selectQuery);
|
||||||
|
}
|
||||||
resultSet = statement.executeQuery(selectQuery);
|
resultSet = statement.executeQuery(selectQuery);
|
||||||
|
|
||||||
return createObjects(resultSet);
|
return createObjects(resultSet);
|
||||||
@ -623,15 +648,17 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: loading object for " + uniqueId);
|
plugin.getLogger().info("DEBUG: loading object for " + uniqueId);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
String query = "SELECT " + getColumns(false) + " FROM `" + dataObject.getCanonicalName() + "` WHERE uniqueId = ? LIMIT 1";
|
String query = "SELECT " + getColumns(false) + " FROM `" + dataObject.getCanonicalName() + "` WHERE uniqueId = ? LIMIT 1";
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
||||||
preparedStatement.setString(1, uniqueId);
|
preparedStatement.setString(1, uniqueId);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: load Object query = " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: load Object query = " + preparedStatement.toString());
|
||||||
|
}
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
List<T> result = createObjects(resultSet);
|
List<T> result = createObjects(resultSet);
|
||||||
@ -673,7 +700,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
IllegalAccessException, IntrospectionException,
|
IllegalAccessException, IntrospectionException,
|
||||||
InvocationTargetException, ClassNotFoundException {
|
InvocationTargetException, ClassNotFoundException {
|
||||||
|
|
||||||
List<T> list = new ArrayList<T>();
|
List<T> list = new ArrayList<>();
|
||||||
// The database can return multiple results in one go, e.g., all the islands in the database
|
// The database can return multiple results in one go, e.g., all the islands in the database
|
||||||
// Run through them one by one
|
// Run through them one by one
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -693,14 +720,16 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Get the write method for this field, because we are going to use it to write the value
|
// Get the write method for this field, because we are going to use it to write the value
|
||||||
// once we get the value from the database
|
// once we get the value from the database
|
||||||
Method method = propertyDescriptor.getWriteMethod();
|
Method method = propertyDescriptor.getWriteMethod();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: propertyDescriptor.getPropertyType() = " + propertyDescriptor.getPropertyType());
|
plugin.getLogger().info("DEBUG: propertyDescriptor.getPropertyType() = " + propertyDescriptor.getPropertyType());
|
||||||
// If the type is a Collection, then we need to deal with set and map tables
|
}
|
||||||
|
// If the type is a Collection, then we need to deal with set and map tables
|
||||||
if (Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())
|
if (Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())
|
||||||
|| Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
|| Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
// Collection
|
// Collection
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Collection or Map");
|
plugin.getLogger().info("DEBUG: Collection or Map");
|
||||||
|
}
|
||||||
// TODO Get the values from the subsidiary tables.
|
// TODO Get the values from the subsidiary tables.
|
||||||
// value is just of type boolean right now
|
// value is just of type boolean right now
|
||||||
String setSql = "SELECT ";
|
String setSql = "SELECT ";
|
||||||
@ -713,21 +742,23 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try (PreparedStatement collStatement = connection.prepareStatement(setSql)) {
|
try (PreparedStatement collStatement = connection.prepareStatement(setSql)) {
|
||||||
// Set the unique ID
|
// Set the unique ID
|
||||||
collStatement.setObject(1, uniqueId);
|
collStatement.setObject(1, uniqueId);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString());
|
plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString());
|
||||||
|
}
|
||||||
try (ResultSet collectionResultSet = collStatement.executeQuery()) {
|
try (ResultSet collectionResultSet = collStatement.executeQuery()) {
|
||||||
|
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString());
|
//plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString());
|
||||||
// Do single dimension types (set and list)
|
// Do single dimension types (set and list)
|
||||||
if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding a set");
|
plugin.getLogger().info("DEBUG: adding a set");
|
||||||
// Loop through the collection resultset
|
}
|
||||||
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be only 1 long
|
// collectionTypes should be only 1 long
|
||||||
Type setType = collectionTypes.get(0);
|
Type setType = collectionTypes.get(0);
|
||||||
value = new HashSet<Object>();
|
value = new HashSet<>();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
||||||
@ -736,14 +767,15 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName())));
|
((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName())));
|
||||||
}
|
}
|
||||||
} else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
} else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Adding a list ");
|
plugin.getLogger().info("DEBUG: Adding a list ");
|
||||||
// Loop through the collection resultset
|
}
|
||||||
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be only 1 long
|
// collectionTypes should be only 1 long
|
||||||
Type setType = collectionTypes.get(0);
|
Type setType = collectionTypes.get(0);
|
||||||
value = new ArrayList<Object>();
|
value = new ArrayList<>();
|
||||||
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
while (collectionResultSet.next()) {
|
while (collectionResultSet.next()) {
|
||||||
//plugin.getLogger().info("DEBUG: adding to the list");
|
//plugin.getLogger().info("DEBUG: adding to the list");
|
||||||
@ -752,29 +784,34 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
} else if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType()) ||
|
} else if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType()) ||
|
||||||
HashMap.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
HashMap.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Adding a map ");
|
plugin.getLogger().info("DEBUG: Adding a map ");
|
||||||
// Loop through the collection resultset
|
}
|
||||||
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be 2 long
|
// collectionTypes should be 2 long
|
||||||
Type keyType = collectionTypes.get(0);
|
Type keyType = collectionTypes.get(0);
|
||||||
Type valueType = collectionTypes.get(1);
|
Type valueType = collectionTypes.get(1);
|
||||||
value = new HashMap<Object, Object>();
|
value = new HashMap<>();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
|
}
|
||||||
while (collectionResultSet.next()) {
|
while (collectionResultSet.next()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: adding to the map");
|
plugin.getLogger().info("DEBUG: adding to the map");
|
||||||
|
}
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
||||||
// Work through the columns
|
// Work through the columns
|
||||||
// Key
|
// Key
|
||||||
Object key = deserialize(collectionResultSet.getObject(1),Class.forName(keyType.getTypeName()));
|
Object key = deserialize(collectionResultSet.getObject(1),Class.forName(keyType.getTypeName()));
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: key = " + key);
|
plugin.getLogger().info("DEBUG: key = " + key);
|
||||||
|
}
|
||||||
Object mapValue = deserialize(collectionResultSet.getObject(2),Class.forName(valueType.getTypeName()));
|
Object mapValue = deserialize(collectionResultSet.getObject(2),Class.forName(valueType.getTypeName()));
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: value = " + mapValue);
|
plugin.getLogger().info("DEBUG: value = " + mapValue);
|
||||||
|
}
|
||||||
((Map<Object,Object>) value).put(key,mapValue);
|
((Map<Object,Object>) value).put(key,mapValue);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -785,27 +822,32 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: regular type");
|
plugin.getLogger().info("DEBUG: regular type");
|
||||||
|
}
|
||||||
value = deserialize(value, propertyDescriptor.getPropertyType());
|
value = deserialize(value, propertyDescriptor.getPropertyType());
|
||||||
}
|
}
|
||||||
// Adapter
|
// Adapter
|
||||||
// Check if there is an annotation on the field
|
// Check if there is an annotation on the field
|
||||||
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
||||||
// If there is a config annotation then do something
|
// If there is a config annotation then do something
|
||||||
if (configEntry != null) {
|
if (configEntry != null) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
|
{
|
||||||
plugin.getLogger().info("DEBUG: there is a configEntry");
|
plugin.getLogger().info("DEBUG: there is a configEntry");
|
||||||
// TODO: add config entry handling
|
// TODO: add config entry handling
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: there is an adapter");
|
plugin.getLogger().info("DEBUG: there is an adapter");
|
||||||
// A conversion adapter has been defined
|
}
|
||||||
|
// A conversion adapter has been defined
|
||||||
value = ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value);
|
value = ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: value now after deserialization = " + value);
|
plugin.getLogger().info("DEBUG: value now after deserialization = " + value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: invoking method " + method.getName());
|
plugin.getLogger().info("DEBUG: invoking method " + method.getName());
|
||||||
@ -833,10 +875,11 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private Object deserialize(Object value, Class<? extends Object> clazz) {
|
private Object deserialize(Object value, Class<? extends Object> clazz) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName());
|
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName());
|
||||||
|
}
|
||||||
if (value instanceof String && value.equals("null")) {
|
if (value instanceof String && value.equals("null")) {
|
||||||
// If the value is null as a string, return null
|
// If the value is null as a string, return null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Types that need to be deserialized
|
// Types that need to be deserialized
|
||||||
@ -894,8 +937,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Second is the unique ID
|
// Second is the unique ID
|
||||||
preparedStatement.setString(1, uniqueId);
|
preparedStatement.setString(1, uniqueId);
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: DELETE Query " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: DELETE Query " + preparedStatement.toString());
|
||||||
|
}
|
||||||
preparedStatement.executeBatch();
|
preparedStatement.executeBatch();
|
||||||
// Delete from any sub tables created from the object
|
// Delete from any sub tables created from the object
|
||||||
// Run through the fields in the class using introspection
|
// Run through the fields in the class using introspection
|
||||||
@ -933,8 +977,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean objectExits(String key) {
|
public boolean objectExits(String key) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: checking if " + key + " exists in the database");
|
plugin.getLogger().info("DEBUG: checking if " + key + " exists in the database");
|
||||||
|
}
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
@ -945,11 +990,13 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
preparedStatement = connection.prepareStatement(query);
|
preparedStatement = connection.prepareStatement(query);
|
||||||
preparedStatement.setString(1, key);
|
preparedStatement.setString(1, key);
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: object exists sql " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: object exists sql " + preparedStatement.toString());
|
||||||
|
}
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: result is " + resultSet.getBoolean(1));
|
plugin.getLogger().info("DEBUG: result is " + resultSet.getBoolean(1));
|
||||||
|
}
|
||||||
return resultSet.getBoolean(1);
|
return resultSet.getBoolean(1);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -17,8 +17,9 @@ public class MySQLDatabaseResourceCloser {
|
|||||||
*/
|
*/
|
||||||
public static void close(ResultSet... resultSets) {
|
public static void close(ResultSet... resultSets) {
|
||||||
|
|
||||||
if (resultSets == null)
|
if (resultSets == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (ResultSet resultSet : resultSets) {
|
for (ResultSet resultSet : resultSets) {
|
||||||
if (resultSet != null) {
|
if (resultSet != null) {
|
||||||
@ -43,8 +44,9 @@ public class MySQLDatabaseResourceCloser {
|
|||||||
* CallableStatement, because they extend Statement.
|
* CallableStatement, because they extend Statement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (statements == null)
|
if (statements == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (Statement statement : statements) {
|
for (Statement statement : statements) {
|
||||||
if (statement != null) {
|
if (statement != null) {
|
||||||
@ -64,8 +66,9 @@ public class MySQLDatabaseResourceCloser {
|
|||||||
* Connections that should be closed
|
* Connections that should be closed
|
||||||
*/
|
*/
|
||||||
public static void close(Connection... connections) {
|
public static void close(Connection... connections) {
|
||||||
if (connections == null)
|
if (connections == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (Connection connection : connections) {
|
for (Connection connection : connections) {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
@ -8,11 +8,11 @@ import us.tastybento.bskyblock.BSkyBlock;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface DataObject {
|
public interface DataObject {
|
||||||
|
|
||||||
default BSkyBlock getPlugin() {
|
default BSkyBlock getPlugin() {
|
||||||
return BSkyBlock.getInstance();
|
return BSkyBlock.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the uniqueId
|
* @return the uniqueId
|
||||||
*/
|
*/
|
||||||
@ -22,5 +22,5 @@ public interface DataObject {
|
|||||||
* @param uniqueId the uniqueId to set
|
* @param uniqueId the uniqueId to set
|
||||||
*/
|
*/
|
||||||
void setUniqueId(String uniqueId);
|
void setUniqueId(String uniqueId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
private String uniqueId = "";
|
private String uniqueId = "";
|
||||||
|
|
||||||
//// Island ////
|
//// Island ////
|
||||||
// The center of the island itself
|
// The center of the island itself
|
||||||
private Location center;
|
private Location center;
|
||||||
|
|
||||||
@ -77,13 +77,13 @@ public class Island implements DataObject {
|
|||||||
//// State ////
|
//// State ////
|
||||||
private boolean locked = false;
|
private boolean locked = false;
|
||||||
private boolean spawn = false;
|
private boolean spawn = false;
|
||||||
|
|
||||||
private boolean purgeProtected = false;
|
private boolean purgeProtected = false;
|
||||||
|
|
||||||
//// Protection flags ////
|
//// Protection flags ////
|
||||||
@Adapter(FlagSerializer.class)
|
@Adapter(FlagSerializer.class)
|
||||||
private HashMap<Flag, Integer> flags = new HashMap<>();
|
private HashMap<Flag, Integer> flags = new HashMap<>();
|
||||||
|
|
||||||
private int levelHandicap;
|
private int levelHandicap;
|
||||||
private Location spawnPoint;
|
private Location spawnPoint;
|
||||||
|
|
||||||
@ -91,16 +91,16 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
public Island(Location location, UUID owner, int protectionRange) {
|
public Island(Location location, UUID owner, int protectionRange) {
|
||||||
setOwner(owner);
|
setOwner(owner);
|
||||||
this.createdDate = System.currentTimeMillis();
|
createdDate = System.currentTimeMillis();
|
||||||
this.updatedDate = System.currentTimeMillis();
|
updatedDate = System.currentTimeMillis();
|
||||||
this.world = location.getWorld();
|
world = location.getWorld();
|
||||||
this.center = location;
|
center = location;
|
||||||
this.range = BSkyBlock.getInstance().getSettings().getIslandDistance();
|
range = BSkyBlock.getInstance().getSettings().getIslandDistance();
|
||||||
this.minX = center.getBlockX() - range;
|
minX = center.getBlockX() - range;
|
||||||
this.minZ = center.getBlockZ() - range;
|
minZ = center.getBlockZ() - range;
|
||||||
this.protectionRange = protectionRange;
|
this.protectionRange = protectionRange;
|
||||||
this.minProtectedX = center.getBlockX() - protectionRange;
|
minProtectedX = center.getBlockX() - protectionRange;
|
||||||
this.minProtectedZ = center.getBlockZ() - protectionRange;
|
minProtectedZ = center.getBlockZ() - protectionRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,10 +108,11 @@ public class Island implements DataObject {
|
|||||||
* @param playerUUID
|
* @param playerUUID
|
||||||
*/
|
*/
|
||||||
public void addMember(UUID playerUUID) {
|
public void addMember(UUID playerUUID) {
|
||||||
if (playerUUID != null)
|
if (playerUUID != null) {
|
||||||
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
||||||
* If the player is a member, coop or trustee, they will be removed from those lists.
|
* If the player is a member, coop or trustee, they will be removed from those lists.
|
||||||
@ -120,8 +121,9 @@ public class Island implements DataObject {
|
|||||||
*/
|
*/
|
||||||
public boolean addToBanList(UUID targetUUID) {
|
public boolean addToBanList(UUID targetUUID) {
|
||||||
// TODO fire ban event
|
// TODO fire ban event
|
||||||
if (targetUUID != null)
|
if (targetUUID != null) {
|
||||||
members.put(targetUUID, RanksManager.BANNED_RANK);
|
members.put(targetUUID, RanksManager.BANNED_RANK);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,6 +352,7 @@ public class Island implements DataObject {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getUniqueId() {
|
public String getUniqueId() {
|
||||||
// Island's have UUID's that are randomly assigned if they do not exist
|
// Island's have UUID's that are randomly assigned if they do not exist
|
||||||
if (uniqueId.isEmpty()) {
|
if (uniqueId.isEmpty()) {
|
||||||
@ -418,7 +421,7 @@ public class Island implements DataObject {
|
|||||||
* @return true if allowed, false if not
|
* @return true if allowed, false if not
|
||||||
*/
|
*/
|
||||||
public boolean isAllowed(Flag flag) {
|
public boolean isAllowed(Flag flag) {
|
||||||
return this.getFlag(flag) >= 0;
|
return getFlag(flag) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,7 +432,7 @@ public class Island implements DataObject {
|
|||||||
*/
|
*/
|
||||||
public boolean isAllowed(User user, Flag flag) {
|
public boolean isAllowed(User user, Flag flag) {
|
||||||
//Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag));
|
//Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag));
|
||||||
return this.getRank(user) >= this.getFlag(flag);
|
return getRank(user) >= getFlag(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -547,7 +550,7 @@ public class Island implements DataObject {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unlock the island
|
// Unlock the island
|
||||||
IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build();
|
IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build();
|
||||||
if(!event.isCancelled()){
|
if(!event.isCancelled()){
|
||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
}
|
}
|
||||||
@ -603,14 +606,16 @@ public class Island implements DataObject {
|
|||||||
*/
|
*/
|
||||||
public void setOwner(UUID owner){
|
public void setOwner(UUID owner){
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
if (owner == null) return;
|
if (owner == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Defensive code: demote any previous owner
|
// Defensive code: demote any previous owner
|
||||||
for (Entry<UUID, Integer> en : members.entrySet()) {
|
for (Entry<UUID, Integer> en : members.entrySet()) {
|
||||||
if (en.getValue().equals(RanksManager.OWNER_RANK)) {
|
if (en.getValue().equals(RanksManager.OWNER_RANK)) {
|
||||||
en.setValue(RanksManager.MEMBER_RANK);
|
en.setValue(RanksManager.MEMBER_RANK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.members.put(owner, RanksManager.OWNER_RANK);
|
members.put(owner, RanksManager.OWNER_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -640,23 +645,25 @@ public class Island implements DataObject {
|
|||||||
* @param rank
|
* @param rank
|
||||||
*/
|
*/
|
||||||
public void setRank(User user, int rank) {
|
public void setRank(User user, int rank) {
|
||||||
if (user.getUniqueId() != null) members.put(user.getUniqueId(), rank);
|
if (user.getUniqueId() != null) {
|
||||||
|
members.put(user.getUniqueId(), rank);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ranks the ranks to set
|
* @param ranks the ranks to set
|
||||||
*/
|
*/
|
||||||
public void setRanks(HashMap<UUID, Integer> ranks) {
|
public void setRanks(HashMap<UUID, Integer> ranks) {
|
||||||
this.members = ranks;
|
members = ranks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isSpawn - if the island is the spawn
|
* @param isSpawn - if the island is the spawn
|
||||||
*/
|
*/
|
||||||
public void setSpawn(boolean isSpawn){
|
public void setSpawn(boolean isSpawn){
|
||||||
this.spawn = isSpawn;
|
spawn = isSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the flags to their default as set in config.yml for the spawn
|
* Resets the flags to their default as set in config.yml for the spawn
|
||||||
*/
|
*/
|
||||||
@ -671,6 +678,7 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setUniqueId(String uniqueId) {
|
public void setUniqueId(String uniqueId) {
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
|
@ -31,21 +31,22 @@ public class Players implements DataObject {
|
|||||||
public Players() {}
|
public Players() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* @param uniqueId
|
* @param uniqueId
|
||||||
* Constructor - initializes the state variables
|
* Constructor - initializes the state variables
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Players(BSkyBlock plugin, final UUID uniqueId) {
|
public Players(BSkyBlock plugin, final UUID uniqueId) {
|
||||||
this.uniqueId = uniqueId.toString();
|
this.uniqueId = uniqueId.toString();
|
||||||
this.homeLocations = new HashMap<>();
|
homeLocations = new HashMap<>();
|
||||||
this.playerName = "";
|
playerName = "";
|
||||||
this.resetsLeft = plugin.getSettings().getResetLimit();
|
resetsLeft = plugin.getSettings().getResetLimit();
|
||||||
this.locale = "";
|
locale = "";
|
||||||
this.kickedList = new HashMap<>();
|
kickedList = new HashMap<>();
|
||||||
this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
|
playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
|
||||||
if (this.playerName == null)
|
if (playerName == null) {
|
||||||
this.playerName = uniqueId.toString();
|
playerName = uniqueId.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +65,7 @@ public class Players implements DataObject {
|
|||||||
public Location getHomeLocation(int number) {
|
public Location getHomeLocation(int number) {
|
||||||
/*
|
/*
|
||||||
Bukkit.getLogger().info("DEBUG: getting home location " + number);
|
Bukkit.getLogger().info("DEBUG: getting home location " + number);
|
||||||
|
|
||||||
Bukkit.getLogger().info("DEBUG: " + homeLocations.toString());
|
Bukkit.getLogger().info("DEBUG: " + homeLocations.toString());
|
||||||
for (Entry<Integer, Location> en : homeLocations.entrySet()) {
|
for (Entry<Integer, Location> en : homeLocations.entrySet()) {
|
||||||
Bukkit.getLogger().info("DEBUG: " + en.getKey() + " ==> " + en.getValue());
|
Bukkit.getLogger().info("DEBUG: " + en.getKey() + " ==> " + en.getValue());
|
||||||
@ -148,7 +149,7 @@ public class Players implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the numbered home location of the player. Numbering starts at 1.
|
* Stores the numbered home location of the player. Numbering starts at 1.
|
||||||
* @param location
|
* @param location
|
||||||
* @param number
|
* @param number
|
||||||
*/
|
*/
|
||||||
@ -165,7 +166,7 @@ public class Players implements DataObject {
|
|||||||
* @param uuid
|
* @param uuid
|
||||||
*/
|
*/
|
||||||
public void setPlayerUUID(final UUID uuid) {
|
public void setPlayerUUID(final UUID uuid) {
|
||||||
this.uniqueId = uuid.toString();
|
uniqueId = uuid.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,9 +211,9 @@ public class Players implements DataObject {
|
|||||||
* Add death
|
* Add death
|
||||||
*/
|
*/
|
||||||
public void addDeath() {
|
public void addDeath() {
|
||||||
this.deaths++;
|
deaths++;
|
||||||
if (this.deaths > getPlugin().getSettings().getDeathsMax()) {
|
if (deaths > getPlugin().getSettings().getDeathsMax()) {
|
||||||
this.deaths = getPlugin().getSettings().getDeathsMax();
|
deaths = getPlugin().getSettings().getDeathsMax();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,5 +15,5 @@ import java.lang.annotation.Target;
|
|||||||
public @interface Adapter {
|
public @interface Adapter {
|
||||||
|
|
||||||
Class<?> value();
|
Class<?> value();
|
||||||
|
|
||||||
}
|
}
|
@ -16,9 +16,9 @@ public interface AdapterInterface<S,V> {
|
|||||||
* @return serialized object
|
* @return serialized object
|
||||||
*/
|
*/
|
||||||
S serialize(Object object);
|
S serialize(Object object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize object
|
* Deserialize object
|
||||||
* @param object
|
* @param object
|
||||||
* @return deserialized object
|
* @return deserialized object
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,7 @@ import us.tastybento.bskyblock.BSkyBlock;
|
|||||||
import us.tastybento.bskyblock.api.flags.Flag;
|
import us.tastybento.bskyblock.api.flags.Flag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and
|
* Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and
|
||||||
* {@link us.tastybento.bskyblock.database.objects.Island#setFlags() setFlags()}
|
* {@link us.tastybento.bskyblock.database.objects.Island#setFlags() setFlags()}
|
||||||
* in {@link us.tastybento.bskyblock.database.objects.Island}
|
* in {@link us.tastybento.bskyblock.database.objects.Island}
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -21,8 +21,9 @@ public class FlagSerializer implements AdapterInterface<HashMap<Flag, Integer>,
|
|||||||
@Override
|
@Override
|
||||||
public HashMap<Flag, Integer> serialize(Object object) {
|
public HashMap<Flag, Integer> serialize(Object object) {
|
||||||
HashMap<Flag, Integer> result = new HashMap<>();
|
HashMap<Flag, Integer> result = new HashMap<>();
|
||||||
if (object == null)
|
if (object == null) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
// For YAML
|
// For YAML
|
||||||
if (object instanceof MemorySection) {
|
if (object instanceof MemorySection) {
|
||||||
MemorySection section = (MemorySection) object;
|
MemorySection section = (MemorySection) object;
|
||||||
@ -42,8 +43,9 @@ public class FlagSerializer implements AdapterInterface<HashMap<Flag, Integer>,
|
|||||||
@Override
|
@Override
|
||||||
public HashMap<String, Integer> deserialize(Object object) {
|
public HashMap<String, Integer> deserialize(Object object) {
|
||||||
HashMap<String, Integer> result = new HashMap<>();
|
HashMap<String, Integer> result = new HashMap<>();
|
||||||
if (object == null)
|
if (object == null) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
HashMap<Flag, Integer> flags = (HashMap<Flag, Integer>)object;
|
HashMap<Flag, Integer> flags = (HashMap<Flag, Integer>)object;
|
||||||
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
||||||
result.put(en.getKey().getID(), en.getValue());
|
result.put(en.getKey().getID(), en.getValue());
|
||||||
|
@ -22,13 +22,13 @@ public class PotionEffectListAdapter implements AdapterInterface<List<PotionEffe
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<String> deserialize(Object to) {
|
public List<String> deserialize(Object to) {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
if (to instanceof ArrayList) {
|
if (to instanceof ArrayList) {
|
||||||
for (PotionEffectType type: (ArrayList<PotionEffectType>)to) {
|
for (PotionEffectType type: (ArrayList<PotionEffectType>)to) {
|
||||||
result.add(type.getName());
|
result.add(type.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
|||||||
BSkyBlock plugin;
|
BSkyBlock plugin;
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
PerlinOctaveGenerator gen;
|
PerlinOctaveGenerator gen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plugin
|
* @param plugin
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +14,7 @@ public class IslandWorld {
|
|||||||
private static final String NETHER = "_nether";
|
private static final String NETHER = "_nether";
|
||||||
private static final String THE_END = "_the_end";
|
private static final String THE_END = "_the_end";
|
||||||
private static final String CREATING = "Creating ";
|
private static final String CREATING = "Creating ";
|
||||||
|
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
private static World islandWorld;
|
private static World islandWorld;
|
||||||
private static World netherWorld;
|
private static World netherWorld;
|
||||||
@ -91,7 +91,7 @@ public class IslandWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,17 +32,17 @@ public class NetherPopulator extends BlockPopulator {
|
|||||||
if (b.getType().equals(Material.MOB_SPAWNER)) {
|
if (b.getType().equals(Material.MOB_SPAWNER)) {
|
||||||
CreatureSpawner cs = (CreatureSpawner) b.getState();
|
CreatureSpawner cs = (CreatureSpawner) b.getState();
|
||||||
switch (random.nextInt(3)) {
|
switch (random.nextInt(3)) {
|
||||||
case 0:
|
case 0:
|
||||||
cs.setSpawnedType(EntityType.BLAZE);
|
cs.setSpawnedType(EntityType.BLAZE);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
cs.setSpawnedType(EntityType.SKELETON);
|
cs.setSpawnedType(EntityType.SKELETON);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
cs.setSpawnedType(EntityType.MAGMA_CUBE);
|
cs.setSpawnedType(EntityType.MAGMA_CUBE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cs.setSpawnedType(EntityType.BLAZE);
|
cs.setSpawnedType(EntityType.BLAZE);
|
||||||
}
|
}
|
||||||
} else if (b.getType().equals(Material.OBSIDIAN)) {
|
} else if (b.getType().equals(Material.OBSIDIAN)) {
|
||||||
b.setType(Material.CHEST);
|
b.setType(Material.CHEST);
|
||||||
|
@ -50,7 +50,7 @@ public class IslandBuilder {
|
|||||||
public IslandBuilder(BSkyBlock plugin, Island island) {
|
public IslandBuilder(BSkyBlock plugin, Island island) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.island = island;
|
this.island = island;
|
||||||
this.world = island.getWorld();
|
world = island.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,16 +61,16 @@ public class IslandBuilder {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case END:
|
case END:
|
||||||
this.world = plugin.getIslandWorldManager().getEndWorld();
|
world = plugin.getIslandWorldManager().getEndWorld();
|
||||||
break;
|
break;
|
||||||
case ISLAND:
|
case ISLAND:
|
||||||
this.world = plugin.getIslandWorldManager().getIslandWorld();
|
world = plugin.getIslandWorldManager().getIslandWorld();
|
||||||
break;
|
break;
|
||||||
case NETHER:
|
case NETHER:
|
||||||
this.world = plugin.getIslandWorldManager().getNetherWorld();
|
world = plugin.getIslandWorldManager().getNetherWorld();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.world = island.getWorld();
|
world = island.getWorld();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -82,8 +82,8 @@ public class IslandBuilder {
|
|||||||
* @param player the player to set
|
* @param player the player to set
|
||||||
*/
|
*/
|
||||||
public IslandBuilder setPlayer(Player player) {
|
public IslandBuilder setPlayer(Player player) {
|
||||||
this.playerUUID = player.getUniqueId();
|
playerUUID = player.getUniqueId();
|
||||||
this.playerName = player.getName();
|
playerName = player.getName();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public class IslandBuilder {
|
|||||||
* @param list the default chestItems to set
|
* @param list the default chestItems to set
|
||||||
*/
|
*/
|
||||||
public IslandBuilder setChestItems(List<ItemStack> list) {
|
public IslandBuilder setChestItems(List<ItemStack> list) {
|
||||||
this.chestItems = list;
|
chestItems = list;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public class IslandBuilder {
|
|||||||
generateNetherBlocks();
|
generateNetherBlocks();
|
||||||
} else if (type == IslandType.END){
|
} else if (type == IslandType.END){
|
||||||
generateEndBlocks();
|
generateEndBlocks();
|
||||||
}
|
}
|
||||||
// Do other stuff
|
// Do other stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,12 +477,12 @@ public class IslandBuilder {
|
|||||||
private void placeSign(int x, int y, int z) {
|
private void placeSign(int x, int y, int z) {
|
||||||
Block blockToChange = world.getBlockAt(x, y, z);
|
Block blockToChange = world.getBlockAt(x, y, z);
|
||||||
blockToChange.setType(Material.SIGN_POST);
|
blockToChange.setType(Material.SIGN_POST);
|
||||||
if (this.playerUUID != null) {
|
if (playerUUID != null) {
|
||||||
Sign sign = (Sign) blockToChange.getState();
|
Sign sign = (Sign) blockToChange.getState();
|
||||||
User user = User.getInstance(playerUUID);
|
User user = User.getInstance(playerUUID);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
sign.setLine(i, user.getTranslation("new-island.sign.line" + i, "[player]", playerName));
|
sign.setLine(i, user.getTranslation("new-island.sign.line" + i, "[player]", playerName));
|
||||||
}
|
}
|
||||||
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
|
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
|
||||||
sign.update();
|
sign.update();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class JoinLeaveListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public JoinLeaveListener(BSkyBlock plugin) {
|
public JoinLeaveListener(BSkyBlock plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.players = plugin.getPlayers();
|
players = plugin.getPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
@ -39,48 +39,56 @@ public class JoinLeaveListener implements Listener {
|
|||||||
}
|
}
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
if (plugin.getPlayers().isKnown(playerUUID)) {
|
if (plugin.getPlayers().isKnown(playerUUID)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: known player");
|
plugin.getLogger().info("DEBUG: known player");
|
||||||
|
}
|
||||||
// Load player
|
// Load player
|
||||||
players.addPlayer(playerUUID);
|
players.addPlayer(playerUUID);
|
||||||
// Reset resets if the admin changes it to or from unlimited
|
// Reset resets if the admin changes it to or from unlimited
|
||||||
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
|
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
|
||||||
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
|
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Setting player's name");
|
plugin.getLogger().info("DEBUG: Setting player's name");
|
||||||
|
}
|
||||||
// Set the player's name (it may have changed), but only if it isn't empty
|
// Set the player's name (it may have changed), but only if it isn't empty
|
||||||
if (!user.getName().isEmpty()) {
|
if (!user.getName().isEmpty()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Player name is " + user.getName());
|
plugin.getLogger().info("DEBUG: Player name is " + user.getName());
|
||||||
|
}
|
||||||
players.setPlayerName(user);
|
players.setPlayerName(user);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Saving player");
|
plugin.getLogger().info("DEBUG: Saving player");
|
||||||
|
}
|
||||||
players.save(playerUUID);
|
players.save(playerUUID);
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
|
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
|
||||||
}
|
}
|
||||||
if (plugin.getSettings().isRemoveMobsOnLogin()) {
|
if (plugin.getSettings().isRemoveMobsOnLogin()) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Removing mobs");
|
plugin.getLogger().info("DEBUG: Removing mobs");
|
||||||
|
}
|
||||||
plugin.getIslands().removeMobs(user.getLocation());
|
plugin.getIslands().removeMobs(user.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if they logged in to a locked island and expel them or if they are banned
|
// Check if they logged in to a locked island and expel them or if they are banned
|
||||||
Island currentIsland = plugin.getIslands().getIslandAt(user.getLocation()).orElse(null);
|
Island currentIsland = plugin.getIslands().getIslandAt(user.getLocation()).orElse(null);
|
||||||
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
|
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
|
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
|
||||||
|
}
|
||||||
if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
|
if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
||||||
|
}
|
||||||
user.sendMessage("locked.islandlocked");
|
user.sendMessage("locked.islandlocked");
|
||||||
plugin.getIslands().homeTeleport(user.getPlayer());
|
plugin.getIslands().homeTeleport(user.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: not a known player");
|
plugin.getLogger().info("DEBUG: not a known player");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +55,16 @@ public class PanelListenerManager implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onInventoryClose(InventoryCloseEvent event) {
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) getOpenPanels().remove(event.getPlayer().getUniqueId());
|
if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) {
|
||||||
|
getOpenPanels().remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onLogOut(PlayerQuitEvent event) {
|
public void onLogOut(PlayerQuitEvent event) {
|
||||||
if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) getOpenPanels().remove(event.getPlayer().getUniqueId());
|
if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) {
|
||||||
|
getOpenPanels().remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,5 +73,5 @@ public class PanelListenerManager implements Listener {
|
|||||||
public static HashMap<UUID, Panel> getOpenPanels() {
|
public static HashMap<UUID, Panel> getOpenPanels() {
|
||||||
return openPanels;
|
return openPanels;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
|
|
||||||
private BSkyBlock plugin = BSkyBlock.getInstance();
|
private BSkyBlock plugin = BSkyBlock.getInstance();
|
||||||
private User user = null;
|
private User user = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the plugin
|
* @return the plugin
|
||||||
*/
|
*/
|
||||||
@ -45,7 +45,7 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
public void setPlugin(BSkyBlock plugin) {
|
public void setPlugin(BSkyBlock plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the player associated with this event.
|
* Sets the player associated with this event.
|
||||||
* If the user is a fake player, they are not counted.
|
* If the user is a fake player, they are not counted.
|
||||||
@ -60,7 +60,7 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
setUser(User.getInstance((Player)getPlayer.invoke(e)));
|
setUser(User.getInstance((Player)getPlayer.invoke(e)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e1) { // Do nothing
|
} catch (Exception e1) { // Do nothing
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -70,7 +70,9 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
* @param user
|
* @param user
|
||||||
*/
|
*/
|
||||||
public AbstractFlagListener setUser(User user) {
|
public AbstractFlagListener setUser(User user) {
|
||||||
if (!plugin.getSettings().getFakePlayers().contains(user.getName())) this.user = user;
|
if (!plugin.getSettings().getFakePlayers().contains(user.getName())) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +94,13 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
* @param silent - if true, message is not sent
|
* @param silent - if true, message is not sent
|
||||||
*/
|
*/
|
||||||
public void noGo(Event e, boolean silent) {
|
public void noGo(Event e, boolean silent) {
|
||||||
if (e instanceof Cancellable)
|
if (e instanceof Cancellable) {
|
||||||
((Cancellable)e).setCancelled(true);
|
((Cancellable)e).setCancelled(true);
|
||||||
|
}
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
if (!silent)
|
if (!silent) {
|
||||||
user.sendMessage("protection.protected");
|
user.sendMessage("protection.protected");
|
||||||
|
}
|
||||||
user.updateInventory();
|
user.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +141,7 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
* @param breakBlocks
|
* @param breakBlocks
|
||||||
* @return true if the check is okay, false if it was disallowed
|
* @return true if the check is okay, false if it was disallowed
|
||||||
*/
|
*/
|
||||||
public boolean checkIsland(Event e, Location loc, Flag breakBlocks) {
|
public boolean checkIsland(Event e, Location loc, Flag breakBlocks) {
|
||||||
return checkIsland(e, loc, breakBlocks, false);
|
return checkIsland(e, loc, breakBlocks, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +156,9 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
|
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
|
||||||
// If this is not an Island World, skip
|
// If this is not an Island World, skip
|
||||||
if (!inWorld(loc)) return true;
|
if (!inWorld(loc)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the island and if present
|
// Get the island and if present
|
||||||
Optional<Island> island = getIslands().getIslandAt(loc);
|
Optional<Island> island = getIslands().getIslandAt(loc);
|
||||||
@ -161,10 +167,10 @@ public abstract class AbstractFlagListener implements Listener {
|
|||||||
if (flag.getType().equals(FlagType.SETTING)) {
|
if (flag.getType().equals(FlagType.SETTING)) {
|
||||||
// If the island exists, return the setting, otherwise return the default setting for this flag
|
// If the island exists, return the setting, otherwise return the default setting for this flag
|
||||||
return island.map(x -> x.isAllowed(flag)).orElse(flag.isDefaultSetting());
|
return island.map(x -> x.isAllowed(flag)).orElse(flag.isDefaultSetting());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protection flag
|
// Protection flag
|
||||||
|
|
||||||
// If the user is not set already, try to get it from the event
|
// If the user is not set already, try to get it from the event
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
// Set the user associated with this event
|
// Set the user associated with this event
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
|||||||
|
|
||||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.CHEST);
|
checkIsland(e, e.getClickedBlock().getLocation(), Flags.CHEST);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACACIA_DOOR:
|
case ACACIA_DOOR:
|
||||||
case BIRCH_DOOR:
|
case BIRCH_DOOR:
|
||||||
case DARK_OAK_DOOR:
|
case DARK_OAK_DOOR:
|
||||||
@ -87,7 +87,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
|||||||
case SPRUCE_FENCE_GATE:
|
case SPRUCE_FENCE_GATE:
|
||||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.GATE);
|
checkIsland(e, e.getClickedBlock().getLocation(), Flags.GATE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BURNING_FURNACE:
|
case BURNING_FURNACE:
|
||||||
case FURNACE:
|
case FURNACE:
|
||||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.FURNACE);
|
checkIsland(e, e.getClickedBlock().getLocation(), Flags.FURNACE);
|
||||||
@ -121,7 +121,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Now check for in-hand items
|
// Now check for in-hand items
|
||||||
if (e.getItem() != null) {
|
if (e.getItem() != null) {
|
||||||
switch (e.getItem().getType()) {
|
switch (e.getItem().getType()) {
|
||||||
case ENDER_PEARL:
|
case ENDER_PEARL:
|
||||||
@ -132,7 +132,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,9 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onPlayerInteract(final PlayerInteractEvent e) {
|
public void onPlayerInteract(final PlayerInteractEvent e) {
|
||||||
// Only handle hitting things
|
// Only handle hitting things
|
||||||
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK)) return;
|
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Look along player's sight line to see if any blocks are skulls
|
// Look along player's sight line to see if any blocks are skulls
|
||||||
try {
|
try {
|
||||||
@ -94,7 +96,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
|||||||
if (inWorld(e.getVehicle()) && e.getAttacker() instanceof Player) {
|
if (inWorld(e.getVehicle()) && e.getAttacker() instanceof Player) {
|
||||||
User user = User.getInstance((Player) e.getAttacker());
|
User user = User.getInstance((Player) e.getAttacker());
|
||||||
// Get the island and if present, check the flag, react if required and return
|
// Get the island and if present, check the flag, react if required and return
|
||||||
getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> {
|
getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> {
|
||||||
if (!x.isAllowed(user, Flags.BREAK_BLOCKS)) {
|
if (!x.isAllowed(user, Flags.BREAK_BLOCKS)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
user.sendMessage("protection.protected");
|
user.sendMessage("protection.protected");
|
||||||
@ -117,7 +119,9 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onEntityDamage(EntityDamageByEntityEvent e) {
|
public void onEntityDamage(EntityDamageByEntityEvent e) {
|
||||||
// Only handle item frames and armor stands
|
// Only handle item frames and armor stands
|
||||||
if (!(e.getEntity() instanceof ItemFrame) && !(e.getEntity() instanceof ArmorStand)) return;
|
if (!(e.getEntity() instanceof ItemFrame) && !(e.getEntity() instanceof ArmorStand)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the attacker
|
// Get the attacker
|
||||||
if (e.getDamager() instanceof Player) {
|
if (e.getDamager() instanceof Player) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -41,13 +41,19 @@ public class BucketListener extends AbstractFlagListener {
|
|||||||
public void onBucketFill(final PlayerBucketFillEvent e) {
|
public void onBucketFill(final PlayerBucketFillEvent e) {
|
||||||
// Check filling of various liquids
|
// Check filling of various liquids
|
||||||
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET)) {
|
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET)) {
|
||||||
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA)) return;
|
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (e.getItemStack().getType().equals(Material.WATER_BUCKET)) {
|
if (e.getItemStack().getType().equals(Material.WATER_BUCKET)) {
|
||||||
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER)) return;
|
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (e.getItemStack().getType().equals(Material.MILK_BUCKET)) {
|
if (e.getItemStack().getType().equals(Material.MILK_BUCKET)) {
|
||||||
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING)) return;
|
if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check general bucket use
|
// Check general bucket use
|
||||||
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
|
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -21,14 +21,14 @@ import us.tastybento.bskyblock.lists.Flags;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EntityInteractListener extends AbstractFlagListener {
|
public class EntityInteractListener extends AbstractFlagListener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||||
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
|
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
|
||||||
if (e.getRightClicked() instanceof ArmorStand) {
|
if (e.getRightClicked() instanceof ArmorStand) {
|
||||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.ARMOR_STAND);
|
checkIsland(e, e.getRightClicked().getLocation(), Flags.ARMOR_STAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
|
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
|
||||||
// Animal riding
|
// Animal riding
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -42,10 +42,14 @@ public class FireListener extends AbstractFlagListener {
|
|||||||
// Check if the island exists and if fire is allowed
|
// Check if the island exists and if fire is allowed
|
||||||
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
||||||
island.ifPresent(x -> {
|
island.ifPresent(x -> {
|
||||||
if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
if (!x.isAllowed(Flags.FIRE_SPREAD)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// If not on an island, check the default setting
|
// If not on an island, check the default setting
|
||||||
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true);
|
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,10 +65,14 @@ public class FireListener extends AbstractFlagListener {
|
|||||||
// Check if the island exists and if fire is allowed
|
// Check if the island exists and if fire is allowed
|
||||||
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
||||||
island.ifPresent(x -> {
|
island.ifPresent(x -> {
|
||||||
if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
if (!x.isAllowed(Flags.FIRE_SPREAD)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// If not on an island, check the default setting
|
// If not on an island, check the default setting
|
||||||
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true);
|
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +92,14 @@ public class FireListener extends AbstractFlagListener {
|
|||||||
// Check if the island exists and if fire is allowed
|
// Check if the island exists and if fire is allowed
|
||||||
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
||||||
island.ifPresent(x -> {
|
island.ifPresent(x -> {
|
||||||
if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true);
|
if (!x.isAllowed(Flags.FIRE)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// If not on an island, check the default setting
|
// If not on an island, check the default setting
|
||||||
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true);
|
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,13 +149,19 @@ public class FireListener extends AbstractFlagListener {
|
|||||||
// Check if the island exists and if fire is allowed
|
// Check if the island exists and if fire is allowed
|
||||||
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
|
||||||
island.ifPresent(x -> {
|
island.ifPresent(x -> {
|
||||||
if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true);
|
if (!x.isAllowed(Flags.FIRE)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// If not on an island, check the default setting
|
// If not on an island, check the default setting
|
||||||
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true);
|
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
// If either of these canceled the event, return
|
// If either of these canceled the event, return
|
||||||
if (e.isCancelled()) return;
|
if (e.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
|
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
|
||||||
if (e.getEntity() instanceof Projectile) {
|
if (e.getEntity() instanceof Projectile) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -89,8 +89,9 @@ public class HurtingListener extends AbstractFlagListener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onFishing(PlayerFishEvent e) {
|
public void onFishing(PlayerFishEvent e) {
|
||||||
if (e.getCaught() == null)
|
if (e.getCaught() == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman
|
if ((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman
|
||||||
|| e.getCaught() instanceof Villager) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
|
|| e.getCaught() instanceof Villager) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
|
||||||
@ -98,7 +99,7 @@ public class HurtingListener extends AbstractFlagListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime)
|
if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime)
|
||||||
&& checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
|
&& checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
|
||||||
e.getHook().remove();
|
e.getHook().remove();
|
||||||
return;
|
return;
|
||||||
@ -126,7 +127,7 @@ public class HurtingListener extends AbstractFlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||||
public void onSplashPotionSplash(final PotionSplashEvent e) {
|
public void onSplashPotionSplash(final PotionSplashEvent e) {
|
||||||
// Try to get the shooter
|
// Try to get the shooter
|
||||||
Projectile projectile = (Projectile) e.getEntity();
|
Projectile projectile = e.getEntity();
|
||||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
||||||
Player attacker = (Player)projectile.getShooter();
|
Player attacker = (Player)projectile.getShooter();
|
||||||
// Run through all the affected entities
|
// Run through all the affected entities
|
||||||
@ -164,7 +165,7 @@ public class HurtingListener extends AbstractFlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||||
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
||||||
// Try to get the shooter
|
// Try to get the shooter
|
||||||
Projectile projectile = (Projectile) e.getEntity();
|
Projectile projectile = e.getEntity();
|
||||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
||||||
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
|
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
|
||||||
// Store it and remove it when the effect is gone
|
// Store it and remove it when the effect is gone
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ public class InventoryListener extends AbstractFlagListener {
|
|||||||
public void onMountInventoryClick(InventoryClickEvent e) {
|
public void onMountInventoryClick(InventoryClickEvent e) {
|
||||||
if (e.getInventory().getHolder() == null) {
|
if (e.getInventory().getHolder() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getInventory().getHolder() instanceof Animals) {
|
if (e.getInventory().getHolder() instanceof Animals) {
|
||||||
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||||
}
|
}
|
||||||
else if (e.getInventory().getHolder() instanceof Chest
|
else if (e.getInventory().getHolder() instanceof Chest
|
||||||
|| e.getInventory().getHolder() instanceof Dispenser
|
|| e.getInventory().getHolder() instanceof Dispenser
|
||||||
|| e.getInventory().getHolder() instanceof Hopper
|
|| e.getInventory().getHolder() instanceof Hopper
|
||||||
|| e.getInventory().getHolder() instanceof Dropper
|
|| e.getInventory().getHolder() instanceof Dropper
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class MobSpawnListener extends AbstractFlagListener {
|
|||||||
|| e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) {
|
|| e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) {
|
||||||
Optional<Island> island = getIslands().getIslandAt(e.getLocation());
|
Optional<Island> island = getIslands().getIslandAt(e.getLocation());
|
||||||
if (island.isPresent()) {
|
if (island.isPresent()) {
|
||||||
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
|
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
|
||||||
if (!island.get().isAllowed(Flags.MOB_SPAWN)) {
|
if (!island.get().isAllowed(Flags.MOB_SPAWN)) {
|
||||||
// Mobs not allowed to spawn
|
// Mobs not allowed to spawn
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -58,7 +58,7 @@ public class MobSpawnListener extends AbstractFlagListener {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Outside of the island
|
// Outside of the island
|
||||||
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
|
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
|
||||||
if (!Flags.MOB_SPAWN.isDefaultSetting()) {
|
if (!Flags.MOB_SPAWN.isDefaultSetting()) {
|
||||||
// Mobs not allowed to spawn
|
// Mobs not allowed to spawn
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -45,8 +45,11 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
public void onEntityDamage(final EntityDamageByEntityEvent e) {
|
public void onEntityDamage(final EntityDamageByEntityEvent e) {
|
||||||
if (e.getEntity() instanceof Player) {
|
if (e.getEntity() instanceof Player) {
|
||||||
Flag flag = Flags.PVP_OVERWORLD;
|
Flag flag = Flags.PVP_OVERWORLD;
|
||||||
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
|
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
|
||||||
else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
|
flag = Flags.PVP_NETHER;
|
||||||
|
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||||
|
flag = Flags.PVP_END;
|
||||||
|
}
|
||||||
respond(e, e.getDamager(), flag);
|
respond(e, e.getDamager(), flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,8 +76,11 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
public void onFishing(PlayerFishEvent e) {
|
public void onFishing(PlayerFishEvent e) {
|
||||||
if (e.getCaught() != null && e.getCaught() instanceof Player) {
|
if (e.getCaught() != null && e.getCaught() instanceof Player) {
|
||||||
Flag flag = Flags.PVP_OVERWORLD;
|
Flag flag = Flags.PVP_OVERWORLD;
|
||||||
if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
|
if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
|
||||||
else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
|
flag = Flags.PVP_NETHER;
|
||||||
|
} else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||||
|
flag = Flags.PVP_END;
|
||||||
|
}
|
||||||
if (checkIsland(e, e.getCaught().getLocation(), flag)) {
|
if (checkIsland(e, e.getCaught().getLocation(), flag)) {
|
||||||
e.getHook().remove();
|
e.getHook().remove();
|
||||||
return;
|
return;
|
||||||
@ -90,11 +96,14 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
public void onSplashPotionSplash(final PotionSplashEvent e) {
|
public void onSplashPotionSplash(final PotionSplashEvent e) {
|
||||||
// Deduce the world
|
// Deduce the world
|
||||||
Flag flag = Flags.PVP_OVERWORLD;
|
Flag flag = Flags.PVP_OVERWORLD;
|
||||||
if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
|
if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
|
||||||
else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
|
flag = Flags.PVP_NETHER;
|
||||||
|
} else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||||
|
flag = Flags.PVP_END;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to get the thrower
|
// Try to get the thrower
|
||||||
Projectile projectile = (Projectile) e.getEntity();
|
Projectile projectile = e.getEntity();
|
||||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
||||||
Player attacker = (Player)projectile.getShooter();
|
Player attacker = (Player)projectile.getShooter();
|
||||||
// Run through all the affected entities
|
// Run through all the affected entities
|
||||||
@ -118,7 +127,7 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||||
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
||||||
// Try to get the shooter
|
// Try to get the shooter
|
||||||
Projectile projectile = (Projectile) e.getEntity();
|
Projectile projectile = e.getEntity();
|
||||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
||||||
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
|
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
|
||||||
// Store it and remove it when the effect is gone
|
// Store it and remove it when the effect is gone
|
||||||
@ -133,13 +142,16 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
|
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
|
||||||
if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
|
if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
|
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
|
||||||
// Deduce the world
|
// Deduce the world
|
||||||
Flag flag = Flags.PVP_OVERWORLD;
|
Flag flag = Flags.PVP_OVERWORLD;
|
||||||
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
|
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
|
||||||
else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
|
flag = Flags.PVP_NETHER;
|
||||||
|
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||||
|
flag = Flags.PVP_END;
|
||||||
|
}
|
||||||
|
|
||||||
UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
|
UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
|
||||||
// Self damage
|
// Self damage
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
// Check in-hand items
|
// Check in-hand items
|
||||||
if (e.getMaterial() != null) {
|
if (e.getMaterial() != null) {
|
||||||
// This check protects against an exploit in 1.7.9 against cactus
|
// This check protects against an exploit in 1.7.9 against cactus
|
||||||
// and sugar cane and placing boats on non-liquids
|
// and sugar cane and placing boats on non-liquids
|
||||||
@ -71,7 +71,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles Frost Walking on visitor's islands. This creates ice blocks, which is like placing blocks
|
* Handles Frost Walking on visitor's islands. This creates ice blocks, which is like placing blocks
|
||||||
* @param e
|
* @param e
|
||||||
@ -80,7 +80,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
|
|||||||
public void onBlockForm(EntityBlockFormEvent e) {
|
public void onBlockForm(EntityBlockFormEvent e) {
|
||||||
if (e.getNewState().getType().equals(Material.FROSTED_ICE)) {
|
if (e.getNewState().getType().equals(Material.FROSTED_ICE)) {
|
||||||
// Silently check
|
// Silently check
|
||||||
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS, true);
|
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners.flags;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ public class TeleportationListener extends AbstractFlagListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ender pearl and chorus fruit teleport checks
|
* Ender pearl and chorus fruit teleport checks
|
||||||
*
|
*
|
||||||
* @param e
|
* @param e
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
@ -38,7 +38,7 @@ public class FlyingMobEvents implements Listener {
|
|||||||
*/
|
*/
|
||||||
public FlyingMobEvents(BSkyBlock plugin) {
|
public FlyingMobEvents(BSkyBlock plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.mobSpawnInfo = new WeakHashMap<>();
|
mobSpawnInfo = new WeakHashMap<>();
|
||||||
|
|
||||||
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
|
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
|
||||||
//Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size());
|
//Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size());
|
||||||
|
@ -29,7 +29,7 @@ import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
|||||||
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||||
|
|
||||||
public class Flags {
|
public class Flags {
|
||||||
|
|
||||||
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
|
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
|
||||||
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
|
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public class Flags {
|
|||||||
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
|
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
|
||||||
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
|
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
|
||||||
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
|
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
|
||||||
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
|
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
|
||||||
|
|
||||||
// Chorus Fruit and Enderpearls
|
// Chorus Fruit and Enderpearls
|
||||||
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
|
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
|
||||||
@ -79,7 +79,7 @@ public class Flags {
|
|||||||
* I'll take you to burn.
|
* I'll take you to burn.
|
||||||
* Fire
|
* Fire
|
||||||
* I'll take you to learn.
|
* I'll take you to learn.
|
||||||
* You gonna burn, burn, burn
|
* You gonna burn, burn, burn
|
||||||
* Fire
|
* Fire
|
||||||
* I'll take you to burn
|
* I'll take you to burn
|
||||||
* - The Crazy World of Arthur Brown
|
* - The Crazy World of Arthur Brown
|
||||||
@ -127,7 +127,7 @@ public class Flags {
|
|||||||
return Arrays.asList(Flags.class.getFields()).stream().map(field -> {
|
return Arrays.asList(Flags.class.getFields()).stream().map(field -> {
|
||||||
try {
|
try {
|
||||||
return (Flag)field.get(null);
|
return (Flag)field.get(null);
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage());
|
Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -34,13 +34,13 @@ public final class AddonsManager {
|
|||||||
private static final String LOCALE_FOLDER = "locales";
|
private static final String LOCALE_FOLDER = "locales";
|
||||||
private List<Addon> addons;
|
private List<Addon> addons;
|
||||||
private List<AddonClassLoader> loader;
|
private List<AddonClassLoader> loader;
|
||||||
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
|
private final Map<String, Class<?>> classes = new HashMap<>();
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
|
|
||||||
public AddonsManager(BSkyBlock plugin) {
|
public AddonsManager(BSkyBlock plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.addons = new ArrayList<>();
|
addons = new ArrayList<>();
|
||||||
this.loader = new ArrayList<>();
|
loader = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ public final class AddonsManager {
|
|||||||
for (File file : f.listFiles()) {
|
for (File file : f.listFiles()) {
|
||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
try {
|
try {
|
||||||
this.loadAddon(file);
|
loadAddon(file);
|
||||||
} catch (InvalidAddonFormatException | InvalidAddonInheritException | InvalidDescriptionException e) {
|
} catch (InvalidAddonFormatException | InvalidAddonInheritException | InvalidDescriptionException e) {
|
||||||
plugin.getLogger().severe("Could not load addon " + file.getName() + " : " + e.getMessage());
|
plugin.getLogger().severe("Could not load addon " + file.getName() + " : " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public final class AddonsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addons.forEach(addon -> {
|
addons.forEach(addon -> {
|
||||||
addon.onEnable();
|
addon.onEnable();
|
||||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build());
|
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build());
|
||||||
addon.setEnabled(true);
|
addon.setEnabled(true);
|
||||||
@ -83,10 +83,14 @@ public final class AddonsManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Optional<Addon> getAddonByName(String name){
|
public Optional<Addon> getAddonByName(String name){
|
||||||
if(name.equals("")) return Optional.empty();
|
if(name.equals("")) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
for(Addon addon : this.addons){
|
for(Addon addon : addons){
|
||||||
if(addon.getDescription().getName().contains(name)) return Optional.of(addon);
|
if(addon.getDescription().getName().contains(name)) {
|
||||||
|
return Optional.of(addon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@ -109,7 +113,7 @@ public final class AddonsManager {
|
|||||||
// Open a reader to the jar
|
// Open a reader to the jar
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
||||||
// Grab the description in the addon.yml file
|
// Grab the description in the addon.yml file
|
||||||
Map<String, String> data = this.data(reader);
|
Map<String, String> data = data(reader);
|
||||||
|
|
||||||
// Load the addon
|
// Load the addon
|
||||||
AddonClassLoader loader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader());
|
AddonClassLoader loader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader());
|
||||||
@ -133,7 +137,7 @@ public final class AddonsManager {
|
|||||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
||||||
|
|
||||||
// Add it to the list of addons
|
// Add it to the list of addons
|
||||||
this.addons.add(addon);
|
addons.add(addon);
|
||||||
|
|
||||||
// Run the onLoad() method
|
// Run the onLoad() method
|
||||||
addon.onLoad();
|
addon.onLoad();
|
||||||
@ -153,8 +157,9 @@ public final class AddonsManager {
|
|||||||
private Map<String, String> data(BufferedReader reader) {
|
private Map<String, String> data(BufferedReader reader) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
reader.lines().forEach(string -> {
|
reader.lines().forEach(string -> {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info("DEBUG: " + string);
|
Bukkit.getLogger().info("DEBUG: " + string);
|
||||||
|
}
|
||||||
String[] data = string.split("\\: ");
|
String[] data = string.split("\\: ");
|
||||||
if (data.length > 1) {
|
if (data.length > 1) {
|
||||||
map.put(data[0], data[1].substring(0, data[1].length()));
|
map.put(data[0], data[1].substring(0, data[1].length()));
|
||||||
@ -223,7 +228,7 @@ public final class AddonsManager {
|
|||||||
/**
|
/**
|
||||||
* Sets a class that this loader should know about
|
* Sets a class that this loader should know about
|
||||||
* Code copied from Bukkit JavaPluginLoader
|
* Code copied from Bukkit JavaPluginLoader
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param clazz
|
* @param clazz
|
||||||
*/
|
*/
|
||||||
|
@ -13,9 +13,10 @@ public final class CommandsManager {
|
|||||||
private HashMap<String, Command> commands = new HashMap<>();
|
private HashMap<String, Command> commands = new HashMap<>();
|
||||||
|
|
||||||
public void registerCommand(Command command) {
|
public void registerCommand(Command command) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
Bukkit.getLogger().info("DEBUG: registering command - " + command.getLabel());
|
Bukkit.getLogger().info("DEBUG: registering command - " + command.getLabel());
|
||||||
commands.put(command.getLabel(), command);
|
}
|
||||||
|
commands.put(command.getLabel(), command);
|
||||||
// Use reflection to obtain the commandMap method in Bukkit's server. It used to be visible, but isn't anymore.
|
// Use reflection to obtain the commandMap method in Bukkit's server. It used to be visible, but isn't anymore.
|
||||||
try{
|
try{
|
||||||
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
@ -25,7 +26,7 @@ public final class CommandsManager {
|
|||||||
}
|
}
|
||||||
catch(Exception exception){
|
catch(Exception exception){
|
||||||
Bukkit.getLogger().severe("Bukkit server commandMap method is not there! This means no commands can be registered!");
|
Bukkit.getLogger().severe("Bukkit server commandMap method is not there! This means no commands can be registered!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command getCommand(String command) {
|
public Command getCommand(String command) {
|
||||||
|
@ -66,7 +66,9 @@ public class FlagsManager {
|
|||||||
|
|
||||||
public Flag getFlagByIcon(PanelItem item) {
|
public Flag getFlagByIcon(PanelItem item) {
|
||||||
for (Flag flag : flags.values()) {
|
for (Flag flag : flags.values()) {
|
||||||
if (flag.getIcon().equals(item)) return flag;
|
if (flag.getIcon().equals(item)) {
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public final class LocalesManager {
|
|||||||
|
|
||||||
public LocalesManager(BSkyBlock plugin) {
|
public LocalesManager(BSkyBlock plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.loadLocales("BSkyBlock"); // Default
|
loadLocales("BSkyBlock"); // Default
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,8 +35,9 @@ public final class LocalesManager {
|
|||||||
*/
|
*/
|
||||||
public String get(User user, String reference) {
|
public String get(User user, String reference) {
|
||||||
BSBLocale locale = languages.get(user.getLocale());
|
BSBLocale locale = languages.get(user.getLocale());
|
||||||
if (locale != null && locale.contains(reference))
|
if (locale != null && locale.contains(reference)) {
|
||||||
return locale.get(reference);
|
return locale.get(reference);
|
||||||
|
}
|
||||||
// Return the default
|
// Return the default
|
||||||
if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) {
|
if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) {
|
||||||
return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference);
|
return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference);
|
||||||
@ -54,23 +55,22 @@ public final class LocalesManager {
|
|||||||
plugin.getLogger().info("DEBUG: loading locale for " + parent);
|
plugin.getLogger().info("DEBUG: loading locale for " + parent);
|
||||||
}
|
}
|
||||||
// Describe the filter - we only want files that are correctly named
|
// Describe the filter - we only want files that are correctly named
|
||||||
FilenameFilter ymlFilter = new FilenameFilter() {
|
FilenameFilter ymlFilter = (dir, name) -> {
|
||||||
@Override
|
// Files must be 9 chars long
|
||||||
public boolean accept(File dir, String name) {
|
if (name.toLowerCase().endsWith(".yml") && name.length() == 9) {
|
||||||
// Files must be 9 chars long
|
if (DEBUG) {
|
||||||
if (name.toLowerCase().endsWith(".yml") && name.length() == 9) {
|
plugin.getLogger().info("DEBUG: bsb locale filename = " + name);
|
||||||
if (DEBUG)
|
}
|
||||||
plugin.getLogger().info("DEBUG: bsb locale filename = " + name);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run through the files and store the locales
|
// Run through the files and store the locales
|
||||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: localeDir = " + localeDir.getAbsolutePath());
|
plugin.getLogger().info("DEBUG: localeDir = " + localeDir.getAbsolutePath());
|
||||||
|
}
|
||||||
// If the folder does not exist, then make it and fill with the locale files from the jar
|
// If the folder does not exist, then make it and fill with the locale files from the jar
|
||||||
// If it does exist, then new files will NOT be written!
|
// If it does exist, then new files will NOT be written!
|
||||||
if (!localeDir.exists()) {
|
if (!localeDir.exists()) {
|
||||||
@ -83,8 +83,9 @@ public final class LocalesManager {
|
|||||||
// Get the last part of the name
|
// Get the last part of the name
|
||||||
int lastIndex = name.lastIndexOf('/');
|
int lastIndex = name.lastIndexOf('/');
|
||||||
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
|
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath());
|
plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath());
|
||||||
|
}
|
||||||
if (!targetFile.exists()) {
|
if (!targetFile.exists()) {
|
||||||
java.nio.file.Files.copy(initialStream, targetFile.toPath());
|
java.nio.file.Files.copy(initialStream, targetFile.toPath());
|
||||||
}
|
}
|
||||||
@ -101,19 +102,23 @@ public final class LocalesManager {
|
|||||||
|
|
||||||
// Store all the locales available
|
// Store all the locales available
|
||||||
for (File language : localeDir.listFiles(ymlFilter)) {
|
for (File language : localeDir.listFiles(ymlFilter)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: parent = " + parent + " language = " + language.getName().substring(0, language.getName().length() - 4));
|
plugin.getLogger().info("DEBUG: parent = " + parent + " language = " + language.getName().substring(0, language.getName().length() - 4));
|
||||||
|
}
|
||||||
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
|
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry());
|
plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry());
|
||||||
|
}
|
||||||
if (languages.containsKey(localeObject)) {
|
if (languages.containsKey(localeObject)) {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: this locale is known");
|
plugin.getLogger().info("DEBUG: this locale is known");
|
||||||
|
}
|
||||||
// Merge into current language
|
// Merge into current language
|
||||||
languages.get(localeObject).merge(language);
|
languages.get(localeObject).merge(language);
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: this locale is not known - new language");
|
plugin.getLogger().info("DEBUG: this locale is not known - new language");
|
||||||
|
}
|
||||||
// New language
|
// New language
|
||||||
languages.put(localeObject, new BSBLocale(localeObject, language));
|
languages.put(localeObject, new BSBLocale(localeObject, language));
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user