Files
src
build.gradle
settings.gradle
Code
4 190
src/main/java/com/kodari/benbow/BenbowInnPlugin.java
package com.kodari.benbow;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class BenbowInnPlugin extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
if (getCommand("benbow") != null) {
getCommand("benbow").setExecutor(this);
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can build the Benbow Inn.");
return true;
}
if (args.length == 0 || !args[0].equalsIgnoreCase("build")) {
player.sendMessage(ChatColor.GOLD + "Usage: " + ChatColor.YELLOW + "/benbow build");
return true;
}
buildInn(player.getLocation().getBlock().getLocation());
player.sendMessage(ChatColor.AQUA + "The Benbow Inn has been built beneath the stars.");
return true;
}
private void buildInn(Location origin) {
World world = origin.getWorld();
if (world == null) {
return;
}
int ox = origin.getBlockX();
int oy = origin.getBlockY();
int oz = origin.getBlockZ();
Material air = material("AIR");
Material foundation = material("COBBLESTONE");
Material floor = material("SPRUCE_PLANKS");
Material wall = material("DARK_OAK_PLANKS");
Material beam = material("DARK_OAK_LOG");
Material roof = material("DARK_OAK_PLANKS");
Material glass = material("GLASS_PANE");
Material brick = material("BRICKS");
Material fence = material("SPRUCE_FENCE");
Material barrel = material("BARREL");
Material bookshelf = material("BOOKSHELF");
Material lantern = material("LANTERN");
Material glowstone = material("GLOWSTONE");
Material sign = material("OAK_SIGN");
fill(world, ox - 7, ox + 7, oy + 1, oy + 8, oz - 1, oz + 11, air);
fill(world, ox - 7, ox + 7, oy, oy, oz - 1, oz + 11, foundation);
fill(world, ox - 6, ox + 6, oy, oy, oz, oz + 10, floor);
fill(world, ox - 6, ox - 6, oy + 1, oy + 5, oz, oz + 10, wall);
fill(world, ox + 6, ox + 6, oy + 1, oy + 5, oz, oz + 10, wall);
fill(world, ox - 5, ox + 5, oy + 1, oy + 5, oz + 10, oz + 10, wall);
fill(world, ox - 5, ox + 5, oy + 1, oy + 5, oz, oz, wall);
fill(world, ox - 5, ox + 5, oy + 4, oy + 4, oz + 1, oz + 9, beam);
fill(world, ox - 5, ox + 5, oy + 5, oy + 5, oz + 1, oz + 9, beam);
fill(world, ox - 6, ox - 6, oy + 5, oy + 5, oz, oz + 10, beam);
fill(world, ox + 6, ox + 6, oy + 5, oy + 5, oz, oz + 10, beam);
place(world, ox, oy + 1, oz, air);
place(world, ox, oy + 2, oz, air);
place(world, ox - 4, oy + 2, oz, glass);
place(world, ox - 3, oy + 2, oz, glass);
place(world, ox + 3, oy + 2, oz, glass);
place(world, ox + 4, oy + 2, oz, glass);
place(world, ox - 6, oy + 2, oz + 3, glass);
place(world, ox - 6, oy + 3, oz + 3, glass);
place(world, ox + 6, oy + 2, oz + 3, glass);
place(world, ox + 6, oy + 3, oz + 3, glass);
place(world, ox - 6, oy + 2, oz + 7, glass);
place(world, ox - 6, oy + 3, oz + 7, glass);
place(world, ox + 6, oy + 2, oz + 7, glass);
place(world, ox + 6, oy + 3, oz + 7, glass);
fill(world, ox - 7, ox + 7, oy + 6, oy + 6, oz - 1, oz + 11, roof);
fill(world, ox - 6, ox + 6, oy + 7, oy + 7, oz, oz + 10, roof);
fill(world, ox - 5, ox + 5, oy + 8, oy + 8, oz + 1, oz + 9, roof);
fill(world, ox + 3, ox + 5, oy + 6, oy + 8, oz + 7, oz + 9, brick);
fill(world, ox - 4, ox - 4, oy + 1, oy + 3, oz + 2, oz + 2, fence);
fill(world, ox + 4, ox + 4, oy + 1, oy + 3, oz + 2, oz + 2, fence);
place(world, ox - 4, oy + 1, oz + 5, barrel);
place(world, ox - 3, oy + 1, oz + 5, barrel);
place(world, ox - 5, oy + 1, oz + 8, bookshelf);
place(world, ox - 4, oy + 1, oz + 8, bookshelf);
place(world, ox + 4, oy + 1, oz + 8, bookshelf);
place(world, ox + 5, oy + 1, oz + 8, bookshelf);
place(world, ox, oy + 5, oz + 5, glowstone);
place(world, ox - 5, oy + 4, oz + 1, lantern);
place(world, ox + 5, oy + 4, oz + 1, lantern);
place(world, ox - 5, oy + 4, oz + 9, lantern);
place(world, ox + 5, oy + 4, oz + 9, lantern);
Block signBlock = world.getBlockAt(ox, oy + 3, oz - 1);
signBlock.setType(sign, false);
if (signBlock.getState() instanceof Sign innSign) {
innSign.setLine(0, ChatColor.DARK_AQUA + "Benbow");
innSign.setLine(1, ChatColor.GOLD + "Inn");
innSign.setLine(2, ChatColor.GRAY + "Est. " + ChatColor.WHITE + "X");
innSign.update(true, false);
}
}
private void fill(World world, int minX, int maxX, int minY, int maxY, int minZ, int maxZ, Material material) {
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
place(world, x, y, z, material);
}
}
}
}
private void place(World world, int x, int y, int z, Material material) {
world.getBlockAt(x, y, z).setType(material, false);
}
private Material material(String name) {
return XMaterial.matchXMaterial(name)
.map(XMaterial::parseMaterial)
.orElseThrow(() -> new IllegalStateException("Unsupported material: " + name));
}
}