Skip to content

Commit

Permalink
Showing 8 changed files with 309 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`).
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
debug:
config: false
replace: false

chance:
wither-skeleton: 0.8
22 changes: 22 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -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/<command> help§f - Show usage help.
§e/<command> reload§f - Reload the configuration.
71 changes: 71 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<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>nu.nerd</groupId>
<name>BeastMaster</name>
<artifactId>${project.name}</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<description>Handles custom mob spawning.</description>
<url>https://github.com/NerdNu/${project.name}</url>
<scm>
<connection>scm:git:git://github.com/NerdNu/${project.name}.git</connection>
<url>https://github.com/NerdNu/${project.name}</url>
<developerConnection>scm:git:git://github.com/NerdNu/${project.name}.git</developerConnection>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package</defaultGoal>
<sourceDirectory>${basedir}/src</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
95 changes: 95 additions & 0 deletions src/nu/nerd/beastmaster/BeastMaster.java
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions src/nu/nerd/beastmaster/Configuration.java
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5bfbab3

Please sign in to comment.