Cleaned up imports and unneeded exceptions

This commit is contained in:
Tastybento 2018-03-11 15:59:03 -07:00
parent 8e97186caf
commit b20fbd55a4
30 changed files with 72 additions and 278 deletions

View File

@ -1,11 +1,11 @@
package us.tastybento.bskyblock.api.commands;
import us.tastybento.bskyblock.api.user.User;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import us.tastybento.bskyblock.api.user.User;
/**
* Interface for BSkyBlock Commands
* @author tastybento

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Optional;
import org.apache.commons.lang.math.NumberUtils;
import us.tastybento.bskyblock.api.user.User;
/**

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.api.configuration;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@ -43,8 +42,8 @@ public class BSBConfig<T> {
List<T> result = new ArrayList<>();
try {
result = handler.loadObjects();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
logger.severe(() -> "Could not load config! Error: " + e.getMessage());
}
return result;
@ -56,12 +55,14 @@ public class BSBConfig<T> {
* @return the object or null if it cannot be loaded
*/
public T loadConfigObject(String uniqueId) {
try {
return handler.loadObject(uniqueId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {
| ClassNotFoundException | IntrospectionException e) {
logger.severe(() -> "Could not load config object! " + e.getMessage());
}
return null;
}
@ -73,7 +74,7 @@ public class BSBConfig<T> {
try {
handler.saveObject(instance);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
| InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) {
| IntrospectionException e) {
logger.severe(() -> "Could not save config! Error: " + e.getMessage());
return false;
}

View File

@ -6,9 +6,9 @@ import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User;
public class Flag implements Comparable<Flag> {

View File

@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User;
public class PanelItem {

View File

@ -2,10 +2,10 @@ package us.tastybento.bskyblock.api.panels.builders;
import java.util.TreeMap;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.PanelListener;
import us.tastybento.bskyblock.api.user.User;
public class PanelBuilder {
private String name;

View File

@ -1,9 +1,9 @@
package us.tastybento.bskyblock.api.placeholders.hooks;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.placeholders.Placeholder;
import us.tastybento.bskyblock.api.placeholders.PlaceholderAPIInterface;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.lists.Placeholders;
/**

View File

@ -1,12 +1,12 @@
package us.tastybento.bskyblock.api.user;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
* Utilities class that helps to avoid spamming the User with potential repeated messages
* @author Poslovitch

View File

@ -5,12 +5,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;

View File

@ -8,8 +8,8 @@ import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.managers.island.NewIsland;

View File

@ -8,8 +8,8 @@ import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.island.NewIsland;

View File

@ -6,9 +6,9 @@ import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User;
public class IslandTeamCommand extends AbstractIslandTeamCommand {

View File

@ -8,9 +8,9 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {

View File

@ -10,9 +10,9 @@ import java.util.UUID;
import org.bukkit.OfflinePlayer;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {

View File

@ -4,9 +4,9 @@ import java.util.List;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User;
public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {

View File

@ -7,9 +7,9 @@ import java.util.Optional;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.database;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.plugin.Plugin;
@ -51,7 +50,7 @@ public abstract class AbstractDatabaseHandler<T> {
* Loads all the records in this table and returns a list of them
* @return list of <T>
*/
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException;
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
/**
* Creates a <T> filled with values from the corresponding
@ -59,20 +58,20 @@ public abstract class AbstractDatabaseHandler<T> {
* @param uniqueId - unique ID
* @return <T>
*/
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException;
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
/**
* Save T into the corresponding database
*
* @param instance that should be inserted into the database
*/
public abstract void saveObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, InstantiationException, NoSuchMethodException;
public abstract void saveObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException ;
/**
* Deletes the object with the unique id from the database
* @param instance
*/
public abstract void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException;
public abstract void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException ;
/**
* Checks if a key exists or not

View File

@ -19,7 +19,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.MemorySection;
@ -49,7 +48,6 @@ import us.tastybento.bskyblock.util.Util;
public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
private static final String DATABASE_FOLDER_NAME = "database";
private static final boolean DEBUG = false;
protected boolean configFlag;
public FlatFileDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
@ -60,7 +58,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#loadObject(java.lang.String)
*/
@Override
public T loadObject(String key) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException {
public T loadObject(String key) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
String path = DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName();
String fileName = key;
StoreAt storeAt = dataObject.getAnnotation(StoreAt.class);
@ -82,7 +80,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#loadObjects()
*/
@Override
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException {
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
List<T> list = new ArrayList<>();
FilenameFilter ymlFilter = (dir, name) -> {
return name.toLowerCase().endsWith(".yml");
@ -126,9 +124,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
// Get the write method
Method method = propertyDescriptor.getWriteMethod();
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);
@ -138,26 +133,15 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
storageLocation = configEntry.path();
}
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
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) {
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));
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: value = " + value);
plugin.getLogger().info(() -> "DEBUG: property type = " + propertyDescriptor.getPropertyType());
plugin.getLogger().info(() -> "DEBUG: " + value.getClass());
}
if (value != null && !value.getClass().equals(MemorySection.class)) {
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
}
@ -179,9 +163,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// collectionTypes should be 2 long
Type keyType = collectionTypes.get(0);
Type valueType = collectionTypes.get(1);
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<>();
if (config.getConfigurationSection(storageLocation) != null) {
@ -193,32 +174,17 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
// Map values can be null - it is allowed here
Object mapValue = deserialize(config.get(storageLocation + "." + key), Class.forName(valueType.getTypeName()));
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: mapKey = " + mapKey + " (" + mapKey.getClass().getCanonicalName() + ")");
plugin.getLogger().info(() -> "DEBUG: mapValue = " + mapValue);
}
value.put(mapKey, mapValue);
}
}
method.invoke(instance, value);
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName());
plugin.getLogger().info("DEBUG: adding a set");
}
// 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) {
plugin.getLogger().info(() -> "DEBUG: is HashSet<" + setType.getTypeName() + ">");
}
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)) {
value.add(deserialize(listValue,Class.forName(setType.getTypeName())));
}
@ -226,9 +192,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// TODO: this may not work with all keys. Further serialization may be required.
method.invoke(instance, value);
} else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding a set");
}
// Loop through the collection resultset
// Note that we have no idea what type this is
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
@ -244,16 +207,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
method.invoke(instance, value);
} else {
// Not a collection
if (DEBUG) {
plugin.getLogger().info("DEBUG: not a collection");
}
Object value = config.get(storageLocation);
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: name = " + field.getName());
plugin.getLogger().info(() -> "DEBUG: value = " + value);
plugin.getLogger().info(() -> "DEBUG: property type = " + propertyDescriptor.getPropertyType());
plugin.getLogger().info(() -> "DEBUG: value class " + value.getClass());
}
if (value != null && !value.getClass().equals(MemorySection.class)) {
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
}
@ -302,18 +256,11 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
Method method = propertyDescriptor.getReadMethod();
// Invoke the read method to get the value. We have no idea what type of value it is.
Object value = method.invoke(instance);
if (DEBUG) {
plugin.getLogger().info("DEBUG: field = " + field.getName() + " value = " + value);
}
String storageLocation = field.getName();
// Check if there is an annotation on the field
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
// If there is a config path annotation then do something
if (configEntry != null) {
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: configEntry fould " + configEntry.toString() + " " + configEntry.specificTo());
plugin.getLogger().info(() -> "DEBUG: " + field.getName());
}
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
continue fields;
}
@ -338,9 +285,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Adapter
Adapter adapterNotation = field.getAnnotation(Adapter.class);
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: there is an adapter");
}
// A conversion adapter has been defined
try {
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
@ -399,9 +343,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
throw new IllegalArgumentException("No uniqueId in class");
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: Saving YAML file : " + path + " " + filename);
}
databaseConnecter.saveYamlFile(config, path, filename, yamlComments);
}
@ -433,13 +374,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object deserialize(Object value, Class<? extends Object> clazz) {
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: deserialize - class is " + clazz.getCanonicalName());
plugin.getLogger().info("DEBUG: value is " + value);
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;

View File

@ -12,9 +12,9 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.panels.ClickType;
import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.user.User;
public class PanelListenerManager implements Listener {

View File

@ -15,9 +15,9 @@ import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.Flag.Type;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.IslandsManager;

View File

@ -19,8 +19,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.BlockIterator;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.lists.Flags;
/**

View File

@ -7,7 +7,18 @@ import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Parrot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Villager;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,8 +31,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -83,13 +94,9 @@ public class HurtingListener extends AbstractFlagListener {
return;
}
if ((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman)
&& checkIsland(e, e.getCaught().getLocation(), Flags.HURT_ANIMALS)) {
e.getHook().remove();
} else if (e.getCaught() instanceof Villager && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_VILLAGERS)) {
e.getHook().remove();
} else if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime)
&& checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
if (((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_ANIMALS))
|| ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS))
|| (e.getCaught() instanceof Villager && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_VILLAGERS))) {
e.getHook().remove();
}
}

View File

@ -20,8 +20,8 @@ import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User;
/**
* TODO: PVP is different to other flags - it's either allowed for everyone or not allowed for everyone. Currently owners can hit visitors.

View File

@ -40,7 +40,6 @@ import us.tastybento.bskyblock.util.teleport.SafeTeleportBuilder;
*/
public class IslandsManager {
private static final boolean DEBUG = false;
/**
* Checks if this location is safe for a player to teleport to. Used by
* warps and boat exits Unsafe is any liquid or air and also if there's no
@ -54,14 +53,9 @@ public class IslandsManager {
if (l == null) {
return false;
}
// TODO: improve the safe location finding.
//Bukkit.getLogger().info("DEBUG: " + l.toString());
final Block ground = l.getBlock().getRelative(BlockFace.DOWN);
final Block space1 = l.getBlock();
final Block space2 = l.getBlock().getRelative(BlockFace.UP);
//Bukkit.getLogger().info("DEBUG: ground = " + ground.getType());
//Bukkit.getLogger().info("DEBUG: space 1 = " + space1.getType());
//Bukkit.getLogger().info("DEBUG: space 2 = " + space2.getType());
// Portals are not "safe"
if (space1.getType() == Material.PORTAL || ground.getType() == Material.PORTAL || space2.getType() == Material.PORTAL
|| space1.getType() == Material.ENDER_PORTAL || ground.getType() == Material.ENDER_PORTAL || space2.getType() == Material.ENDER_PORTAL) {
@ -70,40 +64,32 @@ public class IslandsManager {
// If ground is AIR, then this is either not good, or they are on slab,
// stair, etc.
if (ground.getType() == Material.AIR) {
// Bukkit.getLogger().info("DEBUG: air");
return false;
}
// In BSkyBlock, liquid may be unsafe
// Check if acid has no damage
if (plugin.getSettings().getAcidDamage() > 0D && (ground.isLiquid() || space1.isLiquid() || space2.isLiquid())) {
// Bukkit.getLogger().info("DEBUG: acid");
return false;
}
if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA)
|| space1.getType().equals(Material.STATIONARY_LAVA) || space1.getType().equals(Material.LAVA)
|| space2.getType().equals(Material.STATIONARY_LAVA) || space2.getType().equals(Material.LAVA)) {
// Lava check only
// Bukkit.getLogger().info("DEBUG: lava");
return false;
}
MaterialData md = ground.getState().getData();
if (md instanceof SimpleAttachableMaterialData) {
//Bukkit.getLogger().info("DEBUG: trapdoor/button/tripwire hook etc.");
if (md instanceof TrapDoor) {
TrapDoor trapDoor = (TrapDoor)md;
if (trapDoor.isOpen()) {
//Bukkit.getLogger().info("DEBUG: trapdoor open");
return false;
}
} else {
return false;
}
//Bukkit.getLogger().info("DEBUG: trapdoor closed");
}
if (ground.getType().equals(Material.CACTUS) || ground.getType().equals(Material.BOAT) || ground.getType().equals(Material.FENCE)
|| ground.getType().equals(Material.NETHER_FENCE) || ground.getType().equals(Material.SIGN_POST) || ground.getType().equals(Material.WALL_SIGN)) {
// Bukkit.getLogger().info("DEBUG: cactus");
return false;
}
// Check that the space is not solid
@ -118,9 +104,9 @@ public class IslandsManager {
return false;
}
// Safe
//Bukkit.getLogger().info("DEBUG: safe!");
return true;
}
private BSkyBlock plugin;
private BSBDatabase database;
@ -171,13 +157,6 @@ public class IslandsManager {
depth = l.getBlockY();
}
//plugin.getLogger().info("DEBUG: ranges i = " + i);
//plugin.getLogger().info(" " + minX + "," + minZ + " " + maxX + " " + maxZ);
//plugin.getLogger().info("DEBUG: height = " + height);
//plugin.getLogger().info("DEBUG: depth = " + depth);
//plugin.getLogger().info("DEBUG: trying to find a safe spot at " + l.toString());
// Work outwards from l until the closest safe location is found.
int minXradius = 0;
int maxXradius = 0;
@ -197,10 +176,8 @@ public class IslandsManager {
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
if (!((x > minX && x < maxX) && (z > minZ && z < maxZ) && (y > minY && y < maxY))) {
//plugin.getLogger().info("DEBUG: checking " + x + "," + y + "," + z);
Location ultimate = new Location(l.getWorld(), x + 0.5D, y, z + 0.5D);
if (isSafeLocation(ultimate)) {
//plugin.getLogger().info("DEBUG: Found! " + ultimate);
return ultimate;
}
}
@ -225,8 +202,6 @@ public class IslandsManager {
if (maxYradius < height) {
maxYradius++;
}
//plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius +
// "," + maxXradius + "," + maxYradius + "," + maxZradius);
} while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth
|| maxYradius < height);
// Nothing worked
@ -249,9 +224,6 @@ public class IslandsManager {
* @return Island
*/
public Island createIsland(Location location, UUID owner){
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
}
return islandCache.createIsland(new Island(location, owner, plugin.getSettings().getIslandProtectionRange()));
}
@ -276,13 +248,11 @@ public class IslandsManager {
try {
handler.deleteObject(island);
} catch (Exception e) {
plugin.getLogger().severe("Could not delete island from database! " + e.getMessage());
plugin.getLogger().severe(()->"Could not delete island from database! " + e.getMessage());
}
// Remove blocks from world
new DeleteIslandChunks(plugin, island);
}
//getServer().getPluginManager().callEvent(new IslandDeleteEvent(player, island.getCenter()));
}
/**
@ -296,19 +266,12 @@ public class IslandsManager {
*/
public void deleteIsland(final UUID player, boolean removeBlocks) {
// Removes the island
if (DEBUG) {
plugin.getLogger().info("DEBUG: deleting player island");
}
//CoopPlay.getInstance().clearAllIslandCoops(player);
//getWarpSignsListener().removeWarp(player);
final Island island = getIsland(player);
final Island island = getIsland(player);
if (island != null) {
deleteIsland(island, removeBlocks);
} else {
plugin.getLogger().severe("Could not delete player: " + player.toString() + " island!");
//plugin.getServer().getPluginManager().callEvent(new IslandDeleteEvent(player, null));
plugin.getLogger().severe(()->"Could not delete player: " + player.toString() + " island!");
}
//players.zeroPlayerData(player);
}
/**
@ -359,17 +322,14 @@ public class IslandsManager {
*/
public Optional<Island> getIslandAt(Location location) {
if (location == null) {
//plugin.getLogger().info("DEBUG: location is null");
return Optional.empty();
}
// World check
if (!Util.inWorld(location)) {
//plugin.getLogger().info("DEBUG: not in right world");
return Optional.empty();
}
// Check if it is spawn
if (spawn != null && spawn.onIsland(location)) {
//plugin.getLogger().info("DEBUG: spawn");
return Optional.of(spawn);
}
return Optional.ofNullable(getIslandAt(location.getBlockX(), location.getBlockZ()));
@ -420,7 +380,6 @@ public class IslandsManager {
*/
public Optional<Island> getProtectedIslandAt(Location location) {
//plugin.getLogger().info("DEBUG: getProtectedIslandAt " + location);
// Try spawn
if (spawn != null && spawn.onIsland(location)) {
return Optional.of(spawn);
@ -446,9 +405,6 @@ public class IslandsManager {
l = plugin.getPlayers().getHomeLocation(playerUUID, number);
}
// Check if it is safe
if (DEBUG) {
plugin.getLogger().info("DEBUG: Home location " + l);
}
if (l != null) {
if (isSafeLocation(l)) {
return l;
@ -464,45 +420,24 @@ public class IslandsManager {
}
}
}
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) {
plugin.getLogger().info("DEBUG:player is in team");
}
l = plugin.getIslands().getIslandLocation(playerUUID);
if (isSafeLocation(l)) {
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) {
plugin.getLogger().info("DEBUG: trying leader's home");
}
Location tlh = plugin.getPlayers().getHomeLocation(plugin.getIslands().getTeamLeader(playerUUID));
if (tlh != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: leader has a home");
}
if (isSafeLocation(tlh)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: team leader's home is safe");
}
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
return tlh;
}
}
}
} else {
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);
@ -510,35 +445,23 @@ public class IslandsManager {
}
}
if (l == null) {
plugin.getLogger().warning(plugin.getPlayers().getName(playerUUID) + " player has no island!");
plugin.getLogger().warning(()-> plugin.getPlayers().getName(playerUUID) + " player has no island!");
return null;
}
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) {
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) {
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) {
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)) {
@ -546,9 +469,6 @@ public class IslandsManager {
return n;
}
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: unsuccessful");
}
// Unsuccessful
return null;
}
@ -561,11 +481,7 @@ public class IslandsManager {
* @return the spawnPoint or null if spawn does not exist
*/
public Location getSpawnPoint() {
//plugin.getLogger().info("DEBUG: getting spawn point : " + spawn.getSpawnPoint());
if (spawn == null) {
return null;
}
return spawn.getSpawnPoint();
return spawn == null ? null : spawn.getSpawnPoint();
}
/**
@ -602,14 +518,7 @@ public class IslandsManager {
*/
@SuppressWarnings("deprecation")
public void homeTeleport(final Player player, int number) {
Location home;
if (DEBUG) {
plugin.getLogger().info("home teleport called for #" + number);
}
home = getSafeHomeLocation(player.getUniqueId(), number);
if (DEBUG) {
plugin.getLogger().info("home get safe loc = " + home);
}
Location home = getSafeHomeLocation(player.getUniqueId(), number);
// Check if the player is a passenger in a boat
if (player.isInsideVehicle()) {
Entity boat = player.getVehicle();
@ -622,19 +531,13 @@ public class IslandsManager {
}
}
if (home == null) {
if (DEBUG) {
plugin.getLogger().info("Fixing home location using safe spot teleport");
}
// Try to fix this teleport location and teleport the player if possible
// Try to fix this teleport location and teleport the player if possible
new SafeTeleportBuilder(plugin).entity(player)
.island(plugin.getIslands().getIsland(player.getUniqueId()))
.homeNumber(number)
.build();
return;
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
}
player.teleport(home);
User user = User.getInstance(player);
if (number == 1) {
@ -679,7 +582,6 @@ public class IslandsManager {
if (!plugin.getSettings().isUseOwnGenerator()) {
// Block check
if (!location.getBlock().isEmpty() && !location.getBlock().isLiquid()) {
plugin.getLogger().info("Found solid block at island height - adding");
createIsland(location);
return true;
}
@ -690,7 +592,6 @@ public class IslandsManager {
for (int z = -5; z <= 5; z++) {
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);
return true;
}
@ -721,10 +622,7 @@ public class IslandsManager {
* @return true if the player is the owner of their island, i.e., owner or team leader
*/
public boolean isOwner(UUID uniqueId) {
if (hasIsland(uniqueId)) {
return getIsland(uniqueId).getOwner().equals(uniqueId);
}
return false;
return hasIsland(uniqueId) ? getIsland(uniqueId).getOwner().equals(uniqueId) : false;
}
/**
@ -734,21 +632,11 @@ public class IslandsManager {
islandCache.clear();
spawn = null;
try {
if (DEBUG) {
plugin.getLogger().info("DEBUG: loading grid");
}
for (Island island : handler.loadObjects()) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding island at "+ island.getCenter());
}
islandCache.addIsland(island);
islandCache.addIsland(island);
}
} catch (Exception e) {
plugin.getLogger().severe("Could not load islands to cache! " + e.getMessage());
e.printStackTrace();
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: islands loaded");
plugin.getLogger().severe(()->"Could not load islands to cache! " + e.getMessage());
}
}
@ -822,9 +710,6 @@ public class IslandsManager {
* @param playerUUID - the player's UUID
*/
public void removePlayer(UUID playerUUID) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: removing player");
}
islandCache.removePlayer(playerUUID);
}
@ -837,22 +722,18 @@ public class IslandsManager {
// Teleport players away
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
//plugin.getLogger().info("DEBUG: in island space");
// Teleport island players to their island home
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
//plugin.getLogger().info("DEBUG: home teleport");
homeTeleport(player);
} else {
//plugin.getLogger().info("DEBUG: move player to spawn");
// Move player to spawn
Island spawn = getSpawn();
if (spawn != null) {
// go to island spawn
player.teleport(plugin.getIslandWorldManager().getIslandWorld().getSpawnLocation());
//plugin.getLogger().warning("During island deletion player " + player.getName() + " sent to spawn.");
} else {
if (!player.performCommand(Constants.SPAWNCOMMAND)) {
plugin.getLogger().warning(
plugin.getLogger().warning(()->
"During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry.");
}
}
@ -869,36 +750,26 @@ public class IslandsManager {
Collection<Island> collection = islandCache.getIslands();
if(async){
Runnable save = () -> {
int index = 1;
for(Island island : collection){
if (DEBUG) {
plugin.getLogger().info("DEBUG: saving island async " + index++);
}
try {
handler.saveObject(island);
} catch (Exception e) {
plugin.getLogger().severe("Could not save island to datavase when running async! " + e.getMessage());
plugin.getLogger().severe(()->"Could not save island to datavase when running async! " + e.getMessage());
}
}
};
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
} else {
int index = 1;
for(Island island : collection){
if (DEBUG) {
plugin.getLogger().info("DEBUG: saving island " + index++);
}
try {
handler.saveObject(island);
} catch (Exception e) {
plugin.getLogger().severe("Could not save island to datavase when running sync! " + e.getMessage());
plugin.getLogger().severe(()->"Could not save island to datavase when running sync! " + e.getMessage());
}
}
}
}
// Metrics-related methods //
/**
* Set the island name
* @param owner - the island owner
@ -915,15 +786,8 @@ public class IslandsManager {
*/
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
// Add player to new island
if (DEBUG) {
plugin.getLogger().info("DEBUG: Adding player to new island");
}
teamIsland.addMember(playerUUID);
islandCache.addPlayer(playerUUID, teamIsland);
if (DEBUG) {
plugin.getLogger().info("DEBUG: new team member list:");
plugin.getLogger().info(teamIsland.getMemberSet().toString());
}
// Save the database
save(false);
@ -939,9 +803,6 @@ public class IslandsManager {
* @param playerUUID - the player's UUID
*/
public void setLeaveTeam(UUID playerUUID) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: leaving team");
}
plugin.getPlayers().clearHomeLocations(playerUUID);
removePlayer(playerUUID);
}

View File

@ -8,8 +8,8 @@ import java.util.HashMap;
import java.util.Locale;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.localization.BSBLocale;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.FileLister;
/**

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.managers;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -586,8 +585,7 @@ public class PlayersManager{
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | SecurityException
| InstantiationException | NoSuchMethodException
| IntrospectionException | SQLException e) {
| IntrospectionException e) {
plugin.getLogger().severe("Could not save player to database: " + playerUUID + " " + e.getMessage());
}
} else {

View File

@ -1,11 +1,11 @@
package us.tastybento.bskyblock.panels;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User;
/**
* @author Poslovitch

View File

@ -51,11 +51,11 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagBuilder;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.listeners.flags.AbstractFlagListener;

View File

@ -28,9 +28,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.modules.junit4.PowerMockRunner;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.api.panels.ClickType;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.user.User;
@RunWith(PowerMockRunner.class)
public class PanelItemBuilderTest {

View File

@ -30,8 +30,6 @@ import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.database.mysql.MySQLDatabaseConnecter;
import us.tastybento.bskyblock.database.mysql.MySQLDatabaseHandler;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.database.objects.Players;
import us.tastybento.bskyblock.lists.Flags;