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
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ private enum CheckResult {
/**
* Island is open for teleporting
*/
OPEN
OPEN,
/**
* Island is locked but player has bypass permission
*/
BYPASS_LOCK;

/**
* @return true if the player is allowed to enter the island
*/
boolean isAllowed() {
return this != BANNED && this != LOCKED;
}
}

// Teleport check
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
e.setCancelled(!checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN));
e.setCancelled(!checkAndNotify(e.getPlayer(), e.getTo()).isAllowed());
}

// Movement check
Expand All @@ -59,14 +70,14 @@ public void onPlayerMove(PlayerMoveEvent e) {
if (e.getFrom().getBlockX() - e.getTo().getBlockX() == 0 && e.getFrom().getBlockZ() - e.getTo().getBlockZ() == 0) {
return;
}
if (!checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN)) {
if (!checkAndNotify(e.getPlayer(), e.getTo()).isAllowed()) {
e.setCancelled(true);
e.getPlayer().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
e.getPlayer().setVelocity(new Vector(0,0,0));
e.getPlayer().setGliding(false);
}
// Check from - just in case the player is inside the island
if (!check(e.getPlayer(), e.getFrom()).equals(CheckResult.OPEN)) {
if (!check(e.getPlayer(), e.getFrom()).isAllowed()) {
// Has to be done 1 tick later otherwise it doesn't happen for some reason...
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> eject(e.getPlayer()));
}
Expand All @@ -81,7 +92,7 @@ public void onVehicleMove(VehicleMoveEvent e) {
}
// For each Player in the vehicle
e.getVehicle().getPassengers().stream().filter(Player.class::isInstance).map(Player.class::cast).forEach(p -> {
if (!checkAndNotify(p, e.getTo()).equals(CheckResult.OPEN)) {
if (!checkAndNotify(p, e.getTo()).isAllowed()) {
p.leaveVehicle();
p.teleport(e.getFrom());
e.getVehicle().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
Expand All @@ -93,7 +104,7 @@ public void onVehicleMove(VehicleMoveEvent e) {
// Login check
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerLogin(PlayerJoinEvent e) {
if (!checkAndNotify(e.getPlayer(), e.getPlayer().getLocation()).equals(CheckResult.OPEN)) {
if (!checkAndNotify(e.getPlayer(), e.getPlayer().getLocation()).isAllowed()) {
eject(e.getPlayer());
}
}
Expand Down Expand Up @@ -124,7 +135,7 @@ private CheckResult check(@NonNull Player player, Location loc)
if (!is.isAllowed(User.getInstance(player), Flags.LOCK))
{
return player.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + "mod.bypasslock") ?
CheckResult.OPEN : CheckResult.LOCKED;
CheckResult.BYPASS_LOCK : CheckResult.LOCKED;
}
return CheckResult.OPEN;
}).
Expand All @@ -144,6 +155,8 @@ private CheckResult checkAndNotify(@NonNull Player player, Location loc)
User.getInstance(player).notify("commands.island.ban.you-are-banned");
} else if (result == CheckResult.LOCKED) {
User.getInstance(player).notify("protection.locked");
} else if (result == CheckResult.BYPASS_LOCK) {
User.getInstance(player).notify("protection.locked-island-bypass");
}
return result;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,7 @@ protection:
&a entity mimo hranice ostrova.
name: Světové poškození TNT
locked: '&c Tento ostrov je zamčen!'
locked-island-bypass: '&6 Tento [prefix_island] je zamčen, ale máte povolení ho obejít.'
protected: '&c Ostrov chráněn: [description]'
world-protected: '&c Svět chráněn: [description]'
spawn-protected: '&c Spawn chráněn: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,7 @@ protection:
&a verletzen.
name: Welt-TNT-Schaden
locked: '&c Diese Insel ist gesperrt!'
locked-island-bypass: '&6 Diese [prefix_island] ist gesperrt, aber du hast die Erlaubnis, sie zu betreten.'
protected: '&c Insel geschützt: [description]'
world-protected: '&c Welt geschützt: [description]'
spawn-protected: '&c Spawn geschützt: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ protection:
&a entities outside of [prefix_island] limits.
name: World TNT damage
locked: '&c This [prefix_island] is locked!'
locked-island-bypass: '&6 This [prefix_island] is locked, but you have permission to bypass.'
protected: '&c [prefix_Island] protected: [description].'
world-protected: '&c World protected: [description].'
spawn-protected: '&c Spawn protected: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,7 @@ protection:
&a entidades fuera de los límites de la isla.
name: Daño mundial de TNT
locked: '&cEsta isla esta cerrada!'
locked-island-bypass: '&6Esta [prefix_island] está cerrada, pero tienes permiso para acceder.'
protected: '&cIsla protegida: [description]'
world-protected: '&cMundo protegido: [description]'
spawn-protected: '&cSpawn protegido: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,7 @@ protection:
&a entités en dehors des limites de l’île.
name: Dommages mondiaux au TNT
locked: '&c Cette île est verrouillée!'
locked-island-bypass: '&6 Cette [prefix_island] est verrouillée, mais vous avez la permission de la traverser.'
protected: '&c Île protégée: [description]'
world-protected: '&c Monde protégé: [description]'
spawn-protected: '&c Spawn protégé: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ protection:
&a entiteta izvan granica otoka.
name: Svjetska TNT šteta
locked: '&c Ovaj otok je zaključan!'
locked-island-bypass: '&6 Ovaj [prefix_island] je zaključan, ali imate dozvolu za pristup.'
protected: '&c Otok zaštićen: [opis].'
world-protected: '&c Svijet zaštićen: [opis].'
spawn-protected: '&c Spawn zaštićeno: [opis].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ protection:
&a entitások a [prefix_island] határain kívül.
name: Világ TNT kár
locked: '&c Ez a [prefix_island] le van zárva!'
locked-island-bypass: '&6 Ez a [prefix_island] le van zárva, de van engedélyed a belépésre.'
protected: '&c [prefix_Island] védett: [description].'
world-protected: '&c Világvédett: [description].'
spawn-protected: '&c Spawn védett: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ protection:
&sebuah entitas di luar batas pulau.
name: Kerusakan TNT dunia
locked: '&c Pulau ini terkunci!'
locked-island-bypass: '&6 [prefix_Island] ini terkunci, tetapi kamu memiliki izin untuk melewatinya.'
protected: '&c Pulau dilindungi: [deskripsi].'
world-protected: '&c Dunia dilindungi: [deskripsi].'
spawn-protected: '&c Bibit dilindungi: [deskripsi].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ protection:
&a entità al di fuori dei limiti di [prefix_island].
name: Danno TNT nel mondo
locked: '&cQuest''isola è bloccata!'
locked-island-bypass: '&6Questa [prefix_island] è bloccata, ma hai il permesso di accedervi.'
protected: '&cIsola protetta: [description]'
world-protected: '&c Mondo protetto: [description]'
spawn-protected: '&cSpawn protetto: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ protection:
&a島の制限外のエンティティ。
name: 世界のTNTダメージ
locked: 島はロックされている!
locked-island-bypass: '&6この[prefix_island]はロックされていますが、あなたはバイパスする権限を持っています。'
protected: '島保護: [description]'
world-protected: '&c世界保護: [description]'
spawn-protected: '&c保護されたスポーン: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ protection:
&a 광산차를 허용하세요.
name: 월드 TNT 피해
locked: '&c 이 섬은 잠겨있습니다!'
locked-island-bypass: '&6 이 [prefix_island]은 잠겨있지만, 당신은 우회할 권한이 있습니다.'
protected: '&c 섬 보호: [description].'
world-protected: '&c 월드 보호: [description].'
spawn-protected: '&c 스폰 보호: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ protection:
&a ievainojumus ārpus [prefix_island] robežām.
name: Pasaule TNT kaitējums
locked: '&cŠī sala ir slēgta!'
locked-island-bypass: '&6Šī [prefix_island] ir slēgta, bet jums ir atļauja to apiet.'
protected: '&cSala ir aizsargāta: [description]'
world-protected: '&cPasaule aizsargāta: [description]'
spawn-protected: '&cSākuma sala ir aizsargāta: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ protection:
&a entiteit buiten de eilandgrenzen.
name: Wereld TNT-schade
locked: '&c Dit eiland is op slot!'
locked-island-bypass: '&6 Dit [prefix_island] is op slot, maar je hebt toestemming om dit te negeren.'
protected: '&c Eiland beschermd: [omschrijving].'
world-protected: '&c Wereld beschermd: [omschrijving].'
spawn-protected: '&c Spawn beschermd: [omschrijving].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,7 @@ protection:
&a jednostkom poza granicami [prefix_island].
name: Świat uszkodzenia TNT
locked: '&cTa wyspa jest zamknięta!'
locked-island-bypass: '&6 Ta [prefix_island] jest zamknięta, ale masz uprawnienia, by ją ominąć.'
protected: '&cWyspa chroniona: [description]'
world-protected: '&c Świat chroniony: [description]'
spawn-protected: '&c Spawn chroniony: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,7 @@ protection:
entidades fora dos limites de [prefix_island].
name: Dano de TNT no mundo
locked: '&c Essa ilha está trancada!'
locked-island-bypass: '&6 Essa [prefix_island] está trancada, mas você tem permissão para acessá-la.'
protected: '&c Ilha protegida: [description].'
world-protected: '&c Mundo protegido: [description].'
spawn-protected: '&c Spawn protegido: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,7 @@ protection:
&a entidades fora dos limites da ilha.
name: Danos mundiais de TNT
locked: '&c Esta ilha está trancada!'
locked-island-bypass: '&6 Esta [prefix_island] está trancada, mas tem permissão para aceder.'
protected: '&c Ilha protegida: [descrição].'
world-protected: '&c Protegido mundialmente: [descrição].'
spawn-protected: '&c Spawn protegido: [descrição].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,7 @@ protection:
&o entități în afara limitelor insulei.
name: Daune TNT mondiale
locked: '&c Această insulă este blocată!'
locked-island-bypass: '&6 Această [prefix_island] este blocată, dar ai permisiunea de a o ocoli.'
protected: '&c Insula protejată: [description].'
world-protected: '&c Protecție mondială: [description].'
spawn-protected: '&c Spawn protejat: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ protection:
&a за пределами острова.
name: Разрушение блоков через TNT
locked: '&cЭтот остров заблокирован!'
locked-island-bypass: '&6 Этот [prefix_island] заблокирован, но у вас есть разрешение на вход.'
protected: '&cОстров защищен: [description].'
world-protected: '&cМир защищен: [description].'
spawn-protected: '&cСпавн защищен: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ protection:
&a varlıklara zarar vermesine izin verin.
name: Dünya TNT hasarı
locked: '&4Bu ada kilitli!'
locked-island-bypass: '&6 Bu [prefix_island] kilitli, ancak geçiş izniniz var.'
protected: '&4Ada korunuyor: [description]'
world-protected: '&cDünya korunuyor: [description]'
spawn-protected: '&4Spawn koruması: [description]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ protection:
&a за межами [prefix_island].
name: Світова шкода від ТНТ
locked: '&c Цей [prefix_island] заблоковано!'
locked-island-bypass: '&6 Цей [prefix_island] заблоковано, але у вас є дозвіл на вхід.'
protected: '&c [prefix_Island] захищено: [description].'
world-protected: '&c Світ захищено: [description].'
spawn-protected: '&c Спавн захищено: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/vi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@ protection:
&a ở ngoài đảo.
name: Sát thường từ TNT ngoài đảo
locked: '&c Đảo đã khóa!'
locked-island-bypass: '&6 [prefix_Island] này đã bị khóa, nhưng bạn có quyền đi qua.'
protected: '&c Đảo đã bảo vệ: [description].'
world-protected: '&c Thế giới đã bảo vệ: [description].'
spawn-protected: '&c Điểm triệu hồi đã bảo vệ: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ protection:
&#FAFAD2对岛屿保护范围之外的方块和实体造成破坏和伤害
name: '&b&l边界TNT保护'
locked: '&c这个岛屿已被锁定!'
locked-island-bypass: '&6 这个[prefix_island]已被锁定,但你有权限绕过。'
protected: '&c岛屿保护: [description].'
world-protected: '&c世界保护: [description].'
spawn-protected: '&c出生点保护: [description].'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/zh-HK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ protection:
&7和TNT礦車破壞方塊和實體
name: '&a&l世界TNT傷害'
locked: '&c本島嶼已被鎖定!'
locked-island-bypass: '&6 本[prefix_island]已被鎖定,但您有權限繞過。'
protected: '&c島嶼保護:[description]'
world-protected: '&c世界保護: [description].'
spawn-protected: '&c生成保護:[description]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void testLoginToLockedIslandWithBypassPerm() {
Player player = mock(Player.class);
when(player.isOp()).thenReturn(false);
when(player.hasPermission(anyString())).thenReturn(true);
when(player.getWorld()).thenReturn(world);

when(player.getUniqueId()).thenReturn(uuid);
// Give player an island
Expand All @@ -442,8 +443,8 @@ void testLoginToLockedIslandWithBypassPerm() {

// Log them in
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
// User should not see a message
verify(notifier, never()).notify(any(), anyString());
// User should see a bypass message
verify(notifier).notify(any(), anyString());
// User should not be teleported somewhere
verify(im, never()).homeTeleportAsync(any(), eq(player));
}
Expand Down Expand Up @@ -539,12 +540,14 @@ void testPlayerMoveIntoLockedIslandWithBypass() {
when(mockPlayer.getLocation()).thenReturn(outside);

// Lock island for player
when(island.isAllowed(user, Flags.LOCK)).thenReturn(false);
when(island.isAllowed(any(User.class), eq(Flags.LOCK))).thenReturn(false);

// Move player
PlayerMoveEvent e = new PlayerMoveEvent(mockPlayer, outside, inside);
listener.onPlayerMove(e);
assertFalse(e.isCancelled());
// User should see a bypass notification
verify(notifier).notify(any(), anyString());
}

@Test
Expand Down Expand Up @@ -620,18 +623,21 @@ void testPlayerMoveInsideLockedIslandWithBypass() {
when(player.getUniqueId()).thenReturn(uuid);
when(player.isOp()).thenReturn(false);
when(player.hasPermission(anyString())).thenReturn(true);
when(player.getWorld()).thenReturn(world);
// Give player an island
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
// Place the player inside island
when(player.getLocation()).thenReturn(inside);

// Lock island for player
when(island.isAllowed(user, Flags.LOCK)).thenReturn(false);
when(island.isAllowed(any(User.class), eq(Flags.LOCK))).thenReturn(false);

// Move player
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
listener.onPlayerMove(e);
assertFalse(e.isCancelled());
// User should see a bypass notification
verify(notifier).notify(any(), anyString());
}

@Test
Expand Down
Loading