Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/main/java/world/bentobox/chunkblock/ChunkBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
/**
* Flag to set who can break the magic block.
*/
public final Flag MAGIC_BLOCK = new Flag.Builder("MAGIC_BLOCK", Material.GRASS_BLOCK)
public final Flag CHUNKBLOCK_MAGIC_BLOCK = new Flag.Builder("CHUNKBLOCK_MAGIC_BLOCK", Material.GRASS_BLOCK)

Check warning on line 128 in src/main/java/world/bentobox/chunkblock/ChunkBlock.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "CHUNKBLOCK_MAGIC_BLOCK" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=BentoBoxWorld_ChunkBlock&issues=AZ_pJCvgZ8Hac6hzr8Qc&open=AZ_pJCvgZ8Hac6hzr8Qc&pullRequest=25
.mode(Mode.BASIC)
.type(Type.PROTECTION)
.defaultRank(RanksManager.COOP_RANK)
Expand Down Expand Up @@ -175,19 +175,35 @@
adminCommand = new AdminCommand(this);
// Register flag with BentoBox
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, CHUNKBLOCK_START_SAFETY);
registerFlagOrWarn(CHUNKBLOCK_START_SAFETY);
// Bossbar
if (getSettings().isBossBar()) {
getPlugin().getFlagsManager().registerFlag(this, this.CHUNKBLOCK_BOSSBAR);
registerFlagOrWarn(this.CHUNKBLOCK_BOSSBAR);
}
// Actionbar
if (getSettings().isActionBar()) {
getPlugin().getFlagsManager().registerFlag(this, this.CHUNKBLOCK_ACTIONBAR);
registerFlagOrWarn(this.CHUNKBLOCK_ACTIONBAR);
}
// Magic Block protection
getPlugin().getFlagsManager().registerFlag(this, this.MAGIC_BLOCK);
registerFlagOrWarn(this.CHUNKBLOCK_MAGIC_BLOCK);
// Who may spend level credit on chunks
getPlugin().getFlagsManager().registerFlag(this, this.CHUNKBLOCK_CLAIM_CHUNKS);
registerFlagOrWarn(this.CHUNKBLOCK_CLAIM_CHUNKS);
}
}

