Removed schematics.

This commit is contained in:
Tastybento 2017-12-09 10:44:09 -08:00
parent e10eb194b2
commit 323720598a
21 changed files with 133 additions and 3625 deletions

1
lib/.gitignore vendored
View File

@ -1 +0,0 @@
/spigot-1.12.jar

Binary file not shown.

View File

@ -12,7 +12,6 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<server.jars>${project.basedir}/lib</server.jars>
</properties>
<build>
<defaultGoal>clean package install</defaultGoal>
@ -81,13 +80,6 @@
<artifactId>VaultAPI</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>library-1.12</artifactId>
<scope>system</scope>
<systemPath>${server.jars}/library-1.12.jar</systemPath>
<version>1.12</version>
</dependency>
</dependencies>
<repositories>
<repository>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -27,7 +27,6 @@ import us.tastybento.bskyblock.listeners.protection.IslandGuard;
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_8;
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_9;
import us.tastybento.bskyblock.listeners.protection.NetherEvents;
import us.tastybento.bskyblock.schematics.SchematicsMgr;
import us.tastybento.bskyblock.util.VaultHelper;
/**
@ -44,9 +43,6 @@ public class BSkyBlock extends JavaPlugin {
private IslandsManager islandsManager;
private OfflineHistoryMessages offlineHistoryMessages;
// Schematics
private SchematicsMgr schematicsManager;
// Metrics
private Metrics metrics;
@ -114,7 +110,6 @@ public class BSkyBlock extends JavaPlugin {
new ItemStack(Material.COBBLESTONE,5),
new ItemStack(Material.SAPLING,2)
};
schematicsManager = new SchematicsMgr(plugin);
Settings.defaultLanguage = "en-US";
localeManager = new LocaleManager(plugin);
@ -236,13 +231,6 @@ public class BSkyBlock extends JavaPlugin {
return plugin;
}
/**
* @return the schematics
*/
public SchematicsMgr getSchematics() {
return schematicsManager;
}
/**
* @param sender
* @return Locale object for sender

View File

@ -30,7 +30,6 @@ import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.panels.LanguagePanel;
import us.tastybento.bskyblock.schematics.Schematic;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
@ -332,11 +331,9 @@ public class IslandCommand extends AbstractCommand {
// Create new island and then delete the old one
if (DEBUG)
plugin.getLogger().info("DEBUG: making new island ");
Schematic schematic = plugin.getSchematics().getSchematic("default");
try {
NewIsland.builder()
.player(player)
.schematic(schematic)
.oldIsland(oldIsland)
.build();
} catch (IOException e) {
@ -1527,11 +1524,9 @@ public class IslandCommand extends AbstractCommand {
*/
protected void createIsland(Player player) {
//TODO: Add panels, make a selection.
Schematic schematic = plugin.getSchematics().getSchematic("default");
try {
NewIsland.builder()
.player(player)
.schematic(schematic)
.build();
} catch (IOException e) {
plugin.getLogger().severe("Could not create island for player.");

View File

@ -10,8 +10,8 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.schematics.Schematic;
import us.tastybento.bskyblock.schematics.Schematic.PasteReason;
import us.tastybento.bskyblock.island.builders.IslandBuilder;
import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
/**
* Create and paste a new island
@ -22,14 +22,10 @@ public class NewIsland {
private static final boolean DEBUG = false;
private final BSkyBlock plugin = BSkyBlock.getPlugin();
private Island island;
private final Island oldIsland;
private final Schematic schematic;
private final Player player;
private NewIsland(Island oldIsland, Schematic schematic, Player player) {
private NewIsland(Island oldIsland, Player player) {
super();
this.oldIsland = oldIsland;
this.schematic = schematic;
this.player = player;
newIsland();
if (oldIsland != null) {
@ -60,7 +56,6 @@ public class NewIsland {
*/
public static class Builder {
private Island oldIsland;
private Schematic schematic;
private Player player;
public Builder oldIsland(Island oldIsland) {
@ -68,10 +63,6 @@ public class NewIsland {
return this;
}
public Builder schematic(Schematic schematic) {
this.schematic = schematic;
return this;
}
public Builder player(Player player) {
this.player = player;
@ -79,8 +70,8 @@ public class NewIsland {
}
public Island build() throws IOException {
if (schematic != null && player != null) {
NewIsland newIsland = new NewIsland(oldIsland,schematic, player);
if (player != null) {
NewIsland newIsland = new NewIsland(oldIsland, player);
return newIsland.getIsland();
}
throw new IOException("Insufficient parameters. Must have a schematic and a player");
@ -88,8 +79,7 @@ public class NewIsland {
}
/**
* Makes an island using schematic. No permission checks are made. They have to be decided
* before this method is called.
* Makes an island.
*/
public void newIsland() {
if (DEBUG)
@ -107,8 +97,7 @@ public class NewIsland {
plugin.getLogger().info("DEBUG: found " + next);
// Add to the grid
Island myIsland = plugin.getIslands().createIsland(next, playerUUID);
myIsland.setLevelHandicap(schematic.getLevelHandicap());
island = plugin.getIslands().createIsland(next, playerUUID);
// Save the player so that if the server is reset weird things won't happen
plugin.getPlayers().save(true);
plugin.getIslands().save(true);
@ -118,75 +107,30 @@ public class NewIsland {
// Set the biome
//BiomesPanel.setIslandBiome(next, schematic.getBiome());
// Teleport to the new home
if (schematic.isPlayerSpawn()) {
// Set home and teleport
plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), 1);
}
// Set home loction
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
// Create island based on schematic
if (schematic != null) {
//plugin.getLogger().info("DEBUG: pasting schematic " + schematic.getName() + " " + schematic.getPerm());
//plugin.getLogger().info("DEBUG: nether world is " + BSkyBlock.getNetherWorld());
// Paste the starting island. If it is a HELL biome, then we start in the Nether
if (Settings.netherGenerate && schematic.isInNether() && Settings.netherIslands && IslandWorld.getNetherWorld() != null) {
// Nether start
// Paste the overworld if it exists
if (!schematic.getPartnerName().isEmpty()) {
// A partner schematic is available
pastePartner(plugin.getSchematics().getSchematic(schematic.getPartnerName()),next, player);
}
// Switch home location to the Nether
next = next.toVector().toLocation(IslandWorld.getNetherWorld());
// Set the player's island location to this new spot
//plugin.getPlayers().setIslandLocation(playerUUID, next);
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland);
} else {
// Over world start
//plugin.getLogger().info("DEBUG: pasting");
//long timer = System.nanoTime();
// Paste the island and teleport the player home
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland);
//double diff = (System.nanoTime() - timer)/1000000;
//plugin.getLogger().info("DEBUG: nano time = " + diff + " ms");
//plugin.getLogger().info("DEBUG: pasted overworld");
// Create island
new IslandBuilder(island)
.setPlayer(player)
.setDefaultChestItems(Settings.chestItems)
.setType(IslandType.ISLAND)
.build();
if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) {
// Paste the other world schematic
final Location netherLoc = next.toVector().toLocation(IslandWorld.getNetherWorld());
if (schematic.getPartnerName().isEmpty()) {
// This will paste the over world schematic again
//plugin.getLogger().info("DEBUG: pasting nether");
pastePartner(schematic, netherLoc, player);
//plugin.getLogger().info("DEBUG: pasted nether");
} else {
if (plugin.getSchematics().getAll().containsKey(schematic.getPartnerName())) {
//plugin.getLogger().info("DEBUG: pasting partner");
// A partner schematic is available
pastePartner(plugin.getSchematics().getAll().get(schematic.getPartnerName()),netherLoc, player);
} else {
plugin.getLogger().severe("Partner schematic heading '" + schematic.getPartnerName() + "' does not exist");
new IslandBuilder(island)
.setPlayer(player)
.setDefaultChestItems(Settings.chestItems)
.setType(IslandType.NETHER)
.build();
}
if (Settings.endGenerate && Settings.endIslands && IslandWorld.getEndWorld() != null) {
new IslandBuilder(island)
.setPlayer(player)
.setDefaultChestItems(Settings.chestItems)
.setType(IslandType.END)
.build();
}
}
}
}
}
/**
* Does a delayed pasting of the partner island
* @param schematic
* @param player
*/
private void pastePartner(final Schematic schematic, final Location loc, final Player player) {
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
schematic.pasteSchematic(loc, player, false, PasteReason.PARTNER, null);
}}, 60L);
}
/**
* Get the location of next free island spot

View File

@ -8,13 +8,13 @@ import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.DirectionalContainer;
import org.bukkit.material.Chest;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
@ -123,18 +123,17 @@ public class IslandBuilder {
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
World world = island.getCenter().getWorld();
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++) {
final Block b = world.getBlockAt(x_space, y, 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++) {
final Block b = world.getBlockAt(x_space, y, z_space);
Block b = world.getBlockAt(x_space, y, z_space);
if (y < (islandHeight / 2)) {
b.setType(Material.SANDSTONE);
} else {
@ -147,7 +146,7 @@ public class IslandBuilder {
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) {
final Block b = world.getBlockAt(x_space, y, z_space);
Block b = world.getBlockAt(x_space, y, z_space);
b.setType(Material.STATIONARY_WATER);
}
}
@ -156,7 +155,7 @@ public class IslandBuilder {
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++) {
final Block blockToChange = world.getBlockAt(x_space, y, z_space);
Block blockToChange = world.getBlockAt(x_space, y, z_space);
blockToChange.setType(Material.GRASS);
}
}
@ -209,10 +208,10 @@ public class IslandBuilder {
// Add island items
y = islandHeight;
// Add tree (natural)
final Location treeLoc = new Location(world, x, y + 5D, z);
Location treeLoc = new Location(world, x, y + 5D, z);
world.generateTree(treeLoc, TreeType.ACACIA);
// Place the cow
//final Location location = new Location(world, x, (islandHeight + 5), z - 2);
//Location location = new Location(world, x, (islandHeight + 5), z - 2);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
@ -235,13 +234,19 @@ public class IslandBuilder {
int y = 0;
// 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++) {
final Block blockToChange = world.getBlockAt(x_space, y, z_space);
blockToChange.setType(Material.GRASS);
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);
@ -290,10 +295,10 @@ public class IslandBuilder {
// Add island items
y = islandHeight;
// Add tree (natural)
final Location treeLoc = new Location(world, x, y + 5D, z);
Location treeLoc = new Location(world, x, y + 5D, z);
world.generateTree(treeLoc, TreeType.TREE);
// Place the cow
//final Location location = new Location(world, x, (islandHeight + 5), z - 2);
//Location location = new Location(world, x, (islandHeight + 5), z - 2);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
@ -309,17 +314,20 @@ public class IslandBuilder {
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
World world = island.getCenter().getWorld();
int y = 0;
// 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++) {
final Block blockToChange = world.getBlockAt(x_space, y, z_space);
blockToChange.setType(Material.NETHER_BRICK);
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);
@ -368,10 +376,10 @@ public class IslandBuilder {
// Add island items
y = islandHeight;
// Add tree (natural)
final Location treeLoc = new Location(world, x, y + 5D, z);
Location treeLoc = new Location(world, x, y + 5D, z);
world.generateTree(treeLoc, TreeType.TREE);
// Place the cow
//final Location location = new Location(world, x, (islandHeight + 5), z - 2);
//Location location = new Location(world, x, (islandHeight + 5), z - 2);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
@ -387,17 +395,21 @@ public class IslandBuilder {
int z = island.getCenter().getBlockZ();
int islandHeight = island.getCenter().getBlockY();
World world = island.getCenter().getWorld();
int y = 0;
// 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++) {
final Block blockToChange = world.getBlockAt(x_space, y, z_space);
blockToChange.setType(Material.END_BRICKS);
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);
@ -446,11 +458,11 @@ public class IslandBuilder {
// Add island items
y = islandHeight;
// Add tree (natural)
final Location treeLoc = new Location(world, x, y + 5D, z);
Location treeLoc = new Location(world, x, y + 5D, z);
world.spawnEntity(treeLoc, EntityType.ENDER_CRYSTAL);
//world.generateTree(treeLoc, TreeType.TREE);
// Place the cow
//final Location location = new Location(world, x, (islandHeight + 5), z - 2);
//Location location = new Location(world, x, (islandHeight + 5), z - 2);
// Place a helpful sign in front of player
placeSign(x, islandHeight + 5, z + 3);
@ -474,20 +486,17 @@ public class IslandBuilder {
}
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);
// Only set if the config has items in it
BlockState state = blockToChange.getState();
Chest chest = new Chest(BlockFace.SOUTH);
state.setData(chest);
if (defaultChestItems.length > 0) {
final Chest chest = (Chest) blockToChange.getState();
final Inventory inventory = chest.getInventory();
inventory.clear();
inventory.setContents(defaultChestItems);
chest.update();
InventoryHolder ih = (InventoryHolder) state;
ih.getInventory().setContents(defaultChestItems);
}
// Fill the chest and orient it correctly (1.8 faces it north!
DirectionalContainer dc = (DirectionalContainer) blockToChange.getState().getData();
dc.setFacingDirection(BlockFace.SOUTH);
//blockToChange.setData(dc.getData(), true);
state.update();
}
}

View File

@ -19,8 +19,8 @@ import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.schematics.Schematic;
import us.tastybento.bskyblock.schematics.Schematic.PasteReason;
import us.tastybento.bskyblock.island.builders.IslandBuilder;
import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
import us.tastybento.bskyblock.util.SafeSpotTeleport;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
@ -220,18 +220,12 @@ public class NetherPortals implements Listener {
if (plugin.getIslands().bigScan(netherIsland, 20) == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: big scan is null");
plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic");
Schematic nether = plugin.getSchematics().getSchematic("nether");
if (nether != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector());
nether.pasteSchematic(netherIsland, event.getPlayer(), false, PasteReason.PARTNER, island);
} else {
plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic");
event.setCancelled(true);
Util.sendMessage(event.getPlayer(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe"));
return;
}
plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName());
new IslandBuilder(island)
.setPlayer(event.getPlayer())
.setDefaultChestItems(Settings.chestItems)
.setType(IslandType.NETHER)
.build();
}
}
if (DEBUG)

View File

@ -1,139 +0,0 @@
package us.tastybento.bskyblock.schematics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.DyeColor;
import org.bukkit.block.Banner;
import org.bukkit.block.Block;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import us.tastybento.org.jnbt.CompoundTag;
import us.tastybento.org.jnbt.IntTag;
import us.tastybento.org.jnbt.ListTag;
import us.tastybento.org.jnbt.StringTag;
import us.tastybento.org.jnbt.Tag;
/**
* This class describes banners and is used in schematic importing
*
* @author tastybento
*
*/
public class BannerBlock {
private DyeColor bannerBaseColor;
private List<Pattern> bannerPattern;
private static HashMap<String, PatternType> patternKey;
// bs, mc, cr, drs, dls, hhb, mr, hh, sc, gru, ss, gra, ts, ms, tt
// bts, tr, tts, sku, cre, tl, vhr, vh, bo, cbo, bri
// ss, tt
static {
patternKey = new HashMap<>();
patternKey.put("", PatternType.BASE);
patternKey.put("bo", PatternType.BORDER);
patternKey.put("bri", PatternType.BRICKS);
patternKey.put("mc", PatternType.CIRCLE_MIDDLE);
patternKey.put("cre", PatternType.CREEPER);
patternKey.put("cr", PatternType.CROSS);
patternKey.put("cbo", PatternType.CURLY_BORDER);
patternKey.put("ld", PatternType.DIAGONAL_LEFT);
patternKey.put("lud", PatternType.DIAGONAL_LEFT_MIRROR);
patternKey.put("rd", PatternType.DIAGONAL_RIGHT);
patternKey.put("rud", PatternType.DIAGONAL_RIGHT_MIRROR);
patternKey.put("flo", PatternType.FLOWER);
patternKey.put("gra", PatternType.GRADIENT);
patternKey.put("gru", PatternType.GRADIENT_UP);
patternKey.put("hh", PatternType.HALF_HORIZONTAL);
patternKey.put("hhb", PatternType.HALF_HORIZONTAL_MIRROR);
patternKey.put("vh", PatternType.HALF_VERTICAL);
patternKey.put("vhr", PatternType.HALF_VERTICAL_MIRROR);
patternKey.put("moj", PatternType.MOJANG);
patternKey.put("mr", PatternType.RHOMBUS_MIDDLE);
patternKey.put("sku", PatternType.SKULL);
patternKey.put("bl", PatternType.SQUARE_BOTTOM_LEFT);
patternKey.put("br", PatternType.SQUARE_BOTTOM_RIGHT);
patternKey.put("tl", PatternType.SQUARE_TOP_LEFT);
patternKey.put("tr", PatternType.SQUARE_TOP_RIGHT);
patternKey.put("sc", PatternType.STRAIGHT_CROSS);
patternKey.put("bs", PatternType.STRIPE_BOTTOM);
patternKey.put("ms", PatternType.STRIPE_CENTER);
patternKey.put("dls", PatternType.STRIPE_DOWNLEFT);
patternKey.put("drs", PatternType.STRIPE_DOWNRIGHT);
patternKey.put("ls", PatternType.STRIPE_LEFT);
patternKey.put("ms", PatternType.STRIPE_MIDDLE);
patternKey.put("rs", PatternType.STRIPE_RIGHT);
patternKey.put("ss", PatternType.STRIPE_SMALL);
patternKey.put("ts", PatternType.STRIPE_TOP);
patternKey.put("bt", PatternType.TRIANGLE_BOTTOM);
patternKey.put("tt", PatternType.TRIANGLE_TOP);
patternKey.put("bts", PatternType.TRIANGLES_BOTTOM);
patternKey.put("tts", PatternType.TRIANGLES_TOP);
}
public boolean set(Block block) {
Banner banner = (Banner) block.getState();
banner.setBaseColor(bannerBaseColor);
banner.setPatterns(bannerPattern);
banner.update();
return true;
}
@SuppressWarnings("deprecation")
public boolean prep(Map<String, Tag> tileData) {
// Format for banner is:
// Patterns = List of patterns
// id = String "BannerBlock"
// Base = Int color
// Then the location
// z = Int
// y = Int
// x = Int
try {
// Do the base color
int baseColor = 15 - ((IntTag) tileData.get("Base")).getValue();
// //ASkyBlock.getPlugin().getLogger().info("Base value = " +
// baseColor);
// baseColor green = 10
bannerBaseColor = DyeColor.getByDyeData((byte) baseColor);
// Do the patterns (no idea if this will work or not)
bannerPattern = new ArrayList<>();
ListTag patterns = (ListTag) tileData.get("Patterns");
if (patterns != null) {
for (Tag pattern : patterns.getValue()) {
// ASkyBlock.getPlugin().getLogger().info("pattern = " +
// pattern);
// Translate pattern to PatternType
if (pattern instanceof CompoundTag) {
CompoundTag patternColor = (CompoundTag) pattern;
// The tag is made up of pattern (String) and color
// (int)
Map<String, Tag> patternValue = patternColor.getValue();
StringTag mark = (StringTag) patternValue.get("Pattern");
Integer markColor = 15 - ((IntTag) patternValue.get("Color")).getValue();
// ASkyBlock.getPlugin().getLogger().info("mark = " +
// mark.getValue());
// ASkyBlock.getPlugin().getLogger().info("color = " +
// markColor);
DyeColor dColor = DyeColor.getByDyeData(markColor.byteValue());
// ASkyBlock.getPlugin().getLogger().info(" dye color = "
// + dColor.toString());
if (patternKey.containsKey(mark.getValue())) {
Pattern newPattern = new Pattern(dColor, patternKey.get(mark.getValue()));
bannerPattern.add(newPattern);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}

View File

@ -1,347 +0,0 @@
package us.tastybento.bskyblock.schematics;
import org.bukkit.entity.EntityType;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
public class EntityObject {
private EntityType type;
private BlockVector location;
private byte color;
private float yaw;
private float pitch;
private boolean sheared;
private Vector motion;
private int age;
private int rabbitType;
private int catType;
private boolean sitting;
private int profession;
private boolean carryingChest;
private boolean owned;
private byte collarColor;
// Paintings
private byte facing;
private String motive;
// Item Frames
private float itemDropChance;
private byte itemRotation;
// Coordinates for tiles
private Double tileX = null;
private Double tileY = null;
private Double tileZ = null;
// Items informations
private Byte count = null;
private Short damage = null;
private String id = null;
/**
* @return the type
*/
public EntityType getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(EntityType type) {
this.type = type;
}
/**
* @return the location
*/
public BlockVector getLocation() {
return location;
}
/**
* @param location the location to set
*/
public void setLocation(BlockVector location) {
this.location = location;
}
/**
* @return the color
*/
public byte getColor() {
return color;
}
/**
* @param color the color to set
*/
public void setColor(byte color) {
this.color = color;
}
/**
* @return the yaw
*/
public float getYaw() {
return yaw;
}
/**
* @param yaw the yaw to set
*/
public void setYaw(float yaw) {
this.yaw = yaw;
}
/**
* @return the pitch
*/
public float getPitch() {
return pitch;
}
/**
* @param pitch
*/
public void setPitch(float pitch) {
this.pitch = pitch;
}
/**
* @return the sheared
*/
public boolean isSheared() {
return sheared;
}
/**
* @param sheared the sheared to set
*/
public void setSheared(boolean sheared) {
this.sheared = sheared;
}
/**
* @return the motion
*/
public Vector getMotion() {
return motion;
}
/**
* @param motion the motion to set
*/
public void setMotion(Vector motion) {
this.motion = motion;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the profession
*/
public int getProfession() {
return profession;
}
/**
* @param profession the profession to set
*/
public void setProfession(int profession) {
this.profession = profession;
}
/**
* @return the rabbitType
*/
public int getRabbitType() {
return rabbitType;
}
/**
* @param rabbitType the rabbitType to set
*/
public void setRabbitType(int rabbitType) {
this.rabbitType = rabbitType;
}
/**
* @return the carryingChest
*/
public boolean isCarryingChest() {
return carryingChest;
}
/**
* @param carryingChest the carryingChest to set
*/
public void setCarryingChest(byte carryingChest) {
if (carryingChest > (byte)0) {
this.carryingChest = true;
}
this.carryingChest = false;
}
/**
* @return the catType
*/
public int getCatType() {
return catType;
}
/**
* @param catType the catType to set
*/
public void setCatType(int catType) {
this.catType = catType;
}
/**
* @return the sitting
*/
public boolean isSitting() {
return sitting;
}
/**
* @param sitting the sitting to set
*/
public void setSitting(byte sitting) {
if (sitting > (byte)0) {
this.sitting = true;
}
this.sitting = false;
}
/**
* @return the owned
*/
public boolean isOwned() {
return owned;
}
/**
* @param owned the owned to set
*/
public void setOwned(boolean owned) {
this.owned = owned;
}
/**
* @return the collarColor
*/
public byte getCollarColor() {
return collarColor;
}
/**
* @param collarColor the collarColor to set
*/
public void setCollarColor(byte collarColor) {
this.collarColor = collarColor;
}
/**
* @return the facing
*/
public byte getFacing() {
return facing;
}
/**
* @param facing the facing to set
*/
public void setFacing(byte facing) {
this.facing = facing;
}
/**
* @return the motive
*/
public String getMotive() {
return motive;
}
/**
* @param motive the motive to set
*/
public void setMotive(String motive) {
this.motive = motive;
}
/**
* @return the itemDropChance
*/
public float getItemDropChance() {
return itemDropChance;
}
/**
* @param itemDropChance the itemDropChance to set
*/
public void setItemDropChance(float itemDropChance) {
this.itemDropChance = itemDropChance;
}
/**
* @return the itemRotation
*/
public byte getItemRotation() {
return itemRotation;
}
/**
* @param itemRotation the itemRotation to set
*/
public void setItemRotation(byte itemRotation) {
this.itemRotation = itemRotation;
}
/**
* @return the tileX
*/
public Double getTileX() {
return tileX;
}
/**
* @param tileX the tileX to set
*/
public void setTileX(Double tileX) {
this.tileX = tileX;
}
/**
* @return the tileX
*/
public Double getTileY() {
return tileY;
}
/**
* @param tileY the tileY to set
*/
public void setTileY(Double tileY) {
this.tileY = tileY;
}
/**
* @return the tileX
*/
public Double getTileZ() {
return tileZ;
}
/**
* @param tileZ the tileZ to set
*/
public void setTileZ(Double tileZ) {
this.tileZ = tileZ;
}
/**
* @return the count
*/
public Byte getCount() {
return count;
}
/**
* @param count the count to set
*/
public void setCount(Byte count) {
this.count = count;
}
/**
* @return the damage
*/
public Short getDamage() {
return damage;
}
/**
* @param damage the damage to set
*/
public void setDamage(Short damage) {
this.damage = damage;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
}

View File

@ -1,563 +0,0 @@
package us.tastybento.bskyblock.schematics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
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.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.json.simple.JSONValue;
import org.json.simple.parser.ContainerFactory;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
import us.tastybento.org.jnbt.CompoundTag;
import us.tastybento.org.jnbt.ListTag;
import us.tastybento.org.jnbt.StringTag;
import us.tastybento.org.jnbt.Tag;
public class IslandBlock {
private short typeId;
private byte data;
private int x;
private int y;
private int z;
private List<String> signText;
private BannerBlock banner;
private EntityType spawnerBlockType;
// Chest contents
private HashMap<Byte,ItemStack> chestContents = new HashMap<>();
public static final HashMap<String, Material> WEtoM = new HashMap<>();
public static final HashMap<String, EntityType> WEtoME = new HashMap<>();
static {
// Establish the World Edit to Material look up
// V1.8 items
if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
WEtoM.put("ARMORSTAND",Material.ARMOR_STAND);
WEtoM.put("ACACIA_DOOR",Material.ACACIA_DOOR_ITEM);
WEtoM.put("BIRCH_DOOR",Material.BIRCH_DOOR_ITEM);
WEtoM.put("BIRCH_STAIRS",Material.BIRCH_WOOD_STAIRS);
WEtoM.put("DARK_OAK_DOOR",Material.DARK_OAK_DOOR_ITEM);
WEtoM.put("JUNGLE_DOOR",Material.JUNGLE_DOOR_ITEM);
WEtoM.put("SLIME",Material.SLIME_BLOCK);
WEtoM.put("SPRUCE_DOOR",Material.SPRUCE_DOOR_ITEM);
}
WEtoM.put("BREWING_STAND",Material.BREWING_STAND_ITEM);
WEtoM.put("CARROT_ON_A_STICK",Material.CARROT_STICK);
WEtoM.put("CARROT",Material.CARROT_ITEM);
WEtoM.put("CAULDRON", Material.CAULDRON_ITEM);
WEtoM.put("CLOCK", Material.WATCH);
WEtoM.put("COBBLESTONE_WALL",Material.COBBLE_WALL);
WEtoM.put("COMMAND_BLOCK",Material.COMMAND);
WEtoM.put("COMMANDBLOCK_MINECART",Material.COMMAND_MINECART);
WEtoM.put("COMPARATOR",Material.REDSTONE_COMPARATOR);
WEtoM.put("COOKED_PORKCHOP", Material.GRILLED_PORK);
WEtoM.put("CLOCK", Material.WATCH);
WEtoM.put("CRAFTING_TABLE", Material.WORKBENCH);
WEtoM.put("DIAMOND_HORSE_ARMOR",Material.DIAMOND_BARDING);
WEtoM.put("DIAMOND_SHOVEL",Material.DIAMOND_SPADE);
WEtoM.put("DYE",Material.INK_SACK);
WEtoM.put("ENCHANTING_TABLE", Material.ENCHANTMENT_TABLE); //1.11 rename
WEtoM.put("END_PORTAL_FRAME",Material.ENDER_PORTAL_FRAME);
WEtoM.put("END_PORTAL", Material.ENDER_PORTAL); // 1.11 rename
WEtoM.put("END_STONE", Material.ENDER_STONE);
WEtoM.put("EXPERIENCE_BOTTLE",Material.EXP_BOTTLE);
WEtoM.put("FILLED_MAP",Material.MAP);
WEtoM.put("FIRE_CHARGE",Material.FIREBALL);
WEtoM.put("FIREWORKS",Material.FIREWORK);
WEtoM.put("FLOWER_POT", Material.FLOWER_POT_ITEM);
WEtoM.put("GLASS_PANE",Material.THIN_GLASS);
WEtoM.put("GOLDEN_CHESTPLATE",Material.GOLD_CHESTPLATE);
WEtoM.put("GOLDEN_HORSE_ARMOR",Material.GOLD_BARDING);
WEtoM.put("GOLDEN_LEGGINGS",Material.GOLD_LEGGINGS);
WEtoM.put("GOLDEN_PICKAXE",Material.GOLD_PICKAXE);
WEtoM.put("GOLDEN_RAIL",Material.POWERED_RAIL);
WEtoM.put("GOLDEN_SHOVEL",Material.GOLD_SPADE);
WEtoM.put("GOLDEN_SWORD", Material.GOLD_SWORD);
WEtoM.put("GOLDEN_HELMET", Material.GOLD_HELMET);
WEtoM.put("GOLDEN_HOE", Material.GOLD_HOE);
WEtoM.put("GOLDEN_AXE", Material.GOLD_AXE);
WEtoM.put("GOLDEN_BOOTS", Material.GOLD_BOOTS);
WEtoM.put("GUNPOWDER", Material.SULPHUR);
WEtoM.put("HARDENED_CLAY",Material.HARD_CLAY);
WEtoM.put("HEAVY_WEIGHTED_PRESSURE_PLATE",Material.GOLD_PLATE);
WEtoM.put("IRON_BARS",Material.IRON_FENCE);
WEtoM.put("IRON_HORSE_ARMOR",Material.IRON_BARDING);
WEtoM.put("IRON_SHOVEL",Material.IRON_SPADE);
WEtoM.put("LEAD",Material.LEASH);
WEtoM.put("LEAVES2",Material.LEAVES_2);
WEtoM.put("LIGHT_WEIGHTED_PRESSURE_PLATE",Material.IRON_PLATE);
WEtoM.put("LOG2",Material.LOG_2);
WEtoM.put("MAP",Material.EMPTY_MAP);
WEtoM.put("MYCELIUM", Material.MYCEL);
WEtoM.put("NETHER_BRICK_FENCE",Material.NETHER_FENCE);
WEtoM.put("NETHER_WART",Material.NETHER_STALK);
WEtoM.put("NETHERBRICK",Material.NETHER_BRICK_ITEM);
WEtoM.put("OAK_STAIRS",Material.WOOD_STAIRS);
WEtoM.put("POTATO", Material.POTATO_ITEM);
WEtoM.put("RAIL",Material.RAILS);
WEtoM.put("RECORD_11",Material.RECORD_11);
WEtoM.put("RECORD_13",Material.GOLD_RECORD);
WEtoM.put("RECORD_BLOCKS",Material.RECORD_3);
WEtoM.put("RECORD_CAT",Material.GREEN_RECORD);
WEtoM.put("RECORD_CHIRP",Material.RECORD_4);
WEtoM.put("RECORD_FAR",Material.RECORD_5);
WEtoM.put("RECORD_MALL",Material.RECORD_6);
WEtoM.put("RECORD_MELLOHI",Material.RECORD_7);
WEtoM.put("RECORD_STAL",Material.RECORD_8);
WEtoM.put("RECORD_STRAD",Material.RECORD_9);
WEtoM.put("RECORD_WAIT",Material.RECORD_12);
WEtoM.put("RECORD_WARD",Material.RECORD_10);
WEtoM.put("RED_FLOWER",Material.RED_ROSE);
WEtoM.put("REEDS",Material.SUGAR_CANE);
WEtoM.put("REPEATER",Material.DIODE);
WEtoM.put("SKULL", Material.SKULL_ITEM);
WEtoM.put("SPAWN_EGG",Material.MONSTER_EGG);
WEtoM.put("STONE_BRICK_STAIRS",Material.BRICK_STAIRS);
WEtoM.put("STONE_BRICK_STAIRS",Material.SMOOTH_STAIRS);
WEtoM.put("STONE_SHOVEL",Material.STONE_SPADE);
WEtoM.put("STONE_SLAB",Material.STEP);
WEtoM.put("STONE_STAIRS",Material.COBBLESTONE_STAIRS);
WEtoM.put("TNT_MINECART",Material.EXPLOSIVE_MINECART);
WEtoM.put("WATERLILY",Material.WATER_LILY);
WEtoM.put("WHEAT_SEEDS", Material.SEEDS);
WEtoM.put("WOODEN_AXE",Material.WOOD_AXE);
WEtoM.put("WOODEN_BUTTON",Material.WOOD_BUTTON);
WEtoM.put("WOODEN_DOOR",Material.WOOD_DOOR);
WEtoM.put("WOODEN_HOE",Material.WOOD_HOE);
WEtoM.put("WOODEN_PICKAXE",Material.WOOD_PICKAXE);
WEtoM.put("WOODEN_PRESSURE_PLATE",Material.WOOD_PLATE);
WEtoM.put("WOODEN_SHOVEL",Material.WOOD_SPADE);
WEtoM.put("WOODEN_SLAB",Material.WOOD_STEP);
WEtoM.put("WOODEN_SWORD",Material.WOOD_SWORD);
WEtoM.put("MUSHROOM_STEW",Material.MUSHROOM_SOUP);
// Entities
WEtoME.put("LAVASLIME", EntityType.MAGMA_CUBE);
WEtoME.put("ENTITYHORSE", EntityType.HORSE);
WEtoME.put("OZELOT", EntityType.OCELOT);
WEtoME.put("MUSHROOMCOW", EntityType.MUSHROOM_COW);
WEtoME.put("MOOSHROOM", EntityType.MUSHROOM_COW); // 1.11 rename
WEtoME.put("PIGZOMBIE", EntityType.PIG_ZOMBIE);
WEtoME.put("ZOMBIE_PIGMAN", EntityType.PIG_ZOMBIE); // 1.11 rename
WEtoME.put("CAVESPIDER", EntityType.CAVE_SPIDER);
WEtoME.put("XPORB", EntityType.EXPERIENCE_ORB);
WEtoME.put("XP_ORB", EntityType.EXPERIENCE_ORB); // 1.11 rename
WEtoME.put("MINECARTRIDEABLE", EntityType.MINECART);
WEtoME.put("MINECARTHOPPER", EntityType.MINECART_HOPPER);
WEtoME.put("HOPPER_MINECART", EntityType.MINECART_HOPPER);
WEtoME.put("MINECARTFURNACE", EntityType.MINECART_FURNACE);
WEtoME.put("FURNACE_MINECART", EntityType.MINECART_FURNACE);
WEtoME.put("MINECARTMOBSPAWNER", EntityType.MINECART_MOB_SPAWNER);
WEtoME.put("SPAWNER_MINECART", EntityType.MINECART_MOB_SPAWNER); // 1.11 rename
WEtoME.put("MINECARTTNT", EntityType.MINECART_TNT);
WEtoME.put("TNT_MINECART", EntityType.MINECART_TNT); // 1.11
WEtoME.put("LEASH_KNOT",EntityType.LEASH_HITCH); // 1.11
WEtoME.put("MINECARTCHEST", EntityType.MINECART_CHEST);
WEtoME.put("CHEST_MINECART", EntityType.MINECART_CHEST); //1.11 rename
WEtoME.put("VILLAGERGOLEM", EntityType.IRON_GOLEM);
WEtoME.put("ENDERDRAGON", EntityType.ENDER_DRAGON);
WEtoME.put("PAINTING", EntityType.PAINTING);
WEtoME.put("ITEMFRAME", EntityType.ITEM_FRAME);
if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
WEtoME.put("ENDERCRYSTAL", EntityType.ENDER_CRYSTAL);
WEtoME.put("ARMORSTAND", EntityType.ARMOR_STAND);
}
// 1.10 entities and materials
if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && !Bukkit.getServer().getVersion().contains("(MC: 1.8") && !Bukkit.getServer().getVersion().contains("(MC: 1.9")) {
WEtoME.put("POLARBEAR", EntityType.POLAR_BEAR);
WEtoM.put("ENDER_CRYSTAL", Material.END_CRYSTAL); // 1.11
}
}
/**
* @param x
* @param y
* @param z
*/
public IslandBlock(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
signText = null;
banner = null;
spawnerBlockType = null;
chestContents = new HashMap<>();
}
/**
* @return the type
*/
public int getTypeId() {
return typeId;
}
/**
* @param type the type to set
*/
public void setTypeId(short type) {
this.typeId = type;
}
/**
* @return the data
*/
public int getData() {
return data;
}
/**
* @param data the data to set
*/
public void setData(byte data) {
this.data = data;
}
/**
* @return the signText
*/
public List<String> getSignText() {
return signText;
}
/**
* @param signText the signText to set
*/
public void setSignText(List<String> signText) {
this.signText = signText;
}
/**
* @param s
* @param b
*/
public void setBlock(int s, byte b) {
this.typeId = (short)s;
this.data = b;
}
/**
* Sets this block up with all the banner data required
* @param map
*/
public void setBanner(Map<String, Tag> map) {
banner = new BannerBlock();
banner.prep(map);
}
/**
* Sets the spawner type if this block is a spawner
* @param tileData
*/
public void setSpawnerType(Map<String, Tag> tileData) {
//Bukkit.getLogger().info("DEBUG: " + tileData.toString());
String creatureType = "";
if (tileData.containsKey("EntityId")) {
creatureType = ((StringTag) tileData.get("EntityId")).getValue().toUpperCase();
} else if (tileData.containsKey("SpawnData")) {
// 1.9 format
Map<String,Tag> spawnData = ((CompoundTag) tileData.get("SpawnData")).getValue();
//Bukkit.getLogger().info("DEBUG: " + spawnData.toString());
if (spawnData.containsKey("id")) {
creatureType = ((StringTag) spawnData.get("id")).getValue().toUpperCase();
}
}
//Bukkit.getLogger().info("DEBUG: creature type = " + creatureType);
// The mob type might be prefixed with "Minecraft:"
if (creatureType.startsWith("MINECRAFT:")) {
creatureType = creatureType.substring(10);
}
if (WEtoME.containsKey(creatureType)) {
spawnerBlockType = WEtoME.get(creatureType);
} else {
try {
spawnerBlockType = EntityType.valueOf(creatureType);
} catch (Exception e) {
Bukkit.getLogger().warning("Spawner setting of " + creatureType + " is unknown for this server. Skipping.");
}
}
//Bukkit.getLogger().info("DEBUG: spawnerblock type = " + spawnerBlockType);
}
/**
* Sets this block's sign data
* @param tileData
*/
public void setSign(Map<String, Tag> tileData) {
signText = new ArrayList<>();
List<String> text = new ArrayList<>();
for (int i = 1; i < 5; i++) {
String line = ((StringTag) tileData.get("Text" + String.valueOf(i))).getValue();
// This value can actually be a string that says null sometimes.
if (line.equalsIgnoreCase("null")) {
line = "";
}
//System.out.println("DEBUG: line " + i + " = '"+ line + "' of length " + line.length());
text.add(line);
}
JSONParser parser = new JSONParser();
ContainerFactory containerFactory = new ContainerFactory(){
public List creatArrayContainer() {
return new LinkedList();
}
public Map createObjectContainer() {
return new LinkedHashMap();
}
};
// This just removes all the JSON formatting and provides the raw text
for (int line = 0; line < 4; line++) {
String lineText = "";
if (!text.get(line).equals("\"\"") && !text.get(line).isEmpty()) {
//String lineText = text.get(line).replace("{\"extra\":[\"", "").replace("\"],\"text\":\"\"}", "");
//Bukkit.getLogger().info("DEBUG: sign text = '" + text.get(line) + "'");
if (text.get(line).startsWith("{")) {
// JSON string
try {
Map json = (Map)parser.parse(text.get(line), containerFactory);
List list = (List) json.get("extra");
//System.out.println("DEBUG1:" + JSONValue.toJSONString(list));
if (list != null) {
Iterator iter = list.iterator();
while(iter.hasNext()){
Object next = iter.next();
String format = JSONValue.toJSONString(next);
//System.out.println("DEBUG2:" + format);
// This doesn't see right, but appears to be the easiest way to identify this string as JSON...
if (format.startsWith("{")) {
// JSON string
Map jsonFormat = (Map)parser.parse(format, containerFactory);
Iterator formatIter = jsonFormat.entrySet().iterator();
while (formatIter.hasNext()) {
Map.Entry entry = (Map.Entry)formatIter.next();
//System.out.println("DEBUG3:" + entry.getKey() + "=>" + entry.getValue());
String key = entry.getKey().toString();
String value = entry.getValue().toString();
if (key.equalsIgnoreCase("color")) {
try {
lineText += ChatColor.valueOf(value.toUpperCase());
} catch (Exception noColor) {
Bukkit.getLogger().warning("Unknown color " + value +" in sign when pasting schematic, skipping...");
}
} else if (key.equalsIgnoreCase("text")) {
lineText += value;
} else {
// Formatting - usually the value is always true, but check just in case
if (key.equalsIgnoreCase("obfuscated") && value.equalsIgnoreCase("true")) {
lineText += ChatColor.MAGIC;
} else if (key.equalsIgnoreCase("underlined") && value.equalsIgnoreCase("true")) {
lineText += ChatColor.UNDERLINE;
} else {
// The rest of the formats
try {
lineText += ChatColor.valueOf(key.toUpperCase());
} catch (Exception noFormat) {
// Ignore
//System.out.println("DEBUG3:" + key + "=>" + value);
Bukkit.getLogger().warning("Unknown format " + value +" in sign when pasting schematic, skipping...");
}
}
}
}
} else {
// This is unformatted text. It is included in "". A reset is required to clear
// any previous formatting
if (format.length()>1) {
lineText += ChatColor.RESET + format.substring(format.indexOf('"')+1,format.lastIndexOf('"'));
}
}
}
} else {
// No extra tag
json = (Map)parser.parse(text.get(line), containerFactory);
String value = (String) json.get("text");
//System.out.println("DEBUG text only?:" + value);
lineText += value;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// This is unformatted text (not JSON). It is included in "".
if (text.get(line).length() > 1) {
try {
lineText = text.get(line).substring(text.get(line).indexOf('"')+1,text.get(line).lastIndexOf('"'));
} catch (Exception e) {
//There may not be those "'s, so just use the raw line
lineText = text.get(line);
}
} else {
// just in case it isn't - show the raw line
lineText = text.get(line);
}
}
//Bukkit.getLogger().info("Line " + line + " is " + lineText);
}
signText.add(lineText);
}
}
public void setBook(Map<String, Tag> tileData) {
//Bukkit.getLogger().info("DEBUG: Book data ");
Bukkit.getLogger().info(tileData.toString());
}
@SuppressWarnings("deprecation")
public void setChest(NMSAbstraction nms, Map<String, Tag> tileData) {
try {
ListTag chestItems = (ListTag) tileData.get("Items");
if (chestItems != null) {
//int number = 0;
for (Tag item : chestItems.getValue()) {
// Format for chest items is:
// id = short value of item id
// Damage = short value of item damage
// Count = the number of items
// Slot = the slot in the chest
// inventory
if (item instanceof CompoundTag) {
try {
// Id is a number
short itemType = (Short) ((CompoundTag) item).getValue().get("id").getValue();
short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue();
byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue();
byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue();
ItemStack chestItem = new ItemStack(itemType, itemAmount, itemDamage);
chestContents.put(itemSlot, chestItem);
} catch (ClassCastException ex) {
// Id is a material
String itemType = (String) ((CompoundTag) item).getValue().get("id").getValue();
try {
// Get the material
if (itemType.startsWith("minecraft:")) {
String material = itemType.substring(10).toUpperCase();
// Special case for non-standard material names
Material itemMaterial;
//Bukkit.getLogger().info("DEBUG: " + material);
if (WEtoM.containsKey(material)) {
//Bukkit.getLogger().info("DEBUG: Found in hashmap");
itemMaterial = WEtoM.get(material);
} else {
//Bukkit.getLogger().info("DEBUG: Not in hashmap");
itemMaterial = Material.valueOf(material);
}
short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue();
byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue();
byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue();
ItemStack chestItem = new ItemStack(itemMaterial, itemAmount, itemDamage);
if (itemMaterial.equals(Material.WRITTEN_BOOK)) {
chestItem = nms.setBook(item);
}
// Check for potions
if (itemMaterial.toString().contains("POTION")) {
chestItem = nms.setPotion(itemMaterial, item, chestItem);
}
chestContents.put(itemSlot, chestItem);
}
} catch (Exception exx) {
// Bukkit.getLogger().info(item.toString());
// Bukkit.getLogger().info(((CompoundTag)item).getValue().get("id").getName());
Bukkit.getLogger().severe(
"Could not parse item [" + itemType.substring(10).toUpperCase() + "] in schematic - skipping!");
// Bukkit.getLogger().severe(item.toString());
exx.printStackTrace();
}
}
// Bukkit.getLogger().info("Set chest inventory slot "
// + itemSlot + " to " +
// chestItem.toString());
}
}
//Bukkit.getLogger().info("Added " + number + " items to chest");
}
} catch (Exception e) {
Bukkit.getLogger().severe("Could not parse schematic file item, skipping!");
// e.printStackTrace();
}
}
/**
* Paste this block at blockLoc
* @param nms
* @param blockLoc
*/
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
// Only paste air if it is below the sea level and in the overworld
Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
block.setBiome(biome);
block.getChunk().load();
nms.setBlockSuperFast(block, typeId, data, usePhysics);
if (signText != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Sign
Sign sign = (Sign) block.getState();
int index = 0;
for (String line : signText) {
sign.setLine(index++, line);
}
sign.update();
} else if (banner != null) {
banner.set(block);
} else if (spawnerBlockType != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
CreatureSpawner cs = (CreatureSpawner)block.getState();
cs.setSpawnedType(spawnerBlockType);
} else if (!chestContents.isEmpty()) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Check if this is a double chest
Chest chestBlock = (Chest) block.getState();
InventoryHolder iH = chestBlock.getInventory().getHolder();
if (iH instanceof DoubleChest) {
//Bukkit.getLogger().info("DEBUG: double chest");
DoubleChest doubleChest = (DoubleChest) iH;
for (ItemStack chestItem: chestContents.values()) {
doubleChest.getInventory().addItem(chestItem);
}
} else {
// Single chest
for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
chestBlock.getInventory().setItem(en.getKey(), en.getValue());
}
}
}
}
/**
* @return Vector for where this block is in the schematic
*/
public Vector getVector() {
return new Vector(x,y,z);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +0,0 @@
package us.tastybento.bskyblock.schematics;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.VaultHelper;
public class SchematicsMgr {
private BSkyBlock plugin;
private static HashMap<String, Schematic> schematics = new HashMap<String, Schematic>();
/**
* Class to hold all schematics that are available
* @param plugin
*/
public SchematicsMgr(BSkyBlock plugin) {
this.plugin = plugin;
loadSchematics();
}
/**
* Loads schematics. If the default
* island is not included, it will be made
*/
public void loadSchematics() {
// Check if there is a schematic folder and make it if it does not exist
File schematicFolder = new File(plugin.getDataFolder(), "schematics");
if (!schematicFolder.exists()) {
schematicFolder.mkdir();
}
// Clear the schematic list that is kept in memory
schematics.clear();
// Load the default schematic if it exists
// Set up the default schematic
File schematicFile = new File(schematicFolder, "island.schematic");
File netherFile = new File(schematicFolder, "nether.schematic");
if (!schematicFile.exists()) {
//plugin.getLogger().info("Default schematic does not exist...");
// Only copy if the default exists
if (plugin.getResource("schematics/island.schematic") != null) {
plugin.getLogger().info("Default schematic does not exist, saving it...");
plugin.saveResource("schematics/island.schematic", false);
// Add it to schematics
try {
schematics.put("default",new Schematic(plugin, schematicFile));
} catch (IOException e) {
plugin.getLogger().severe("Could not load default schematic!");
e.printStackTrace();
}
// If this is repeated later due to the schematic config, fine, it will only add info
} else {
// No islands.schematic in the jar, so just make the default using
// built-in island generation
schematics.put("default",new Schematic(plugin));
}
//plugin.getLogger().info("Loaded default nether schematic");
} else {
// It exists, so load it
try {
schematics.put("default",new Schematic(plugin, schematicFile));
//plugin.getLogger().info("Loaded default island schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default schematic!");
e.printStackTrace();
}
}
// Add the nether default too
if (!netherFile.exists()) {
if (plugin.getResource("schematics/nether.schematic") != null) {
plugin.saveResource("schematics/nether.schematic", false);
// Add it to schematics
try {
Schematic netherIsland = new Schematic(plugin, netherFile);
netherIsland.setVisible(false);
schematics.put("nether", netherIsland);
//plugin.getLogger().info("Loaded default nether schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default nether schematic!");
e.printStackTrace();
}
} else {
plugin.getLogger().severe("Could not find default nether schematic!");
}
} else {
// It exists, so load it
try {
Schematic netherIsland = new Schematic(plugin, netherFile);
netherIsland.setVisible(false);
schematics.put("nether", netherIsland);
//plugin.getLogger().info("Loaded default nether schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default nether schematic!");
e.printStackTrace();
}
}
// Set up some basic settings
if (schematics.containsKey("default")) {
schematics.get("default").setName("Island");
schematics.get("default").setDescription("");
schematics.get("default").setPartnerName("nether");
schematics.get("default").setBiome(Settings.defaultBiome);
schematics.get("default").setIcon(Material.GRASS);
if (Settings.chestItems.length == 0) {
schematics.get("default").setUseDefaultChest(false);
}
schematics.get("default").setOrder(0);
}
if (schematics.containsKey("nether")) {
schematics.get("nether").setName("NetherBlock Island");
schematics.get("nether").setDescription("Nether Island");
schematics.get("nether").setPartnerName("default");
schematics.get("nether").setBiome(Biome.HELL);
schematics.get("nether").setIcon(Material.NETHERRACK);
schematics.get("nether").setVisible(false);
schematics.get("nether").setPasteEntities(true);
if (Settings.chestItems.length == 0) {
schematics.get("nether").setUseDefaultChest(false);
}
}
// TODO: Load other settings from config.yml
}
/**
* Get schematic with name
* @param name
* @return schematic or null if it does not exist
*/
public Schematic getSchematic(String name) {
return schematics.get(name);
}
/**
* List schematics this player can access. If @param ignoreNoPermission is true, then only
* schematics with a specific permission set will be checked. I.e., no common schematics will
* be returned (including the default one).
* @param player
* @param ignoreNoPermission
* @return List of schematics this player can use based on their permission level
*/
public List<Schematic> getSchematics(Player player, boolean ignoreNoPermission) {
List<Schematic> result = new ArrayList<>();
// Find out what schematics this player can choose from
//Bukkit.getLogger().info("DEBUG: Checking schematics for " + player.getName());
for (Schematic schematic : schematics.values()) {
//Bukkit.getLogger().info("DEBUG: schematic name is '"+ schematic.getName() + "'");
//Bukkit.getLogger().info("DEBUG: perm is " + schematic.getPerm());
if ((!ignoreNoPermission && schematic.getPerm().isEmpty()) || VaultHelper.hasPerm(player, schematic.getPerm())) {
//Bukkit.getLogger().info("DEBUG: player can use this schematic");
// Only add if it's visible
if (schematic.isVisible()) {
// Check if it's a nether island, but the nether is not enables
if (schematic.getBiome().equals(Biome.HELL)) {
if (Settings.netherGenerate && IslandWorld.getNetherWorld() != null) {
result.add(schematic);
}
} else {
result.add(schematic);
}
}
}
}
// Sort according to order
Collections.sort(result, (s1, s2) -> (s2.getOrder() < s1.getOrder()) ? 1 : -1);
return result;
}
public HashMap<String, Schematic> getAll() {
return schematics;
}
}

View File

@ -1,7 +1,6 @@
package us.tastybento.bskyblock.util;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -31,7 +30,6 @@ import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
/**
@ -53,38 +51,6 @@ public class Util {
}
}
/**
* Checks what version the server is running and picks the appropriate NMS handler, or fallback
* @return NMSAbstraction class
* @throws ClassNotFoundException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
public static NMSAbstraction getNMSHandler() throws ClassNotFoundException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
String serverPackageName = plugin.getServer().getClass().getPackage().getName();
String pluginPackageName = plugin.getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
Class<?> clazz;
try {
clazz = Class.forName(pluginPackageName + ".util.nms." + version + ".NMSHandler");
} catch (Exception e) {
plugin.getLogger().info("No NMS Handler found for " + version + ", falling back to Bukkit API.");
clazz = Class.forName(pluginPackageName + ".util.nms.fallback.NMSHandler");
}
// Check if we have a NMSAbstraction implementing class at that location.
if (NMSAbstraction.class.isAssignableFrom(clazz)) {
return (NMSAbstraction) clazz.getConstructor().newInstance();
} else {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement NMSAbstraction");
}
}
/**
* Converts a serialized location to a Location. Returns null if string is
* empty

View File

@ -1,73 +0,0 @@
package us.tastybento.bskyblock.util.nms;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import us.tastybento.org.jnbt.Tag;
public interface NMSAbstraction {
/**
* Update the low-level chunk information for the given block to the new block ID and data. This
* change will not be propagated to clients until the chunk is refreshed to them.
* @param block
* @param blockId
* @param data
* @param applyPhysics
*/
public void setBlockSuperFast(Block block, int blockId, byte data, boolean applyPhysics);
public ItemStack setBook(Tag item);
/**
* Sets a block to be an item stack
* @param block
* @param itemStack
*/
public void setFlowerPotBlock(Block block, ItemStack itemStack);
boolean isPotion(ItemStack item);
/**
* Returns a potion ItemStack
* @param itemMaterial
* @param itemTag
* @param chestItem
* @return
*/
public ItemStack setPotion(Material itemMaterial, Tag itemTag, ItemStack chestItem);
/**
* Gets a monster egg itemstack
* @param type
* @param amount
* @return itemstack
*/
public ItemStack getSpawnEgg(EntityType type, int amount);
/**
* Send an action bar message to player
* @param player
* @param message
*/
public void sendActionBar(Player player, String message);
/**
* Send a title to a player
* @param player
* @param message
*/
public void sendTitle(Player player, String message);
/**
* Send a subtitle to a player
* @param player
* @param message
*/
public void sendSubtitle(Player player, String message);
}

View File

@ -1,142 +0,0 @@
package us.tastybento.bskyblock.util.nms.fallback;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
import us.tastybento.org.jnbt.CompoundTag;
import us.tastybento.org.jnbt.StringTag;
import us.tastybento.org.jnbt.Tag;
/**
* A fallback NMS Handler when the NMS version is not supported by BSkyBlock
*
* @author Tastybento
* @author Poslovitch
*/
public class NMSHandler implements NMSAbstraction{
@Override
public void sendActionBar(Player player, String message) {
// TODO Auto-generated method stub
}
@Override
public void sendTitle(Player player, String message) {
// TODO Auto-generated method stub
}
@Override
public void sendSubtitle(Player player, String message) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.wasteofplastic.askyblock.nms.NMSAbstraction#getSpawnEgg(org.bukkit.entity.EntityType, int)
*/
@Override
public ItemStack getSpawnEgg(EntityType type, int amount) {
ItemStack egg = new ItemStack(Material.MONSTER_EGG, amount);
SpawnEggMeta spm = (SpawnEggMeta)egg.getItemMeta();
spm.setSpawnedType(type);
egg.setItemMeta(spm);
return egg;
}
@Override
public boolean isPotion(ItemStack item) {
if (item.getType().equals(Material.POTION) && item.getDurability() != 0) {
return true;
}
return false;
}
/* (non-Javadoc)
* @see com.wasteofplastic.askyblock.nms.NMSAbstraction#setBlockSuperFast(org.bukkit.block.Block, org.bukkit.Material)
*/
@SuppressWarnings("deprecation")
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
b.setTypeIdAndData(blockId, data, applyPhysics);
}
@Override
public ItemStack setBook(Tag item) {
Bukkit.getLogger().warning("Written books in schematics not supported with this version of server");
return new ItemStack(Material.WRITTEN_BOOK);
}
@SuppressWarnings("deprecation")
@Override
public void setFlowerPotBlock(Block block, ItemStack itemStack) {
block.setTypeIdAndData(itemStack.getTypeId(), itemStack.getData().getData(), false);
}
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
ItemStack chestItem) {
// Try some backwards compatibility with new 1.9 schematics
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
StringTag stringTag = ((StringTag)contents.get("Potion"));
if (stringTag != null) {
String tag = stringTag.getValue().replace("minecraft:", "");
PotionType type = null;
boolean strong = tag.contains("strong");
boolean _long = tag.contains("long");
//Bukkit.getLogger().info("tag = " + tag);
if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
type = PotionType.FIRE_RESISTANCE;
}else if(tag.equals("harming") || tag.equals("strong_harming")){
type = PotionType.INSTANT_DAMAGE;
}else if(tag.equals("healing") || tag.equals("strong_healing")){
type = PotionType.INSTANT_HEAL;
}else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
type = PotionType.INVISIBILITY;
}else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
type = PotionType.JUMP;
}else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
type = PotionType.NIGHT_VISION;
}else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
type = PotionType.POISON;
}else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
type = PotionType.REGEN;
}else if(tag.equals("slowness") || tag.equals("long_slowness")){
type = PotionType.SLOWNESS;
}else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
type = PotionType.SPEED;
}else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
type = PotionType.STRENGTH;
}else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
type = PotionType.WATER_BREATHING;
}else if(tag.equals("water")){
type = PotionType.WATER;
}else if(tag.equals("weakness") || tag.equals("long_weakness")){
type = PotionType.WEAKNESS;
}else{
return chestItem;
}
chestItem = new ItemStack(Material.POTION, chestItem.getAmount());
PotionMeta pm = (PotionMeta)chestItem.getItemMeta();
PotionData pd = new PotionData(type, _long, strong);
pm.setBasePotionData(pd);
chestItem.setItemMeta(pm);
}
return chestItem;
}
}

