Files
src
build.gradle
generate_schem.py
settings.gradle
Code
6 361
src/main/java/com/kodari/ragebox/RageBoxPlugin.java
package com.kodari.ragebox;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
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;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
public final class RageBoxPlugin extends JavaPlugin implements CommandExecutor {
private static final int WIDTH = 54;
private static final int HEIGHT = 40;
private static final int SCALE = 2;
private static final Map<Character, String[]> FONT = new HashMap<>();
static {
FONT.put('A', new String[]{"01110", "11011", "11011", "11111", "11011", "11011", "11011"});
FONT.put('B', new String[]{"11110", "11011", "11011", "11110", "11011", "11011", "11110"});
FONT.put('E', new String[]{"11111", "11000", "11000", "11110", "11000", "11000", "11111"});
FONT.put('G', new String[]{"01111", "11000", "11000", "11011", "11011", "11011", "01111"});
FONT.put('O', new String[]{"01110", "11011", "11011", "11011", "11011", "11011", "01110"});
FONT.put('R', new String[]{"11110", "11011", "11011", "11110", "11010", "11011", "11011"});
FONT.put('X', new String[]{"11011", "11011", "01110", "00100", "01110", "11011", "11011"});
}
@Override
public void onEnable() {
saveDefaultConfig();
if (getCommand("ragebox") != null) {
getCommand("ragebox").setExecutor(this);
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("ragebox.reload")) {
sender.sendMessage(ChatColor.RED + "У вас нет прав на перезагрузку плагина.");
return true;
}
reloadConfig();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "RageBox перезагружен.");
return true;
}
if (!(sender instanceof Player player)) {
sender.sendMessage("Команду может выполнить только игрок.");
return true;
}
Material purple = Material.matchMaterial("PURPLE_CONCRETE");
Material black = Material.matchMaterial("BLACK_CONCRETE");
if (purple == null || black == null) {
player.sendMessage(ChatColor.RED + "Не найдены PURPLE_CONCRETE или BLACK_CONCRETE.");
return true;
}
World world = player.getWorld();
Vector forward = player.getLocation().getDirection().setY(0);
if (forward.lengthSquared() == 0) {
forward.setZ(1);
}
forward.normalize();
Vector right = new Vector(-forward.getZ(), 0, forward.getX());
Vector center = player.getLocation().toVector().add(forward.multiply(getConfig().getDouble("placement.distance", 12.0)));
Vector origin = center.clone().subtract(right.clone().multiply(WIDTH / 2.0));
int baseY = player.getLocation().getBlockY() + getConfig().getInt("placement.height-offset", 2);
if (baseY < world.getMinHeight() || baseY + HEIGHT >= world.getMaxHeight()) {
player.sendMessage(ChatColor.RED + "Недостаточно места по высоте для надписи.");
return true;
}
drawWord(world, origin, right, forward, baseY, "RAGE", 23, purple, black);
drawWord(world, origin, right, forward, baseY, "BOX", 5, purple, black);
player.sendMessage(ChatColor.LIGHT_PURPLE + "RAGE BOX создан! " + ChatColor.GRAY
+ "Размер: примерно " + WIDTH + "x" + HEIGHT + ".");
return true;
}
private void drawWord(World world, Vector origin, Vector right, Vector forward, int baseY, String word, int bottom,
Material purple, Material black) {
int startX = (WIDTH - wordWidth(word)) / 2;
for (int letterIndex = 0; letterIndex < word.length(); letterIndex++) {
String[] glyph = FONT.get(word.charAt(letterIndex));
int letterX = startX + letterIndex * 6 * SCALE;
for (int row = 0; row < glyph.length; row++) {
for (int column = 0; column < glyph[row].length(); column++) {
if (glyph[row].charAt(column) != '1') {
continue;
}
int x = letterX + column * SCALE;
int y = bottom + (6 - row) * SCALE;
fill(world, origin, right, forward, baseY, x - 1, y - 1, 0,
SCALE + 2, SCALE + 2, 1, black);
fill(world, origin, right, forward, baseY, x, y, 0,
SCALE, SCALE, 1, purple);
}
}
}
}
private int wordWidth(String word) {
return (word.length() * 5 + word.length() - 1) * SCALE;
}
private void fill(World world, Vector origin, Vector right, Vector forward, int baseY,
int x, int y, int depth, int width, int height, int length, Material material) {
for (int px = x; px < x + width; px++) {
for (int py = y; py < y + height; py++) {
for (int pz = depth; pz < depth + length; pz++) {
Vector position = origin.clone()
.add(right.clone().multiply(px))
.add(forward.clone().multiply(pz));
Block block = world.getBlockAt((int) Math.round(position.getX()), baseY + py,
(int) Math.round(position.getZ()));
block.setType(material, false);
}
}
}
}
}