Skip to content

Commit

Permalink
Fixes bugs with when world border needs to be shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 21, 2021
1 parent 1ad4d9a commit f007304
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
19 changes: 10 additions & 9 deletions src/main/java/world/bentobox/border/Border.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public void onLoad() {

@Override
public void onEnable() {
// Check for WorldBorderAPI
if (getSettings().isUseWbapi()) {
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldBorderAPI");
if (plugin == null || !plugin.isEnabled()) {
logError("WorldBorderAPI not found. Download from https://github.com/yannicklamprecht/WorldBorderAPI/releases");
logError("Disabling addon");
this.setState(State.DISABLED);
return;
}
}
gameModes.clear();
playerBorder = new PlayerBorder(this);
// Register commands
Expand Down Expand Up @@ -87,15 +97,6 @@ private void loadSettings() {
// Save new version
this.config.saveConfigObject(settings);

// Check for WorldBorderAPI
if (getSettings().isUseWbapi()) {
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldBorderAPI");
if (plugin == null || !plugin.isEnabled()) {
getLogger().warning("WorldBorderAPI not found. Download from https://github.com/yannicklamprecht/WorldBorderAPI/releases");
this.setState(State.DISABLED);
return;
}
}
}

public Settings getSettings() {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/world/bentobox/border/listeners/PlayerBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,27 @@ public BorderShower getBorder() {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent e) {
// Remove head movement
if (!e.getFrom().toVector().equals(e.getTo().toVector())) {
if (!addon.getSettings().isUseWbapi() && !e.getFrom().toVector().equals(e.getTo().toVector())) {
addon.getIslands().getIslandAt(e.getPlayer().getLocation()).ifPresent(i -> barrier.showBorder(e.getPlayer(), i));
}
}

@EventHandler(priority = EventPriority.NORMAL)
public void onVehicleMove(VehicleMoveEvent e) {
// Remove head movement
if (!e.getFrom().toVector().equals(e.getTo().toVector())) {
if (!addon.getSettings().isUseWbapi() && !e.getFrom().toVector().equals(e.getTo().toVector())) {
e.getVehicle().getPassengers().stream().filter(en -> en instanceof Player).map(en -> (Player)en).forEach(p ->
addon.getIslands().getIslandAt(p.getLocation()).ifPresent(i -> barrier.showBorder(p, i)));
}
}

@EventHandler(priority = EventPriority.NORMAL)
public void onProtectionRangeChange(IslandProtectionRangeChangeEvent e) {
// Cleans up barrier blocks that were on old range
e.getIsland().getPlayersOnIsland().forEach(player -> barrier.hideBorder(User.getInstance(player)));
// Hide and show again
e.getIsland().getPlayersOnIsland().forEach(player -> {
barrier.hideBorder(User.getInstance(player));
barrier.showBorder(player, e.getIsland());
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public PlayerListener(Border addon) {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent e) {
shower.clearUser(User.getInstance(e.getPlayer()));
addon.getIslands().getProtectedIslandAt(e.getPlayer().getLocation()).ifPresent(i ->
shower.showBorder(e.getPlayer(), i));
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> addon.getIslands().getProtectedIslandAt(e.getPlayer().getLocation()).ifPresent(i ->
shower.showBorder(e.getPlayer(), i)));
}

@EventHandler(priority = EventPriority.NORMAL)
Expand All @@ -70,6 +70,9 @@ public void onPlayerTeleport(PlayerTeleportEvent e) {

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerLeaveIsland(PlayerMoveEvent e) {
if (addon.getSettings().isUseWbapi()) {
return;
}
Player p = e.getPlayer();
Location from = e.getFrom();
if (!outsideCheck(e.getPlayer(), from, e.getTo())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ public ShowBarrier(Border addon) {
@Override
public void showBorder(Player player, Island island) {

if (addon.getSettings().getDisabledGameModes().contains(island.getGameMode()))
return;

if (!User.getInstance(player).getMetaData(BORDER_STATE_META_DATA).map(MetaDataValue::asBoolean).orElse(addon.getSettings().isShowByDefault())) {
if (addon.getSettings().getDisabledGameModes().contains(island.getGameMode())
|| !User.getInstance(player).getMetaData(BORDER_STATE_META_DATA).map(MetaDataValue::asBoolean).orElse(addon.getSettings().isShowByDefault())) {
return;
}

Expand Down

0 comments on commit f007304

Please sign in to comment.