Skip to content

Commit

Permalink
Merge pull request #159 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.19.0
  • Loading branch information
tastybento authored Aug 17, 2024
2 parents eb1ef35 + 284e7e9 commit f7ae02f
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 23 deletions.
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.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<bentobox.version>2.5.0-SNAPSHOT</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.18.2</build.version>
<build.version>1.19.0</build.version>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_AcidIsland</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/world/bentobox/acidisland/AISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.google.common.base.Enums;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.StoreAt;
Expand Down Expand Up @@ -201,6 +202,15 @@ public class AISettings implements WorldSettings {
@ConfigEntry(path = "world.island-height")
private int islandHeight = 50;

@ConfigComment("The number of concurrent islands a player can have in the world")
@ConfigComment("A value of 0 will use the BentoBox config.yml default")
@ConfigEntry(path = "world.concurrent-islands")
private int concurrentIslands = 0;

@ConfigComment("Disallow players to have other islands if they are in a team.")
@ConfigEntry(path = "world.disallow-team-member-islands")
boolean disallowTeamMemberIslands = true;

@ConfigComment("Use your own world generator for this world.")
@ConfigComment("In this case, the plugin will not generate anything.")
@ConfigEntry(path = "world.use-own-generator", experimental = true)
Expand All @@ -220,6 +230,21 @@ public class AISettings implements WorldSettings {
@ConfigEntry(path = "world.ocean-floor", needsReset = true)
private boolean oceanFloor = false;

@ConfigComment("Structures")
@ConfigComment("This creates an vanilla structures in the worlds.")
@ConfigEntry(path = "world.make-structures", needsReset = true)
private boolean makeStructures = false;

@ConfigComment("Caves")
@ConfigComment("This creates an vanilla caves in the worlds.")
@ConfigEntry(path = "world.make-caves", needsReset = true)
private boolean makeCaves = false;

@ConfigComment("Decorations")
@ConfigComment("This creates an vanilla decorations in the worlds.")
@ConfigEntry(path = "world.make-decorations", needsReset = true)
private boolean makeDecorations = true;

@ConfigComment("Maximum number of islands in the world. Set to -1 or 0 for unlimited. ")
@ConfigComment("If the number of islands is greater than this number, no new island will be created.")
@ConfigEntry(path = "world.max-islands")
Expand Down Expand Up @@ -2024,4 +2049,79 @@ public boolean isOceanFloor() {
public void setOceanFloor(boolean oceanFloor) {
this.oceanFloor = oceanFloor;
}

/**
* @return the makeStructures
*/
public boolean isMakeStructures() {
return makeStructures;
}

/**
* @param makeStructures the makeStructures to set
*/
public void setMakeStructures(boolean makeStructures) {
this.makeStructures = makeStructures;
}

/**
* @return the makeCaves
*/
public boolean isMakeCaves() {
return makeCaves;
}

/**
* @param makeCaves the makeCaves to set
*/
public void setMakeCaves(boolean makeCaves) {
this.makeCaves = makeCaves;
}

/**
* @return the makeDecorations
*/
public boolean isMakeDecorations() {
return makeDecorations;
}

/**
* @param makeDecorations the makeDecorations to set
*/
public void setMakeDecorations(boolean makeDecorations) {
this.makeDecorations = makeDecorations;
}

/**
* @return the disallowTeamMemberIslands
*/
@Override
public boolean isDisallowTeamMemberIslands() {
return disallowTeamMemberIslands;
}

/**
* @param disallowTeamMemberIslands the disallowTeamMemberIslands to set
*/
public void setDisallowTeamMemberIslands(boolean disallowTeamMemberIslands) {
this.disallowTeamMemberIslands = disallowTeamMemberIslands;
}

/**
* @return the concurrentIslands
*/
@Override
public int getConcurrentIslands() {
if (concurrentIslands <= 0) {
return BentoBox.getInstance().getSettings().getIslandNumber();
}
return concurrentIslands;
}

/**
* @param concurrentIslands the concurrentIslands to set
*/
public void setConcurrentIslands(int concurrentIslands) {
this.concurrentIslands = concurrentIslands;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@


import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.addons.Pladdon;

public class AcidIslandPladdon extends Pladdon {

private GameModeAddon addon;

@Override
public Addon getAddon() {
return new AcidIsland();
if (addon == null) {
addon = new AcidIsland();
}
return addon;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package world.bentobox.acidisland.events;

import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Fired when an entity (items excluded) receives damage from acid
* @author Poslovitch
* @author Poslovitch, tastybento
* @since 1.0
*/
public class EntityDamageByAcidEvent extends Event {
public class EntityDamageByAcidEvent extends Event implements Cancellable {

private final Entity entity;
private double damage;

public enum Acid { RAIN, WATER }
private final Acid cause;
private boolean cancelled;
private static final HandlerList handlers = new HandlerList();

@Override
Expand Down Expand Up @@ -64,4 +66,15 @@ public void setDamage(double damage) {
public Acid getCause() {
return cause;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;

}
}
37 changes: 28 additions & 9 deletions src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ protected boolean checkForRain(Player player) {
// Check they are still in this world
} else if (wetPlayers.containsKey(player) && wetPlayers.get(player) < System.currentTimeMillis()) {
double protection = addon.getSettings().getAcidRainDamage() * getDamageReduced(player);
double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection);

User user = User.getInstance(player);
// Get the percentage reduction and ensure the value is between 0 and 100
double percent = (100
- Math.max(0, Math.min(100, user.getPermissionValue("acidisland.protection.rain", 0)))) / 100D;

double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection) * percent;

AcidRainEvent event = new AcidRainEvent(player, totalDamage, protection,
addon.getSettings().getAcidRainEffects());
Bukkit.getPluginManager().callEvent(event);
Expand All @@ -187,11 +194,13 @@ protected boolean checkForRain(Player player) {
.addPotionEffect(new PotionEffect(t, addon.getSettings().getRainEffectDuation() * 20, 1)));
// Apply damage if there is any
if (event.getRainDamage() > 0D) {
player.damage(event.getRainDamage());
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
EntityDamageByAcidEvent e = new EntityDamageByAcidEvent(player, event.getRainDamage(), Acid.RAIN);
// Fire event
Bukkit.getPluginManager().callEvent(e);
if (!e.isCancelled()) {
player.damage(event.getRainDamage());
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
}
}
}
}
Expand All @@ -204,19 +213,28 @@ protected boolean continuouslyHurtPlayer(Player player) {
return true;
} else if (burningPlayers.containsKey(player) && burningPlayers.get(player) < System.currentTimeMillis()) {
double protection = addon.getSettings().getAcidDamage() * getDamageReduced(player);
double totalDamage = Math.max(0, addon.getSettings().getAcidDamage() - protection);

User user = User.getInstance(player);
// Get the percentage reduction and ensure the value is between 0 and 100
double percent = (100
- Math.max(0, Math.min(100, user.getPermissionValue("acidisland.protection.acid", 0)))) / 100D;

double totalDamage = Math.max(0, addon.getSettings().getAcidDamage() - protection) * percent;

AcidEvent event = new AcidEvent(player, totalDamage, protection, addon.getSettings().getAcidEffects());
addon.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
event.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player
.addPotionEffect(new PotionEffect(t, addon.getSettings().getAcidEffectDuation() * 20, 1)));
// Apply damage if there is any
if (event.getTotalDamage() > 0D) {
player.damage(event.getTotalDamage());
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
if (event.getTotalDamage() > 0D) {
EntityDamageByAcidEvent e = new EntityDamageByAcidEvent(player, event.getTotalDamage(), Acid.WATER);
// Fire event
Bukkit.getPluginManager().callEvent(e);
if (!e.isCancelled()) {
player.damage(event.getTotalDamage());
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
}
}
}
}
Expand All @@ -230,9 +248,10 @@ protected boolean continuouslyHurtPlayer(Player player) {
*/
private boolean isSafeFromRain(Player player) {
if (isEssentialsGodMode(player) || player.getWorld().getEnvironment().equals(Environment.NETHER)
|| player.getGameMode() != GameMode.SURVIVAL
|| player.getWorld().getEnvironment().equals(Environment.THE_END)
|| (addon.getSettings().isHelmetProtection() && (player.getInventory().getHelmet() != null
&& player.getInventory().getHelmet().getType().name().contains("HELMET")))
&& player.getInventory().getHelmet().getType().name().contains("HELMET")))
|| (!addon.getSettings().isAcidDamageSnow() && player.getLocation().getBlock().getTemperature() < 0.1) // snow falls
|| player.getLocation().getBlock().getHumidity() == 0 // dry
|| (player.getActivePotionEffects().stream().map(PotionEffect::getType)
Expand Down Expand Up @@ -260,7 +279,7 @@ private boolean isSafeFromRain(Player player) {
*/
boolean isSafeFromAcid(Player player) {
// Check for GodMode
if (isEssentialsGodMode(player)
if (isEssentialsGodMode(player) || player.getGameMode() != GameMode.SURVIVAL
// Protect visitors
|| (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name())
&& !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player)))) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/world/bentobox/acidisland/world/AcidTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class AcidTask {
i.add(EntityType.POLAR_BEAR);
i.add(EntityType.TURTLE);
i.add(EntityType.DROWNED);
i.add(EntityType.GUARDIAN);
i.add(EntityType.ELDER_GUARDIAN);
Enums.getIfPresent(EntityType.class, "AXOLOTL").toJavaUtil().ifPresent(i::add);
IMMUNE = Collections.unmodifiableList(i);
}
Expand Down Expand Up @@ -86,10 +88,12 @@ void findEntities() {
void applyDamage(Entity e, long damage) {
if (e instanceof LivingEntity) {
double actualDamage = Math.max(0, damage - damage * AcidEffect.getDamageReduced((LivingEntity)e));
((LivingEntity)e).damage(actualDamage);
EntityDamageByAcidEvent event = new EntityDamageByAcidEvent(e, actualDamage, Acid.WATER);
// Fire event
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
((LivingEntity)e).damage(actualDamage);
}
} else if (addon.getSettings().getAcidDestroyItemTime() > 0 && e instanceof Item){
// Item
if (e.getLocation().getBlock().getType().equals(Material.WATER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
*/
public class ChunkGeneratorWorld extends ChunkGenerator {

private record FloorMats(Material base, Material top) {
}

private final AcidIsland addon;
private final Random rand = new Random();
private final Map<Environment, WorldConfig> seaHeight = new EnumMap<>(Environment.class);
private final Map<Vector, Material> roofChunk = new HashMap<>();
private static final Map<Environment, FloorMats> floorMats = Map.of(Environment.NETHER,
new FloorMats(Material.NETHERRACK, Material.SOUL_SAND), Environment.NORMAL,
new FloorMats(Material.SANDSTONE, Material.SAND), Environment.THE_END,
new FloorMats(Material.END_STONE, Material.END_STONE));
private PerlinOctaveGenerator gen;

private record WorldConfig(int seaHeight, Material waterBlock) {}
Expand Down Expand Up @@ -72,7 +79,8 @@ private void addNoise(@NonNull WorldInfo worldInfo, int chunkX, int chunkZ, @Non
for (int z = 0; z < 16; z++) {
int n = (int)(25 * gen.noise((chunkX << 4) + (double)x, (chunkZ << 4) + (double)z, 0.5, 0.5, true));
for (int y = worldInfo.getMinHeight(); y < 25 + n; y++) {
chunkData.setBlock(x, y, z, rand.nextBoolean() ? Material.SAND : Material.SANDSTONE);
chunkData.setBlock(x, y, z, rand.nextBoolean() ? floorMats.get(worldInfo.getEnvironment()).top()
: floorMats.get(worldInfo.getEnvironment()).base());
}
}
}
Expand All @@ -90,19 +98,19 @@ public boolean shouldGenerateSurface() {
}
@Override
public boolean shouldGenerateCaves() {
return addon.getSettings().isOceanFloor();
return addon.getSettings().isMakeCaves();
}
@Override
public boolean shouldGenerateDecorations() {
return addon.getSettings().isOceanFloor();
return addon.getSettings().isMakeDecorations();
}
@Override
public boolean shouldGenerateMobs() {
return true;
}
@Override
public boolean shouldGenerateStructures() {
return addon.getSettings().isOceanFloor();
return addon.getSettings().isMakeStructures();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: AcidIsland
main: world.bentobox.acidisland.AcidIsland
version: ${version}${build.number}
api-version: 1.22.1
api-version: 2.4.0
metrics: true
repository: "BentoBoxWorld/AcidIsland"
icon: "OAK_BOAT"
Expand Down
Loading

0 comments on commit f7ae02f

Please sign in to comment.