diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a5d9509 --- /dev/null +++ b/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index a1c2a23..c836fce 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..e515c48 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + skyblock + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..839d647 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/img/1.png b/img/1.png new file mode 100644 index 0000000..d82dae5 Binary files /dev/null and b/img/1.png differ diff --git a/img/2.png b/img/2.png new file mode 100644 index 0000000..73d1c14 Binary files /dev/null and b/img/2.png differ diff --git a/img/3.png b/img/3.png new file mode 100644 index 0000000..8c27b8e Binary files /dev/null and b/img/3.png differ diff --git a/img/4.png b/img/4.png new file mode 100644 index 0000000..542a651 Binary files /dev/null and b/img/4.png differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ebdb3cb --- /dev/null +++ b/pom.xml @@ -0,0 +1,97 @@ + + + + 4.0.0 + + com.gekkedev.skyblock + skyblock + 1.0 + + skyblock + + http://www.example.com + + + UTF-8 + 1.8 + 1.8 + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + junit + junit + 4.11 + test + + + org.spigotmc + spigot-api + 1.13.2-R0.1-SNAPSHOT + provided + + + + + ${project.basedir}/src/main/java + + + ${project.basedir}/src/main/resources + + plugin.yml + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/src/main/java/com/gekkedev/skyblock/Island.java b/src/main/java/com/gekkedev/skyblock/Island.java new file mode 100644 index 0000000..3efc5e2 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/Island.java @@ -0,0 +1,116 @@ +package com.gekkedev.skyblock; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.TreeType; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class Island { + private Player owner; + + public Island(Player player) { + this.owner = player; + if (!Main.config.isConfigurationSection("IslandBases." + player.getName())) { + Location newLoc = getNewLocation(); + ConfigurationSection section = Main.config.createSection("IslandBases." + player.getName()); + section.set("x", newLoc.getX()); + section.set("y", newLoc.getY()); + section.set("z", newLoc.getZ()); + + generateIsland(); + } + } + + private Location getNewLocation() { + //generate a random spawn location + int radius = 15; + int maxRadius = radius * Main.config.getConfigurationSection("IslandBases").getKeys(false).size(); + return new Location( + Main.sbworld, + Math.random() * maxRadius * 2 - maxRadius, + 20, //height + Math.random() * maxRadius * 2 - maxRadius + ); + } + + public void generateIsland() { //generate island at predefined spawn location + Bukkit.getLogger().info("Spawning SkyBlock island for " + this.owner.getName()); + this.owner.sendMessage(ChatColor.AQUA + "Please wait while your island is being generated..."); + Bukkit.broadcastMessage(this.owner.getName() + " joined the SkyBlock community!"); + Block spawner = getIslandBase().getBlock(); + for (int x = spawner.getX(); x <= spawner.getX() + 7; x++) { + for (int z = spawner.getZ(); z <= spawner.getZ() + 4; z++) { + for (int y = spawner.getY(); y <= spawner.getY() + 15; y++) { + int height = y - spawner.getY(); + if (height >= 0 && height <= 1) { + int dice = (int) Math.round(Math.random() * 5); + switch (dice) { + case 0: + case 1: + Main.sbworld.getBlockAt(x, y, z).setType(Material.DIRT); + break; + case 2: + case 3: + case 4: + Main.sbworld.getBlockAt(x, y, z).setType(Material.STONE); + break; + case 5: + Main.sbworld.getBlockAt(x, y, z).setType(Material.IRON_ORE); + break; + } + } else if (height == 2) { + Main.sbworld.getBlockAt(x, y, z).setType(Material.SAND); + } else if (height == 3) { + Main.sbworld.getBlockAt(x, y, z).setType(Material.GRASS_BLOCK); + }/* else if (height >= 6 && height <= 11) { + Main.sbworld.getBlockAt(6, y, 4).setType(Material.STRIPPED_OAK_WOOD); + }*/ + else Main.sbworld.getBlockAt(x, y, z).setType(Material.AIR); + } + } + } + + Block chestBlock = getPlayerSpawn().getBlock().getRelative(4, 0, 2); + chestBlock.setType(Material.CHEST); + Chest chest = (Chest) chestBlock.getState(); + ItemStack seeds = new ItemStack(Material.WHEAT_SEEDS); + seeds.setAmount(3); + chest.getBlockInventory().addItem( + new ItemStack(Material.LAVA_BUCKET), + new ItemStack(Material.ICE), + new ItemStack(Material.SUGAR_CANE), + seeds + ); + + if (!Main.sbworld.generateTree(getPlayerSpawn().add(3, 0, 0), TreeType.TREE)) + this.owner.sendMessage(ChatColor.RED + "Error: Could not generate tree!"); + + //generate a piece of bedrock to mark the spawn location + getPlayerSpawn().getBlock().getRelative(0, -1, 0).setType(Material.BEDROCK); + } + + private Location getIslandBase() { + return new Location( + Main.sbworld, + Main.config.getDouble("IslandBases." + this.owner.getName() + ".x"), + Main.config.getDouble("IslandBases." + this.owner.getName() + ".y"), + Main.config.getDouble("IslandBases." + this.owner.getName() + ".z") + ); + } + + private Location getPlayerSpawn() { + return getIslandBase().add(2, 4, 2); + } + + public void tpThere() { + this.owner.sendMessage("Teleporting you to your SkyBlock island..."); + this.owner.getInventory().clear(); + this.owner.teleport(getPlayerSpawn()); + } +} diff --git a/src/main/java/com/gekkedev/skyblock/Main.java b/src/main/java/com/gekkedev/skyblock/Main.java new file mode 100644 index 0000000..5f186c2 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/Main.java @@ -0,0 +1,73 @@ +package com.gekkedev.skyblock; +import java.io.File; +import java.io.IOException; + +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import com.gekkedev.skyblock.commands.SBCommand; +import com.gekkedev.skyblock.handlers.AutoSaver; +import com.gekkedev.skyblock.handlers.ChatModifier; +import com.gekkedev.skyblock.handlers.MotdModifier; + +/** + * Skyblock plugin by gekkedev + */ +public class Main extends JavaPlugin +{ + public static World sbworld; + String WORLDNAME = "skyblock_world"; + public static YamlConfiguration config; + String configName = "config.yml"; + public static File cfgFile; + @Override + public void onEnable() { + getLogger().info("SkyBlock by gekkedev initialized!"); + + //generate or load world + WorldCreator creator = new WorldCreator(WORLDNAME); + creator.generator(new SkyblockChunkGenerator()); + creator.environment(Environment.NORMAL); + sbworld = creator.createWorld(); + + //register events + getServer().getPluginManager().registerEvents(new MotdModifier(), this); + getServer().getPluginManager().registerEvents(new ChatModifier(), this); + getServer().getPluginManager().registerEvents(new AutoSaver(), this); + + //register commands + this.getCommand("skyblock").setExecutor(new SBCommand()); + + //init config + cfgFile = new File(getDataFolder() + File.separator + configName); + try { + config = YamlConfiguration.loadConfiguration(cfgFile); + getLogger().info("Loaded config."); + } catch (Exception e) { + getLogger().info("Could not load config."); + config = new YamlConfiguration(); + } + if (!config.contains("IslandBases")) { + config.createSection("IslandBases"); + saveData(); + } + } + + @Override + public void onDisable() { + getLogger().info("Saving skyblock data!"); + saveData(); + } + + public static void saveData() { + try { + Main.config.save(Main.cfgFile); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/gekkedev/skyblock/SkyblockChunkGenerator.java b/src/main/java/com/gekkedev/skyblock/SkyblockChunkGenerator.java new file mode 100644 index 0000000..c51d7c3 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/SkyblockChunkGenerator.java @@ -0,0 +1,26 @@ +package com.gekkedev.skyblock; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; + +public class SkyblockChunkGenerator extends ChunkGenerator { + public Location getFixedSpawnLocation(World world, Random random){ + return new Location(world, 0, 70, 0); + } + + public List getDefaultPopulators(World world){ + return new ArrayList(); + } + + public short[][] generateExtBlockSections(World world, Random random, int chunkX, int chunkY, BiomeGrid biomegrid){ + return new short[world.getMaxHeight() / 16][]; + } + public ChunkData generateChunkData(World world, Random random, int x, int z, ChunkGenerator.BiomeGrid biome) { + return createChunkData(world); + } +} diff --git a/src/main/java/com/gekkedev/skyblock/commands/SBCommand.java b/src/main/java/com/gekkedev/skyblock/commands/SBCommand.java new file mode 100644 index 0000000..f89b70d --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/commands/SBCommand.java @@ -0,0 +1,50 @@ +package com.gekkedev.skyblock.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gekkedev.skyblock.Island; + + +public class SBCommand implements CommandExecutor { + // This method is called whenever somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + /*Block block = newSpawn.getBlock(); + boolean free = true; + for (int x = radius; x >= -radius; x--) { + for (int y = radius; y >= -radius; y--) { + for (int z = radius; z >= -radius; z--) { + if (block.getRelative(x, y, z).getType() != Material.AIR && block.getRelative(x, y, z).getType() != Material.VOID_AIR) { + //player.sendMessage("Blocking block found: " + block.getRelative(x, y, z).getType().name()); + free = false; + } + } + } + } + if (free) { + ConfigurationSection section = Main.config.createSection("PlayerSpawns." + player.getName()); + section.set("x", newSpawn.getX()); + section.set("y", newSpawn.getY()); + section.set("z", newSpawn.getZ()); + } else { + player.sendMessage(ChatColor.RED + "ERROR: Seems like at your randomly taken position there already is a SkyBlock island!"); + player.sendMessage("Island position is blocked. Please try again"); + return true; + }*/ + + Island island = new Island(player); + if (args.length == 1 && args[0].equalsIgnoreCase("restart")) { + island.generateIsland(); + } + island.tpThere(); + } else Bukkit.getLogger().warning("Please use this command ingame only!"); + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/com/gekkedev/skyblock/handlers/AutoSaver.java b/src/main/java/com/gekkedev/skyblock/handlers/AutoSaver.java new file mode 100644 index 0000000..95b9703 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/handlers/AutoSaver.java @@ -0,0 +1,18 @@ +package com.gekkedev.skyblock.handlers; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldSaveEvent; + +import com.gekkedev.skyblock.Main; + + +public class AutoSaver implements Listener { + @EventHandler + public void onWorldSave(WorldSaveEvent event) + { + if (event.getWorld() == Main.sbworld) { + Main.saveData(); + } + } +} diff --git a/src/main/java/com/gekkedev/skyblock/handlers/ChatModifier.java b/src/main/java/com/gekkedev/skyblock/handlers/ChatModifier.java new file mode 100644 index 0000000..f92dbf5 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/handlers/ChatModifier.java @@ -0,0 +1,20 @@ +package com.gekkedev.skyblock.handlers; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import com.gekkedev.skyblock.Main; + +import org.bukkit.ChatColor; + + +public class ChatModifier implements Listener { + @EventHandler + public void onPlayerChat(AsyncPlayerChatEvent event) + { + if (event.getPlayer().getWorld() == Main.sbworld) { + event.setFormat(ChatColor.UNDERLINE + "[SkyBlock]" + ChatColor.RESET + " %s : %s"); + } + } +} diff --git a/src/main/java/com/gekkedev/skyblock/handlers/MotdModifier.java b/src/main/java/com/gekkedev/skyblock/handlers/MotdModifier.java new file mode 100644 index 0000000..0917cf2 --- /dev/null +++ b/src/main/java/com/gekkedev/skyblock/handlers/MotdModifier.java @@ -0,0 +1,13 @@ +package com.gekkedev.skyblock.handlers; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerListPingEvent; + +public class MotdModifier implements Listener { + @EventHandler + public void onServerListPing(ServerListPingEvent event) { + event.setMotd(event.getMotd() + ChatColor.GREEN + "|SkyBlock" + ChatColor.RESET); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4489fc0 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +main: com.gekkedev.skyblock.Main +name: SkyBlock +version: 1.0 +api-version: 1.13 +commands: + skyblock: + description: Teleport to your SkyBlock island + usage: + /skyblock - Join SkyBlock! + /skyblock restart - Regenerate your SkyBlock island! + aliases: [sb] \ No newline at end of file diff --git a/src/test/java/com/gekkedev/skyblock/test/MainTest.java b/src/test/java/com/gekkedev/skyblock/test/MainTest.java new file mode 100644 index 0000000..72d7c50 --- /dev/null +++ b/src/test/java/com/gekkedev/skyblock/test/MainTest.java @@ -0,0 +1,20 @@ +package com.gekkedev.skyblock.test; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class MainTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +}