Fix some issues with ShopTrait item costs/results and add NBT filter API. Adjust /npc item to be more flexible.

This commit is contained in:
fullwall 2022-12-03 18:21:46 +08:00
parent c68a7ad82f
commit ede598cc9b
57 changed files with 971 additions and 617 deletions

View File

@ -164,8 +164,12 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
if (registry == null) if (registry == null)
continue; continue;
if (save) { if (save) {
if (registry == npcRegistry) {
storeNPCs(false);
} else {
registry.saveToStore(); registry.saveToStore();
} }
}
registry.despawnNPCs(DespawnReason.RELOAD); registry.despawnNPCs(DespawnReason.RELOAD);
} }
} }

View File

@ -34,7 +34,6 @@ import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit; import org.bukkit.entity.Rabbit;
@ -124,6 +123,7 @@ import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.Poses; import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType; import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.RotationTrait;
import net.citizensnpcs.trait.ScoreboardTrait; import net.citizensnpcs.trait.ScoreboardTrait;
import net.citizensnpcs.trait.ScriptTrait; import net.citizensnpcs.trait.ScriptTrait;
import net.citizensnpcs.trait.SheepTrait; import net.citizensnpcs.trait.SheepTrait;
@ -133,7 +133,6 @@ import net.citizensnpcs.trait.SkinLayers;
import net.citizensnpcs.trait.SkinLayers.Layer; import net.citizensnpcs.trait.SkinLayers.Layer;
import net.citizensnpcs.trait.SkinTrait; import net.citizensnpcs.trait.SkinTrait;
import net.citizensnpcs.trait.SlimeSize; import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.RotationTrait;
import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.WitherTrait; import net.citizensnpcs.trait.WitherTrait;
import net.citizensnpcs.trait.WolfModifiers; import net.citizensnpcs.trait.WolfModifiers;
@ -1148,7 +1147,7 @@ public class NPCCommands {
max = 1, max = 1,
permission = "citizens.npc.id") permission = "citizens.npc.id")
public void id(CommandContext args, CommandSender sender, NPC npc) { public void id(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, npc.getId()); sender.sendMessage(Integer.toString(npc.getId()));
} }
@Command( @Command(
@ -1165,38 +1164,29 @@ public class NPCCommands {
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "item [item] (data)", usage = "item (item) (amount) (data)",
desc = "Sets the NPC's item", desc = "Sets the NPC's item",
modifiers = { "item", }, modifiers = { "item", },
min = 2, min = 1,
max = 3, max = 3,
flags = "", flags = "h",
permission = "citizens.npc.item") permission = "citizens.npc.item")
@Requirements( @Requirements(selected = true, ownership = true)
selected = true, public void item(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Material mat, @Arg(2) Integer amount,
ownership = true, @Arg(3) Byte data) throws CommandException {
types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME, EntityType.FALLING_BLOCK }) EntityType type = npc.getOrAddTrait(MobType.class).getType();
public void item(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Material mat) throws CommandException { if (!type.name().contains("ITEM_FRAME") && type != EntityType.DROPPED_ITEM && type != EntityType.FALLING_BLOCK)
if (mat == null) throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE);
ItemStack stack = args.hasFlag('h') ? ((Player) sender).getItemInHand()
: new ItemStack(mat, amount == null ? 1 : amount, data == null ? 0 : data);
if (mat == null && !args.hasFlag('h'))
throw new CommandException(Messages.UNKNOWN_MATERIAL); throw new CommandException(Messages.UNKNOWN_MATERIAL);
int data = args.getInteger(2, 0); npc.setItemProvider(() -> stack);
npc.data().setPersistent(NPC.ITEM_ID_METADATA, mat.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
switch (npc.getEntity().getType()) {
case DROPPED_ITEM:
((org.bukkit.entity.Item) npc.getEntity()).getItemStack().setType(mat);
break;
case ITEM_FRAME:
((ItemFrame) npc.getEntity()).setItem(new ItemStack(mat, 1));
break;
default:
break;
}
if (npc.isSpawned()) { if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN); npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN); npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
} }
Messaging.sendTr(sender, Messages.ITEM_SET, Util.prettyEnum(mat)); Messaging.sendTr(sender, Messages.ITEM_SET, Util.prettyEnum(stack.getType()));
} }
@Command( @Command(

View File

@ -36,9 +36,7 @@ public class NPCConfigurator extends InventoryMenuPage {
ConfiguratorInfo info = entry.getValue(); ConfiguratorInfo info = entry.getValue();
InventoryMenuSlot slot = ctx.getSlot(entry.getKey()); InventoryMenuSlot slot = ctx.getSlot(entry.getKey());
slot.setItemStack(new ItemStack(info.material, 1)); slot.setItemStack(new ItemStack(info.material, 1));
slot.setClickHandler((evt) -> { slot.setClickHandler((evt) -> info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, evt)));
info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, evt));
});
info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, null)); info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, null));
} }
} }

View File

