Skip to content

Commit 0ba1a98

Browse files
authored
feat: first iteration of upgrades api, builtin team upgrades (#578)
* feat: started working on new upgrades API * feat: start working on builtin enchantment upgrades * feat: WIP enchantment upgrades now we need to actually apply those upgrades * docs: update licenses * feat: apply to configuration for enchantment upgrades * feat: enchantment upgrade handling * feat: healpool and traps * feat: spawner auto discovery, fixed upgrade shop config * fix: upgrade shop prefab, applying enchantment upgrade
1 parent d865f29 commit 0ba1a98

34 files changed

+1396
-56
lines changed

api/src/main/java/org/screamingsandals/bedwars/api/Team.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.jetbrains.annotations.ApiStatus;
2323
import org.jetbrains.annotations.UnknownNullability;
2424
import org.screamingsandals.bedwars.api.game.LocalGame;
25+
import org.screamingsandals.bedwars.api.game.upgrade.Upgradable;
2526
import org.screamingsandals.bedwars.api.game.target.Target;
2627
import org.screamingsandals.bedwars.api.player.BWPlayer;
2728
import org.screamingsandals.lib.api.types.server.ContainerHolder;
@@ -35,7 +36,7 @@
3536
* @author ScreamingSandals
3637
*/
3738
@ApiStatus.NonExtendable
38-
public interface Team {
39+
public interface Team extends Upgradable {
3940
/**
4041
* <p>Gets the team's current game.</p>
4142
*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2025 ScreamingSandals
3+
*
4+
* This file is part of Screaming BedWars.
5+
*
6+
* Screaming BedWars is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Screaming BedWars is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.screamingsandals.bedwars.api.events;
21+
22+
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.NotNull;
24+
import org.screamingsandals.bedwars.api.BedwarsAPI;
25+
import org.screamingsandals.bedwars.api.Team;
26+
import org.screamingsandals.bedwars.api.game.LocalGame;
27+
import org.screamingsandals.bedwars.api.player.BWPlayer;
28+
29+
import java.util.function.Consumer;
30+
31+
@ApiStatus.NonExtendable
32+
public interface TrapTriggeredEvent extends BWCancellable {
33+
@NotNull LocalGame game();
34+
35+
@NotNull BWPlayer player();
36+
37+
@NotNull Team owningTeam();
38+
39+
// TODO: potion effect (add type to api-utils)
40+
41+
boolean affectsTeamMembers();
42+
43+
boolean affectsEnemies();
44+
45+
boolean singularUse();
46+
47+
double detectionRange();
48+
49+
static void handle(@NotNull Object plugin, @NotNull Consumer<@NotNull TrapTriggeredEvent> consumer) {
50+
BedwarsAPI.getInstance().getEventUtils().handle(plugin, TrapTriggeredEvent.class, consumer);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2025 ScreamingSandals
3+
*
4+
* This file is part of Screaming BedWars.
5+
*
6+
* Screaming BedWars is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Screaming BedWars is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.screamingsandals.bedwars.api.events;
21+
22+
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.NotNull;
24+
import org.screamingsandals.bedwars.api.BedwarsAPI;
25+
import org.screamingsandals.bedwars.api.game.LocalGame;
26+
import org.screamingsandals.bedwars.api.game.upgrade.Upgradable;
27+
import org.screamingsandals.bedwars.api.game.upgrade.Upgrade;
28+
29+
import java.util.function.Consumer;
30+
31+
@ApiStatus.NonExtendable
32+
public interface UpgradeLevelChangeEvent extends BWCancellable {
33+
@NotNull LocalGame getGame();
34+
35+
@NotNull Upgradable getUpgradable();
36+
37+
@NotNull String getName();
38+
39+
@NotNull Upgrade getUpgrade();
40+
41+
double getOldLevel();
42+
43+
double getNewLevel();
44+
45+
double getOriginallyRequestedNewLevel();
46+
47+
void setNewLevel(double level);
48+
49+
static void handle(@NotNull Object plugin, @NotNull Consumer<@NotNull UpgradeLevelChangeEvent> consumer) {
50+
BedwarsAPI.getInstance().getEventUtils().handle(plugin, UpgradeLevelChangeEvent.class, consumer);
51+
}
52+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2025 ScreamingSandals
3+
*
4+
* This file is part of Screaming BedWars.
5+
*
6+
* Screaming BedWars is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Screaming BedWars is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.screamingsandals.bedwars.api.events;
21+
22+
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.NotNull;
24+
import org.screamingsandals.bedwars.api.BedwarsAPI;
25+
import org.screamingsandals.bedwars.api.game.LocalGame;
26+
import org.screamingsandals.bedwars.api.game.upgrade.Upgradable;
27+
import org.screamingsandals.bedwars.api.game.upgrade.Upgrade;
28+
29+
import java.util.function.Consumer;
30+
31+
@ApiStatus.NonExtendable
32+
public interface UpgradeLevelChangedEvent {
33+
@NotNull LocalGame getGame();
34+
35+
@NotNull Upgradable getUpgradable();
36+
37+
@NotNull String getName();
38+
39+
@NotNull Upgrade getUpgrade();
40+
41+
double getOldLevel();
42+
43+
double getNewLevel();
44+
45+
static void handle(@NotNull Object plugin, @NotNull Consumer<@NotNull UpgradeLevelChangedEvent> consumer) {
46+
BedwarsAPI.getInstance().getEventUtils().handle(plugin, UpgradeLevelChangedEvent.class, consumer);
47+
}
48+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (C) 2025 ScreamingSandals
3+
*
4+
* This file is part of Screaming BedWars.
5+
*
6+
* Screaming BedWars is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Screaming BedWars is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.screamingsandals.bedwars.api.game.upgrade;
21+
22+
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.NotNull;
24+
import org.jetbrains.annotations.Nullable;
25+
import org.jetbrains.annotations.Unmodifiable;
26+
27+
import java.util.Map;
28+
29+
/**
30+
* EXPERIMENTAL: Upgrade API is subject to change.
31+
*
32+
* @author ScreamingSandals
33+
* @since 0.3.0
34+
*/
35+
@ApiStatus.NonExtendable
36+
@ApiStatus.Experimental
37+
public interface Upgradable {
38+
/**
39+
* Registers a new upgrade for this upgradable object.
40+
*
41+
* @param name upgrade name. To prevent collisions among plugins, it is recommended to use resource location-like names,
42+
* e.g. {@code my_awesome_plugin:my_awesome_upgrade}, or any other identifier containing the plugin name.
43+
* @param initialLevel initial level
44+
* @throws IllegalStateException if the name is already registered on this upgradable object
45+
* @since 0.3.0
46+
*/
47+
default @NotNull Upgrade registerUpgrade(@NotNull String name, double initialLevel) throws IllegalStateException {
48+
return registerUpgrade(name, initialLevel, null);
49+
}
50+
51+
/**
52+
* Registers a new upgrade for this upgradable object.
53+
*
54+
* @param name upgrade name. To prevent collisions among plugins, it is recommended to use resource location-like names,
55+
* e.g. {@code my_awesome_plugin:my_awesome_upgrade}, or any other identifier containing the plugin name.
56+
* @param initialLevel initial level
57+
* @param maxLevel maximal level or null
58+
* @throws IllegalStateException if the name is already registered on this upgradable object
59+
* @since 0.3.0
60+
*/
61+
@NotNull Upgrade registerUpgrade(@NotNull String name, double initialLevel, @Nullable Double maxLevel) throws IllegalStateException;
62+
63+
/**
64+
* Checks whether an upgrade with such name is registered
65+
*
66+
* @param name upgrade name
67+
* @return true if the upgrade is registered; otherwise false.
68+
* @since 0.3.0
69+
*/
70+
default boolean isUpgradeRegistered(@NotNull String name) {
71+
return getUpgrade(name) != null;
72+
}
73+
74+
/**
75+
* Gets a registered upgrade.
76+
*
77+
* @param name upgrade name
78+
* @return registered upgrade or null if the upgrade is not registered.
79+
* @since 0.3.0
80+
*/
81+
@Nullable Upgrade getUpgrade(@NotNull String name);
82+
83+
/**
84+
* Gets all registered upgrades.
85+
*
86+
* @return all upgrades on this object
87+
* @since 0.3.0
88+
*/
89+
@Unmodifiable @NotNull Map<@NotNull String, @NotNull Upgrade> getUpgrades();
90+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (C) 2025 ScreamingSandals
3+
*
4+
* This file is part of Screaming BedWars.
5+
*
6+
* Screaming BedWars is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Screaming BedWars is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.screamingsandals.bedwars.api.game.upgrade;
21+
22+
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.Nullable;
24+
25+
/**
26+
* EXPERIMENTAL: Upgrade API is subject to change.
27+
*
28+
* @author ScreamingSandals
29+
* @since 0.3.0
30+
*/
31+
@ApiStatus.NonExtendable
32+
@ApiStatus.Experimental
33+
public interface Upgrade {
34+
/**
35+
* Gets the current level of this upgrade.
36+
*
37+
* @return current level of upgrade
38+
* @since 0.3.0
39+
*/
40+
double getLevel();
41+
42+
/**
43+
* Sets level of this upgrade
44+
*
45+
* @param level Current level
46+
* @since 0.3.0
47+
*/
48+
void setLevel(double level);
49+
50+
/**
51+
* Add levels to this upgrade
52+
*
53+
* @param level Levels that will be added to current level
54+
* @since 0.3.0
55+
*/
56+
void increaseLevel(double level);
57+
58+
/**
59+
* Gets the initial level of this upgrade.
60+
*
61+
* @return the initial level of the upgrade
62+
* @since 0.3.0
63+
*/
64+
double getInitialLevel();
65+
66+
/**
67+
* Gets the maximal level to which a player can upgrade. Plugins can bypass this level using {@link #setLevel(double)}, or {@link #increaseLevel(double)}
68+
*
69+
* @return the maximal level of the upgrade
70+
* @since 0.3.0
71+
*/
72+
@Nullable Double getMaximalLevel();
73+
}

api/src/main/java/org/screamingsandals/bedwars/api/upgrades/Upgrade.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
package org.screamingsandals.bedwars.api.upgrades;
2121

22+
import org.jetbrains.annotations.ApiStatus;
2223
import org.screamingsandals.bedwars.api.game.LocalGame;
2324

2425
/**
25-
* @author ScreamingSandals
26+
* EXPERIMENTAL: Upgrade API is subject to change.
2627
*
28+
* @author ScreamingSandals
2729
*/
30+
@ApiStatus.Experimental
2831
public interface Upgrade {
2932

3033
/**

api/src/main/java/org/screamingsandals/bedwars/api/upgrades/UpgradeRegistry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919

2020
package org.screamingsandals.bedwars.api.upgrades;
2121

22+
import org.jetbrains.annotations.ApiStatus;
2223
import org.screamingsandals.bedwars.api.game.LocalGame;
2324
import org.screamingsandals.bedwars.api.game.ItemSpawner;
2425

2526
import java.util.HashMap;
2627
import java.util.Map;
2728

2829
/**
30+
* EXPERIMENTAL: Upgrade API is subject to change.
31+
*
2932
* @author ScreamingSandals
3033
*/
34+
@ApiStatus.Experimental
3135
public final class UpgradeRegistry {
3236
private static final Map<String, UpgradeStorage> registeredUpgrades = new HashMap<>();
3337

api/src/main/java/org/screamingsandals/bedwars/api/upgrades/UpgradeStorage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.screamingsandals.bedwars.api.upgrades;
2121

22+
import org.jetbrains.annotations.ApiStatus;
2223
import org.screamingsandals.bedwars.api.BedwarsAPI;
2324
import org.screamingsandals.bedwars.api.game.LocalGame;
2425
import org.screamingsandals.bedwars.api.game.ItemSpawner;
@@ -31,8 +32,11 @@
3132
import java.util.Map;
3233

3334
/**
35+
* EXPERIMENTAL: Upgrade API is subject to change.
36+
*
3437
* @author ScreamingSandals
3538
*/
39+
@ApiStatus.Experimental
3640
public final class UpgradeStorage {
3741
private final String upgradeName;
3842
private final Class<? extends Upgrade> upgradeClass;

0 commit comments

Comments
 (0)