Merge branch 'develop'

This commit is contained in:
tastybento 2018-07-03 17:51:52 -07:00
commit ed69f1d394
24 changed files with 635 additions and 849 deletions

View File

@ -127,9 +127,10 @@ commands:
parameters: "<load><copy><paste><pos1><pos2><save>" parameters: "<load><copy><paste><pos1><pos2><save>"
description: "manipulate schems" description: "manipulate schems"
copy-first: "&cCopy a schem first!" copy-first: "&cCopy a schem first!"
file-exists: "&cFile already exists, overwrite?"
no-such-file: "&cNo such file!" no-such-file: "&cNo such file!"
could-not-load: "&cCould not load that file!" could-not-load: "&cCould not load that file!"
could-not-save: "&Hmm, something went wrong saving that file: [message]" could-not-save: "&cHmm, something went wrong saving that file: [message]"
set-pos1: "&aPosition 1 set at [vector]" set-pos1: "&aPosition 1 set at [vector]"
set-pos2: "&aPosition 2 set at [vector]" set-pos2: "&aPosition 2 set at [vector]"
set-different-pos: "&cSet a different location - this pos is already set!" set-different-pos: "&cSet a different location - this pos is already set!"

View File

@ -41,13 +41,13 @@ permissions:
default: true default: true
bskyblock.island.lock: bskyblock.island.lock:
description: Allows island locking description: Allows island locking
default: false default: true
bskyblock.island.expel: bskyblock.island.expel:
description: Allows expelling of visitors description: Allows expelling of visitors
default: true default: true
bskyblock.island.ban: bskyblock.island.ban:
description: Allows banning of visitors description: Allows banning of visitors
default: false default: true
bskyblock.island.settings: bskyblock.island.settings:
description: Player can see server settings description: Player can see server settings
default: true default: true

Binary file not shown.

Binary file not shown.

View File

@ -25,6 +25,7 @@ import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.LocalesManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
import us.tastybento.bskyblock.managers.RanksManager; import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.managers.SchemsManager;
import us.tastybento.bskyblock.util.HeadGetter; import us.tastybento.bskyblock.util.HeadGetter;
/** /**
@ -50,6 +51,7 @@ public class BSkyBlock extends JavaPlugin {
private FlagsManager flagsManager; private FlagsManager flagsManager;
private IslandWorldManager islandWorldManager; private IslandWorldManager islandWorldManager;
private RanksManager ranksManager; private RanksManager ranksManager;
private SchemsManager schemsManager;
// Settings // Settings
private Settings settings; private Settings settings;
@ -61,6 +63,9 @@ public class BSkyBlock extends JavaPlugin {
@Override @Override
public void onEnable(){ public void onEnable(){
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
final long startMillis = System.currentTimeMillis();
// Save the default config from config.yml // Save the default config from config.yml
saveDefaultConfig(); saveDefaultConfig();
setInstance(this); setInstance(this);
@ -95,6 +100,10 @@ public class BSkyBlock extends JavaPlugin {
getServer().getScheduler().runTask(this, () -> { getServer().getScheduler().runTask(this, () -> {
// Create the world if it does not exist // Create the world if it does not exist
islandWorldManager = new IslandWorldManager(instance); islandWorldManager = new IslandWorldManager(instance);
// Load schems manager
schemsManager = new SchemsManager(instance);
// Load the default island schems
schemsManager.loadIslands(getIWM().getIslandWorld());
// Set up commands // Set up commands
new IslandCommand(); new IslandCommand();
@ -121,7 +130,6 @@ public class BSkyBlock extends JavaPlugin {
islandsManager.load(); islandsManager.load();
// Save islands & players data asynchronously every X minutes // Save islands & players data asynchronously every X minutes
instance.getServer().getScheduler().runTaskTimer(instance, () -> { instance.getServer().getScheduler().runTaskTimer(instance, () -> {
playersManager.save(true); playersManager.save(true);
islandsManager.save(true); islandsManager.save(true);
@ -129,6 +137,7 @@ public class BSkyBlock extends JavaPlugin {
instance.log("#############################################"); instance.log("#############################################");
instance.log(instance.getDescription().getFullName() + " has been fully enabled."); instance.log(instance.getDescription().getFullName() + " has been fully enabled.");
instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms"));
instance.log("Thanks for using our plugin !"); instance.log("Thanks for using our plugin !");
instance.log("- Tastybento and Poslovitch, 2017-2018"); instance.log("- Tastybento and Poslovitch, 2017-2018");
instance.log("#############################################"); instance.log("#############################################");
@ -317,4 +326,14 @@ public class BSkyBlock extends JavaPlugin {
islandWorldManager.addWorld(world, worldSettings); islandWorldManager.addWorld(world, worldSettings);
} }
/**
* @return the schemsManager
*/
public SchemsManager getSchemsManager() {
return schemsManager;
}
} }

View File

@ -6,12 +6,14 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.api.configuration.ConfigComment; import us.tastybento.bskyblock.api.configuration.ConfigComment;
import us.tastybento.bskyblock.api.configuration.ConfigEntry; import us.tastybento.bskyblock.api.configuration.ConfigEntry;
import us.tastybento.bskyblock.api.configuration.StoreAt; import us.tastybento.bskyblock.api.configuration.StoreAt;
@ -165,7 +167,7 @@ public class Settings implements DataObject, WorldSettings {
private int islandZOffset; private int islandZOffset;
@ConfigComment("Island height - Lowest is 5.") @ConfigComment("Island height - Lowest is 5.")
@ConfigComment("It is the y coordinate of the bedrock block in the schematic") @ConfigComment("It is the y coordinate of the bedrock block in the schem")
@ConfigEntry(path = "world.island-height") @ConfigEntry(path = "world.island-height")
private int islandHeight = 100; private int islandHeight = 100;
@ -428,6 +430,7 @@ public class Settings implements DataObject, WorldSettings {
@ConfigEntry(path = "panel.close-on-click-outside") @ConfigEntry(path = "panel.close-on-click-outside")
private boolean closePanelOnClickOutside = true; private boolean closePanelOnClickOutside = true;
//---------------------------------------------------------------------------------------/
private String uniqueId = "config"; private String uniqueId = "config";
// Getters and setters // Getters and setters
@ -1562,5 +1565,11 @@ public class Settings implements DataObject, WorldSettings {
this.onLeaveResetEnderChest = onLeaveResetEnderChest; this.onLeaveResetEnderChest = onLeaveResetEnderChest;
} }
@Override
public Optional<Addon> getAddon() {
// This is a plugin, not an addon
return Optional.empty();
}
} }

View File

@ -282,4 +282,16 @@ public abstract class Addon implements AddonInterface {
public Optional<Addon> getAddonByName(String name) { public Optional<Addon> getAddonByName(String name) {
return getBSkyBlock().getAddonsManager().getAddonByName(name); return getBSkyBlock().getAddonsManager().getAddonByName(name);
} }
public void log(String string) {
getBSkyBlock().log(string);
}
public void logWarning(String string) {
getBSkyBlock().logWarning(string);
}
public void logError(String string) {
getBSkyBlock().logError(string);
}
} }

View File

@ -2,11 +2,14 @@ package us.tastybento.bskyblock.api.configuration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import us.tastybento.bskyblock.api.addons.Addon;
/** /**
* Contains world-specific settings. Only getters are required, but you may need setters for your own class. * Contains world-specific settings. Only getters are required, but you may need setters for your own class.
* @author tastybento * @author tastybento
@ -182,4 +185,9 @@ public interface WorldSettings {
*/ */
public boolean isOnLeaveResetEnderChest(); public boolean isOnLeaveResetEnderChest();
/**
* @return the Addon that registered this world
*/
public Optional<Addon> getAddon();
} }

View File

