Skip to content

Commit

Permalink
Merge branch 'release/v1.0.3-BETA'
Browse files Browse the repository at this point in the history
  • Loading branch information
hoqhuuep committed Feb 23, 2016
2 parents 84b5b59 + b1b5603 commit d3ddcf1
Show file tree
Hide file tree
Showing 110 changed files with 2,374 additions and 1,473 deletions.
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/target
/.settings
/.checkstyle
/.classpath
/.project
IslandCraft-NMS-v1_8_R1/bin/
**/bin/
**/build/
**/.settings/
/.checkstyle/
/.gradle/
*.class
*.yml
/bin/
*.classpath
*.jar
!/gradle/wrapper/gradle-wrapper.jar
*.project
5 changes: 0 additions & 5 deletions IslandCraft-Api/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions IslandCraft-Api/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import org.bukkit.event.world.WorldInitEvent;

import com.github.hoqhuuep.islandcraft.api.ICWorld;
import com.github.hoqhuuep.islandcraft.api.IslandCraft;
import com.github.hoqhuuep.islandcraft.core.ICLogger;
import com.github.hoqhuuep.islandcraft.core.IslandCache;
import com.github.hoqhuuep.islandcraft.core.DefaultIslandCraft;
import com.github.hoqhuuep.islandcraft.core.DefaultWorld;
import com.github.hoqhuuep.islandcraft.core.ICClassLoader;
import com.github.hoqhuuep.islandcraft.core.IslandDatabase;
Expand Down Expand Up @@ -60,7 +58,7 @@ public void onWorldInit(final WorldInitEvent event) {
return;
}
ICLogger.logger.info("Installing biome generator in WorldInitEvent for world with name: " + worldName);
final ICWorld icWorld = new DefaultWorld(worldName, world.getSeed(), database, config, cache, classLoader);
final ICWorld icWorld = new DefaultWorld(worldName, world.getSeed(), database, new BukkitWorldConfig(worldName, config), cache, classLoader);
final BiomeGenerator biomeGenerator = new IslandCraftBiomeGenerator(icWorld);
nms.installBiomeGenerator(world, biomeGenerator);
worldsDone.add(worldName);
Expand All @@ -87,7 +85,7 @@ public void onChunkLoad(final ChunkLoadEvent event) {
return;
}
ICLogger.logger.info("Installing biome generator in ChunkLoadEvent for world with name: " + worldName);
final ICWorld icWorld = new DefaultWorld(worldName, world.getSeed(), database, config, cache, classLoader);
final ICWorld icWorld = new DefaultWorld(worldName, world.getSeed(), database, new BukkitWorldConfig(worldName, config), cache, classLoader);
final BiomeGenerator biomeGenerator = new IslandCraftBiomeGenerator(icWorld);
if (nms.installBiomeGenerator(world, biomeGenerator)) {
// If this is the very first time, regenerate the chunk
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.hoqhuuep.islandcraft.bukkit;

import java.util.List;

import org.bukkit.configuration.ConfigurationSection;

import com.github.hoqhuuep.islandcraft.core.ICWorldConfig;
import com.github.hoqhuuep.islandcraft.core.ICLogger;

public class BukkitWorldConfig implements ICWorldConfig {
private final String worldName;
private final ConfigurationSection config;

public BukkitWorldConfig(String worldName, ConfigurationSection config) {
this.worldName = worldName;
this.config = config;
}

@Override
public String getOcean() {
if (!config.contains("ocean") || !config.isString("ocean")) {
ICLogger.logger.warning("No string-value for 'worlds." + worldName + ".ocean' found in config.yml");
ICLogger.logger.warning("Default value 'com.github.hoqhuuep.islandcraft.core.ConstantBiomeDistribution DEEP_OCEAN' will be used");
}
return config.getString("ocean", "com.github.hoqhuuep.islandcraft.core.ConstantBiomeDistribution DEEP_OCEAN");
}

@Override
public String getIslandDistribution() {
if (!config.contains("island-distribution") || !config.isString("island-distribution")) {
ICLogger.logger.warning("No string-value for 'worlds." + worldName + ".island-distribution' found in config.yml");
ICLogger.logger.warning("Default value 'com.github.hoqhuuep.islandcraft.core.EmptyIslandDistribution' will be used");
}
return config.getString("island-distribution", "com.github.hoqhuuep.islandcraft.core.EmptyIslandDistribution");
}

@Override
public String[] getIslandGenerstors() {
if (!config.contains("island-generators") || !config.isList("island-generators")) {
ICLogger.logger.warning("No list-value for 'worlds." + worldName + ".island-generators' found in config.yml");
ICLogger.logger.warning("Default value '[com.github.hoqhuuep.islandcraft.core.EmptyIslandGenerator]' will be used");
}
List<String> islandGenerators = config.getStringList("island-generators");
if (islandGenerators.isEmpty()) {
islandGenerators.add("com.github.hoqhuuep.islandcraft.core.EmptyIslandGenerator");
}
return islandGenerators.toArray(new String[islandGenerators.size()]);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.hoqhuuep.islandcraft.core;
package com.github.hoqhuuep.islandcraft.bukkit;

import java.io.Serializable;

Expand All @@ -9,6 +9,8 @@
import javax.persistence.Table;

import com.avaje.ebean.EbeanServer;
import com.github.hoqhuuep.islandcraft.core.ICLogger;
import com.github.hoqhuuep.islandcraft.core.IslandDatabase;

public class EbeanServerIslandDatabase implements IslandDatabase {
private final EbeanServer ebeanServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.hoqhuuep.islandcraft.core;
package com.github.hoqhuuep.islandcraft.bukkit;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -17,6 +17,7 @@
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.ddl.DdlGenerator;
import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
import com.github.hoqhuuep.islandcraft.core.ICLogger;

public class EbeanServerUtil {
public static EbeanServer build(final JavaPlugin javaPlugin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public ICBiome[] generateChunkBiomes(final int x, final int z) {

@Override
public void cleanupCache() {
// NOP
// Nothing to do
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
package com.github.hoqhuuep.islandcraft.bukkit;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;

import com.avaje.ebean.EbeanServer;
import com.github.hoqhuuep.islandcraft.api.ICLocation;
import com.github.hoqhuuep.islandcraft.api.ICRegion;
import com.github.hoqhuuep.islandcraft.api.IslandCraft;
import com.github.hoqhuuep.islandcraft.core.DefaultIslandCraft;
import com.github.hoqhuuep.islandcraft.core.ICLogger;
import com.github.hoqhuuep.islandcraft.core.IslandDatabase;
import com.github.hoqhuuep.islandcraft.nms.NmsWrapper;

public class IslandCraftPlugin extends JavaPlugin {

private DefaultIslandCraft islandCraft = null;

@Override
public void onEnable() {
ICLogger.logger = new JavaUtilLogger(getLogger());

// https://github.com/Hidendra/Plugin-Metrics/wiki/Usage
try {
final Metrics metrics = new Metrics(this);
metrics.start();
} catch (final Exception e) {
ICLogger.logger.warning("Failed to start MCStats");
}

saveDefaultConfig();
FileConfiguration config = getConfig();
if (!config.contains("config-version") || !config.isString("config-version")) {
ICLogger.logger.error("No string-value for 'config-version' found in config.yml");
ICLogger.logger.error("Check for updates at http://dev.bukkit.org/bukkit-plugins/islandcraft/");
setEnabled(false);
return;
}
final String configVersion = config.getString("config-version");
if (!configVersion.equals("1.0.0")) {
ICLogger.logger.error("Incompatible config-version found in config.yml");
ICLogger.logger.error("Check for updates at http://dev.bukkit.org/bukkit-plugins/islandcraft/");
setEnabled(false);
return;
}

if (!config.contains("verbose-logging") || !config.isBoolean("verbose-logging")) {
ICLogger.logger.warning("No boolean-value for 'verbose-logging' found in config.yml");
ICLogger.logger.warning("Default value 'false' will be used");
}
final boolean verboseLogging = config.getBoolean("verbose-logging", false);
getLogger().setLevel(verboseLogging ? Level.ALL : Level.WARNING);

final NmsWrapper nms = NmsWrapper.getInstance(getServer());
if (nms == null) {
ICLogger.logger.error("IslandCraft does not currently support this CraftBukkit version");
ICLogger.logger.error("Check for updates at http://dev.bukkit.org/bukkit-plugins/islandcraft/");
setEnabled(false);
return;
}

IslandDatabase database;
try {
final EbeanServer ebeanServer = EbeanServerUtil.build(this);
database = new EbeanServerIslandDatabase(ebeanServer);
} catch (final Exception e) {
ICLogger.logger.error("Error creating EbeanServer database");
ICLogger.logger.error("Check for updates at http://dev.bukkit.org/bukkit-plugins/islandcraft/");
ICLogger.logger.error("Exception message: " + e.getMessage());
setEnabled(false);
return;
}

try {
islandCraft = new DefaultIslandCraft();
final Listener listener = new BiomeGeneratorListener(this, database, nms);
getServer().getPluginManager().registerEvents(listener, this);
} catch (final Exception e) {
ICLogger.logger.error("Error creating or registering BiomeGeneratorListener");
ICLogger.logger.error("Check for updates at http://dev.bukkit.org/bukkit-plugins/islandcraft/");
ICLogger.logger.error("Exception message: " + e.getMessage());
setEnabled(false);
return;
}
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
sender.sendMessage("This command can only be executed by console!");
return false;
}
if (args.length == 0) {
sender.sendMessage("/ic <reload|create>");
return false;
}
if ("reload".equals(args[0])) {
sender.sendMessage("Reloaded IslandCraft configuration");
reloadConfig();
} else if ("create".equals(args[0])) {
// ic create 2 1 ConstantBiomeDistribution IslandGeneratorAlpha
if (args.length < 4) {
sender.sendMessage("/ic create <world> <island-size> <ocean-size>");
sender.sendMessage("OR");
sender.sendMessage("/ic create <world> <island-size> <ocean-size> [distribution] [generator]");
sender.sendMessage("Note: An island size of 1 = 4 chunks");
return false;
}
String world = args[1];
int island;
int ocean;
try {
island = Integer.parseInt(args[2]) * 32;
ocean = Integer.parseInt(args[3]) * 32;
} catch (Exception e) {
sender.sendMessage("Invalid size for:");
sender.sendMessage("/ic create <world> <island-size> <ocean-size> [distribution] [generator]");
return false;
}
String distribution = "SquareIslandDistribution";
String generator = "IslandGeneratorAlpha";
if (args.length > 4) {
distribution = args[4];
}
if (args.length > 5) {
distribution = args[5];
}
FileConfiguration config = getConfig();
String path = "worlds." + world;
config.set(path + "." + "ocean",
"com.github.hoqhuuep.islandcraft.core.ConstantBiomeDistribution DEEP_OCEAN");
config.set(path + "." + "island-distribution",
"com.github.hoqhuuep.islandcraft.core." + distribution + " " + island + " " + ocean);
String[] gen_types = {
"com.github.hoqhuuep.islandcraft.core." + generator
+ " BIRCH_FOREST BIRCH_FOREST_M BIRCH_FOREST_HILLS BIRCH_FOREST_HILLS_M ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " COLD_TAIGA COLD_TAIGA_M COLD_TAIGA_HILLS ~ ~ ~ OCEAN COLD_BEACH FROZEN_RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " DESERT DESERT_M DESERT_HILLS ~ ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " EXTREME_HILLS EXTREME_HILLS_M EXTREME_HILLS_PLUS EXTREME_HILLS_PLUS_M EXTREME_HILLS_EDGE ~ OCEAN STONE_BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " FOREST ~ FOREST_HILLS ~ FLOWER_FOREST ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " ICE_PLAINS ~ ICE_MOUNTAINS ~ ICE_PLAINS_SPIKES ~ OCEAN FROZEN_OCEAN FROZEN_RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " JUNGLE JUNGLE_M JUNGLE_HILLS ~ JUNGLE_EDGE JUNGLE_EDGE_M OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " MEGA_TAIGA MEGA_SPRUCE_TAIGA MEGA_TAIGA_HILLS MEGA_SPRUCE_TAIGA_HILLS ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " MESA MESA_BRYCE MESA_PLATEAU MESA_PLATEAU_M MESA_PLATEAU_F MESA_PLATEAU_F_M OCEAN MESA RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " MUSHROOM_ISLAND ~ ~ ~ ~ ~ OCEAN MUSHROOM_ISLAND_SHORE RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " PLAINS ~ SUNFLOWER_PLAINS ~ ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " ROOFED_FOREST ROOFED_FOREST_M ~ ~ ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " SAVANNA SAVANNA_M SAVANNA_PLATEAU SAVANNA_PLATEAU_M ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " SWAMPLAND SWAMPLAND_M ~ ~ ~ ~ OCEAN BEACH RIVER",
"com.github.hoqhuuep.islandcraft.core." + generator
+ " TAIGA TAIGA_M TAIGA_HILLS ~ ~ ~ OCEAN BEACH RIVER" };

config.set(path + "." + "island-generators", gen_types);

sender.sendMessage("Saving configuration!");
saveConfig();
reloadConfig();
sender.sendMessage("Generating world; please wait...");
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null)
&& Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv create " + world + " normal");
} else {
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null)
&& Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
} else {
Bukkit.createWorld(new WorldCreator(world).environment(World.Environment.NORMAL));
}
}
sender.sendMessage("Done!");
} else {
sender.sendMessage("/ic <reload|create>");
}
return true;
}

@Override
public void onDisable() {
ICLogger.logger = null;
}

@Override
public List<Class<?>> getDatabaseClasses() {
final Class<?>[] classes = { EbeanServerIslandDatabase.IslandBean.class,
EbeanServerIslandDatabase.IslandPK.class };
return Arrays.asList(classes);
}

public IslandCraft getIslandCraft() {
return islandCraft;
}

private static final int BLOCKS_PER_CHUNK = 16;

public void regenerate(final World world, final ICRegion region) {
final ICLocation min = region.getMin();
final ICLocation max = region.getMax();
final int minX = min.getX() / BLOCKS_PER_CHUNK;
final int minZ = min.getZ() / BLOCKS_PER_CHUNK;
final int maxX = max.getX() / BLOCKS_PER_CHUNK;
final int maxZ = max.getZ() / BLOCKS_PER_CHUNK;
// Must loop from high to low for trees to generate correctly
for (int x = maxX - 1; x >= minX; --x) {
for (int z = maxZ - 1; z >= minZ; --z) {
// TODO queue these?
world.regenerateChunk(x, z);
}
}
}
}
Loading

0 comments on commit d3ddcf1

Please sign in to comment.