TeamHalle #6
@ -221,8 +221,10 @@ public class NPC {
|
|||||||
|
|
||||||
private void move(Player player) {
|
private void move(Player player) {
|
||||||
TinyProtocol.instance.sendPacket(player, headRotation);
|
TinyProtocol.instance.sendPacket(player, headRotation);
|
||||||
|
if (move != null) {
|
||||||
TinyProtocol.instance.sendPacket(player, move);
|
TinyProtocol.instance.sendPacket(player, move);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
display.delete();
|
display.delete();
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.lobby.LobbySystem;
|
|||||||
import de.steamwar.lobby.display.NPC;
|
import de.steamwar.lobby.display.NPC;
|
||||||
import de.steamwar.lobby.listener.BasicListener;
|
import de.steamwar.lobby.listener.BasicListener;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -35,12 +36,37 @@ import org.bukkit.event.entity.EntityInteractEvent;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class TeamPlayer extends BasicListener {
|
public class TeamPlayer extends BasicListener {
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class Cuboid {
|
||||||
|
private double x1;
|
||||||
|
private double y1;
|
||||||
|
private double z1;
|
||||||
|
private double x2;
|
||||||
|
private double y2;
|
||||||
|
private double z2;
|
||||||
|
|
||||||
|
public boolean contains(Location location) {
|
||||||
|
return location.getX() >= x1 && location.getX() <= x2 && location.getY() >= y1 && location.getY() <= y2 && location.getZ() >= z1 && location.getZ() <= z2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final List<Cuboid> cuboids = new ArrayList<>();
|
||||||
|
static {
|
||||||
|
cuboids.add(new Cuboid(1509, 52, 1464, 1510, 58, 1469));
|
||||||
|
cuboids.add(new Cuboid(1538, 52, 1464, 1539, 58, 1469));
|
||||||
|
cuboids.add(new Cuboid(1518, 55, 1433, 1530, 60, 1434));
|
||||||
|
cuboids.add(new Cuboid(1587, 52, 1471, 1588, 56, 1475));
|
||||||
|
cuboids.add(new Cuboid(1479, 52, 1461, 1478, 56, 1463));
|
||||||
|
}
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
private static final Map<String, NPC> entities = new HashMap<>();
|
private static final Map<String, NPC> entities = new HashMap<>();
|
||||||
|
|
||||||
@ -53,7 +79,7 @@ public class TeamPlayer extends BasicListener {
|
|||||||
villager.setInvulnerable(true);
|
villager.setInvulnerable(true);
|
||||||
villager.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false, false, false));
|
villager.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false, false, false));
|
||||||
villager.setCustomName(name);
|
villager.setCustomName(name);
|
||||||
villager.setProfession(Villager.Profession.NITWIT);
|
villager.setProfession(Villager.Profession.NONE);
|
||||||
entities.put(name, npc);
|
entities.put(name, npc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +111,25 @@ public class TeamPlayer extends BasicListener {
|
|||||||
world.getEntitiesByClasses(Villager.class).forEach(entity -> {
|
world.getEntitiesByClasses(Villager.class).forEach(entity -> {
|
||||||
NPC npc = entities.get(entity.getName());
|
NPC npc = entities.get(entity.getName());
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
|
if (illegalLocation(entity.getLocation())) {
|
||||||
|
entity.teleport(npc.getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
npc.setLocation(entity.getLocation());
|
npc.setLocation(entity.getLocation());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1L, 1L);
|
}, 1L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean illegalLocation(Location location) {
|
||||||
|
for (Cuboid cuboid : cuboids) {
|
||||||
|
if (cuboid.contains(location)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityInteract(EntityInteractEvent event) {
|
public void onEntityInteract(EntityInteractEvent event) {
|
||||||
if (event.getEntityType() == EntityType.VILLAGER) {
|
if (event.getEntityType() == EntityType.VILLAGER) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren