From 5bfbab31762433e8059ed4421cb85fbb1b269c98 Mon Sep 17 00:00:00 2001 From: totemo Date: Mon, 6 Feb 2017 01:43:38 +1030 Subject: [PATCH] Version 1.0.0 --- .gitignore | 9 ++ LICENSE | 4 +- README.md | 55 +++++++++++++ config.yml | 6 ++ plugin.yml | 22 +++++ pom.xml | 71 ++++++++++++++++ src/nu/nerd/beastmaster/BeastMaster.java | 95 ++++++++++++++++++++++ src/nu/nerd/beastmaster/Configuration.java | 49 +++++++++++ 8 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 config.yml create mode 100644 plugin.yml create mode 100644 pom.xml create mode 100644 src/nu/nerd/beastmaster/BeastMaster.java create mode 100644 src/nu/nerd/beastmaster/Configuration.java diff --git a/.gitignore b/.gitignore index 32858aa..e1365cb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,12 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Eclipse stuff: +.project +.settings +.classpath + +# Build: +/classes/ +target/ diff --git a/LICENSE b/LICENSE index 013e685..50722f6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2017 NerdNu +Copyright (c) 2016 NerdNu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..860de17 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +NerdAnim +======== +A Bukkit plugin that handles custom mob spawning. + + +Features +-------- +Currently this is just a small plugin that restores Minecraft 1.10 wither +skeleton spawning behaviour to 1.11 survival mode servers. In specific terms, it +replaces a configurable percentage of skeletons spawned in the PLAINS biome in +the NETHER environement with wither skeletons. + +Time permitting, this plugin may be expanded to be a more general custom-mob +spawning system with facilities like OtherDrops (currently defunct) or +MythicMobs. + +The design principles for expanding the capabilities of the plugin would be: + + * No reliance on NMS classes, since that presents a maintenance obstacle. + * Loose coupling to other plugins (soft dependencies only). + * As much as possible, in-game configuration only: mob types, including their + equipment should be designable in-game with minimal commands and no + configuration editing. Their spawnable areas should be defined in-game as + spheres or rectangular prisms from a specified location. + * Complex configuration languages should be avoided; YAML should not be abused + for this purpose: most Bukkit plugin configuration languages based on YAML + have horrible, quirky, poorly documented syntax. OtherDrops and MythicMobs + are prime examples of this. The YAML parser in Bukkit is extremely + unforgiving of minor syntax errors. Instead of YAML, the configuration + language, which would be used mostly for configurating mob *behaviours*, + should use a pre-existing Java implementation of an established scripting + language like Lua, Python (Jython) or Groovy to set properties of a + well-documented object model. + + +Commands +-------- + + * `/beastmaster reload` - Reload the plugin configuration. + + +Configuration +------------- + +| Setting | Description | +| :--- | :--- | +| `debug.config` | If true, log the configuration on reload. | +| `debug.replace` | If true, log replacement of skeletons by wither skeletons. | +| `chance.wither-skeleton` | Probability, in the range [0.0,1.0] that a plains biome skeleton spawn in the nether environment will be replaced by a wither skeleton. | + + +Permissions +----------- + + * `beastmaster.admin` - Permission to administer the plugin (run `/beastmaster reload`). diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..8091eb2 --- /dev/null +++ b/config.yml @@ -0,0 +1,6 @@ +debug: + config: false + replace: false + +chance: + wither-skeleton: 0.8 \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..3c649c2 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,22 @@ +name: ${project.name} +version: ${project.version} +author: totemo +authors: [] +description: ${project.description} +website: ${project.url} +database: true +main: nu.nerd.beastmaster.BeastMaster + +permissions: + beastmaster.admin: + description: Permission to administer the plugin. + default: op + +commands: + beastmaster: + description: ${project.name} administrative command. + permission: beastmaster.admin + usage: | + + §e/ help§f - Show usage help. + §e/ reload§f - Reload the configuration. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dba3dab --- /dev/null +++ b/pom.xml @@ -0,0 +1,71 @@ + + 4.0.0 + nu.nerd + BeastMaster + ${project.name} + 1.0.0 + jar + Handles custom mob spawning. + https://github.com/NerdNu/${project.name} + + scm:git:git://github.com/NerdNu/${project.name}.git + https://github.com/NerdNu/${project.name} + scm:git:git://github.com/NerdNu/${project.name}.git + + + UTF-8 + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + org.spigotmc + spigot-api + 1.11.2-R0.1-SNAPSHOT + + + + clean package + ${basedir}/src + + + . + true + ${basedir} + + plugin.yml + config.yml + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + false + + ${project.artifactId}-${project.version} + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.8 + 1.8 + + + + + + diff --git a/src/nu/nerd/beastmaster/BeastMaster.java b/src/nu/nerd/beastmaster/BeastMaster.java new file mode 100644 index 0000000..786106a --- /dev/null +++ b/src/nu/nerd/beastmaster/BeastMaster.java @@ -0,0 +1,95 @@ +package nu.nerd.beastmaster; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import net.md_5.bungee.api.ChatColor; + +// ---------------------------------------------------------------------------- +/** + * Plugin, command handling and event handler class. + */ +public class BeastMaster extends JavaPlugin implements Listener { + // ------------------------------------------------------------------------ + /** + * Configuration wrapper instance. + */ + public static Configuration CONFIG = new Configuration(); + + /** + * This plugin, accessible as, effectively, a singleton. + */ + public static BeastMaster PLUGIN; + + // ------------------------------------------------------------------------ + /** + * @see org.bukkit.plugin.java.JavaPlugin#onEnable() + */ + @Override + public void onEnable() { + PLUGIN = this; + saveDefaultConfig(); + CONFIG.reload(); + + getServer().getPluginManager().registerEvents(this, this); + } + + // ------------------------------------------------------------------------ + /** + * @see org.bukkit.plugin.java.JavaPlugin#onDisable() + */ + @Override + public void onDisable() { + Bukkit.getScheduler().cancelTasks(this); + } + + // ------------------------------------------------------------------------ + /** + * @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, + * org.bukkit.command.Command, java.lang.String, java.lang.String[]) + */ + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1 || args[0].equalsIgnoreCase("help")) { + return false; + } + + if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { + CONFIG.reload(); + sender.sendMessage(ChatColor.GOLD + getName() + " configuration reloaded."); + } + return true; + } + + // ------------------------------------------------------------------------ + /** + * In the plains biome in the nether environment, replace the configured + * percentage of Skeletons with WitherSkeletons. + */ + @EventHandler(ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + Location loc = event.getLocation(); + World world = loc.getWorld(); + if (world.getEnvironment() == Environment.NETHER && + loc.getBlock().getBiome() == Biome.PLAINS && + event.getEntityType() == EntityType.SKELETON && + Math.random() < CONFIG.CHANCE_WITHER_SKELETON) { + if (CONFIG.DEBUG_REPLACE) { + getLogger().info(String.format("Replacing skeleton at (%d, %d, %d, %s) with wither skeleton.", + loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName())); + } + event.getEntity().remove(); + world.spawnEntity(loc, EntityType.WITHER_SKELETON); + } + } +} // class BeastMaster \ No newline at end of file diff --git a/src/nu/nerd/beastmaster/Configuration.java b/src/nu/nerd/beastmaster/Configuration.java new file mode 100644 index 0000000..00f3585 --- /dev/null +++ b/src/nu/nerd/beastmaster/Configuration.java @@ -0,0 +1,49 @@ +package nu.nerd.beastmaster; + +import java.util.logging.Logger; + +import org.bukkit.configuration.file.FileConfiguration; + +// ---------------------------------------------------------------------------- +/** + * Reads and exposes the plugin configuration. + */ +public class Configuration { + // ------------------------------------------------------------------------ + /** + * If true, log the configuration on reload. + */ + public boolean DEBUG_CONFIG; + + /** + * If true, log replacement of skeletons by wither skeletons. + */ + public boolean DEBUG_REPLACE; + + /** + * Probability, in the range [0.0,1.0] that a plains biome skeleton spawn in + * the nether environment will be replaced by a wither skeleton. + */ + public double CHANCE_WITHER_SKELETON; + + // ------------------------------------------------------------------------ + /** + * Load the plugin configuration. + */ + public void reload() { + BeastMaster.PLUGIN.reloadConfig(); + FileConfiguration config = BeastMaster.PLUGIN.getConfig(); + DEBUG_CONFIG = config.getBoolean("debug.config"); + DEBUG_REPLACE = config.getBoolean("debug.replace"); + CHANCE_WITHER_SKELETON = config.getDouble("chance.wither-skeleton"); + + Logger logger = BeastMaster.PLUGIN.getLogger(); + if (DEBUG_CONFIG) { + logger.info("Configuration:"); + logger.info("DEBUG_REPLACE: " + DEBUG_REPLACE); + logger.info("CHANCE_WITHER_SKELETON: " + CHANCE_WITHER_SKELETON); + } + } // reload + + // ------------------------------------------------------------------------ +} // class Configuration \ No newline at end of file