@ -91,9 +91,10 @@ public class CitizensNPCRegistry implements NPCRegistry {
NPC npc = createNPC(type, name); NPC npc = createNPC(type, name);
if (type == EntityType.DROPPED_ITEM || type == EntityType.FALLING_BLOCK || type == EntityType.GLOW_ITEM_FRAME if (type == EntityType.DROPPED_ITEM || type == EntityType.FALLING_BLOCK || type == EntityType.GLOW_ITEM_FRAME
|| type == EntityType.ITEM_FRAME) { || type == EntityType.ITEM_FRAME) {
npc.data().set(NPC.ITEM_ID_METADATA, item.getType().name()); npc.data().set(NPC.Metadata.ITEM_AMOUNT, item.getAmount());
npc.data().set(NPC.ITEM_DATA_METADATA, (int) item.getData().getData()); npc.data().set(NPC.Metadata.ITEM_ID, item.getType().getId());
npc.data().set(NPC.ITEM_AMOUNT_METADATA, item.getAmount()); npc.data().set(NPC.Metadata.ITEM_DATA, item.getData().getData());
npc.setItemProvider(() -> item);
} else { } else {
throw new UnsupportedOperationException("Not an item entity type"); throw new UnsupportedOperationException("Not an item entity type");
} }

View File

@ -73,11 +73,11 @@ public class ShopTrait extends Trait {
} }
public NPCShop getDefaultShop() { public NPCShop getDefaultShop() {
return StoredShops.NPC_SHOPS.computeIfAbsent(npc.getUniqueId().toString(), (s) -> new NPCShop(npc.getName())); return StoredShops.NPC_SHOPS.computeIfAbsent(npc.getUniqueId().toString(), (s) -> new NPCShop(s));
} }
public NPCShop getShop(String name) { public NPCShop getShop(String name) {
return StoredShops.GLOBAL_SHOPS.computeIfAbsent(name, (s) -> new NPCShop(name)); return StoredShops.GLOBAL_SHOPS.computeIfAbsent(name, (s) -> new NPCShop(s));
} }
public void onRightClick(Player player) { public void onRightClick(Player player) {
@ -121,7 +121,7 @@ public class ShopTrait extends Trait {
} }
public String getName() { public String getName() {
return name; return name == null ? "" : name;
} }
public NPCShopPage getOrCreatePage(int page) { public NPCShopPage getOrCreatePage(int page) {
@ -178,7 +178,6 @@ public class ShopTrait extends Trait {
final int idx = i; final int idx = i;
slot.setClickHandler(evt -> { slot.setClickHandler(evt -> {
evt.setCancelled(true);
ctx.clearSlots(); ctx.clearSlots();
NPCShopItem display = item; NPCShopItem display = item;
if (display == null) { if (display == null) {
@ -367,20 +366,16 @@ public class ShopTrait extends Trait {
NPCShopAction oldCost = modified.cost.stream().filter(template::manages).findFirst().orElse(null); NPCShopAction oldCost = modified.cost.stream().filter(template::manages).findFirst().orElse(null);
costItems.getSlots().get(pos) costItems.getSlots().get(pos)
.setItemStack(Util.editTitle(template.createMenuItem(oldCost), title -> title + " Cost")); .setItemStack(Util.editTitle(template.createMenuItem(oldCost), title -> title + " Cost"));
costItems.getSlots().get(pos).setClickHandler(event -> { costItems.getSlots().get(pos).setClickHandler(event -> ctx.getMenu().transition(
event.setCancelled(true); template.createEditor(oldCost, cost -> modified.changeCost(template::manages, cost))));
ctx.getMenu().transition(
template.createEditor(oldCost, cost -> modified.changeCost(template::manages, cost)));
});
NPCShopAction oldResult = modified.result.stream().filter(template::manages).findFirst().orElse(null); NPCShopAction oldResult = modified.result.stream().filter(template::manages).findFirst().orElse(null);
actionItems.getSlots().get(pos) actionItems.getSlots().get(pos)
.setItemStack(Util.editTitle(template.createMenuItem(oldResult), title -> title + " Result")); .setItemStack(Util.editTitle(template.createMenuItem(oldResult), title -> title + " Result"));
actionItems.getSlots().get(pos).setClickHandler(event -> { actionItems.getSlots().get(pos).setClickHandler(event ->
event.setCancelled(true);
ctx.getMenu().transition(template.createEditor(oldResult, ctx.getMenu().transition(template.createEditor(oldResult,
result -> modified.changeResult(template::manages, result))); result -> modified.changeResult(template::manages, result)))
}); );
pos++; pos++;
} }
@ -530,8 +525,8 @@ public class ShopTrait extends Trait {
this.ctx = ctx; this.ctx = ctx;
ctx.getSlot(2).setDescription("<f>Edit shop view permission<br>" + shop.getRequiredPermission()); ctx.getSlot(2).setDescription("<f>Edit shop view permission<br>" + shop.getRequiredPermission());
ctx.getSlot(6).setDescription("<f>Edit shop title<br>" + shop.title); ctx.getSlot(6).setDescription("<f>Edit shop title<br>" + shop.title);
ctx.getSlot(8).setDescription( ctx.getSlot(8)
"<f>Show shop on right click<br>" + (shop.name != null && shop.name.equals(trait.rightClickShop))); .setDescription("<f>Show shop on right click<br>" + shop.getName().equals(trait.rightClickShop));
} }
@MenuSlot(slot = { 0, 4 }, material = Material.FEATHER, amount = 1, title = "<f>Edit shop items") @MenuSlot(slot = { 0, 4 }, material = Material.FEATHER, amount = 1, title = "<f>Edit shop items")
@ -568,13 +563,13 @@ public class ShopTrait extends Trait {
@MenuSlot(slot = { 0, 8 }, material = Material.COMMAND_BLOCK, amount = 1) @MenuSlot(slot = { 0, 8 }, material = Material.COMMAND_BLOCK, amount = 1)
public void onToggleRightClick(InventoryMenuSlot slot, CitizensInventoryClickEvent event) { public void onToggleRightClick(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true); event.setCancelled(true);
if (shop.name != null && shop.name.equals(trait.rightClickShop)) { if (shop.getName().equals(trait.rightClickShop)) {
trait.rightClickShop = null; trait.rightClickShop = null;
} else { } else {
trait.rightClickShop = shop.name; trait.rightClickShop = shop.name;
} }
ctx.getSlot(8).setDescription( ctx.getSlot(8)
"<f>Show shop on right click<br>" + (shop.name != null && shop.name.equals(trait.rightClickShop))); .setDescription("<f>Show shop on right click<br>" + (shop.getName().equals(trait.rightClickShop)));
} }
} }

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.trait.shop;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -19,17 +18,25 @@ import org.bukkit.inventory.meta.Damageable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.citizensnpcs.api.gui.BooleanSlotHandler; import net.citizensnpcs.api.gui.BooleanSlotHandler;
import net.citizensnpcs.api.gui.InputMenus;
import net.citizensnpcs.api.gui.InventoryMenuPage; import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot; import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu; import net.citizensnpcs.api.gui.Menu;
import net.citizensnpcs.api.gui.MenuContext; import net.citizensnpcs.api.gui.MenuContext;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
public class ItemAction extends NPCShopAction { public class ItemAction extends NPCShopAction {
@Persist
public boolean compareSimilarity = false;
@Persist @Persist
public List<ItemStack> items = Lists.newArrayList(); public List<ItemStack> items = Lists.newArrayList();
@Persist @Persist
public List<String> metaFilter = Lists.newArrayList();
@Persist
public boolean requireUndamaged = true; public boolean requireUndamaged = true;
public ItemAction() { public ItemAction() {
@ -44,17 +51,27 @@ public class ItemAction extends NPCShopAction {
} }
private boolean containsItems(Inventory source, BiFunction<ItemStack, Integer, ItemStack> filter) { private boolean containsItems(Inventory source, BiFunction<ItemStack, Integer, ItemStack> filter) {
Map<Material, Integer> required = items.stream() List<Integer> req = items.stream().map(i -> i.getAmount()).collect(Collectors.toList());
.collect(Collectors.toMap(k -> k.getType(), v -> v.getAmount()));
ItemStack[] contents = source.getContents(); ItemStack[] contents = source.getContents();
for (int i = 0; i < contents.length; i++) { for (int i = 0; i < contents.length; i++) {
ItemStack stack = contents[i]; ItemStack stack = contents[i];
if (stack == null || stack.getType() == Material.AIR || !required.containsKey(stack.getType())) if (stack == null || stack.getType() == Material.AIR)
continue; continue;
if (requireUndamaged && stack.getItemMeta() instanceof Damageable if (requireUndamaged && stack.getItemMeta() instanceof Damageable
&& ((Damageable) stack.getItemMeta()).getDamage() != 0) && ((Damageable) stack.getItemMeta()).getDamage() != 0)
continue; continue;
int remaining = required.remove(stack.getType()); for (int j = 0; j < items.size(); j++) {
ItemStack match = items.get(j);
if (req.get(j) <= 0)
continue;
if (match.getType() != stack.getType())
continue;
if (metaFilter.size() > 0 && !metaMatches(match, stack, metaFilter))
continue;
if (compareSimilarity && !match.isSimilar(stack))
continue;
int remaining = req.get(j);
int taken = stack.getAmount() > remaining ? remaining : stack.getAmount(); int taken = stack.getAmount() > remaining ? remaining : stack.getAmount();
ItemStack res = filter.apply(stack, taken); ItemStack res = filter.apply(stack, taken);
if (res == null) { if (res == null) {
@ -62,11 +79,10 @@ public class ItemAction extends NPCShopAction {
} else { } else {
source.setItem(i, res); source.setItem(i, res);
} }
if (remaining - taken > 0) { req.set(j, remaining - taken);
required.put(stack.getType(), remaining - taken);
} }
} }
return required.size() == 0; return req.stream().collect(Collectors.summingInt(n -> n)) <= 0;
} }
@Override @Override
@ -104,19 +120,43 @@ public class ItemAction extends NPCShopAction {
}); });
} }
private boolean metaMatches(ItemStack needle, ItemStack haystack, List<String> meta) {
CompoundTag source = NMS.getNBT(needle);
CompoundTag compare = NMS.getNBT(haystack);
for (String nbt : meta) {
String[] parts = nbt.split("\\.");
Tag acc = source;
Tag cmp = compare;
for (int i = 0; i < parts.length; i++) {
if (acc == null)
return false;
if (cmp == null)
return false;
if (i < parts.length - 1) {
if (!(acc instanceof CompoundTag) || !(cmp instanceof CompoundTag))
return false;
if (parts[i].equals(acc.getName()) && acc.getName().equals(cmp.getName()))
continue;
acc = ((CompoundTag) acc).getValue().get(parts[i]);
cmp = ((CompoundTag) cmp).getValue().get(parts[i]);
continue;
}
if (!acc.getName().equals(parts[i]) || !cmp.getName().equals(parts[i]))
return false;
if (!acc.getValue().equals(cmp.getValue()))
return false;
}
}
return true;
}
@Override @Override
public Transaction take(Entity entity) { public Transaction take(Entity entity) {
if (!(entity instanceof InventoryHolder)) if (!(entity instanceof InventoryHolder))
return Transaction.fail(); return Transaction.fail();
Inventory source = ((InventoryHolder) entity).getInventory(); Inventory source = ((InventoryHolder) entity).getInventory();
return Transaction.create(() -> { return Transaction.create(() -> {
boolean contains = containsItems(source, (s, t) -> s); return containsItems(source, (stack, taken) -> stack);
for (ItemStack item : items) {
if (item.hasItemMeta() && !source.contains(item)) {
contains = false;
}
}
return contains;
}, () -> { }, () -> {
containsItems(source, (stack, taken) -> { containsItems(source, (stack, taken) -> {
if (stack.getAmount() == taken) { if (stack.getAmount() == taken) {
@ -151,7 +191,7 @@ public class ItemAction extends NPCShopAction {
for (int i = 0; i < 3 * 9; i++) { for (int i = 0; i < 3 * 9; i++) {
InventoryMenuSlot slot = ctx.getSlot(i); InventoryMenuSlot slot = ctx.getSlot(i);
slot.clear(); slot.clear();
if (base != null && i < base.items.size()) { if (i < base.items.size()) {
slot.setItemStack(base.items.get(i).clone()); slot.setItemStack(base.items.get(i).clone());
} }
slot.setClickHandler(event -> { slot.setClickHandler(event -> {
@ -159,11 +199,22 @@ public class ItemAction extends NPCShopAction {
event.setCurrentItem(event.getCursorNonNull()); event.setCurrentItem(event.getCursorNonNull());
}); });
} }
ctx.getSlot(3 * 9 + 1).setItemStack(new ItemStack(Material.ANVIL), "Must have no damage");
ctx.getSlot(3 * 9 + 1).setItemStack(new ItemStack(Material.ANVIL), "Must have no damage",
base.requireUndamaged ? ChatColor.GREEN + "On" : ChatColor.RED + "Off");
ctx.getSlot(3 * 9 + 1).addClickHandler(new BooleanSlotHandler((res) -> { ctx.getSlot(3 * 9 + 1).addClickHandler(new BooleanSlotHandler((res) -> {
base.requireUndamaged = res; base.requireUndamaged = res;
return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"; return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off";
}, base == null ? false : base.requireUndamaged)); }, base.requireUndamaged));
ctx.getSlot(3 * 9 + 2).setItemStack(new ItemStack(Material.COMPARATOR), "Compare item similarity",
base.compareSimilarity ? ChatColor.GREEN + "On" : ChatColor.RED + "Off");
ctx.getSlot(3 * 9 + 2).addClickHandler(new BooleanSlotHandler((res) -> {
base.compareSimilarity = res;
return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off";
}, base.compareSimilarity));
ctx.getSlot(3 * 9 + 3).setItemStack(new ItemStack(Material.BOOK), "NBT comparison filter");
ctx.getSlot(3 * 9 + 3).addClickHandler((event) -> ctx.getMenu()
.transition(InputMenus.stringSetter(() -> "", res -> base.metaFilter = Lists.newArrayList(res))));
} }
@Override @Override
@ -174,14 +225,15 @@ public class ItemAction extends NPCShopAction {
items.add(ctx.getSlot(i).getCurrentItem().clone()); items.add(ctx.getSlot(i).getCurrentItem().clone());
} }
} }
callback.accept(items.isEmpty() ? null : new ItemAction(items)); base.items = items;
callback.accept(items.isEmpty() ? null : base);
} }
} }
public static class ItemActionGUI implements GUI { public static class ItemActionGUI implements GUI {
@Override @Override
public InventoryMenuPage createEditor(NPCShopAction previous, Consumer<NPCShopAction> callback) { public InventoryMenuPage createEditor(NPCShopAction previous, Consumer<NPCShopAction> callback) {
return new ItemActionEditor(previous == null ? new ItemAction() : null, callback); return new ItemActionEditor(previous == null ? new ItemAction() : (ItemAction) previous, callback);
} }
@Override @Override

View File

@ -112,6 +112,7 @@ public class PermissionAction extends NPCShopAction {
} }
ctx.getSlot(i).setClickHandler(event -> { ctx.getSlot(i).setClickHandler(event -> {
if (event.isRightClick()) { if (event.isRightClick()) {
event.setCancelled(true);
if (idx < base.permissions.size()) { if (idx < base.permissions.size()) {
base.permissions.remove(idx); base.permissions.remove(idx);
ctx.getSlot(idx).setItemStack(null); ctx.getSlot(idx).setItemStack(null);

View File

@ -22,6 +22,7 @@ import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -32,6 +33,7 @@ import com.mojang.authlib.GameProfileRepository;
import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -61,12 +63,11 @@ public class NMS {
public static void cancelMoveDestination(Entity entity) { public static void cancelMoveDestination(Entity entity) {
BRIDGE.cancelMoveDestination(entity); BRIDGE.cancelMoveDestination(entity);
} }/*
/*
* Yggdrasil's default implementation of this method silently fails instead of throwing * Yggdrasil's default implementation of this method silently fails instead of throwing
* an Exception like it should. * an Exception like it should.
*/ */
public static GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable { public static GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable {
return BRIDGE.fillProfileProperties(profile, requireSecure); return BRIDGE.fillProfileProperties(profile, requireSecure);
} }
@ -327,6 +328,10 @@ public class NMS {
return null; return null;
} }
public static CompoundTag getNBT(ItemStack item) {
return BRIDGE.getNBT(item);
}
public static NPC getNPC(Entity entity) { public static NPC getNPC(Entity entity) {
return BRIDGE.getNPC(entity); return BRIDGE.getNPC(entity);
} }

View File

@ -17,6 +17,7 @@ import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -27,6 +28,7 @@ import com.mojang.authlib.GameProfileRepository;
import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -65,6 +67,8 @@ public interface NMSBridge {
public float getHorizontalMovement(Entity entity); public float getHorizontalMovement(Entity entity);
public CompoundTag getNBT(ItemStack item);
public NPC getNPC(Entity entity); public NPC getNPC(Entity entity);
public List<Entity> getPassengers(Entity entity); public List<Entity> getPassengers(Entity entity);

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.Block; import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.Blocks;
import net.minecraft.server.v1_10_R1.EntityFallingBlock; import net.minecraft.server.v1_10_R1.EntityFallingBlock;
import net.minecraft.server.v1_10_R1.IBlockData; import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.NBTTagCompound; import net.minecraft.server.v1_10_R1.NBTTagCompound;
@ -36,14 +35,9 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.fromLegacyData(data)); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftItem; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftItem;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -25,7 +23,6 @@ import net.minecraft.server.v1_10_R1.EntityItem;
import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound; import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.World; import net.minecraft.server.v1_10_R1.World;
import net.minecraft.server.v1_10_R1.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -33,20 +30,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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 (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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.nms.v1_10_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftItemFrame;
@ -10,8 +9,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_10_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_10_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -111,30 +108,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
Material id = Material.STONE; setItem(npc.getItemProvider().get());
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);
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -8,6 +8,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -33,6 +34,7 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -53,6 +55,7 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; import com.mojang.authlib.HttpAuthenticationService;
@ -69,6 +72,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -417,6 +433,11 @@ public class NMSImpl implements NMSBridge {
return handle.bg; return handle.bg;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1421,6 +1442,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_10_R1.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.c()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_10_R1.NBTBase base) {
if (base instanceof net.minecraft.server.v1_10_R1.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_10_R1.NBTTagInt) base).e());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_10_R1.NBTTagFloat) base).i());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_10_R1.NBTTagDouble) base).h());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_10_R1.NBTTagLong) base).d());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_10_R1.NBTTagShort) base).f());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_10_R1.NBTTagByte) base).g());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_10_R1.NBTTagByteArray) base).c());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_10_R1.NBTTagIntArray) base).d());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagString) {
return new StringTag(key, base.toString());
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagList) {
List<net.minecraft.server.v1_10_R1.NBTBase> list = (List<net.minecraft.server.v1_10_R1.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_10_R1.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_10_R1.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1) { public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {
if ((entity.ct()) || (entity.bA())) { if ((entity.ct()) || (entity.bA())) {
if ((entity.isInWater()) if ((entity.isInWater())

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_11_R1.Block; import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.Blocks;
import net.minecraft.server.v1_11_R1.EntityFallingBlock; import net.minecraft.server.v1_11_R1.EntityFallingBlock;
import net.minecraft.server.v1_11_R1.EnumMoveType; import net.minecraft.server.v1_11_R1.EnumMoveType;
import net.minecraft.server.v1_11_R1.IBlockData; import net.minecraft.server.v1_11_R1.IBlockData;
@ -37,14 +36,9 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.fromLegacyData(data)); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftItem; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftItem;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -25,7 +23,6 @@ import net.minecraft.server.v1_11_R1.EntityItem;
import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NBTTagCompound; import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.World; import net.minecraft.server.v1_11_R1.World;
import net.minecraft.server.v1_11_R1.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -33,20 +30,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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 (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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_11_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer; import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_11_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_11_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -112,25 +108,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"));
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -8,9 +8,11 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -32,6 +34,7 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -52,6 +55,7 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; import com.mojang.authlib.HttpAuthenticationService;
@ -68,6 +72,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -436,6 +453,11 @@ public class NMSImpl implements NMSBridge {
return handle.bf; return handle.bf;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1485,6 +1507,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_11_R1.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.c()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_11_R1.NBTBase base) {
if (base instanceof net.minecraft.server.v1_11_R1.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_11_R1.NBTTagInt) base).e());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_11_R1.NBTTagFloat) base).i());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_11_R1.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_11_R1.NBTTagLong) base).d());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_11_R1.NBTTagShort) base).f());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_11_R1.NBTTagByte) base).g());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_11_R1.NBTTagByteArray) base).c());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_11_R1.NBTTagIntArray) base).d());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagString) {
return new StringTag(key, base.toString());
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagList) {
List<net.minecraft.server.v1_11_R1.NBTBase> list = (List<net.minecraft.server.v1_11_R1.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_11_R1.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_11_R1.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1) { public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {
if ((entity.cu()) || (entity.bA())) { if ((entity.cu()) || (entity.bA())) {
if (entity.isInWater()) { if (entity.isInWater()) {

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_12_R1.Block; import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.Blocks;
import net.minecraft.server.v1_12_R1.EntityFallingBlock; import net.minecraft.server.v1_12_R1.EntityFallingBlock;
import net.minecraft.server.v1_12_R1.EnumMoveType; import net.minecraft.server.v1_12_R1.EnumMoveType;
import net.minecraft.server.v1_12_R1.IBlockData; import net.minecraft.server.v1_12_R1.IBlockData;
@ -37,14 +36,9 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.fromLegacyData(data)); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftItem; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftItem;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -25,7 +23,6 @@ import net.minecraft.server.v1_12_R1.EntityItem;
import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.NBTTagCompound; import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.World; import net.minecraft.server.v1_12_R1.World;
import net.minecraft.server.v1_12_R1.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -33,20 +30,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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 (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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_12_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer; import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_12_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_12_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -112,25 +108,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"));
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -8,9 +8,11 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -32,6 +34,7 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -52,6 +55,7 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; import com.mojang.authlib.HttpAuthenticationService;
@ -68,6 +72,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -440,6 +457,11 @@ public class NMSImpl implements NMSBridge {
return handle.bg; return handle.bg;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1495,6 +1517,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_12_R1.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.c()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_12_R1.NBTBase base) {
if (base instanceof net.minecraft.server.v1_12_R1.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_12_R1.NBTTagInt) base).e());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_12_R1.NBTTagFloat) base).i());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_12_R1.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_12_R1.NBTTagLong) base).d());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_12_R1.NBTTagShort) base).f());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_12_R1.NBTTagByte) base).g());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_12_R1.NBTTagByteArray) base).c());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_12_R1.NBTTagIntArray) base).d());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagString) {
return new StringTag(key, base.toString());
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagList) {
List<net.minecraft.server.v1_12_R1.NBTBase> list = (List<net.minecraft.server.v1_12_R1.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_12_R1.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_12_R1.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) { public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) {
if ((entity.cC()) || (entity.bI())) { if ((entity.cC()) || (entity.bI())) {
if ((entity.isInWater())) { if ((entity.isInWater())) {
@ -1822,11 +1894,8 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g"); private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g");
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h"); private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h");
private static Field SKULL_PROFILE_FIELD; private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD; private static MethodHandle TEAM_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG"); private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG");
static { static {

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R2.Block; import net.minecraft.server.v1_13_R2.Block;
import net.minecraft.server.v1_13_R2.Blocks;
import net.minecraft.server.v1_13_R2.EntityFallingBlock; import net.minecraft.server.v1_13_R2.EntityFallingBlock;
import net.minecraft.server.v1_13_R2.EnumMoveType; import net.minecraft.server.v1_13_R2.EnumMoveType;
import net.minecraft.server.v1_13_R2.FluidType; import net.minecraft.server.v1_13_R2.FluidType;
@ -39,13 +38,7 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.getBlockData()); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItem; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItem;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -27,7 +25,6 @@ import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NBTTagCompound; import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.Tag; import net.minecraft.server.v1_13_R2.Tag;
import net.minecraft.server.v1_13_R2.World; import net.minecraft.server.v1_13_R2.World;
import net.minecraft.server.v1_13_R2.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -35,20 +32,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_13_R2.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer; import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R2.entity.MobEntityController; import net.citizensnpcs.nms.v1_13_R2.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -128,25 +124,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -8,9 +8,11 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -34,6 +36,7 @@ import org.bukkit.craftbukkit.v1_13_R2.entity.CraftWither;
import org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -54,6 +57,7 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; import com.mojang.authlib.HttpAuthenticationService;
@ -70,6 +74,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -462,6 +479,11 @@ public class NMSImpl implements NMSBridge {
return handle.bj; return handle.bj;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1534,6 +1556,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_13_R2.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_13_R2.NBTBase base) {
if (base instanceof net.minecraft.server.v1_13_R2.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_13_R2.NBTTagInt) base).asInt());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_13_R2.NBTTagFloat) base).asFloat());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_13_R2.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_13_R2.NBTTagLong) base).asLong());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_13_R2.NBTTagShort) base).asShort());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_13_R2.NBTTagByte) base).asByte());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_13_R2.NBTTagByteArray) base).c());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_13_R2.NBTTagIntArray) base).d());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagString) {
return new StringTag(key, base.asString());
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagList) {
List<net.minecraft.server.v1_13_R2.NBTBase> list = (List<net.minecraft.server.v1_13_R2.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_13_R2.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_13_R2.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) { public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) {
if ((entity.cP()) || (entity.bT())) { if ((entity.cP()) || (entity.bT())) {
double d0 = 0.08D; double d0 = 0.08D;

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_14_R1.Block; import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.Blocks;
import net.minecraft.server.v1_14_R1.EntityFallingBlock; import net.minecraft.server.v1_14_R1.EntityFallingBlock;
import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumMoveType; import net.minecraft.server.v1_14_R1.EnumMoveType;
@ -41,13 +40,7 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.getBlockData()); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftItem; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftItem;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -30,7 +28,6 @@ import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.Tag; import net.minecraft.server.v1_14_R1.Tag;
import net.minecraft.server.v1_14_R1.Vec3D; import net.minecraft.server.v1_14_R1.Vec3D;
import net.minecraft.server.v1_14_R1.World; import net.minecraft.server.v1_14_R1.World;
import net.minecraft.server.v1_14_R1.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -38,20 +35,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer; import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
@ -127,25 +123,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -35,6 +36,7 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -71,6 +73,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -504,6 +519,11 @@ public class NMSImpl implements NMSBridge {
return handle.bd; return handle.bd;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1687,6 +1707,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_14_R1.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_14_R1.NBTBase base) {
if (base instanceof net.minecraft.server.v1_14_R1.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_14_R1.NBTTagInt) base).asInt());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_14_R1.NBTTagFloat) base).asFloat());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_14_R1.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_14_R1.NBTTagLong) base).asLong());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_14_R1.NBTTagShort) base).asShort());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_14_R1.NBTTagByte) base).asByte());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_14_R1.NBTTagByteArray) base).getBytes());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_14_R1.NBTTagIntArray) base).getInts());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagString) {
return new StringTag(key, base.asString());
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagList) {
List<net.minecraft.server.v1_14_R1.NBTBase> list = (List<net.minecraft.server.v1_14_R1.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_14_R1.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_14_R1.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) { public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
double d0; double d0;
float f; float f;

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_15_R1.Block; import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.Blocks;
import net.minecraft.server.v1_15_R1.EntityFallingBlock; import net.minecraft.server.v1_15_R1.EntityFallingBlock;
import net.minecraft.server.v1_15_R1.EntityTypes; import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EnumMoveType; import net.minecraft.server.v1_15_R1.EnumMoveType;
@ -41,13 +40,7 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.getBlockData()); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItem; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItem;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_15_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_15_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -30,7 +28,6 @@ import net.minecraft.server.v1_15_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.Tag; import net.minecraft.server.v1_15_R1.Tag;
import net.minecraft.server.v1_15_R1.Vec3D; import net.minecraft.server.v1_15_R1.Vec3D;
import net.minecraft.server.v1_15_R1.World; import net.minecraft.server.v1_15_R1.World;
import net.minecraft.server.v1_15_R1.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -38,20 +35,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_15_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer; import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_15_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_15_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_15_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_15_R1.util.NMSImpl;
@ -127,25 +123,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -35,6 +36,7 @@ import org.bukkit.craftbukkit.v1_15_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -71,6 +73,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -513,6 +528,11 @@ public class NMSImpl implements NMSBridge {
return handle.bb; return handle.bb;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1731,6 +1751,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_15_R1.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_15_R1.NBTBase base) {
if (base instanceof net.minecraft.server.v1_15_R1.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_15_R1.NBTTagInt) base).asInt());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_15_R1.NBTTagFloat) base).asFloat());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_15_R1.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_15_R1.NBTTagLong) base).asLong());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_15_R1.NBTTagShort) base).asShort());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_15_R1.NBTTagByte) base).asByte());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_15_R1.NBTTagByteArray) base).getBytes());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_15_R1.NBTTagIntArray) base).getInts());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagString) {
return new StringTag(key, base.asString());
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagList) {
List<net.minecraft.server.v1_15_R1.NBTBase> list = (List<net.minecraft.server.v1_15_R1.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_15_R1.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_15_R1.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) { public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
double d0; double d0;
float f; float f;

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.Block; import net.minecraft.server.v1_16_R3.Block;
import net.minecraft.server.v1_16_R3.Blocks;
import net.minecraft.server.v1_16_R3.EntityFallingBlock; import net.minecraft.server.v1_16_R3.EntityFallingBlock;
import net.minecraft.server.v1_16_R3.EntityTypes; import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.EnumMoveType; import net.minecraft.server.v1_16_R3.EnumMoveType;
@ -41,13 +40,7 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.getBlockData()); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftItem; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftItem;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl; import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -30,7 +28,6 @@ import net.minecraft.server.v1_16_R3.NBTTagCompound;
import net.minecraft.server.v1_16_R3.Tag; import net.minecraft.server.v1_16_R3.Tag;
import net.minecraft.server.v1_16_R3.Vec3D; import net.minecraft.server.v1_16_R3.Vec3D;
import net.minecraft.server.v1_16_R3.World; import net.minecraft.server.v1_16_R3.World;
import net.minecraft.server.v1_16_R3.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -38,20 +35,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,17 +2,13 @@ package net.citizensnpcs.nms.v1_16_R3.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftItemFrame;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_16_R3.entity.MobEntityController; import net.citizensnpcs.nms.v1_16_R3.entity.MobEntityController;
import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl; import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
@ -127,25 +123,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -35,6 +36,7 @@ import org.bukkit.craftbukkit.v1_16_R3.entity.CraftWither;
import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -72,6 +74,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -522,6 +537,11 @@ public class NMSImpl implements NMSBridge {
return handle.aT; return handle.aT;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1758,6 +1778,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_16_R3.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_16_R3.NBTBase base) {
if (base instanceof net.minecraft.server.v1_16_R3.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_16_R3.NBTTagInt) base).asInt());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_16_R3.NBTTagFloat) base).asFloat());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_16_R3.NBTTagDouble) base).asDouble());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_16_R3.NBTTagLong) base).asLong());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_16_R3.NBTTagShort) base).asShort());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_16_R3.NBTTagByte) base).asByte());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_16_R3.NBTTagByteArray) base).getBytes());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_16_R3.NBTTagIntArray) base).getInts());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagString) {
return new StringTag(key, base.asString());
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagList) {
List<net.minecraft.server.v1_16_R3.NBTBase> list = (List<net.minecraft.server.v1_16_R3.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_16_R3.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_16_R3.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) { public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
if (entity.doAITick() || entity.cs()) { if (entity.doAITick() || entity.cs()) {
double d0 = 0.08D; double d0 = 0.08D;

View File

@ -28,7 +28,6 @@ import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -41,13 +40,7 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.defaultBlockState()); id.defaultBlockState());
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -2,14 +2,11 @@ package net.citizensnpcs.nms.v1_17_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftGlowItemFrame; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftGlowItemFrame;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_17_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_17_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ItemFrameController.EntityItemFrameNPC; import net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ItemFrameController.EntityItemFrameNPC;
@ -126,28 +123,12 @@ public class GlowItemFrameController extends MobEntityController {
public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) { public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
Material id = Material.STONE; setItem(npc.getItemProvider().get());
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().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1));
getItem().setType(id);
getItem().setDurability((short) data);
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -14,14 +14,12 @@ import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_17_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_17_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -39,19 +37,8 @@ public class ItemController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,15 +2,11 @@ package net.citizensnpcs.nms.v1_17_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_17_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_17_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_17_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_17_R1.util.NMSImpl;
@ -126,25 +122,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -35,6 +36,7 @@ import org.bukkit.craftbukkit.v1_17_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -69,6 +71,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -536,6 +551,11 @@ public class NMSImpl implements NMSBridge {
return handle.zza; return handle.zza;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1749,6 +1769,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.nbt.CompoundTag tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getAllKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.nbt.Tag base) {
if (base instanceof net.minecraft.nbt.IntTag) {
return new IntTag(key, ((net.minecraft.nbt.IntTag) base).getAsInt());
} else if (base instanceof net.minecraft.nbt.FloatTag) {
return new FloatTag(key, ((net.minecraft.nbt.FloatTag) base).getAsFloat());
} else if (base instanceof net.minecraft.nbt.DoubleTag) {
return new DoubleTag(key, ((net.minecraft.nbt.DoubleTag) base).getAsDouble());
} else if (base instanceof net.minecraft.nbt.LongTag) {
return new LongTag(key, ((net.minecraft.nbt.LongTag) base).getAsLong());
} else if (base instanceof net.minecraft.nbt.ShortTag) {
return new ShortTag(key, ((net.minecraft.nbt.ShortTag) base).getAsShort());
} else if (base instanceof net.minecraft.nbt.ByteTag) {
return new ByteTag(key, ((net.minecraft.nbt.ByteTag) base).getAsByte());
} else if (base instanceof net.minecraft.nbt.ByteArrayTag) {
return new ByteArrayTag(key, ((net.minecraft.nbt.ByteArrayTag) base).getAsByteArray());
} else if (base instanceof net.minecraft.nbt.IntArrayTag) {
return new IntArrayTag(key, ((net.minecraft.nbt.IntArrayTag) base).getAsIntArray());
} else if (base instanceof net.minecraft.nbt.StringTag) {
return new StringTag(key, base.getAsString());
} else if (base instanceof net.minecraft.nbt.ListTag) {
List<net.minecraft.nbt.Tag> list = (List<net.minecraft.nbt.Tag>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.nbt.CompoundTag) {
return convertNBT(((net.minecraft.nbt.CompoundTag) base));
} else if (base instanceof net.minecraft.nbt.EndTag) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) { public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) {
if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) { if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) {
double d0 = 0.08D; double d0 = 0.08D;

View File

@ -30,7 +30,6 @@ import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -42,18 +41,11 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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")), false));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(EntityType.FALLING_BLOCK, ws, npc); final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(EntityType.FALLING_BLOCK, ws, npc);
handle.setPos(at.getX(), at.getY(), at.getZ()); handle.setPos(at.getX(), at.getY(), at.getZ());
handle.setDeltaMovement(Vec3.ZERO); handle.setDeltaMovement(Vec3.ZERO);
NMSImpl.setFallingBlockState(handle, id.defaultBlockState()); NMSImpl.setFallingBlockState(handle, id.defaultBlockState());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,14 +2,11 @@ package net.citizensnpcs.nms.v1_18_R2.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer; import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftGlowItemFrame; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftGlowItemFrame;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_18_R2.entity.MobEntityController; import net.citizensnpcs.nms.v1_18_R2.entity.MobEntityController;
import net.citizensnpcs.nms.v1_18_R2.entity.nonliving.ItemFrameController.EntityItemFrameNPC; import net.citizensnpcs.nms.v1_18_R2.entity.nonliving.ItemFrameController.EntityItemFrameNPC;
@ -134,24 +131,12 @@ public class GlowItemFrameController extends MobEntityController {
public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) { public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1)); setItem(npc.getItemProvider().get());
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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -14,7 +14,6 @@ import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_18_R2.util.NMSImpl; import net.citizensnpcs.nms.v1_18_R2.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -40,19 +39,8 @@ public class ItemController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,15 +2,11 @@ package net.citizensnpcs.nms.v1_18_R2.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer; import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_18_R2.entity.MobEntityController; import net.citizensnpcs.nms.v1_18_R2.entity.MobEntityController;
import net.citizensnpcs.nms.v1_18_R2.util.NMSImpl; import net.citizensnpcs.nms.v1_18_R2.util.NMSImpl;
@ -134,28 +130,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
if (npc.data().has(NPC.ITEM_AMOUNT_METADATA)) { setItem(npc.getItemProvider().get());
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA));
}
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1);
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -36,6 +37,7 @@ import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_18_R2.event.CraftPortalEvent; import org.bukkit.craftbukkit.v1_18_R2.event.CraftPortalEvent;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -71,6 +73,19 @@ import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -541,6 +556,11 @@ public class NMSImpl implements NMSBridge {
return handle.zza; return handle.zza;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1756,6 +1776,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.nbt.CompoundTag tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getAllKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.nbt.Tag base) {
if (base instanceof net.minecraft.nbt.IntTag) {
return new IntTag(key, ((net.minecraft.nbt.IntTag) base).getAsInt());
} else if (base instanceof net.minecraft.nbt.FloatTag) {
return new FloatTag(key, ((net.minecraft.nbt.FloatTag) base).getAsFloat());
} else if (base instanceof net.minecraft.nbt.DoubleTag) {
return new DoubleTag(key, ((net.minecraft.nbt.DoubleTag) base).getAsDouble());
} else if (base instanceof net.minecraft.nbt.LongTag) {
return new LongTag(key, ((net.minecraft.nbt.LongTag) base).getAsLong());
} else if (base instanceof net.minecraft.nbt.ShortTag) {
return new ShortTag(key, ((net.minecraft.nbt.ShortTag) base).getAsShort());
} else if (base instanceof net.minecraft.nbt.ByteTag) {
return new ByteTag(key, ((net.minecraft.nbt.ByteTag) base).getAsByte());
} else if (base instanceof net.minecraft.nbt.ByteArrayTag) {
return new ByteArrayTag(key, ((net.minecraft.nbt.ByteArrayTag) base).getAsByteArray());
} else if (base instanceof net.minecraft.nbt.IntArrayTag) {
return new IntArrayTag(key, ((net.minecraft.nbt.IntArrayTag) base).getAsIntArray());
} else if (base instanceof net.minecraft.nbt.StringTag) {
return new StringTag(key, base.getAsString());
} else if (base instanceof net.minecraft.nbt.ListTag) {
List<net.minecraft.nbt.Tag> list = (List<net.minecraft.nbt.Tag>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.nbt.CompoundTag) {
return convertNBT(((net.minecraft.nbt.CompoundTag) base));
} else if (base instanceof net.minecraft.nbt.EndTag) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) { public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) {
if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) { if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) {
double d0 = 0.08D; double d0 = 0.08D;

View File

@ -461,7 +461,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
} }
public void setPathfindingMalus(BlockPathTypes pathtype, float f) { public void setPathfindingMalus(BlockPathTypes pathtype, float f) {
this.malus.put(pathtype, f); malus.put(pathtype, f);
} }
public void setShouldJump() { public void setShouldJump() {
@ -470,7 +470,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
@Override @Override
public void setSkinFlags(byte flags) { public void setSkinFlags(byte flags) {
this.getEntityData().set(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION, flags); getEntityData().set(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION, flags);
} }
@Override @Override
@ -489,7 +489,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
} }
public void setTracked(PlayerlistTracker tracker) { public void setTracked(PlayerlistTracker tracker) {
this.playerlistTracker = tracker; playerlistTracker = tracker;
} }
@Override @Override

