Skip to content

Commit

Permalink
Fixed DropQueue Stack Overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jul 21, 2021
1 parent 8cda5be commit 8982300
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DropQueue {
/**
* The internally used {@link DropQueue}.
*/
private final DropQueue handle;
private final InternalDropQueue handle;

/**
* @param player The player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface DropQueueFactory {
* @param player The player.
* @return The Queue.
*/
DropQueue create(@NotNull Player player);
InternalDropQueue create(@NotNull Player player);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.willfp.eco.core.drops;

import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

/**
* Internal interface for backend DropQueue implementations.
*/
public interface InternalDropQueue {
/**
* Add item to queue.
*
* @param item The item to add.
* @return The DropQueue.
*/
InternalDropQueue addItem(@NotNull ItemStack item);

/**
* Add multiple items to queue.
*
* @param itemStacks The items to add.
* @return The DropQueue.
*/
InternalDropQueue addItems(@NotNull Collection<ItemStack> itemStacks);

/**
* Add xp to queue.
*
* @param amount The amount to add.
* @return The DropQueue.
*/
InternalDropQueue addXP(int amount);

/**
* Set location of the origin of the drops.
*
* @param location The location.
* @return The DropQueue.
*/
InternalDropQueue setLocation(@NotNull Location location);

/**
* Force the queue to act as if player is telekinetic.
*
* @return The DropQueue.
*/
InternalDropQueue forceTelekinesis();

/**
* Push the queue.
*/
void push();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.willfp.eco.internal.drops;

import com.willfp.eco.core.drops.DropQueue;
import com.willfp.eco.core.drops.DropQueueFactory;
import com.willfp.eco.core.drops.InternalDropQueue;
import com.willfp.eco.internal.drops.impl.EcoDropQueue;
import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class EcoDropQueueFactory implements DropQueueFactory {
@Override
public DropQueue create(@NotNull final Player player) {
public InternalDropQueue create(@NotNull final Player player) {
return DropManager.getType() == DropQueueType.COLLATED ? new EcoFastCollatedDropQueue(player) : new EcoDropQueue(player);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.willfp.eco.internal.drops.impl;

import com.willfp.eco.core.drops.DropQueue;
import com.willfp.eco.core.drops.InternalDropQueue;
import com.willfp.eco.util.TelekinesisUtils;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -21,7 +21,7 @@
import java.util.HashMap;
import java.util.List;

public class EcoDropQueue extends DropQueue {
public class EcoDropQueue implements InternalDropQueue {
@Getter(AccessLevel.PROTECTED)
private final List<ItemStack> items;

Expand All @@ -38,39 +38,38 @@ public class EcoDropQueue extends DropQueue {
private boolean hasTelekinesis = false;

public EcoDropQueue(@NotNull final Player player) {
super(player);
this.items = new ArrayList<>();
this.xp = 0;
this.player = player;
this.loc = player.getLocation();
}

@Override
public DropQueue addItem(@NotNull final ItemStack item) {
public InternalDropQueue addItem(@NotNull final ItemStack item) {
this.items.add(item);
return this;
}

@Override
public DropQueue addItems(@NotNull final Collection<ItemStack> itemStacks) {
public InternalDropQueue addItems(@NotNull final Collection<ItemStack> itemStacks) {
this.items.addAll(itemStacks);
return this;
}

@Override
public DropQueue addXP(final int amount) {
public InternalDropQueue addXP(final int amount) {
this.xp += amount;
return this;
}

@Override
public DropQueue setLocation(@NotNull final Location location) {
public InternalDropQueue setLocation(@NotNull final Location location) {
this.loc = location;
return this;
}

@Override
public DropQueue forceTelekinesis() {
public InternalDropQueue forceTelekinesis() {
this.hasTelekinesis = true;
return this;
}
Expand Down

0 comments on commit 8982300

Please sign in to comment.