package de.anura.core; import de.anura.core.API.Core; 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.AdminCommands; import de.anura.core.commands.OtherCommands; import de.anura.core.commands.PlayerCommands; import de.anura.core.commands.TeamCommands; import de.anura.core.events.BlockBreak; import de.anura.core.events.BlockPlace; import de.anura.core.events.BlockSpread; import de.anura.core.events.CmdPreprocess; import de.anura.core.events.DropItem; import de.anura.core.events.EntityDamage; import de.anura.core.events.EntityDamageByE; import de.anura.core.events.FoodChange; import de.anura.core.events.HangingEBreak; import de.anura.core.events.InvClick; import de.anura.core.events.LeavesDecay; import de.anura.core.events.PlayerChat; import de.anura.core.events.PlayerInteract; import de.anura.core.events.PlayerInteractE; import de.anura.core.events.PlayerJoin; import de.anura.core.events.PlayerKick; import de.anura.core.events.PlayerMove; import de.anura.core.events.PlayerQuit; import de.anura.core.events.PlayerTeleport; import de.anura.core.events.SignChange; import de.anura.core.events.WeatherChange; import java.sql.ResultSet; import java.sql.SQLException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.material.Stairs; import org.bukkit.util.Vector; public class Setup { public static void setupConfig() { Core.getMainClass().getConfig().addDefault("no-damage", false); Core.getMainClass().getConfig().addDefault("no-void-death", false); Core.getMainClass().getConfig().addDefault("no-change-blocks", false); Core.getMainClass().getConfig().addDefault("is-main-lobby", false); Core.getMainClass().getConfig().addDefault("no-hunger", false); Core.getMainClass().getConfig().addDefault("no-rain", false); Core.getMainClass().getConfig().addDefault("enable-leaves-decay", true); Core.getMainClass().getConfig().addDefault("server-name", "lobby"); Core.getMainClass().getConfig().addDefault("allow-stairs-sit", false); Core.getMainClass().getConfig().addDefault("disable-mushroom-spread", false); Core.getMainClass().getConfig().addDefault("on-join-to-spawn", false); Core.getMainClass().getConfig().addDefault("golf", false); Core.getMainClass().getConfig().addDefault("realtime-day", false); Core.getMainClass().getConfig().options().copyDefaults(true); Core.getMainClass().getConfig().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()); } public static void setupClasses() { Core.getMainClass().lang = new LanguageSupport(Core.getMainClass()); 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"); try { 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); } } catch (SQLException ex) { System.err.println("Error whilst trying to setup flower pots"); } Core.getMainClass().features = new Features(); Core.getMainClass().features.updateFeaturesAll(); } public static void setupTasks() { 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") + "'"); try { 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()); } } } catch (SQLException ex) { System.err.println("Error whilst trying to setup stairs"); } 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); } 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); } private static void setupInventories() { 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); 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", 2, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW)); Inventories.putIntoInventory("MINIGAMES", 4, Inventories.buildItems(Material.FIREWORK, "inv_lobby_rocketmatch", ChatColor.DARK_AQUA)); Inventories.putIntoInventory("MINIGAMES", 8, Inventories.buildItems(Material.ENDER_PEARL, "inv_lobby_back", ChatColor.YELLOW)); Inventories.registerAction("MINIGAMES", 0, Inventories.Action.SERVER, "smash"); Inventories.registerAction("MINIGAMES", 2, Inventories.Action.SERVER, "farmfight"); Inventories.registerAction("MINIGAMES", 4, 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.EXP_BOTTLE, "inv_lobby_xpbattle", ChatColor.GREEN)); Inventories.putIntoInventory("LOBBY", 4, Inventories.buildItems(Material.POTION, "inv_lobby_pool", ChatColor.BLUE)); 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"), -288, 32, -1714)); Inventories.registerAction("LOBBY", 3, Inventories.Action.COMMAND, "toggleminigame xpbattle"); Inventories.registerAction("LOBBY", 1, Inventories.Action.COMMAND, "toggleminigame pool"); 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.registerAction("FEATURES", 2, Inventories.Action.COMMAND, "toggledbljump"); 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"); } }