View File

@ -29,7 +29,6 @@ import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -41,18 +40,11 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
// 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")), false));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(EntityType.FALLING_BLOCK, ws, npc); final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(EntityType.FALLING_BLOCK, ws, npc);
handle.setPos(at.getX(), at.getY(), at.getZ()); handle.setPos(at.getX(), at.getY(), at.getZ());
handle.setDeltaMovement(Vec3.ZERO); handle.setDeltaMovement(Vec3.ZERO);
NMSImpl.setFallingBlockState(handle, id.defaultBlockState()); NMSImpl.setFallingBlockState(handle, id.defaultBlockState());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,14 +2,11 @@ package net.citizensnpcs.nms.v1_19_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer; import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftGlowItemFrame; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftGlowItemFrame;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_19_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_19_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_19_R1.entity.nonliving.ItemFrameController.EntityItemFrameNPC; import net.citizensnpcs.nms.v1_19_R1.entity.nonliving.ItemFrameController.EntityItemFrameNPC;
@ -135,24 +132,12 @@ public class GlowItemFrameController extends MobEntityController {
public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) { public GlowItemFrameNPC(EntityGlowItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
getItem().setAmount(npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1)); setItem(npc.getItemProvider().get());
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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -14,7 +14,6 @@ import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.nms.v1_19_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_19_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -40,19 +39,8 @@ public class ItemController extends AbstractEntityController {
@Override @Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(), at.getY(), at.getZ(),
Material id = Material.STONE; CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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), 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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,15 +2,11 @@ package net.citizensnpcs.nms.v1_19_R1.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer; import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_19_R1.entity.MobEntityController; import net.citizensnpcs.nms.v1_19_R1.entity.MobEntityController;
import net.citizensnpcs.nms.v1_19_R1.util.NMSImpl; import net.citizensnpcs.nms.v1_19_R1.util.NMSImpl;
@ -135,25 +131,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
int amount = npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1); setItem(npc.getItemProvider().get());
Material material = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, "STONE"), false);
Number durability = npc.data().<Number> get(NPC.ITEM_DATA_METADATA,
npc.data().<Number> get("falling-block-data", (short) 0));
setItem(new ItemStack(material, amount, durability.shortValue()));
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -36,6 +37,7 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_19_R1.event.CraftPortalEvent; import org.bukkit.craftbukkit.v1_19_R1.event.CraftPortalEvent;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -71,6 +73,19 @@ import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -553,6 +568,11 @@ public class NMSImpl implements NMSBridge {
return handle.zza; return handle.zza;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1777,6 +1797,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.nbt.CompoundTag tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.getAllKeys()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.nbt.Tag base) {
if (base instanceof net.minecraft.nbt.IntTag) {
return new IntTag(key, ((net.minecraft.nbt.IntTag) base).getAsInt());
} else if (base instanceof net.minecraft.nbt.FloatTag) {
return new FloatTag(key, ((net.minecraft.nbt.FloatTag) base).getAsFloat());
} else if (base instanceof net.minecraft.nbt.DoubleTag) {
return new DoubleTag(key, ((net.minecraft.nbt.DoubleTag) base).getAsDouble());
} else if (base instanceof net.minecraft.nbt.LongTag) {
return new LongTag(key, ((net.minecraft.nbt.LongTag) base).getAsLong());
} else if (base instanceof net.minecraft.nbt.ShortTag) {
return new ShortTag(key, ((net.minecraft.nbt.ShortTag) base).getAsShort());
} else if (base instanceof net.minecraft.nbt.ByteTag) {
return new ByteTag(key, ((net.minecraft.nbt.ByteTag) base).getAsByte());
} else if (base instanceof net.minecraft.nbt.ByteArrayTag) {
return new ByteArrayTag(key, ((net.minecraft.nbt.ByteArrayTag) base).getAsByteArray());
} else if (base instanceof net.minecraft.nbt.IntArrayTag) {
return new IntArrayTag(key, ((net.minecraft.nbt.IntArrayTag) base).getAsIntArray());
} else if (base instanceof net.minecraft.nbt.StringTag) {
return new StringTag(key, base.getAsString());
} else if (base instanceof net.minecraft.nbt.ListTag) {
List<net.minecraft.nbt.Tag> list = (List<net.minecraft.nbt.Tag>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.nbt.CompoundTag) {
return convertNBT(((net.minecraft.nbt.CompoundTag) base));
} else if (base instanceof net.minecraft.nbt.EndTag) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) { public static void flyingMoveLogic(LivingEntity entity, Vec3 vec3d) {
if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) { if (entity.isEffectiveAi() || entity.isControlledByLocalInstance()) {
double d0 = 0.08D; double d0 = 0.08D;
@ -2275,6 +2345,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle SIZE_FIELD_SETTER = NMS.getFirstSetter(Entity.class, EntityDimensions.class); private static final MethodHandle SIZE_FIELD_SETTER = NMS.getFirstSetter(Entity.class, EntityDimensions.class);
private static Field SKULL_PROFILE_FIELD; private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD; private static MethodHandle TEAM_FIELD;
static { static {
try { try {
ENTITY_REGISTRY = new CustomEntityRegistry(Registry.ENTITY_TYPE); ENTITY_REGISTRY = new CustomEntityRegistry(Registry.ENTITY_TYPE);

View File

@ -21,7 +21,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.EntityFallingBlock; import net.minecraft.server.v1_8_R3.EntityFallingBlock;
import net.minecraft.server.v1_8_R3.IBlockData; import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagCompound;
@ -36,14 +35,9 @@ public class FallingBlockController extends AbstractEntityController {
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = CraftMagicNumbers.getBlock(npc.getItemProvider().get().getType());
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
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"))));
}
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.fromLegacyData(data)); id.getBlockData());
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -8,14 +8,12 @@ import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason; import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -25,7 +23,6 @@ import net.minecraft.server.v1_8_R3.EntityItem;
import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World; import net.minecraft.server.v1_8_R3.World;
import net.minecraft.server.v1_8_R3.WorldServer;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
@ -33,20 +30,9 @@ public class ItemController extends AbstractEntityController {
} }
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); final EntityItemNPC handle = new EntityItemNPC(((CraftWorld) at.getWorld()).getHandle(), npc, at.getX(),
Material id = Material.STONE; at.getY(), at.getZ(), CraftItemStack.asNMSCopy(npc.getItemProvider().get()));
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 (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,
npc.data().get(NPC.ITEM_AMOUNT_METADATA, 1), (short) data)));
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.nms.v1_8_R3.entity.nonliving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItemFrame; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItemFrame;
@ -10,8 +9,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -111,30 +108,12 @@ public class ItemFrameController extends MobEntityController {
public ItemFrameNPC(EntityItemFrameNPC entity) { public ItemFrameNPC(EntityItemFrameNPC entity) {
super((CraftServer) Bukkit.getServer(), entity); super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc; this.npc = entity.npc;
Material id = Material.STONE; setItem(npc.getItemProvider().get());
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().<Integer> get(NPC.ITEM_AMOUNT_METADATA));
}
getItem().setType(id);
getItem().setDurability((short) data);
} }
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
public void setType(Material material, int data) {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
} }
} }

