Skip to content

Commit 8b2cb30

Browse files
authored
Merge pull request #456 from BentoBoxWorld/develop
Release 1.21.0
2 parents c1381ab + f9376f1 commit 8b2cb30

File tree

12 files changed

+352
-58
lines changed

12 files changed

+352
-58
lines changed

pom.xml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<!-- Do not change unless you want different name for local builds. -->
6565
<build.number>-LOCAL</build.number>
6666
<!-- This allows to change between versions. -->
67-
<build.version>1.20.1</build.version>
67+
<build.version>1.21.0</build.version>
6868
<!-- SonarCloud -->
6969
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
7070
<sonar.organization>bentobox-world</sonar.organization>
@@ -123,8 +123,12 @@
123123

124124
<repositories>
125125
<repository>
126-
<id>spigot-repo</id>
127-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
126+
<id>jitpack.io</id>
127+
<url>https://jitpack.io</url>
128+
</repository>
129+
<repository>
130+
<id>papermc</id>
131+
<url>https://repo.papermc.io/repository/maven-public/</url>
128132
</repository>
129133
<repository>
130134
<id>minecraft-repo</id>
@@ -153,18 +157,17 @@
153157
</repositories>
154158

155159
<dependencies>
156-
<!-- Spigot API -->
157160
<dependency>
158-
<groupId>org.spigotmc</groupId>
159-
<artifactId>spigot-api</artifactId>
160-
<version>${spigot.version}</version>
161-
<scope>provided</scope>
162-
</dependency>
161+
<groupId>com.github.MockBukkit</groupId>
162+
<artifactId>MockBukkit</artifactId>
163+
<version>v1.21-SNAPSHOT</version>
164+
<scope>test</scope>
165+
</dependency>
163166
<dependency>
164-
<groupId>org.spigotmc</groupId>
165-
<artifactId>plugin-annotations</artifactId>
166-
<version>1.2.3-SNAPSHOT</version>
167-
<scope>compile</scope>
167+
<groupId>io.papermc.paper</groupId>
168+
<artifactId>paper-api</artifactId>
169+
<version>1.21.10-R0.1-SNAPSHOT</version>
170+
<scope>provided</scope>
168171
</dependency>
169172
<!-- Apache Commons Text -->
170173
<dependency>
@@ -223,7 +226,6 @@
223226
<version>${items-adder.version}</version>
224227
<scope>provided</scope>
225228
</dependency>
226-
227229
</dependencies>
228230

229231
<build>
@@ -292,7 +294,6 @@
292294
<version>3.0.0-M5</version>
293295
<configuration>
294296
<argLine>
295-
${argLine}
296297
--add-opens java.base/java.lang=ALL-UNNAMED
297298
--add-opens java.base/java.math=ALL-UNNAMED
298299
--add-opens java.base/java.io=ALL-UNNAMED

src/main/java/world/bentobox/aoneblock/AOneBlock.java

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import world.bentobox.bentobox.api.flags.Flag.Mode;
3939
import world.bentobox.bentobox.api.flags.Flag.Type;
4040
import world.bentobox.bentobox.database.objects.Island;
41+
import world.bentobox.bentobox.managers.RanksManager;
4142

