2020-01-21 16:42:42 +00:00
|
|
|
package net.seanomik.tamablefoxes;
|
|
|
|
|
2020-01-26 07:05:18 +00:00
|
|
|
import net.minecraft.server.v1_15_R1.*;
|
2020-01-26 23:57:21 +00:00
|
|
|
import net.seanomik.tamablefoxes.versions.version_1_15.command.CommandSpawnTamableFox;
|
2020-01-26 07:05:18 +00:00
|
|
|
import net.seanomik.tamablefoxes.io.LanguageConfig;
|
2020-01-21 16:42:42 +00:00
|
|
|
import org.bukkit.*;
|
|
|
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
2020-01-24 16:21:13 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
2020-01-21 16:42:42 +00:00
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Modifier;
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-26 23:57:21 +00:00
|
|
|
// @TODO:
|
|
|
|
|
2020-05-03 17:36:56 +00:00
|
|
|
/* @CHANGELOG (1.6.0-SNAPSHOT):
|
|
|
|
* Fix a bug of duplicating water/lava buckets.
|
2020-01-26 23:57:21 +00:00
|
|
|
*/
|
2020-01-24 16:21:13 +00:00
|
|
|
public final class TamableFoxes extends JavaPlugin implements Listener {
|
|
|
|
private static TamableFoxes plugin;
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-26 07:05:18 +00:00
|
|
|
private boolean versionSupported = true;
|
|
|
|
|
2020-01-21 16:42:42 +00:00
|
|
|
@Override
|
2020-01-24 16:21:13 +00:00
|
|
|
public void onLoad() {
|
2020-01-26 07:05:18 +00:00
|
|
|
plugin = this;
|
|
|
|
|
|
|
|
LanguageConfig.getConfig().saveDefault();
|
|
|
|
|
2020-01-21 16:42:42 +00:00
|
|
|
String version = Bukkit.getServer().getClass().getPackage().getName();
|
|
|
|
if (!version.equals("org.bukkit.craftbukkit.v1_15_R1")) {
|
2020-01-26 07:05:18 +00:00
|
|
|
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getUnsupportedMCVersionRegister());
|
|
|
|
versionSupported = false;
|
2020-01-21 16:42:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
try { // Replace the fox entity
|
|
|
|
Field field = EntityTypes.FOX.getClass().getDeclaredField("ba");
|
|
|
|
field.setAccessible(true);
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-02-01 19:01:23 +00:00
|
|
|
// If the field is final, then make it non final
|
|
|
|
if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
|
|
|
|
Field fieldMutable = field.getClass().getDeclaredField("modifiers");
|
|
|
|
fieldMutable.setAccessible(true);
|
|
|
|
fieldMutable.set(field, fieldMutable.getInt(field) & ~Modifier.FINAL);
|
|
|
|
fieldMutable.setAccessible(false);
|
|
|
|
}
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
field.set(EntityTypes.FOX, (EntityTypes.b<EntityFox>) (type, world) -> new EntityTamableFox(type, world));
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
field.setAccessible(false);
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-26 07:05:18 +00:00
|
|
|
getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
2020-01-24 16:21:13 +00:00
|
|
|
} catch (Exception e) {
|
2020-02-01 19:01:23 +00:00
|
|
|
//e.printStackTrace();
|
2020-01-26 07:05:18 +00:00
|
|
|
getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
2020-01-24 16:21:13 +00:00
|
|
|
}
|
2020-01-21 16:42:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-24 16:21:13 +00:00
|
|
|
public void onEnable() {
|
2020-01-26 07:05:18 +00:00
|
|
|
if (!versionSupported) {
|
|
|
|
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getUnsupportedMCVersionDisable());
|
2020-01-24 16:21:13 +00:00
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
2020-01-21 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
getServer().getPluginManager().registerEvents(this, this);
|
|
|
|
this.getCommand("spawntamablefox").setExecutor(new CommandSpawnTamableFox(this));
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
this.saveDefaultConfig();
|
|
|
|
getConfig().options().copyDefaults(true);
|
|
|
|
saveConfig();
|
2020-01-21 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2020-01-26 07:05:18 +00:00
|
|
|
getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.YELLOW + LanguageConfig.getSavingFoxMessage());
|
2020-01-21 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 07:05:18 +00:00
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
public EntityTamableFox spawnTamableFox(Location loc, EntityFox.Type type) {
|
|
|
|
EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle();
|
|
|
|
tamableFox.setFoxType(type);
|
2020-01-21 16:42:42 +00:00
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
return tamableFox;
|
2020-01-21 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-24 16:21:13 +00:00
|
|
|
public static TamableFoxes getPlugin() {
|
|
|
|
return plugin;
|
2020-01-21 16:42:42 +00:00
|
|
|
}
|
|
|
|
}
|