mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 01:27:33 +01:00
Implement helper methods and allow hologram lines to be items
This commit is contained in:
parent
da71b8d811
commit
750f8e2e4c
@ -2312,6 +2312,25 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, swim ? Messages.SWIMMING_SET : Messages.SWIMMING_UNSET, npc.getName());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "target [name|UUID] (-a[ggressive])",
|
||||
desc = "Target a given entity",
|
||||
modifiers = { "target" },
|
||||
flags = "a",
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "citizens.npc.target")
|
||||
public void target(CommandContext args, Player sender, NPC npc) {
|
||||
Entity toTarget = args.argsLength() < 2 ? sender : Bukkit.getPlayer(args.getString(1));
|
||||
if (toTarget == null) {
|
||||
toTarget = Bukkit.getEntity(UUID.fromString(args.getString(1)));
|
||||
}
|
||||
if (toTarget != null) {
|
||||
npc.getNavigator().setTarget(toTarget, args.hasFlag('a'));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "targetable",
|
||||
|
@ -9,9 +9,11 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
@ -21,6 +23,7 @@ import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.DespawnReason;
|
||||
import net.citizensnpcs.api.event.NPCCreateEvent;
|
||||
import net.citizensnpcs.api.event.SpawnReason;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCDataStore;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
@ -51,6 +54,13 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
return createNPC(type, UUID.randomUUID(), generateUniqueId(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC createNPC(EntityType type, String name, Location loc) {
|
||||
NPC npc = createNPC(type, name);
|
||||
npc.spawn(loc, SpawnReason.PLUGIN);
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC createNPC(EntityType type, UUID uuid, int id, String name) {
|
||||
Preconditions.checkNotNull(name, "name cannot be null");
|
||||
@ -72,6 +82,20 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC createNPCUsingItem(EntityType type, String name, ItemStack item) {
|
||||
NPC npc = createNPC(type, name);
|
||||
if (type == EntityType.DROPPED_ITEM || type == EntityType.FALLING_BLOCK || type == EntityType.GLOW_ITEM_FRAME
|
||||
|| type == EntityType.ITEM_FRAME) {
|
||||
npc.data().set(NPC.ITEM_ID_METADATA, item.getType().name());
|
||||
npc.data().set(NPC.ITEM_DATA_METADATA, (int) item.getData().getData());
|
||||
npc.data().set(NPC.ITEM_AMOUNT_METADATA, item.getAmount());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Not an item entity type");
|
||||
}
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(NPC npc) {
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
|
@ -2,12 +2,16 @@ package net.citizensnpcs.trait;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -80,6 +84,21 @@ public class HologramTrait extends Trait {
|
||||
getEntityHeight()
|
||||
+ (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset),
|
||||
0));
|
||||
Matcher itemMatcher = ITEM_MATCHER.matcher(line);
|
||||
if (itemMatcher.matches()) {
|
||||
Material item = Material.matchMaterial(itemMatcher.group(1), false);
|
||||
NPC itemNPC = registry.createNPCUsingItem(EntityType.DROPPED_ITEM, "", new ItemStack(item, 1));
|
||||
itemNPC.spawn(currentLoc);
|
||||
((ArmorStand) hologramNPC.getEntity()).addPassenger(itemNPC.getEntity());
|
||||
itemNPC.addRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!itemNPC.isSpawned() || !itemNPC.getEntity().isInsideVehicle()) {
|
||||
itemNPC.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return hologramNPC;
|
||||
}
|
||||
|
||||
@ -221,6 +240,9 @@ public class HologramTrait extends Trait {
|
||||
break;
|
||||
}
|
||||
String text = lines.get(i);
|
||||
if (ITEM_MATCHER.matcher(text).matches()) {
|
||||
text = null;
|
||||
}
|
||||
if (text != null && !ChatColor.stripColor(Colorizer.parseColors(text)).isEmpty()) {
|
||||
hologramNPC.setName(Placeholders.replace(text, null, npc));
|
||||
hologramNPC.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, true);
|
||||
@ -281,4 +303,6 @@ public class HologramTrait extends Trait {
|
||||
BOTTOM_UP,
|
||||
TOP_DOWN;
|
||||
}
|
||||
|
||||
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:(.*?)>");
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ public class ItemController extends AbstractEntityController {
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ public class ItemController extends AbstractEntityController {
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ public class ItemController extends AbstractEntityController {
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -38,14 +38,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -40,14 +40,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -40,14 +40,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -71,14 +71,6 @@ public class ItemFrameController extends MobEntityController {
|
||||
return npc == null ? super.d(save) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void h(double x, double y, double z) {
|
||||
Vector vector = Util.callPushEvent(npc, x, y, z);
|
||||
if (vector != null) {
|
||||
super.h(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
||||
@ -92,6 +84,14 @@ public class ItemFrameController extends MobEntityController {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void h(double x, double y, double z) {
|
||||
Vector vector = Util.callPushEvent(npc, x, y, z);
|
||||
if (vector != null) {
|
||||
super.h(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean survives() {
|
||||
return npc == null || !npc.isProtected() ? super.survives() : true;
|
||||
@ -118,6 +118,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -40,14 +40,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ public class GlowItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1));
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -40,14 +40,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class FallingBlockController extends AbstractEntityController {
|
||||
// TODO: how to incorporate this - probably delete?
|
||||
if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = CraftMagicNumbers.getBlock(Material.getMaterial(
|
||||
npc.data().<String> get(NPC.ITEM_ID_METADATA, npc.data().<String> get("falling-block-id"))));
|
||||
npc.data().<String> get(NPC.ITEM_ID_METADATA, npc.data().<String> get("falling-block-id")), false));
|
||||
}
|
||||
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
id.defaultBlockState());
|
||||
|
@ -113,13 +113,10 @@ public class GlowItemFrameController extends MobEntityController {
|
||||
public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1));
|
||||
getItem().setType(Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false));
|
||||
getItem().setDurability(npc.data().<Short> get(NPC.ITEM_DATA_METADATA,
|
||||
npc.data().<Short> get("falling-block-data", (short) 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,14 +40,15 @@ public class ItemController extends AbstractEntityController {
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA), false);
|
||||
}
|
||||
if (id == Material.AIR) {
|
||||
id = Material.STONE;
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -112,13 +112,12 @@ public class ItemFrameController extends MobEntityController {
|
||||
public ItemFrameNPC(EntityItemFrameNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
Material id = Material.STONE;
|
||||
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
getItem().setType(Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false));
|
||||
getItem().setDurability(npc.data().<Short> get(NPC.ITEM_DATA_METADATA,
|
||||
npc.data().<Short> get("falling-block-data", (short) 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,20 +1,12 @@
|
||||
package net.citizensnpcs.nms.v1_18_R1.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.StatType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class EmptyServerStatsCounter extends ServerStatsCounter {
|
||||
@ -22,14 +14,6 @@ public class EmptyServerStatsCounter extends ServerStatsCounter {
|
||||
super(null, CitizensAPI.getDataFolder());
|
||||
}
|
||||
|
||||
private Set<Stat<?>> getDirty() {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
private <T> Optional<Stat<T>> getStat(StatType<T> statisticwrapper, String s) {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAllDirty() {
|
||||
}
|
||||
@ -55,12 +39,4 @@ public class EmptyServerStatsCounter extends ServerStatsCounter {
|
||||
return "{\"stats\":{},\"DataVersion\":" + Integer.valueOf(SharedConstants.getCurrentVersion().getWorldVersion())
|
||||
+ "}";
|
||||
}
|
||||
|
||||
private static CompoundTag fromJson(JsonObject jsonobject) {
|
||||
return new CompoundTag();
|
||||
}
|
||||
|
||||
private static <T> ResourceLocation getKey(Stat<T> statistic) {
|
||||
return statistic.getType().getRegistry().getKey(statistic.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -1681,7 +1681,7 @@ public class NMSImpl implements NMSBridge {
|
||||
NPC npc = ((NPCHolder) minecart).getNPC();
|
||||
if (npc == null)
|
||||
return;
|
||||
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
|
||||
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""), false);
|
||||
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0); // TODO: migration for this
|
||||
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);
|
||||
minecart.setCustomDisplay(mat != null);
|
||||
|
@ -11,7 +11,7 @@ import net.minecraft.world.level.pathfinder.Node;
|
||||
import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
|
||||
public abstract class PlayerNodeEvaluatorBase extends NodeEvaluator {
|
||||
protected final Int2ObjectMap<Node> c = new Int2ObjectOpenHashMap();
|
||||
protected final Int2ObjectMap<Node> c = new Int2ObjectOpenHashMap<Node>();
|
||||
protected boolean canFloat;
|
||||
protected boolean canOpenDoors;
|
||||
protected boolean canPassDoors;
|
||||
|
@ -9,7 +9,6 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@ -80,7 +79,6 @@ public class PlayerPathfinder extends PathFinder {
|
||||
var1.f = var1.h;
|
||||
this.openSet.clear();
|
||||
this.openSet.insert(var1);
|
||||
ImmutableSet immutableSet = ImmutableSet.of();
|
||||
int var8 = 0;
|
||||
Set<Target> var9 = Sets.newHashSetWithExpectedSize(var6.size());
|
||||
int var10 = (int) (this.maxVisitedNodes * var5);
|
||||
|
@ -45,7 +45,8 @@ public class ItemController extends AbstractEntityController {
|
||||
Messaging.severe(npc.getId(), "invalid Material: converted to stone");
|
||||
}
|
||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id,
|
||||
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ public class ItemFrameController extends MobEntityController {
|
||||
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||
}
|
||||
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) {
|
||||
getItem().setAmount(npc.data().<Integer> get(NPC.ITEM_AMOUNT_METADATA));
|
||||
}
|
||||
getItem().setType(id);
|
||||
getItem().setDurability((short) data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user