Skip to content

Commit

Permalink
Fixed upgrades not supporting more than one slot (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed May 5, 2023
1 parent 6659037 commit 8b9488b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
@@ -1,5 +1,8 @@
package com.bgsoftware.superiorskyblock.api.upgrades;

import javax.annotation.Nullable;
import java.util.List;

public interface Upgrade {

/**
Expand All @@ -23,13 +26,34 @@ public interface Upgrade {
/**
* Get the slot the upgrade is in the upgrades menu.
*/
@Deprecated
int getSlot();

/**
* Get the slots the upgrade is in the upgrades menu.
*/
List<Integer> getSlots();

/**
* Check whether the upgrade is in the given slot in the upgrades menu.
*
* @param slot The slot to check.
*/
boolean isSlot(int slot);

/**
* Set the slot the upgrade is in the upgrades menu.
*
* @param slot The slot to set the upgrade item in.
*/
@Deprecated
void setSlot(int slot);

/**
* Set the slots the upgrade is in the upgrades menu.
*
* @param slots The slots to set the upgrade item in.
*/
void setSlots(@Nullable List<Integer> slots);

}
Expand Up @@ -66,10 +66,10 @@ public static MenuIslandUpgrades createInstance() {
continue;
}

int slot = MenuParserImpl.getInstance().parseButtonSlots(upgradeSection, "item", menuPatternSlots).get(0);
upgrade.setSlot(slot);
List<Integer> slots = MenuParserImpl.getInstance().parseButtonSlots(upgradeSection, "item", menuPatternSlots);
upgrade.setSlots(slots);

patternBuilder.mapButton(slot, new UpgradeButton.Builder(upgrade));
patternBuilder.mapButtons(slots, new UpgradeButton.Builder(upgrade));

for (String levelSectionKey : upgradeSection.getKeys(false)) {
int level;
Expand All @@ -81,7 +81,7 @@ public static MenuIslandUpgrades createInstance() {
continue;
}

if (slot == -1) {
if (slots.isEmpty()) {
Log.warnFromFile("upgrades.yml", "The item of the upgrade ", upgrade.getName(),
" (level ", level, ") is not inside the pattern, skipping...");
continue;
Expand Down
@@ -1,16 +1,19 @@
package com.bgsoftware.superiorskyblock.island.upgrade;

import com.bgsoftware.superiorskyblock.api.key.KeyMap;
import com.bgsoftware.superiorskyblock.api.upgrades.Upgrade;
import com.bgsoftware.superiorskyblock.island.upgrade.cost.EmptyUpgradeCost;
import com.bgsoftware.superiorskyblock.island.container.value.Value;
import com.bgsoftware.superiorskyblock.core.key.KeyMapImpl;
import org.bukkit.World;
import com.bgsoftware.superiorskyblock.island.container.value.Value;
import com.bgsoftware.superiorskyblock.island.upgrade.cost.EmptyUpgradeCost;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class SUpgrade implements Upgrade {

Expand All @@ -36,7 +39,7 @@ public class SUpgrade implements Upgrade {
private final String name;

private SUpgradeLevel[] upgradeLevels = new SUpgradeLevel[0];
private int slot = -1;
private final Set<Integer> slots = new LinkedHashSet<>();

public SUpgrade(String name) {
this.name = name;
Expand All @@ -59,12 +62,31 @@ public int getMaxUpgradeLevel() {

@Override
public int getSlot() {
return slot;
return getSlots().get(0);
}

@Override
public List<Integer> getSlots() {
return Collections.unmodifiableList(new LinkedList<>(this.slots));
}

@Override
public boolean isSlot(int slot) {
return this.slots.contains(slot);
}

@Override
public void setSlot(int slot) {
this.slot = slot;
this.slots.add(slot);
}

@Override
public void setSlots(@Nullable List<Integer> slots) {
if (slots == null) {
this.slots.clear();
} else {
this.slots.addAll(slots);
}
}

public void addUpgradeLevel(int level, SUpgradeLevel upgradeLevel) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ public Upgrade getUpgrade(String upgradeName) {
@Override
public Upgrade getUpgrade(int slot) {
return this.upgrades.values().stream()
.filter(upgrade -> upgrade.getSlot() == slot)
.filter(upgrade -> upgrade.isSlot(slot))
.findFirst()
.orElse(null);
}
Expand Down

0 comments on commit 8b9488b

Please sign in to comment.