/**
* Registers a flag and complains if it is refused. A flag whose ID is already taken by
* another addon is dropped silently by the flags manager, and this addon then runs
* against whichever definition won — so the only symptom would be settings that
* quietly do nothing. Every ID here is prefixed to avoid that, and this says so out
* loud if one ever collides anyway.
*
* @param flag the flag to register
*/
private void registerFlagOrWarn(Flag flag) {
if (!registerFlag(flag)) {
logError("Flag " + flag.getID() + " is already registered by another addon, so ChunkBlock's own "
+ "definition was dropped. Its island settings will behave as that addon defines them.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void onBlockFromTo(final BlockFromToEvent e) {

/**
* Cancels a magic-block break as early as possible when the player lacks the
* {@link ChunkBlock#MAGIC_BLOCK} permission.
* {@link ChunkBlock#CHUNKBLOCK_MAGIC_BLOCK} permission.
* <p>
* The full magic-block processing runs at {@link EventPriority#HIGHEST} so that
* other protection plugins get a chance to cancel first. However, reward-granting
Expand All @@ -256,7 +256,7 @@ public void onBlockBreakDeny(final BlockBreakEvent e) {
// checkIsland cancels the event and sends the protection message if the player
// is not allowed to break the magic block.
addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
.ifPresent(i -> checkIsland(e, e.getPlayer(), i.getCenter(), addon.MAGIC_BLOCK));
.ifPresent(i -> checkIsland(e, e.getPlayer(), i.getCenter(), addon.CHUNKBLOCK_MAGIC_BLOCK));
}

/**
Expand Down Expand Up @@ -394,7 +394,7 @@ private void process(@NonNull Cancellable e, @NonNull Island island, @Nullable P
// player (e.g. the block is broken by a JetsMinions minion) the protection flag
// check is skipped: it requires a User and would otherwise throw an NPE inside
// BentoBox's FlagListener. See https://github.com/BentoBoxWorld/ChunkBlock/issues/525
if (player != null && !checkIsland((@NonNull Event) e, player, island.getCenter(), addon.MAGIC_BLOCK)) {
if (player != null && !checkIsland((@NonNull Event) e, player, island.getCenter(), addon.CHUNKBLOCK_MAGIC_BLOCK)) {
// Not allowed
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ world:
BREAK_BLOCKS: 500
CHORUS_FRUIT: 500
CONTAINER: 500
MAGIC_BLOCK: 200
CHUNKBLOCK_MAGIC_BLOCK: 200
CHUNKBLOCK_CLAIM_CHUNKS: 1000
JUKEBOX: 500
POTION_THROWING: 500
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/cs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Ochrana Kouzelného Bloku
description: |-
&b Hodnost, která může rozbít
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/de.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Schutz des Magischen Blocks
description: |-
&b Rang, der den magischen
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Magic Block Protection
description: |-
&b Rank that can break the magic
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Protección de Bloque Mágico
description: |-
&b Rango que puede romper el
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Protection du Bloc Magique
description: |-
&b Rang qui peut casser le bloc
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/hr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Zaštita Magičnog Bloka
description: |-
&b Rang koji može razbiti
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/hu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Mágikus Blokk Védelem
description: |-
&b Rang, amely képes
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/id.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Perlindungan Blok Ajaib
description: |-
&b Pangkat yang dapat
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/it.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Protezione Blocco Magico
description: |-
&b Rango che può rompere il
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: 魔法ブロック保護
description: |-
&b ブロックを破壊できる場合、
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/pl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Ochrona Magicznego Bloku
description: |-
&b Ranga, która może zniszczyć
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/pt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Proteção de Bloco Mágico
description: |-
&b Rank que pode quebrar o
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Магический блок
description: |-
<green>Предотвращает ломание</green>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/tr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Büyülü Blok Koruması
description: |-
&b Blokları kırabilirlerse
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/uk.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Захист Магічного Блоку
description: |-
&b Ранг, який може зламати
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/vi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: Bảo Vệ Khối Ma Thuật
description: |-
&b Xếp hạng có thể phá
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: 魔法方块保护
description: |-
&b 如果玩家可以破坏方块,
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/locales/zh-TW.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protection:
flags:
MAGIC_BLOCK:
CHUNKBLOCK_MAGIC_BLOCK:
name: 魔法方塊保護
description: |-
&b 如果玩家可以破壞方塊,
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/world/bentobox/chunkblock/ChunkBlockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -38,6 +39,7 @@
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.Addon.State;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseSetup;
Expand Down Expand Up @@ -209,6 +211,26 @@ void testOnLoad() {

}

/**
* Every flag ID must be prefixed. AOneBlock, which this addon was forked from, declares
* flags of its own, and BentoBox's flags manager silently drops the second registration
* of an ID — so an unprefixed ID means that whichever gamemode loads second quietly runs
* on the other one's definition. See issue #24.
*/
@Test
void testEveryFlagIdIsPrefixed() throws IllegalAccessException {
int checked = 0;
for (Field field : ChunkBlock.class.getDeclaredFields()) {
if (Flag.class.isAssignableFrom(field.getType())) {
String id = ((Flag) field.get(addon)).getID();
assertTrue(id.startsWith("CHUNKBLOCK_"),
"Flag " + id + " needs a CHUNKBLOCK_ prefix or it collides with another addon");
checked++;
}
}
assertTrue(checked > 0, "no flags found to check — has the field type changed?");
}

/**
* Test method for {@link world.bentobox.chunkblock.ChunkBlock#onReload()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ void testOnBlockBreakDenyRegisteredAtLowestPriority() throws NoSuchMethodExcepti
/**
* Test method for
* {@link world.bentobox.chunkblock.listeners.BlockListener#onBlockBreakDeny(BlockBreakEvent)}
* When the player lacks the MAGIC_BLOCK permission the break is cancelled at this
* When the player lacks the CHUNKBLOCK_MAGIC_BLOCK permission the break is cancelled at this
* early stage (via checkIsland), so later reward plugins are skipped. Regression
* test for https://github.com/BentoBoxWorld/ChunkBlock/issues/534
*/
Expand Down
Loading