package eu.univento.teamvento.listener; import eu.univento.core.api.player.CustomPlayer; import eu.univento.teamvento.utils.Plot; import eu.univento.teamvento.utils.PlotManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import java.util.ArrayList; import java.util.List; public class SignInteract implements Listener { @EventHandler public void onInteract(PlayerInteractEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if(e.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && e.getClickedBlock().getLocation().add(0.0D, -1.0D, 0.0D).getBlock().getType() == Material.COMMAND) { e.setCancelled(true); if (PlotManager.hasPlot(p)) { Plot plot = PlotManager.getPlotByPlayer(p); assert plot != null; Location loc = plot.getSpawn(); p.teleport(new Location(Bukkit.getWorld("plots"), loc.getX(), loc.getY(), loc.getZ(), 89.0F, 6.0F)); } else { PlotManager.createPlot(p); } } if(e.getClickedBlock().getType() == Material.SPONGE) { generateSpiral(0, 0, 10); } } } public void generateSpiral(int midX, int midZ, int radius) { int x = midX; int z = midZ; int f = 1; List points = new ArrayList<>(); while(f <= radius * 2) { for(int e = z + f; z < e; z++) { points.add(new Point(x, z)); } for(int e = x + f; x < e; x++) { points.add(new Point(x, z)); } f++; for(int e = z - f; z > e; z--) { points.add(new Point(x, z)); } for(int e = x - f; x > e; x--) { points.add(new Point(x, z)); } f++; } for(int e = z + f - 1; z < e; z++) { points.add(new Point(x, z)); } for(Point point : points) new Location(Bukkit.getWorld("plots"), point.getX(), 100, point.getZ()).getBlock().setType(Material.BEDROCK); } public class Point{ private int x; private int z; public int getX() { return this.x; } public int getZ() { return this.z; } public Point(int x, int z) { this.x = x; this.z = z; } @Override public String toString() { return "{" + this.x + " | " + this.z + "}"; } } }