@ -14,4 +14,5 @@ public class TextVariables {
public static final String RANK = "[rank]"; public static final String RANK = "[rank]";
public static final String LABEL = "[label]"; public static final String LABEL = "[label]";
public static final String PERMISSION = "[permission]"; public static final String PERMISSION = "[permission]";
public static final String SPAWN_HERE = "[spawn_here]";
} }

View File

@ -1,5 +1,6 @@
package us.tastybento.bskyblock.commands.admin; package us.tastybento.bskyblock.commands.admin;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -21,6 +22,7 @@ public class AdminSchemCommand extends CompositeCommand {
super(parent, "schem"); super(parent, "schem");
} }
@Override
public void setup() { public void setup() {
setPermission("admin.schem"); setPermission("admin.schem");
setParameters("commands.admin.schem.parameters"); setParameters("commands.admin.schem.parameters");
@ -29,13 +31,15 @@ public class AdminSchemCommand extends CompositeCommand {
clipboards = new HashMap<>(); clipboards = new HashMap<>();
} }
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
if (args.isEmpty()) { if (args.isEmpty()) {
showHelp(this, user); showHelp(this, user);
return false; return false;
} }
Clipboard cb = clipboards.getOrDefault(user.getUniqueId(), new Clipboard(getPlugin())); File schemFolder = new File(getIWM().getDataFolder(getWorld()), "schems");
Clipboard cb = clipboards.getOrDefault(user.getUniqueId(), new Clipboard(getPlugin(), schemFolder));
if (args.get(0).equalsIgnoreCase("paste")) { if (args.get(0).equalsIgnoreCase("paste")) {
if (cb.isFull()) { if (cb.isFull()) {
@ -90,7 +94,15 @@ public class AdminSchemCommand extends CompositeCommand {
if (args.get(0).equalsIgnoreCase("save")) { if (args.get(0).equalsIgnoreCase("save")) {
if (cb.isFull()) { if (cb.isFull()) {
if (args.size() == 2) { if (args.size() == 2) {
// Check if file exists
File newFile = new File(schemFolder, args.get(1) + ".schem");
if (newFile.exists()) {
user.sendMessage("commands.admin.schem.file-exists");
this.askConfirmation(user, () -> cb.save(user, args.get(1)));
return false;
} else {
return cb.save(user, args.get(1)); return cb.save(user, args.get(1));
}
} else { } else {
showHelp(this, user); showHelp(this, user);
return false; return false;

View File

@ -11,6 +11,7 @@ import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -101,7 +102,7 @@ public class Island implements DataObject {
@Expose @Expose
private int levelHandicap; private int levelHandicap;
@Expose @Expose
private Location spawnPoint; private Map<Environment, Location> spawnPoint = new HashMap<>();
public Island() {} public Island() {}
public Island(Location location, UUID owner, int protectionRange) { public Island(Location location, UUID owner, int protectionRange) {
@ -288,10 +289,6 @@ public class Island implements DataObject {
return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK); return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK);
} }
public Location getSpawnPoint() {
return spawnPoint;
}
/** /**
* @param material - Material * @param material - Material
* @return count of how many tile entities of type mat are on the island at last count. Counts are done when a player places * @return count of how many tile entities of type mat are on the island at last count. Counts are done when a player places
@ -620,9 +617,21 @@ public class Island implements DataObject {
//TODO default flags //TODO default flags
} }
public void setSpawnPoint(Location location) { /**
spawnPoint = location; * Get the default spawn location for this island. Note that this may only be valid
* after the initial pasting because the player can change the island after that point
* @return the spawnPoint
*/
public Map<Environment, Location> getSpawnPoint() {
return spawnPoint;
}
/**
* Set when island is pasted
* @param spawnPoint the spawnPoint to set
*/
public void setSpawnPoint(Map<Environment, Location> spawnPoint) {
this.spawnPoint = spawnPoint;
} }
@Override @Override
@ -731,5 +740,23 @@ public class Island implements DataObject {
} }
} }
/**
* Set the spawn location for this island type
* @param islandType - island type
* @param l - location
*/
public void setSpawnPoint(Environment islandType, Location l) {
spawnPoint.put(islandType, l);
}
/**
* Get the spawn point for this island type
* @param islandType - island type
* @return - location or null if one does not exist
*/
public Location getSpawnPoint(Environment islandType) {
return spawnPoint.get(islandType);
}
} }

View File

@ -9,14 +9,20 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.World;
import org.bukkit.block.Banner; import org.bukkit.block.Banner;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -28,7 +34,14 @@ import org.bukkit.block.banner.PatternType;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -41,10 +54,13 @@ import org.bukkit.material.MaterialData;
import org.bukkit.material.Openable; import org.bukkit.material.Openable;
import org.bukkit.material.Redstone; import org.bukkit.material.Redstone;
import org.bukkit.material.Stairs; import org.bukkit.material.Stairs;
import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.localization.TextVariables; import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
public class Clipboard { public class Clipboard {
@ -76,14 +92,15 @@ public class Clipboard {
private File schemFolder; private File schemFolder;
public Clipboard(BSkyBlock plugin) { public Clipboard(BSkyBlock plugin, File schemFolder) {
super(); super();
this.plugin = plugin; this.plugin = plugin;
schemFolder = new File(plugin.getDataFolder(), "schems");
if (!schemFolder.exists()) { if (!schemFolder.exists()) {
schemFolder.mkdirs(); schemFolder.mkdirs();
} }
this.schemFolder = schemFolder;
} }
/** /**
* @return the pos1 * @return the pos1
*/ */
@ -133,8 +150,11 @@ public class Clipboard {
user.sendMessage("commands.admin.schem.need-pos1-pos2"); user.sendMessage("commands.admin.schem.need-pos1-pos2");
return false; return false;
} }
// World
World world = pos1.getWorld();
// Clear the clipboard // Clear the clipboard
blockConfig = new YamlConfiguration(); blockConfig = new YamlConfiguration();
int count = 0; int count = 0;
int minX = Math.max(pos1.getBlockX(),pos2.getBlockX()); int minX = Math.max(pos1.getBlockX(),pos2.getBlockX());
int maxX = Math.min(pos1.getBlockX(), pos2.getBlockX()); int maxX = Math.min(pos1.getBlockX(), pos2.getBlockX());
@ -142,11 +162,15 @@ public class Clipboard {
int maxY = Math.min(pos1.getBlockY(), pos2.getBlockY()); int maxY = Math.min(pos1.getBlockY(), pos2.getBlockY());
int minZ = Math.max(pos1.getBlockZ(),pos2.getBlockZ()); int minZ = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
int maxZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); int maxZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ());
for (int x = Math.min(pos1.getBlockX(), pos2.getBlockX()); x <= Math.max(pos1.getBlockX(),pos2.getBlockX()); x++) { for (int x = Math.min(pos1.getBlockX(), pos2.getBlockX()); x <= Math.max(pos1.getBlockX(),pos2.getBlockX()); x++) {
for (int y = Math.min(pos1.getBlockY(), pos2.getBlockY()); y <= Math.max(pos1.getBlockY(),pos2.getBlockY()); y++) { for (int y = Math.min(pos1.getBlockY(), pos2.getBlockY()); y <= Math.max(pos1.getBlockY(),pos2.getBlockY()); y++) {
for (int z = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); z <= Math.max(pos1.getBlockZ(),pos2.getBlockZ()); z++) { for (int z = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); z <= Math.max(pos1.getBlockZ(),pos2.getBlockZ()); z++) {
Block block = pos1.getWorld().getBlockAt(x, y, z); Block block = world.getBlockAt(x, y, z);
if (copyBlock(block, origin == null ? user.getLocation() : origin, copyAir)) { if (copyBlock(block, origin == null ? user.getLocation() : origin, copyAir, world.getLivingEntities().stream()
.filter(Objects::nonNull)
.filter(e -> !(e instanceof Player) && e.getLocation().getBlock().equals(block))
.collect(Collectors.toList()))) {
minX = Math.min(minX, x); minX = Math.min(minX, x);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
@ -167,137 +191,227 @@ public class Clipboard {
} }
/** /**
* Pastes the clipboard to location * Pastes the clipboard to island location
* @param location - location to paste * @param world - world in which to paste
* @param island - location to paste
* @param task - task to run after pasting
*/ */
public void paste(Location location) { public void paste(World world, Island island, Runnable task) {
blockConfig.getConfigurationSection(BLOCK).getKeys(false).forEach(b -> pasteBlock(location, blockConfig.getConfigurationSection(BLOCK + "." + b))); // Offset due to bedrock
Vector off = new Vector(0,0,0);
if (blockConfig.contains("bedrock")) {
String[] offset = blockConfig.getString("bedrock").split(",");
off = new Vector(Integer.valueOf(offset[0]), Integer.valueOf(offset[1]), Integer.valueOf(offset[2]));
}
// Calculate location for pasting
Location loc = island.getCenter().toVector().subtract(off).toLocation(world);
// Paste
blockConfig.getConfigurationSection(BLOCK).getKeys(false).forEach(b -> pasteBlock(world, island, loc, blockConfig.getConfigurationSection(BLOCK + "." + b)));
// Run follow on task if it exists
if (task != null) {
Bukkit.getScheduler().runTaskLater(plugin, task, 2L);
}
} }
private void pasteBlock(Location location, ConfigurationSection s) { /**
String[] pos = s.getName().split(","); * Paste clipboard at this location
* @param location
*/
public void paste(Location location) {
blockConfig.getConfigurationSection(BLOCK).getKeys(false).forEach(b -> pasteBlock(location.getWorld(), null, location, blockConfig.getConfigurationSection(BLOCK + "." + b)));
}
private void writeSign(Island island, Block block, List<String> lines) {
Sign sign = (Sign) block.getState();
org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
// Handle spawn sign
if (island != null && !lines.isEmpty() && lines.get(0).equalsIgnoreCase(TextVariables.SPAWN_HERE)) {
block.setType(Material.AIR);
// Orient to face same direction as sign
Location spawnPoint = new Location(block.getWorld(), block.getX() + 0.5D, block.getY(),
block.getZ() + 0.5D, Util.blockFaceToFloat(s.getFacing().getOppositeFace()), 30F);
island.setSpawnPoint(block.getWorld().getEnvironment(), spawnPoint);
return;
}
String name = TextVariables.NAME;
if (island != null) {
name = plugin.getPlayers().getName(island.getOwner());
}
// Sub in player's name
for (int i = 0 ; i < lines.size(); i++) {
sign.setLine(i, lines.get(i).replace(TextVariables.NAME, name));
}
sign.update();
}
private void pasteBlock(World world, Island island, Location location, ConfigurationSection config) {
String[] pos = config.getName().split(",");
int x = location.getBlockX() + Integer.valueOf(pos[0]); int x = location.getBlockX() + Integer.valueOf(pos[0]);
int y = location.getBlockY() + Integer.valueOf(pos[1]); int y = location.getBlockY() + Integer.valueOf(pos[1]);
int z = location.getBlockZ() + Integer.valueOf(pos[2]); int z = location.getBlockZ() + Integer.valueOf(pos[2]);
Material m = Material.getMaterial(s.getString("type")); // Default type is air
Block block = location.getWorld().getBlockAt(x, y, z); Material material = Material.getMaterial(config.getString("type", "AIR"));
if (s.getBoolean(ATTACHED)) { Block block = world.getBlockAt(x, y, z);
plugin.log("Setting 1 tick later for " + m.toString()); if (config.getBoolean(ATTACHED)) {
plugin.getServer().getScheduler().runTask(plugin, () -> setBlock(block, s, m)); plugin.getServer().getScheduler().runTask(plugin, () -> setBlock(island, block, config, material));
} else { } else {
setBlock(block, s, m); setBlock(island, block, config, material);
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void setBlock(Block block, ConfigurationSection s, Material m) { private void setBlock(Island island, Block block, ConfigurationSection config, Material material) {
// Block state // Block state
if (s.getBoolean(ATTACHED) && m.toString().contains("TORCH")) { if (config.getBoolean(ATTACHED) && material.toString().contains("TORCH")) {
TorchDir d = TorchDir.valueOf(s.getString(FACING)); TorchDir d = TorchDir.valueOf(config.getString(FACING));
// The block below has to be set to something solid for this to work
Block rel = block.getRelative(BlockFace.DOWN); Block rel = block.getRelative(BlockFace.DOWN);
Material rm = rel.getType(); Material rm = rel.getType();
Byte data = rel.getData(); Byte data = rel.getData();
if (rel.isEmpty() || rel.isLiquid()) { if (rel.isEmpty() || rel.isLiquid()) {
rel.setType(Material.STONE); rel.setType(Material.STONE);
block.setType(m); block.setType(material);
block.setData((byte)d.ordinal()); block.setData((byte)d.ordinal());
// Set the block back to what it was // Set the block back to what it was
rel.setType(rm); rel.setType(rm);
rel.setData(data); rel.setData(data);
} else { } else {
block.setType(m); block.setType(material);
block.setData((byte)d.ordinal()); block.setData((byte)d.ordinal());
} }
return; return;
} }
// Set the block type
block.setType(m, false); block.setType(material, false);
// Set the block data
BlockState bs = block.getState(); byte data = (byte)config.getInt("data");
byte data = (byte)s.getInt("data");
block.setData(data); block.setData(data);
// Get the block state
BlockState bs = block.getState();
// Material Data // Material Data
MaterialData md = bs.getData(); MaterialData md = bs.getData();
if (md instanceof Openable) { if (md instanceof Openable) {
Openable open = (Openable)md; Openable open = (Openable)md;
open.setOpen(s.getBoolean("open")); open.setOpen(config.getBoolean("open"));
} }
if (md instanceof Directional) { if (md instanceof Directional) {
Directional facing = (Directional)md; Directional facing = (Directional)md;
if (md instanceof Stairs) { if (md instanceof Stairs) {
facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING)).getOppositeFace()); //facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING)).getOppositeFace());
Stairs stairs = (Stairs)md;
stairs.setInverted(config.getBoolean("inverted"));
stairs.setFacingDirection(BlockFace.valueOf(config.getString(FACING, "NORTH")));
} else { } else {
facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING))); facing.setFacingDirection(BlockFace.valueOf(config.getString(FACING, "NORTH")));
} }
} }
if (md instanceof Lever) { if (md instanceof Lever) {
Lever r = (Lever)md; Lever r = (Lever)md;
r.setPowered(s.getBoolean(POWERED)); r.setPowered(config.getBoolean(POWERED));
} }
if (md instanceof Button) { if (md instanceof Button) {
Button r = (Button)md; Button r = (Button)md;
r.setPowered(s.getBoolean(POWERED)); r.setPowered(config.getBoolean(POWERED));
} }
// Block data // Block data
// Signs
if (bs instanceof Sign) { if (bs instanceof Sign) {
Sign sign = (Sign)bs; List<String> lines = config.getStringList("lines");
List<String> lines = s.getStringList("lines"); writeSign(island, block, lines);
for (int i =0 ; i < lines.size(); i++) {
sign.setLine(i, lines.get(i));
}
sign.update();
} }
// Banners
if (bs instanceof Banner) { if (bs instanceof Banner) {
Banner banner = (Banner)bs; Banner banner = (Banner)bs;
DyeColor baseColor = DyeColor.valueOf(s.getString("baseColor")); DyeColor baseColor = DyeColor.valueOf(config.getString("baseColor", "RED"));
banner.setBaseColor(baseColor); banner.setBaseColor(baseColor);
int i = 0; int i = 0;
ConfigurationSection pat = s.getConfigurationSection("pattern"); ConfigurationSection pat = config.getConfigurationSection("pattern");
if (pat != null) { if (pat != null) {
for (String pattern : pat.getKeys(false)) { for (String pattern : pat.getKeys(false)) {
banner.setPattern(i, new Pattern(DyeColor.valueOf(pat.getString(pattern)) banner.setPattern(i, new Pattern(DyeColor.valueOf(pat.getString(pattern, "GREEN"))
, PatternType.valueOf(pattern))); , PatternType.valueOf(pattern)));
i++; i++;
} }
} }
bs.update(true, false);
} }
// Mob spawners
if (bs instanceof CreatureSpawner) { if (bs instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) bs); CreatureSpawner spawner = ((CreatureSpawner) bs);
spawner.setSpawnedType(EntityType.valueOf(s.getString("spawnedType", "PIG"))); spawner.setSpawnedType(EntityType.valueOf(config.getString("spawnedType", "PIG")));
spawner.setMaxNearbyEntities(s.getInt("maxNearbyEntities", 16)); spawner.setMaxNearbyEntities(config.getInt("maxNearbyEntities", 16));
spawner.setMaxSpawnDelay(s.getInt("maxSpawnDelay", 2*60*20)); spawner.setMaxSpawnDelay(config.getInt("maxSpawnDelay", 2*60*20));
spawner.setMinSpawnDelay(s.getInt("minSpawnDelay", 5*20)); spawner.setMinSpawnDelay(config.getInt("minSpawnDelay", 5*20));
spawner.setDelay(s.getInt("delay", -1));
spawner.setRequiredPlayerRange(s.getInt("requiredPlayerRange", 16));
spawner.setSpawnRange(s.getInt("spawnRange", 4));
}
spawner.setDelay(config.getInt("delay", -1));
spawner.setRequiredPlayerRange(config.getInt("requiredPlayerRange", 16));
spawner.setSpawnRange(config.getInt("spawnRange", 4));
bs.update(true, false); bs.update(true, false);
}
// Chests, in general
if (bs instanceof InventoryHolder) { if (bs instanceof InventoryHolder) {
bs.update(true, false);
Inventory ih = ((InventoryHolder)bs).getInventory(); Inventory ih = ((InventoryHolder)bs).getInventory();
ConfigurationSection inv = s.getConfigurationSection("inventory"); if (config.isConfigurationSection("inventory")) {
ConfigurationSection inv = config.getConfigurationSection("inventory");
inv.getKeys(false).forEach(i -> ih.setItem(Integer.valueOf(i), (ItemStack)inv.get(i))); inv.getKeys(false).forEach(i -> ih.setItem(Integer.valueOf(i), (ItemStack)inv.get(i)));
} }
}
// Entities
if (config.isConfigurationSection("entity")) {
ConfigurationSection en = config.getConfigurationSection("entity");
en.getKeys(false).forEach(k -> {
ConfigurationSection ent = en.getConfigurationSection(k);
Location center = block.getLocation().add(new Vector(0.5, 0.0, 0.5));
LivingEntity e = (LivingEntity)block.getWorld().spawnEntity(center, EntityType.valueOf(ent.getString("type", "PIG")));
if (e instanceof Nameable) {
e.setCustomName(ent.getString("name"));
}
if (e instanceof Colorable) {
if (ent.contains("color")) {
((Colorable) e).setColor(DyeColor.valueOf(ent.getString("color")));
}
}
if (e instanceof Tameable) {
((Tameable)e).setTamed(ent.getBoolean("tamed"));
}
if (e instanceof ChestedHorse) {
((ChestedHorse)e).setCarryingChest(ent.getBoolean("chest"));
}
if (e instanceof Ageable) {
if (ent.getBoolean("adult")) {
((Ageable)e).setAdult();
} else {
((Ageable)e).setBaby();
}
}
if (e instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse)e;
horse.setDomestication(ent.getInt("domestication"));
ConfigurationSection inv = ent.getConfigurationSection("inventory");
inv.getKeys(false).forEach(i -> horse.getInventory().setItem(Integer.valueOf(i), (ItemStack)inv.get(i)));
}
if (e instanceof AbstractHorse) {
Horse horse = (Horse)e;
horse.setStyle(Horse.Style.valueOf(ent.getString("style", "NONE")));
}
});
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private boolean copyBlock(Block block, Location copyOrigin, boolean copyAir) { private boolean copyBlock(Block block, Location copyOrigin, boolean copyAir, Collection<LivingEntity> entities) {
if (!copyAir && block.getType().equals(Material.AIR)) { if (!copyAir && block.getType().equals(Material.AIR) && entities.isEmpty()) {
return false; return false;
} }
// Create position // Create position
@ -308,11 +422,57 @@ public class Clipboard {
// Position defines the section // Position defines the section
ConfigurationSection s = blockConfig.createSection(BLOCK + "." + pos); ConfigurationSection s = blockConfig.createSection(BLOCK + "." + pos);
// Set entities
for (LivingEntity e: entities) {
ConfigurationSection en = s.createSection("entity." + e.getUniqueId());
en.set("type", e.getType().name());
if (e instanceof Nameable) {
en.set("name", e.getCustomName());
}
if (e instanceof Colorable) {
Colorable c = (Colorable)e;
en.set("color", c.getColor().name());
}
if (e instanceof Tameable && ((Tameable)e).isTamed()) {
en.set("tamed", true);
}
if (e instanceof ChestedHorse && ((ChestedHorse)e).isCarryingChest()) {
en.set("chest", true);
}
if (e instanceof Ageable) {
en.set("adult", ((Ageable)e).isAdult());
}
if (e instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse)e;
en.set("domestication", horse.getDomestication());
for (int index = 0; index < horse.getInventory().getSize(); index++) {
ItemStack i = horse.getInventory().getItem(index);
if (i != null) {
en.set("inventory." + index, i);
}
}
}
if (e instanceof Horse) {
Horse horse = (Horse)e;
en.set("style", horse.getStyle().name());
}
}
// Return if this is just air block
if (!copyAir && block.getType().equals(Material.AIR) && !entities.isEmpty()) {
return true;
}
// Set the block type // Set the block type
s.set("type", block.getType().toString()); s.set("type", block.getType().toString());
if (block.getData() != 0) { if (block.getData() != 0) {
s.set("data", block.getData()); s.set("data", block.getData());
} }
if (block.getType().equals(Material.BEDROCK)) {
blockConfig.set("bedrock", x + "," + y + "," + z);
}
// Block state // Block state
BlockState bs = block.getState(); BlockState bs = block.getState();
@ -324,9 +484,16 @@ public class Clipboard {
s.set("open", open.isOpen()); s.set("open", open.isOpen());
} }
if (md instanceof Directional) { if (md instanceof Directional) {
if (md instanceof Stairs) {
//facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING)).getOppositeFace());
Stairs stairs = (Stairs)md;
s.set("inverted", stairs.isInverted());
s.set(FACING, stairs.getAscendingDirection().name());
} else {
Directional facing = (Directional)md; Directional facing = (Directional)md;
s.set(FACING, facing.getFacing().name()); s.set(FACING, facing.getFacing().name());
} }
}
if (md instanceof Attachable) { if (md instanceof Attachable) {
Attachable facing = (Attachable)md; Attachable facing = (Attachable)md;
s.set(FACING, facing.getFacing().name()); s.set(FACING, facing.getFacing().name());
@ -493,11 +660,11 @@ public class Clipboard {
/** /**
* Save the clipboard to a file * Save the clipboard to a file
* @param user - user who is copying * @param user - user who is copying
* @param string - filename * @param newFile - filename
* @return - true if successful, false if error * @return - true if successful, false if error
*/ */
public boolean save(User user, String string) { public boolean save(User user, String newFile) {
File file = new File(schemFolder, string); File file = new File(schemFolder, newFile);
try { try {
getBlockConfig().save(file); getBlockConfig().save(file);
} catch (IOException e) { } catch (IOException e) {
@ -515,4 +682,6 @@ public class Clipboard {
user.sendMessage("general.success"); user.sendMessage("general.success");
return true; return true;
} }
} }

View File

@ -1,487 +0,0 @@
package us.tastybento.bskyblock.island.builders;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Chest;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.Constants.GameType;
import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
/**
* Fired when a team event happens.
*
* @author tastybento
* @since 1.0
*/
public class IslandBuilder {
public enum IslandType {
ISLAND,
NETHER,
END
}
private Island island;
private World world;
private IslandType type = IslandType.ISLAND;
private List<ItemStack> chestItems;
private UUID playerUUID;
private String playerName;
//TODO support companions?
public IslandBuilder(Island island) {
this.island = island;
world = island.getWorld();
}
/**
* @param type the type to set
*/
public IslandBuilder setType(IslandType type) {
this.type = type;
return this;
}
/**
* @param player - the player the player to set
*/
public IslandBuilder setPlayer(Player player) {
playerUUID = player.getUniqueId();
playerName = player.getName();
return this;
}
/**
* @param list the default chestItems to set
*/
public IslandBuilder setChestItems(List<ItemStack> list) {
chestItems = list;
return this;
}
public void build() {
// Switch on island type
switch (type) {
case ISLAND:
world = island.getWorld();
if (Constants.GAMETYPE == GameType.ACIDISLAND) {
generateAcidIslandBlocks();
} else {
generateIslandBlocks();
}
break;
case NETHER:
world = Bukkit.getWorld(island.getWorld().getName() + "_nether");
if (world == null) {
return;
}
generateNetherBlocks();
break;
case END:
world = Bukkit.getWorld(island.getWorld().getName() + "_the_end");
if (world == null) {
return;
}
generateEndBlocks();
break;
}
// Do other stuff
}
/**
* Creates the AcidIsland default island block by block
*/
private void generateAcidIslandBlocks() {
// AcidIsland
// Build island layer by layer
// Start from the base
// half sandstone; half sand
int x = island.getCenter().getBlockX();
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
int y = 0;
for (int x_space = x - 4; x_space <= x + 4; x_space++) {
for (int z_space = z - 4; z_space <= z + 4; z_space++) {
Block b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.BEDROCK);
}
}
for (y = 1; y < islandHeight + 5; y++) {
for (int x_space = x - 4; x_space <= x + 4; x_space++) {
for (int z_space = z - 4; z_space <= z + 4; z_space++) {
Block b = world.getBlockAt(x_space, y, z_space);
if (y < (islandHeight / 2)) {
b.setType(Material.SANDSTONE);
} else {
b.setType(Material.SAND);
}
}
}
}
// Then cut off the corners to make it round-ish
for (y = 0; y < islandHeight + 5; y++) {
for (int x_space = x - 4; x_space <= x + 4; x_space += 8) {
for (int z_space = z - 4; z_space <= z + 4; z_space += 8) {
Block b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.STATIONARY_WATER);
}
}
}
// Add some grass
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
Block blockToChange = world.getBlockAt(x_space, y, z_space);
blockToChange.setType(Material.GRASS);
}
}
}
// Place bedrock - MUST be there (ensures island are not
// overwritten
Block b = world.getBlockAt(x, islandHeight, z);
b.setType(Material.BEDROCK);
// Then add some more dirt in the classic shape
y = islandHeight + 3;
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.DIRT);
}
}
b = world.getBlockAt(x - 3, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 3, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 3);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 3);
b.setType(Material.DIRT);
y = islandHeight + 2;
for (int x_space = x - 1; x_space <= x + 1; x_space++) {
for (int z_space = z - 1; z_space <= z + 1; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.DIRT);
}
}
b = world.getBlockAt(x - 2, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 2, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 2);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 2);
b.setType(Material.DIRT);
y = islandHeight + 1;
b = world.getBlockAt(x - 1, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 1, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 1);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 1);
b.setType(Material.DIRT);
// Add island items
y = islandHeight;
// Add tree (natural)
Location treeLoc = new Location(world, x, y + 5D, z);
world.generateTree(treeLoc, TreeType.ACACIA);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
// Place the chest - no need to use the safe spawn function
// because we
// know what this island looks like
placeChest(x, islandHeight + 5, z + 1);
}
private void generateIslandBlocks() {
// Skyblock
// Build island layer by layer
// Start from the base
// half sandstone; half sand
int x = island.getCenter().getBlockX();
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
World world = island.getCenter().getWorld();
int y;
// Add some grass
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
for (int z_space = z - 3; z_space <= z + 3; z_space++) {
world.getBlockAt(x_space, y, z_space).setType(Material.GRASS);
}
}
}
// Then cut off the corners to make it round-ish
for (int x_space = x - 3; x_space <= x + 3; x_space += 6) {
for (int z_space = z - 3; z_space <= z + 3; z_space += 6) {
world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR);
}
}
// Place bedrock - MUST be there (ensures island are not
// overwritten
Block b = world.getBlockAt(x, islandHeight, z);
b.setType(Material.BEDROCK);
// Then add some more dirt in the classic shape
y = islandHeight + 3;
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.DIRT);
}
}
b = world.getBlockAt(x - 3, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 3, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 3);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 3);
b.setType(Material.DIRT);
y = islandHeight + 2;
for (int x_space = x - 1; x_space <= x + 1; x_space++) {
for (int z_space = z - 1; z_space <= z + 1; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.DIRT);
}
}
b = world.getBlockAt(x - 2, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 2, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 2);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 2);
b.setType(Material.DIRT);
y = islandHeight + 1;
b = world.getBlockAt(x - 1, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x + 1, y, z);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z - 1);
b.setType(Material.DIRT);
b = world.getBlockAt(x, y, z + 1);
b.setType(Material.DIRT);
// Add island items
y = islandHeight;
// Add tree (natural)
Location treeLoc = new Location(world, x, y + 5D, z);
world.generateTree(treeLoc, TreeType.TREE);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
// Place the chest - no need to use the safe spawn function
// because we
// know what this island looks like
placeChest(x, islandHeight + 5, z + 1);
}
private void generateNetherBlocks() {
// Nether block
int x = island.getCenter().getBlockX();
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
int y;
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
for (int z_space = z - 3; z_space <= z + 3; z_space++) {
world.getBlockAt(x_space, y, z_space).setType(Material.NETHER_BRICK);
}
}
}
// Then cut off the corners to make it round-ish
for (int x_space = x - 3; x_space <= x + 3; x_space += 6) {
for (int z_space = z - 3; z_space <= z + 3; z_space += 6) {
world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR);
}
}
// Place bedrock - MUST be there (ensures island are not
// overwritten
Block b = world.getBlockAt(x, islandHeight, z);
b.setType(Material.BEDROCK);
// Then add some more dirt in the classic shape
y = islandHeight + 3;
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.NETHERRACK);
}
}
b = world.getBlockAt(x - 3, y, z);
b.setType(Material.SOUL_SAND);
b = world.getBlockAt(x + 3, y, z);
b.setType(Material.SOUL_SAND);
b = world.getBlockAt(x, y, z - 3);
b.setType(Material.SOUL_SAND);
b = world.getBlockAt(x, y, z + 3);
b.setType(Material.SOUL_SAND);
y = islandHeight + 2;
for (int x_space = x - 1; x_space <= x + 1; x_space++) {
for (int z_space = z - 1; z_space <= z + 1; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.GRAVEL);
}
}
b = world.getBlockAt(x - 2, y, z);
b.setType(Material.QUARTZ_ORE);
b = world.getBlockAt(x + 2, y, z);
b.setType(Material.QUARTZ_ORE);
b = world.getBlockAt(x, y, z - 2);
b.setType(Material.QUARTZ_ORE);
b = world.getBlockAt(x, y, z + 2);
b.setType(Material.QUARTZ_ORE);
y = islandHeight + 1;
b = world.getBlockAt(x - 1, y, z);
b.setType(Material.MAGMA);
b = world.getBlockAt(x + 1, y, z);
b.setType(Material.MAGMA);
b = world.getBlockAt(x, y, z - 1);
b.setType(Material.MAGMA);
b = world.getBlockAt(x, y, z + 1);
b.setType(Material.MAGMA);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
// Place the chest - no need to use the safe spawn function
// because we know what this island looks like
placeChest(x, islandHeight + 5, z + 1);
}
private void generateEndBlocks() {
// Nether block
int x = island.getCenter().getBlockX();
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
int y;
// Add some grass
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
for (int z_space = z - 3; z_space <= z + 3; z_space++) {
world.getBlockAt(x_space, y, z_space).setType(Material.END_BRICKS);
}
}
}
// Then cut off the corners to make it round-ish
for (int x_space = x - 3; x_space <= x + 3; x_space += 6) {
for (int z_space = z - 3; z_space <= z + 3; z_space += 6) {
world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR);
}
}
// Place bedrock - MUST be there (ensures island are not
// overwritten
Block b = world.getBlockAt(x, islandHeight, z);
b.setType(Material.BEDROCK);
// Then add some more dirt in the classic shape
y = islandHeight + 3;
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.ENDER_STONE);
}
}
b = world.getBlockAt(x - 3, y, z);
b.setType(Material.OBSIDIAN);
b = world.getBlockAt(x + 3, y, z);
b.setType(Material.OBSIDIAN);
b = world.getBlockAt(x, y, z - 3);
b.setType(Material.OBSIDIAN);
b = world.getBlockAt(x, y, z + 3);
b.setType(Material.OBSIDIAN);
y = islandHeight + 2;
for (int x_space = x - 1; x_space <= x + 1; x_space++) {
for (int z_space = z - 1; z_space <= z + 1; z_space++) {
b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.ENDER_STONE);
}
}
b = world.getBlockAt(x - 2, y, z);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x + 2, y, z);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x, y, z - 2);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x, y, z + 2);
b.setType(Material.ENDER_STONE);
y = islandHeight + 1;
b = world.getBlockAt(x - 1, y, z);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x + 1, y, z);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x, y, z - 1);
b.setType(Material.ENDER_STONE);
b = world.getBlockAt(x, y, z + 1);
b.setType(Material.ENDER_STONE);
// Add island items
y = islandHeight;
// Spawn an ender crystal
world.spawnEntity(new Location(world, x, y + 5D, z), EntityType.ENDER_CRYSTAL);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
// Place the chest - no need to use the safe spawn function
// because we know what this island looks like
placeChest(x, islandHeight + 5, z + 1);
}
private void placeSign(int x, int y, int z) {
Block blockToChange = world.getBlockAt(x, y, z);
blockToChange.setType(Material.SIGN_POST);
if (playerUUID != null) {
Sign sign = (Sign) blockToChange.getState();
User user = User.getInstance(playerUUID);
// Sets the lines of the sign
sign.setLine(0, user.getTranslation("new-island.sign.line0", TextVariables.NAME, playerName));
sign.setLine(1, user.getTranslation("new-island.sign.line1", TextVariables.NAME, playerName));
sign.setLine(2, user.getTranslation("new-island.sign.line2", TextVariables.NAME, playerName));
sign.setLine(3, user.getTranslation("new-island.sign.line3", TextVariables.NAME, playerName));
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
sign.update();
}
}
private void placeChest(int x, int y, int z) {
// Fill the chest and orient it correctly
Block blockToChange = world.getBlockAt(x, y, z);
blockToChange.setType(Material.CHEST);
BlockState state = blockToChange.getState();
Chest chest = new Chest(BlockFace.SOUTH);
state.setData(chest);
state.update();
if (!chestItems.isEmpty()) {
InventoryHolder chestBlock = (InventoryHolder) state;
for (ItemStack item: chestItems) {
chestBlock.getInventory().addItem(item);
}
}
}
}

