mirror of
https://github.com/shansen/EggCatcher.git
synced 2025-01-03 14:27:49 +01:00
Various code clean up
This commit is contained in:
parent
dbdff0616c
commit
afc967a960
140
pom.xml
140
pom.xml
@ -1,17 +1,17 @@
|
||||
<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>
|
||||
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>me.shansen</groupId>
|
||||
<artifactId>EggCatcher</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>me.shansen</groupId>
|
||||
<artifactId>EggCatcher</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EggCatcher</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<name>EggCatcher</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
@ -19,67 +19,67 @@
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.0</version>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.bukkit:bukkit</exclude>
|
||||
<exclude>org.yaml:snakeyaml</exclude>
|
||||
<exclude>net.milkbowl.vault:Vault</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.0</version>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.bukkit:bukkit</exclude>
|
||||
<exclude>org.yaml:snakeyaml</exclude>
|
||||
<exclude>net.milkbowl.vault:Vault</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Plugin Metrics</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Plugin Metrics</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.20-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.20-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -18,18 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package me.shansen.EggCatcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import me.shansen.EggCatcher.listeners.EggCatcherEntityListener;
|
||||
import me.shansen.EggCatcher.listeners.EggCatcherPlayerListener;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Egg;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -40,44 +32,46 @@ import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EggCatcher extends JavaPlugin {
|
||||
Logger log = Logger.getLogger("Minecraft");
|
||||
public static List<Egg> eggs = new ArrayList<Egg>();
|
||||
public static Economy economy = null;
|
||||
Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
public static List<Egg> eggs = new ArrayList<Egg>();
|
||||
public static Economy economy = null;
|
||||
public void onDisable() {
|
||||
log.info(this.getDescription().getName() + " v" + this.getDescription().getVersion() + " is disabled!");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
log.info(this.getDescription().getName() + " v"
|
||||
+ this.getDescription().getVersion() + " is disabled!");
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
public void onEnable() {
|
||||
this.CheckUpdate();
|
||||
this.CheckConfigurationFile();
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
log.info(this.getDescription().getName() + " v"
|
||||
+ this.getDescription().getVersion() + " is enabled!");
|
||||
this.CheckConfigurationFile();
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
log.info(this.getDescription().getName() + " v" + this.getDescription().getVersion() + " is enabled!");
|
||||
|
||||
final EggCatcherPlayerListener playerListener = new EggCatcherPlayerListener();
|
||||
final EggCatcherEntityListener entityListener = new EggCatcherEntityListener(
|
||||
this);
|
||||
final EggCatcherPlayerListener playerListener = new EggCatcherPlayerListener();
|
||||
final EggCatcherEntityListener entityListener = new EggCatcherEntityListener(this);
|
||||
|
||||
pm.registerEvents(playerListener, this);
|
||||
pm.registerEvents(entityListener, this);
|
||||
pm.registerEvents(playerListener, this);
|
||||
pm.registerEvents(entityListener, this);
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer()
|
||||
.getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration
|
||||
(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckUpdate() {
|
||||
try {
|
||||
@ -87,22 +81,25 @@ public class EggCatcher extends JavaPlugin {
|
||||
|
||||
NodeList nodes = document.getElementsByTagName("item");
|
||||
|
||||
String latestVersion = ((Element)nodes.item(0)).getElementsByTagName("title").item(0).getTextContent().replace("v","");
|
||||
String link = ((Element)nodes.item(0)).getElementsByTagName("link").item(0).getTextContent();
|
||||
if(!this.getDescription().getVersion().equalsIgnoreCase(latestVersion)){
|
||||
this.getLogger().info(String.format("There's a new version available (%s). Get it from %s", latestVersion, link));
|
||||
String latestVersion = ((Element) nodes.item(0)).getElementsByTagName("title").item(0).getTextContent()
|
||||
.replace("v", "");
|
||||
String link = ((Element) nodes.item(0)).getElementsByTagName("link").item(0).getTextContent();
|
||||
if (!this.getDescription().getVersion().equalsIgnoreCase(latestVersion)) {
|
||||
this.getLogger().info(String.format("There's a new version available (%s). Get it from %s",
|
||||
latestVersion, link));
|
||||
}
|
||||
|
||||
} catch (Exception e) { }
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
public void CheckConfigurationFile() {
|
||||
double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0);
|
||||
|
||||
public void CheckConfigurationFile() {
|
||||
double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0);
|
||||
if (configVersion == 1.25) {
|
||||
//
|
||||
this.saveConfig();
|
||||
}
|
||||
else if (configVersion == 1.22) {
|
||||
} else if (configVersion == 1.22) {
|
||||
this.getConfig().set("UseHealthPercentage", false);
|
||||
this.getConfig().set("HealthPercentage.Pig", 100.0);
|
||||
this.getConfig().set("HealthPercentage.Sheep", 100.0);
|
||||
@ -127,31 +124,32 @@ public class EggCatcher extends JavaPlugin {
|
||||
this.getConfig().set("HealthPercentage.Ocelot", 100.0);
|
||||
this.getConfig().set("HealthPercentage.Witch", 100.0);
|
||||
this.getConfig().set("HealthPercentage.Bat", 100.0);
|
||||
this.getConfig().set("Messages.HealthPercentageFail", "The mob has more than %s percent health left and cannot be caught!");
|
||||
this.getConfig().set("Messages.HealthPercentageFail", "The mob has more than %s percent health left and "
|
||||
+ "cannot be caught!");
|
||||
this.getConfig().set("ConfigVersion", 1.25);
|
||||
this.saveConfig();
|
||||
}else if (configVersion == 1.21) {
|
||||
this.getConfig().set("VaultTargetBankAccount", "");
|
||||
this.getConfig().set("ConfigVersion", 1.22);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.18) {
|
||||
this.getConfig().set("ConfigVersion", 1.21);
|
||||
this.getConfig().set("CatchChance.Bat", 100.0);
|
||||
this.getConfig().set("CatchChance.Witch", 100.0);
|
||||
this.getConfig().set("VaultCost.Bat", 0.0);
|
||||
this.getConfig().set("VaultCost.Witch", 0.0);
|
||||
this.getConfig().set("ItemCost.Amount.Bat", 0);
|
||||
this.getConfig().set("ItemCost.Amount.Witch", 0);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.17) {
|
||||
this.getConfig().set("ConfigVersion", 1.18);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.16) {
|
||||
this.getConfig().set("ConfigVersion", 1.17);
|
||||
this.saveConfig();
|
||||
} else {
|
||||
this.saveResource("config.yml", true);
|
||||
this.reloadConfig();
|
||||
}
|
||||
}
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.21) {
|
||||
this.getConfig().set("VaultTargetBankAccount", "");
|
||||
this.getConfig().set("ConfigVersion", 1.22);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.18) {
|
||||
this.getConfig().set("ConfigVersion", 1.21);
|
||||
this.getConfig().set("CatchChance.Bat", 100.0);
|
||||
this.getConfig().set("CatchChance.Witch", 100.0);
|
||||
this.getConfig().set("VaultCost.Bat", 0.0);
|
||||
this.getConfig().set("VaultCost.Witch", 0.0);
|
||||
this.getConfig().set("ItemCost.Amount.Bat", 0);
|
||||
this.getConfig().set("ItemCost.Amount.Witch", 0);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.17) {
|
||||
this.getConfig().set("ConfigVersion", 1.18);
|
||||
this.saveConfig();
|
||||
} else if (configVersion == 1.16) {
|
||||
this.getConfig().set("ConfigVersion", 1.17);
|
||||
this.saveConfig();
|
||||
} else {
|
||||
this.saveResource("config.yml", true);
|
||||
this.reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
@ -22,60 +22,60 @@ 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");
|
||||
|
||||
|
||||
private final EntityType entityType;
|
||||
private final Integer creatureId;
|
||||
private final String friendlyName;
|
||||
|
||||
EggType(EntityType entityType, Integer creatureId, String friendlyName){
|
||||
this.entityType = entityType;
|
||||
this.creatureId = creatureId;
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public short getCreatureId() {
|
||||
return this.creatureId.shortValue();
|
||||
}
|
||||
|
||||
public EntityType getCreatureType() {
|
||||
return this.entityType;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return this.friendlyName;
|
||||
}
|
||||
|
||||
public static EggType getEggType(Entity entity){
|
||||
for(EggType eggType : EggType.values()){
|
||||
if(!eggType.getCreatureType().getEntityClass().isInstance(entity)){
|
||||
continue;
|
||||
}
|
||||
return eggType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
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");
|
||||
|
||||
|
||||
private final EntityType entityType;
|
||||
private final Integer creatureId;
|
||||
private final String friendlyName;
|
||||
|
||||
EggType(EntityType entityType, Integer creatureId, String friendlyName) {
|
||||
this.entityType = entityType;
|
||||
this.creatureId = creatureId;
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public short getCreatureId() {
|
||||
return this.creatureId.shortValue();
|
||||
}
|
||||
|
||||
public EntityType getCreatureType() {
|
||||
return this.entityType;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return this.friendlyName;
|
||||
}
|
||||
|
||||
public static EggType getEggType(Entity entity) {
|
||||
for (EggType eggType : EggType.values()) {
|
||||
if (!eggType.getCreatureType().getEntityClass().isInstance(entity)) {
|
||||
continue;
|
||||
}
|
||||
return eggType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -8,34 +8,32 @@ import org.bukkit.event.entity.EntityEvent;
|
||||
|
||||
public class EggCaptureEvent extends EntityEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
boolean cancelled = false;
|
||||
Egg egg;
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
boolean cancelled = false;
|
||||
Egg egg;
|
||||
|
||||
public EggCaptureEvent(Entity what, Egg egg) {
|
||||
super(what);
|
||||
this.egg = egg;
|
||||
}
|
||||
public EggCaptureEvent(Entity what, Egg egg) {
|
||||
super(what);
|
||||
this.egg = egg;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
public Egg getEgg() {
|
||||
return this.egg;
|
||||
}
|
||||
public Egg getEgg() {
|
||||
return this.egg;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean isCancelled) {
|
||||
this.cancelled = isCancelled;
|
||||
}
|
||||
public void setCancelled(boolean isCancelled) {
|
||||
this.cancelled = isCancelled;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package me.shansen.EggCatcher.listeners;
|
||||
|
||||
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
||||
import me.shansen.EggCatcher.EggCatcher;
|
||||
import me.shansen.EggCatcher.EggType;
|
||||
|
||||
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.*;
|
||||
@ -35,142 +34,129 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class EggCatcherEntityListener implements Listener {
|
||||
|
||||
FileConfiguration config;
|
||||
JavaPlugin plugin;
|
||||
private final Boolean usePermissions;
|
||||
private final Boolean useCatchChance;
|
||||
private final Boolean usePermissions;
|
||||
private final Boolean useCatchChance;
|
||||
private final Boolean useHealthPercentage;
|
||||
private final Boolean looseEggOnFail;
|
||||
private final Boolean useVaultCost;
|
||||
private final Boolean useItemCost;
|
||||
private final Boolean explosionEffect;
|
||||
private final Boolean smokeEffect;
|
||||
private final Boolean nonPlayerCatching;
|
||||
private final Boolean preventCatchingBabyAnimals;
|
||||
private final Boolean preventCatchingTamableAnimals;
|
||||
private final Boolean preventCatchingShearedSheeps;
|
||||
|
||||
private final String catchChanceSuccessMessage;
|
||||
private final String catchChanceFailMessage;
|
||||
private final Boolean looseEggOnFail;
|
||||
private final Boolean useVaultCost;
|
||||
private final Boolean useItemCost;
|
||||
private final Boolean explosionEffect;
|
||||
private final Boolean smokeEffect;
|
||||
private final Boolean nonPlayerCatching;
|
||||
private final Boolean preventCatchingBabyAnimals;
|
||||
private final Boolean preventCatchingTamableAnimals;
|
||||
private final Boolean preventCatchingShearedSheeps;
|
||||
private final String catchChanceSuccessMessage;
|
||||
private final String catchChanceFailMessage;
|
||||
private final String healthPercentageFailMessage;
|
||||
|
||||
private final String vaultTargetBankAccount;
|
||||
private final String vaultTargetBankAccount;
|
||||
private final Boolean spawnChickenOnFail;
|
||||
private final Boolean spawnChickenOnSuccess;
|
||||
FileConfiguration config;
|
||||
JavaPlugin plugin;
|
||||
|
||||
private final Boolean spawnChickenOnFail;
|
||||
private final Boolean spawnChickenOnSuccess;
|
||||
|
||||
public EggCatcherEntityListener(JavaPlugin plugin) {
|
||||
this.config = plugin.getConfig();
|
||||
this.plugin = plugin;
|
||||
this.usePermissions = this.config.getBoolean("UsePermissions", true);
|
||||
this.useCatchChance = this.config.getBoolean("UseCatchChance", true);
|
||||
public EggCatcherEntityListener(JavaPlugin plugin) {
|
||||
this.config = plugin.getConfig();
|
||||
this.plugin = plugin;
|
||||
this.usePermissions = this.config.getBoolean("UsePermissions", true);
|
||||
this.useCatchChance = this.config.getBoolean("UseCatchChance", true);
|
||||
this.useHealthPercentage = this.config.getBoolean("UseHealthPercentage", false);
|
||||
this.looseEggOnFail = this.config.getBoolean("LooseEggOnFail", true);
|
||||
this.useVaultCost = this.config.getBoolean("UseVaultCost", false);
|
||||
this.useItemCost = this.config.getBoolean("UseItemCost", false);
|
||||
this.explosionEffect = this.config.getBoolean("ExplosionEffect", true);
|
||||
this.smokeEffect = this.config.getBoolean("SmokeEffect", false);
|
||||
this.nonPlayerCatching = this.config.getBoolean("NonPlayerCatching",
|
||||
true);
|
||||
this.catchChanceSuccessMessage = this.config
|
||||
.getString("Messages.CatchChanceSuccess");
|
||||
this.catchChanceFailMessage = this.config
|
||||
.getString("Messages.CatchChanceFail");
|
||||
this.looseEggOnFail = this.config.getBoolean("LooseEggOnFail", true);
|
||||
this.useVaultCost = this.config.getBoolean("UseVaultCost", false);
|
||||
this.useItemCost = this.config.getBoolean("UseItemCost", false);
|
||||
this.explosionEffect = this.config.getBoolean("ExplosionEffect", true);
|
||||
this.smokeEffect = this.config.getBoolean("SmokeEffect", false);
|
||||
this.nonPlayerCatching = this.config.getBoolean("NonPlayerCatching", true);
|
||||
this.catchChanceSuccessMessage = this.config.getString("Messages.CatchChanceSuccess");
|
||||
this.catchChanceFailMessage = this.config.getString("Messages.CatchChanceFail");
|
||||
this.healthPercentageFailMessage = this.config.getString("Messages.HealthPercentageFail");
|
||||
this.preventCatchingBabyAnimals = this.config.getBoolean(
|
||||
"PreventCatchingBabyAnimals", true);
|
||||
this.preventCatchingTamableAnimals = this.config.getBoolean(
|
||||
"PreventCatchingTamableAnimals", true);
|
||||
this.preventCatchingShearedSheeps = this.config.getBoolean(
|
||||
"PreventCatchingShearedSheeps", true);
|
||||
this.spawnChickenOnFail = this.config.getBoolean("SpawnChickenOnFail",
|
||||
true);
|
||||
this.spawnChickenOnSuccess = this.config.getBoolean(
|
||||
"SpawnChickenOnSuccess", false);
|
||||
this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", "");
|
||||
}
|
||||
this.preventCatchingBabyAnimals = this.config.getBoolean("PreventCatchingBabyAnimals", true);
|
||||
this.preventCatchingTamableAnimals = this.config.getBoolean("PreventCatchingTamableAnimals", true);
|
||||
this.preventCatchingShearedSheeps = this.config.getBoolean("PreventCatchingShearedSheeps", true);
|
||||
this.spawnChickenOnFail = this.config.getBoolean("SpawnChickenOnFail", true);
|
||||
this.spawnChickenOnSuccess = this.config.getBoolean("SpawnChickenOnSuccess", false);
|
||||
this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", "");
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
|
||||
public void onEntityHitByEgg(EntityDamageEvent event) {
|
||||
EntityDamageByEntityEvent damageEvent = null;
|
||||
Egg egg = null;
|
||||
EggType eggType = null;
|
||||
double vaultCost = 0.0;
|
||||
Entity entity = event.getEntity();
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onEntityHitByEgg(EntityDamageEvent event) {
|
||||
EntityDamageByEntityEvent damageEvent = null;
|
||||
Egg egg = null;
|
||||
EggType eggType = null;
|
||||
double vaultCost = 0.0;
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(event instanceof EntityDamageByEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
if (!(event instanceof EntityDamageByEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
damageEvent = (EntityDamageByEntityEvent) event;
|
||||
damageEvent = (EntityDamageByEntityEvent) event;
|
||||
|
||||
if (!(damageEvent.getDamager() instanceof Egg)) {
|
||||
return;
|
||||
}
|
||||
if (!(damageEvent.getDamager() instanceof Egg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
egg = (Egg) damageEvent.getDamager();
|
||||
eggType = EggType.getEggType(entity);
|
||||
egg = (Egg) damageEvent.getDamager();
|
||||
eggType = EggType.getEggType(entity);
|
||||
|
||||
if (eggType == null) {
|
||||
return;
|
||||
}
|
||||
if (eggType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.spawnChickenOnFail) {
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
if (!this.spawnChickenOnFail) {
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
|
||||
if (this.preventCatchingBabyAnimals) {
|
||||
if (entity instanceof Animals) {
|
||||
if (!((Animals) entity).isAdult()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.preventCatchingBabyAnimals) {
|
||||
if (entity instanceof Animals) {
|
||||
if (!((Animals) entity).isAdult()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.preventCatchingTamableAnimals) {
|
||||
if (entity instanceof Tameable) {
|
||||
if (((Tameable) entity).isTamed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.preventCatchingTamableAnimals) {
|
||||
if (entity instanceof Tameable) {
|
||||
if (((Tameable) entity).isTamed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.preventCatchingShearedSheeps) {
|
||||
if (entity instanceof Sheep) {
|
||||
if (((Sheep) entity).isSheared()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.preventCatchingShearedSheeps) {
|
||||
if (entity instanceof Sheep) {
|
||||
if (((Sheep) entity).isSheared()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EggCaptureEvent eggCaptureEvent = new EggCaptureEvent(entity, egg);
|
||||
this.plugin.getServer().getPluginManager().callEvent(eggCaptureEvent);
|
||||
if (eggCaptureEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
EggCaptureEvent eggCaptureEvent = new EggCaptureEvent(entity, egg);
|
||||
this.plugin.getServer().getPluginManager().callEvent(eggCaptureEvent);
|
||||
if (eggCaptureEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (egg.getShooter() instanceof Player) {
|
||||
Player player = (Player) egg.getShooter();
|
||||
if (egg.getShooter() instanceof Player) {
|
||||
Player player = (Player) egg.getShooter();
|
||||
|
||||
if (this.usePermissions) {
|
||||
if (!player.hasPermission("eggcatcher.catch."
|
||||
+ eggType.getFriendlyName().toLowerCase())) {
|
||||
player.sendMessage(config
|
||||
.getString("Messages.PermissionFail"));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
if (this.usePermissions) {
|
||||
if (!player.hasPermission("eggcatcher.catch." + eggType.getFriendlyName().toLowerCase())) {
|
||||
player.sendMessage(config.getString("Messages.PermissionFail"));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useHealthPercentage) {
|
||||
double healthPercentage = config.getDouble("HealthPercentage."
|
||||
+ eggType.getFriendlyName());
|
||||
double currentHealth = ((LivingEntity)entity).getHealth() * 100.0 / ((LivingEntity)entity).getMaxHealth();
|
||||
if(healthPercentage < currentHealth) {
|
||||
double healthPercentage = config.getDouble("HealthPercentage." + eggType.getFriendlyName());
|
||||
double currentHealth = ((LivingEntity) entity).getHealth() * 100.0 / ((LivingEntity) entity)
|
||||
.getMaxHealth();
|
||||
if (healthPercentage < currentHealth) {
|
||||
if (this.healthPercentageFailMessage.length() > 0) {
|
||||
player.sendMessage(String.format(this.healthPercentageFailMessage, healthPercentage));
|
||||
}
|
||||
@ -182,99 +168,88 @@ public class EggCatcherEntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("CatchChance."
|
||||
+ eggType.getFriendlyName());
|
||||
if (Math.random() * 100 <= catchChance) {
|
||||
if (this.catchChanceSuccessMessage.length() > 0) {
|
||||
player.sendMessage(catchChanceSuccessMessage);
|
||||
}
|
||||
} else {
|
||||
if (this.catchChanceFailMessage.length() > 0) {
|
||||
player.sendMessage(this.catchChanceFailMessage);
|
||||
}
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("CatchChance." + eggType.getFriendlyName());
|
||||
if (Math.random() * 100 <= catchChance) {
|
||||
if (this.catchChanceSuccessMessage.length() > 0) {
|
||||
player.sendMessage(catchChanceSuccessMessage);
|
||||
}
|
||||
} else {
|
||||
if (this.catchChanceFailMessage.length() > 0) {
|
||||
player.sendMessage(this.catchChanceFailMessage);
|
||||
}
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useVaultCost) {
|
||||
vaultCost = config.getDouble("VaultCost."
|
||||
+ eggType.getFriendlyName());
|
||||
if (!EggCatcher.economy.has(player.getName(), vaultCost)) {
|
||||
player.sendMessage(String.format(
|
||||
config.getString("Messages.VaultFail"), vaultCost));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
if (this.useVaultCost) {
|
||||
vaultCost = config.getDouble("VaultCost." + eggType.getFriendlyName());
|
||||
if (!EggCatcher.economy.has(player.getName(), vaultCost)) {
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultFail"), vaultCost));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
EggCatcher.economy.withdrawPlayer(player.getName(),
|
||||
vaultCost);
|
||||
|
||||
if(!this.vaultTargetBankAccount.isEmpty()) {
|
||||
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||
}
|
||||
|
||||
player.sendMessage(String.format(
|
||||
config.getString("Messages.VaultSuccess"),
|
||||
vaultCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
EggCatcher.economy.withdrawPlayer(player.getName(), vaultCost);
|
||||
|
||||
if (this.useItemCost) {
|
||||
int itemId = config.getInt("ItemCost.ItemId", 266);
|
||||
int itemAmount = config.getInt(
|
||||
"ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||
ItemStack itemStack = new ItemStack(itemId, itemAmount);
|
||||
if (player.getInventory().contains(itemId, itemAmount)) {
|
||||
player.sendMessage(String.format(
|
||||
config.getString("Messages.ItemCostSuccess"),
|
||||
String.valueOf(itemAmount)));
|
||||
player.getInventory().removeItem(itemStack);
|
||||
} else {
|
||||
player.sendMessage(String.format(
|
||||
config.getString("Messages.ItemCostFail"),
|
||||
String.valueOf(itemAmount)));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||
}
|
||||
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultSuccess"), vaultCost));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useItemCost) {
|
||||
int itemId = config.getInt("ItemCost.ItemId", 266);
|
||||
int itemAmount = config.getInt("ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||
ItemStack itemStack = new ItemStack(itemId, itemAmount);
|
||||
if (player.getInventory().contains(itemId, itemAmount)) {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostSuccess"),
|
||||
String.valueOf(itemAmount)));
|
||||
player.getInventory().removeItem(itemStack);
|
||||
} else {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostFail"),
|
||||
String.valueOf(itemAmount)));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(344, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Dispenser
|
||||
if (!this.nonPlayerCatching) {
|
||||
return;
|
||||
}
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("CatchChance."
|
||||
+ eggType.getFriendlyName());
|
||||
if (Math.random() * 100 > catchChance) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Dispenser
|
||||
if (!this.nonPlayerCatching) {
|
||||
return;
|
||||
}
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("CatchChance." + eggType.getFriendlyName());
|
||||
if (Math.random() * 100 > catchChance) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entity.remove();
|
||||
if (this.explosionEffect) {
|
||||
entity.getWorld().createExplosion(entity.getLocation(), 0);
|
||||
}
|
||||
if (this.smokeEffect) {
|
||||
entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 0);
|
||||
}
|
||||
entity.getWorld().dropItem(entity.getLocation(),
|
||||
new ItemStack(383, 1, eggType.getCreatureId()));
|
||||
entity.remove();
|
||||
if (this.explosionEffect) {
|
||||
entity.getWorld().createExplosion(entity.getLocation(), 0);
|
||||
}
|
||||
if (this.smokeEffect) {
|
||||
entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 0);
|
||||
}
|
||||
entity.getWorld().dropItem(entity.getLocation(), new ItemStack(383, 1, eggType.getCreatureId()));
|
||||
|
||||
if (!this.spawnChickenOnSuccess) {
|
||||
if (!EggCatcher.eggs.contains(egg)) {
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.spawnChickenOnSuccess) {
|
||||
if (!EggCatcher.eggs.contains(egg)) {
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package me.shansen.EggCatcher.listeners;
|
||||
|
||||
import me.shansen.EggCatcher.EggCatcher;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
|
||||
public class EggCatcherPlayerListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||
if (EggCatcher.eggs.contains(event.getEgg())) {
|
||||
event.setHatching(false);
|
||||
EggCatcher.eggs.remove(event.getEgg());
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||
if (EggCatcher.eggs.contains(event.getEgg())) {
|
||||
event.setHatching(false);
|
||||
EggCatcher.eggs.remove(event.getEgg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user