Skip to content

Commit

Permalink
Version 1.2.1 (#32)
Browse files Browse the repository at this point in the history
* Version 1.2.1

* Added null checks.

* Added null checks.

* Added tests for Settings.

* Improve code smells

* Updated .gitignore

* Made fields local

* JavaDoc fixes

* Make fields final

* Removed exception

* Renamed plugin Pladdon

* Enderpearls were moving islandd centers in other worlds

#31
  • Loading branch information
tastybento committed Sep 17, 2021
1 parent 1453239 commit e99802b
Show file tree
Hide file tree
Showing 14 changed files with 511 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.DS_Store
/pom.xml.versionsBackup
/bin/
/boxed.iml
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.17.0</bentobox.version>
<bentobox.version>1.17.3</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.2.0</build.version>
<build.version>1.2.1</build.version>

<sonar.projectKey>BentoBoxWorld_Boxed</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AdvancementsManager {
private int unknownAdvChange;

/**
* @param addon
* @param addon addon
*/
public AdvancementsManager(Boxed addon) {
this.addon = addon;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/world/bentobox/boxed/Boxed.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ public class Boxed extends GameModeAddon {
// Settings
private Settings settings;
private ChunkGenerator chunkGenerator;
private Config<Settings> configObject = new Config<>(this, Settings.class);
private final Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager;
private DeleteGen delChunks;
private ChunkGenerator netherChunkGenerator;
private PlaceholdersManager phManager;

@Override
public void onLoad() {
Expand Down Expand Up @@ -104,10 +103,10 @@ public void onEnable(){
return;
}
// Check for recommended addons
if (!this.getPlugin().getAddonsManager().getAddonByName("Border").isPresent()) {
if (this.getPlugin().getAddonsManager().getAddonByName("Border").isEmpty()) {
this.logWarning("Boxed normally requires the Border addon.");
}
if (!this.getPlugin().getAddonsManager().getAddonByName("InvSwitcher").isPresent()) {
if (this.getPlugin().getAddonsManager().getAddonByName("InvSwitcher").isEmpty()) {
this.logWarning("Boxed normally requires the InvSwitcher addon for per-world Advancements.");
}
// Advancements manager
Expand All @@ -130,7 +129,7 @@ public void onEnable(){
this.registerListener(new EnderPearlListener(this));

// Register placeholders
phManager = new PlaceholdersManager(this);
PlaceholdersManager phManager = new PlaceholdersManager(this);
getPlugin().getPlaceholdersManager().registerPlaceholder(this,"visited_island_advancements", phManager::getCountByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this,"island_advancements", phManager::getCount);

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/world/bentobox/boxed/PlaceholdersManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public String getCount(User user) {
* @return string of advancement count
*/
public String getCountByLocation(User user) {
if (user == null || user.getUniqueId() == null) return "";
return addon.getIslands().getIslandAt(user.getLocation())
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
if (user != null && user.getUniqueId() != null && user.getLocation() != null) {
return addon.getIslands().getIslandAt(user.getLocation())
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
} else {
return "";
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ abstract class AbstractBoxedBiomeGenerator implements BiomeGenerator {
ENV_MAP = Collections.unmodifiableMap(e);
}

private final SortedMap<Double, Biome> northEast;
private final SortedMap<Double, Biome> southEast;
private final SortedMap<Double, Biome> northWest;
private final SortedMap<Double, Biome> southWest;

protected final Map<BlockFace, SortedMap<Double, Biome>> quadrants;

private final Boxed addon;
Expand All @@ -50,7 +45,7 @@ abstract class AbstractBoxedBiomeGenerator implements BiomeGenerator {
private final Biome defaultBiome;


public AbstractBoxedBiomeGenerator(Boxed boxed, Environment env, Biome defaultBiome) {
protected AbstractBoxedBiomeGenerator(Boxed boxed, Environment env, Biome defaultBiome) {
this.addon = boxed;
this.defaultBiome = defaultBiome;
dist = addon.getSettings().getIslandDistance();
Expand All @@ -62,10 +57,10 @@ public AbstractBoxedBiomeGenerator(Boxed boxed, Environment env, Biome defaultBi
addon.saveResource("biomes.yml", true);
}
YamlConfiguration config = YamlConfiguration.loadConfiguration(biomeFile);
northEast = loadQuad(config, ENV_MAP.get(env) + ".north-east");
southEast = loadQuad(config, ENV_MAP.get(env) + ".south-east");
northWest = loadQuad(config, ENV_MAP.get(env) + ".north-west");
southWest = loadQuad(config, ENV_MAP.get(env) + ".south-west");
SortedMap<Double, Biome> northEast = loadQuad(config, ENV_MAP.get(env) + ".north-east");
SortedMap<Double, Biome> southEast = loadQuad(config, ENV_MAP.get(env) + ".south-east");
SortedMap<Double, Biome> northWest = loadQuad(config, ENV_MAP.get(env) + ".north-west");
SortedMap<Double, Biome> southWest = loadQuad(config, ENV_MAP.get(env) + ".south-west");

quadrants = new EnumMap<>(BlockFace.class);
quadrants.put(BlockFace.NORTH_EAST, northEast);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BoxedChunkGenerator {

private final WorldRef wordRef;
private final Boxed addon;
private WorldRef wordRefNether;
private final WorldRef wordRefNether;

public BoxedChunkGenerator(Boxed addon) {
this.addon = addon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DeleteGen extends ChunkGenerator {

private final Map<World, World> backMap;
/**
* @param addon
* @param addon addon
*/
public DeleteGen(Boxed addon) {
backMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class NetherGenerator implements BaseNoiseGenerator {
private final BiomeNoise defaultNoise = new BiomeNoise(10D, 0D, 2D);
private final NoiseGenerator mainNoiseGenerator;
private final Boxed addon;
private final YamlConfiguration config;
private final Map<Biome, BiomeNoise> biomeNoiseMap;


Expand All @@ -40,7 +39,7 @@ public NetherGenerator(Boxed addon, long seed) {
if (!biomeFile.exists()) {
addon.saveResource("biomes.yml", true);
}
config = YamlConfiguration.loadConfiguration(biomeFile);
YamlConfiguration config = YamlConfiguration.loadConfiguration(biomeFile);
biomeNoiseMap = new EnumMap<>(Biome.class);
if (config.isConfigurationSection(NETHER_BIOMES)) {
for (String key : config.getConfigurationSection(NETHER_BIOMES).getKeys(false)) {
Expand All @@ -53,14 +52,14 @@ public NetherGenerator(Boxed addon, long seed) {
}
}

class BiomeNoise {
static class BiomeNoise {
double noiseScaleHorizontal = 10D;
double height = 0D;
double noiseScaleVertical = 2D;
/**
* @param noiseScaleHorizontal
* @param height
* @param noiseScaleVertical
* @param noiseScaleHorizontal horizontal noise scale
* @param height height
* @param noiseScaleVertical vertical noise scale
*/
public BiomeNoise(double noiseScaleHorizontal, double height, double noiseScaleVertical) {
this.noiseScaleHorizontal = noiseScaleHorizontal;
Expand Down
101 changes: 57 additions & 44 deletions src/main/java/world/bentobox/boxed/listeners/AdvancementListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -42,14 +43,14 @@
*/
public class AdvancementListener implements Listener {

private Boxed addon;
private final Boxed addon;
private final Advancement netherAdvancement;
private final Advancement endAdvancement;
private final Advancement netherRoot;
private final Advancement endRoot;

/**
* @param addon
* @param addon addon
*/
public AdvancementListener(Boxed addon) {
this.addon = addon;
Expand Down Expand Up @@ -77,20 +78,27 @@ public void onAdvancement(PlayerAdvancementDoneEvent e) {
e.getAdvancement().getCriteria().forEach(c ->
e.getPlayer().getAdvancementProgress(e.getAdvancement()).revokeCriteria(c));
User u = User.getInstance(e.getPlayer());
u.notify("boxed.adv-disallowed", TextVariables.NAME, e.getPlayer().getName(), TextVariables.DESCRIPTION, this.keyToString(u, e.getAdvancement().getKey()));
if (u != null) {
u.notify("boxed.adv-disallowed", TextVariables.NAME, e.getPlayer().getName(), TextVariables.DESCRIPTION, this.keyToString(u, e.getAdvancement().getKey()));
}
return;
}

int score = addon.getAdvManager().addAdvancement(e.getPlayer(), e.getAdvancement());
if (score != 0) {
User user = User.getInstance(e.getPlayer());
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> tellTeam(user, e.getAdvancement().getKey(), score));
if (user != null) {
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> tellTeam(user, e.getAdvancement().getKey(), score));
}
}
}
}

private void tellTeam(User user, NamespacedKey key, int score) {
Island island = addon.getIslands().getIsland(addon.getOverWorld(), user);
if (island == null) {
return;
}
island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(User::getInstance)
.filter(User::isOnline)
Expand Down Expand Up @@ -119,16 +127,16 @@ public void syncAdvancements(User user) {
int diff = addon.getAdvManager().checkIslandSize(island);
if (diff > 0) {
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(diff));
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
} else if (diff < 0) {
user.sendMessage("boxed.size-decreased", TextVariables.NUMBER, String.valueOf(Math.abs(diff)));
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_VILLAGER_DEATH, 1F, 2F);
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_VILLAGER_DEATH, 1F, 2F);
}
}
}

private void informPlayer(User user, NamespacedKey key, int score) {
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
user.sendMessage("boxed.completed", TextVariables.NAME, keyToString(user, key));
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));

Expand All @@ -137,7 +145,7 @@ private void informPlayer(User user, NamespacedKey key, int score) {
private String keyToString(User user, NamespacedKey key) {
String adv = user.getTranslationOrNothing("boxed.advancements." + key.toString());
if (adv.isEmpty()) {
adv = Util.prettifyText(key.getKey().substring(key.getKey().lastIndexOf("/") + 1, key.getKey().length()));
adv = Util.prettifyText(key.getKey().substring(key.getKey().lastIndexOf("/") + 1));
}
return adv;
}
Expand Down Expand Up @@ -186,7 +194,7 @@ public void onPlayerEnterWorld(PlayerChangedWorldEvent e) {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onTeamJoinTime(TeamJoinedEvent e) {
User user = User.getInstance(e.getPlayerUUID());
if (addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
if (user != null && addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
// Clear and set advancements
clearAndSetAdv(user, addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
Expand All @@ -198,7 +206,7 @@ public void onTeamJoinTime(TeamJoinedEvent e) {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onTeamLeaveTime(TeamLeaveEvent e) {
User user = User.getInstance(e.getPlayerUUID());
if (addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
if (user != null && addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
// Clear and set advancements
clearAndSetAdv(user, addon.getSettings().isOnLeaveResetAdvancements(), addon.getSettings().getOnLeaveGrantAdvancements());
Expand All @@ -208,7 +216,10 @@ public void onTeamLeaveTime(TeamLeaveEvent e) {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onFirstTime(IslandNewIslandEvent e) {
clearAndSetAdv(User.getInstance(e.getPlayerUUID()), addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
User user = User.getInstance(e.getPlayerUUID());
if (user != null) {
clearAndSetAdv(user, addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
}
}


Expand Down Expand Up @@ -241,42 +252,11 @@ private void grantAdv(User user, List<String> list) {
}
}

@SuppressWarnings("deprecation")

private void clearAdv(User user) {
// Clear stats
// Statistics
Arrays.stream(Statistic.values()).forEach(s -> {
switch(s.getType()) {
case BLOCK:
for (Material m: Material.values()) {
if (m.isBlock() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ITEM:
for (Material m: Material.values()) {
if (m.isItem() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ENTITY:
for (EntityType en: EntityType.values()) {
if (en.isAlive()) {
user.getPlayer().setStatistic(s, en, 0);
}
}
break;
case UNTYPED:
user.getPlayer().setStatistic(s, 0);
break;
default:
break;

}

});
Arrays.stream(Statistic.values()).forEach(s -> resetStats(user, s));
// Clear advancements
Iterator<Advancement> it = Bukkit.advancementIterator();
while (it.hasNext()) {
Expand All @@ -287,4 +267,37 @@ private void clearAdv(User user) {

}

@SuppressWarnings("deprecation")
private void resetStats(User user, Statistic s) {
switch(s.getType()) {
case BLOCK:
for (Material m: Material.values()) {
if (m.isBlock() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ITEM:
for (Material m: Material.values()) {
if (m.isItem() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ENTITY:
for (EntityType en: EntityType.values()) {
if (en.isAlive()) {
user.getPlayer().setStatistic(s, en, 0);
}
}
break;
case UNTYPED:
user.getPlayer().setStatistic(s, 0);
break;
default:
break;

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class EnderPearlListener implements Listener {
private final Boxed addon;

/**
* @param addon
* @param addon addon
*/
public EnderPearlListener(Boxed addon) {
this.addon = addon;
Expand All @@ -38,15 +38,15 @@ public EnderPearlListener(Boxed addon) {
public void onEnderPearlLand(ProjectileHitEvent e) {
if (!e.getEntityType().equals(EntityType.ENDER_PEARL)
|| e.getHitBlock() == null
|| !addon.getPlugin().getIWM().inWorld(e.getHitBlock().getLocation())) {
|| !addon.inWorld(e.getHitBlock().getLocation())) {
return;
}
Location l = e.getHitBlock().getRelative(BlockFace.UP).getLocation();
EnderPearl ep = (EnderPearl)e.getEntity();
if (ep.getShooter() instanceof Player) {
User u = User.getInstance((Player)ep.getShooter());
if (ep.getShooter() instanceof Player player) {
User u = User.getInstance(player);
addon.getIslands().getIslandAt(l).ifPresent(i -> {
// Check flag
// Check flag
if (i.isAllowed(u, Boxed.MOVE_BOX) && addon.getIslands().isSafeLocation(l)) {
// Reset home locations
i.getMemberSet().forEach(uuid -> {
Expand Down

0 comments on commit e99802b

Please sign in to comment.