96 lines
4.0 KiB
Java
96 lines
4.0 KiB
Java
package eu.univento.teamvento.listener;
|
|
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.Hologram;
|
|
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)) {
|
|
Location loc = PlotManager.getPlotByPlayer(p).getSpawn();
|
|
p.teleport(new Location(Bukkit.getWorld("plots"), loc.getX(), loc.getY(), loc.getZ(), 89.0F, 6.0F));
|
|
} else {
|
|
p.sendTitle("§eBitte warten", "§aDein Grundstück wird generiert");
|
|
JoinQuit.holograms.get(p).hidePlayer(p);
|
|
Hologram holo = new Hologram(new String[]{"§eZu deinem Plot teleportieren", "|", "|", "▼"}, Config.readLocation("Build.Locs.Holo"));
|
|
holo.showPlayer(p);
|
|
Plot plot = PlotManager.createPlot(p);
|
|
PlotManager.createPlot(plot);
|
|
PlotManager.generatePlot(plot);
|
|
p.setFlying(true);
|
|
Location loc = plot.getSpawn();
|
|
p.teleport(new Location(Bukkit.getWorld("plots"), loc.getX(), loc.getY(), loc.getZ(), 89.0F, 6.0F));
|
|
|
|
}
|
|
}
|
|
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<Point> points = new ArrayList<>();
|
|
while(f <= radius * 2) { // der Radius ist Länge der Strecke zwischen dem Rand und dem Mittelpunkt ohne die Mitte selbst, in deinem Beispiel 2.
|
|
for(int e = z + f; z < e; z++) { // nach oben
|
|
points.add(new Point(x, z));
|
|
}
|
|
for(int e = x + f; x < e; x++) { // nach rechts
|
|
points.add(new Point(x, z));
|
|
}
|
|
f++; // die Linie muss ja eins länger sein, sonst würde es sich überschneiden
|
|
for(int e = z - f; z > e; z--) { // nach unten
|
|
points.add(new Point(x, z));
|
|
}
|
|
for(int e = x - f; x > e; x--) { // nach links
|
|
points.add(new Point(x, z));
|
|
}
|
|
f++; // dasselbe wie oben
|
|
} // dann alles von vorne, bis man in der unteren linken Ecke mit dem vorgegebenen Radius angelangt ist.
|
|
for(int e = z + f - 1; z < e; z++) { // nach oben damit die Spirale fertigestellt wird
|
|
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 + "}";
|
|
}
|
|
}
|
|
} |