Skip to content

Commit

Permalink
Fixed some nesting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
briannastatic committed Mar 14, 2024
1 parent b02e594 commit 9ba7647
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 109 deletions.
115 changes: 58 additions & 57 deletions src/main/java/com/craftaro/skyblock/scoreboard/ScoreboardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,104 +65,105 @@ public void updateOnlinePlayers() {
}

public void updatePlayerScoreboardType(Player player) {
if (this.enabled) {
PlayerDataManager playerDataManager = this.plugin.getPlayerDataManager();
IslandManager islandManager = this.plugin.getIslandManager();

PlayerData playerData = playerDataManager.getPlayerData(player);
Island island = islandManager.getIsland(player);

if (playerData.isScoreboard()) {
ScoreboardType type;
if (island != null) {
Visit islandVisit = island.getVisit();
boolean hasVisitors = (islandVisit != null &&
islandVisit.getVisitors() != null &&
islandVisit.getVisitors().size() > 1);
boolean hasMembers = (islandVisit != null &&
islandVisit.getMembers() > 1);

if (hasMembers) {
if (hasVisitors) {
type = ScoreboardType.ISLAND_TEAM_VISITORS;
} else {
type = ScoreboardType.ISLAND_TEAM_EMPTY;
}
} else {
if (hasVisitors) {
type = ScoreboardType.ISLAND_SOLO_VISITORS;
} else {
type = ScoreboardType.ISLAND_SOLO_EMPTY;
}
}
if (!this.enabled)
return;

PlayerDataManager playerDataManager = this.plugin.getPlayerDataManager();
IslandManager islandManager = this.plugin.getIslandManager();

PlayerData playerData = playerDataManager.getPlayerData(player);
Island island = islandManager.getIsland(player);

if (!playerData.isScoreboard())
return;

ScoreboardType type;
if (island != null) {
Visit islandVisit = island.getVisit();
boolean hasVisitors = (islandVisit != null &&
islandVisit.getVisitors() != null &&
islandVisit.getVisitors().size() > 1);
boolean hasMembers = (islandVisit != null &&
islandVisit.getMembers() > 1);

if (hasMembers) {
if (hasVisitors) {
type = ScoreboardType.ISLAND_TEAM_VISITORS;
} else {
type = ScoreboardType.NO_ISLAND;
type = ScoreboardType.ISLAND_TEAM_EMPTY;
}
synchronized (player) {
setPlayerScoreboard(player, type);
} else {
if (hasVisitors) {
type = ScoreboardType.ISLAND_SOLO_VISITORS;
} else {
type = ScoreboardType.ISLAND_SOLO_EMPTY;
}
}
} else {
type = ScoreboardType.NO_ISLAND;
}
synchronized (player) {
setPlayerScoreboard(player, type);
}
}


public void setPlayerScoreboard(Player player, ScoreboardType type) {
if (this.enabled) {
for (Driver driver : this.drivers) {
driver.unregisterHolder(player);
if (driver.getBoardType() == type) {
driver.registerHolder(new Holder(this.plugin, driver, player));
}
}
if (!enabled)
return;

for (Driver driver : drivers) {
driver.unregisterHolder(player);
if (driver.getBoardType() == type)
driver.registerHolder(new Holder(plugin, driver, player));
}
}

public void unregisterPlayer(Player player) {
if (this.enabled) {
for (Driver driver : this.drivers) {
driver.unregisterHolder(player);
}
player.setScoreboard(this.emptyScoreboard);
}
if (!enabled)
return;

for (Driver driver : drivers)
driver.unregisterHolder(player);
player.setScoreboard(emptyScoreboard);
}

public void addDisabledPlayer(Player player) {
if (this.enabled) {
this.disabledPlayers.add(player);
Bukkit.getScheduler().runTask(this.plugin, () -> this.unregisterPlayer(player));
Bukkit.getScheduler().runTask(plugin, () -> unregisterPlayer(player));
}
}

public void removeDisabledPlayer(Player player) {
if (this.enabled) {
if (this.enabled)
this.disabledPlayers.remove(player);
}
}

public boolean isPlayerDisabled(Player player) {
return this.disabledPlayers.contains(player);
}

private void newDriver(ScoreboardType board) {
FileManager fileManager = this.plugin.getFileManager();
FileManager fileManager = plugin.getFileManager();
FileConfiguration configload = fileManager.getConfig(
new File(this.plugin.getDataFolder(), "config.yml")).getFileConfiguration();
new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration();

Driver driver = new Driver(this.plugin, board);
Driver driver = new Driver(plugin, board);
if (configload.getBoolean("Island.Scoreboard.Async", true)) {
driver.runTaskTimerAsynchronously(this.plugin, 1L, 1L);
driver.runTaskTimerAsynchronously(plugin, 1L, 1L);
} else {
driver.runTaskTimer(this.plugin, 1L, 1L);
driver.runTaskTimer(plugin, 1L, 1L);
}
this.drivers.add(driver);
drivers.add(driver);
}

public void clearDrivers() {
if (this.enabled) {
if (enabled) {
for (Driver driver : this.drivers) {
driver.cancel();
}
this.drivers.clear();
drivers.clear();
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/craftaro/skyblock/tasks/HologramTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public static HologramTask startTask(SkyBlock plug) {
public void run() {
for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.VOTES) {
if (!plugin.getConfiguration().getBoolean("Island.Visitor.Vote")) {
if (!plugin.getConfiguration().getBoolean("Island.Visitor.Vote"))
continue;
}
}
spawnHologram(hologramTypeList);
}
Expand Down
83 changes: 33 additions & 50 deletions src/main/java/com/craftaro/skyblock/tasks/MobNetherWaterTask.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
package com.craftaro.skyblock.tasks;

import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.skyblock.SkyBlock;
import com.craftaro.skyblock.island.IslandWorld;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Hoglin;
import org.bukkit.entity.MagmaCube;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Piglin;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Strider;
import org.bukkit.entity.Wither;
import org.bukkit.entity.Zoglin;
import org.bukkit.entity.*;
import org.bukkit.scheduler.BukkitRunnable;

public class MobNetherWaterTask extends BukkitRunnable {
Expand All @@ -44,49 +33,43 @@ public static MobNetherWaterTask startTask(SkyBlock plug) {

@Override
public void run() {
if (plugin.getConfiguration().getBoolean("Island.Nether.WaterDisappearWithNetherMobs", false)) {
for (World world : Bukkit.getServer().getWorlds()) {
if (plugin.getWorldManager().isIslandWorld(world) && plugin.getWorldManager().getIslandWorld(world) == IslandWorld.NETHER) {
for (Entity ent : world.getEntities()) {
boolean witherSkeleton;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
witherSkeleton = ent.getType() == EntityType.WITHER_SKELETON;
} else {
witherSkeleton = ent instanceof Skeleton && ((Skeleton) ent).getSkeletonType() == Skeleton.SkeletonType.WITHER;
}
if ((((ent instanceof Blaze || ent instanceof MagmaCube) || ent instanceof Wither) || ent instanceof Ghast) || witherSkeleton) {
Block block = ent.getLocation().getBlock();
removeWater(world, block);
removeWater(world, block.getRelative(BlockFace.UP));
} else {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
if (((ent instanceof Piglin || ent instanceof Hoglin) || ent instanceof Strider) || ent instanceof Zoglin) {
Block block = ent.getLocation().getBlock();
removeWater(world, block);
removeWater(world, block.getRelative(BlockFace.UP));
}
} else {
if (ent instanceof PigZombie) {
Block block = ent.getLocation().getBlock();
removeWater(world, block);
removeWater(world, block.getRelative(BlockFace.UP));
}
}
}
}
}
}
if (!plugin.getConfiguration().getBoolean("Island.Nether.WaterDisappearWithNetherMobs", false))
return;

for (World world : Bukkit.getServer().getWorlds()) {
if (!plugin.getWorldManager().isIslandWorld(world) || plugin.getWorldManager().getIslandWorld(world) != IslandWorld.NETHER)
continue;

for (Entity ent : world.getEntities())
if (isNetherMob(ent))
removeWaterAround(world, ent.getLocation().getBlock());
}
}

private void removeWater(World world, Block block) {
if (block.getType() == Material.WATER) {
block.setType(Material.AIR, true);
XSound.BLOCK_FIRE_EXTINGUISH.play(block.getLocation());
world.playEffect(block.getLocation(), Effect.SMOKE, 1);
private boolean isNetherMob(Entity ent) {
if (ent instanceof Blaze || ent instanceof MagmaCube || ent instanceof Wither || ent instanceof Ghast)
return true;

if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
return ent.getType() == EntityType.WITHER_SKELETON;
} else {
return ent instanceof Skeleton && ((Skeleton) ent).getSkeletonType() == Skeleton.SkeletonType.WITHER;
}
}

private void removeWaterAround(World world, Block block) {
removeWater(world, block);
removeWater(world, block.getRelative(BlockFace.UP));
}

private void removeWater(World world, Block block) {
if (block.getType() != Material.WATER)
return;
block.setType(Material.AIR, true);
XSound.BLOCK_FIRE_EXTINGUISH.play(block.getLocation());
world.playEffect(block.getLocation(), Effect.SMOKE, 1);
}

public void onDisable() {
}
}

0 comments on commit 9ba7647

Please sign in to comment.