after a big rewrite and tons of new features, rc1 for 0.3
This commit is contained in:
72
src/main/java/us/camin/regions/ui/Colors.java
Normal file
72
src/main/java/us/camin/regions/ui/Colors.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class Colors {
|
||||
public static ChatColor[] regionColors = {
|
||||
ChatColor.AQUA,
|
||||
ChatColor.BLACK,
|
||||
ChatColor.BLUE,
|
||||
ChatColor.BOLD,
|
||||
ChatColor.DARK_AQUA,
|
||||
ChatColor.DARK_BLUE,
|
||||
ChatColor.DARK_GRAY,
|
||||
ChatColor.DARK_GREEN,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.DARK_RED,
|
||||
ChatColor.GOLD,
|
||||
ChatColor.GRAY,
|
||||
ChatColor.GREEN,
|
||||
ChatColor.LIGHT_PURPLE,
|
||||
ChatColor.RED,
|
||||
ChatColor.WHITE,
|
||||
ChatColor.YELLOW,
|
||||
};
|
||||
|
||||
public static ChatColor chatColorForName(String name) {
|
||||
int colorCount = regionColors.length;
|
||||
int hashed = Math.abs(name.hashCode());
|
||||
return regionColors[hashed % (colorCount - 1)];
|
||||
}
|
||||
|
||||
public static ChatColor chatColorForColor(DyeColor color) {
|
||||
switch (color) {
|
||||
case BLACK:
|
||||
return ChatColor.BLACK;
|
||||
case BLUE:
|
||||
return ChatColor.BLUE;
|
||||
case BROWN:
|
||||
return ChatColor.DARK_RED;
|
||||
case CYAN:
|
||||
return ChatColor.AQUA;
|
||||
case GRAY:
|
||||
return ChatColor.GRAY;
|
||||
case GREEN:
|
||||
return ChatColor.GREEN;
|
||||
case LIGHT_BLUE:
|
||||
return ChatColor.BLUE;
|
||||
case LIGHT_GRAY:
|
||||
return ChatColor.GRAY;
|
||||
case LIME:
|
||||
return ChatColor.GREEN;
|
||||
case MAGENTA:
|
||||
return ChatColor.LIGHT_PURPLE;
|
||||
case ORANGE:
|
||||
return ChatColor.GOLD;
|
||||
case PINK:
|
||||
return ChatColor.RED;
|
||||
case PURPLE:
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case RED:
|
||||
return ChatColor.RED;
|
||||
case WHITE:
|
||||
return ChatColor.WHITE;
|
||||
case YELLOW:
|
||||
return ChatColor.YELLOW;
|
||||
}
|
||||
return ChatColor.WHITE;
|
||||
}
|
||||
}
|
||||
210
src/main/java/us/camin/regions/ui/PlayerInventoryTeleporter.java
Normal file
210
src/main/java/us/camin/regions/ui/PlayerInventoryTeleporter.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.CompassMeta;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.RegionManager;
|
||||
import us.camin.regions.events.PlayerPostInteractEvent;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.lang.Math;
|
||||
|
||||
public class PlayerInventoryTeleporter implements Listener {
|
||||
Map<Player, Inventory> m_playerInventories;
|
||||
Plugin m_plugin;
|
||||
RegionManager m_manager;
|
||||
|
||||
public PlayerInventoryTeleporter(Plugin plugin, RegionManager manager) {
|
||||
m_plugin = plugin;
|
||||
m_manager = manager;
|
||||
m_playerInventories = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventory(InventoryClickEvent event) {
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HumanEntity clicker = event.getWhoClicked();
|
||||
|
||||
if (clicker instanceof Player) {
|
||||
Player player = (Player)clicker;
|
||||
Inventory neighborInv = m_playerInventories.get(player);
|
||||
if (neighborInv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTopInventory() == neighborInv) {
|
||||
event.setResult(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (event.getClickedInventory() == neighborInv) {
|
||||
ItemMeta meta = event.getCurrentItem().getItemMeta();
|
||||
Material mat = event.getCurrentItem().getType();
|
||||
if (mat == Material.BEDROCK || mat == Material.COMPASS || mat == Material.LANTERN) {
|
||||
return;
|
||||
}
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> event.getView().close());
|
||||
Region nearest = m_manager.nearestRegion(player.getLocation());
|
||||
|
||||
final String selectedName = meta.getDisplayName();
|
||||
final Optional<Region> destination = m_plugin.regionManager().regionsForWorld(player.getLocation().getWorld())
|
||||
.stream()
|
||||
.filter((r) -> r.name().equals(selectedName))
|
||||
.findFirst();
|
||||
if (destination.isPresent()) {
|
||||
player.sendMessage("Teleporting you there now...");
|
||||
nearest.addCharges(-1);
|
||||
destination.get().addCharges(1);
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(nearest, m_plugin);
|
||||
builder.updateLantern();
|
||||
});
|
||||
m_plugin.saveRegions();
|
||||
new PlayerTeleporter(player, nearest.teleportLocation(), destination.get().teleportLocation(), m_plugin).teleport().thenRun(() -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(destination.get(), m_plugin);
|
||||
builder.updateLantern();
|
||||
});
|
||||
if (nearest.charges() == 0) {
|
||||
nearest.location().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, (float)1.0, (float)1.0);
|
||||
//player.sendMessage("You've consumed this region post's last charge! You won't be able to return without recharging it.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("There is no region with that name. This is a bug.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerPostInteractEvent event) {
|
||||
Collection<Region> nearby = m_manager.neighborsForRegion(event.region);
|
||||
Collection<Region> hubs = m_manager.worldHubs(event.region.location().getWorld());
|
||||
if (!m_playerInventories.containsKey(event.player)) {
|
||||
m_playerInventories.put(event.player, Bukkit.createInventory(null, InventoryType.CHEST, "Nearby Regions"));
|
||||
}
|
||||
Inventory neighborInventory = m_playerInventories.get(event.player);
|
||||
neighborInventory.clear();
|
||||
|
||||
ArrayList<Region> sorted = new ArrayList<Region>();
|
||||
ArrayList<String> foundNames = new ArrayList<String>();
|
||||
Region nearest = m_manager.nearestRegion(event.player.getLocation());
|
||||
for(Region r : nearby) {
|
||||
if (!r.name().equals(nearest.name())) {
|
||||
foundNames.add(r.name());
|
||||
sorted.add(r);
|
||||
}
|
||||
}
|
||||
for(Region r : hubs) {
|
||||
if (!foundNames.contains(r.name()) && !r.name().equals(nearest.name())) {
|
||||
foundNames.add(r.name());
|
||||
sorted.add(r);
|
||||
}
|
||||
}
|
||||
sorted.sort((Region a, Region b) -> Integer.compare(b.visits(), a.visits()));
|
||||
|
||||
for(Region region : sorted) {
|
||||
boolean isHub = hubs.contains(region);
|
||||
boolean visible = isHub || region.seenByPlayer(event.player) || event.player.hasPermission("regions.bypass.discovery");
|
||||
ItemStack item;
|
||||
if (visible) {
|
||||
item = region.icon();
|
||||
} else {
|
||||
item = new ItemStack(Material.BEDROCK);
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(region.name());
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
Location center = region.location();
|
||||
int altitude = center.getBlockY();
|
||||
if (visible) {
|
||||
if (isHub) {
|
||||
lore.add("" + ChatColor.GOLD + ChatColor.BOLD + "World hub" + ChatColor.GOLD + " - Accessable from anywhere");
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
}
|
||||
lore.add(ChatColor.WHITE + "Distance: " + ChatColor.YELLOW + Math.round(region.location().distance(event.region.location())));
|
||||
lore.add(ChatColor.WHITE + "Population: " + ChatColor.YELLOW + m_plugin.playerWatcher().playersInRegion(region).size());
|
||||
lore.add(ChatColor.WHITE + "Altitude: " + ChatColor.YELLOW + altitude);
|
||||
Collection<Region> neighborNeighbors = m_manager.neighborsForRegion(region);
|
||||
ArrayList<String> neighborNames = new ArrayList<String>();
|
||||
for(Region r : neighborNeighbors) {
|
||||
if (!foundNames.contains(r.name())) {
|
||||
neighborNames.add(r.coloredName());
|
||||
}
|
||||
}
|
||||
lore.add("Nearby connections: " + String.join(", ", neighborNames));
|
||||
} else {
|
||||
lore.add("" + ChatColor.BOLD + ChatColor.GOLD + "You haven't discovered this location yet!");
|
||||
lore.add(ChatColor.WHITE + "Distance: " + ChatColor.YELLOW + ChatColor.MAGIC + Math.round(region.location().distance(event.region.location())));
|
||||
lore.add(ChatColor.WHITE + "Population: " + ChatColor.YELLOW + ChatColor.MAGIC + m_plugin.playerWatcher().playersInRegion(region).size());
|
||||
lore.add(ChatColor.WHITE + "Altitude: " + ChatColor.YELLOW + ChatColor.MAGIC + altitude);
|
||||
lore.add(ChatColor.GOLD + "Coordinates: " + ChatColor.YELLOW + region.location().getX() + ", "+ region.location().getZ());
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
neighborInventory.addItem(item);
|
||||
}
|
||||
ItemStack chargesItem = new ItemStack(event.region.charges() == 0 ? Material.SOUL_LANTERN : Material.LANTERN);
|
||||
ItemMeta meta = chargesItem.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.BOLD + "Region Post Configuration");
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.WHITE + "Name: "+event.region.coloredName());
|
||||
lore.add(ChatColor.WHITE + "Visits: " + ChatColor.YELLOW + event.region.visits());
|
||||
lore.add(ChatColor.WHITE + "Charges remaining: " + (event.region.charges() == 0 ? ChatColor.RED : ChatColor.GREEN) + event.region.charges());
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
chargesItem.setItemMeta(meta);
|
||||
// 22 Is the middle of the bottom row
|
||||
neighborInventory.setItem(22, chargesItem);
|
||||
|
||||
event.player.openInventory(neighborInventory);
|
||||
}
|
||||
}
|
||||
88
src/main/java/us/camin/regions/ui/PlayerTeleporter.java
Normal file
88
src/main/java/us/camin/regions/ui/PlayerTeleporter.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Sound;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import us.camin.regions.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PlayerTeleporter {
|
||||
Logger log = Logger.getLogger("Regions.PlayerTeleporter");
|
||||
|
||||
private Player m_player;
|
||||
private Location m_src;
|
||||
private Location m_dest;
|
||||
private Plugin m_plugin;
|
||||
|
||||
public PlayerTeleporter(Player p, Location src, Location dest, Plugin plugin) {
|
||||
this.m_player = p;
|
||||
this.m_src = src;
|
||||
this.m_dest = dest;
|
||||
this.m_plugin = plugin;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> teleport() {
|
||||
CompletableFuture<Void> ret = new CompletableFuture<Void>();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
|
||||
BukkitTask hoverGenerator = scheduler.runTaskTimer(m_plugin, () -> applyHoverEffect(), 0, 10);
|
||||
BukkitTask particleGenerator = scheduler.runTaskTimer(m_plugin, () -> spawnHoverParticles(), 0, 1);
|
||||
playTeleportSound();
|
||||
|
||||
m_plugin.getServer().getScheduler().runTaskLater(m_plugin, () -> {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 3 + 120, 1, false, false, false));
|
||||
}, 20 * 3);
|
||||
|
||||
m_plugin.getServer().getScheduler().runTaskLater(m_plugin, () -> {
|
||||
spawnTeleportStartParticles();
|
||||
PaperLib.teleportAsync(m_player, m_dest, TeleportCause.COMMAND).thenAccept(res -> {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 1, false, false, false));
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1, false, false, false));
|
||||
spawnEndParticles();
|
||||
particleGenerator.cancel();
|
||||
hoverGenerator.cancel();
|
||||
ret.complete(null);
|
||||
});
|
||||
}, 20 * 6);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void spawnTeleportStartParticles() {
|
||||
World world = m_dest.getWorld();
|
||||
world.spawnParticle(Particle.CLOUD, m_dest, 70, 1, 1, 1);
|
||||
}
|
||||
|
||||
void spawnEndParticles() {
|
||||
World world = m_player.getLocation().getWorld();
|
||||
world.playSound(m_dest, Sound.BLOCK_PORTAL_TRAVEL, (float)0.5, (float)1.0);
|
||||
world.spawnParticle(Particle.CLOUD, m_dest, 70, 1, 1, 1);
|
||||
world.spawnParticle(Particle.SPELL_MOB, m_dest, 5, 2, 2, 2);
|
||||
world.spawnParticle(Particle.PORTAL, m_player.getLocation(), 70, 1, 1, 1);
|
||||
}
|
||||
|
||||
void applyHoverEffect() {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 10, 1, false, false, false));
|
||||
}
|
||||
|
||||
void spawnHoverParticles() {
|
||||
World w = m_player.getLocation().getWorld();
|
||||
w.spawnParticle(Particle.SPELL_MOB, m_dest, 5, 1, 1, 1);
|
||||
w.spawnParticle(Particle.SPELL_MOB, m_src, 5, 2, 2, 2);
|
||||
}
|
||||
|
||||
void playTeleportSound() {
|
||||
m_src.getWorld().playSound(m_src, Sound.BLOCK_PORTAL_TRIGGER, (float)0.5, (float)0.6);
|
||||
m_src.getWorld().playSound(m_src, Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, (float)0.5, (float)1.0);
|
||||
m_src.getWorld().playSound(m_dest, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, (float)0.5, (float)1.0);
|
||||
}
|
||||
}
|
||||
231
src/main/java/us/camin/regions/ui/RegionPostBuilder.java
Normal file
231
src/main/java/us/camin/regions/ui/RegionPostBuilder.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.data.type.Lantern;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.Runnable;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.Plugin;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class RegionPostBuilder {
|
||||
Logger log = Logger.getLogger("Regions.RegionPostBuilder");
|
||||
Plugin m_plugin;
|
||||
Region m_region;
|
||||
public RegionPostBuilder(Region r, Plugin p) {
|
||||
m_region = r;
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
private final Material[] bannerTypes = {
|
||||
Material.WHITE_WALL_BANNER,
|
||||
Material.YELLOW_WALL_BANNER,
|
||||
Material.BLUE_WALL_BANNER,
|
||||
Material.BLACK_WALL_BANNER,
|
||||
Material.BROWN_WALL_BANNER,
|
||||
Material.CYAN_WALL_BANNER,
|
||||
Material.GREEN_WALL_BANNER,
|
||||
Material.LIGHT_BLUE_WALL_BANNER,
|
||||
Material.GRAY_WALL_BANNER,
|
||||
Material.LIGHT_GRAY_WALL_BANNER,
|
||||
Material.LIME_WALL_BANNER,
|
||||
Material.MAGENTA_WALL_BANNER,
|
||||
Material.ORANGE_WALL_BANNER,
|
||||
Material.PINK_WALL_BANNER,
|
||||
Material.PURPLE_WALL_BANNER,
|
||||
Material.RED_WALL_BANNER,
|
||||
};
|
||||
|
||||
boolean isBannerBlock(Block block) {
|
||||
return Tag.BANNERS.isTagged(block.getType());
|
||||
}
|
||||
|
||||
/*void buildPad(Location center) {
|
||||
World world = m_region.location().getWorld();
|
||||
// Fill in the cobblestone pad
|
||||
for(int x = -1;x <= 1;x++) {
|
||||
for(int z = -1;z <= 1;z++) {
|
||||
Block b = world.getBlockAt(center.getBlockX() + x, center.getBlockY(), center.getBlockZ() + z);
|
||||
if (b.getType() != Material.COBBLESTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_STONE_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, center, 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
|
||||
void buildPost(Location center) {
|
||||
World world = m_region.location().getWorld();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
|
||||
// Draw the glowstone base of the tower
|
||||
Block b = world.getBlockAt(center.getBlockX(), center.getBlockY() + 1, center.getBlockZ());
|
||||
if (b.getType() != Material.GLOWSTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.GLOWSTONE);
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_GLASS_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, b.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
if (markerBlock.getType() != m_region.blockMaterial()) {
|
||||
markerBlock.breakNaturally();
|
||||
markerBlock.setType(m_region.blockMaterial());
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, markerBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}, 15);
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
Block lanternBlock = markerBlock.getRelative(BlockFace.UP);
|
||||
Material lanternType = (m_region.charges() > 0) ? Material.LANTERN : Material.SOUL_LANTERN;
|
||||
if (lanternBlock.getType() != Material.LANTERN && lanternBlock.getType() != Material.SOUL_LANTERN) {
|
||||
lanternBlock.breakNaturally();
|
||||
world.playSound(center, Sound.BLOCK_LANTERN_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, lanternBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
lanternBlock.setType(lanternType);
|
||||
Lantern lanternData = (Lantern)lanternBlock.getBlockData();
|
||||
lanternData.setHanging(false);
|
||||
lanternBlock.setBlockData(lanternData);
|
||||
}, 30);
|
||||
}*/
|
||||
|
||||
public void build() {
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
scheduler.runTask(m_plugin, new PadBuilder());
|
||||
scheduler.runTaskLater(m_plugin, new PostBuilder(), 20);
|
||||
scheduler.runTaskLater(m_plugin, new BannerBuilder(), 20 * 2);
|
||||
scheduler.runTaskLater(m_plugin, new LanternBuilder(), 20 * 3);
|
||||
}
|
||||
|
||||
public void updateLantern() {
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
scheduler.runTask(m_plugin, new LanternBuilder());
|
||||
}
|
||||
|
||||
public class PadBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
// Fill in the cobblestone pad
|
||||
for(int x = -1;x <= 1;x++) {
|
||||
for(int z = -1;z <= 1;z++) {
|
||||
Block b = world.getBlockAt(center.getBlockX() + x, center.getBlockY(), center.getBlockZ() + z);
|
||||
if (b.getType() != Material.COBBLESTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_STONE_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, center, 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}
|
||||
|
||||
public class PostBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
|
||||
// Draw the glowstone base of the tower
|
||||
Block b = world.getBlockAt(center.getBlockX(), center.getBlockY() + 1, center.getBlockZ());
|
||||
if (b.getType() != Material.GLOWSTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.GLOWSTONE);
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_GLASS_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, b.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
if (markerBlock.getType() != m_region.blockMaterial()) {
|
||||
markerBlock.breakNaturally();
|
||||
markerBlock.setType(m_region.blockMaterial());
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, markerBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
|
||||
public class BannerBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
// Place the banners
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
BlockFace[] directions = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST};
|
||||
log.info("Rebuilding banners...");
|
||||
for(BlockFace face : directions) {
|
||||
Block b = markerBlock.getRelative(face);
|
||||
if (!isBannerBlock(b)) {
|
||||
b.breakNaturally();
|
||||
}
|
||||
b.setType(m_region.bannerBlockMaterial());
|
||||
Directional bannerDir = (Directional)b.getBlockData();
|
||||
bannerDir.setFacing(face);
|
||||
b.setBlockData(bannerDir);
|
||||
Banner bannerState = (Banner)b.getState();
|
||||
bannerState.setPatterns(m_region.bannerPatterns());
|
||||
bannerState.update();
|
||||
world.spawnParticle(Particle.CLOUD, markerBlock.getLocation().add(0.5, 0.5, 0.5), 10, 1, 1, 1);
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
}
|
||||
}
|
||||
|
||||
public class LanternBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
Block lanternBlock = markerBlock.getRelative(BlockFace.UP);
|
||||
Material lanternType = (m_region.charges() > 0) ? Material.LANTERN : Material.SOUL_LANTERN;
|
||||
if (lanternBlock.getType() != Material.LANTERN && lanternBlock.getType() != Material.SOUL_LANTERN) {
|
||||
lanternBlock.breakNaturally();
|
||||
world.playSound(center, Sound.BLOCK_LANTERN_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, lanternBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
lanternBlock.setType(lanternType);
|
||||
Lantern lanternData = (Lantern)lanternBlock.getBlockData();
|
||||
lanternData.setHanging(false);
|
||||
lanternBlock.setBlockData(lanternData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user