Permalink
Browse files

Fixed a few deprecated method warnings.

  • Loading branch information...
me4502 committed Jan 8, 2018
1 parent 03944ad commit fb7f710d7eab72a866b455b35e02e8382841b32e
@@ -49,6 +49,7 @@
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
import org.spongepowered.api.item.recipe.smelting.SmeltingResult;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.text.Text;
@@ -89,11 +90,6 @@ public void onInitialize() throws CraftBookException {
super.onInitialize();
}
@Override
public void onDisable() {
super.onDisable();
}
@Override
public boolean verifyLines(Location<World> location, List<Text> lines, @Nullable Player player) {
((SpongeSelfTriggerManager) CraftBookPlugin.inst().getSelfTriggerManager().get()).register(this, location);
@@ -220,7 +216,7 @@ public void onThink(Location<World> location) {
continue;
}
if (inventory.offer(result.getResult().createStack()).getRejectedItems().isEmpty()) {
inventory.queryAny(item).poll(1);
inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(item)).poll(1);
lastTick -= 50;
break;
}
@@ -53,6 +53,7 @@
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
@@ -173,7 +174,8 @@ public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First
int outputBottles = (int) Math.min(bottleCount.get(), Math.floor(((float) xp) / xpPerBottle.getValue()));
if(requireBottle.getValue()) {
outputBottles = player.getInventory().query(ItemTypes.GLASS_BOTTLE).poll(outputBottles).orElse(ItemStack.of(ItemTypes.GLASS_BOTTLE, 0)).getQuantity();
outputBottles = player.getInventory().query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.GLASS_BOTTLE))
.poll(outputBottles).orElse(ItemStack.of(ItemTypes.GLASS_BOTTLE, 0)).getQuantity();
}
// Reset their xp
@@ -204,7 +206,7 @@ public void onThink(Location<World> signLocation) {
int bottleCount = Integer.MAX_VALUE;
if (requireBottle.getValue()) {
bottleCount = inventory.query(ItemTypes.GLASS_BOTTLE).totalItems();
bottleCount = inventory.query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.GLASS_BOTTLE)).totalItems();
if (bottleCount == 0) {
continue;
}
@@ -223,7 +225,8 @@ public void onThink(Location<World> signLocation) {
bottleCount = (int) Math.min(bottleCount, Math.floor(((float) xp) / xpPerBottle.getValue()));
if(requireBottle.getValue()) {
bottleCount = inventory.query(ItemTypes.GLASS_BOTTLE).poll(bottleCount).orElse(ItemStack.of(ItemTypes.GLASS_BOTTLE, 0)).getQuantity();
bottleCount = inventory.query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.GLASS_BOTTLE))
.poll(bottleCount).orElse(ItemStack.of(ItemTypes.GLASS_BOTTLE, 0)).getQuantity();
}
int remainingXp = convertXp(location, xp, bottleCount);
@@ -21,7 +21,6 @@
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.data.DataView;
import org.spongepowered.api.data.MemoryDataContainer;
import org.spongepowered.api.data.Queries;
import org.spongepowered.api.data.persistence.AbstractDataBuilder;
import org.spongepowered.api.data.persistence.InvalidDataException;
@@ -119,7 +118,7 @@ public int getContentVersion() {
@Override
public DataContainer toContainer() {
return new MemoryDataContainer()
return DataContainer.createNew()
.set(Queries.CONTENT_VERSION, getContentVersion())
.set(DataQuery.of("Items"), itemStacks);
}
@@ -20,6 +20,7 @@
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult;
import java.util.ArrayList;
@@ -59,7 +60,7 @@ public boolean has(List<ItemStack> itemStacks) {
public List<ItemStack> remove(List<ItemStack> itemStacks) {
List<ItemStack> output = new ArrayList<>();
for(ItemStack stack : itemStacks) {
Inventory view = inventory.query(stack);
Inventory view = inventory.query(QueryOperationTypes.ITEM_STACK_EXACT.of(stack));
//view.poll(stack.getQuantity());
//InventoryTransactionResult result = ;
//if(result.getRejectedItems().size() > 0) {
@@ -26,10 +26,8 @@
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.event.cause.entity.spawn.SpawnType;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.event.entity.SpawnEntityEvent;
import org.spongepowered.api.event.filter.cause.ContextValue;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.event.item.inventory.DropItemEvent;
import org.spongepowered.api.item.inventory.Inventory;
@@ -19,13 +19,12 @@
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.data.MemoryDataContainer;
public abstract class SerializedICData implements DataSerializable {
@Override
public DataContainer toContainer() {
return new MemoryDataContainer()
return DataContainer.createNew()
.set(DataQuery.of("ContentVersion"), this.getContentVersion());
}
}
@@ -32,17 +32,10 @@
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.DataView;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.persistence.InvalidDataException;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.InventoryArchetypes;
import org.spongepowered.api.item.inventory.property.InventoryDimension;
import org.spongepowered.api.item.inventory.property.InventoryTitle;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.world.BlockChangeFlag;
import org.spongepowered.api.world.BlockChangeFlags;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
@@ -51,8 +44,6 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
public class BlockReplacer extends IC {
@@ -22,7 +22,6 @@
import com.sk89q.craftbook.sponge.mechanics.ics.SerializedICData;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.ICFactory;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.SerializedICFactory;
import com.sk89q.craftbook.sponge.util.BlockUtil;
import com.sk89q.craftbook.sponge.util.SignUtil;
import com.sk89q.craftbook.sponge.util.prompt.EntityArchetypeDataPrompt;
import org.spongepowered.api.Sponge;
@@ -30,6 +30,7 @@
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.Direction;
@@ -80,7 +81,9 @@ private String getBookCode(Location<World> chestBlock) throws CodeNotFoundExcept
Chest c = chestBlock.getTileEntity().map(te -> (Chest) te).get();
Inventory i = c.getDoubleChestInventory().orElse(c.getInventory());
ItemStack book = null;
for (Slot slot : i.query(ItemTypes.WRITABLE_BOOK, ItemTypes.WRITTEN_BOOK).<Slot>slots()) {
for (Slot slot : i.query(
QueryOperationTypes.ITEM_TYPE.of(ItemTypes.WRITABLE_BOOK),
QueryOperationTypes.ITEM_TYPE.of(ItemTypes.WRITTEN_BOOK)).<Slot>slots()) {
ItemStack item = slot.peek().orElse(null);
if (item != null && item.getQuantity() > 0 ) {
if (book != null) throw new CodeNotFoundException("More than one written book found in chest!!");
@@ -96,13 +96,10 @@ private void performPipeAction(Location<World> location) {
Location<World> inventorySource = location.getRelative(direction);
//Let's try and find a source of items!
Optional<Inventory> inventory = LocationUtil.getInventoryForLocation(inventorySource);
if(inventory.isPresent()) {
while (inventory.get().peek(1).isPresent()) {
Optional<ItemStack> itemStackOptional = inventory.get().poll(1);
if (itemStackOptional.isPresent()) {
ItemStack itemStack = itemStackOptional.get();
LocationUtil.getInventoryForLocation(inventorySource).ifPresent(inv -> {
while (inv.peek(1).isPresent()) {
Optional<ItemStack> itemStackOptional = inv.poll(1);
itemStackOptional.ifPresent(itemStack -> {
Set<Location<World>> traversed = new HashSet<>();
try {
@@ -113,18 +110,18 @@ private void performPipeAction(Location<World> location) {
}
if (itemStack.getQuantity() > 0) {
for (ItemStackSnapshot snapshot : inventory.get().offer(itemStack).getRejectedItems()) {
for (ItemStackSnapshot snapshot : inv.offer(itemStack).getRejectedItems()) {
Item item = (Item) location.getExtent().createEntity(EntityTypes.ITEM, location.getPosition());
item.offer(Keys.REPRESENTED_ITEM, snapshot);
location.getExtent().spawnEntity(item);
}
}
}
});
if (stackPerPull.getValue()) {
break;
}
}
}
});
}
private ItemStack doPipeIteration(Location<World> location, ItemStack itemStack, Direction fromDirection, Set<Location<World>> traversed) {
@@ -65,12 +65,17 @@ else if (line.contains("&"))
if(offsets.getFloorX() == 0 && offsets.getFloorY() == 0 && offsets.getFloorZ() == 0)
return target;
if (relative == LocationCheckType.RELATIVE)
target = LocationUtil.getRelativeOffset(sign.getLocation(), offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ());
else if (relative == LocationCheckType.OFFSET)
target = LocationUtil.getOffset(target, offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ());
else if (relative == LocationCheckType.ABSOLUTE)
target = target.getExtent().getLocation(offsets.getX(), offsets.getY(), offsets.getZ());
switch (relative) {
case RELATIVE:
target = LocationUtil.getRelativeOffset(sign.getLocation(), offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ());
break;
case OFFSET:
target = LocationUtil.getOffset(target, offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ());
break;
case ABSOLUTE:
target = target.getExtent().getLocation(offsets.getX(), offsets.getY(), offsets.getZ());
break;
}
return target;
}

0 comments on commit fb7f710

Please sign in to comment.