mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-23 07:41:29 +01:00
Refactor common code, add missing condition
This commit is contained in:
parent
43ff6370b2
commit
7743763d3c
@ -107,7 +107,7 @@ import net.citizensnpcs.util.Util;
|
|||||||
public class EventListen implements Listener {
|
public class EventListen implements Listener {
|
||||||
private final Map<String, NPCRegistry> registries;
|
private final Map<String, NPCRegistry> registries;
|
||||||
private final SkinUpdateTracker skinUpdateTracker;
|
private final SkinUpdateTracker skinUpdateTracker;
|
||||||
private final ListMultimap<ChunkCoord, NPC> toRespawn = ArrayListMultimap.create();
|
private final ListMultimap<ChunkCoord, NPC> toRespawn = ArrayListMultimap.create(64, 4);
|
||||||
|
|
||||||
EventListen(Map<String, NPCRegistry> registries) {
|
EventListen(Map<String, NPCRegistry> registries) {
|
||||||
this.registries = registries;
|
this.registries = registries;
|
||||||
|
@ -10,6 +10,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -110,6 +112,16 @@ public class Util {
|
|||||||
return "CIT-" + id.toString().replace("-", "").substring(0, 12);
|
return "CIT-" + id.toString().replace("-", "").substring(0, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean inBlock(Entity entity) {
|
||||||
|
// TODO: bounding box aware?
|
||||||
|
Location loc = entity.getLocation(AT_LOCATION);
|
||||||
|
if (!Util.isLoaded(loc)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Block in = loc.getBlock();
|
||||||
|
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAlwaysFlyable(EntityType type) {
|
public static boolean isAlwaysFlyable(EntityType type) {
|
||||||
if (type.name().toLowerCase().equals("vex") || type.name().toLowerCase().equals("parrot")
|
if (type.name().toLowerCase().equals("vex") || type.name().toLowerCase().equals("parrot")
|
||||||
|| type.name().toLowerCase().equals("bee") || type.name().toLowerCase().equals("phantom"))
|
|| type.name().toLowerCase().equals("bee") || type.name().toLowerCase().equals("phantom"))
|
||||||
|
@ -7,8 +7,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -246,15 +244,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -7,8 +7,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -277,15 +275,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -8,8 +8,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -297,15 +295,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -8,8 +8,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -276,15 +274,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -7,8 +7,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -267,15 +265,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -7,8 +7,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -268,15 +266,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -9,8 +9,6 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -282,15 +280,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
|
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -246,15 +245,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inBlock() {
|
public boolean inBlock() {
|
||||||
if (npc == null || noclip) {
|
if (npc == null || noclip || isSleeping()) {
|
||||||
return super.inBlock();
|
return super.inBlock();
|
||||||
}
|
}
|
||||||
Location loc = getBukkitEntity().getLocation(LOADED_LOCATION);
|
return Util.inBlock(getBukkitEntity());
|
||||||
if (!Util.isLoaded(loc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
org.bukkit.block.Block in = loc.getBlock();
|
|
||||||
return in.getType().isSolid() && in.getRelative(BlockFace.UP).getType().isSolid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(MinecraftServer minecraftServer) {
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user