mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-01 00:10:40 +01:00
Cleans up code smells.
This commit is contained in:
parent
dd0396161e
commit
3f3ac57f1e
@ -386,7 +386,7 @@ public abstract class Addon {
|
||||
|
||||
/**
|
||||
* Register request handler to answer requests from plugins.
|
||||
* @param handler
|
||||
* @param handler request handler
|
||||
*/
|
||||
public void registerRequestHandler(AddonRequestHandler handler) {
|
||||
requestHandlers.put(handler.getLabel(), handler);
|
||||
@ -394,8 +394,8 @@ public abstract class Addon {
|
||||
|
||||
/**
|
||||
* Send request to addon.
|
||||
* @param label
|
||||
* @param metaData
|
||||
* @param label label
|
||||
* @param metaData meta data
|
||||
* @return request response, null if no response.
|
||||
*/
|
||||
public Object request(String label, Map<String, Object> metaData) {
|
||||
|
@ -30,6 +30,7 @@ import world.bentobox.bentobox.managers.AddonsManager;
|
||||
*/
|
||||
public class AddonClassLoader extends URLClassLoader {
|
||||
|
||||
private static final String DEFAULT = ".default";
|
||||
private final Map<String, Class<?>> classes = new HashMap<>();
|
||||
private Addon addon;
|
||||
private AddonsManager loader;
|
||||
@ -71,7 +72,7 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
if (data.isConfigurationSection("permissions")) {
|
||||
ConfigurationSection perms = data.getConfigurationSection("permissions");
|
||||
perms.getKeys(true).forEach(perm -> {
|
||||
if (perms.contains(perm + ".default") && perms.contains(perm + ".description")) {
|
||||
if (perms.contains(perm + DEFAULT) && perms.contains(perm + ".description")) {
|
||||
registerPermission(perms, perm);
|
||||
}
|
||||
});
|
||||
@ -79,7 +80,11 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
private void registerPermission(ConfigurationSection perms, String perm) {
|
||||
PermissionDefault pd = PermissionDefault.getByName(perms.getString(perm + ".default"));
|
||||
if (perms.getString(perm + DEFAULT) == null) {
|
||||
Bukkit.getLogger().severe("Permission default is invalid : " + perms.getName());
|
||||
return;
|
||||
}
|
||||
PermissionDefault pd = PermissionDefault.getByName(perms.getString(perm + DEFAULT));
|
||||
if (pd == null) {
|
||||
Bukkit.getLogger().severe("Permission default is invalid : " + perms.getName());
|
||||
return;
|
||||
@ -138,7 +143,6 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
result = super.findClass(name);
|
||||
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||
// Do nothing.
|
||||
result = null;
|
||||
}
|
||||
if (result != null) {
|
||||
loader.setClass(name, result);
|
||||
|
@ -18,7 +18,7 @@ public class AddonRequestBuilder
|
||||
/**
|
||||
* Define the addon you wish to request.
|
||||
*
|
||||
* @param addonName
|
||||
* @param addonName addon name
|
||||
*/
|
||||
public AddonRequestBuilder addon(String addonName) {
|
||||
this.addonName = addonName;
|
||||
@ -28,7 +28,7 @@ public class AddonRequestBuilder
|
||||
/**
|
||||
* Define label for addon request.
|
||||
*
|
||||
* @param requestLabel
|
||||
* @param requestLabel request label
|
||||
*/
|
||||
public AddonRequestBuilder label(String requestLabel) {
|
||||
this.requestLabel = requestLabel;
|
||||
@ -38,8 +38,8 @@ public class AddonRequestBuilder
|
||||
/**
|
||||
* Add meta data to addon request.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
public AddonRequestBuilder addMetaData(String key, Object value) {
|
||||
metaData.put(key, value);
|
||||
|
@ -24,7 +24,7 @@ public abstract class AddonRequestHandler
|
||||
* This is used only for Addons to respond to addon requests from plugins.
|
||||
* Example: request island level from Levels addon.
|
||||
*
|
||||
* @param metaData
|
||||
* @param metaData meta data
|
||||
* @return request response
|
||||
*/
|
||||
public abstract Object handle(Map<String, Object> metaData);
|
||||
|
@ -238,8 +238,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* Does not traverse the tree of subcommands in args.
|
||||
* Event is not fired and it cannot be cancelled.
|
||||
* @param user - user calling this command
|
||||
* @param label - label used
|
||||
* @param args - list of args
|
||||
* @param cmdLabel - label used
|
||||
* @param cmdArgs - list of args
|
||||
* @return {@code true} if successful, {@code false} if not.
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@ -250,7 +250,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
return false;
|
||||
}
|
||||
// Check perms, but only if this isn't the console
|
||||
if (user.isPlayer() && !user.isOp() && !getPermission().isEmpty() && !user.hasPermission(getPermission())) {
|
||||
if (user.isPlayer() && !user.isOp() && getPermission() != null && !getPermission().isEmpty() && !user.hasPermission(getPermission())) {
|
||||
user.sendMessage("general.errors.no-permission", TextVariables.PERMISSION, getPermission());
|
||||
return false;
|
||||
}
|
||||
@ -592,7 +592,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
if (command.isOnlyPlayer() && !(sender instanceof Player)) {
|
||||
return options;
|
||||
}
|
||||
if (!command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
|
||||
if (command.getPermission() != null && !command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
|
||||
return options;
|
||||
}
|
||||
// Add any tab completion from the subcommand
|
||||
@ -624,7 +624,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
@NonNull
|
||||
private List<String> getSubCommandLabels(@NonNull CommandSender sender, @NonNull CompositeCommand command) {
|
||||
return command.getSubCommands().values().stream()
|
||||
.filter(cmd -> !cmd.isOnlyPlayer() || sender.isOp() || (sender instanceof Player && (cmd.getPermission().isEmpty() || sender.hasPermission(cmd.getPermission()))) )
|
||||
.filter(cmd -> !cmd.isOnlyPlayer() || sender.isOp() || (sender instanceof Player && cmd.getPermission() != null && (cmd.getPermission().isEmpty() || sender.hasPermission(cmd.getPermission()))) )
|
||||
.map(CompositeCommand::getLabel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class AdminWhyCommand extends ConfirmableCommand {
|
||||
}
|
||||
// Determine the debug mode and toggle if required
|
||||
boolean newValue = !target.getPlayer().getMetadata(getWorld().getName() + "_why_debug").stream()
|
||||
.filter(p -> p.getOwningPlugin().equals(getPlugin())).findFirst().map(MetadataValue::asBoolean).orElse(false);
|
||||
.filter(p -> getPlugin().equals(p.getOwningPlugin())).findFirst().map(MetadataValue::asBoolean).orElse(false);
|
||||
if (newValue) {
|
||||
user.sendMessage("commands.admin.why.turning-on", TextVariables.NAME, target.getName());
|
||||
} else {
|
||||
|
@ -15,6 +15,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeletedEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
||||
|
||||
@ -120,7 +121,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
||||
return getPlugin().getIslands().getIslands().stream()
|
||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||
.filter(i -> i.getOwner() == null)
|
||||
.map(i -> i.getUniqueId())
|
||||
.map(Island::getUniqueId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
}
|
||||
@ -131,7 +132,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
||||
.filter(i -> i.getOwner() != null)
|
||||
.filter(i -> i.getMembers().size() == 1)
|
||||
.filter(i -> (System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) > days * 1000 * 24 * 3600)
|
||||
.map(i -> i.getUniqueId())
|
||||
.map(Island::getUniqueId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@ public class OfflineMessageEvent extends BentoBoxEvent {
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* @param offlinePlayer
|
||||
* @param message
|
||||
* @param offlinePlayer - offline player
|
||||
* @param message message to send offline player
|
||||
*/
|
||||
public OfflineMessageEvent(UUID offlinePlayer, String message) {
|
||||
this.offlinePlayer = offlinePlayer;
|
||||
|
@ -472,7 +472,7 @@ public class Flag implements Comparable<Flag> {
|
||||
|
||||
/**
|
||||
* Make this flag specific to this gameMode
|
||||
* @param gameModeAddon
|
||||
* @param gameModeAddon game mode addon
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder setGameMode(GameModeAddon gameModeAddon) {
|
||||
@ -482,7 +482,7 @@ public class Flag implements Comparable<Flag> {
|
||||
|
||||
/**
|
||||
* The addon registering this flag. Ensure this is set to enable the addon to be reloaded.
|
||||
* @param addon
|
||||
* @param addon addon
|
||||
* @return Builder
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
@ -39,9 +39,9 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||
|
||||
/**
|
||||
* Construct a cycle clicker with a min and max rank
|
||||
* @param id
|
||||
* @param minRank
|
||||
* @param maxRank
|
||||
* @param id flag id
|
||||
* @param minRank minimum rank value
|
||||
* @param maxRank maximum rank value
|
||||
*/
|
||||
public CycleClick(String id, int minRank, int maxRank) {
|
||||
this.id = id;
|
||||
|
@ -10,16 +10,16 @@ import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
public class IslandLockClick extends CycleClick {
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param id flag id
|
||||
*/
|
||||
public IslandLockClick(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param minRank
|
||||
* @param maxRank
|
||||
* @param id flag id
|
||||
* @param minRank minimum rank
|
||||
* @param maxRank maximum rank
|
||||
*/
|
||||
public IslandLockClick(String id, int minRank, int maxRank) {
|
||||
super(id, minRank, maxRank);
|
||||
|
@ -145,7 +145,7 @@ public class Panel implements HeadRequester, InventoryHolder {
|
||||
ItemStack it = inventory.getItem(i);
|
||||
if (it != null && it.getType().equals(Material.PLAYER_HEAD)) {
|
||||
ItemMeta meta = it.getItemMeta();
|
||||
if (item.getName().equals(meta.getLocalizedName())) {
|
||||
if (meta != null && item.getName().equals(meta.getLocalizedName())) {
|
||||
inventory.setItem(i, item.getItem());
|
||||
// If one is found, we are done
|
||||
return;
|
||||
|
@ -142,8 +142,8 @@ public class PanelItem {
|
||||
public void setHead(ItemStack itemStack) {
|
||||
this.icon = itemStack;
|
||||
// Get the meta
|
||||
meta = icon.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta = icon.getItemMeta();
|
||||
// Set flags to neaten up the view
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
|
@ -246,7 +246,7 @@ public class User {
|
||||
*/
|
||||
public boolean removePerm(String name) {
|
||||
for (PermissionAttachmentInfo p : player.getEffectivePermissions()) {
|
||||
if (p.getPermission().equals(name)) {
|
||||
if (p.getPermission().equals(name) && p.getAttachment() != null) {
|
||||
player.removeAttachment(p.getAttachment());
|
||||
break;
|
||||
}
|
||||
@ -422,7 +422,7 @@ public class User {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to sender if message is not empty and if the same wasn't sent within the previous {@link Notifier#NOTIFICATION_DELAY} seconds.
|
||||
* Sends a message to sender if message is not empty and if the same wasn't sent within the previous Notifier.NOTIFICATION_DELAY seconds.
|
||||
* @param reference - language file reference
|
||||
* @param variables - CharSequence target, replacement pairs
|
||||
*
|
||||
@ -436,7 +436,7 @@ public class User {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to sender if message is not empty and if the same wasn't sent within the previous {@link Notifier#NOTIFICATION_DELAY} seconds.
|
||||
* Sends a message to sender if message is not empty and if the same wasn't sent within the previous Notifier.NOTIFICATION_DELAY seconds.
|
||||
* @param world - the world the translation should come from
|
||||
* @param reference - language file reference
|
||||
* @param variables - CharSequence target, replacement pairs
|
||||
|
@ -1,16 +1,7 @@
|
||||
package world.bentobox.bentobox.blueprints;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -18,12 +9,7 @@ import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.Colorable;
|
||||
@ -31,9 +17,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -43,6 +26,12 @@ import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This class pastes the clipboard it is given
|
||||
* @author tastybento
|
||||
@ -115,9 +104,9 @@ public class BlueprintPaster {
|
||||
*/
|
||||
private void paste(@NonNull World world, @Nullable Island island, @NonNull Location loc, @NonNull Blueprint blueprint, @Nullable Runnable task) {
|
||||
// Iterators for the various maps to paste
|
||||
Map<Vector, BlueprintBlock> blocks = blueprint.getBlocks() == null ? new HashMap<>() : blueprint.getBlocks();
|
||||
Map<Vector, BlueprintBlock> attached = blueprint.getAttached() == null ? new HashMap<>() : blueprint.getAttached();
|
||||
Map<Vector, List<BlueprintEntity>> entities = blueprint.getEntities() == null ? new HashMap<>() : blueprint.getEntities();
|
||||
Map<Vector, BlueprintBlock> blocks = blueprint.getBlocks() == null ? Collections.emptyMap() : blueprint.getBlocks();
|
||||
Map<Vector, BlueprintBlock> attached = blueprint.getAttached() == null ? Collections.emptyMap() : blueprint.getAttached();
|
||||
Map<Vector, List<BlueprintEntity>> entities = blueprint.getEntities() == null ? Collections.emptyMap() : blueprint.getEntities();
|
||||
Iterator<Entry<Vector, BlueprintBlock>> it = blocks.entrySet().iterator();
|
||||
Iterator<Entry<Vector, BlueprintBlock>> it2 = attached.entrySet().iterator();
|
||||
Iterator<Entry<Vector, List<BlueprintEntity>>> it3 = entities.entrySet().iterator();
|
||||
@ -132,28 +121,23 @@ public class BlueprintPaster {
|
||||
pasteBlock(world, island, loc, it.next());
|
||||
count++;
|
||||
}
|
||||
while (it2 != null && pasteState.equals(PasteState.ATTACHMENTS) && count < pasteSpeed && it2.hasNext()) {
|
||||
while (pasteState.equals(PasteState.ATTACHMENTS) && count < pasteSpeed && it2.hasNext()) {
|
||||
pasteBlock(world, island, loc, it2.next());
|
||||
count++;
|
||||
}
|
||||
while (it3 != null && pasteState.equals(PasteState.ENTITIES) && count < pasteSpeed && it3.hasNext()) {
|
||||
while (pasteState.equals(PasteState.ENTITIES) && count < pasteSpeed && it3.hasNext()) {
|
||||
pasteEntity(world, loc, it3.next());
|
||||
count++;
|
||||
}
|
||||
// STATE SHIFT
|
||||
if (pasteState.equals(PasteState.BLOCKS) && !it.hasNext()) {
|
||||
// Blocks done.
|
||||
if (it2 == null && it3 == null) {
|
||||
// No attachments or entities
|
||||
pasteState = PasteState.DONE;
|
||||
} else {
|
||||
// Next paste attachments, otherwise skip to entities
|
||||
pasteState = it2 != null ? PasteState.ATTACHMENTS : PasteState.ENTITIES;
|
||||
}
|
||||
// Blocks done
|
||||
// Next paste attachments
|
||||
pasteState = PasteState.ATTACHMENTS;
|
||||
}
|
||||
if (pasteState.equals(PasteState.ATTACHMENTS) && !it2.hasNext()) {
|
||||
// Attachments done. Next paste entities, otherwise done
|
||||
pasteState = it3 != null ? PasteState.ENTITIES : PasteState.DONE;
|
||||
// Attachments done. Next paste entities
|
||||
pasteState = PasteState.ENTITIES;
|
||||
}
|
||||
if (pasteState.equals(PasteState.ENTITIES) && !it3.hasNext()) {
|
||||
pasteState = PasteState.DONE;
|
||||
@ -270,6 +254,7 @@ public class BlueprintPaster {
|
||||
// Center, and just a bit high
|
||||
Location center = location.add(new Vector(0.5, 0.5, 0.5));
|
||||
LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType());
|
||||
if (e == null) return;
|
||||
if (k.getCustomName() != null) {
|
||||
e.setCustomName(k.getCustomName());
|
||||
}
|
||||
@ -336,7 +321,7 @@ public class BlueprintPaster {
|
||||
}
|
||||
|
||||
private void writeSign(final Island island, final Block block, final List<String> lines) {
|
||||
BlockFace bf = null;
|
||||
BlockFace bf;
|
||||
if (block.getType().name().contains("WALL_SIGN")) {
|
||||
WallSign wallSign = (WallSign)block.getBlockData();
|
||||
bf = wallSign.getFacing();
|
||||
|
@ -19,8 +19,8 @@ public class DescriptionSuccessPrompt extends MessagePrompt {
|
||||
private BlueprintBundle bb;
|
||||
|
||||
/**
|
||||
* @param addon
|
||||
* @param bb
|
||||
* @param addon game mode addon
|
||||
* @param bb blueprint bundle
|
||||
*/
|
||||
public DescriptionSuccessPrompt(GameModeAddon addon, BlueprintBundle bb) {
|
||||
this.addon = addon;
|
||||
|
@ -155,7 +155,7 @@ public class BlueprintBundle implements DataObject {
|
||||
/**
|
||||
* Adds a line to the description
|
||||
*
|
||||
* @param string
|
||||
* @param string description
|
||||
*/
|
||||
public void setDescription(String string) {
|
||||
if (description == null)
|
||||
|
@ -22,7 +22,7 @@ public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHan
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin BentoBox plugin
|
||||
* @param type The type of the objects that should be created and filled with
|
||||
* values from the database or inserted into the database
|
||||
* @param databaseConnector Contains the settings to create a connection to the database
|
||||
|
@ -35,7 +35,7 @@ public class BentoboxTypeAdapterFactory implements TypeAdapterFactory {
|
||||
BentoBox plugin;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* @param plugin plugin
|
||||
*/
|
||||
public BentoboxTypeAdapterFactory(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -29,7 +29,7 @@ public class JSONDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin BentoBox plugin
|
||||
* @param type The type of the objects that should be created and filled with
|
||||
* values from the database or inserted into the database
|
||||
* @param databaseConnector Contains the settings to create a connection to the database
|
||||
|
@ -204,6 +204,8 @@ public class Island implements DataObject {
|
||||
this.uniqueId = island.uniqueId;
|
||||
this.updatedDate = island.updatedDate;
|
||||
this.world = island.world;
|
||||
this.cooldowns = island.cooldowns;
|
||||
this.commandRanks = island.commandRanks;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -17,7 +17,7 @@ public class PostgreSQLDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin BentoBox plugin
|
||||
* @param type The type of the objects that should be created and filled with
|
||||
* values from the database or inserted into the database
|
||||
* @param databaseConnector Contains the settings to create a connection to the database
|
||||
|
@ -20,7 +20,7 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin BentoBox plugin
|
||||
* @param type The type of the objects that should be created and filled with
|
||||
* values from the database or inserted into the database
|
||||
* @param databaseConnector Contains the settings to create a connection to the database
|
||||
|
@ -138,9 +138,9 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
* @param config - YAML config file
|
||||
*
|
||||
* @return <T> filled with values
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws SecurityException security exception
|
||||
* @throws NoSuchMethodException no such method
|
||||
* @throws IllegalArgumentException illegal argument
|
||||
*/
|
||||
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
|
||||
// Create a new instance of the dataObject of type T (which can be any class)
|
||||
|
@ -28,7 +28,7 @@ public class VaultHook extends Hook {
|
||||
return false;
|
||||
}
|
||||
economy = rsp.getProvider();
|
||||
return economy != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
@ -14,8 +10,8 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -25,6 +21,10 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JoinLeaveListener implements Listener {
|
||||
|
||||
private BentoBox plugin;
|
||||
@ -141,6 +141,7 @@ public class JoinLeaveListener implements Listener {
|
||||
|
||||
if (!candidates.isEmpty() && !plugin.getSettings().isAutoOwnershipTransferIgnoreRanks()) {
|
||||
// Ranks are not ignored, our candidates can only have the highest rank
|
||||
// TODO Complete this section
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -153,7 +154,7 @@ public class JoinLeaveListener implements Listener {
|
||||
Island island = plugin.getIslands().getIsland(world, user);
|
||||
if (island != null) {
|
||||
// Check if new owner has a different range permission than the island size
|
||||
int range = user.getPermissionValue(plugin.getIWM().getAddon(island.getWorld()).get().getPermissionPrefix() + "island.range", island.getProtectionRange());
|
||||
int range = user.getPermissionValue(plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("") + "island.range", island.getProtectionRange());
|
||||
|
||||
// Range can go up or down
|
||||
if (range != island.getProtectionRange()) {
|
||||
|
@ -87,7 +87,6 @@ public class CommandRankClickListener implements ClickHandler {
|
||||
* Gets the rank command panel item
|
||||
* @param c - rank string
|
||||
* @param user - user
|
||||
* @param island - user's island
|
||||
* @return panel item for this command
|
||||
*/
|
||||
public PanelItem getPanelItem(String c, User user) {
|
||||
|
@ -290,7 +290,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
default:
|
||||
if (stringFlags.containsKey(type.name())) {
|
||||
Optional<Flag> f = BentoBox.getInstance().getFlagsManager().getFlag(stringFlags.get(type.name()));
|
||||
if (f.isPresent()) checkIsland(e, player, loc, f.get());
|
||||
f.ifPresent(flag -> checkIsland(e, player, loc, flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class LockAndBanListener extends FlagListener {
|
||||
}
|
||||
if (!checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN)) {
|
||||
e.setCancelled(true);
|
||||
e.getFrom().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||
e.getPlayer().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||
e.getPlayer().setVelocity(new Vector(0,0,0));
|
||||
e.getPlayer().setGliding(false);
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class LockAndBanListener extends FlagListener {
|
||||
if (!checkAndNotify(p, e.getTo()).equals(CheckResult.OPEN)) {
|
||||
p.leaveVehicle();
|
||||
p.teleport(e.getFrom());
|
||||
e.getFrom().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||
e.getVehicle().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||
eject(p);
|
||||
}
|
||||
});
|
||||
|
@ -31,6 +31,8 @@ import world.bentobox.bentobox.util.Pair;
|
||||
*/
|
||||
public class CleanSuperFlatListener extends FlagListener {
|
||||
|
||||
private BentoBox plugin = BentoBox.getInstance();
|
||||
|
||||
/**
|
||||
* Stores pairs of X,Z coordinates of chunks that need to be regenerated.
|
||||
* @since 1.1
|
||||
@ -60,23 +62,9 @@ public class CleanSuperFlatListener extends FlagListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onChunkLoad(ChunkLoadEvent e) {
|
||||
if (!ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
World world = e.getWorld();
|
||||
// Clean super flat does not work if the world handles its own generator explicitly
|
||||
if (getIWM().inWorld(world) && Flags.CLEAN_SUPER_FLAT.isSetForWorld(world) && getIWM().isUseOwnGenerator(world)) {
|
||||
Flags.CLEAN_SUPER_FLAT.setSetting(world, false);
|
||||
getPlugin().logWarning("Clean super flat is not available for " + world.getName());
|
||||
return;
|
||||
}
|
||||
BentoBox plugin = BentoBox.getInstance();
|
||||
if (!getIWM().inWorld(world) || !Flags.CLEAN_SUPER_FLAT.isSetForWorld(world) ||
|
||||
(!e.getChunk().getBlock(0, 0, 0).getType().equals(Material.BEDROCK)
|
||||
|| (world.getEnvironment().equals(Environment.NETHER) && (!plugin.getIWM().isNetherGenerate(world)
|
||||
|| !plugin.getIWM().isNetherIslands(world)))
|
||||
|| (world.getEnvironment().equals(Environment.THE_END) && (!plugin.getIWM().isEndGenerate(world)
|
||||
|| !plugin.getIWM().isEndIslands(world))))) {
|
||||
if (noClean(world, e)) {
|
||||
return;
|
||||
}
|
||||
MyBiomeGrid grid = new MyBiomeGrid(world.getEnvironment());
|
||||
@ -89,24 +77,55 @@ public class CleanSuperFlatListener extends FlagListener {
|
||||
// Add to queue
|
||||
chunkQueue.add(new Pair<>(e.getChunk().getX(), e.getChunk().getZ()));
|
||||
if (task == null || task.isCancelled()) {
|
||||
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
if (!chunkQueue.isEmpty()) {
|
||||
Pair<Integer, Integer> chunkXZ = chunkQueue.poll();
|
||||
ChunkData cd = cg.generateChunkData(world, new Random(), e.getChunk().getX(), e.getChunk().getZ(), grid);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < world.getMaxHeight(); y++) {
|
||||
e.getChunk().getBlock(x, y, z).setBlockData(cd.getBlockData(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugin.getSettings().isLogCleanSuperFlatChunks()) {
|
||||
plugin.log(chunkQueue.size() + " Regenerating superflat chunk " + world.getName() + " " + chunkXZ.x + ", " + chunkXZ.z);
|
||||
}
|
||||
} else {
|
||||
task.cancel();
|
||||
}
|
||||
}, 0L, 1L);
|
||||
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> cleanChunk(e, world, cg, grid), 0L, 1L);
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanChunk(ChunkLoadEvent e, World world, ChunkGenerator cg, MyBiomeGrid grid) {
|
||||
if (!chunkQueue.isEmpty()) {
|
||||
Pair<Integer, Integer> chunkXZ = chunkQueue.poll();
|
||||
ChunkData cd = cg.generateChunkData(world, new Random(), e.getChunk().getX(), e.getChunk().getZ(), grid);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < world.getMaxHeight(); y++) {
|
||||
e.getChunk().getBlock(x, y, z).setBlockData(cd.getBlockData(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugin.getSettings().isLogCleanSuperFlatChunks()) {
|
||||
plugin.log(chunkQueue.size() + " Regenerating superflat chunk " + world.getName() + " " + chunkXZ.x + ", " + chunkXZ.z);
|
||||
}
|
||||
} else {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if chunk should be cleaned or not
|
||||
* @param world - world
|
||||
* @param plugin - plugin
|
||||
* @param e chunk load event
|
||||
* @return true if the chunk should not be cleaned
|
||||
*/
|
||||
private boolean noClean(World world, ChunkLoadEvent e) {
|
||||
if (!ready) {
|
||||
return true;
|
||||
}
|
||||
// Clean super flat does not work if the world handles its own generator explicitly
|
||||
if (getIWM().inWorld(world) && Flags.CLEAN_SUPER_FLAT.isSetForWorld(world) && getIWM().isUseOwnGenerator(world)) {
|
||||
Flags.CLEAN_SUPER_FLAT.setSetting(world, false);
|
||||
getPlugin().logWarning("Clean super flat is not available for " + world.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getIWM().inWorld(world) || !Flags.CLEAN_SUPER_FLAT.isSetForWorld(world) ||
|
||||
(!e.getChunk().getBlock(0, 0, 0).getType().equals(Material.BEDROCK)
|
||||
|| (world.getEnvironment().equals(Environment.NETHER) && (!plugin.getIWM().isNetherGenerate(world)
|
||||
|| !plugin.getIWM().isNetherIslands(world)))
|
||||
|| (world.getEnvironment().equals(Environment.THE_END) && (!plugin.getIWM().isEndGenerate(world)
|
||||
|| !plugin.getIWM().isEndIslands(world))))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class BlueprintClipboardManager {
|
||||
* Loads a blueprint
|
||||
* @param fileName - the filename without the suffix
|
||||
* @return the blueprint
|
||||
* @throws IOException
|
||||
* @throws IOException exception if there's an issue loading or unzipping
|
||||
*/
|
||||
public Blueprint loadBlueprint(String fileName) throws IOException {
|
||||
File zipFile = new File(blueprintFolder, fileName + BlueprintsManager.BLUEPRINT_SUFFIX);
|
||||
|
@ -224,7 +224,7 @@ public class BlueprintsManager {
|
||||
/**
|
||||
* This should never be needed and is just a boot strap
|
||||
*
|
||||
* @param addon
|
||||
* @param addon addon
|
||||
*/
|
||||
private void makeDefaults(@NonNull GameModeAddon addon) {
|
||||
plugin.logError("No blueprint bundles found! Creating a default one.");
|
||||
|
@ -41,7 +41,7 @@ public class IslandDeletionManager implements Listener {
|
||||
|
||||
/**
|
||||
* When BentoBox is fully loaded, load the islands that still need to be deleted and kick them off
|
||||
* @param e
|
||||
* @param e BentoBox Ready event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBentoBoxReady(BentoBoxReadyEvent e) {
|
||||
|
@ -695,7 +695,11 @@ public class IslandsManager {
|
||||
player.leaveVehicle();
|
||||
// Remove the boat so they don't lie around everywhere
|
||||
boat.remove();
|
||||
player.getInventory().addItem(new ItemStack(Material.getMaterial(((Boat) boat).getWoodType().toString() + "_BOAT"), 1));
|
||||
Material boatMat = Material.getMaterial(((Boat) boat).getWoodType().toString() + "_BOAT");
|
||||
if (boatMat == null) {
|
||||
boatMat = Material.OAK_BOAT;
|
||||
}
|
||||
player.getInventory().addItem(new ItemStack(boatMat, 1));
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class LocalesManager {
|
||||
|
||||
private void copyFile(String name, File targetFile) {
|
||||
try (InputStream initialStream = plugin.getResource(name)) {
|
||||
if (!targetFile.exists()) {
|
||||
if (initialStream != null && !targetFile.exists()) {
|
||||
java.nio.file.Files.copy(initialStream, targetFile.toPath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -425,8 +425,8 @@ public class PlayersManager {
|
||||
|
||||
/**
|
||||
* Adds a reset to this player's number of resets
|
||||
* @param world
|
||||
* @param playerUUID
|
||||
* @param world world where island is
|
||||
* @param playerUUID player's UUID
|
||||
*/
|
||||
public void addReset(World world, UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
|
@ -105,7 +105,7 @@ public class NewIsland {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param world world where the island will go
|
||||
* @deprecated use {@link #addon} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@ -155,7 +155,7 @@ public class NewIsland {
|
||||
|
||||
/**
|
||||
* Makes an island.
|
||||
* @param oldIsland
|
||||
* @param oldIsland old island that is being replaced, if any
|
||||
*/
|
||||
public void newIsland(Island oldIsland) {
|
||||
Location next = getNextIsland();
|
||||
@ -282,7 +282,7 @@ public class NewIsland {
|
||||
Result r = isIsland(last);
|
||||
|
||||
while (!r.equals(Result.FREE) && result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS) {
|
||||
last = nextGridLocation(last);
|
||||
nextGridLocation(last);
|
||||
result.merge(r, 1, (k,v) -> v++);
|
||||
r = isIsland(last);
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ public class SchemToBlueprint {
|
||||
* Imports one schem set to the game mode
|
||||
*
|
||||
* @param addon - game mode addon
|
||||
* @param schems
|
||||
* @param name
|
||||
* @param schems - schems folder
|
||||
* @param name - name of the schematic
|
||||
*/
|
||||
private void importSchemSet(GameModeAddon addon, File schems, String name) {
|
||||
// Make a new blueprint bundle
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
|
||||
/**
|
||||
* Utility class that parses a String into an ItemStack.
|
||||
@ -113,15 +114,21 @@ public class ItemParser {
|
||||
private static ItemStack banner(String[] part) {
|
||||
try {
|
||||
if (part.length >= 2) {
|
||||
ItemStack result = new ItemStack(Material.getMaterial(part[0]), Integer.parseInt(part[1]));
|
||||
Material bannerMat = Material.getMaterial(part[0]);
|
||||
if (bannerMat == null) {
|
||||
BentoBox.getInstance().logError("Could not parse banner item " + part[0] + " so using a white banner.");
|
||||
bannerMat = Material.WHITE_BANNER;
|
||||
}
|
||||
ItemStack result = new ItemStack(bannerMat, Integer.parseInt(part[1]));
|
||||
|
||||
BannerMeta meta = (BannerMeta) result.getItemMeta();
|
||||
for (int i = 2; i < part.length; i += 2) {
|
||||
meta.addPattern(new Pattern(DyeColor.valueOf(part[i + 1]), PatternType.valueOf(part[i])));
|
||||
if (meta != null) {
|
||||
for (int i = 2; i < part.length; i += 2) {
|
||||
meta.addPattern(new Pattern(DyeColor.valueOf(part[i + 1]), PatternType.valueOf(part[i])));
|
||||
}
|
||||
result.setItemMeta(meta);
|
||||
}
|
||||
|
||||
result.setItemMeta(meta);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -94,7 +94,9 @@ public class SafeSpotTeleport {
|
||||
// Add chunk snapshots to the list
|
||||
while (it.hasNext() && chunkSnapshot.size() < MAX_CHUNKS) {
|
||||
Pair<Integer, Integer> pair = it.next();
|
||||
chunkSnapshot.add(location.getWorld().getChunkAt(pair.x, pair.z).getChunkSnapshot());
|
||||
if (location.getWorld() != null) {
|
||||
chunkSnapshot.add(location.getWorld().getChunkAt(pair.x, pair.z).getChunkSnapshot());
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
// Move to next step
|
||||
|
@ -714,11 +714,7 @@ protection:
|
||||
description: "Toggle egg throwing"
|
||||
name: "Egg throwing"
|
||||
hint: "No egg throwing"
|
||||
ELYTRA:
|
||||
description: "Toggle use on island"
|
||||
name: "Elytra"
|
||||
hint: "No elytra flying allowed"
|
||||
ENCHANTING:
|
||||
ENCHANTING:
|
||||
description: "Toggle use"
|
||||
name: "Enchanting table"
|
||||
hint: "No table use"
|
||||
|
@ -807,7 +807,6 @@ protection:
|
||||
description: "Abilita/disabilita uso"
|
||||
name: "Uso di leve"
|
||||
hint: "Uso di leve disabilitato"
|
||||
hint: "Uso di leve disabilitato"
|
||||
LIQUIDS_FLOWING_OUT:
|
||||
name: "Liquidi scorrono fuori dall'isola"
|
||||
description: |-
|
||||
|
@ -361,6 +361,7 @@ public class LockAndBanListenerTest {
|
||||
passengers.add(player);
|
||||
passengers.add(player2);
|
||||
when(vehicle.getPassengers()).thenReturn(passengers);
|
||||
when(vehicle.getWorld()).thenReturn(world);
|
||||
// Move vehicle
|
||||
listener.onVehicleMove(new VehicleMoveEvent(vehicle, outside, inside));
|
||||
// Player should see a message and nothing should be sent to Player 2
|
||||
@ -702,6 +703,7 @@ public class LockAndBanListenerTest {
|
||||
passengers.add(player);
|
||||
passengers.add(player2);
|
||||
when(vehicle.getPassengers()).thenReturn(passengers);
|
||||
when(vehicle.getWorld()).thenReturn(world);
|
||||
// Move vehicle
|
||||
listener.onVehicleMove(new VehicleMoveEvent(vehicle, outside, inside));
|
||||
// Player should see a message and nothing should be sent to Player 2
|
||||
|
Loading…
Reference in New Issue
Block a user