-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78bdf88
Showing
13 changed files
with
1,442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Eclipse stuff | ||
/.classpath | ||
/.project | ||
/.settings | ||
|
||
# maven | ||
/build.xml | ||
/target | ||
/maven.txt | ||
|
||
# temp files | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[2014-05-03] v1.0 | ||
- Initial re-release | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
DeadHorses | ||
========== | ||
|
||
Allow players to tame and ride undead horses! | ||
|
||
Permissions | ||
----------- | ||
deadhorses.admin - Grants access to reload and user node | ||
deadhorses.user - Allows players to use the plugin | ||
|
||
Commands | ||
-------- | ||
/deadhorses reload - Reload configuration from disk | ||
/deadhorses summon - Summon dead horses for testing | ||
|
||
Configuration | ||
------------- | ||
Each variant of dead horse has its own food list (from org.bukkit.Material) | ||
Foods can be defined with data values like: `'golden_apple:1': 100.0` | ||
Foods map to chance-to-tame odds, in percent (0.0-100.0) | ||
Default config.yml: | ||
|
||
skeleton_horse: | ||
spider_eye: 2.5 | ||
fermented_spider_eye: 5.0 | ||
poisonous_potato: 10.0 | ||
undead_horse: | ||
raw_beef: 10.0 | ||
pork: 5.0 | ||
raw_chicken: 2.5 | ||
raw_fish: 1.25 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<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>net.easymfne.plugins</groupId> | ||
<artifactId>DeadHorses</artifactId> | ||
<version>1.0</version> | ||
<name>${project.artifactId}</name> | ||
<build> | ||
<finalName>${project.artifactId}-${project.version}</finalName> | ||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<targetPath>.</targetPath> | ||
<filtering>true</filtering> | ||
<directory>${basedir}/src/main/resources/</directory> | ||
<includes> | ||
<include>*.yml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<excludes> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptors> | ||
<descriptor>src/main/assembly/package.xml</descriptor> | ||
</descriptors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>build</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
<updatePolicy>always</updatePolicy> | ||
<checksumPolicy>fail</checksumPolicy> | ||
</snapshots> | ||
<id>bukkit-repo</id> | ||
<url>http://repo.bukkit.org/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bukkit</groupId> | ||
<artifactId>bukkit</artifactId> | ||
<version>LATEST</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit-dep</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<description>Allow players to tame and ride undead horses!</description> | ||
</project> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> | ||
<id>source</id> | ||
<includeBaseDirectory>false</includeBaseDirectory> | ||
<formats> | ||
<format>zip</format> | ||
</formats> | ||
<fileSets> | ||
<fileSet> | ||
<directory>${basedir}/src</directory> | ||
<outputDirectory>/src</outputDirectory> | ||
</fileSet> | ||
</fileSets> | ||
<files> | ||
<file> | ||
<source>${project.build.directory}/${project.artifactId}-${project.version}.jar</source> | ||
<outputDirectory>/</outputDirectory> | ||
<destName>${project.artifactId}-${project.version}.jar</destName> | ||
</file> | ||
</files> | ||
</assembly> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of the DeadHorses plugin by EasyMFnE. | ||
* | ||
* DeadHorses 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 any later version. | ||
* | ||
* DeadHorses 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 details. | ||
* | ||
* You should have received a copy of the GNU General Public License v3 along | ||
* with DeadHorses. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.easymfne.deadhorses; | ||
|
||
import org.bukkit.entity.Horse; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* Configuration helper class, with methods for accessing the configuration. | ||
* | ||
* @author Eric Hildebrand | ||
*/ | ||
public class Config { | ||
|
||
private DeadHorses plugin = null; | ||
|
||
/** | ||
* Instantiate the class and give it a reference back to the plugin itself. | ||
* | ||
* @param plugin | ||
* The DeadHorses plugin | ||
*/ | ||
public Config(DeadHorses plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
/** | ||
* Examine an itemstack and determine the probability that a given horse | ||
* variant will become tamed upon consuming one item. | ||
* | ||
* @param variant | ||
* The type of Horse | ||
* @param item | ||
* The ItemStack that may be edible | ||
* @return The chance of becoming tamed | ||
*/ | ||
public double getFoodChance(Horse.Variant variant, ItemStack item) { | ||
String node = variant.name().toLowerCase() + "." | ||
+ item.getType().name().toLowerCase(); | ||
/* Check to see if the food is defined without a data value */ | ||
if (plugin.getConfig().contains(node)) { | ||
return plugin.getConfig().getDouble(node, 0.0); | ||
} | ||
/* Check to see if the food is defined with a data value */ | ||
if (plugin.getConfig().contains(node + ":" + item.getDurability())) { | ||
return plugin.getConfig().getDouble( | ||
node + ":" + item.getDurability(), 0.0); | ||
} | ||
return 0.0; | ||
} | ||
|
||
/** | ||
* Examine an itemstack and determine if a specific horse Variant can eat it | ||
* | ||
* @param variant | ||
* The type of Horse | ||
* @param item | ||
* The ItemStack that may be edible | ||
* @return Whether the Horse can eat the item or not | ||
*/ | ||
public boolean isFood(Horse.Variant variant, ItemStack item) { | ||
String node = variant.name().toLowerCase() + "." | ||
+ item.getType().name().toLowerCase(); | ||
/* Check to see if the food is defined without a data value */ | ||
if (plugin.getConfig().contains(node) | ||
&& plugin.getConfig().getDouble(node, 0.0) > 0.0) { | ||
return true; | ||
} | ||
/* Check to see if the food is defined with a data value */ | ||
if (plugin.getConfig().contains(node + ":" + item.getDurability()) | ||
&& plugin.getConfig().getDouble( | ||
node + ":" + item.getDurability(), 0.0) > 0.0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* This file is part of the DeadHorses plugin by EasyMFnE. | ||
* | ||
* DeadHorses 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 any later version. | ||
* | ||
* DeadHorses 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 details. | ||
* | ||
* You should have received a copy of the GNU General Public License v3 along | ||
* with DeadHorses. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.easymfne.deadhorses; | ||
|
||
import java.io.File; | ||
import java.util.Calendar; | ||
import java.util.logging.Level; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
/** | ||
* Main plugin class, responsible for its own setup, logging, reloading, and | ||
* shutdown operations. Maintains instances of Config, DeadHorsesCommand, and | ||
* PlayerListener. | ||
* | ||
* @author Eric Hildebrand | ||
*/ | ||
public class DeadHorses extends JavaPlugin { | ||
|
||
private Config config = null; | ||
private DeadHorsesCommand deadHorsesCommand = null; | ||
private PlayerListener playerListener = null; | ||
|
||
/* Strings for fancyLog() methods */ | ||
private final String logPrefix = ChatColor.DARK_GREEN + "[DeadHorses] "; | ||
private final String logColor = ChatColor.DARK_GRAY.toString(); | ||
|
||
/** | ||
* Log a message to the console using color, with a specific logging Level. | ||
* If there is no console open, log the message without any coloration. | ||
* | ||
* @param level | ||
* Level at which the message should be logged | ||
* @param message | ||
* The message to be logged | ||
*/ | ||
protected void fancyLog(Level level, String message) { | ||
if (getServer().getConsoleSender() != null) { | ||
getServer().getConsoleSender().sendMessage( | ||
logPrefix + logColor + message); | ||
} else { | ||
getServer().getLogger().log(level, | ||
ChatColor.stripColor(logPrefix + message)); | ||
} | ||
} | ||
|
||
/** | ||
* Log a message to the console using color, defaulting to the Info level. | ||
* If there is no console open, log the message without any coloration. | ||
* | ||
* @param message | ||
* The message to be logged | ||
*/ | ||
protected void fancyLog(String message) { | ||
fancyLog(Level.INFO, message); | ||
} | ||
|
||
/** | ||
* @return the configuration helper instance | ||
*/ | ||
public Config getPluginConfig() { | ||
return config; | ||
} | ||
|
||
/** | ||
* Close all event handlers and command listeners, then null instances to | ||
* mark them for garbage collection. Displays elapsed time to console when | ||
* finished. | ||
*/ | ||
@Override | ||
public void onDisable() { | ||
long start = Calendar.getInstance().getTimeInMillis(); | ||
fancyLog("=== DISABLE START ==="); | ||
playerListener.close(); | ||
playerListener = null; | ||
deadHorsesCommand.close(); | ||
deadHorsesCommand = null; | ||
config = null; | ||
fancyLog("=== DISABLE COMPLETE (" | ||
+ (Calendar.getInstance().getTimeInMillis() - start) | ||
+ "ms) ==="); | ||
} | ||
|
||
/** | ||
* Set up the plugin by: loading config.yml (creating from default if not | ||
* existent), then instantiating its own Config, DeadHorsesCommand, and | ||
* PlayerListener objects. Displays elapsed time to console when finished. | ||
*/ | ||
@Override | ||
public void onEnable() { | ||
long start = Calendar.getInstance().getTimeInMillis(); | ||
fancyLog("=== ENABLE START ==="); | ||
File configFile = new File(getDataFolder(), "config.yml"); | ||
if (!configFile.exists()) { | ||
saveDefaultConfig(); | ||
fancyLog("Saved default config.yml"); | ||
} | ||
|
||
config = new Config(this); | ||
deadHorsesCommand = new DeadHorsesCommand(this); | ||
playerListener = new PlayerListener(this); | ||
fancyLog("=== ENABLE COMPLETE (" | ||
+ (Calendar.getInstance().getTimeInMillis() - start) | ||
+ "ms) ==="); | ||
} | ||
|
||
/** | ||
* Reload the configuration from disk and perform any necessary functions. | ||
* Displays elapsed time to console when finished. | ||
*/ | ||
public void reload() { | ||
long start = Calendar.getInstance().getTimeInMillis(); | ||
fancyLog("=== RELOAD START ==="); | ||
reloadConfig(); | ||
fancyLog("=== RELOAD COMPLETE (" | ||
+ (Calendar.getInstance().getTimeInMillis() - start) | ||
+ "ms) ==="); | ||
} | ||
|
||
} |
Oops, something went wrong.