Compare commits
64 Commits
Author | SHA1 | Date |
---|---|---|
Shansen | ba1d47b0e6 | |
shansen | 31c8b4ae77 | |
shansen | b3e9de17e8 | |
shansen | 3493e0b84f | |
shansen | f7e71f302e | |
shansen | c551f44c48 | |
shansen | 662bbc8088 | |
shansen | fe0c996f8b | |
shansen | 3656fcf5a6 | |
shansen | 832fcaacf0 | |
shansen | 7191006cdc | |
shansen | dadf2162ed | |
shansen | 4c036ba2e7 | |
shansen | 335c6c26c8 | |
shansen | 09cfcd2ead | |
shansen | fb25c3fb3c | |
shansen | 304cf29b42 | |
shansen | bbef805c28 | |
shansen | e313a1c41c | |
shansen | b915530a30 | |
shansen | 804a3e59e6 | |
shansen | a88e12a8f7 | |
shansen | 322981bdf5 | |
shansen | 5a70b9cae6 | |
shansen | accf9e2552 | |
shansen | 1c5d81c98f | |
Carter | e3268ef46c | |
shansen | 19b269d425 | |
shansen | e399df0d6f | |
shansen | 6eb0d3cc7c | |
shansen | 7da6b04898 | |
shansen | f28dad66f4 | |
shansen | 65bc2f1f93 | |
shansen | 7a6f65c13f | |
shansen | 9c4dd2a5da | |
shansen | 2cc3ea7eec | |
Shansen | 42385e9f45 | |
shansen | 3a0af57e0c | |
Asgarioth | c7d61e3bb6 | |
shansen | b6d9d62d3c | |
shansen | 48ea20fdca | |
shansen | 9af91bb570 | |
shansen | faa261de24 | |
shansen | bf1ce3d38a | |
shansen | d4ba2ea5dc | |
shansen | b41a7099b0 | |
shansen | 52037c2e7f | |
shansen | ddb945401c | |
Shansen | 1c0f29242e | |
shansen | 622f9340c4 | |
shansen | 978271402f | |
shansen | 47c315a73f | |
shansen | fa4216dda9 | |
shansen | 93e0401c14 | |
shansen | 5379c5ab32 | |
shansen | 965d3aa8c2 | |
shansen | 850f79783f | |
shansen | 3b613360d4 | |
shansen | dbf74377d5 | |
shansen | 95b9960db1 | |
shansen | b294d1db5b | |
shansen | 54df5d2299 | |
shansen | f4977e7312 | |
shansen | eadfd0aa02 |
|
@ -0,0 +1,15 @@
|
|||
before_script:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y software-properties-common
|
||||
- add-apt-repository -y ppa:webupd8team/java
|
||||
- apt-get update -qq
|
||||
- echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
|
||||
- echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
|
||||
- apt-get install -y oracle-java8-installer
|
||||
- apt-get install -y maven
|
||||
build:
|
||||
script:
|
||||
- mvn install
|
||||
artifacts:
|
||||
paths:
|
||||
- target/EggCatcher-1.0-SNAPSHOT.jar
|
|
@ -1,3 +1,7 @@
|
|||
language: java
|
||||
dist: trusty
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
[![Build Status](https://secure.travis-ci.org/shansen/EggCatcher.png)](http://travis-ci.org/shansen/EggCatcher)
|
||||
#EggCatcher
|
||||
# EggCatcher [![Build Status](https://travis-ci.org/shansen/EggCatcher.svg?branch=master)](https://travis-ci.org/shansen/EggCatcher)
|
||||
|
||||
This plugin allows the players to get spawn eggs by throwing regular eggs at mobs. It is intended to be simple to set up and use. If you make any changes, pull requests are appreciated.
|
||||
|
||||
|
@ -12,8 +11,9 @@ This plugin allows the players to get spawn eggs by throwing regular eggs at mob
|
|||
* Configurable catch chance.
|
||||
* Configurable cost (vault support, or items).
|
||||
* Explosion effects.
|
||||
|
||||
## Installation and requirements ##
|
||||
**Vault is not required unless you intend to use it**
|
||||
**Vault is supported but not required**
|
||||
|
||||
Download the jar file and the [configuration](http://dev.bukkit.org/server-mods/eggcatcher/pages/configuration/) file will be generated on the first startup.
|
||||
|
||||
|
@ -22,6 +22,6 @@ Download the jar file and the [configuration](http://dev.bukkit.org/server-mods/
|
|||
* [Configuration](http://dev.bukkit.org/server-mods/eggcatcher/pages/configuration/)
|
||||
|
||||
## Video ##
|
||||
[![ScreenShot](http://dl.dropbox.com/u/456896/eggcatcgervideo.png)](http://youtu.be/k1Wcj8Cvmsc)
|
||||
[![ScreenShot](https://www.dropbox.com/s/uujjrmat555j707/eggcatchervideo.png?raw=1)](http://youtu.be/k1Wcj8Cvmsc)
|
||||
|
||||
Video credits: [VariationVault](http://www.youtube.com/user/VariationVault)
|
||||
|
|
40
pom.xml
40
pom.xml
|
@ -14,19 +14,22 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.bstats:*</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>org.bukkit:bukkit</exclude>
|
||||
<exclude>org.yaml:snakeyaml</exclude>
|
||||
|
@ -35,8 +38,8 @@
|
|||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>me.shansen.EggCatcher.mcstats</shadedPattern>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.shansen.EggCatcher.bstats</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
|
@ -58,16 +61,16 @@
|
|||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public/</url>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Plugin Metrics</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/public</url>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
@ -75,18 +78,19 @@
|
|||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.27</version>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R7</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -25,8 +25,7 @@ import org.bukkit.entity.Egg;
|
|||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
import java.io.IOException;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -40,10 +39,6 @@ public class EggCatcher extends JavaPlugin {
|
|||
public void onEnable() {
|
||||
this.CheckConfigurationFile();
|
||||
|
||||
if (this.getConfig().getBoolean("CheckForUpdates")) {
|
||||
this.CheckUpdate();
|
||||
}
|
||||
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
|
||||
final EggCatcherPlayerListener playerListener = new EggCatcherPlayerListener();
|
||||
|
@ -59,22 +54,17 @@ public class EggCatcher extends JavaPlugin {
|
|||
economy = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckUpdate() {
|
||||
Updater updater = new Updater(this, 35664, this.getFile(), Updater.UpdateType.DEFAULT, false);
|
||||
Metrics metrics = new Metrics(this, 894);
|
||||
}
|
||||
|
||||
public void CheckConfigurationFile() {
|
||||
double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0);
|
||||
if (configVersion != 2.00) {
|
||||
if (configVersion == 5.0) {
|
||||
this.saveConfig();
|
||||
} else {
|
||||
this.saveResource("config.yml", true);
|
||||
this.reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package me.shansen.EggCatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
//Created 11/11/2016 2:21 AM
|
||||
public class EggCatcherLogger{
|
||||
private final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
private File file;
|
||||
|
||||
public EggCatcherLogger(File file){
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public void logToFile(String message){
|
||||
if (!file.exists()){
|
||||
try{
|
||||
file.createNewFile();
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
PrintWriter pw = null;
|
||||
try{
|
||||
pw = new PrintWriter(new FileWriter(file, true));
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
pw.println(dateFormat.format(System.currentTimeMillis()) + " " + message);
|
||||
pw.flush();
|
||||
pw.close();
|
||||
}
|
||||
|
||||
public File getFile(){
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file){
|
||||
this.file = file;
|
||||
}
|
||||
}
|
|
@ -18,49 +18,79 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
package me.shansen.EggCatcher;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public enum EggType {
|
||||
PIG_ZOMBIE(EntityType.PIG_ZOMBIE, 57, "PigZombie"),
|
||||
MAGMA_CUBE(EntityType.MAGMA_CUBE, 62, "MagmaCube"),
|
||||
CAVE_SPIDER(EntityType.CAVE_SPIDER, 59, "CaveSpider"),
|
||||
MUSHROOM_COW(EntityType.MUSHROOM_COW, 96, "MushroomCow"),
|
||||
CREEPER(EntityType.CREEPER, 50, "Creeper"),
|
||||
SKELETON(EntityType.SKELETON, 51, "Skeleton"),
|
||||
SPIDER(EntityType.SPIDER, 52, "Spider"),
|
||||
ZOMBIE(EntityType.ZOMBIE, 54, "Zombie"),
|
||||
SLIME(EntityType.SLIME, 55, "Slime"),
|
||||
GHAST(EntityType.GHAST, 56, "Ghast"),
|
||||
ENDERMAN(EntityType.ENDERMAN, 58, "Enderman"),
|
||||
SILVERFISH(EntityType.SILVERFISH, 60, "Silverfish"),
|
||||
BLAZE(EntityType.BLAZE, 61, "Blaze"),
|
||||
PIG(EntityType.PIG, 90, "Pig"),
|
||||
SHEEP(EntityType.SHEEP, 91, "Sheep"),
|
||||
COW(EntityType.COW, 92, "Cow"),
|
||||
CHICKEN(EntityType.CHICKEN, 93, "Chicken"),
|
||||
SQUID(EntityType.SQUID, 94, "Squid"),
|
||||
WOLF(EntityType.WOLF, 95, "Wolf"),
|
||||
VILLAGER(EntityType.VILLAGER, 120, "Villager"),
|
||||
OCELOT(EntityType.OCELOT, 98, "Ocelot"),
|
||||
BAT(EntityType.BAT, 65, "Bat"),
|
||||
WITCH(EntityType.WITCH, 66, "Witch"),
|
||||
HORSE(EntityType.HORSE, 100, "Horse");
|
||||
|
||||
|
||||
DROWNED(EntityType.DROWNED, "Drowned", Material.DROWNED_SPAWN_EGG),
|
||||
EVOKER(EntityType.EVOKER,"Evoker", Material.EVOKER_SPAWN_EGG),
|
||||
VEX(EntityType.VEX, "Vex", Material.VEX_SPAWN_EGG),
|
||||
VINDICATOR(EntityType.VINDICATOR, "Vindicator", Material.VINDICATOR_SPAWN_EGG),
|
||||
PIG_ZOMBIE(EntityType.PIG_ZOMBIE, "PigZombie", Material.ZOMBIE_PIGMAN_SPAWN_EGG),
|
||||
MAGMA_CUBE(EntityType.MAGMA_CUBE, "MagmaCube", Material.MAGMA_CUBE_SPAWN_EGG),
|
||||
CAVE_SPIDER(EntityType.CAVE_SPIDER, "CaveSpider", Material.CAVE_SPIDER_SPAWN_EGG),
|
||||
MUSHROOM_COW(EntityType.MUSHROOM_COW, "MushroomCow", Material.MOOSHROOM_SPAWN_EGG),
|
||||
CREEPER(EntityType.CREEPER,"Creeper", Material.CREEPER_SPAWN_EGG),
|
||||
WITHER_SKELETON(EntityType.WITHER_SKELETON, "WitherSkeleton", Material.WITHER_SKELETON_SPAWN_EGG),
|
||||
STRAY(EntityType.STRAY, "Stray", Material.STRAY_SPAWN_EGG),
|
||||
SKELETON(EntityType.SKELETON, "Skeleton", Material.SKELETON_SPAWN_EGG),
|
||||
SPIDER(EntityType.SPIDER, "Spider", Material.SPIDER_SPAWN_EGG),
|
||||
HUSK(EntityType.HUSK, "Husk", Material.HUSK_SPAWN_EGG),
|
||||
ZOMBIE_VILLAGER(EntityType.ZOMBIE_VILLAGER, "ZombieVillager", Material.ZOMBIE_VILLAGER_SPAWN_EGG),
|
||||
ZOMBIE(EntityType.ZOMBIE, "Zombie", Material.ZOMBIE_SPAWN_EGG),
|
||||
SLIME(EntityType.SLIME, "Slime", Material.SLIME_SPAWN_EGG),
|
||||
GHAST(EntityType.GHAST, "Ghast", Material.GHAST_SPAWN_EGG),
|
||||
ENDERMAN(EntityType.ENDERMAN, "Enderman", Material.ENDERMAN_SPAWN_EGG),
|
||||
SILVERFISH(EntityType.SILVERFISH, "Silverfish", Material.SILVERFISH_SPAWN_EGG),
|
||||
BLAZE(EntityType.BLAZE, "Blaze", Material.BLAZE_SPAWN_EGG),
|
||||
PIG(EntityType.PIG, "Pig", Material.PIG_SPAWN_EGG),
|
||||
SHEEP(EntityType.SHEEP, "Sheep", Material.SHEEP_SPAWN_EGG),
|
||||
COW(EntityType.COW, "Cow", Material.COW_SPAWN_EGG),
|
||||
CHICKEN(EntityType.CHICKEN, "Chicken", Material.CHICKEN_SPAWN_EGG),
|
||||
SQUID(EntityType.SQUID, "Squid", Material.SQUID_SPAWN_EGG),
|
||||
WOLF(EntityType.WOLF, "Wolf", Material.WOLF_SPAWN_EGG),
|
||||
VILLAGER(EntityType.VILLAGER, "Villager", Material.VILLAGER_SPAWN_EGG),
|
||||
OCELOT(EntityType.OCELOT, "Ocelot", Material.OCELOT_SPAWN_EGG),
|
||||
BAT(EntityType.BAT, "Bat", Material.BAT_SPAWN_EGG),
|
||||
WITCH(EntityType.WITCH, "Witch", Material.WITCH_SPAWN_EGG),
|
||||
ZOMBIE_HORSE(EntityType.ZOMBIE_HORSE, "ZombieHorse", Material.ZOMBIE_HORSE_SPAWN_EGG),
|
||||
SKELETON_HORSE(EntityType.SKELETON_HORSE, "SkeletonHorse", Material.SKELETON_HORSE_SPAWN_EGG),
|
||||
TRADER_LLAMA(EntityType.TRADER_LLAMA, "TraderLlama", Material.TRADER_LLAMA_SPAWN_EGG),
|
||||
LLAMA(EntityType.LLAMA, "Llama", Material.LLAMA_SPAWN_EGG),
|
||||
DONKEY(EntityType.DONKEY, "Donkey", Material.DONKEY_SPAWN_EGG),
|
||||
MULE(EntityType.MULE, "Mule", Material.MULE_SPAWN_EGG),
|
||||
HORSE(EntityType.HORSE, "Horse", Material.HORSE_SPAWN_EGG),
|
||||
ENDERMITE(EntityType.ENDERMITE, "Endermite", Material.ENDERMITE_SPAWN_EGG),
|
||||
ELDER_GUARDIAN(EntityType.ELDER_GUARDIAN, "ElderGuardian", Material.ELDER_GUARDIAN_SPAWN_EGG),
|
||||
GUARDIAN(EntityType.GUARDIAN, "Guardian", Material.GUARDIAN_SPAWN_EGG),
|
||||
RABBIT(EntityType.RABBIT, "Rabbit", Material.RABBIT_SPAWN_EGG),
|
||||
POLAR_BEAR(EntityType.POLAR_BEAR, "PolarBear", Material.POLAR_BEAR_SPAWN_EGG),
|
||||
SHULKER(EntityType.SHULKER, "Shulker", Material.SHULKER_SPAWN_EGG),
|
||||
PARROT(EntityType.PARROT, "Parrot", Material.PARROT_SPAWN_EGG),
|
||||
BEE(EntityType.BEE, "Bee", Material.BEE_SPAWN_EGG),
|
||||
CAT(EntityType.CAT, "Cat", Material.CAT_SPAWN_EGG),
|
||||
COD(EntityType.COD, "Cod", Material.COD_SPAWN_EGG),
|
||||
DOLPHIN(EntityType.DOLPHIN, "Dolphin", Material.DOLPHIN_SPAWN_EGG),
|
||||
FOX(EntityType.FOX, "Fox", Material.FOX_SPAWN_EGG),
|
||||
PANDA(EntityType.PANDA, "Panda", Material.PANDA_SPAWN_EGG),
|
||||
PHANTOM(EntityType.PHANTOM, "Phantom", Material.PHANTOM_SPAWN_EGG),
|
||||
PILLAGER(EntityType.PILLAGER, "Pillager", Material.PILLAGER_SPAWN_EGG),
|
||||
PUFFERFISH(EntityType.PUFFERFISH, "Pufferfish", Material.PUFFERFISH_SPAWN_EGG),
|
||||
RAVAGER(EntityType.RAVAGER, "Ravager", Material.RAVAGER_SPAWN_EGG),
|
||||
SALMON(EntityType.SALMON, "Salmon", Material.SALMON_SPAWN_EGG),
|
||||
TROPICAL_FISH(EntityType.TROPICAL_FISH, "TropicalFish", Material.TROPICAL_FISH_SPAWN_EGG),
|
||||
TURTLE(EntityType.TURTLE, "Turtle", Material.TURTLE_SPAWN_EGG),
|
||||
WANDERING_TRADER(EntityType.WANDERING_TRADER, "WanderingTrader", Material.WANDERING_TRADER_SPAWN_EGG);
|
||||
|
||||
private final EntityType entityType;
|
||||
private final Integer creatureId;
|
||||
private final String friendlyName;
|
||||
private final Material material;
|
||||
|
||||
EggType(EntityType entityType, Integer creatureId, String friendlyName) {
|
||||
EggType(EntityType entityType, String friendlyName, Material material) {
|
||||
this.entityType = entityType;
|
||||
this.creatureId = creatureId;
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public short getCreatureId() {
|
||||
return this.creatureId.shortValue();
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public EntityType getCreatureType() {
|
||||
|
@ -71,6 +101,10 @@ public enum EggType {
|
|||
return this.friendlyName;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public static EggType getEggType(Entity entity) {
|
||||
for (EggType eggType : EggType.values()) {
|
||||
if (!eggType.getCreatureType().getEntityClass().isInstance(entity)) {
|
||||
|
|
|
@ -1,515 +0,0 @@
|
|||
/*
|
||||
* Updater for Bukkit.
|
||||
*
|
||||
* This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org
|
||||
*/
|
||||
|
||||
package me.shansen.EggCatcher;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
|
||||
* <p/>
|
||||
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating.
|
||||
* <br>
|
||||
* It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>.
|
||||
* <br>
|
||||
* If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
|
||||
* <p/>
|
||||
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater.
|
||||
* <br>
|
||||
* If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
|
||||
*
|
||||
* @author Gravity
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
public class Updater {
|
||||
|
||||
private Plugin plugin;
|
||||
private UpdateType type;
|
||||
private String versionName;
|
||||
private String versionLink;
|
||||
private String versionType;
|
||||
private String versionGameVersion;
|
||||
|
||||
private boolean announce; // Whether to announce file downloads
|
||||
|
||||
private URL url; // Connecting to RSS
|
||||
private File file; // The plugin's file
|
||||
private Thread thread; // Updater thread
|
||||
|
||||
private int id = -1; // Project's Curse ID
|
||||
private String apiKey = null; // BukkitDev ServerMods API key
|
||||
private static final String TITLE_VALUE = "name"; // Gets remote file's title
|
||||
private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link
|
||||
private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type
|
||||
private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version
|
||||
private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
|
||||
private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
|
||||
|
||||
private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
|
||||
private static final int BYTE_SIZE = 1024; // Used for downloading files
|
||||
private YamlConfiguration config; // Config file
|
||||
private String updateFolder;// The folder that downloads will be placed in
|
||||
private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process
|
||||
|
||||
/**
|
||||
* Gives the dev the result of the update process. Can be obtained by called getResult().
|
||||
*/
|
||||
public enum UpdateResult {
|
||||
/**
|
||||
* The updater found an update, and has readied it to be loaded the next time the server restarts/reloads.
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* The updater did not find an update, and nothing was downloaded.
|
||||
*/
|
||||
NO_UPDATE,
|
||||
/**
|
||||
* The server administrator has disabled the updating system
|
||||
*/
|
||||
DISABLED,
|
||||
/**
|
||||
* The updater found an update, but was unable to download it.
|
||||
*/
|
||||
FAIL_DOWNLOAD,
|
||||
/**
|
||||
* For some reason, the updater was unable to contact dev.bukkit.org to download the file.
|
||||
*/
|
||||
FAIL_DBO,
|
||||
/**
|
||||
* When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'.
|
||||
*/
|
||||
FAIL_NOVERSION,
|
||||
/**
|
||||
* The id provided by the plugin running the updater was invalid and doesn't exist on DBO.
|
||||
*/
|
||||
FAIL_BADID,
|
||||
/**
|
||||
* The server administrator has improperly configured their API key in the configuration
|
||||
*/
|
||||
FAIL_APIKEY,
|
||||
/**
|
||||
* The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded.
|
||||
*/
|
||||
UPDATE_AVAILABLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the dev to specify the type of update that will be run.
|
||||
*/
|
||||
public enum UpdateType {
|
||||
/**
|
||||
* Run a version check, and then if the file is out of date, download the newest version.
|
||||
*/
|
||||
DEFAULT,
|
||||
/**
|
||||
* Don't run a version check, just find the latest update and download it.
|
||||
*/
|
||||
NO_VERSION_CHECK,
|
||||
/**
|
||||
* Get information about the version and the download size, but don't actually download anything.
|
||||
*/
|
||||
NO_DOWNLOAD
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the updater
|
||||
*
|
||||
* @param plugin The plugin that is checking for an update.
|
||||
* @param id The dev.bukkit.org id of the project
|
||||
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
|
||||
* @param type Specify the type of update this will be. See {@link UpdateType}
|
||||
* @param announce True if the program should announce the progress of new updates in console
|
||||
*/
|
||||
public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.announce = announce;
|
||||
this.file = file;
|
||||
this.id = id;
|
||||
this.updateFolder = plugin.getServer().getUpdateFolder();
|
||||
|
||||
final File pluginFile = plugin.getDataFolder().getParentFile();
|
||||
final File updaterFile = new File(pluginFile, "Updater");
|
||||
final File updaterConfigFile = new File(updaterFile, "config.yml");
|
||||
|
||||
if (!updaterFile.exists()) {
|
||||
updaterFile.mkdir();
|
||||
}
|
||||
if (!updaterConfigFile.exists()) {
|
||||
try {
|
||||
updaterConfigFile.createNewFile();
|
||||
} catch (final IOException e) {
|
||||
plugin.getLogger().severe("The updater could not create a configuration in " + updaterFile.getAbsolutePath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.config = YamlConfiguration.loadConfiguration(updaterConfigFile);
|
||||
|
||||
this.config.options().header("This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )" + '\n'
|
||||
+ "If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below." + '\n'
|
||||
+ "Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration.");
|
||||
this.config.addDefault("api-key", "PUT_API_KEY_HERE");
|
||||
this.config.addDefault("disable", false);
|
||||
|
||||
if (this.config.get("api-key", null) == null) {
|
||||
this.config.options().copyDefaults(true);
|
||||
try {
|
||||
this.config.save(updaterConfigFile);
|
||||
} catch (final IOException e) {
|
||||
plugin.getLogger().severe("The updater could not save the configuration in " + updaterFile.getAbsolutePath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.config.getBoolean("disable")) {
|
||||
this.result = UpdateResult.DISABLED;
|
||||
return;
|
||||
}
|
||||
|
||||
String key = this.config.getString("api-key");
|
||||
if (key.equalsIgnoreCase("PUT_API_KEY_HERE") || key.equals("")) {
|
||||
key = null;
|
||||
}
|
||||
|
||||
this.apiKey = key;
|
||||
|
||||
try {
|
||||
this.url = new URL(Updater.HOST + Updater.QUERY + id);
|
||||
} catch (final MalformedURLException e) {
|
||||
plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid.");
|
||||
this.result = UpdateResult.FAIL_BADID;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.thread = new Thread(new UpdateRunnable());
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result of the update process.
|
||||
*/
|
||||
public Updater.UpdateResult getResult() {
|
||||
this.waitForThread();
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's release type (release, beta, or alpha).
|
||||
*/
|
||||
public String getLatestType() {
|
||||
this.waitForThread();
|
||||
return this.versionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's game version.
|
||||
*/
|
||||
public String getLatestGameVersion() {
|
||||
this.waitForThread();
|
||||
return this.versionGameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's name.
|
||||
*/
|
||||
public String getLatestName() {
|
||||
this.waitForThread();
|
||||
return this.versionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's file link.
|
||||
*/
|
||||
public String getLatestFileLink() {
|
||||
this.waitForThread();
|
||||
return this.versionLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish
|
||||
* before allowing anyone to check the result.
|
||||
*/
|
||||
private void waitForThread() {
|
||||
if ((this.thread != null) && this.thread.isAlive()) {
|
||||
try {
|
||||
this.thread.join();
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an update from dev.bukkit.org into the server's update folder.
|
||||
*/
|
||||
private void saveFile(File folder, String file, String u) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
try {
|
||||
// Download the file
|
||||
final URL url = new URL(u);
|
||||
final int fileLength = url.openConnection().getContentLength();
|
||||
in = new BufferedInputStream(url.openStream());
|
||||
fout = new FileOutputStream(folder.getAbsolutePath() + "/" + file);
|
||||
|
||||
final byte[] data = new byte[Updater.BYTE_SIZE];
|
||||
int count;
|
||||
if (this.announce) {
|
||||
this.plugin.getLogger().info("About to download a new update: " + this.versionName);
|
||||
}
|
||||
long downloaded = 0;
|
||||
while ((count = in.read(data, 0, Updater.BYTE_SIZE)) != -1) {
|
||||
downloaded += count;
|
||||
fout.write(data, 0, count);
|
||||
final int percent = (int) ((downloaded * 100) / fileLength);
|
||||
if (this.announce && ((percent % 10) == 0)) {
|
||||
this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
|
||||
}
|
||||
}
|
||||
//Just a quick check to make sure we didn't leave any files from last time...
|
||||
for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) {
|
||||
if (xFile.getName().endsWith(".zip")) {
|
||||
xFile.delete();
|
||||
}
|
||||
}
|
||||
// Check to see if it's a zip file, if it is, unzip it.
|
||||
final File dFile = new File(folder.getAbsolutePath() + "/" + file);
|
||||
if (dFile.getName().endsWith(".zip")) {
|
||||
// Unzip
|
||||
this.unzip(dFile.getCanonicalPath());
|
||||
}
|
||||
if (this.announce) {
|
||||
this.plugin.getLogger().info("Finished updating.");
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
|
||||
this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of Zip-File-Extractor, modified by Gravity for use with Bukkit
|
||||
*/
|
||||
private void unzip(String file) {
|
||||
try {
|
||||
final File fSourceZip = new File(file);
|
||||
final String zipPath = file.substring(0, file.length() - 4);
|
||||
ZipFile zipFile = new ZipFile(fSourceZip);
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
File destinationFilePath = new File(zipPath, entry.getName());
|
||||
destinationFilePath.getParentFile().mkdirs();
|
||||
if (entry.isDirectory()) {
|
||||
continue;
|
||||
} else {
|
||||
final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
|
||||
int b;
|
||||
final byte buffer[] = new byte[Updater.BYTE_SIZE];
|
||||
final FileOutputStream fos = new FileOutputStream(destinationFilePath);
|
||||
final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE);
|
||||
while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) {
|
||||
bos.write(buffer, 0, b);
|
||||
}
|
||||
bos.flush();
|
||||
bos.close();
|
||||
bis.close();
|
||||
final String name = destinationFilePath.getName();
|
||||
if (name.endsWith(".jar") && this.pluginFile(name)) {
|
||||
destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name));
|
||||
}
|
||||
}
|
||||
entry = null;
|
||||
destinationFilePath = null;
|
||||
}
|
||||
e = null;
|
||||
zipFile.close();
|
||||
zipFile = null;
|
||||
|
||||
// Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
|
||||
for (final File dFile : new File(zipPath).listFiles()) {
|
||||
if (dFile.isDirectory()) {
|
||||
if (this.pluginFile(dFile.getName())) {
|
||||
final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
|
||||
final File[] contents = oFile.listFiles(); // List of existing files in the current dir
|
||||
for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir
|
||||
{
|
||||
boolean found = false;
|
||||
for (final File xFile : contents) // Loop through contents to see if it exists
|
||||
{
|
||||
if (xFile.getName().equals(cFile.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Move the new file into the current dir
|
||||
cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
|
||||
} else {
|
||||
// This file already exists, so we don't need it anymore.
|
||||
cFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dFile.delete();
|
||||
}
|
||||
new File(zipPath).delete();
|
||||
fSourceZip.delete();
|
||||
} catch (final IOException ex) {
|
||||
this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
|
||||
this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
|
||||
ex.printStackTrace();
|
||||
}
|
||||
new File(file).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
|
||||
*/
|
||||
private boolean pluginFile(String name) {
|
||||
for (final File file : new File("plugins").listFiles()) {
|
||||
if (file.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated
|
||||
*/
|
||||
private boolean versionCheck(String title) {
|
||||
if (this.type != UpdateType.NO_VERSION_CHECK) {
|
||||
final String version = this.plugin.getDescription().getVersion();
|
||||
if (title.split(" v").length == 2) {
|
||||
final String remoteVersion = title.split(" v")[1].split(" ")[0]; // Get the newest file's version number
|
||||
|
||||
if (this.hasTag(version) || version.equalsIgnoreCase(remoteVersion)) {
|
||||
// We already have the latest version, or this build is tagged for no-update
|
||||
this.result = Updater.UpdateResult.NO_UPDATE;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The file's name did not contain the string 'vVersion'
|
||||
final String authorInfo = this.plugin.getDescription().getAuthors().size() == 0 ? "" : " (" + this.plugin.getDescription().getAuthors().get(0) + ")";
|
||||
this.plugin.getLogger().warning("The author of this plugin" + authorInfo + " has misconfigured their Auto Update system");
|
||||
this.plugin.getLogger().warning("File versions should follow the format 'PluginName vVERSION'");
|
||||
this.plugin.getLogger().warning("Please notify the author of this error.");
|
||||
this.result = Updater.UpdateResult.FAIL_NOVERSION;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate whether the version number is marked showing that it should not be updated by this program
|
||||
*/
|
||||
private boolean hasTag(String version) {
|
||||
for (final String string : Updater.NO_UPDATE_TAG) {
|
||||
if (version.contains(string)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean read() {
|
||||
try {
|
||||
final URLConnection conn = this.url.openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
|
||||
if (this.apiKey != null) {
|
||||
conn.addRequestProperty("X-API-Key", this.apiKey);
|
||||
}
|
||||
conn.addRequestProperty("User-Agent", "Updater (by Gravity)");
|
||||
|
||||
conn.setDoOutput(true);
|
||||
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
final String response = reader.readLine();
|
||||
|
||||
final JSONArray array = (JSONArray) JSONValue.parse(response);
|
||||
|
||||
if (array.size() == 0) {
|
||||
this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id);
|
||||
this.result = UpdateResult.FAIL_BADID;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE);
|
||||
this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE);
|
||||
this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE);
|
||||
this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE);
|
||||
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
if (e.getMessage().contains("HTTP response code: 403")) {
|
||||
this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml");
|
||||
this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct.");
|
||||
this.result = UpdateResult.FAIL_APIKEY;
|
||||
} else {
|
||||
this.plugin.getLogger().warning("The updater could not contact dev.bukkit.org for updating.");
|
||||
this.plugin.getLogger().warning("If you have not recently modified your configuration and this is the first time you are seeing this message, the site may be experiencing temporary downtime.");
|
||||
this.result = UpdateResult.FAIL_DBO;
|
||||
}
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Updater.this.url != null) {
|
||||
// Obtain the results of the project's file feed
|
||||
if (Updater.this.read()) {
|
||||
if (Updater.this.versionCheck(Updater.this.versionName)) {
|
||||
if ((Updater.this.versionLink != null) && (Updater.this.type != UpdateType.NO_DOWNLOAD)) {
|
||||
String name = Updater.this.file.getName();
|
||||
// If it's a zip file, it shouldn't be downloaded as the plugin's name
|
||||
if (Updater.this.versionLink.endsWith(".zip")) {
|
||||
final String[] split = Updater.this.versionLink.split("/");
|
||||
name = split[split.length - 1];
|
||||
}
|
||||
Updater.this.saveFile(new File(Updater.this.plugin.getDataFolder().getParent(), Updater.this.updateFolder), name, Updater.this.versionLink);
|
||||
} else {
|
||||
Updater.this.result = UpdateResult.UPDATE_AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
package me.shansen.EggCatcher.listeners;
|
||||
|
||||
import me.shansen.EggCatcher.EggCatcher;
|
||||
import me.shansen.EggCatcher.EggCatcherLogger;
|
||||
import me.shansen.EggCatcher.EggType;
|
||||
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
||||
|
||||
|
@ -36,6 +37,8 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class EggCatcherEntityListener implements Listener {
|
||||
|
||||
private final boolean usePermissions;
|
||||
|
@ -56,8 +59,13 @@ public class EggCatcherEntityListener implements Listener {
|
|||
private final String vaultTargetBankAccount;
|
||||
private final boolean spawnChickenOnFail;
|
||||
private final boolean spawnChickenOnSuccess;
|
||||
private final boolean deleteVillagerInventoryOnCatch;
|
||||
private final boolean logCaptures;
|
||||
FileConfiguration config;
|
||||
JavaPlugin plugin;
|
||||
private final File captureLogFile;
|
||||
private final EggCatcherLogger captureLogger;
|
||||
|
||||
|
||||
public EggCatcherEntityListener(JavaPlugin plugin) {
|
||||
this.config = plugin.getConfig();
|
||||
|
@ -80,7 +88,11 @@ public class EggCatcherEntityListener implements Listener {
|
|||
this.spawnChickenOnFail = this.config.getBoolean("SpawnChickenOnFail", true);
|
||||
this.spawnChickenOnSuccess = this.config.getBoolean("SpawnChickenOnSuccess", false);
|
||||
this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", "");
|
||||
}
|
||||
this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false);
|
||||
this.logCaptures = this.config.getBoolean("LogEggCaptures", false);
|
||||
this.captureLogFile = new File(plugin.getDataFolder(), "captures.txt");
|
||||
this.captureLogger = new EggCatcherLogger(captureLogFile);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onEntityHitByEgg(EntityDamageEvent event) {
|
||||
|
@ -213,11 +225,11 @@ public class EggCatcherEntityListener implements Listener {
|
|||
}
|
||||
|
||||
if (this.useItemCost && !freeCatch) {
|
||||
int itemId = config.getInt("ItemCost.ItemId", 266);
|
||||
Material itemMaterial = Material.matchMaterial(config.getString("ItemCost.ItemId", "gold_nugget"));
|
||||
int itemData = config.getInt("ItemCost.ItemData", 0);
|
||||
int itemAmount = config.getInt("ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||
@SuppressWarnings("deprecation")
|
||||
ItemStack itemStack = new ItemStack(itemId, itemAmount, (short) itemData);
|
||||
ItemStack itemStack = new ItemStack(itemMaterial, itemAmount, (short) itemData);
|
||||
if (player.getInventory().containsAtLeast(itemStack, itemStack.getAmount())) {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostSuccess"),
|
||||
String.valueOf(itemAmount)));
|
||||
|
@ -253,7 +265,7 @@ public class EggCatcherEntityListener implements Listener {
|
|||
entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 0);
|
||||
}
|
||||
|
||||
ItemStack eggStack = new ItemStack(Material.MONSTER_EGG, 1, eggType.getCreatureId());
|
||||
ItemStack eggStack = new ItemStack(eggType.getMaterial(), 1);
|
||||
|
||||
String customName = ((LivingEntity) entity).getCustomName();
|
||||
|
||||
|
@ -276,7 +288,8 @@ public class EggCatcherEntityListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
if(entity instanceof InventoryHolder){
|
||||
if((entity instanceof Villager && !this.deleteVillagerInventoryOnCatch) ||
|
||||
(!(entity instanceof Villager) && entity instanceof InventoryHolder)) {
|
||||
|
||||
ItemStack[] items = ((InventoryHolder) entity).getInventory().getContents();
|
||||
|
||||
|
@ -294,5 +307,9 @@ public class EggCatcherEntityListener implements Listener {
|
|||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.logCaptures){
|
||||
captureLogger.logToFile("Player " + ((Player) egg.getShooter()).getName() + " caught " + entity.getType() + " at X" + Math.round(entity.getLocation().getX()) + ",Y" + Math.round(entity.getLocation().getY()) + ",Z" + Math.round(entity.getLocation().getZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package me.shansen.nbt;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NbtReflection {
|
||||
|
||||
public static ItemStack setNewEntityTag(ItemStack itemStack, String entityType) {
|
||||
try {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
if(version.contains("1_7") || version.contains("1_8")) {
|
||||
// Legacy support. Can be cleaned up later.
|
||||
return itemStack;
|
||||
}
|
||||
Class craftItemStack = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
||||
Object nmsItemStack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(craftItemStack, itemStack);
|
||||
Object rootTag = Class.forName("net.minecraft.server." + version + ".NBTTagCompound").newInstance();
|
||||
Object nbtEntityTag = Class.forName("net.minecraft.server." + version + ".NBTTagCompound").newInstance();
|
||||
|
||||
nbtEntityTag.getClass().getMethod("setString", String.class, String.class).invoke(nbtEntityTag, "id", "minecraft:" + entityType);
|
||||
rootTag.getClass().getMethod("set", String.class, rootTag.getClass().getSuperclass())
|
||||
.invoke(rootTag, "EntityTag", nbtEntityTag);
|
||||
|
||||
nmsItemStack.getClass().getMethod("setTag", rootTag.getClass()).invoke(nmsItemStack, rootTag);
|
||||
return (ItemStack) craftItemStack.getMethod("asBukkitCopy", nmsItemStack.getClass())
|
||||
.invoke(craftItemStack, nmsItemStack);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,109 +13,251 @@ PreventCatchingShearedSheeps: true
|
|||
SpawnChickenOnSuccess: false
|
||||
SpawnChickenOnFail: true
|
||||
VaultTargetBankAccount: ""
|
||||
DeleteVillagerInventoryOnCatch: false
|
||||
LogEggCaptures: false
|
||||
CatchChance:
|
||||
Pig: 100.0
|
||||
Sheep: 100.0
|
||||
MushroomCow: 100.0
|
||||
Cow: 100.0
|
||||
Chicken: 100.0
|
||||
Squid: 100.0
|
||||
Wolf: 100.0
|
||||
Creeper: 0.0
|
||||
Skeleton: 100.0
|
||||
CaveSpider: 100.0
|
||||
Spider: 100.0
|
||||
PigZombie: 100.0
|
||||
Zombie: 100.0
|
||||
MagmaCube: 100.0
|
||||
Slime: 100.0
|
||||
Ghast: 0.0
|
||||
Enderman: 100.0
|
||||
Silverfish: 100.0
|
||||
Blaze: 0.0
|
||||
Villager: 100.0
|
||||
Ocelot: 100.0
|
||||
Witch: 100.0
|
||||
Bat: 100.0
|
||||
Bee: 100.0
|
||||
Blaze: 100.0
|
||||
Cat: 100.0
|
||||
CaveSpider: 100.0
|
||||
Chicken: 100.0
|
||||
Cod: 100.0
|
||||
Cow: 100.0
|
||||
Creeper: 100.0
|
||||
Dolphin: 100.0
|
||||
Donkey: 100.0
|
||||
Drowned: 100.0
|
||||
ElderGuardian: 100.0
|
||||
Enderman: 100.0
|
||||
Endermite: 100.0
|
||||
Evoker: 100.0
|
||||
Fox: 100.0
|
||||
Ghast: 100.0
|
||||
Guardian: 100.0
|
||||
Horse: 100.0
|
||||
Husk: 100.0
|
||||
Llama: 100.0
|
||||
MagmaCube: 100.0
|
||||
Mule: 100.0
|
||||
MushroomCow: 100.0
|
||||
Ocelot: 100.0
|
||||
Panda: 100.0
|
||||
Parrot: 100.0
|
||||
Phantom: 100.0
|
||||
Pig: 100.0
|
||||
PigZombie: 100.0
|
||||
Pillager: 100.0
|
||||
PolarBear: 100.0
|
||||
Pufferfish: 100.0
|
||||
Rabbit: 100.0
|
||||
Ravager: 100.0
|
||||
Salmon: 100.0
|
||||
Sheep: 100.0
|
||||
Shulker: 100.0
|
||||
Silverfish: 100.0
|
||||
Skeleton: 100.0
|
||||
SkeletonHorse: 100.0
|
||||
Slime: 100.0
|
||||
Spider: 100.0
|
||||
Squid: 100.0
|
||||
Stray: 100.0
|
||||
TraderLlama: 100.0
|
||||
TropicalFish: 100.0
|
||||
Turtle: 100.0
|
||||
Vex: 100.0
|
||||
Villager: 100.0
|
||||
Vindicator: 100.0
|
||||
WanderingTrader: 100.0
|
||||
Witch: 100.0
|
||||
WitherSkeleton: 100.0
|
||||
Wolf: 100.0
|
||||
Zombie: 100.0
|
||||
ZombieHorse: 100.0
|
||||
ZombieVillager: 100.0
|
||||
VaultCost:
|
||||
Pig: 0.0
|
||||
Sheep: 0.0
|
||||
MushroomCow: 0.0
|
||||
Cow: 0.0
|
||||
Chicken: 0.0
|
||||
Squid: 0.0
|
||||
Wolf: 0.0
|
||||
Creeper: 0.0
|
||||
Skeleton: 0.0
|
||||
CaveSpider: 0.0
|
||||
Spider: 0.0
|
||||
PigZombie: 0.0
|
||||
Zombie: 0.0
|
||||
MagmaCube: 0.0
|
||||
Slime: 0.0
|
||||
Ghast: 0.0
|
||||
Enderman: 0.0
|
||||
Silverfish: 0.0
|
||||
Blaze: 0.0
|
||||
Villager: 0.0
|
||||
Ocelot: 0.0
|
||||
Witch: 0.0
|
||||
Bat: 0.0
|
||||
Bee: 0.0
|
||||
Blaze: 0.0
|
||||
Cat: 0.0
|
||||
CaveSpider: 0.0
|
||||
Chicken: 0.0
|
||||
Cod: 0.0
|
||||
Cow: 0.0
|
||||
Creeper: 0.0
|
||||
Dolphin: 0.0
|
||||
Donkey: 0.0
|
||||
Drowned: 0.0
|
||||
ElderGuardian: 0.0
|
||||
Enderman: 0.0
|
||||
Endermite: 0.0
|
||||
Evoker: 0.0
|
||||
Fox: 0.0
|
||||
Ghast: 0.0
|
||||
Guardian: 0.0
|
||||
Horse: 0.0
|
||||
Husk: 0.0
|
||||
Llama: 0.0
|
||||
MagmaCube: 0.0
|
||||
Mule: 0.0
|
||||
MushroomCow: 0.0
|
||||
Ocelot: 0.0
|
||||
Panda: 0.0
|
||||
Parrot: 0.0
|
||||
Phantom: 0.0
|
||||
Pig: 0.0
|
||||
PigZombie: 0.0
|
||||
Pillager: 0.0
|
||||
PolarBear: 0.0
|
||||
Pufferfish: 0.0
|
||||
Rabbit: 0.0
|
||||
Ravager: 0.0
|
||||
Salmon: 0.0
|
||||
Sheep: 0.0
|
||||
Shulker: 0.0
|
||||
Silverfish: 0.0
|
||||
Skeleton: 0.0
|
||||
SkeletonHorse: 0.0
|
||||
Slime: 0.0
|
||||
Spider: 0.0
|
||||
Squid: 0.0
|
||||
Stray: 0.0
|
||||
TraderLlama: 0.0
|
||||
TropicalFish: 0.0
|
||||
Turtle: 0.0
|
||||
Vex: 0.0
|
||||
Villager: 0.0
|
||||
Vindicator: 0.0
|
||||
WanderingTrader: 0.0
|
||||
Witch: 0.0
|
||||
WitherSkeleton: 0.0
|
||||
Wolf: 0.0
|
||||
Zombie: 0.0
|
||||
ZombieHorse: 0.0
|
||||
ZombieVillager: 0.0
|
||||
ItemCost:
|
||||
ItemId: 371
|
||||
ItemId: gold_nugget
|
||||
ItemData: 0
|
||||
Amount:
|
||||
Pig: 0
|
||||
Sheep: 0
|
||||
MushroomCow: 0
|
||||
Cow: 0
|
||||
Chicken: 0
|
||||
Squid: 0
|
||||
Wolf: 0
|
||||
Creeper: 0
|
||||
Skeleton: 0
|
||||
CaveSpider: 0
|
||||
Spider: 0
|
||||
PigZombie: 0
|
||||
Zombie: 0
|
||||
MagmaCube: 0
|
||||
Slime: 0
|
||||
Ghast: 0
|
||||
Enderman: 0
|
||||
Silverfish: 0
|
||||
Blaze: 0
|
||||
Villager: 0
|
||||
Ocelot: 0
|
||||
Witch: 0
|
||||
Bat: 0
|
||||
Horse: 0
|
||||
Bat: 0.0
|
||||
Bee: 0.0
|
||||
Blaze: 0.0
|
||||
Cat: 0.0
|
||||
CaveSpider: 0.0
|
||||
Chicken: 0.0
|
||||
Cod: 0.0
|
||||
Cow: 0.0
|
||||
Creeper: 0.0
|
||||
Dolphin: 0.0
|
||||
Donkey: 0.0
|
||||
Drowned: 0.0
|
||||
ElderGuardian: 0.0
|
||||
Enderman: 0.0
|
||||
Endermite: 0.0
|
||||
Evoker: 0.0
|
||||
Fox: 0.0
|
||||
Ghast: 0.0
|
||||
Guardian: 0.0
|
||||
Horse: 0.0
|
||||
Husk: 0.0
|
||||
Llama: 0.0
|
||||
MagmaCube: 0.0
|
||||
Mule: 0.0
|
||||
MushroomCow: 0.0
|
||||
Ocelot: 0.0
|
||||
Panda: 0.0
|
||||
Parrot: 0.0
|
||||
Phantom: 0.0
|
||||
Pig: 0.0
|
||||
PigZombie: 0.0
|
||||
Pillager: 0.0
|
||||
PolarBear: 0.0
|
||||
Pufferfish: 0.0
|
||||
Rabbit: 0.0
|
||||
Ravager: 0.0
|
||||
Salmon: 0.0
|
||||
Sheep: 0.0
|
||||
Shulker: 0.0
|
||||
Silverfish: 0.0
|
||||
Skeleton: 0.0
|
||||
SkeletonHorse: 0.0
|
||||
Slime: 0.0
|
||||
Spider: 0.0
|
||||
Squid: 0.0
|
||||
Stray: 0.0
|
||||
TraderLlama: 0.0
|
||||
TropicalFish: 0.0
|
||||
Turtle: 0.0
|
||||
Vex: 0.0
|
||||
Villager: 0.0
|
||||
Vindicator: 0.0
|
||||
WanderingTrader: 0.0
|
||||
Witch: 0.0
|
||||
WitherSkeleton: 0.0
|
||||
Wolf: 0.0
|
||||
Zombie: 0.0
|
||||
ZombieHorse: 0.0
|
||||
ZombieVillager: 0.0
|
||||
HealthPercentage:
|
||||
Pig: 100.0
|
||||
Sheep: 100.0
|
||||
MushroomCow: 100.0
|
||||
Cow: 100.0
|
||||
Chicken: 100.0
|
||||
Squid: 100.0
|
||||
Wolf: 100.0
|
||||
Creeper: 100.0
|
||||
Skeleton: 100.0
|
||||
CaveSpider: 100.0
|
||||
Spider: 100.0
|
||||
PigZombie: 100.0
|
||||
Zombie: 100.0
|
||||
MagmaCube: 100.0
|
||||
Slime: 100.0
|
||||
Ghast: 100.0
|
||||
Enderman: 100.0
|
||||
Silverfish: 100.0
|
||||
Blaze: 100.0
|
||||
Villager: 100.0
|
||||
Ocelot: 100.0
|
||||
Witch: 100.0
|
||||
Bat: 100.0
|
||||
Bee: 100.0
|
||||
Blaze: 100.0
|
||||
Cat: 100.0
|
||||
CaveSpider: 100.0
|
||||
Chicken: 100.0
|
||||
Cod: 100.0
|
||||
Cow: 100.0
|
||||
Creeper: 100.0
|
||||
Dolphin: 100.0
|
||||
Donkey: 100.0
|
||||
Drowned: 100.0
|
||||
ElderGuardian: 100.0
|
||||
Enderman: 100.0
|
||||
Endermite: 100.0
|
||||
Evoker: 100.0
|
||||
Fox: 100.0
|
||||
Ghast: 100.0
|
||||
Guardian: 100.0
|
||||
Horse: 100.0
|
||||
Husk: 100.0
|
||||
Llama: 100.0
|
||||
MagmaCube: 100.0
|
||||
Mule: 100.0
|
||||
MushroomCow: 100.0
|
||||
Ocelot: 100.0
|
||||
Panda: 100.0
|
||||
Parrot: 100.0
|
||||
Phantom: 100.0
|
||||
Pig: 100.0
|
||||
PigZombie: 100.0
|
||||
Pillager: 100.0
|
||||
PolarBear: 100.0
|
||||
Pufferfish: 100.0
|
||||
Rabbit: 100.0
|
||||
Ravager: 100.0
|
||||
Salmon: 100.0
|
||||
Sheep: 100.0
|
||||
Shulker: 100.0
|
||||
Silverfish: 100.0
|
||||
Skeleton: 100.0
|
||||
SkeletonHorse: 100.0
|
||||
Slime: 100.0
|
||||
Spider: 100.0
|
||||
Squid: 100.0
|
||||
Stray: 100.0
|
||||
TraderLlama: 100.0
|
||||
TropicalFish: 100.0
|
||||
Turtle: 100.0
|
||||
Vex: 100.0
|
||||
Villager: 100.0
|
||||
Vindicator: 100.0
|
||||
WanderingTrader: 100.0
|
||||
Witch: 100.0
|
||||
WitherSkeleton: 100.0
|
||||
Wolf: 100.0
|
||||
Zombie: 100.0
|
||||
ZombieHorse: 100.0
|
||||
ZombieVillager: 100.0
|
||||
Messages:
|
||||
PermissionFail: "You do not have permission to catch this mob!"
|
||||
VaultFail: "It costs %s dollars to catch this mob!"
|
||||
|
@ -125,5 +267,4 @@ Messages:
|
|||
CatchChanceFail: "You failed to catch this mob!"
|
||||
CatchChanceSuccess: ""
|
||||
HealthPercentageFail: "The mob has more than %s percent health left and cannot be caught!"
|
||||
ConfigVersion: 2.00
|
||||
CheckForUpdates: true
|
||||
ConfigVersion: 5.0
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
name: EggCatcher
|
||||
version: 2.1.1
|
||||
version: 5.0
|
||||
description: This plugin allows you to catch mobs in eggs.
|
||||
author: shansen
|
||||
api-version: 1.15
|
||||
|
||||
main: me.shansen.EggCatcher.EggCatcher
|
||||
|
||||
|
@ -10,30 +11,65 @@ permissions:
|
|||
description: Gives access to catch all types of mobs.
|
||||
default: op
|
||||
children:
|
||||
eggcatcher.catch.pig: true
|
||||
eggcatcher.catch.sheep: true
|
||||
eggcatcher.catch.cow: true
|
||||
eggcatcher.catch.chicken: true
|
||||
eggcatcher.catch.squid: true
|
||||
eggcatcher.catch.wolf: true
|
||||
eggcatcher.catch.mushroomCow: true
|
||||
eggcatcher.catch.creeper: true
|
||||
eggcatcher.catch.skeleton: true
|
||||
eggcatcher.catch.spider: true
|
||||
eggcatcher.catch.zombie: true
|
||||
eggcatcher.catch.slime: true
|
||||
eggcatcher.catch.ghast: true
|
||||
eggcatcher.catch.pigzombie: true
|
||||
eggcatcher.catch.enderman: true
|
||||
eggcatcher.catch.cavespider: true
|
||||
eggcatcher.catch.silverfish: true
|
||||
eggcatcher.catch.blaze: true
|
||||
eggcatcher.catch.magmacube: true
|
||||
eggcatcher.catch.villager: true
|
||||
eggcatcher.catch.ocelot: true
|
||||
eggcatcher.catch.bat: true
|
||||
eggcatcher.catch.witch: true
|
||||
eggcatcher.catch.bee: true
|
||||
eggcatcher.catch.blaze: true
|
||||
eggcatcher.catch.cat: true
|
||||
eggcatcher.catch.cavespider: true
|
||||
eggcatcher.catch.chicken: true
|
||||
eggcatcher.catch.cod: true
|
||||
eggcatcher.catch.cow: true
|
||||
eggcatcher.catch.creeper: true
|
||||
eggcatcher.catch.dolphin: true
|
||||
eggcatcher.catch.donkey: true
|
||||
eggcatcher.catch.drowned: true
|
||||
eggcatcher.catch.elderguardian: true
|
||||
eggcatcher.catch.enderman: true
|
||||
eggcatcher.catch.endermite: true
|
||||
eggcatcher.catch.evoker: true
|
||||
eggcatcher.catch.fox: true
|
||||
eggcatcher.catch.ghast: true
|
||||
eggcatcher.catch.guardian: true
|
||||
eggcatcher.catch.horse: true
|
||||
eggcatcher.catch.husk: true
|
||||
eggcatcher.catch.llama: true
|
||||
eggcatcher.catch.magmacube: true
|
||||
eggcatcher.catch.mule: true
|
||||
eggcatcher.catch.mushroomcow: true
|
||||
eggcatcher.catch.ocelot: true
|
||||
eggcatcher.catch.panda: true
|
||||
eggcatcher.catch.parrot: true
|
||||
eggcatcher.catch.phantom: true
|
||||
eggcatcher.catch.pig: true
|
||||
eggcatcher.catch.pigzombie: true
|
||||
eggcatcher.catch.pillager: true
|
||||
eggcatcher.catch.polarbear: true
|
||||
eggcatcher.catch.pufferfish: true
|
||||
eggcatcher.catch.rabbit: true
|
||||
eggcatcher.catch.ravager: true
|
||||
eggcatcher.catch.salmon: true
|
||||
eggcatcher.catch.sheep: true
|
||||
eggcatcher.catch.shulker: true
|
||||
eggcatcher.catch.silverfish: true
|
||||
eggcatcher.catch.skeleton: true
|
||||
eggcatcher.catch.skeletonhorse: true
|
||||
eggcatcher.catch.slime: true
|
||||
eggcatcher.catch.spider: true
|
||||
eggcatcher.catch.squid: true
|
||||
eggcatcher.catch.stray: true
|
||||
eggcatcher.catch.traderllama: true
|
||||
eggcatcher.catch.tropicalfish: true
|
||||
eggcatcher.catch.turtle: true
|
||||
eggcatcher.catch.vex: true
|
||||
eggcatcher.catch.villager: true
|
||||
eggcatcher.catch.vindicator: true
|
||||
eggcatcher.catch.wanderingtrader: true
|
||||
eggcatcher.catch.witch: true
|
||||
eggcatcher.catch.witherskeleton: true
|
||||
eggcatcher.catch.wolf: true
|
||||
eggcatcher.catch.zombie: true
|
||||
eggcatcher.catch.zombiehorse: true
|
||||
eggcatcher.catch.zombievillager: true
|
||||
eggcatcher.free:
|
||||
description: Makes catching a mob free.
|
||||
default: false
|
||||
default: false
|
||||
|
|
Loading…
Reference in New Issue