View File

@ -30,6 +30,7 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWither; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWither;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
@ -51,6 +52,7 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; import com.mojang.authlib.HttpAuthenticationService;
@ -66,6 +68,19 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.jnbt.ByteArrayTag;
import net.citizensnpcs.api.jnbt.ByteTag;
import net.citizensnpcs.api.jnbt.CompoundTag;
import net.citizensnpcs.api.jnbt.DoubleTag;
import net.citizensnpcs.api.jnbt.EndTag;
import net.citizensnpcs.api.jnbt.FloatTag;
import net.citizensnpcs.api.jnbt.IntArrayTag;
import net.citizensnpcs.api.jnbt.IntTag;
import net.citizensnpcs.api.jnbt.ListTag;
import net.citizensnpcs.api.jnbt.LongTag;
import net.citizensnpcs.api.jnbt.ShortTag;
import net.citizensnpcs.api.jnbt.StringTag;
import net.citizensnpcs.api.jnbt.Tag;
import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -381,6 +396,11 @@ public class NMSImpl implements NMSBridge {
return handle.ba; return handle.ba;
} }
@Override
public CompoundTag getNBT(org.bukkit.inventory.ItemStack item) {
return convertNBT(CraftItemStack.asNMSCopy(item).getTag());
}
@Override @Override
public NPC getNPC(org.bukkit.entity.Entity entity) { public NPC getNPC(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
@ -1367,6 +1387,56 @@ public class NMSImpl implements NMSBridge {
} }
} }
private static CompoundTag convertNBT(net.minecraft.server.v1_8_R3.NBTTagCompound tag) {
if (tag == null) {
return new CompoundTag("", Collections.EMPTY_MAP);
}
Map<String, Tag> tags = Maps.newHashMap();
for (String key : tag.c()) {
tags.put(key, convertNBT(key, tag.get(key)));
}
return new CompoundTag("", tags);
}
private static Tag convertNBT(String key, net.minecraft.server.v1_8_R3.NBTBase base) {
if (base instanceof net.minecraft.server.v1_8_R3.NBTTagInt) {
return new IntTag(key, ((net.minecraft.server.v1_8_R3.NBTTagInt) base).d());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagFloat) {
return new FloatTag(key, ((net.minecraft.server.v1_8_R3.NBTTagFloat) base).h());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagDouble) {
return new DoubleTag(key, ((net.minecraft.server.v1_8_R3.NBTTagDouble) base).g());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagLong) {
return new LongTag(key, ((net.minecraft.server.v1_8_R3.NBTTagLong) base).c());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagShort) {
return new ShortTag(key, ((net.minecraft.server.v1_8_R3.NBTTagShort) base).e());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagByte) {
return new ByteTag(key, ((net.minecraft.server.v1_8_R3.NBTTagByte) base).f());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagByteArray) {
return new ByteArrayTag(key, ((net.minecraft.server.v1_8_R3.NBTTagByteArray) base).c());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagIntArray) {
return new IntArrayTag(key, ((net.minecraft.server.v1_8_R3.NBTTagIntArray) base).c());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagString) {
return new StringTag(key, base.toString());
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagList) {
List<net.minecraft.server.v1_8_R3.NBTBase> list = (List<net.minecraft.server.v1_8_R3.NBTBase>) base;
List<Tag> converted = Lists.newArrayList();
if (list.size() > 0) {
Class<? extends Tag> tagType = convertNBT("", list.get(0)).getClass();
for (int i = 0; i < list.size(); i++) {
converted.add(convertNBT("", list.get(i)));
}
return new ListTag(key, tagType, converted);
}
return null;
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagCompound) {
return convertNBT(((net.minecraft.server.v1_8_R3.NBTTagCompound) base));
} else if (base instanceof net.minecraft.server.v1_8_R3.NBTTagEnd) {
return new EndTag();
}
return null;
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1) { public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {
if (entity.bM()) { if (entity.bM()) {
if ((entity.V())) { if ((entity.V())) {