mirror of
https://github.com/shansen/EggCatcher.git
synced 2024-11-28 21:15:44 +01:00
Goldentoenail changes
This commit is contained in:
parent
42385e9f45
commit
f2fd18aa06
@ -1,104 +1,119 @@
|
|||||||
/*
|
|
||||||
EggCatcher
|
|
||||||
Copyright (C) 2012, 2013 me@shansen.me
|
|
||||||
|
|
||||||
This program 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
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.shansen.EggCatcher;
|
package me.shansen.EggCatcher;
|
||||||
|
|
||||||
import me.shansen.EggCatcher.listeners.EggCatcherEntityListener;
|
|
||||||
import me.shansen.EggCatcher.listeners.EggCatcherPlayerListener;
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
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 java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class EggCatcher extends JavaPlugin {
|
import me.shansen.EggCatcher.listeners.EggCatcherEntityListener;
|
||||||
|
import me.shansen.EggCatcher.listeners.EggCatcherPlayerListener;
|
||||||
|
import me.shansen.EggCatcher.mcstats.Metrics;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Egg;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class EggCatcher
|
||||||
|
extends JavaPlugin {
|
||||||
public static List<Egg> eggs = new ArrayList<Egg>();
|
public static List<Egg> eggs = new ArrayList<Egg>();
|
||||||
public static Economy economy = null;
|
//GTN removed public static Economy economy = null;
|
||||||
|
//GTN added
|
||||||
|
public final Logger logger;
|
||||||
|
public boolean econSupport;
|
||||||
|
public static Economy economy;
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
//GTN removed RegisteredServiceProvider economyProvider;
|
||||||
this.CheckConfigurationFile();
|
this.CheckConfigurationFile();
|
||||||
|
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
EggCatcherPlayerListener playerListener = new EggCatcherPlayerListener();
|
||||||
final EggCatcherPlayerListener playerListener = new EggCatcherPlayerListener();
|
EggCatcherEntityListener entityListener = new EggCatcherEntityListener(this);
|
||||||
final EggCatcherEntityListener entityListener = new EggCatcherEntityListener(this);
|
pm.registerEvents((Listener)playerListener, (Plugin)this);
|
||||||
|
pm.registerEvents((Listener)entityListener, (Plugin)this);
|
||||||
pm.registerEvents(playerListener, this);
|
//GTN removed if (this.getServer().getPluginManager().getPlugin("Vault") != null && (economyProvider = this.getServer().getServicesManager().getRegistration((Class)Economy.class)) != null) {
|
||||||
pm.registerEvents(entityListener, this);
|
//GTN removed economy = (Economy)economyProvider.getProvider();
|
||||||
|
//GTN removed }
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
//GTN added
|
||||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration
|
if (!this.setupEconomy()) {
|
||||||
(Economy.class);
|
this.logger.warning(String.format("[%s] Vault not found! Economy support disabled!", this.getDescription().getName()));
|
||||||
if (economyProvider != null) {
|
this.econSupport = false;
|
||||||
economy = economyProvider.getProvider();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.logger.info(String.format("[%s] Vault found! Economy support enabled!", this.getDescription().getName()));
|
||||||
|
}
|
||||||
|
//GTN end of addition
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics((Plugin)this);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException metrics) {
|
||||||
|
// empty catch block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckConfigurationFile() {
|
public void CheckConfigurationFile() {
|
||||||
double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0);
|
double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0);
|
||||||
if (configVersion == 2.6) {
|
if (configVersion == 2.7) {
|
||||||
|
this.saveConfig();
|
||||||
|
} else if (configVersion == 2.6) {
|
||||||
|
this.getConfig().set("CatchChance.IronGolem", (Object)100.0);
|
||||||
|
this.getConfig().set("VaultCost.IronGolem", (Object)100.0);
|
||||||
|
this.getConfig().set("ItemCost.Amount.IronGolem", (Object)5);
|
||||||
|
this.getConfig().set("HealthPercentage.IronGolem", (Object)100.0);
|
||||||
|
this.getConfig().set("ConfigVersion", (Object)2.7);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
} else if (configVersion == 2.5) {
|
} else if (configVersion == 2.5) {
|
||||||
this.getConfig().set("CatchChance.PolarBear", 100.0);
|
this.getConfig().set("CatchChance.PolarBear", (Object)100.0);
|
||||||
this.getConfig().set("VaultCost.PolarBear", 0);
|
this.getConfig().set("VaultCost.PolarBear", (Object)0);
|
||||||
this.getConfig().set("ItemCost.Amount.PolarBear", 0);
|
this.getConfig().set("ItemCost.Amount.PolarBear", (Object)0);
|
||||||
this.getConfig().set("HealthPercentage.PolarBear", 100.0);
|
this.getConfig().set("HealthPercentage.PolarBear", (Object)100.0);
|
||||||
this.getConfig().set("ConfigVersion", 2.6);
|
this.getConfig().set("ConfigVersion", (Object)2.6);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
} else if (configVersion == 2.2) {
|
} else if (configVersion == 2.2) {
|
||||||
this.getConfig().set("DeleteVillagerInventoryOnCatch", false);
|
this.getConfig().set("DeleteVillagerInventoryOnCatch", (Object)false);
|
||||||
|
this.getConfig().set("ConfigVersion", (Object)2.5);
|
||||||
this.getConfig().set("ConfigVersion", 2.5);
|
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
} else if (configVersion == 2.0) {
|
} else if (configVersion == 2.0) {
|
||||||
this.getConfig().set("CatchChance.Endermite", 100.0);
|
this.getConfig().set("CatchChance.Endermite", (Object)100.0);
|
||||||
this.getConfig().set("VaultCost.Endermite", 0);
|
this.getConfig().set("VaultCost.Endermite", (Object)0);
|
||||||
this.getConfig().set("ItemCost.Amount.Endermite", 0);
|
this.getConfig().set("ItemCost.Amount.Endermite", (Object)0);
|
||||||
this.getConfig().set("HealthPercentage.Endermite", 100.0);
|
this.getConfig().set("HealthPercentage.Endermite", (Object)100.0);
|
||||||
|
this.getConfig().set("CatchChance.Guardian", (Object)100.0);
|
||||||
this.getConfig().set("CatchChance.Guardian", 100.0);
|
this.getConfig().set("VaultCost.Guardian", (Object)0);
|
||||||
this.getConfig().set("VaultCost.Guardian", 0);
|
this.getConfig().set("ItemCost.Amount.Guardian", (Object)0);
|
||||||
this.getConfig().set("ItemCost.Amount.Guardian", 0);
|
this.getConfig().set("HealthPercentage.Guardian", (Object)100.0);
|
||||||
this.getConfig().set("HealthPercentage.Guardian", 100.0);
|
this.getConfig().set("CatchChance.Rabbit", (Object)100.0);
|
||||||
|
this.getConfig().set("VaultCost.Rabbit", (Object)0);
|
||||||
this.getConfig().set("CatchChance.Rabbit", 100.0);
|
this.getConfig().set("ItemCost.Amount.Rabbit", (Object)0);
|
||||||
this.getConfig().set("VaultCost.Rabbit", 0);
|
this.getConfig().set("HealthPercentage.Rabbit", (Object)100.0);
|
||||||
this.getConfig().set("ItemCost.Amount.Rabbit", 0);
|
this.getConfig().set("ConfigVersion", (Object)2.2);
|
||||||
this.getConfig().set("HealthPercentage.Rabbit", 100.0);
|
|
||||||
|
|
||||||
this.getConfig().set("ConfigVersion", 2.2);
|
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
} else {
|
} else {
|
||||||
this.saveResource("config.yml", true);
|
this.saveResource("config.yml", true);
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GTN added
|
||||||
|
private boolean setupEconomy() {
|
||||||
|
final RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (economyProvider != null) {
|
||||||
|
EggCatcher.economy = (Economy)economyProvider.getProvider();
|
||||||
|
}
|
||||||
|
return EggCatcher.economy != null;
|
||||||
|
}
|
||||||
|
//GTN added
|
||||||
|
public EggCatcher() {
|
||||||
|
this.logger = Logger.getLogger("Minecraft");
|
||||||
|
this.econSupport = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,3 @@
|
|||||||
/*
|
|
||||||
EggCatcher
|
|
||||||
Copyright (C) 2012, 2013 me@shansen.me
|
|
||||||
|
|
||||||
This program 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
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.shansen.EggCatcher;
|
package me.shansen.EggCatcher;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -49,15 +31,14 @@ public enum EggType {
|
|||||||
ENDERMITE(EntityType.ENDERMITE, 67, "Endermite"),
|
ENDERMITE(EntityType.ENDERMITE, 67, "Endermite"),
|
||||||
GUARDIAN(EntityType.GUARDIAN, 68, "Guardian"),
|
GUARDIAN(EntityType.GUARDIAN, 68, "Guardian"),
|
||||||
RABBIT(EntityType.RABBIT, 101, "Rabbit"),
|
RABBIT(EntityType.RABBIT, 101, "Rabbit"),
|
||||||
POLAR_BEAR(EntityType.POLAR_BEAR, 102, "PolarBear");
|
POLAR_BEAR(EntityType.POLAR_BEAR, 102, "PolarBear"),
|
||||||
|
IRON_GOLEM(EntityType.IRON_GOLEM, 99, "IronGolem");
|
||||||
|
|
||||||
|
|
||||||
private final EntityType entityType;
|
private final EntityType entityType;
|
||||||
private final Integer creatureId;
|
private final Integer creatureId;
|
||||||
private final String friendlyName;
|
private final String friendlyName;
|
||||||
|
|
||||||
EggType(EntityType entityType, Integer creatureId, String friendlyName) {
|
private EggType(EntityType entityType, Integer creatureId, String friendlyName) {
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.creatureId = creatureId;
|
this.creatureId = creatureId;
|
||||||
this.friendlyName = friendlyName;
|
this.friendlyName = friendlyName;
|
||||||
@ -77,11 +58,10 @@ public enum EggType {
|
|||||||
|
|
||||||
public static EggType getEggType(Entity entity) {
|
public static EggType getEggType(Entity entity) {
|
||||||
for (EggType eggType : EggType.values()) {
|
for (EggType eggType : EggType.values()) {
|
||||||
if (!eggType.getCreatureType().getEntityClass().isInstance(entity)) {
|
if (!eggType.getCreatureType().getEntityClass().isInstance((Object)entity)) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return eggType;
|
return eggType;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,3 @@
|
|||||||
/*
|
|
||||||
EggCatcher
|
|
||||||
Copyright (C) 2012, 2013 me@shansen.me, andre@norcode.com
|
|
||||||
|
|
||||||
This program 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
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.shansen.EggCatcher.events;
|
package me.shansen.EggCatcher.events;
|
||||||
|
|
||||||
import org.bukkit.entity.Egg;
|
import org.bukkit.entity.Egg;
|
||||||
@ -24,8 +6,9 @@ import org.bukkit.event.Cancellable;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.entity.EntityEvent;
|
import org.bukkit.event.entity.EntityEvent;
|
||||||
|
|
||||||
public class EggCaptureEvent extends EntityEvent implements Cancellable {
|
public class EggCaptureEvent
|
||||||
|
extends EntityEvent
|
||||||
|
implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
Egg egg;
|
Egg egg;
|
||||||
@ -55,3 +38,4 @@ public class EggCaptureEvent extends EntityEvent implements Cancellable {
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,32 +1,24 @@
|
|||||||
/*
|
|
||||||
EggCatcher
|
|
||||||
Copyright (C) 2012, 2013 me@shansen.me
|
|
||||||
|
|
||||||
This program 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
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.shansen.EggCatcher.listeners;
|
package me.shansen.EggCatcher.listeners;
|
||||||
|
|
||||||
import me.shansen.EggCatcher.EggCatcher;
|
import me.shansen.EggCatcher.EggCatcher;
|
||||||
import me.shansen.EggCatcher.EggType;
|
import me.shansen.EggCatcher.EggType;
|
||||||
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
||||||
|
|
||||||
import me.shansen.nbt.NbtReflection;
|
import me.shansen.nbt.NbtReflection;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Ageable;
|
||||||
|
import org.bukkit.entity.Egg;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Horse;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Pig;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Sheep;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -37,8 +29,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class EggCatcherEntityListener implements Listener {
|
public class EggCatcherEntityListener
|
||||||
|
implements Listener {
|
||||||
private final boolean usePermissions;
|
private final boolean usePermissions;
|
||||||
private final boolean useCatchChance;
|
private final boolean useCatchChance;
|
||||||
private final boolean useHealthPercentage;
|
private final boolean useHealthPercentage;
|
||||||
@ -85,220 +77,227 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false);
|
this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
/*
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Lifted jumps to return sites
|
||||||
|
*/
|
||||||
|
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
|
||||||
public void onEntityHitByEgg(EntityDamageEvent event) {
|
public void onEntityHitByEgg(EntityDamageEvent event) {
|
||||||
|
//GTN added Booleans
|
||||||
|
Boolean playerHasFunds = false;
|
||||||
|
Boolean playerHasItems = false;
|
||||||
EntityDamageByEntityEvent damageEvent = null;
|
EntityDamageByEntityEvent damageEvent = null;
|
||||||
Egg egg = null;
|
Egg egg = null;
|
||||||
EggType eggType = null;
|
EggType eggType = null;
|
||||||
double vaultCost = 0.0;
|
double vaultCost = 0.0;
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (!(event instanceof EntityDamageByEntityEvent)) {
|
if (!(event instanceof EntityDamageByEntityEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
damageEvent = (EntityDamageByEntityEvent)event;
|
||||||
damageEvent = (EntityDamageByEntityEvent) event;
|
|
||||||
|
|
||||||
if (!(damageEvent.getDamager() instanceof Egg)) {
|
if (!(damageEvent.getDamager() instanceof Egg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
egg = (Egg)damageEvent.getDamager();
|
||||||
egg = (Egg) damageEvent.getDamager();
|
|
||||||
eggType = EggType.getEggType(entity);
|
eggType = EggType.getEggType(entity);
|
||||||
|
|
||||||
if (eggType == null) {
|
if (eggType == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.spawnChickenOnFail) {
|
if (!this.spawnChickenOnFail) {
|
||||||
EggCatcher.eggs.add(egg);
|
EggCatcher.eggs.add(egg);
|
||||||
}
|
}
|
||||||
|
if (this.preventCatchingBabyAnimals && entity instanceof Ageable && !((Ageable)entity).isAdult()) {
|
||||||
if (this.preventCatchingBabyAnimals) {
|
return;
|
||||||
if (entity instanceof Ageable) {
|
|
||||||
if (!((Ageable) entity).isAdult()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (this.preventCatchingTamedAnimals && entity instanceof Tameable && ((Tameable)entity).isTamed()) {
|
||||||
if (this.preventCatchingTamedAnimals) {
|
return;
|
||||||
if (entity instanceof Tameable) {
|
|
||||||
if (((Tameable) entity).isTamed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (this.preventCatchingShearedSheeps && entity instanceof Sheep && ((Sheep)entity).isSheared()) {
|
||||||
if (this.preventCatchingShearedSheeps) {
|
return;
|
||||||
if (entity instanceof Sheep) {
|
|
||||||
if (((Sheep) entity).isSheared()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EggCaptureEvent eggCaptureEvent = new EggCaptureEvent(entity, egg);
|
EggCaptureEvent eggCaptureEvent = new EggCaptureEvent(entity, egg);
|
||||||
this.plugin.getServer().getPluginManager().callEvent(eggCaptureEvent);
|
this.plugin.getServer().getPluginManager().callEvent((Event)eggCaptureEvent);
|
||||||
if (eggCaptureEvent.isCancelled()) {
|
if (eggCaptureEvent.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (egg.getShooter() instanceof Player) {
|
if (egg.getShooter() instanceof Player) {
|
||||||
Player player = (Player) egg.getShooter();
|
double currentHealth;
|
||||||
|
double healthPercentage;
|
||||||
if (this.usePermissions) {
|
Player player = (Player)egg.getShooter();
|
||||||
if (!player.hasPermission("eggcatcher.catch." + eggType.getFriendlyName().toLowerCase())) {
|
if (this.usePermissions && !player.hasPermission("eggcatcher.catch." + eggType.getFriendlyName().toLowerCase())) {
|
||||||
player.sendMessage(config.getString("Messages.PermissionFail"));
|
player.sendMessage(this.config.getString("Messages.PermissionFail"));
|
||||||
if (!this.looseEggOnFail) {
|
if (this.looseEggOnFail) return;
|
||||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
player.getInventory().addItem(new ItemStack[]{new ItemStack(Material.EGG, 1)});
|
||||||
EggCatcher.eggs.add(egg);
|
EggCatcher.eggs.add(egg);
|
||||||
}
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (this.useHealthPercentage && (healthPercentage = this.config.getDouble("HealthPercentage." + eggType.getFriendlyName())) < (currentHealth = ((LivingEntity)entity).getHealth() * 100.0 / ((LivingEntity)entity).getMaxHealth())) {
|
||||||
if (this.useHealthPercentage) {
|
if (this.healthPercentageFailMessage.length() > 0) {
|
||||||
double healthPercentage = config.getDouble("HealthPercentage." + eggType.getFriendlyName());
|
player.sendMessage(String.format(this.healthPercentageFailMessage, healthPercentage));
|
||||||
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));
|
|
||||||
}
|
|
||||||
if (!this.looseEggOnFail) {
|
|
||||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
|
||||||
EggCatcher.eggs.add(egg);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (this.looseEggOnFail) return;
|
||||||
|
player.getInventory().addItem(new ItemStack[]{new ItemStack(Material.EGG, 1)});
|
||||||
|
EggCatcher.eggs.add(egg);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.useCatchChance) {
|
if (this.useCatchChance) {
|
||||||
double catchChance = config.getDouble("CatchChance." + eggType.getFriendlyName());
|
double catchChance = this.config.getDouble("CatchChance." + eggType.getFriendlyName());
|
||||||
if (Math.random() * 100 <= catchChance) {
|
if (Math.random() * 100.0 <= catchChance) {
|
||||||
if (this.catchChanceSuccessMessage.length() > 0) {
|
if (this.catchChanceSuccessMessage.length() > 0) {
|
||||||
player.sendMessage(catchChanceSuccessMessage);
|
player.sendMessage(this.catchChanceSuccessMessage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.catchChanceFailMessage.length() > 0) {
|
if (this.catchChanceFailMessage.length() > 0) {
|
||||||
player.sendMessage(this.catchChanceFailMessage);
|
player.sendMessage(this.catchChanceFailMessage);
|
||||||
}
|
}
|
||||||
if (!this.looseEggOnFail) {
|
if (this.looseEggOnFail) return;
|
||||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
player.getInventory().addItem(new ItemStack[]{new ItemStack(Material.EGG, 1)});
|
||||||
EggCatcher.eggs.add(egg);
|
EggCatcher.eggs.add(egg);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
boolean freeCatch = player.hasPermission("eggcatcher.free");
|
||||||
|
//GTN The structure of the plugin makes it so that
|
||||||
|
//GTN The catch cost for Vault and Item are seperate
|
||||||
|
//GTN so the charge must be either/or NOT both!
|
||||||
|
|
||||||
|
//GTN Let me restructure this as a solution!
|
||||||
|
//GTN so we have 'useVaultCost', 'useItemCost', 'freeCatch'
|
||||||
|
//GTN proposed structure
|
||||||
|
//GTN Use a Boolean of playerHasFunds
|
||||||
|
//GTN Use a Boolean of playerHasItems
|
||||||
|
//GTN process as normal but delay the PAYMENT
|
||||||
|
//GTN Use three PAYMENT methods of 'VaultOnly' or 'ItemOnly' or 'Both'
|
||||||
|
//GTN *** check if playerHasFunds
|
||||||
|
if (this.useVaultCost && !freeCatch) {
|
||||||
|
//GTN testing player.sendMessage(String.format("You have %s", EggCatcher.economy.format(EggCatcher.economy.getBalance(player))));//.getBalance(player.getName()))));
|
||||||
|
vaultCost = this.config.getDouble("VaultCost." + eggType.getFriendlyName());
|
||||||
|
//GTN was if (!EggCatcher.economy.has(player.getName(), vaultCost)) {
|
||||||
|
//GTN replaced with
|
||||||
|
if (EggCatcher.economy.getBalance(player) < vaultCost) {
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.VaultFail"), vaultCost));
|
||||||
|
if (this.looseEggOnFail) return;
|
||||||
|
player.getInventory().addItem(new ItemStack[]{new ItemStack(Material.EGG, 1)});
|
||||||
|
EggCatcher.eggs.add(egg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//GTN Move this to take payment
|
||||||
|
playerHasFunds = true;
|
||||||
|
//GTN was EggCatcher.economy.withdrawPlayer(player.getName(), vaultCost);
|
||||||
|
//GTN replaced with
|
||||||
|
//EggCatcher.economy.withdrawPlayer(player, vaultCost);
|
||||||
|
//if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||||
|
// EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||||
|
//}
|
||||||
|
//player.sendMessage(String.format(this.config.getString("Messages.VaultSuccess"), vaultCost));
|
||||||
|
}
|
||||||
|
//GTN *** check if playerHasItems as MATERIAL
|
||||||
|
if (this.useItemCost && !freeCatch) {
|
||||||
|
//GTN Replaced static value of 'Gold_Ingot' (266) with configured ItemId.MATERIAL
|
||||||
|
//GTN was int itemId = this.config.getInt("ItemCost.ItemId", 266);
|
||||||
|
//GTN replaced with
|
||||||
|
|
||||||
|
String itemId = this.config.getString("ItemCost.ItemId");
|
||||||
|
int itemData = this.config.getInt("ItemCost.ItemData", 0);
|
||||||
|
int itemAmount = this.config.getInt("ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||||
|
|
||||||
|
//GTN was ItemStack itemStack = new ItemStack(itemId, itemAmount, (short)itemData);
|
||||||
|
//GTN replaced with
|
||||||
|
ItemStack itemStack = new ItemStack(Material.getMaterial(itemId), itemAmount, (short)itemData);
|
||||||
|
//GTN the problem is that Vault has already taken money but what happens if there are not enough items?
|
||||||
|
if (!player.getInventory().containsAtLeast(itemStack, itemStack.getAmount())) {
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.ItemCostFail"), String.valueOf(itemAmount)));
|
||||||
|
if (this.looseEggOnFail) return;
|
||||||
|
player.getInventory().addItem(new ItemStack[]{new ItemStack(Material.EGG, 1)});
|
||||||
|
EggCatcher.eggs.add(egg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//GTN Move this to take payment
|
||||||
|
playerHasItems = true;
|
||||||
|
//player.sendMessage(String.format(this.config.getString("Messages.ItemCostSuccess"), String.valueOf(itemAmount)));
|
||||||
|
//player.getInventory().removeItem(new ItemStack[]{itemStack});
|
||||||
|
}
|
||||||
|
//GTN **** TAKE PAYMENT HERE
|
||||||
|
if (!freeCatch) {
|
||||||
|
//vaultCost only
|
||||||
|
if (this.useVaultCost && playerHasFunds && !this.useItemCost) {
|
||||||
|
EggCatcher.economy.withdrawPlayer(player, vaultCost);
|
||||||
|
if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||||
|
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||||
|
}
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.VaultSuccess"), vaultCost));
|
||||||
|
}
|
||||||
|
//itemCost only
|
||||||
|
if (this.useItemCost && playerHasItems && !this.useVaultCost) {
|
||||||
|
String itemId = this.config.getString("ItemCost.ItemId");
|
||||||
|
int itemData = this.config.getInt("ItemCost.ItemData", 0);
|
||||||
|
int itemAmount = this.config.getInt("ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||||
|
ItemStack itemStack = new ItemStack(Material.getMaterial(itemId), itemAmount, (short)itemData);
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.ItemCostSuccess"), String.valueOf(itemAmount)));
|
||||||
|
player.getInventory().removeItem(new ItemStack[]{itemStack});
|
||||||
|
}
|
||||||
|
//Both vaultCost and itemCost
|
||||||
|
if (this.useVaultCost && playerHasFunds && this.useItemCost && playerHasItems) {
|
||||||
|
EggCatcher.economy.withdrawPlayer(player, vaultCost);
|
||||||
|
if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||||
|
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||||
|
}
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.VaultSuccess"), vaultCost));
|
||||||
|
String itemId = this.config.getString("ItemCost.ItemId");
|
||||||
|
int itemData = this.config.getInt("ItemCost.ItemData", 0);
|
||||||
|
int itemAmount = this.config.getInt("ItemCost.Amount." + eggType.getFriendlyName(), 0);
|
||||||
|
ItemStack itemStack = new ItemStack(Material.getMaterial(itemId), itemAmount, (short)itemData);
|
||||||
|
player.sendMessage(String.format(this.config.getString("Messages.ItemCostSuccess"), String.valueOf(itemAmount)));
|
||||||
|
player.getInventory().removeItem(new ItemStack[]{itemStack});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean freeCatch = player.hasPermission("eggcatcher.free");
|
//GTN *** END OF TAKE PAYMENT
|
||||||
|
|
||||||
if (this.useVaultCost && !freeCatch) {
|
|
||||||
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(Material.EGG, 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.useItemCost && !freeCatch) {
|
|
||||||
int itemId = config.getInt("ItemCost.ItemId", 266);
|
|
||||||
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);
|
|
||||||
if (player.getInventory().containsAtLeast(itemStack, itemStack.getAmount())) {
|
|
||||||
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(Material.EGG, 1));
|
|
||||||
EggCatcher.eggs.add(egg);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Dispenser
|
|
||||||
if (!this.nonPlayerCatching) {
|
if (!this.nonPlayerCatching) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.useCatchChance) {
|
if (this.useCatchChance) {
|
||||||
double catchChance = config.getDouble("CatchChance." + eggType.getFriendlyName());
|
double catchChance = this.config.getDouble("CatchChance." + eggType.getFriendlyName());
|
||||||
if (Math.random() * 100 > catchChance) {
|
if (Math.random() * 100.0 > catchChance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.remove();
|
entity.remove();
|
||||||
if (this.explosionEffect) {
|
if (this.explosionEffect) {
|
||||||
entity.getWorld().createExplosion(entity.getLocation(), 0);
|
entity.getWorld().createExplosion(entity.getLocation(), 0.0f);
|
||||||
}
|
}
|
||||||
if (this.smokeEffect) {
|
if (this.smokeEffect) {
|
||||||
entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 0);
|
entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack eggStack = new ItemStack(Material.MONSTER_EGG, 1, eggType.getCreatureId());
|
ItemStack eggStack = new ItemStack(Material.MONSTER_EGG, 1, eggType.getCreatureId());
|
||||||
|
//GTN was eggStack = NbtReflection.setNewEntityTag(eggStack, entity.getType().name());
|
||||||
|
//GTN replaced with
|
||||||
eggStack = NbtReflection.setNewEntityTag(eggStack, entity.getType().getName());
|
eggStack = NbtReflection.setNewEntityTag(eggStack, entity.getType().getName());
|
||||||
|
String customName = ((LivingEntity)entity).getCustomName();
|
||||||
String customName = ((LivingEntity) entity).getCustomName();
|
|
||||||
|
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
// Entity had custom name
|
|
||||||
ItemMeta meta = eggStack.getItemMeta();
|
ItemMeta meta = eggStack.getItemMeta();
|
||||||
meta.setDisplayName(customName);
|
meta.setDisplayName(customName);
|
||||||
eggStack.setItemMeta(meta);
|
eggStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
if (entity instanceof Pig && ((Pig)entity).hasSaddle()) {
|
||||||
if(entity instanceof Pig) {
|
entity.getWorld().dropItem(entity.getLocation(), new ItemStack(Material.SADDLE, 1));
|
||||||
if(((Pig)entity).hasSaddle()) {
|
}
|
||||||
entity.getWorld().dropItem(entity.getLocation(), new ItemStack(Material.SADDLE, 1));
|
if (entity instanceof Horse && ((Horse)entity).isCarryingChest()) {
|
||||||
|
entity.getWorld().dropItemNaturally(entity.getLocation(), new ItemStack(Material.CHEST));
|
||||||
|
}
|
||||||
|
if (entity instanceof Villager && !this.deleteVillagerInventoryOnCatch || !(entity instanceof Villager) && entity instanceof InventoryHolder) {
|
||||||
|
ItemStack[] items;
|
||||||
|
for (ItemStack itemStack : items = ((InventoryHolder)entity).getInventory().getContents()) {
|
||||||
|
if (itemStack == null) continue;
|
||||||
|
entity.getWorld().dropItemNaturally(entity.getLocation(), itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entity instanceof Horse) {
|
|
||||||
if(((Horse) entity).isCarryingChest()){
|
|
||||||
entity.getWorld().dropItemNaturally(entity.getLocation(), new ItemStack(Material.CHEST));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if((entity instanceof Villager && !this.deleteVillagerInventoryOnCatch) ||
|
|
||||||
(!(entity instanceof Villager) && entity instanceof InventoryHolder)) {
|
|
||||||
|
|
||||||
ItemStack[] items = ((InventoryHolder) entity).getInventory().getContents();
|
|
||||||
|
|
||||||
for(ItemStack itemStack : items) {
|
|
||||||
if(itemStack!=null){
|
|
||||||
entity.getWorld().dropItemNaturally(entity.getLocation(), itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.getWorld().dropItem(entity.getLocation(), eggStack);
|
entity.getWorld().dropItem(entity.getLocation(), eggStack);
|
||||||
|
if (this.spawnChickenOnSuccess) return;
|
||||||
if (!this.spawnChickenOnSuccess) {
|
if (EggCatcher.eggs.contains((Object)egg)) return;
|
||||||
if (!EggCatcher.eggs.contains(egg)) {
|
EggCatcher.eggs.add(egg);
|
||||||
EggCatcher.eggs.add(egg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,34 +1,56 @@
|
|||||||
/*
|
|
||||||
EggCatcher
|
|
||||||
Copyright (C) 2012, 2013 me@shansen.me
|
|
||||||
|
|
||||||
This program 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
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.shansen.EggCatcher.listeners;
|
package me.shansen.EggCatcher.listeners;
|
||||||
|
|
||||||
import me.shansen.EggCatcher.EggCatcher;
|
import me.shansen.EggCatcher.EggCatcher;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class EggCatcherPlayerListener implements Listener {
|
public class EggCatcherPlayerListener
|
||||||
|
implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||||
if (EggCatcher.eggs.contains(event.getEgg())) {
|
if (EggCatcher.eggs.contains((Object)event.getEgg())) {
|
||||||
event.setHatching(false);
|
event.setHatching(false);
|
||||||
EggCatcher.eggs.remove(event.getEgg());
|
EggCatcher.eggs.remove((Object)event.getEgg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GTN SpawnMobFromEgg Event
|
||||||
|
@EventHandler
|
||||||
|
public void spawnMobFromEgg(PlayerInteractEvent event) {
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.getInventory().getItemInMainHand().getType() == Material.MONSTER_EGG) {
|
||||||
|
ItemStack spawnEggItem = player.getInventory().getItemInMainHand();
|
||||||
|
//GTN remove unneeded Entity entity = null;
|
||||||
|
EntityType spawnEggEntity = EggNBT.getSpawnEggEntityType(spawnEggItem);
|
||||||
|
//GTN debug player.sendMessage("EggType EntityType - " + EggNBT.getSpawnEggEntityType(eggItem));
|
||||||
|
//GTN rewrite if (spawnEggEntity.toString() == "IRON_GOLEM") {
|
||||||
|
if (!(spawnEggEntity == null)) {
|
||||||
|
//GTN rewrite Location loc = ((PlayerInteractEvent)event).getClickedBlock().getRelative(((PlayerInteractEvent)event).getBlockFace()).getLocation();
|
||||||
|
Location loc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
|
||||||
|
//GTN remove unneeded entity = player.getWorld().spawnEntity(loc, EntityType.IRON_GOLEM);
|
||||||
|
//GTN rewrite player.getWorld().spawnEntity(loc, EntityType.IRON_GOLEM);
|
||||||
|
player.getWorld().spawnEntity(loc, spawnEggEntity);
|
||||||
|
event.setCancelled(true);
|
||||||
|
int spawnEggAmount = spawnEggItem.getAmount();
|
||||||
|
if (spawnEggAmount == 1) {
|
||||||
|
player.getInventory().setItemInMainHand(null);
|
||||||
|
} else if (spawnEggAmount > 1) {
|
||||||
|
spawnEggItem.setAmount(spawnEggAmount - 1);
|
||||||
|
player.getInventory().setItemInMainHand(spawnEggItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
src/main/java/me/shansen/EggCatcher/listeners/EggNBT.java
Normal file
60
src/main/java/me/shansen/EggCatcher/listeners/EggNBT.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package me.shansen.EggCatcher.listeners;
|
||||||
|
|
||||||
|
import me.shansen.EggCatcher.EggType;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTBase;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Phillip from Mobcatcher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EggNBT {
|
||||||
|
public static EntityType getSpawnEggEntityType(ItemStack item) {
|
||||||
|
net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack)item);
|
||||||
|
NBTTagCompound tag = stack.getTag().getCompound("EntityTag");
|
||||||
|
String entityString = tag.getString("id");
|
||||||
|
char[] chars = entityString.toCharArray();
|
||||||
|
int i = 0;
|
||||||
|
while (i <= chars.length - 1) {
|
||||||
|
if (Character.isUpperCase(chars[i]) && i != 0) {
|
||||||
|
entityString = new StringBuilder(entityString).insert(i, "_").toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
entityString = entityString.toUpperCase();
|
||||||
|
if (entityString.equalsIgnoreCase("OZELOT")) {
|
||||||
|
entityString = "OCELOT";
|
||||||
|
} else if (entityString.equalsIgnoreCase("LAVA_SLIME")) {
|
||||||
|
entityString = "MAGMA_CUBE";
|
||||||
|
} else if (entityString.equalsIgnoreCase("ENTITY_HORSE")) {
|
||||||
|
entityString = "HORSE";
|
||||||
|
} else if (entityString.equalsIgnoreCase("VILLAGER_GOLEM")) {
|
||||||
|
entityString = "IRON_GOLEM";
|
||||||
|
}
|
||||||
|
EntityType type = EntityType.valueOf((String)entityString);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack setSpawnEggEntityType(ItemStack item, EggType eggMob) {
|
||||||
|
ItemStack newItem = new ItemStack(Material.MONSTER_EGG, 1);
|
||||||
|
net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack)newItem);
|
||||||
|
NBTTagCompound tagCompound = stack.getTag();
|
||||||
|
if (tagCompound == null) {
|
||||||
|
tagCompound = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound id = new NBTTagCompound();
|
||||||
|
id.setString("id", eggMob.getCreatureType().getName());
|
||||||
|
tagCompound.set("EntityTag", (NBTBase)id);
|
||||||
|
stack.setTag(tagCompound);
|
||||||
|
ItemStack bukkitStack = CraftItemStack.asBukkitCopy((net.minecraft.server.v1_10_R1.ItemStack)stack);
|
||||||
|
bukkitStack.setDurability(item.getDurability());
|
||||||
|
return bukkitStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
507
src/main/java/me/shansen/EggCatcher/mcstats/Metrics.java
Normal file
507
src/main/java/me/shansen/EggCatcher/mcstats/Metrics.java
Normal file
@ -0,0 +1,507 @@
|
|||||||
|
/*
|
||||||
|
* Decompiled with CFR 0_115.
|
||||||
|
*
|
||||||
|
* Could not load the following classes:
|
||||||
|
* org.bukkit.Bukkit
|
||||||
|
* org.bukkit.Server
|
||||||
|
* org.bukkit.configuration.InvalidConfigurationException
|
||||||
|
* org.bukkit.configuration.file.YamlConfiguration
|
||||||
|
* org.bukkit.configuration.file.YamlConfigurationOptions
|
||||||
|
* org.bukkit.entity.Player
|
||||||
|
* org.bukkit.plugin.Plugin
|
||||||
|
* org.bukkit.plugin.PluginDescriptionFile
|
||||||
|
* org.bukkit.scheduler.BukkitScheduler
|
||||||
|
* org.bukkit.scheduler.BukkitTask
|
||||||
|
*/
|
||||||
|
package me.shansen.EggCatcher.mcstats;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfigurationOptions;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
public class Metrics {
|
||||||
|
private static final int REVISION = 7;
|
||||||
|
private static final String BASE_URL = "http://report.mcstats.org";
|
||||||
|
private static final String REPORT_URL = "/plugin/%s";
|
||||||
|
private static final int PING_INTERVAL = 15;
|
||||||
|
private final Plugin plugin;
|
||||||
|
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet());
|
||||||
|
private final YamlConfiguration configuration;
|
||||||
|
private final File configurationFile;
|
||||||
|
private final String guid;
|
||||||
|
private final boolean debug;
|
||||||
|
private final Object optOutLock = new Object();
|
||||||
|
private volatile BukkitTask task = null;
|
||||||
|
|
||||||
|
public Metrics(Plugin plugin) throws IOException {
|
||||||
|
if (plugin == null) {
|
||||||
|
throw new IllegalArgumentException("Plugin cannot be null");
|
||||||
|
}
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.configurationFile = this.getConfigFile();
|
||||||
|
this.configuration = YamlConfiguration.loadConfiguration((File)this.configurationFile);
|
||||||
|
this.configuration.addDefault("opt-out", (Object)false);
|
||||||
|
this.configuration.addDefault("guid", (Object)UUID.randomUUID().toString());
|
||||||
|
this.configuration.addDefault("debug", (Object)false);
|
||||||
|
if (this.configuration.get("guid", (Object)null) == null) {
|
||||||
|
this.configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||||
|
this.configuration.save(this.configurationFile);
|
||||||
|
}
|
||||||
|
this.guid = this.configuration.getString("guid");
|
||||||
|
this.debug = this.configuration.getBoolean("debug", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Graph createGraph(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("Graph name cannot be null");
|
||||||
|
}
|
||||||
|
Graph graph = new Graph(name);
|
||||||
|
this.graphs.add(graph);
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGraph(Graph graph) {
|
||||||
|
if (graph == null) {
|
||||||
|
throw new IllegalArgumentException("Graph cannot be null");
|
||||||
|
}
|
||||||
|
this.graphs.add(graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public boolean start() {
|
||||||
|
Object object = this.optOutLock;
|
||||||
|
synchronized (object) {
|
||||||
|
if (this.isOptOut()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.task != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable(){
|
||||||
|
private boolean firstPost;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void run() {
|
||||||
|
block7 : {
|
||||||
|
try {
|
||||||
|
Object object = Metrics.this.optOutLock;
|
||||||
|
synchronized (object) {
|
||||||
|
if (Metrics.this.isOptOut() && Metrics.this.task != null) {
|
||||||
|
Metrics.this.task.cancel();
|
||||||
|
Metrics.this.task = null;
|
||||||
|
for (Graph graph : Metrics.this.graphs) {
|
||||||
|
graph.onOptOut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Metrics.this.postPlugin(!this.firstPost);
|
||||||
|
this.firstPost = false;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
if (!Metrics.this.debug) break block7;
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 18000);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public boolean isOptOut() {
|
||||||
|
Object object = this.optOutLock;
|
||||||
|
synchronized (object) {
|
||||||
|
try {
|
||||||
|
this.configuration.load(this.getConfigFile());
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
if (this.debug) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (InvalidConfigurationException ex) {
|
||||||
|
if (this.debug) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return this.configuration.getBoolean("opt-out", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void enable() throws IOException {
|
||||||
|
Object object = this.optOutLock;
|
||||||
|
synchronized (object) {
|
||||||
|
if (this.isOptOut()) {
|
||||||
|
this.configuration.set("opt-out", (Object)false);
|
||||||
|
this.configuration.save(this.configurationFile);
|
||||||
|
}
|
||||||
|
if (this.task == null) {
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void disable() throws IOException {
|
||||||
|
Object object = this.optOutLock;
|
||||||
|
synchronized (object) {
|
||||||
|
if (!this.isOptOut()) {
|
||||||
|
this.configuration.set("opt-out", (Object)true);
|
||||||
|
this.configuration.save(this.configurationFile);
|
||||||
|
}
|
||||||
|
if (this.task != null) {
|
||||||
|
this.task.cancel();
|
||||||
|
this.task = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getConfigFile() {
|
||||||
|
File pluginsFolder = this.plugin.getDataFolder().getParentFile();
|
||||||
|
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getOnlinePlayers() {
|
||||||
|
try {
|
||||||
|
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers", new Class[0]);
|
||||||
|
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
|
||||||
|
return ((Collection)onlinePlayerMethod.invoke((Object)Bukkit.getServer(), new Object[0])).size();
|
||||||
|
}
|
||||||
|
return ((Player[])onlinePlayerMethod.invoke((Object)Bukkit.getServer(), new Object[0])).length;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
if (this.debug) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
private void postPlugin(boolean isPing) throws IOException {
|
||||||
|
PluginDescriptionFile description = this.plugin.getDescription();
|
||||||
|
String pluginName = description.getName();
|
||||||
|
boolean onlineMode = Bukkit.getServer().getOnlineMode();
|
||||||
|
String pluginVersion = description.getVersion();
|
||||||
|
String serverVersion = Bukkit.getVersion();
|
||||||
|
int playersOnline = this.getOnlinePlayers();
|
||||||
|
StringBuilder json = new StringBuilder(1024);
|
||||||
|
json.append('{');
|
||||||
|
Metrics.appendJSONPair(json, "guid", this.guid);
|
||||||
|
Metrics.appendJSONPair(json, "plugin_version", pluginVersion);
|
||||||
|
Metrics.appendJSONPair(json, "server_version", serverVersion);
|
||||||
|
Metrics.appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||||
|
String osname = System.getProperty("os.name");
|
||||||
|
String osarch = System.getProperty("os.arch");
|
||||||
|
String osversion = System.getProperty("os.version");
|
||||||
|
String java_version = System.getProperty("java.version");
|
||||||
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||||
|
if (osarch.equals("amd64")) {
|
||||||
|
osarch = "x86_64";
|
||||||
|
}
|
||||||
|
Metrics.appendJSONPair(json, "osname", osname);
|
||||||
|
Metrics.appendJSONPair(json, "osarch", osarch);
|
||||||
|
Metrics.appendJSONPair(json, "osversion", osversion);
|
||||||
|
Metrics.appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||||
|
Metrics.appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||||
|
Metrics.appendJSONPair(json, "java_version", java_version);
|
||||||
|
if (isPing) {
|
||||||
|
Metrics.appendJSONPair(json, "ping", "1");
|
||||||
|
}
|
||||||
|
if (this.graphs.size() > 0) {
|
||||||
|
Set<Graph> set = this.graphs;
|
||||||
|
synchronized (set) {
|
||||||
|
json.append(',');
|
||||||
|
json.append('\"');
|
||||||
|
json.append("graphs");
|
||||||
|
json.append('\"');
|
||||||
|
json.append(':');
|
||||||
|
json.append('{');
|
||||||
|
boolean firstGraph = true;
|
||||||
|
for (Graph graph : this.graphs) {
|
||||||
|
StringBuilder graphJson = new StringBuilder();
|
||||||
|
graphJson.append('{');
|
||||||
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
|
Metrics.appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||||
|
}
|
||||||
|
graphJson.append('}');
|
||||||
|
if (!firstGraph) {
|
||||||
|
json.append(',');
|
||||||
|
}
|
||||||
|
json.append(Metrics.escapeJSON(graph.getName()));
|
||||||
|
json.append(':');
|
||||||
|
json.append(graphJson);
|
||||||
|
firstGraph = false;
|
||||||
|
}
|
||||||
|
json.append('}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.append('}');
|
||||||
|
URL url = new URL("http://report.mcstats.org" + String.format("/plugin/%s", Metrics.urlEncode(pluginName)));
|
||||||
|
URLConnection connection = this.isMineshafterPresent() ? url.openConnection(Proxy.NO_PROXY) : url.openConnection();
|
||||||
|
byte[] uncompressed = json.toString().getBytes();
|
||||||
|
byte[] compressed = Metrics.gzip(json.toString());
|
||||||
|
connection.addRequestProperty("User-Agent", "MCStats/7");
|
||||||
|
connection.addRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||||
|
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
||||||
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
|
connection.addRequestProperty("Connection", "close");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
if (this.debug) {
|
||||||
|
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||||
|
}
|
||||||
|
OutputStream os = connection.getOutputStream();
|
||||||
|
os.write(compressed);
|
||||||
|
os.flush();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String response = reader.readLine();
|
||||||
|
os.close();
|
||||||
|
reader.close();
|
||||||
|
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||||
|
if (response == null) {
|
||||||
|
response = "null";
|
||||||
|
} else if (response.startsWith("7")) {
|
||||||
|
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||||
|
}
|
||||||
|
throw new IOException(response);
|
||||||
|
}
|
||||||
|
if (response.equals("1") || response.contains("This is your first update this hour")) {
|
||||||
|
Set<Graph> set = this.graphs;
|
||||||
|
synchronized (set) {
|
||||||
|
for (Graph graph : this.graphs) {
|
||||||
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
|
plotter.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static byte[] gzip(String input) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
GZIPOutputStream gzos = null;
|
||||||
|
try {
|
||||||
|
gzos = new GZIPOutputStream(baos);
|
||||||
|
gzos.write(input.getBytes("UTF-8"));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (gzos != null) {
|
||||||
|
try {
|
||||||
|
gzos.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isMineshafterPresent() {
|
||||||
|
try {
|
||||||
|
Class.forName("mineshafter.MineServer");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||||
|
boolean isValueNumeric = false;
|
||||||
|
try {
|
||||||
|
if (value.equals("0") || !value.endsWith("0")) {
|
||||||
|
Double.parseDouble(value);
|
||||||
|
isValueNumeric = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
isValueNumeric = false;
|
||||||
|
}
|
||||||
|
if (json.charAt(json.length() - 1) != '{') {
|
||||||
|
json.append(',');
|
||||||
|
}
|
||||||
|
json.append(Metrics.escapeJSON(key));
|
||||||
|
json.append(':');
|
||||||
|
if (isValueNumeric) {
|
||||||
|
json.append(value);
|
||||||
|
} else {
|
||||||
|
json.append(Metrics.escapeJSON(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escapeJSON(String text) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append('\"');
|
||||||
|
block7 : for (int index = 0; index < text.length(); ++index) {
|
||||||
|
char chr = text.charAt(index);
|
||||||
|
switch (chr) {
|
||||||
|
case '\"':
|
||||||
|
case '\\': {
|
||||||
|
builder.append('\\');
|
||||||
|
builder.append(chr);
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
case '\b': {
|
||||||
|
builder.append("\\b");
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
case '\t': {
|
||||||
|
builder.append("\\t");
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
case '\n': {
|
||||||
|
builder.append("\\n");
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
case '\r': {
|
||||||
|
builder.append("\\r");
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
if (chr < ' ') {
|
||||||
|
String t = "000" + Integer.toHexString(chr);
|
||||||
|
builder.append("\\u" + t.substring(t.length() - 4));
|
||||||
|
continue block7;
|
||||||
|
}
|
||||||
|
builder.append(chr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.append('\"');
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
||||||
|
return URLEncoder.encode(text, "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Plotter {
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public Plotter() {
|
||||||
|
this("Default");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plotter(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract int getValue();
|
||||||
|
|
||||||
|
public String getColumnName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return this.getColumnName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if (!(object instanceof Plotter)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Plotter plotter = (Plotter)object;
|
||||||
|
return plotter.name.equals(this.name) && plotter.getValue() == this.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
|
||||||
|
*/
|
||||||
|
public static class Graph {
|
||||||
|
private final String name;
|
||||||
|
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||||
|
|
||||||
|
private Graph(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlotter(Plotter plotter) {
|
||||||
|
this.plotters.add(plotter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlotter(Plotter plotter) {
|
||||||
|
this.plotters.remove(plotter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Plotter> getPlotters() {
|
||||||
|
return Collections.unmodifiableSet(this.plotters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return this.name.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if (!(object instanceof Graph)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Graph graph = (Graph)object;
|
||||||
|
return graph.name.equals(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onOptOut() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,33 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Decompiled with CFR 0_115.
|
||||||
|
*
|
||||||
|
* Could not load the following classes:
|
||||||
|
* org.bukkit.Bukkit
|
||||||
|
* org.bukkit.inventory.ItemStack
|
||||||
|
*/
|
||||||
package me.shansen.nbt;
|
package me.shansen.nbt;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class NbtReflection {
|
public class NbtReflection {
|
||||||
|
|
||||||
public static ItemStack setNewEntityTag(ItemStack itemStack, String entityType) {
|
public static ItemStack setNewEntityTag(ItemStack itemStack, String entityType) {
|
||||||
try {
|
try {
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
if(version.contains("1_7") || version.contains("1_8")) {
|
if (version.contains("1_7") || version.contains("1_8")) {
|
||||||
// Legacy support. Can be cleaned up later.
|
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
Class craftItemStack = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
Class craftItemStack = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
||||||
Object nmsItemStack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(craftItemStack, itemStack);
|
Object nmsItemStack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(craftItemStack, new Object[]{itemStack});
|
||||||
Object rootTag = Class.forName("net.minecraft.server." + version + ".NBTTagCompound").newInstance();
|
Object rootTag = Class.forName("net.minecraft.server." + version + ".NBTTagCompound").newInstance();
|
||||||
Object nbtEntityTag = 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", entityType);
|
nbtEntityTag.getClass().getMethod("setString", String.class, String.class).invoke(nbtEntityTag, "id", entityType);
|
||||||
rootTag.getClass().getMethod("set", String.class, rootTag.getClass().getSuperclass())
|
rootTag.getClass().getMethod("set", String.class, rootTag.getClass().getSuperclass()).invoke(rootTag, "EntityTag", nbtEntityTag);
|
||||||
.invoke(rootTag, "EntityTag", nbtEntityTag);
|
|
||||||
|
|
||||||
nmsItemStack.getClass().getMethod("setTag", rootTag.getClass()).invoke(nmsItemStack, rootTag);
|
nmsItemStack.getClass().getMethod("setTag", rootTag.getClass()).invoke(nmsItemStack, rootTag);
|
||||||
return (ItemStack) craftItemStack.getMethod("asBukkitCopy", nmsItemStack.getClass())
|
return (ItemStack)craftItemStack.getMethod("asBukkitCopy", nmsItemStack.getClass()).invoke(craftItemStack, nmsItemStack);
|
||||||
.invoke(craftItemStack, nmsItemStack);
|
}
|
||||||
} catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user