use of org.bukkit.block.Chest in project Minigames by AddstarMC.
the class BlockData method randomizeContents.
public void randomizeContents(int minContents, int maxContents) {
if (hasRandomized || items == null)
return;
List<ItemStack> itemRand = new ArrayList<ItemStack>();
for (int i = 0; i < items.length; i++) {
if (items[i] != null) {
itemRand.add(items[i].clone());
}
}
Collections.shuffle(itemRand);
List<ItemStack> itemChest = new ArrayList<ItemStack>();
if (maxContents > itemRand.size()) {
maxContents = itemRand.size();
}
if (minContents > itemRand.size()) {
minContents = itemRand.size();
}
int rand = minContents + (int) (Math.random() * ((maxContents - minContents) + 1));
for (int i = 0; i < items.length; i++) {
if (i < rand) {
itemChest.add(i, itemRand.get(i));
} else {
itemChest.add(null);
}
}
Collections.shuffle(itemChest);
ItemStack[] newItems = new ItemStack[itemChest.size()];
int inc = 0;
for (ItemStack item : itemChest) {
newItems[inc] = item;
inc++;
}
if (state instanceof Chest) {
Chest chest = (Chest) state;
chest.getInventory().setContents(newItems);
}
hasRandomized = true;
}
use of org.bukkit.block.Chest in project VoxelGamesLibv2 by VoxelGamesLib.
the class MapScanner method searchForMarkers.
/**
* Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
*
* @param map the map to scan
* @param center the center location
* @param range the range in where to scan
*/
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
World world = Bukkit.getWorld(map.getLoadedName(gameid));
if (world == null) {
throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getName() + ")" + ". Is it loaded?");
}
List<Marker> markers = new ArrayList<>();
List<ChestMarker> chestMarkers = new ArrayList<>();
int startX = (int) center.getX();
int startY = (int) center.getZ();
int minX = Math.min(startX - range, startX + range);
int minZ = Math.min(startY - range, startY + range);
int maxX = Math.max(startX - range, startX + range);
int maxZ = Math.max(startY - range, startY + range);
for (int x = minX; x <= maxX; x += 16) {
for (int z = minZ; z <= maxZ; z += 16) {
Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
for (BlockState te : chunk.getTileEntities()) {
if (te.getType() == Material.SKULL) {
Skull skull = (Skull) te;
if (skull.getSkullType() == SkullType.PLAYER) {
String markerData = getMarkerData(skull);
if (markerData == null)
continue;
MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()), DirectionUtil.directionToYaw(skull.getRotation()), markerData, markerDefinition));
}
} else if (te.getType() == Material.CHEST) {
Chest chest = (Chest) te;
String name = chest.getBlockInventory().getName();
ItemStack[] items = new ItemStack[chest.getBlockInventory().getStorageContents().length];
for (int i = 0; i < items.length; i++) {
ItemStack is = chest.getBlockInventory().getItem(i);
if (is == null) {
items[i] = new ItemStack(Material.AIR);
} else {
items[i] = is;
}
}
chestMarkers.add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name, items));
}
}
}
}
map.setMarkers(markers);
map.setChestMarkers(chestMarkers);
}
use of org.bukkit.block.Chest in project askyblock by tastybento.
the class Schematic method pasteSchematic.
/*
* This function pastes using World Edit - problem is that because it reads a file, it's slow.
@SuppressWarnings("deprecation")
*/
/*
*
public void pasteSchematic(final Location loc, final Player player, boolean teleport) {
plugin.getLogger().info("WE Pasting");
com.sk89q.worldedit.Vector WEorigin = new com.sk89q.worldedit.Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), 999999999);
try {
CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
cc.paste(es, WEorigin, false);
cc.pasteEntities(WEorigin);
} catch (Exception e) {
e.printStackTrace();
}
if (teleport) {
World world = loc.getWorld();
player.teleport(world.getSpawnLocation());
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
plugin.getGrid().homeTeleport(player);
}}, 10L);
}
}
*/
/**
* This method pastes a schematic.
* @param loc - where to paste it
* @param player - who for
* @param teleport - should the player be teleported after pasting?
* @param reason - why this was pasted
*/
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason) {
// If this is not a file schematic, paste the default island
if (this.file == null) {
if (Settings.GAMETYPE == GameType.ACIDISLAND) {
generateIslandBlocks(loc, player, reason);
} else {
loc.getBlock().setType(Material.BEDROCK);
ASkyBlock.getPlugin().getLogger().severe("Missing schematic - using bedrock block only");
}
return;
}
World world = loc.getWorld();
Location blockLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
// Location blockLoc = new Location(world, loc.getX(), Settings.island_level, loc.getZ());
blockLoc.subtract(bedrock);
// plugin.getLogger().info("DEBUG: islandBlock size (paste) = " + islandBlocks.size());
for (IslandBlock b : islandBlocks) {
b.paste(nms, blockLoc, this.usePhysics, biome);
}
// Bukkit.getLogger().info("Block loc = " + blockLoc);
if (pasteEntities) {
for (EntityObject ent : entitiesList) {
// If TileX/Y/Z id defined, we have to use it (for Item Frame & Painting)
if (ent.getTileX() != null && ent.getTileY() != null && ent.getTileZ() != null) {
ent.setLocation(new BlockVector(ent.getTileX(), ent.getTileY(), ent.getTileZ()));
}
Location entitySpot = ent.getLocation().toLocation(blockLoc.getWorld()).add(blockLoc.toVector());
entitySpot.setPitch(ent.getPitch());
entitySpot.setYaw(ent.getYaw());
// Bukkit.getLogger().info("DEBUG: Entity type = " + ent.getType());
if (ent.getType() == EntityType.PAINTING) {
// Bukkit.getLogger().info("DEBUG: spawning " + ent.getType().toString() + " at " + entitySpot);
try {
Painting painting = blockLoc.getWorld().spawn(entitySpot, Painting.class);
if (painting != null) {
if (paintingList.containsKey(ent.getMotive())) {
// painting.setArt(Art.GRAHAM);
painting.setArt(paintingList.get(ent.getMotive()), true);
} else {
// Set default
painting.setArt(Art.ALBAN, true);
}
// http://minecraft.gamepedia.com/Painting#Data_values
if (facingList.containsKey(ent.getFacing())) {
painting.setFacingDirection(facingList.get(ent.getFacing()), true);
} else {
// set default direction
painting.setFacingDirection(BlockFace.NORTH, true);
}
// Bukkit.getLogger().info("DEBUG: Painting setFacingDirection: " + painting.getLocation().toString() + "; facing: " + painting.getFacing() + "; ent facing: " + ent.getFacing());
// Bukkit.getLogger().info("DEBUG: Painting setArt: " + painting.getLocation().toString() + "; art: " + painting.getArt() + "; ent motive: " + ent.getMotive());
}
} catch (IllegalArgumentException e) {
// plugin.getLogger().warning("Cannot paste painting from schematic");
}
} else if (ent.getType() == EntityType.ITEM_FRAME) {
// Bukkit.getLogger().info("DEBUG: spawning itemframe at" + entitySpot.toString());
// Bukkit.getLogger().info("DEBUG: tileX: " + ent.getTileX() + ", tileY: " + ent.getTileY() + ", tileZ: " + ent.getTileZ());
ItemFrame itemFrame = (ItemFrame) blockLoc.getWorld().spawnEntity(entitySpot, EntityType.ITEM_FRAME);
if (itemFrame != null) {
// Need to improve this shity fix ...
Material material = Material.matchMaterial(ent.getId().substring(10).toUpperCase());
;
if (material == null && IslandBlock.WEtoM.containsKey(ent.getId().substring(10).toUpperCase())) {
material = IslandBlock.WEtoM.get(ent.getId().substring(10).toUpperCase());
}
ItemStack item;
if (material != null) {
// Bukkit.getLogger().info("DEBUG: id: " + ent.getId() + ", material match: " + material.toString());
if (ent.getCount() != null) {
if (ent.getDamage() != null) {
item = new ItemStack(material, ent.getCount(), ent.getDamage());
} else {
item = new ItemStack(material, ent.getCount(), (short) 0);
}
} else {
if (ent.getDamage() != null) {
item = new ItemStack(material, 1, ent.getDamage());
} else {
item = new ItemStack(material, 1, (short) 0);
}
}
} else {
// Bukkit.getLogger().info("DEBUG: material can't be found for: " + ent.getId() + " (" + ent.getId().substring(10).toUpperCase() + ")");
// Set to default content
item = new ItemStack(Material.STONE, 0, (short) 4);
}
ItemMeta itemMeta = item.getItemMeta();
// TODO: Implement methods to get enchantement, names, lore etc.
item.setItemMeta(itemMeta);
itemFrame.setItem(item);
if (facingList.containsKey(ent.getFacing())) {
itemFrame.setFacingDirection(facingList.get(ent.getFacing()), true);
} else {
// set default direction
itemFrame.setFacingDirection(BlockFace.NORTH, true);
}
// TODO: Implements code to handle the rotation of the item in the itemframe
if (rotationList.containsKey(ent.getItemRotation())) {
itemFrame.setRotation(rotationList.get(ent.getItemRotation()));
} else {
// Set default direction
itemFrame.setRotation(Rotation.NONE);
}
}
} else {
// Bukkit.getLogger().info("Spawning " + ent.getType().toString() + " at " + entitySpot);
Entity spawned = blockLoc.getWorld().spawnEntity(entitySpot, ent.getType());
if (spawned != null) {
spawned.setVelocity(ent.getMotion());
if (ent.getType() == EntityType.SHEEP) {
Sheep sheep = (Sheep) spawned;
if (ent.isSheared()) {
sheep.setSheared(true);
}
DyeColor[] set = DyeColor.values();
sheep.setColor(set[ent.getColor()]);
sheep.setAge(ent.getAge());
} else if (ent.getType() == EntityType.HORSE) {
Horse horse = (Horse) spawned;
Horse.Color[] set = Horse.Color.values();
horse.setColor(set[ent.getColor()]);
horse.setAge(ent.getAge());
horse.setCarryingChest(ent.isCarryingChest());
} else if (ent.getType() == EntityType.VILLAGER) {
Villager villager = (Villager) spawned;
villager.setAge(ent.getAge());
Profession[] proffs = Profession.values();
villager.setProfession(proffs[ent.getProfession()]);
} else if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && ent.getType() == EntityType.RABBIT) {
Rabbit rabbit = (Rabbit) spawned;
Rabbit.Type[] set = Rabbit.Type.values();
rabbit.setRabbitType(set[ent.getRabbitType()]);
rabbit.setAge(ent.getAge());
} else if (ent.getType() == EntityType.OCELOT) {
Ocelot cat = (Ocelot) spawned;
if (ent.isOwned()) {
cat.setTamed(true);
cat.setOwner(player);
}
Ocelot.Type[] set = Ocelot.Type.values();
cat.setCatType(set[ent.getCatType()]);
cat.setAge(ent.getAge());
cat.setSitting(ent.isSitting());
} else if (ent.getType() == EntityType.WOLF) {
Wolf wolf = (Wolf) spawned;
if (ent.isOwned()) {
wolf.setTamed(true);
wolf.setOwner(player);
}
wolf.setAge(ent.getAge());
wolf.setSitting(ent.isSitting());
DyeColor[] color = DyeColor.values();
wolf.setCollarColor(color[ent.getCollarColor()]);
}
}
}
}
}
// Find the grass spot
final Location grass;
if (topGrass != null) {
Location gr = topGrass.clone().toLocation(loc.getWorld()).subtract(bedrock);
gr.add(loc.toVector());
// Center of block and a bit up so the animal drops a bit
gr.add(new Vector(0.5D, 1.1D, 0.5D));
grass = gr;
} else {
grass = null;
}
// Bukkit.getLogger().info("DEBUG cow location " + grass);
Block blockToChange = null;
// Place a helpful sign in front of player
if (welcomeSign != null) {
// Bukkit.getLogger().info("DEBUG welcome sign schematic relative is:"
// + welcomeSign.toString());
Vector ws = welcomeSign.clone().subtract(bedrock);
// Bukkit.getLogger().info("DEBUG welcome sign relative to bedrock is:"
// + welcomeSign.toString());
ws.add(loc.toVector());
// Bukkit.getLogger().info("DEBUG welcome sign actual position is:"
// + welcomeSign.toString());
blockToChange = ws.toLocation(world).getBlock();
BlockState signState = blockToChange.getState();
if (signState instanceof Sign) {
Sign sign = (Sign) signState;
if (sign.getLine(0).isEmpty()) {
sign.setLine(0, plugin.myLocale(player.getUniqueId()).signLine1.replace("[player]", player.getName()));
}
if (sign.getLine(1).isEmpty()) {
sign.setLine(1, plugin.myLocale(player.getUniqueId()).signLine2.replace("[player]", player.getName()));
}
if (sign.getLine(2).isEmpty()) {
sign.setLine(2, plugin.myLocale(player.getUniqueId()).signLine3.replace("[player]", player.getName()));
}
if (sign.getLine(3).isEmpty()) {
sign.setLine(3, plugin.myLocale(player.getUniqueId()).signLine4.replace("[player]", player.getName()));
}
// BlockFace direction = ((org.bukkit.material.Sign)
// sign.getData()).getFacing();
// ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
sign.update(true, false);
}
}
if (chest != null) {
Vector ch = chest.clone().subtract(bedrock);
ch.add(loc.toVector());
// Place the chest - no need to use the safe spawn function because we
// know what this island looks like
blockToChange = ch.toLocation(world).getBlock();
// Settings.chestItems.length);
if (useDefaultChest) {
// Fill the chest
if (blockToChange.getType() == Material.CHEST) {
final Chest islandChest = (Chest) blockToChange.getState();
DoubleChest doubleChest = null;
InventoryHolder iH = islandChest.getInventory().getHolder();
if (iH instanceof DoubleChest) {
// Bukkit.getLogger().info("DEBUG: double chest");
doubleChest = (DoubleChest) iH;
}
if (doubleChest != null) {
Inventory inventory = doubleChest.getInventory();
inventory.clear();
inventory.setContents(defaultChestItems);
} else {
Inventory inventory = islandChest.getInventory();
inventory.clear();
inventory.setContents(defaultChestItems);
}
}
}
}
if (teleport) {
plugin.getPlayers().setInTeleport(player.getUniqueId(), true);
// plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
if (player.getWorld().equals(world)) {
// plugin.getLogger().info("DEBUG: same world");
int distSq = (int) ((player.getLocation().distanceSquared(loc) - ((double) Settings.islandDistance * Settings.islandDistance) / 16));
// plugin.getLogger().info("DEBUG: distsq = " + distSq);
if (plugin.getServer().getViewDistance() * plugin.getServer().getViewDistance() < distSq) {
// plugin.getLogger().info("DEBUG: teleporting");
player.teleport(world.getSpawnLocation());
}
}
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
plugin.getGrid().homeTeleport(player);
plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
// Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world
plugin.resetPlayer(player);
// Reset money if required
if (Settings.resetMoney) {
resetMoney(player);
}
// Show fancy titles!
if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) {
// plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
}
if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) {
// plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
}
if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) {
// plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""
// + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
}
}
if (reason.equals(PasteReason.NEW_ISLAND)) {
// plugin.getLogger().info("DEBUG: First time");
if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) {
// plugin.getLogger().info("DEBUG: Executing new island commands");
IslandCmd.runCommands(Settings.startCommands, player);
}
} else if (reason.equals(PasteReason.RESET)) {
// plugin.getLogger().info("DEBUG: Reset");
if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) {
// plugin.getLogger().info("DEBUG: Executing reset island commands");
IslandCmd.runCommands(Settings.resetCommands, player);
}
}
}
}, 10L);
}
if (!islandCompanion.isEmpty() && grass != null) {
Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(), new Runnable() {
@Override
public void run() {
spawnCompanion(player, grass);
}
}, 40L);
}
// Set the bedrock block meta data to the original spawn location
// Doesn't survive a server restart. TODO: change to add this info elsewhere.
/*
if (playerSpawn != null) {
blockToChange = loc.getBlock();
if (blockToChange.getType().equals(Material.BEDROCK)) {
String spawnLoc = Util.getStringLocation(loc.clone().add(playerSpawn).add(new Vector(0.5D,0D,0.5D)));
blockToChange.setMetadata("playerSpawn", new FixedMetadataValue(plugin, spawnLoc));
}
}
*/
}
use of org.bukkit.block.Chest in project acidisland by tastybento.
the class Schematic method pasteSchematic.
/*
* This function pastes using World Edit - problem is that because it reads a file, it's slow.
@SuppressWarnings("deprecation")
*/
/*
*
public void pasteSchematic(final Location loc, final Player player, boolean teleport) {
plugin.getLogger().info("WE Pasting");
com.sk89q.worldedit.Vector WEorigin = new com.sk89q.worldedit.Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), 999999999);
try {
CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
cc.paste(es, WEorigin, false);
cc.pasteEntities(WEorigin);
} catch (Exception e) {
e.printStackTrace();
}
if (teleport) {
World world = loc.getWorld();
player.teleport(world.getSpawnLocation());
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
plugin.getGrid().homeTeleport(player);
}}, 10L);
}
}
*/
/**
* This method pastes a schematic.
* @param loc - where to paste it
* @param player - who for
* @param teleport - should the player be teleported after pasting?
* @param reason - why this was pasted
*/
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason) {
// If this is not a file schematic, paste the default island
if (this.file == null) {
if (Settings.GAMETYPE == GameType.ACIDISLAND) {
generateIslandBlocks(loc, player, reason);
} else {
loc.getBlock().setType(Material.BEDROCK);
ASkyBlock.getPlugin().getLogger().severe("Missing schematic - using bedrock block only");
}
return;
}
World world = loc.getWorld();
Location blockLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
// Location blockLoc = new Location(world, loc.getX(), Settings.island_level, loc.getZ());
blockLoc.subtract(bedrock);
// plugin.getLogger().info("DEBUG: islandBlock size (paste) = " + islandBlocks.size());
for (IslandBlock b : islandBlocks) {
b.paste(nms, blockLoc, this.usePhysics, biome);
}
// Bukkit.getLogger().info("Block loc = " + blockLoc);
if (pasteEntities) {
for (EntityObject ent : entitiesList) {
// If TileX/Y/Z id defined, we have to use it (for Item Frame & Painting)
if (ent.getTileX() != null && ent.getTileY() != null && ent.getTileZ() != null) {
ent.setLocation(new BlockVector(ent.getTileX(), ent.getTileY(), ent.getTileZ()));
}
Location entitySpot = ent.getLocation().toLocation(blockLoc.getWorld()).add(blockLoc.toVector());
entitySpot.setPitch(ent.getPitch());
entitySpot.setYaw(ent.getYaw());
// Bukkit.getLogger().info("DEBUG: Entity type = " + ent.getType());
if (ent.getType() == EntityType.PAINTING) {
// Bukkit.getLogger().info("DEBUG: spawning " + ent.getType().toString() + " at " + entitySpot);
try {
Painting painting = blockLoc.getWorld().spawn(entitySpot, Painting.class);
if (painting != null) {
if (paintingList.containsKey(ent.getMotive())) {
// painting.setArt(Art.GRAHAM);
painting.setArt(paintingList.get(ent.getMotive()), true);
} else {
// Set default
painting.setArt(Art.ALBAN, true);
}
// http://minecraft.gamepedia.com/Painting#Data_values
if (facingList.containsKey(ent.getFacing())) {
painting.setFacingDirection(facingList.get(ent.getFacing()), true);
} else {
// set default direction
painting.setFacingDirection(BlockFace.NORTH, true);
}
// Bukkit.getLogger().info("DEBUG: Painting setFacingDirection: " + painting.getLocation().toString() + "; facing: " + painting.getFacing() + "; ent facing: " + ent.getFacing());
// Bukkit.getLogger().info("DEBUG: Painting setArt: " + painting.getLocation().toString() + "; art: " + painting.getArt() + "; ent motive: " + ent.getMotive());
}
} catch (IllegalArgumentException e) {
// plugin.getLogger().warning("Cannot paste painting from schematic");
}
} else if (ent.getType() == EntityType.ITEM_FRAME) {
// Bukkit.getLogger().info("DEBUG: spawning itemframe at" + entitySpot.toString());
// Bukkit.getLogger().info("DEBUG: tileX: " + ent.getTileX() + ", tileY: " + ent.getTileY() + ", tileZ: " + ent.getTileZ());
ItemFrame itemFrame = (ItemFrame) blockLoc.getWorld().spawnEntity(entitySpot, EntityType.ITEM_FRAME);
if (itemFrame != null) {
// Need to improve this shity fix ...
Material material = Material.matchMaterial(ent.getId().substring(10).toUpperCase());
;
if (material == null && IslandBlock.WEtoM.containsKey(ent.getId().substring(10).toUpperCase())) {
material = IslandBlock.WEtoM.get(ent.getId().substring(10).toUpperCase());
}
ItemStack item;
if (material != null) {
// Bukkit.getLogger().info("DEBUG: id: " + ent.getId() + ", material match: " + material.toString());
if (ent.getCount() != null) {
if (ent.getDamage() != null) {
item = new ItemStack(material, ent.getCount(), ent.getDamage());
} else {
item = new ItemStack(material, ent.getCount(), (short) 0);
}
} else {
if (ent.getDamage() != null) {
item = new ItemStack(material, 1, ent.getDamage());
} else {
item = new ItemStack(material, 1, (short) 0);
}
}
} else {
// Bukkit.getLogger().info("DEBUG: material can't be found for: " + ent.getId() + " (" + ent.getId().substring(10).toUpperCase() + ")");
// Set to default content
item = new ItemStack(Material.STONE, 0, (short) 4);
}
ItemMeta itemMeta = item.getItemMeta();
// TODO: Implement methods to get enchantement, names, lore etc.
item.setItemMeta(itemMeta);
itemFrame.setItem(item);
if (facingList.containsKey(ent.getFacing())) {
itemFrame.setFacingDirection(facingList.get(ent.getFacing()), true);
} else {
// set default direction
itemFrame.setFacingDirection(BlockFace.NORTH, true);
}
// TODO: Implements code to handle the rotation of the item in the itemframe
if (rotationList.containsKey(ent.getItemRotation())) {
itemFrame.setRotation(rotationList.get(ent.getItemRotation()));
} else {
// Set default direction
itemFrame.setRotation(Rotation.NONE);
}
}
} else {
// Bukkit.getLogger().info("Spawning " + ent.getType().toString() + " at " + entitySpot);
Entity spawned = blockLoc.getWorld().spawnEntity(entitySpot, ent.getType());
if (spawned != null) {
spawned.setVelocity(ent.getMotion());
if (ent.getType() == EntityType.SHEEP) {
Sheep sheep = (Sheep) spawned;
if (ent.isSheared()) {
sheep.setSheared(true);
}
DyeColor[] set = DyeColor.values();
sheep.setColor(set[ent.getColor()]);
sheep.setAge(ent.getAge());
} else if (ent.getType() == EntityType.HORSE) {
Horse horse = (Horse) spawned;
Horse.Color[] set = Horse.Color.values();
horse.setColor(set[ent.getColor()]);
horse.setAge(ent.getAge());
horse.setCarryingChest(ent.isCarryingChest());
} else if (ent.getType() == EntityType.VILLAGER) {
Villager villager = (Villager) spawned;
villager.setAge(ent.getAge());
Profession[] proffs = Profession.values();
villager.setProfession(proffs[ent.getProfession()]);
} else if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && ent.getType() == EntityType.RABBIT) {
Rabbit rabbit = (Rabbit) spawned;
Rabbit.Type[] set = Rabbit.Type.values();
rabbit.setRabbitType(set[ent.getRabbitType()]);
rabbit.setAge(ent.getAge());
} else if (ent.getType() == EntityType.OCELOT) {
Ocelot cat = (Ocelot) spawned;
if (ent.isOwned()) {
cat.setTamed(true);
cat.setOwner(player);
}
Ocelot.Type[] set = Ocelot.Type.values();
cat.setCatType(set[ent.getCatType()]);
cat.setAge(ent.getAge());
cat.setSitting(ent.isSitting());
} else if (ent.getType() == EntityType.WOLF) {
Wolf wolf = (Wolf) spawned;
if (ent.isOwned()) {
wolf.setTamed(true);
wolf.setOwner(player);
}
wolf.setAge(ent.getAge());
wolf.setSitting(ent.isSitting());
DyeColor[] color = DyeColor.values();
wolf.setCollarColor(color[ent.getCollarColor()]);
}
}
}
}
}
// Find the grass spot
final Location grass;
if (topGrass != null) {
Location gr = topGrass.clone().toLocation(loc.getWorld()).subtract(bedrock);
gr.add(loc.toVector());
// Center of block and a bit up so the animal drops a bit
gr.add(new Vector(0.5D, 1.1D, 0.5D));
grass = gr;
} else {
grass = null;
}
// Bukkit.getLogger().info("DEBUG cow location " + grass);
Block blockToChange = null;
// Place a helpful sign in front of player
if (welcomeSign != null) {
// Bukkit.getLogger().info("DEBUG welcome sign schematic relative is:"
// + welcomeSign.toString());
Vector ws = welcomeSign.clone().subtract(bedrock);
// Bukkit.getLogger().info("DEBUG welcome sign relative to bedrock is:"
// + welcomeSign.toString());
ws.add(loc.toVector());
// Bukkit.getLogger().info("DEBUG welcome sign actual position is:"
// + welcomeSign.toString());
blockToChange = ws.toLocation(world).getBlock();
BlockState signState = blockToChange.getState();
if (signState instanceof Sign) {
Sign sign = (Sign) signState;
if (sign.getLine(0).isEmpty()) {
sign.setLine(0, plugin.myLocale(player.getUniqueId()).signLine1.replace("[player]", player.getName()));
}
if (sign.getLine(1).isEmpty()) {
sign.setLine(1, plugin.myLocale(player.getUniqueId()).signLine2.replace("[player]", player.getName()));
}
if (sign.getLine(2).isEmpty()) {
sign.setLine(2, plugin.myLocale(player.getUniqueId()).signLine3.replace("[player]", player.getName()));
}
if (sign.getLine(3).isEmpty()) {
sign.setLine(3, plugin.myLocale(player.getUniqueId()).signLine4.replace("[player]", player.getName()));
}
// BlockFace direction = ((org.bukkit.material.Sign)
// sign.getData()).getFacing();
// ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
sign.update(true, false);
}
}
if (chest != null) {
Vector ch = chest.clone().subtract(bedrock);
ch.add(loc.toVector());
// Place the chest - no need to use the safe spawn function because we
// know what this island looks like
blockToChange = ch.toLocation(world).getBlock();
// Settings.chestItems.length);
if (useDefaultChest) {
// Fill the chest
if (blockToChange.getType() == Material.CHEST) {
final Chest islandChest = (Chest) blockToChange.getState();
DoubleChest doubleChest = null;
InventoryHolder iH = islandChest.getInventory().getHolder();
if (iH instanceof DoubleChest) {
// Bukkit.getLogger().info("DEBUG: double chest");
doubleChest = (DoubleChest) iH;
}
if (doubleChest != null) {
Inventory inventory = doubleChest.getInventory();
inventory.clear();
inventory.setContents(defaultChestItems);
} else {
Inventory inventory = islandChest.getInventory();
inventory.clear();
inventory.setContents(defaultChestItems);
}
}
}
}
if (teleport) {
plugin.getPlayers().setInTeleport(player.getUniqueId(), true);
// plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
if (player.getWorld().equals(world)) {
// plugin.getLogger().info("DEBUG: same world");
int distSq = (int) ((player.getLocation().distanceSquared(loc) - ((double) Settings.islandDistance * Settings.islandDistance) / 16));
// plugin.getLogger().info("DEBUG: distsq = " + distSq);
if (plugin.getServer().getViewDistance() * plugin.getServer().getViewDistance() < distSq) {
// plugin.getLogger().info("DEBUG: teleporting");
player.teleport(world.getSpawnLocation());
}
}
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
plugin.getGrid().homeTeleport(player);
plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
// Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world
plugin.resetPlayer(player);
// Reset money if required
if (Settings.resetMoney) {
resetMoney(player);
}
// Show fancy titles!
if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) {
// plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
}
if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) {
// plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
}
if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) {
// plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""
// + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
}
}
if (reason.equals(PasteReason.NEW_ISLAND)) {
// plugin.getLogger().info("DEBUG: First time");
if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) {
// plugin.getLogger().info("DEBUG: Executing new island commands");
IslandCmd.runCommands(Settings.startCommands, player);
}
} else if (reason.equals(PasteReason.RESET)) {
// plugin.getLogger().info("DEBUG: Reset");
if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) {
// plugin.getLogger().info("DEBUG: Executing reset island commands");
IslandCmd.runCommands(Settings.resetCommands, player);
}
}
}
}, 10L);
}
if (!islandCompanion.isEmpty() && grass != null) {
Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(), new Runnable() {
@Override
public void run() {
spawnCompanion(player, grass);
}
}, 40L);
}
// Set the bedrock block meta data to the original spawn location
// Doesn't survive a server restart. TODO: change to add this info elsewhere.
/*
if (playerSpawn != null) {
blockToChange = loc.getBlock();
if (blockToChange.getType().equals(Material.BEDROCK)) {
String spawnLoc = Util.getStringLocation(loc.clone().add(playerSpawn).add(new Vector(0.5D,0D,0.5D)));
blockToChange.setMetadata("playerSpawn", new FixedMetadataValue(plugin, spawnLoc));
}
}
*/
}
use of org.bukkit.block.Chest in project Village_Defense by Plajer.
the class ShopManager method registerShop.
public static void registerShop(Arena a) {
Location location = Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString("instances." + a.getID() + ".shop"));
if (!(location.getBlock().getState() instanceof Chest)) {
if (Main.isDebugged()) {
System.out.print("[Village Debugger] Location for shop isn't a chest!");
}
return;
}
int i = ((Chest) location.getBlock().getState()).getInventory().getContents().length;
Inventory inventory = Bukkit.createInventory(null, Util.serializeInt(i), ChatManager.colorMessage("In-Game.Messages.Shop-Messages.Shop-GUI-Name"));
i = 0;
for (ItemStack itemStack : ((Chest) location.getBlock().getState()).getInventory().getContents()) {
if (itemStack != null && itemStack.getType() != Material.REDSTONE_BLOCK)
inventory.setItem(i, itemStack);
i++;
}
arenaShop.put(a, inventory);
}
Aggregations