4243
/**
4344
* Main OneBlock class - provides an island minigame in the sky
@@ -46,29 +47,65 @@
4647
*/
4748
public class AOneBlock extends GameModeAddon {
4849

50+
/** Suffix for the nether world */
4951
private static final String NETHER = "_nether";
52+
/** Suffix for the end world */
5053
private static final String THE_END = "_the_end";
54+
/** Whether ItemsAdder is present on the server */
5155
private boolean hasItemsAdder = false;
5256

53-
// Settings
57+
/** The addon settings */
5458
private Settings settings;
59+
/** The custom chunk generator for OneBlock worlds */
5560
private ChunkGeneratorWorld chunkGenerator;
61+
/** The configuration object for settings */
5662
private final Config<Settings> configObject = new Config<>(this, Settings.class);
63+
/** The listener for block-related events */
5764
private BlockListener blockListener;
65+
/** The manager for OneBlock phases and blocks */
5866
private OneBlocksManager oneBlockManager;
67+
/** The placeholder manager for AOneBlock */
5968
private AOneBlockPlaceholders phManager;
69+
/** The listener for hologram-related events */
6070
private HoloListener holoListener;
6171

62-
// Flag
72+
/**
73+
* Flag to enable or disable start safety for players.
74+
*/
6375
public final Flag START_SAFETY = new Flag.Builder("START_SAFETY", Material.BAMBOO_BLOCK)
6476
.mode(Mode.BASIC)
6577
.type(Type.WORLD_SETTING)
6678
.listener(new StartSafetyListener(this))
6779
.defaultSetting(false)
6880
.build();
81+
/** The listener for the boss bar */
6982
private BossBarListener bossBar = new BossBarListener(this);
70-
public final Flag ONEBLOCK_BOSSBAR = new Flag.Builder("ONEBLOCK_BOSSBAR", Material.DRAGON_HEAD).mode(Mode.BASIC)
71-
.type(Type.SETTING).listener(bossBar).defaultSetting(true).build();
83+
/**
84+
* Flag to enable or disable the OneBlock boss bar.
85+
*/
86+
public final Flag ONEBLOCK_BOSSBAR = new Flag.Builder("ONEBLOCK_BOSSBAR", Material.DRAGON_HEAD)
87+
.mode(Mode.BASIC)
88+
.type(Type.SETTING)
89+
.listener(bossBar)
90+
.defaultSetting(true)
91+
.build();
92+
/**
93+
* Flag to enable or disable the OneBlock action bar.
94+
*/
95+
public final Flag ONEBLOCK_ACTIONBAR = new Flag.Builder("ONEBLOCK_ACTIONBAR", Material.IRON_BARS)
96+
.mode(Mode.BASIC)
97+
.type(Type.SETTING)
98+
.listener(bossBar)
99+
.defaultSetting(true)
100+
.build();
101+
/**
102+
* Flag to set who can break the magic block.
103+
*/
104+
public final Flag MAGIC_BLOCK = new Flag.Builder("MAGIC_BLOCK", Material.GRASS_BLOCK)
105+
.mode(Mode.BASIC)
106+
.type(Type.PROTECTION)
107+
.defaultRank(RanksManager.COOP_RANK)
108+
.build();
72109

73110
@Override
74111
public void onLoad() {
@@ -94,9 +131,15 @@ public void onLoad() {
94131
getPlugin().getFlagsManager().registerFlag(this, START_SAFETY);
95132
// Bossbar
96133
getPlugin().getFlagsManager().registerFlag(this, this.ONEBLOCK_BOSSBAR);
134+
// Magic Block protection
135+
getPlugin().getFlagsManager().registerFlag(this, this.MAGIC_BLOCK);
97136
}
98137
}
99138

139+
/**
140+
* Loads the settings from the config file.
141+
* @return true if settings were loaded successfully, false otherwise.
142+
*/
100143
private boolean loadSettings() {
101144
// Load settings again to get worlds
102145
settings = configObject.loadConfigObject();
@@ -114,11 +157,14 @@ private boolean loadSettings() {
114157

115158
@Override
116159
public void onEnable() {
160+
// Initialize the OneBlock manager
117161
oneBlockManager = new OneBlocksManager(this);
162+
// Load phase data
118163
if (loadData()) {
119164
// Failed to load - don't register anything
120165
return;
121166
}
167+
// Initialize and register listeners
122168
blockListener = new BlockListener(this);
123169
registerListener(blockListener);
124170
registerListener(new NoBlockHandler(this));
@@ -138,12 +184,15 @@ public void onEnable() {
138184
registerListener(holoListener);
139185
}
140186

141-
// Load phase data
187+
/**
188+
* Load phase data from oneblock.yml.
189+
* @return true if there was an error, false otherwise.
190+
*/
142191
public boolean loadData() {
143192
try {
144193
oneBlockManager.loadPhases();
145194
} catch (IOException e) {
146-
// Disable
195+
// Disable the addon if phase data cannot be loaded
147196
logError("AOneBlock settings could not load (oneblock.yml error)! Addon disabled.");
148197
logError(e.getMessage());
149198
setState(State.DISABLED);
@@ -169,6 +218,7 @@ public void onDisable() {
169218
public void onReload() {
170219
// save cache
171220
blockListener.saveCache();
221+
// Reload settings and phase data
172222
if (loadSettings()) {
173223
log("Reloaded AOneBlock settings");
174224
loadData();
@@ -223,6 +273,7 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
223273
worldName2 = env.equals(World.Environment.NETHER) ? worldName2 + NETHER : worldName2;
224274
worldName2 = env.equals(World.Environment.THE_END) ? worldName2 + THE_END : worldName2;
225275
WorldCreator wc = WorldCreator.name(worldName2).environment(env);
276+
// Use custom generator if configured, otherwise default
226277
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
227278
// Set spawn rates
228279
if (w != null) {
@@ -232,6 +283,10 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
232283

233284
}
234285

286+
/**
287+
* Sets the spawn rates for a given world based on the addon's settings.
288+
* @param w The world to set spawn rates for.
289+
*/
235290
private void setSpawnRates(World w) {
236291
if (getSettings().getSpawnLimitMonsters() > 0) {
237292
w.setSpawnLimit(SpawnCategory.MONSTER, getSettings().getSpawnLimitMonsters());
@@ -298,6 +353,9 @@ public OneBlockIslands getOneBlocksIsland(@NonNull Island i) {
298353
return blockListener.getIsland(Objects.requireNonNull(i));
299354
}
300355

356+
/**
357+
* @return The OneBlock manager.
358+
*/
301359
public OneBlocksManager getOneBlockManager() {
302360
return oneBlockManager;
303361
}
@@ -341,6 +399,10 @@ public void setIslandWorld(World world) {
341399

342400
}
343401

402+
/**
403+
* Sets the addon's settings. Used only for testing.
404+
* @param settings The settings to set.
405+
*/
344406
public void setSettings(Settings settings) {
345407
this.settings = settings;
346408
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package world.bentobox.aoneblock.commands.island;
2+
3+
import java.util.List;
4+
5+
import world.bentobox.aoneblock.AOneBlock;
6+
import world.bentobox.bentobox.api.commands.CompositeCommand;
7+
import world.bentobox.bentobox.api.user.User;
8+
9+
public class IslandActionBarCommand extends CompositeCommand {
10+
11+
private AOneBlock addon;
12+
13+
public IslandActionBarCommand(CompositeCommand islandCommand, String label, String[] aliases)
14+
{
15+
super(islandCommand, label, aliases);
16+
}
17+
18+
@Override
19+
public void setup() {
20+
setDescription("aoneblock.commands.island.actionbar.description");
21+
setOnlyPlayer(true);
22+
// Permission
23+
setPermission("island.actionbar");
24+
addon = getAddon();
25+
}
26+
27+
@Override
28+
public boolean execute(User user, String label, List<String> args) {
29+
addon.getBossBar().toggleUser(user);
30+
getIslands().getIslandAt(user.getLocation()).ifPresent(i -> {
31+
if (!i.isAllowed(addon.ONEBLOCK_ACTIONBAR)) {
32+
user.sendMessage("aoneblock.actionbar.not-active");
33+
}
34+
});
35+
return true;
36+
}
37+
}

0 commit comments

Comments
 (0)