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