@Override
  public void onEnable() {
    inst = this;

    // Config
    getConfig().options().copyDefaults(true);
    saveConfig();

    // Setup database
    Infractions.setDatabase(new LegacyDatabase());
    Infractions.setDefaultOrigin(
        new Origin(Bukkit.getServerName(), Bukkit.getServerName(), OriginType.SERVER));

    getLogger().info("Initializing.");

    // Handle data
    DataManager.initAllData();
    LegacyData.asyncConvert();
    LegacyData.asyncConvertIds();

    loadCommands();
    loadListeners();
    loadMetrics();

    initializeThreads();

    Map<Integer, String> scores = Maps.newHashMap();
    for (int i = 1; i < 6; i++)
      scores.put(
          i,
          ChatColor.translateAlternateColorCodes(
              '&', SettingUtil.getSettingString("chat_score_" + i)));
    CHAT_SCORES = ImmutableMap.copyOf(scores);

    if (SettingUtil.getSettingBoolean("update"))
      new Updater(this, 44721, getFile(), Updater.UpdateType.DEFAULT, true);

    message("enabled");
  }
Пример #2
0
  @EventHandler
  public void on(PlayerJoinEvent e) {

    final Player p = e.getPlayer();

    Tablist tab = new Tablist();
    tab.setFooter("§3OreBattle v1.0");
    tab.setHeader("§a" + Bukkit.getServerName());
    tab.send(p);

    if (Devathlon.Status == GameStatus.Lobby) {

      /*TagManager tm = new TagManager(p);
      tm.changeTag(tm.getTagByPermissions());
      tm.setTag();*/

      e.setJoinMessage(
          "§7> "
              + p.getDisplayName()
              + " §3hat das Spiel betreten. ("
              + Bukkit.getOnlinePlayers().size()
              + "/"
              + Bukkit.getMaxPlayers()
              + ")");

      if (Bukkit.getOnlinePlayers().size() == 5 && Devathlon.Timer > 10) {
        Devathlon.Timer = 10;
      }

      clearupperson(p);
      createPlayerStats(p);

      p.getInventory()
          .setItem(
              0, createItemstack(Material.COMPASS, "§9Teamauswahl §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              8,
              createItemstack(
                  Material.SLIME_BALL, "§9Zurück zur Lobby §7<Rechtsklick>", 1, (byte) 0));
      if (Devathlon.sql == true) {
        p.getInventory()
            .setItem(
                4,
                createItemstack(Material.NETHER_STAR, "§9Kitauswahl §7<Rechtsklick>", 1, (byte) 0));
      }

      p.getInventory().setHeldItemSlot(0);
      p.teleport(OreBattle_Command.getLocation("Lobby", true));
      p.sendMessage(Devathlon.prefix + "§3Willkommen bei OreBattle v1.0");

    } else {

      e.setJoinMessage("");

      p.getInventory().clear();
      p.getInventory()
          .setItem(
              0,
              createItemstack(Material.REDSTONE_BLOCK, "§cTeam Rot §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              1, createItemstack(Material.LAPIS_BLOCK, "§9Team Blau §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              8,
              createItemstack(
                  Material.SLIME_BALL, "§9Zurück zur Lobby §7<Rechtsklick>", 1, (byte) 0));

      TagManager tm = new TagManager(p);
      tm.changeTag("7");
      tm.setTag();
      p.setPlayerListName("§7[§cX§7] §8| §7" + p.getName());
      p.setDisplayName("§7[§cX§7] " + p.getName());

      Global.spectator.add(p);

      for (Player all : Bukkit.getOnlinePlayers()) {
        all.hidePlayer(p);
        for (Player spec : Global.spectator) {
          spec.showPlayer(p);
          p.showPlayer(spec);
        }
      }

      p.setAllowFlight(true);
      p.setFlying(true);
      p.sendMessage(Devathlon.prefix + "§3Du bist jetzt Spectator.");
      p.teleport(OreBattle_Command.getLocation("Spectator", true));
    }
  }
  @Override
  public void onPluginMessageReceived(String channel, Player sender, byte[] message) {
    if (!channel.equalsIgnoreCase(BungeeSuiteBukkit.INCOMING_PLUGIN_CHANNEL)) return;

    DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));

    String chan = null;

    try {
      chan = in.readUTF();
    } catch (IOException e5) {
      e5.printStackTrace();
    }

    if (chan.equalsIgnoreCase("CreatePortal")) {
      Player player = null;
      String name = null;
      String type = null;
      String dest = null;
      try {
        if (!plugin.utils.serverExists(Bukkit.getServerName())) {
          player.sendMessage(
              ChatColor.RED
                  + "This server does not exist. Make sure your server.properties server-name is the same as your BungeeCord config.");
          return;
        }
      } catch (SQLException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      }
      try {
        player = Bukkit.getPlayer(in.readUTF());
        name = in.readUTF();
        type = in.readUTF();
        dest = in.readUTF();
      } catch (IOException e4) {
        e4.printStackTrace();
      }

      if (!(type.equalsIgnoreCase("warp") || type.equalsIgnoreCase("server"))) {
        player.sendMessage(ChatColor.RED + "invalid type use server or warp");
        return;
      }

      try {
        if (type.equalsIgnoreCase("warp") && !plugin.utils.warpExists(dest)) {
          player.sendMessage(ChatColor.RED + "That warp doesnt exist!");
          return;
        }

        if (type.equalsIgnoreCase("server") && !plugin.utils.serverExists(dest)) {
          player.sendMessage(ChatColor.RED + "That server doesnt exist!");
          return;
        }

        if (plugin.utils.portalExists(name)) {
          player.sendMessage(ChatColor.RED + "That portal already exists!");
          return;
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }

      FillType ft = FillType.getFillType("WATER");
      Region portalArea = plugin.rsm.getSelection(player.getName());
      if (portalArea == null) {
        player.sendMessage(ChatColor.RED + "ERROR: Make a selection with the wood axe");
        return;
      }

      try {
        if (type.equalsIgnoreCase("warp"))
          plugin.utils.createPortal(name, null, dest, portalArea, ft);
        else if (type.equalsIgnoreCase("server"))
          plugin.utils.createPortal(name, dest, null, portalArea, ft);
      } catch (SQLException e) {
        e.printStackTrace();
      }

      player.sendMessage(ChatColor.DARK_GREEN + "Portal " + name + " created!");
      return;
    }

    if (chan.equalsIgnoreCase("DeletePortal")) {
      String portalName = null;
      try {
        portalName = in.readUTF();
        plugin.utils.deletePortal(portalName);
      } catch (SQLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    if (chan.equalsIgnoreCase("SetWarp")) {
      Player player = null;
      String name = null;
      boolean visible = true;

      try {
        player = Bukkit.getPlayer(in.readUTF());
        name = in.readUTF();

        if (plugin.utils.warpExists(name)) {
          player.sendMessage(ChatColor.RED + "Warp already exists");
          return;
        }

        visible = in.readBoolean();
        if (!plugin.utils.serverExists(Bukkit.getServerName())) {
          player.sendMessage(
              ChatColor.RED
                  + "This does not exist. Make sure your server.properties server-name is the same as your BungeeCord config.");
          return;
        }
        plugin.utils.createWarp(name, player.getLocation(), visible);
      } catch (SQLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      player.sendMessage(ChatColor.DARK_GREEN + "Warp " + name + " created!");
      return;
    }

    if (chan.equalsIgnoreCase("warp")) {
      WarpLocation wl = null;
      String warp[] = null;
      String warps = null;
      Player player = null;

      try {
        player = Bukkit.getPlayer(in.readUTF());
        warps = in.readUTF();
        warp = warps.split("~");
      } catch (IOException e) {
        e.printStackTrace();
      }

      wl =
          new WarpLocation(
              warp[0],
              warp[1],
              Double.parseDouble(warp[2]),
              Double.parseDouble(warp[3]),
              Double.parseDouble(warp[4]),
              Float.parseFloat(warp[5]),
              Float.parseFloat(warp[6]));

      Chunk c = wl.getLocation().getChunk();
      c.load();
      while (!c.isLoaded()) {
        c.load();
      }

      player.teleport(wl.getLocation());
      return;
    }

    if (chan.equalsIgnoreCase("Teleport")) {
      Player player = null;
      String targetPlayer = null;

      try {
        player = Bukkit.getPlayer(in.readUTF());
        targetPlayer = in.readUTF();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      Player tp = Bukkit.getPlayer(targetPlayer);
      player.teleport(tp);
      return;
    }
  }