View File

@ -1,196 +0,0 @@
package us.tastybento.bskyblock.island.builders;
import java.io.File;
import java.io.IOException;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Chest;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
/**
* Generates islands
*
* @author tastybento
* @since 1.0
*/
public class IslandBuilderNew {
public enum IslandType {
ISLAND,
NETHER,
END
}
private Island island;
private World world;
private IslandType type = IslandType.ISLAND;
private List<ItemStack> chestItems;
private UUID playerUUID;
private String playerName;
private BSkyBlock plugin;
private Map<IslandType, Clipboard> islandSchems = new EnumMap<>(IslandType.class);
//TODO support companions?
public IslandBuilderNew(BSkyBlock plugin, Island island) {
this.plugin = plugin;
this.island = island;
world = island.getWorld();
loadIslands();
}
private void loadIslands() {
File schems = new File(plugin.getDataFolder(), "schems");
if (!schems.exists()) {
if (!schems.mkdirs()) {
plugin.logError("Could not make schems folder!");
} else {
copySchems(schems);
}
}
try {
Clipboard cb = new Clipboard(plugin);
cb.load("island");
islandSchems.put(IslandType.ISLAND, cb);
} catch (IOException | InvalidConfigurationException e) {
plugin.logError("Could not load default island");
}
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) {
try {
Clipboard cbn = new Clipboard(plugin);
cbn.load("nether-island");
islandSchems.put(IslandType.NETHER, cbn);
} catch (IOException | InvalidConfigurationException e) {
plugin.logError("Could not load default nether island");
}
}
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) {
try {
Clipboard cbe = new Clipboard(plugin);
cbe.load("end-island");
islandSchems.put(IslandType.END, cbe);
} catch (IOException | InvalidConfigurationException e) {
plugin.logError("Could not load default end island");
}
}
plugin.log("Loaded " + islandSchems.size() + " islands");
}
/**
* Copies schems from the jar file
* @param schems2 - file containing schem
*/
private void copySchems(File schems2) {
plugin.saveResource("schems/island.schem", false);
plugin.saveResource("schems/nether-island.schem", false);
plugin.saveResource("schems/end-island.schem", false);
}
/**
* @param type the type to set
*/
public IslandBuilderNew setType(IslandType type) {
this.type = type;
return this;
}
/**
* @param player - the player the player to set
*/
public IslandBuilderNew setPlayer(Player player) {
playerUUID = player.getUniqueId();
playerName = player.getName();
return this;
}
/**
* @param list the default chestItems to set
*/
public IslandBuilderNew setChestItems(List<ItemStack> list) {
chestItems = list;
return this;
}
public void build() {
plugin.log("Pasting island to " + type);
Location loc = island.getCenter();
// Switch on island type
switch (type) {
case NETHER:
world = Bukkit.getWorld(island.getWorld().getName() + "_nether");
if (world == null) {
return;
}
loc = island.getCenter().toVector().toLocation(world);
break;
case END:
world = Bukkit.getWorld(island.getWorld().getName() + "_the_end");
if (world == null) {
return;
}
loc = island.getCenter().toVector().toLocation(world);
break;
default:
break;
}
plugin.log("Pasting island to " + loc);
islandSchems.get(type).paste(loc);
// Do other stuff
}
private void placeSign(int x, int y, int z) {
Block blockToChange = world.getBlockAt(x, y, z);
blockToChange.setType(Material.SIGN_POST);
if (playerUUID != null) {
Sign sign = (Sign) blockToChange.getState();
User user = User.getInstance(playerUUID);
// Sets the lines of the sign
sign.setLine(0, user.getTranslation("new-island.sign.line0", TextVariables.NAME, playerName));
sign.setLine(1, user.getTranslation("new-island.sign.line1", TextVariables.NAME, playerName));
sign.setLine(2, user.getTranslation("new-island.sign.line2", TextVariables.NAME, playerName));
sign.setLine(3, user.getTranslation("new-island.sign.line3", TextVariables.NAME, playerName));
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
sign.update();
}
}
private void placeChest(int x, int y, int z) {
// Fill the chest and orient it correctly
Block blockToChange = world.getBlockAt(x, y, z);
blockToChange.setType(Material.CHEST);
BlockState state = blockToChange.getState();
Chest chest = new Chest(BlockFace.SOUTH);
state.setData(chest);
state.update();
if (!chestItems.isEmpty()) {
InventoryHolder chestBlock = (InventoryHolder) state;
for (ItemStack item: chestItems) {
chestBlock.getInventory().addItem(item);
}
}
}
}

