Skip to content

Commit

Permalink
Fix some out of date elements
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 13, 2024
1 parent 838507c commit 9c52265
Show file tree
Hide file tree
Showing 8 changed files with 1,336 additions and 1,272 deletions.
387 changes: 208 additions & 179 deletions src/main/java/world/bentobox/upgrades/UpgradesManager.java

Large diffs are not rendered by default.

506 changes: 255 additions & 251 deletions src/main/java/world/bentobox/upgrades/api/Upgrade.java

Large diffs are not rendered by default.

1,644 changes: 839 additions & 805 deletions src/main/java/world/bentobox/upgrades/config/Settings.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.limits.events.LimitsJoinPermCheckEvent;
import world.bentobox.upgrades.UpgradesAddon;

public class IslandChangeListener implements Listener {
Expand All @@ -15,11 +14,12 @@ public IslandChangeListener(UpgradesAddon addon) {
this.addon = addon;
}

/*
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onLimitsJoinPermCheckEvent(LimitsJoinPermCheckEvent e) {
// Stop LimitsJoinPermCheck else reset limits upgrades when player join
//e.setCancelled(true);
}
}*/

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onIslandDeleteEvent(IslandDeleteEvent e) {
Expand Down
52 changes: 24 additions & 28 deletions src/main/java/world/bentobox/upgrades/ui/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,66 @@
import world.bentobox.upgrades.api.Upgrade;

public class Panel {

public Panel(UpgradesAddon addon, Island island) {
super();
this.addon = addon;
this.island = island;
}

public void showPanel(User user) {
int islandLevel = this.addon.getUpgradesManager().getIslandLevel(this.island);

PanelBuilder pb = new PanelBuilder().name(user.getTranslation("upgrades.ui.upgradepanel.title"));

this.addon.getAvailableUpgrades().forEach(upgrade -> {
upgrade.updateUpgradeValue(user, this.island);

if (!upgrade.isShowed(user, this.island))
return;

String ownDescription = upgrade.getOwnDescription(user);
List<String> fullDescription = new ArrayList<>();
if (ownDescription != null && upgrade.getUpgradeValues(user) != null)

if (ownDescription != null && upgrade.getUpgradeValues(user) != null) {
fullDescription.add(ownDescription);
}
fullDescription.addAll(this.getDescription(user, upgrade, islandLevel));

pb.item(new PanelItemBuilder()
.name(upgrade.getDisplayName())
.icon(upgrade.getIcon())
.description(fullDescription)
.clickHandler(new PanelClick(upgrade, this.island))
.build());

pb.item(new PanelItemBuilder().name(upgrade.getDisplayName()).icon(upgrade.getIcon())
.description(fullDescription).clickHandler(new PanelClick(upgrade, this.island)).build());
});

pb.user(user).build();
}

private List<String> getDescription(User user, Upgrade upgrade, int islandLevel) {
List<String> descrip = new ArrayList<>();

if (upgrade.getUpgradeValues(user) == null)
descrip.add(user.getTranslation("upgrades.ui.upgradepanel.maxlevel"));
else {
if (this.addon.isLevelProvided()) {
descrip.add((upgrade.getUpgradeValues(user).getIslandLevel() <= islandLevel ? "§a" : "§c") +
user.getTranslation("upgrades.ui.upgradepanel.islandneed",
"[islandlevel]", Integer.toString(upgrade.getUpgradeValues(user).getIslandLevel())));
descrip.add((upgrade.getUpgradeValues(user).getIslandLevel() <= islandLevel ? "§a" : "§c")
+ user.getTranslation("upgrades.ui.upgradepanel.islandneed", "[islandlevel]",
Integer.toString(upgrade.getUpgradeValues(user).getIslandLevel())));
}

if (this.addon.isVaultProvided()) {
boolean hasMoney = this.addon.getVaultHook().has(user, upgrade.getUpgradeValues(user).getMoneyCost());
descrip.add((hasMoney ? "§a" : "§c") +
user.getTranslation("upgrades.ui.upgradepanel.moneycost",
descrip.add((hasMoney ? "§a" : "§c") + user.getTranslation("upgrades.ui.upgradepanel.moneycost",
"[cost]", Integer.toString(upgrade.getUpgradeValues(user).getMoneyCost())));
}

if (this.addon.isLevelProvided() && upgrade.getUpgradeValues(user).getIslandLevel() > islandLevel) {
descrip.add("§8" + user.getTranslation("upgrades.ui.upgradepanel.tryreloadlevel"));
}
}

return descrip;
}

private UpgradesAddon addon;
private Island island;

}
10 changes: 5 additions & 5 deletions src/main/java/world/bentobox/upgrades/upgrades/RangeUpgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Upgrade Object for range upgrade
*
* @author Ikkino
* @author Ikkino, tastybento
*
*/
public class RangeUpgrade extends Upgrade {
Expand Down Expand Up @@ -142,7 +142,7 @@ private void logError(String name, String perm, String error) {
@Override
public boolean doUpgrade(User user, Island island) {
// Get the new range
long newRange = (long)island.getProtectionRange() + this.getUpgradeValues(user).getUpgradeValue();
int newRange = island.getProtectionRange() + this.getUpgradeValues(user).getUpgradeValue();

// If newRange is more than the authorized range (Config problem)
if (newRange > island.getRange()) {
Expand All @@ -159,12 +159,12 @@ public boolean doUpgrade(User user, Island island) {
// Save oldRange for rangeChange event
int oldRange = island.getProtectionRange();

// Set range
island.setProtectionRange((int) newRange);
// Add range bonus
island.addBonusRange(this.getUpgradesAddon().getDescription().getName(), this.getUpgradeValues(user).getUpgradeValue(), "");

// Launch range change event
IslandEvent.builder().island(island).location(island.getCenter()).reason(IslandEvent.Reason.RANGE_CHANGE)
.involvedPlayer(user.getUniqueId()).admin(false).protectionRange((int) newRange, oldRange).build();
.involvedPlayer(user.getUniqueId()).admin(false).protectionRange(island.getProtectionRange(), oldRange).build();

user.sendMessage("upgrades.ui.upgradepanel.rangeupgradedone", "[rangelevel]",
Integer.toString(this.getUpgradeValues(user).getUpgradeValue()));
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Upgrades
main: world.bentobox.upgrades.UpgradesAddon
version: ${version}${build.number}
api-version: '1.16'
api-version: '1.20'
repository: "BentoBoxWorld/Upgrades"
metrics: true
icon: GOLD_INGOT

authors:
- Guillaume-Lebegue
- tastybento

softdepend: BSkyBlock, AcidIsland, CaveBlock, SkyGrid, AOneBlock, Level, Limits
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ entity-group-icon:
group1: CHICKEN_SPAWN_EGG

command-icon:
lambda-upgrade: GRASS
lambda-upgrade: GRASS_BLOCK

0 comments on commit 9c52265

Please sign in to comment.