Files
AnuraCore/src/de/anura/core/Setup.java

321 lines
18 KiB
Java

package de.anura.core;
import de.anura.core.API.Core;
import de.anura.core.API.Errors;
import de.anura.core.API.Inventories;
import de.anura.core.API.Level;
import de.anura.core.API.Tools;
import static de.anura.core.AnuraCore.sql;
import de.anura.core.commands.*;
import de.anura.core.events.*;
import java.sql.ResultSet;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.material.Stairs;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.util.Vector;
public class Setup {
public static void setupConfig() {
FileConfiguration c = Core.getMainClass().getConfig();
c.addDefault("no-damage", false);
c.addDefault("no-void-death", false);
c.addDefault("no-change-blocks", false);
c.addDefault("is-main-lobby", false);
c.addDefault("no-hunger", false);
c.addDefault("no-rain", false);
c.addDefault("enable-leaves-decay", true);
c.addDefault("server-name", "none");
c.addDefault("allow-stairs-sit", false);
c.addDefault("disable-mushroom-spread", false);
c.addDefault("on-join-to-spawn", false);
c.addDefault("golf", false);
c.addDefault("realtime-day", false);
c.addDefault("no-snow-melt", false);
c.addDefault("spawn.world", "none");
c.addDefault("spawn.X", 0);
c.addDefault("spawn.Y", 0);
c.addDefault("spawn.Z", 0);
c.addDefault("spawn.yaw", 0d);
c.addDefault("spawn.pitch", 0d);
c.addDefault("enable-votifier", false);
c.options().copyDefaults(true);
c.options().header("Config File of the Anura Core-Plugin:");
}
public static void setupEvents() {
new PlayerJoin(Core.getMainClass());
new PlayerMove(Core.getMainClass());
new PlayerInteract(Core.getMainClass());
new BlockBreak(Core.getMainClass());
new BlockPlace(Core.getMainClass());
new PlayerQuit(Core.getMainClass());
new PlayerKick(Core.getMainClass());
new PlayerChat(Core.getMainClass());
new EntityDamage(Core.getMainClass());
new WeatherChange(Core.getMainClass());
new CmdPreprocess(Core.getMainClass());
new HangingEBreak(Core.getMainClass());
new FoodChange(Core.getMainClass());
new LeavesDecay(Core.getMainClass());
new EntityDamageByE(Core.getMainClass());
new PlayerInteractE(Core.getMainClass());
new SignChange(Core.getMainClass());
new PlayerTeleport(Core.getMainClass());
new InvClick(Core.getMainClass());
new BlockSpread(Core.getMainClass());
new DropItem(Core.getMainClass());
new EntityChangeBlock(Core.getMainClass());
new BlockFade(Core.getMainClass());
new VillagerEvents(Core.getMainClass());
}
public static void setupClasses() {
try {
Core.getMainClass().lang = new LanguageSupport();
new Inventories(Core.getMainClass());
setupInventories();
Core.getMainClass().perms = new Permissions(Core.getMainClass());
Core.getMainClass().tools = new Tools();
Core.getMainClass().pots = new FlowerPots();
Core.getMainClass().signs = new Signs();
Core.getMainClass().level = new Level();
RealTime.setup();
ResultSet rs = sql.querySelect("SELECT id, X, Y, Z, world, type, waitTime FROM corePots");
while (rs.next()) {
World w = Bukkit.getWorld(rs.getString("world"));
if (w == null) {
continue;
}
Location l = new Location(w, rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
Core.getMainClass().flowerPots.put(rs.getInt("id"), l);
if (rs.getBoolean("type")) {
Core.getMainClass().flowerPotsWait.put(rs.getInt("id"), rs.getInt("waitTime"));
}
l.getBlock().setType(Material.BROWN_MUSHROOM);
}
Core.getMainClass().features = new Features();
Core.getMainClass().features.updateFeaturesAll();
} catch (Throwable e) {
Errors.reportException(e);
}
}
public static void setupTasks() {
try {
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new Runnable() {
@Override
public void run() {
for (Player P : Core.getMainClass().golfPower.keySet()) {
if (Core.getMainClass().releaseGolf.get(P)) {
P.setExp(0);
int power = Core.getMainClass().golfPower.get(P);
Entity i = Core.getMainClass().golfBall.get(P);
if (i != null && i.isValid()) {
Vector v = P.getLocation().getDirection();
v.multiply(new Vector(power / 10 + 1, 1.2, power / 10 + 1));
i.setVelocity(v);
}
Core.getMainClass().golfPower.remove(P);
Core.getMainClass().releaseGolf.remove(P);
} else {
Core.getMainClass().releaseGolf.put(P, true);
}
}
}
}, 5, 5);
ResultSet rs = sql.querySelect("SELECT world, X, Y, Z FROM coreStairs WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
while (rs.next()) {
World w = Bukkit.getWorld(rs.getString("world"));
if (w == null) {
continue;
}
Location l = new Location(w, rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
if (l.getBlock().getState().getData() instanceof Stairs) {
Core.getMainClass().sittableBlocks.add(l.getBlock());
}
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new Runnable() {
@Override
public void run() {
for (Player p : AnuraCore.getInstance().sittingPlayer.keySet()) {
Location loc = AnuraCore.getInstance().sittingPlayer.get(p).getLocation();
Arrow a = loc.getWorld().spawnArrow(loc, new Vector(0, 0, 0), 0, 0);
a.setPassenger(p);
AnuraCore.getInstance().sittingPlayer.get(p).remove();
AnuraCore.getInstance().sittingPlayer.put(p, a);
}
}
}, 600, 600);
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new Runnable() {
@Override
public void run() {
AnuraCore.getInstance().signs.updateServerSigns();
}
}, 20 * 5, 20 * 5);
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new VillagerTask(), 20, 20);
} catch (Throwable e) {
Errors.reportException(e);
}
}
public static void setupCommands() {
TeamCommands tc = new TeamCommands();
AdminCommands ac = new AdminCommands();
PlayerCommands pc = new PlayerCommands();
OtherCommands oc = new OtherCommands();
Core.getMainClass().getCommand("setjumper").setExecutor(tc);
Core.getMainClass().getCommand("setspawn").setExecutor(ac);
Core.getMainClass().getCommand("spawn").setExecutor(pc);
Core.getMainClass().getCommand("money").setExecutor(pc);
Core.getMainClass().getCommand("gm").setExecutor(tc);
Core.getMainClass().getCommand("sun").setExecutor(tc);
Core.getMainClass().getCommand("core").setExecutor(ac);
Core.getMainClass().getCommand("hilfe").setExecutor(pc);
Core.getMainClass().getCommand("none").setExecutor(oc);
Core.getMainClass().getCommand("flyspeed").setExecutor(tc);
Core.getMainClass().getCommand("setwarp").setExecutor(tc);
Core.getMainClass().getCommand("warp").setExecutor(pc);
Core.getMainClass().getCommand("remwarp").setExecutor(tc);
Core.getMainClass().getCommand("flowerpot").setExecutor(tc);
Core.getMainClass().getCommand("addmap").setExecutor(tc);
Core.getMainClass().getCommand("rendermap").setExecutor(tc);
Core.getMainClass().getCommand("cleararrows").setExecutor(ac);
Core.getMainClass().getCommand("stairmode").setExecutor(tc);
Core.getMainClass().getCommand("addcmd").setExecutor(tc);
Core.getMainClass().getCommand("setcmd").setExecutor(tc);
Core.getMainClass().getCommand("togglecommands").setExecutor(oc);
Core.getMainClass().getCommand("addmap").setExecutor(tc);
Core.getMainClass().getCommand("toggledbljump").setExecutor(pc);
Core.getMainClass().getCommand("joinminigame").setExecutor(pc);
Core.getMainClass().getCommand("leaveminigame").setExecutor(pc);
Core.getMainClass().getCommand("toggleminigame").setExecutor(pc);
Core.getMainClass().getCommand("addAimTWWin").setExecutor(oc);
Core.getMainClass().getCommand("toggleboat").setExecutor(pc);
Core.getMainClass().getCommand("toggleboatflight").setExecutor(tc);
Core.getMainClass().getCommand("bug").setExecutor(pc);
Core.getMainClass().getCommand("warplist").setExecutor(tc);
Core.getMainClass().getCommand("addInvItems").setExecutor(oc);
Core.getMainClass().getCommand("villager").setExecutor(ac);
Core.getMainClass().getCommand("i").setExecutor(tc);
Core.getMainClass().getCommand("mute").setExecutor(tc);
Core.getMainClass().getCommand("unmute").setExecutor(tc);
}
private static void setupInventories() {
try {
Inventories.registerInventory("GAMEMODES", "select_gamemode_inv", ChatColor.DARK_BLUE);
Inventories.putIntoInventory("GAMEMODES", 0, Inventories.buildItems(Material.RED_ROSE, "inv_lobby_tps", ChatColor.DARK_GREEN));
Inventories.putIntoInventory("GAMEMODES", 2, Inventories.buildItems(Material.CARROT_STICK, "inv_lobby_minigames", ChatColor.BLUE));
Inventories.putIntoInventory("GAMEMODES", 4, Inventories.buildItems(Material.IRON_PICKAXE, "inv_lobby_freebuild", ChatColor.GOLD));
Inventories.registerAction("GAMEMODES", 0, Inventories.Action.OPEN_INV, "LOBBY");
Inventories.registerAction("GAMEMODES", 2, Inventories.Action.OPEN_INV, "MINIGAMES");
Inventories.registerAction("GAMEMODES", 4, Inventories.Action.SERVER, "freebuild");
Inventories.registerInventory("MINIGAMES", "minigames_inv", ChatColor.DARK_BLUE);
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
Inventories.putIntoInventory("MINIGAMES", 0, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN, ChatColor.BLUE, "smash_description_1", "smash_description_2", "smash_description_3", "smash_description_4", "smash_description_5", "smash_description_6"));
Inventories.putIntoInventory("MINIGAMES", 1, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
Inventories.putIntoInventory("MINIGAMES", 2, Inventories.buildItems(Material.FIREWORK, "inv_lobby_rocketmatch", ChatColor.DARK_AQUA));
Inventories.putIntoInventory("MINIGAMES", 4, Inventories.buildItems(Material.EXP_BOTTLE, "inv_lobby_xpbattle", ChatColor.GREEN));
Inventories.putIntoInventory("MINIGAMES", 5, Inventories.buildItems(Material.POTION, "inv_lobby_pool", ChatColor.DARK_AQUA));
} else {
Inventories.putIntoInventory("MINIGAMES", 0, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN, ChatColor.BLUE, "smash_description_1", "smash_description_2", "smash_description_3", "smash_description_4", "smash_description_5", "smash_description_6"));
Inventories.putIntoInventory("MINIGAMES", 3, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
Inventories.putIntoInventory("MINIGAMES", 6, Inventories.buildItems(Material.FIREWORK, "inv_lobby_rocketmatch", ChatColor.DARK_AQUA));
}
Inventories.putIntoInventory("MINIGAMES", 8, Inventories.buildItems(Material.ENDER_PEARL, "inv_lobby_back", ChatColor.YELLOW));
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
Inventories.registerAction("MINIGAMES", 0, Inventories.Action.SERVER, "smash");
Inventories.registerAction("MINIGAMES", 1, Inventories.Action.SERVER, "farmfight");
Inventories.registerAction("MINIGAMES", 2, Inventories.Action.SERVER, "rocketmatch");
Inventories.registerAction("MINIGAMES", 4, Inventories.Action.COMMAND, "toggleminigame xpbattle");
Inventories.registerAction("MINIGAMES", 5, Inventories.Action.COMMAND, "aimthewater");
} else {
Inventories.registerAction("MINIGAMES", 0, Inventories.Action.SERVER, "smash");
Inventories.registerAction("MINIGAMES", 3, Inventories.Action.SERVER, "farmfight");
Inventories.registerAction("MINIGAMES", 6, Inventories.Action.SERVER, "rocketmatch");
}
Inventories.registerAction("MINIGAMES", 8, Inventories.Action.OPEN_INV, "GAMEMODES");
Inventories.registerInventory("LOBBY", "lobby_inv", ChatColor.DARK_BLUE);
Inventories.putIntoInventory("LOBBY", 0, Inventories.buildItems(Material.SLIME_BALL, "inv_lobby_jump", ChatColor.DARK_GREEN));
Inventories.putIntoInventory("LOBBY", 1, Inventories.buildItems(Material.WATER_BUCKET, "inv_lobby_swim", ChatColor.DARK_AQUA));
Inventories.putIntoInventory("LOBBY", 3, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN));
Inventories.putIntoInventory("LOBBY", 4, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
Inventories.putIntoInventory("LOBBY", 6, Inventories.buildItems(Material.WOOD_DOOR, "tp_to_spawn", ChatColor.GOLD));
Inventories.putIntoInventory("LOBBY", 8, Inventories.buildItems(Material.ENDER_PEARL, "inv_lobby_back", ChatColor.YELLOW));
Inventories.registerAction("LOBBY", 0, Inventories.Action.COMMAND, "jumpinv");
Inventories.registerAction("LOBBY", 1, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), -289, 31, -1715));
Inventories.registerAction("LOBBY", 3, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), 64, 34, -1490));
Inventories.registerAction("LOBBY", 4, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), -106, 22, -1806));
Inventories.registerAction("LOBBY", 6, Inventories.Action.COMMAND, "spawn");
Inventories.registerAction("LOBBY", 8, Inventories.Action.OPEN_INV, "GAMEMODES");
Inventories.registerInventory("FEATURES", "features_inv", ChatColor.DARK_BLUE);
Inventories.putIntoInventory("FEATURES", 2, Inventories.buildItems(Material.LEATHER_BOOTS, "inv_lobby_double_jump", ChatColor.DARK_AQUA));
Inventories.putIntoInventory("FEATURES", 4, Inventories.buildItems(Material.BOAT, "inv_lobby_boat", ChatColor.DARK_AQUA));
Inventories.registerAction("FEATURES", 2, Inventories.Action.COMMAND, "toggledbljump");
Inventories.registerAction("FEATURES", 4, Inventories.Action.COMMAND, "toggleboat");
Inventories.registerInventory("LANGUAGE", "Select language", ChatColor.DARK_BLUE);
int i = 0;
for (String langu : Core.getMainClass().lang.languages.keySet()) {
Inventories.putIntoInventory("LANGUAGE", i, Inventories.buildItems(Material.BOOK_AND_QUILL, Core.getMainClass().lang.languages.get(langu), ChatColor.DARK_GREEN, ChatColor.GOLD, "set_lang_to", Core.getMainClass().lang.languages.get(langu)));
Inventories.registerAction("LANGUAGE", i, Inventories.Action.LANGUAGE, langu);
i++;
}
Inventories.buildInvItem("COMPASS", Material.COMPASS, "select_game", ChatColor.DARK_AQUA);
Inventories.buildInvItem("SIGN", Material.SIGN, "Change language", ChatColor.DARK_GREEN);
Inventories.buildInvItem("CHARGE", Material.FIREBALL, "features_item", ChatColor.BLUE);
Inventories.buildInvItem("DOOR", Material.WOOD_DOOR, "tp_to_spawn", ChatColor.YELLOW);
Inventories.buildInvItem("EYE", Material.EYE_OF_ENDER, "inv_to_lobby", ChatColor.YELLOW);
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
Inventories.setItemInPlayerInv("COMPASS", 0);
Inventories.setItemInPlayerInv("SIGN", 1);
Inventories.setItemInPlayerInv("DOOR", 8);
}
Inventories.registerItemAction("COMPASS", Inventories.Action.OPEN_INV, "GAMEMODES");
Inventories.registerItemAction("SIGN", Inventories.Action.OPEN_INV, "LANGUAGE");
Inventories.registerItemAction("CHARGE", Inventories.Action.OPEN_INV, "FEATURES");
Inventories.registerItemAction("DOOR", Inventories.Action.COMMAND, "spawn");
Inventories.registerItemAction("EYE", Inventories.Action.SERVER, "lobby");
} catch (Throwable e) {
Errors.reportException(e);
}
}
public static void setupXPBattle() {
Scoreboard s = Bukkit.getScoreboardManager().getMainScoreboard();
if (s.getObjective("xpBattleStart") == null) {
s.registerNewObjective("xpBattleStart", "dummy");
s.registerNewObjective("xpBattleJoin", "dummy");
s.registerNewObjective("xpBattleEnd", "dummy");
s.registerNewObjective("xpBattleIngame", "dummy");
}
}
public static void setupVotifier() {
AnuraCore.getInstance().getServer().getPluginManager().registerEvents(new VotifierListener(), AnuraCore.getInstance());
AnuraCore.getInstance().getServer().getMessenger().registerIncomingPluginChannel(AnuraCore.getInstance(), "BungeeCord", new VotifierListener());
}
}