View File

@ -1,8 +1,10 @@
package us.tastybento.bskyblock.managers; package us.tastybento.bskyblock.managers;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -16,6 +18,7 @@ import org.bukkit.WorldType;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.api.configuration.WorldSettings; import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -538,4 +541,21 @@ public class IslandWorldManager {
return worldSettings.get(Util.getWorld(world)).isOnLeaveResetEnderChest(); return worldSettings.get(Util.getWorld(world)).isOnLeaveResetEnderChest();
} }
/**
* The data folder for the addon that registered this world, or the plugin's data folder if none found
* @return
*/
public File getDataFolder(World world) {
return worldSettings.get(Util.getWorld(world)).getAddon().map(Addon::getDataFolder).orElse(plugin.getDataFolder());
}
/**
* Get the addon associated with this world set
* @param world - world
* @return Addon, or empty
*/
public Optional<Addon> getAddon(World world) {
return worldSettings.get(Util.getWorld(world)).getAddon();
}
} }

View File

@ -348,6 +348,7 @@ public class IslandsManager {
public Location getSafeHomeLocation(World world, User user, int number) { public Location getSafeHomeLocation(World world, User user, int number) {
// Try the numbered home location first // Try the numbered home location first
Location l = plugin.getPlayers().getHomeLocation(world, user, number); Location l = plugin.getPlayers().getHomeLocation(world, user, number);
if (l == null) { if (l == null) {
// Get the default home, which may be null too, but that's okay // Get the default home, which may be null too, but that's okay
number = 1; number = 1;
@ -433,7 +434,7 @@ public class IslandsManager {
* @return the spawnPoint or null if spawn does not exist * @return the spawnPoint or null if spawn does not exist
*/ */
public Location getSpawnPoint(World world) { public Location getSpawnPoint(World world) {
return spawn.containsKey(world) ? spawn.get(world).getSpawnPoint() : null; return spawn.containsKey(world) ? spawn.get(world).getSpawnPoint(world.getEnvironment()) : null;
} }
/** /**
@ -723,7 +724,7 @@ public class IslandsManager {
// Move player to spawn // Move player to spawn
if (spawn.containsKey(island.getWorld())) { if (spawn.containsKey(island.getWorld())) {
// go to island spawn // go to island spawn
player.teleport(spawn.get(island.getWorld()).getSpawnPoint()); player.teleport(spawn.get(island.getWorld()).getSpawnPoint(island.getWorld().getEnvironment()));
} else { } else {
if (!player.performCommand(Constants.SPAWNCOMMAND)) { if (!player.performCommand(Constants.SPAWNCOMMAND)) {
plugin.logWarning("During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry."); plugin.logWarning("During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry.");

View File

@ -0,0 +1,114 @@
package us.tastybento.bskyblock.managers;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.island.builders.Clipboard;
public class SchemsManager {
private BSkyBlock plugin;
private Map<World, Clipboard> islandSchems;
/**
* @param plugin
*/
public SchemsManager(BSkyBlock plugin) {
this.plugin = plugin;
islandSchems = new HashMap<>();
}
private void copySchems(File schems, World world, String name) {
if (!schems.exists() && !schems.mkdirs()) {
plugin.logError("Could not make schems folder!");
return;
}
Optional<Addon> addon = plugin.getIWM().getAddon(world);
if (addon.isPresent()) {
addon.get().saveResource("schems/" + name + ".schem", false);
} else {
plugin.saveResource("schems/" + name + ".schem", false);
}
}
public Clipboard get(World world) {
return islandSchems.get(world);
}
/**
* Load schems for world. Will try and load nether and end schems too if settings are set.
* @param world - world
*/
public void loadIslands(World world) {
if (plugin.getSchemsManager().loadSchem(world, "island")) {
plugin.log("Loaded island for " + plugin.getIWM().getFriendlyName(world));
} else {
plugin.logError("Could not load island for " + plugin.getIWM().getFriendlyName(world));
}
if (plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world)) {
if (plugin.getSchemsManager().loadSchem(plugin.getIWM().getNetherWorld(world), "nether-island")) {
plugin.log("Loaded nether island for " + plugin.getIWM().getFriendlyName(world));
} else {
plugin.logError("Could not load nether island for " + plugin.getIWM().getFriendlyName(world));
}
}
if (plugin.getIWM().isEndGenerate(world) && plugin.getIWM().isEndIslands(world)) {
if (plugin.getSchemsManager().loadSchem(plugin.getIWM().getEndWorld(world), "end-island")) {
plugin.log("Loaded end island for " + plugin.getIWM().getFriendlyName(world));
} else {
plugin.logError("Could not load end island for " + plugin.getIWM().getFriendlyName(world));
}
}
}
private boolean loadSchem(World world, String name) {
File schems = new File(plugin.getIWM().getDataFolder(world), "schems");
copySchems(schems, world, name);
try {
Clipboard cb = new Clipboard(plugin, schems);
cb.load(name);
islandSchems.put(world, cb);
} catch (IOException | InvalidConfigurationException e) {
plugin.logError("Could not load " + name + " schem");
e.printStackTrace();
return false;
}
return true;
}
/**
* Paste the schem for world to the island center location and run task afterwards
* @param world - world to paste to
* @param island - the island who owns this schem
* @param task - task to run after pasting is completed
*/
public void paste(World world, Island island, Runnable task) {
if (islandSchems.containsKey(world)) {
islandSchems.get(world).paste(world, island, task);
}
}
/**
* Paste the schem to world for island
* @param world
* @param island
*/
public void paste(World world, Island island) {
paste(world, island, null);
}
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
@ -11,7 +12,6 @@ import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.island.builders.IslandBuilderNew;
/** /**
* Create and paste a new island * Create and paste a new island
@ -117,21 +117,29 @@ public class NewIsland {
.island(island) .island(island)
.location(island.getCenter()) .location(island.getCenter())
.build(); .build();
if (!event.isCancelled()) { if (event.isCancelled()) {
return;
}
// Create island // Create island
IslandBuilderNew ib = new IslandBuilderNew(plugin, island) plugin.getSchemsManager().paste(world, island, () -> {
.setPlayer(user.getPlayer()) // Set initial spawn point if one exists
.setChestItems(plugin.getSettings().getChestItems()) if (island.getSpawnPoint(Environment.NORMAL) != null) {
.setType(IslandBuilderNew.IslandType.ISLAND); plugin.getPlayers().setHomeLocation(user, island.getSpawnPoint(Environment.NORMAL), 1);
ib.build();
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIWM().getNetherWorld() != null) {
ib.setType(IslandBuilderNew.IslandType.NETHER).build();
} }
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIWM().getEndWorld() != null) { // Teleport player after this island is built
ib.setType(IslandBuilderNew.IslandType.END).build();
}
// Teleport player to their island
plugin.getIslands().homeTeleport(world, user.getPlayer(), true); plugin.getIslands().homeTeleport(world, user.getPlayer(), true);
});
// Make nether island
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIWM().getNetherWorld() != null) {
plugin.getSchemsManager().paste(plugin.getIWM().getNetherWorld(world), island);
}
// Make end island
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIWM().getEndWorld() != null) {
plugin.getSchemsManager().paste(plugin.getIWM().getEndWorld(world), island);
}
// Fire exit event // Fire exit event
Reason reasonDone = Reason.CREATED; Reason reasonDone = Reason.CREATED;
switch (reason) { switch (reason) {
@ -150,7 +158,7 @@ public class NewIsland {
.island(island) .island(island)
.location(island.getCenter()) .location(island.getCenter())
.build(); .build();
}
} }
/** /**

View File

@ -2,6 +2,8 @@ package us.tastybento.bskyblock.panels;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
@ -23,8 +25,16 @@ public class LanguagePanel {
.name(user.getTranslation("language.panel-title")); .name(user.getTranslation("language.panel-title"));
for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales(true)) { for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales(true)) {
PanelItemBuilder localeIcon = new PanelItemBuilder().icon(BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner()) PanelItemBuilder localeIcon = new PanelItemBuilder();
.name(fancyLocaleDisplayName(user, locale))
ItemStack localeBanner = BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner();
if (localeBanner != null) {
localeIcon.icon(localeBanner);
} else {
localeIcon.icon(new ItemStack(Material.BANNER, 1)); // Set to a blank banner.
}
localeIcon.name(fancyLocaleDisplayName(user, locale))
.clickHandler((panel, u, click, slot) -> { .clickHandler((panel, u, click, slot) -> {
BSkyBlock.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag()); BSkyBlock.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag());
u.sendMessage("language.edited", "[lang]", fancyLocaleDisplayName(u, locale)); u.sendMessage("language.edited", "[lang]", fancyLocaleDisplayName(u, locale));

View File

@ -132,11 +132,11 @@ public class ItemParser {
if (part.length == 2) { if (part.length == 2) {
return new ItemStack(Material.BANNER, Integer.parseInt(part[1])); return new ItemStack(Material.BANNER, Integer.parseInt(part[1]));
} }
if (part.length > 3) { if (part.length >= 3) {
int reqAmount = Integer.parseInt(part[1]); int reqAmount = Integer.parseInt(part[1]);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
ItemStack result = new ItemStack(Material.BANNER, reqAmount, (short) DyeColor.valueOf(part[2]).getDyeData()); ItemStack result = new ItemStack(Material.BANNER, reqAmount, DyeColor.valueOf(part[2]).getDyeData());
BannerMeta meta = (BannerMeta) result.getItemMeta(); BannerMeta meta = (BannerMeta) result.getItemMeta();
for (int i = 3; i < part.length; i += 2) { for (int i = 3; i < part.length; i += 2) {
@ -147,10 +147,10 @@ public class ItemParser {
return result; return result;
} else { } else {
return new ItemStack(Material.BANNER, 1); // Return a blank banner return null;
} }
} catch (Exception e) { } catch (Exception e) {
return new ItemStack(Material.BANNER, 1); // Return a blank banner return null;
} }
} }
} }

View File

@ -13,6 +13,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -243,5 +244,49 @@ public class Util {
return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll(NETHER, "").replaceAll(THE_END, "")); return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll(NETHER, "").replaceAll(THE_END, ""));
} }
/**
* Converts block face direction to radial degrees. Returns 0 if block face
* is not radial.
*
* @param face
* @return degrees
*/
public static float blockFaceToFloat(BlockFace face) {
switch (face) {
case EAST:
return 90F;
case EAST_NORTH_EAST:
return 67.5F;
case EAST_SOUTH_EAST:
return 0F;
case NORTH:
return 0F;
case NORTH_EAST:
return 45F;
case NORTH_NORTH_EAST:
return 22.5F;
case NORTH_NORTH_WEST:
return 337.5F;
case NORTH_WEST:
return 315F;
case SOUTH:
return 180F;
case SOUTH_EAST:
return 135F;
case SOUTH_SOUTH_EAST:
return 157.5F;
case SOUTH_SOUTH_WEST:
return 202.5F;
case SOUTH_WEST:
return 225F;
case WEST:
return 270F;
case WEST_NORTH_WEST:
return 292.5F;
case WEST_SOUTH_WEST:
return 247.5F;
default:
return 0F;
}
}
} }

View File

@ -16,6 +16,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -149,7 +150,7 @@ public class MySQLDatabaseHandlerTest {
island.setPurgeProtected(true); island.setPurgeProtected(true);
island.setRange(100); island.setRange(100);
island.setSpawn(true); island.setSpawn(true);
island.setSpawnPoint(location); island.setSpawnPoint(Environment.NORMAL, location);
island.setWorld(world); island.setWorld(world);
MySQLDatabaseHandler<Island> ih = new MySQLDatabaseHandler<>(plugin, Island.class, dbConn); MySQLDatabaseHandler<Island> ih = new MySQLDatabaseHandler<>(plugin, Island.class, dbConn);

View File

@ -600,7 +600,7 @@ public class IslandsManagerTest {
Island island = mock(Island.class); Island island = mock(Island.class);
when(island.getWorld()).thenReturn(world); when(island.getWorld()).thenReturn(world);
// Make a spawn position on the island // Make a spawn position on the island
when(island.getSpawnPoint()).thenReturn(location); when(island.getSpawnPoint(Mockito.any())).thenReturn(location);
// Set the spawn island // Set the spawn island
im.setSpawn(island); im.setSpawn(island);
assertEquals(location,im.getSpawnPoint(world)); assertEquals(location,im.getSpawnPoint(world));

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
@ -16,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SpawnEggMeta; import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import org.junit.Before; import org.junit.Before;
@ -201,12 +203,14 @@ public class ItemParserTest {
assertEquals(2, result.getAmount()); assertEquals(2, result.getAmount());
} }
@SuppressWarnings("deprecation")
@Test @Test
public void testParseBannerThreeArgs() { public void testParseBannerThreeArgs() {
// Germany // Germany
ItemStack result = ItemParser.parse("BANNER:1:RED"); ItemStack result = ItemParser.parse("BANNER:1:RED");
assertEquals(Material.BANNER, result.getType()); assertEquals(Material.BANNER, result.getType());
assertEquals(1, result.getAmount()); assertEquals(1, result.getAmount());
assertEquals(new MaterialData(Material.BANNER, DyeColor.RED.getDyeData()), result.getData());
} }
@Test @Test
@ -216,6 +220,14 @@ public class ItemParserTest {
Mockito.verify(bannerMeta, Mockito.times(2)).addPattern(Mockito.any()); Mockito.verify(bannerMeta, Mockito.times(2)).addPattern(Mockito.any());
} }
@Test
public void testParseBannerTooManyColons() {
ItemStack result = ItemParser.parse("BANNER:1::::::::::::::");
Mockito.verify(bannerMeta, Mockito.never()).addPattern(Mockito.any());
assertEquals(Material.BANNER, result.getType());
assertEquals(1, result.getAmount());
}
@Test @Test
public void testParseTwoItem() { public void testParseTwoItem() {
ItemStack result = ItemParser.parse("STONE:5"); ItemStack result = ItemParser.parse("STONE:5");