View File

@ -1,228 +0,0 @@
package us.tastybento.bskyblock.util.nms.v1_12_R1;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.NBTTagList;
import net.minecraft.server.v1_12_R1.NBTTagString;
import net.minecraft.server.v1_12_R1.TileEntityFlowerPot;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
import us.tastybento.org.jnbt.CompoundTag;
import us.tastybento.org.jnbt.ListTag;
import us.tastybento.org.jnbt.StringTag;
import us.tastybento.org.jnbt.Tag;
/**
* NMS Handler for v1_12_R1
*
* @author Tastybento
* @author Poslovitch
*/
public class NMSHandler implements NMSAbstraction{
private static HashMap<EntityType, String> bToMConversion;
static {
bToMConversion = new HashMap<EntityType, String> ();
bToMConversion.put(EntityType.MUSHROOM_COW, "mooshroom");
bToMConversion.put(EntityType.PIG_ZOMBIE, "zombie_pigman");
}
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
net.minecraft.server.v1_12_R1.World w = ((CraftWorld) b.getWorld()).getHandle();
net.minecraft.server.v1_12_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
int combined = blockId + (data << 12);
IBlockData ibd = net.minecraft.server.v1_12_R1.Block.getByCombinedId(combined);
if (applyPhysics) {
w.setTypeAndData(bp, ibd, 3);
} else {
w.setTypeAndData(bp, ibd, 2);
}
chunk.a(bp, ibd);
}
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
//Bukkit.getLogger().info("item data");
//Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag)contents.get("author")).getValue();
}
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag)contents.get("title")).getValue();
}
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
}
tag.set("pages", pages); //Add the pages to the tag
}
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
/* (non-Javadoc)
* @see com.wasteofplastic.askyblock.nms.NMSAbstraction#setBlock(org.bukkit.block.Block, org.bukkit.inventory.ItemStack)
*/
@Override
public void setFlowerPotBlock(final Block block, final ItemStack itemStack) {
if (block.getType().equals(Material.FLOWER_POT)) {
Location loc = block.getLocation();
CraftWorld cw = (CraftWorld)block.getWorld();
BlockPosition bp = new BlockPosition(loc.getX(), loc.getY(), loc.getZ());
TileEntityFlowerPot te = (TileEntityFlowerPot)cw.getHandle().getTileEntity(bp);
//Bukkit.getLogger().info("Debug: flowerpot materialdata = " + (new ItemStack(potItem, 1,(short) potItemData).toString()));
net.minecraft.server.v1_12_R1.ItemStack cis = CraftItemStack.asNMSCopy(itemStack);
te.setContents(cis);
te.update();
}
}
/* (non-Javadoc)
* @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack)
*/
@Override
public boolean isPotion(ItemStack item) {
//Bukkit.getLogger().info("DEBUG:item = " + item);
if (item.getType().equals(Material.POTION)) {
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = stack.getTag();
//Bukkit.getLogger().info("DEBUG: tag is " + tag);
//Bukkit.getLogger().info("DEBUG: display is " + tag.getString("display"));
/*
for (String list : tag.c()) {
Bukkit.getLogger().info("DEBUG: list = " + list);
}*/
if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) {
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag)
*/
@SuppressWarnings({ "unchecked"})
@Override
public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) {
Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
if (cont != null) {
if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
StringTag stringTag = ((StringTag)contents.get("Potion"));
if (stringTag != null) {
String tag = ((StringTag)contents.get("Potion")).getValue();
//Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
NBTTagCompound tagCompound = stack.getTag();
if(tagCompound == null){
tagCompound = new NBTTagCompound();
}
tagCompound.setString("Potion", tag);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
}
}
// Schematic is old, the potions do not have tags
// Set it to zero so that the potion bottles don't look like giant purple and black blocks
chestItem.setDurability((short)0);
Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water.");
return chestItem;
}
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
public ItemStack getSpawnEgg(EntityType type, int amount) {
//Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if(tagCompound == null){
tagCompound = new NBTTagCompound();
}
//Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
NBTTagCompound id = new NBTTagCompound();
if (!bToMConversion.containsKey(type)) {
id.setString("id", "minecraft:" + type.toString().toLowerCase());
} else {
id.setString("id", "minecraft:" + bToMConversion.get(type));
}
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
//Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
@Override
public void sendActionBar(Player player, String message) {
// TODO Auto-generated method stub
}
@Override
public void sendTitle(Player player, String message) {
// TODO Auto-generated method stub
}
@Override
public void sendSubtitle(Player player, String message) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,51 @@
package bskyblock;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
public class TestTest {
private final UUID playerUUID = UUID.randomUUID();
@Before
public void setUp() {
World world = mock(World.class);
//Mockito.when(world.getWorldFolder()).thenReturn(worldFile);
Server server = mock(Server.class);
Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
Mockito.when(server.getWorld("world")).thenReturn(world);
Mockito.when(server.getVersion()).thenReturn("TestTestMocking");
Mockito.when(server.getVersion()).thenReturn("TestTestMocking");
Bukkit.setServer(server);
}
@Test
public void createAndSave() {
TeamEvent event = TeamEvent.builder()
//.island(getIslands().getIsland(playerUUID))
.reason(TeamReason.INFO)
.involvedPlayer(playerUUID)
.build();
assertEquals(playerUUID, event.getPlayer());
}
}