mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-22 02:25:55 +01:00
Initial commit
This commit is contained in:
commit
e1f897995d
6
addon.yml
Executable file
6
addon.yml
Executable file
@ -0,0 +1,6 @@
|
||||
name: BSkyBlock-AcidIsland
|
||||
main: bskyblock.addon.acidisland.AcidIsland
|
||||
version: 0.1
|
||||
|
||||
authors: tastybento
|
||||
|
7
config.yml
Normal file
7
config.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# Warp Restriction - needed levels to be able to create a warp
|
||||
# 0 or negative values will disable this restriction
|
||||
# 10 is default
|
||||
warplevelrestriction: 10
|
||||
|
||||
welcomeLine: [WELCOME]
|
||||
|
28
locales/en-US.yml
Executable file
28
locales/en-US.yml
Executable file
@ -0,0 +1,28 @@
|
||||
###########################################################################################
|
||||
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
|
||||
# the one at http://yaml-online-parser.appspot.com #
|
||||
###########################################################################################
|
||||
|
||||
warps:
|
||||
removed: "&CWarp sign removed"
|
||||
success: "&ASuccess!"
|
||||
sign-removed: "&CWarp sign removed!"
|
||||
title: "Warp Signs"
|
||||
previous: "&6Previous page"
|
||||
next: "&6Next page"
|
||||
warpToPlayersSign: "&6Warping to [player]'s sign"
|
||||
warpTip: "&6Place a warp sign with [Welcome] on the top"
|
||||
error:
|
||||
no-remove: "&CYou cannot remove that sign!"
|
||||
not-enough-level: "&CYour island level is not high enough!"
|
||||
no-permission: "&CYou do not have permission to do that!"
|
||||
not-on-island: "&CYou must be on your island to do that!"
|
||||
duplicate: "&CDuplicate sign placed"
|
||||
no-warps-yet: "&CThere are no warps available yet"
|
||||
help:
|
||||
description: "open the warps panel"
|
||||
warp:
|
||||
help:
|
||||
parameters: "<name>"
|
||||
description: "warp to the player's warp sign"
|
||||
|
61
pom.xml
Normal file
61
pom.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>addon-acidisland</groupId>
|
||||
<artifactId>addon-acidisland</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<build>
|
||||
<defaultGoal>clean package install</defaultGoal>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath>locales</targetPath>
|
||||
<filtering>false</filtering>
|
||||
<directory>${basedir}/locales</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.tastybento</groupId>
|
||||
<artifactId>bskyblock</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
63
src/main/java/bskyblock/addon/acidisland/AcidIsland.java
Normal file
63
src/main/java/bskyblock/addon/acidisland/AcidIsland.java
Normal file
@ -0,0 +1,63 @@
|
||||
package bskyblock.addon.acidisland;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import bskyblock.addon.acidisland.listeners.AcidEffect;
|
||||
import bskyblock.addon.acidisland.listeners.IslandBuilder;
|
||||
import us.tastybento.bskyblock.api.addons.Addon;
|
||||
|
||||
/**
|
||||
* Addin to BSkyBlock that enables AcidIsland
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AcidIsland extends Addon {
|
||||
|
||||
private Settings settings;
|
||||
private AcidIslandWorld aiw;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
settings = new Settings();
|
||||
// Create worlds
|
||||
aiw = new AcidIslandWorld(this);
|
||||
// Register settings
|
||||
//getBSkyBlock().getSettings().register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Register listener
|
||||
PluginManager manager = getServer().getPluginManager();
|
||||
// Player join events
|
||||
manager.registerEvents(new AcidEffect(this), this.getBSkyBlock());
|
||||
manager.registerEvents(new IslandBuilder(this), this.getBSkyBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the aiw
|
||||
*/
|
||||
public AcidIslandWorld getAiw() {
|
||||
return aiw;
|
||||
}
|
||||
|
||||
public World getIslandWorld() {
|
||||
return aiw.getOverWorld();
|
||||
}
|
||||
|
||||
public void log(String string) {
|
||||
getBSkyBlock().log(string);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bskyblock.addon.acidisland;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AcidIslandWorld {
|
||||
|
||||
private static final String NETHER = "_nether";
|
||||
private static final String THE_END = "_the_end";
|
||||
private World islandWorld;
|
||||
private World netherWorld;
|
||||
private World endWorld;
|
||||
|
||||
/**
|
||||
* Create a register worlds with BSkyBlock
|
||||
* @param addon
|
||||
*/
|
||||
public AcidIslandWorld(AcidIsland addon) {
|
||||
String worldName = addon.getSettings().getWorldName();
|
||||
if (addon.getServer().getWorld(worldName) == null) {
|
||||
addon.getLogger().info("Creating AcidIsland...");
|
||||
}
|
||||
// Create the world if it does not exist
|
||||
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(addon))
|
||||
.createWorld();
|
||||
addon.getBSkyBlock().registerWorld("acidisland", islandWorld);
|
||||
// Make the nether if it does not exist
|
||||
if (addon.getSettings().isNetherGenerate()) {
|
||||
if (addon.getServer().getWorld(worldName + NETHER) == null) {
|
||||
addon.log("Creating AcidIsland's Nether...");
|
||||
}
|
||||
if (!addon.getSettings().isNetherIslands()) {
|
||||
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
|
||||
} else {
|
||||
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon))
|
||||
.environment(World.Environment.NETHER).createWorld();
|
||||
}
|
||||
addon.getBSkyBlock().registerWorld("acid_nether", netherWorld);
|
||||
}
|
||||
// Make the end if it does not exist
|
||||
if (addon.getSettings().isEndGenerate()) {
|
||||
if (addon.getServer().getWorld(worldName + THE_END) == null) {
|
||||
addon.log("Creating AcidIsland's End World...");
|
||||
}
|
||||
if (!addon.getSettings().isEndIslands()) {
|
||||
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
|
||||
} else {
|
||||
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon))
|
||||
.environment(World.Environment.THE_END).createWorld();
|
||||
}
|
||||
addon.getBSkyBlock().registerWorld("acid_end", endWorld);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a player is in any of the island worlds
|
||||
* @param loc - player to check
|
||||
* @return true if in a world or false if not
|
||||
*/
|
||||
public boolean inWorld(Location loc) {
|
||||
return Util.sameWorld(loc.getWorld(), islandWorld);
|
||||
}
|
||||
|
||||
public World getOverWorld() {
|
||||
return islandWorld;
|
||||
}
|
||||
|
||||
public World getNetherWorld() {
|
||||
return netherWorld;
|
||||
}
|
||||
|
||||
public World getEndWorld() {
|
||||
return endWorld;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
package bskyblock.addon.acidisland;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||
|
||||
public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
|
||||
AcidIsland addon;
|
||||
Random rand = new Random();
|
||||
PerlinOctaveGenerator gen;
|
||||
|
||||
/**
|
||||
* @param addon
|
||||
*/
|
||||
public ChunkGeneratorWorld(AcidIsland addon) {
|
||||
super();
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
|
||||
if (world.getEnvironment().equals(World.Environment.NETHER)) {
|
||||
return generateNetherChunks(world, random, chunkX, chunkZ, biomeGrid);
|
||||
}
|
||||
ChunkData result = createChunkData(world);
|
||||
if (addon.getSettings().getSeaHeight() != 0) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < addon.getSettings().getSeaHeight(); y++) {
|
||||
result.setBlock(x, y, z, Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// This needs to be set to return true to override minecraft's default
|
||||
// behavior
|
||||
@Override
|
||||
public boolean canSpawn(World world, int x, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
||||
return Arrays.asList(new BlockPopulator[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Nether Section
|
||||
*/
|
||||
private ChunkData generateNetherChunks(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||
ChunkData result = createChunkData(world);
|
||||
rand.setSeed(world.getSeed());
|
||||
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
||||
// This is a nether generator
|
||||
if (!world.getEnvironment().equals(Environment.NETHER)) {
|
||||
return result;
|
||||
}
|
||||
if (addon.getSettings().isNetherRoof()) {
|
||||
// Make the roof - common across the world
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
// Do the ceiling
|
||||
int maxHeight = world.getMaxHeight();
|
||||
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
|
||||
// Next three layers are a mix of bedrock and netherrack
|
||||
for (int y = 2; y < 5; y++) {
|
||||
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
|
||||
if (r > 0D) {
|
||||
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
|
||||
}
|
||||
}
|
||||
// Next three layers are a mix of netherrack and air
|
||||
for (int y = 5; y < 8; y++) {
|
||||
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
|
||||
if (r > 0D) {
|
||||
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
|
||||
} else {
|
||||
result.setBlock(x, (maxHeight - y), z, Material.AIR);
|
||||
}
|
||||
}
|
||||
// Layer 8 may be glowstone
|
||||
double r = gen.noise(x, (double)maxHeight - 8, z, random.nextFloat(), random.nextFloat());
|
||||
if (r > 0.5D) {
|
||||
// Have blobs of glowstone
|
||||
switch (random.nextInt(4)) {
|
||||
case 1:
|
||||
// Single block
|
||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||
if (x < 14 && z < 14) {
|
||||
result.setBlock(x + 1, (maxHeight - 8), z + 1, Material.GLOWSTONE);
|
||||
result.setBlock(x + 2, (maxHeight - 8), z + 2, Material.GLOWSTONE);
|
||||
result.setBlock(x + 1, (maxHeight - 8), z + 2, Material.GLOWSTONE);
|
||||
result.setBlock(x + 1, (maxHeight - 8), z + 2, Material.GLOWSTONE);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// Stalatite
|
||||
for (int i = 0; i < random.nextInt(10); i++) {
|
||||
result.setBlock(x, (maxHeight - 8 - i), z, Material.GLOWSTONE);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||
if (x > 3 && z > 3) {
|
||||
for (int xx = 0; xx < 3; xx++) {
|
||||
for (int zz = 0; zz < 3; zz++) {
|
||||
result.setBlock(x - xx, (maxHeight - 8 - random.nextInt(2)), z - xx, Material.GLOWSTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||
}
|
||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||
} else {
|
||||
result.setBlock(x, (maxHeight - 8), z, Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
77
src/main/java/bskyblock/addon/acidisland/Settings.java
Normal file
77
src/main/java/bskyblock/addon/acidisland/Settings.java
Normal file
@ -0,0 +1,77 @@
|
||||
package bskyblock.addon.acidisland;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class Settings {
|
||||
|
||||
public boolean isNetherGenerate() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNetherIslands() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEndGenerate() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEndIslands() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getSeaHeight() {
|
||||
return 125;
|
||||
}
|
||||
|
||||
public boolean isNetherRoof() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return "AcidIsland";
|
||||
}
|
||||
|
||||
public int getRainDamage() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getAcidDamage() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean getDamageOps() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<PotionEffectType> getAcidDamageType() {
|
||||
List<PotionEffectType> result = new ArrayList<>();
|
||||
result.add(PotionEffectType.CONFUSION);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean getHelmetProtection() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getFullArmorProtection() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ItemStack> getChestItems() {
|
||||
// TODO Auto-generated method stub
|
||||
List<ItemStack> result = new ArrayList<>();
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,357 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of ASkyBlock.
|
||||
*
|
||||
* ASkyBlock is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ASkyBlock is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ASkyBlock. If not, see <http://www.gnu.org/licenses/>.
|
||||
*******************************************************************************/
|
||||
|
||||
package bskyblock.addon.acidisland.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import bskyblock.addon.acidisland.AcidIsland;
|
||||
|
||||
/**
|
||||
* Applies the acid effect to players
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class AcidEffect implements Listener {
|
||||
|
||||
private final AcidIsland addon;
|
||||
private List<Player> burningPlayers = new ArrayList<Player>();
|
||||
private boolean isRaining = false;
|
||||
private List<Player> wetPlayers = new ArrayList<Player>();
|
||||
|
||||
public AcidEffect(AcidIsland addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
burningPlayers.remove((Player) e.getEntity());
|
||||
wetPlayers.remove((Player) e.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
// Fast return if acid isn't being used
|
||||
if (addon.getSettings().getRainDamage() == 0 && addon.getSettings().getAcidDamage() == 0) {
|
||||
return;
|
||||
}
|
||||
final Player player = e.getPlayer();
|
||||
// Fast checks
|
||||
if (player.isDead() || player.getGameMode().toString().startsWith("SPECTATOR")) {
|
||||
return;
|
||||
}
|
||||
// Check if in teleport
|
||||
if (addon.getPlayers().isInTeleport(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
// Check that they are in the ASkyBlock world
|
||||
if (!player.getWorld().equals(addon.getAiw().getOverWorld())) {
|
||||
return;
|
||||
}
|
||||
// Return if players are immune
|
||||
if (player.isOp()) {
|
||||
if (!addon.getSettings().getDamageOps()) {
|
||||
return;
|
||||
}
|
||||
} else if (player.hasPermission("acidisland.mod.noburn") || player.hasPermission("admin.noburn")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Slow checks
|
||||
Location playerLoc = player.getLocation();
|
||||
|
||||
// Check for acid rain
|
||||
if (addon.getSettings().getRainDamage() > 0D && isRaining) {
|
||||
// Only check if they are in a non-dry biome
|
||||
Biome biome = playerLoc.getBlock().getBiome();
|
||||
if (biome != Biome.DESERT && biome != Biome.DESERT_HILLS
|
||||
&& biome != Biome.SAVANNA && biome != Biome.MESA && biome != Biome.HELL) {
|
||||
if (isSafeFromRain(player)) {
|
||||
wetPlayers.remove(player);
|
||||
} else {
|
||||
if (!wetPlayers.contains(player)) {
|
||||
// Start hurting them
|
||||
// Add to the list
|
||||
wetPlayers.add(player);
|
||||
// This runnable continuously hurts the player even if
|
||||
// they are not
|
||||
// moving but are in acid rain.
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Check if it is still raining or player is safe or dead or there is no damage
|
||||
if (!isRaining || player.isDead() || isSafeFromRain(player) || addon.getSettings().getRainDamage() <= 0D) {
|
||||
wetPlayers.remove(player);
|
||||
this.cancel();
|
||||
// Check they are still in this world
|
||||
} else {
|
||||
player.damage((addon.getSettings().getRainDamage() - addon.getSettings().getRainDamage() * getDamageReduced(player)));
|
||||
if (addon.getServer().getVersion().contains("(MC: 1.8") || addon.getServer().getVersion().contains("(MC: 1.7")) {
|
||||
player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
|
||||
} else {
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(addon.getBSkyBlock(), 0L, 20L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find out if they are at the bottom of the sea and if so bounce them
|
||||
// back up
|
||||
if (playerLoc.getBlockY() < 1) {
|
||||
final Vector v = new Vector(player.getVelocity().getX(), 1D, player.getVelocity().getZ());
|
||||
player.setVelocity(v);
|
||||
}
|
||||
// If they are already burning in acid then return
|
||||
if (burningPlayers.contains(player)) {
|
||||
// plugin.getLogger().info("DEBUG: no acid water is false");
|
||||
if (isSafeFromAcid(player)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// ACID!
|
||||
// Put the player into the acid list
|
||||
burningPlayers.add(player);
|
||||
// This runnable continuously hurts the player even if they are not
|
||||
// moving but are in acid.
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (player.isDead() || isSafeFromAcid(player)) {
|
||||
burningPlayers.remove(player);
|
||||
this.cancel();
|
||||
} else {
|
||||
if (!addon.getSettings().getAcidDamageType().isEmpty()) {
|
||||
for (PotionEffectType t : addon.getSettings().getAcidDamageType()) {
|
||||
if (t.equals(PotionEffectType.BLINDNESS) || t.equals(PotionEffectType.CONFUSION) || t.equals(PotionEffectType.HUNGER)
|
||||
|| t.equals(PotionEffectType.SLOW) || t.equals(PotionEffectType.SLOW_DIGGING) || t.equals(PotionEffectType.WEAKNESS)) {
|
||||
player.addPotionEffect(new PotionEffect(t, 600, 1));
|
||||
} else {
|
||||
// Poison
|
||||
player.addPotionEffect(new PotionEffect(t, 200, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Apply damage if there is any
|
||||
if (addon.getSettings().getAcidDamage() > 0D) {
|
||||
player.damage((addon.getSettings().getAcidDamage() - addon.getSettings().getAcidDamage() * getDamageReduced(player)));
|
||||
if (addon.getServer().getVersion().contains("(MC: 1.8") || addon.getServer().getVersion().contains("(MC: 1.7")) {
|
||||
player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
|
||||
} else {
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(addon.getBSkyBlock(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player is safe from rain
|
||||
* @param player
|
||||
* @return true if they are safe
|
||||
*/
|
||||
private boolean isSafeFromRain(Player player) {
|
||||
if (!player.getWorld().equals(addon.getIslandWorld())) {
|
||||
return true;
|
||||
}
|
||||
// Check if player has a helmet on and helmet protection is true
|
||||
if (addon.getSettings().getHelmetProtection() && (player.getInventory().getHelmet() != null
|
||||
&& player.getInventory().getHelmet().getType().name().contains("HELMET"))) {
|
||||
return true;
|
||||
}
|
||||
// Check potions
|
||||
Collection<PotionEffect> activePotions = player.getActivePotionEffects();
|
||||
for (PotionEffect s : activePotions) {
|
||||
if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
|
||||
// Safe!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Check if all air above player
|
||||
for (int y = player.getLocation().getBlockY() + 2; y < player.getLocation().getWorld().getMaxHeight(); y++) {
|
||||
if (!player.getLocation().getWorld().getBlockAt(player.getLocation().getBlockX(), y, player.getLocation().getBlockZ()).getType().equals(Material.AIR)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can be burned by acid
|
||||
* @param player
|
||||
* @return true if player is not safe
|
||||
*/
|
||||
private boolean isSafeFromAcid(Player player) {
|
||||
if (!player.getWorld().equals(addon.getIslandWorld())) {
|
||||
return true;
|
||||
}
|
||||
// In liquid
|
||||
Material bodyMat = player.getLocation().getBlock().getType();
|
||||
Material headMat = player.getLocation().getBlock().getRelative(BlockFace.UP).getType();
|
||||
if (bodyMat.equals(Material.STATIONARY_WATER))
|
||||
bodyMat = Material.WATER;
|
||||
if (headMat.equals(Material.STATIONARY_WATER))
|
||||
headMat = Material.WATER;
|
||||
if (bodyMat != Material.WATER && headMat != Material.WATER) {
|
||||
return true;
|
||||
}
|
||||
// Check if player is in a boat
|
||||
Entity playersVehicle = player.getVehicle();
|
||||
if (playersVehicle != null) {
|
||||
// They are in a Vehicle
|
||||
if (playersVehicle.getType().equals(EntityType.BOAT)) {
|
||||
// I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Check if full armor protects
|
||||
if (addon.getSettings().getFullArmorProtection()) {
|
||||
boolean fullArmor = true;
|
||||
for (ItemStack item : player.getInventory().getArmorContents()) {
|
||||
if (item == null || (item != null && item.getType().equals(Material.AIR))) {
|
||||
fullArmor = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fullArmor) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Check if player has an active water potion or not
|
||||
Collection<PotionEffect> activePotions = player.getActivePotionEffects();
|
||||
for (PotionEffect s : activePotions) {
|
||||
// plugin.getLogger().info("Potion is : " +
|
||||
// s.getType().toString());
|
||||
if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
|
||||
// Safe!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @return A double between 0.0 and 0.80 that reflects how much armor the
|
||||
* player has on. The higher the value, the more protection they
|
||||
* have.
|
||||
*/
|
||||
static public double getDamageReduced(Player player) {
|
||||
org.bukkit.inventory.PlayerInventory inv = player.getInventory();
|
||||
ItemStack boots = inv.getBoots();
|
||||
ItemStack helmet = inv.getHelmet();
|
||||
ItemStack chest = inv.getChestplate();
|
||||
ItemStack pants = inv.getLeggings();
|
||||
double red = 0.0;
|
||||
if (helmet != null) {
|
||||
if (helmet.getType() == Material.LEATHER_HELMET)
|
||||
red = red + 0.04;
|
||||
else if (helmet.getType() == Material.GOLD_HELMET)
|
||||
red = red + 0.08;
|
||||
else if (helmet.getType() == Material.CHAINMAIL_HELMET)
|
||||
red = red + 0.08;
|
||||
else if (helmet.getType() == Material.IRON_HELMET)
|
||||
red = red + 0.08;
|
||||
else if (helmet.getType() == Material.DIAMOND_HELMET)
|
||||
red = red + 0.12;
|
||||
}
|
||||
if (boots != null) {
|
||||
if (boots.getType() == Material.LEATHER_BOOTS)
|
||||
red = red + 0.04;
|
||||
else if (boots.getType() == Material.GOLD_BOOTS)
|
||||
red = red + 0.04;
|
||||
else if (boots.getType() == Material.CHAINMAIL_BOOTS)
|
||||
red = red + 0.04;
|
||||
else if (boots.getType() == Material.IRON_BOOTS)
|
||||
red = red + 0.08;
|
||||
else if (boots.getType() == Material.DIAMOND_BOOTS)
|
||||
red = red + 0.12;
|
||||
}
|
||||
// Pants
|
||||
if (pants != null) {
|
||||
if (pants.getType() == Material.LEATHER_LEGGINGS)
|
||||
red = red + 0.08;
|
||||
else if (pants.getType() == Material.GOLD_LEGGINGS)
|
||||
red = red + 0.12;
|
||||
else if (pants.getType() == Material.CHAINMAIL_LEGGINGS)
|
||||
red = red + 0.16;
|
||||
else if (pants.getType() == Material.IRON_LEGGINGS)
|
||||
red = red + 0.20;
|
||||
else if (pants.getType() == Material.DIAMOND_LEGGINGS)
|
||||
red = red + 0.24;
|
||||
}
|
||||
// Chest plate
|
||||
if (chest != null) {
|
||||
if (chest.getType() == Material.LEATHER_CHESTPLATE)
|
||||
red = red + 0.12;
|
||||
else if (chest.getType() == Material.GOLD_CHESTPLATE)
|
||||
red = red + 0.20;
|
||||
else if (chest.getType() == Material.CHAINMAIL_CHESTPLATE)
|
||||
red = red + 0.20;
|
||||
else if (chest.getType() == Material.IRON_CHESTPLATE)
|
||||
red = red + 0.24;
|
||||
else if (chest.getType() == Material.DIAMOND_CHESTPLATE)
|
||||
red = red + 0.32;
|
||||
}
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks weather changes and acid rain
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onWeatherChange(final WeatherChangeEvent e) {
|
||||
if (e.getWorld().equals(addon.getIslandWorld())) {
|
||||
this.isRaining = e.toWeatherState();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
package bskyblock.addon.acidisland.listeners;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Chest;
|
||||
|
||||
import bskyblock.addon.acidisland.AcidIsland;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandCreateEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandResetEvent;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
|
||||
public class IslandBuilder implements Listener {
|
||||
private static final String PLAYER_PLACEHOLDER = "[player]";
|
||||
private AcidIsland addon;
|
||||
|
||||
/**
|
||||
* @param addon
|
||||
*/
|
||||
public IslandBuilder(AcidIsland addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onIslandCreate(final IslandCreateEvent event) {
|
||||
if (addon.isEnabled()) {
|
||||
event.setCancelled(true);
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getOverWorld());
|
||||
if (addon.getSettings().isNetherGenerate() && addon.getSettings().isNetherIslands()) {
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getNetherWorld());
|
||||
}
|
||||
if (addon.getSettings().isEndGenerate() && addon.getSettings().isEndIslands()) {
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getEndWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onIslandReset(final IslandResetEvent event) {
|
||||
if (addon.isEnabled()) {
|
||||
event.setCancelled(true);
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getOverWorld());
|
||||
if (addon.getSettings().isNetherGenerate() && addon.getSettings().isNetherIslands()) {
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getNetherWorld());
|
||||
}
|
||||
if (addon.getSettings().isEndGenerate() && addon.getSettings().isEndIslands()) {
|
||||
generateAcidIslandBlocks(event.getIsland(), addon.getAiw().getEndWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the AcidIsland default island block by block
|
||||
*/
|
||||
private void generateAcidIslandBlocks(Island island, World world) {
|
||||
// AcidIsland
|
||||
// Build island layer by layer
|
||||
// Start from the base
|
||||
// half sandstone; half sand
|
||||
int x = island.getCenter().getBlockX();
|
||||
int z = island.getCenter().getBlockZ();
|
||||
int islandHeight = island.getCenter().getBlockY();
|
||||
|
||||
int y = 0;
|
||||
for (int x_space = x - 4; x_space <= x + 4; x_space++) {
|
||||
for (int z_space = z - 4; z_space <= z + 4; z_space++) {
|
||||
Block b = world.getBlockAt(x_space, y, z_space);
|
||||
b.setType(Material.BEDROCK);
|
||||
}
|
||||
}
|
||||
for (y = 1; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 4; x_space <= x + 4; x_space++) {
|
||||
for (int z_space = z - 4; z_space <= z + 4; z_space++) {
|
||||
Block b = world.getBlockAt(x_space, y, z_space);
|
||||
if (y < (islandHeight / 2)) {
|
||||
b.setType(Material.SANDSTONE);
|
||||
} else {
|
||||
b.setType(Material.SAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Then cut off the corners to make it round-ish
|
||||
for (y = 0; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 4; x_space <= x + 4; x_space += 8) {
|
||||
for (int z_space = z - 4; z_space <= z + 4; z_space += 8) {
|
||||
Block b = world.getBlockAt(x_space, y, z_space);
|
||||
b.setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add some grass
|
||||
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
|
||||
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
|
||||
Block blockToChange = world.getBlockAt(x_space, y, z_space);
|
||||
blockToChange.setType(Material.GRASS);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Place bedrock - MUST be there (ensures island are not
|
||||
// overwritten
|
||||
Block b = world.getBlockAt(x, islandHeight, z);
|
||||
b.setType(Material.BEDROCK);
|
||||
// Then add some more dirt in the classic shape
|
||||
y = islandHeight + 3;
|
||||
for (int x_space = x - 2; x_space <= x + 2; x_space++) {
|
||||
for (int z_space = z - 2; z_space <= z + 2; z_space++) {
|
||||
b = world.getBlockAt(x_space, y, z_space);
|
||||
b.setType(Material.DIRT);
|
||||
}
|
||||
}
|
||||
b = world.getBlockAt(x - 3, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x + 3, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z - 3);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z + 3);
|
||||
b.setType(Material.DIRT);
|
||||
y = islandHeight + 2;
|
||||
for (int x_space = x - 1; x_space <= x + 1; x_space++) {
|
||||
for (int z_space = z - 1; z_space <= z + 1; z_space++) {
|
||||
b = world.getBlockAt(x_space, y, z_space);
|
||||
b.setType(Material.DIRT);
|
||||
}
|
||||
}
|
||||
b = world.getBlockAt(x - 2, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x + 2, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z - 2);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z + 2);
|
||||
b.setType(Material.DIRT);
|
||||
y = islandHeight + 1;
|
||||
b = world.getBlockAt(x - 1, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x + 1, y, z);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z - 1);
|
||||
b.setType(Material.DIRT);
|
||||
b = world.getBlockAt(x, y, z + 1);
|
||||
b.setType(Material.DIRT);
|
||||
|
||||
// Add island items
|
||||
y = islandHeight;
|
||||
// Add tree (natural)
|
||||
Location treeLoc = new Location(world, x, y + 5D, z);
|
||||
world.generateTree(treeLoc, TreeType.ACACIA);
|
||||
|
||||
// Place a helpful sign in front of player
|
||||
placeSign(island.getOwner(), world, x, islandHeight + 5, z + 3);
|
||||
// Place the chest - no need to use the safe spawn function
|
||||
// because we
|
||||
// know what this island looks like
|
||||
placeChest(world, x, islandHeight + 5, z + 1);
|
||||
}
|
||||
|
||||
private void placeSign(UUID playerUUID, World world, int x, int y, int z) {
|
||||
Block blockToChange = world.getBlockAt(x, y, z);
|
||||
blockToChange.setType(Material.SIGN_POST);
|
||||
if (playerUUID != null) {
|
||||
Sign sign = (Sign) blockToChange.getState();
|
||||
User user = User.getInstance(playerUUID);
|
||||
|
||||
// Sets the lines of the sign
|
||||
sign.setLine(0, user.getTranslation("new-island.sign.line0", PLAYER_PLACEHOLDER, user.getName()));
|
||||
sign.setLine(1, user.getTranslation("new-island.sign.line1", PLAYER_PLACEHOLDER, user.getName()));
|
||||
sign.setLine(2, user.getTranslation("new-island.sign.line2", PLAYER_PLACEHOLDER, user.getName()));
|
||||
sign.setLine(3, user.getTranslation("new-island.sign.line3", PLAYER_PLACEHOLDER, user.getName()));
|
||||
|
||||
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
|
||||
private void placeChest(World world, int x, int y, int z) {
|
||||
// Fill the chest and orient it correctly
|
||||
Block blockToChange = world.getBlockAt(x, y, z);
|
||||
blockToChange.setType(Material.CHEST);
|
||||
BlockState state = blockToChange.getState();
|
||||
Chest chest = new Chest(BlockFace.SOUTH);
|
||||
state.setData(chest);
|
||||
state.update();
|
||||
InventoryHolder chestBlock = (InventoryHolder) state;
|
||||
for (ItemStack item: addon.getSettings().getChestItems()) {
|
||||
chestBlock.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user