예제 #1
0
 public void shutdown(String messageToKickWith) {
   System.out.print(HungergamesApi.getConfigManager().getLoggerConfig().getShuttingDown());
   ServerShutdownEvent event = new ServerShutdownEvent();
   Bukkit.getServer().getPluginManager().callEvent(event);
   if (!event.isCancelled()) {
     for (String command : mainConfig.getCommandsToRunBeforeShutdown())
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
     for (Player player : Bukkit.getOnlinePlayers()) {
       player.kickPlayer(messageToKickWith);
     }
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), mainConfig.getCommandToStopTheServerWith());
   } else
     System.out.print(HungergamesApi.getConfigManager().getLoggerConfig().getShutdownCancelled());
 }
예제 #2
0
 @Command(
     aliases = {"toggle"},
     desc = "Toggle a setting.",
     usage = "<setting>",
     min = 1)
 public static void toggle(final CommandContext cmd, CommandSender sender)
     throws CommandException {
   if (sender instanceof Player) {
     if (Settings.getSettingByName(cmd.getString(0)) != null) {
       int index =
           Settings.getSettingByName(cmd.getString(0))
               .getValues()
               .indexOf(
                   Settings.getSettingByName(cmd.getString(0)).getValueByPlayer((Player) sender));
       index++;
       if (index >= Settings.getSettingByName(cmd.getString(0)).getValues().size()) index = 0;
       Bukkit.dispatchCommand(
           sender,
           "set "
               + cmd.getString(0)
               + " "
               + Settings.getSettingByName(cmd.getString(0)).getValues().get(index).getValue());
     } else throw new CommandException("No setting by this name!");
   } else throw new CommandException("Console cannot use this command.");
 }
예제 #3
0
 @Override
 public void perform() {
   for (String cmd : commands) {
     if (useConsole) Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replaceAll("\\\\", ""));
     else this.player.performCommand(cmd.replaceAll("\\\\", "/"));
   }
 }
예제 #4
0
 @EventHandler
 public void onRespawn(PlayerRespawnEvent e) {
   Player p = e.getPlayer();
   if (respawn.contains(p.getName())) {
     Bukkit.dispatchCommand(p, "admin");
     respawn.remove(p.getName());
   }
 }
예제 #5
0
파일: Test.java 프로젝트: Co0sh/BetonTest
 /** Pauses the test for the player. */
 private void pause(Player player) {
   if (messagePause != null) player.sendMessage(messagePause.replace('&', '§'));
   if (commandPause != null)
     Bukkit.dispatchCommand(
         Bukkit.getConsoleSender(), commandPause.replace("%player%", player.getName()));
   plugin.getData().set(player.getUniqueId() + ".current", null);
   plugin.getData().set(player.getUniqueId() + ".paused.name", name);
   plugin
       .getData()
       .set(player.getUniqueId() + ".paused.chances", chances.get(player.getUniqueId()));
 }
예제 #6
0
파일: Test.java 프로젝트: Co0sh/BetonTest
 /** Fails the test for the player. */
 private void fail(Player player) {
   if (messageFail != null) player.sendMessage(messageFail.replace('&', '§'));
   if (commandFail != null)
     Bukkit.dispatchCommand(
         Bukkit.getConsoleSender(), commandFail.replace("%player%", player.getName()));
   plugin.getData().set(player.getUniqueId() + ".current", null);
   List<String> newList = plugin.getData().getStringList(player.getUniqueId() + ".failed");
   newList.add(name);
   plugin.getData().set(player.getUniqueId() + ".failed", newList);
   plugin.logTest(player, this, false);
   if (teleportBack) player.teleport(getLocation(player));
 }
예제 #7
0
 public void startStage(Player p, Stage s) {
   switch (s) {
     case FIRST:
       Bukkit.dispatchCommand(
           Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial");
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName());
       break;
     case SECOND:
       Bukkit.dispatchCommand(
           Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial2");
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName());
       break;
     case THIRD:
       p.teleport(new Location(Bukkit.getWorld("OrbiA"), -2268.0, 98.0, -3436.0));
       p.sendMessage(
           ChatColor.GREEN
               + "Betrete das Dungeon über der Kaserne in Angin! (x: -2167 y: 145 z: -3529)");
       break;
     case FOURTH:
       Bukkit.dispatchCommand(
           Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial3");
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName());
     case FITH:
       p.teleport(new Location(Bukkit.getWorld("OrbiA"), -2433.0, 202.0, -3659.0));
       p.sendMessage(
           ChatColor.GREEN
               + "Wähle eine Klasse bei einem der Graubärte (Rechtsklick auf den Graubart! Gehe dann zurück zu Gondolf und rede mit ihm!");
     default:
       break;
   }
 }
예제 #8
0
 @Override
 public void onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
   if (sender instanceof Player) {
     sender.sendMessage(ChatColor.RED + "This command can only be used from the console.");
     return;
   }
   Player player = Bukkit.getPlayer(args[0]);
   if (player != null) {
     for (String perm : perms) {
       Bukkit.dispatchCommand(
           Bukkit.getConsoleSender(), "pex user " + player.getName() + " add " + perm + " plots");
     }
   }
 }
예제 #9
0
  public void acceptBanRequest(CommandSender sender, BanRequest a) {

    sender.sendMessage(ChatColor.GREEN + "Accepting ban request of " + a.defendantName);

    String acceptor = "Console";
    if (Utils.isPlayer(sender)) acceptor = ((Player) sender).getName();

    for (Player p : Bukkit.getOnlinePlayers())
      if (p.hasPermission("SafeBan.Alert.BanWasAccepted"))
        p.sendMessage(formatMessage(BannedReasonTell, a, acceptor));

    Bukkit.dispatchCommand(
        Bukkit.getConsoleSender(),
        "ban " + a.getDefendantName() + " " + formatMessage(BannedReason, a, acceptor));
  }
예제 #10
0
 public static ItemStack displayItem(Player player, Location chest) {
   HashMap<ItemStack, String> items = getItems(player);
   int stop = 0;
   for (; items.size() == 0; stop++) {
     if (stop == 100) {
       break;
     }
     items = getItems(player);
   }
   Random r = new Random();
   ArrayList<ItemStack> I = new ArrayList<ItemStack>();
   ArrayList<String> P = new ArrayList<String>();
   I.addAll(items.keySet());
   for (ItemStack it : I) {
     P.add(items.get(it));
   }
   int pick = r.nextInt(I.size());
   String pa = P.get(pick);
   path.put(player, pa);
   FileConfiguration file = Main.settings.getFile(GUI.Crate.get(player));
   if (file.contains(path.get(player) + ".Items")) {
     for (ItemStack i : getFinalItems(path.get(player), player)) {
       player.getInventory().addItem(i);
     }
   }
   if (file.contains(path.get(player) + ".Commands")) {
     for (String command : file.getStringList(path.get(player) + ".Commands")) {
       command = color(command);
       command = command.replace("%Player%", player.getName());
       command = command.replace("%player%", player.getName());
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
     }
   }
   if (file.contains(path.get(player) + ".Messages")) {
     for (String msg : file.getStringList(path + ".Messages")) {
       msg = Api.color(msg);
       msg = msg.replace("%Player%", player.getName());
       msg = msg.replace("%player%", player.getName());
       player.sendMessage(msg);
     }
   }
   if (file.getBoolean(path.get(player) + ".Firework")) {
     fireWork(chest);
   }
   return I.get(pick);
 }
예제 #11
0
 @Override
 public void onBuy(Player p) {
   CCPlayerModule ccpm = plugin.api.getModuleForClass(CCPlayerModule.class);
   CCPlayer ccp = ccpm.getPlayer(p);
   if (!p.hasPermission(this.getPermision(p))) {
     if (ccp.getCredits() >= this.getPrice(p)) {
       ccp.removeCredits(getPrice(p));
       this.onBought(p);
       Bukkit.dispatchCommand(
           Bukkit.getConsoleSender(), "pex user " + p.getName() + " add " + this.getPermision(p));
     } else {
       p.sendMessage("You don't have enough credits for " + getName());
     }
   } else {
     p.sendMessage("You already have " + getName());
   }
 }
예제 #12
0
  public static void seekersWin(Arena arena) {
    ArenaHandler.sendFMessage(arena, ConfigC.normal_winSeekers, true);
    for (Player player : arena.playersInArena) {
      playerLeaveArena(player, false, false);
      player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
      if (arena.seekersWinCommands != null) {
        for (String command : arena.seekersWinCommands) {
          Bukkit.dispatchCommand(
              Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName()));
        }
      }
    }

    arena.playersInArena.clear();
    arena.seekers.clear();
    arena.gameState = ArenaState.WAITING;
  }
예제 #13
0
 @Command(
     aliases = {"settings"},
     desc = "List all settings.",
     usage = "[page]")
 public static void settings(final CommandContext cmd, CommandSender sender)
     throws CommandException {
   if (cmd.argsLength() == 0) {
     Bukkit.dispatchCommand(sender, "settings 1");
   } else {
     int page = cmd.getInteger(0);
     if (page > (Settings.getSettings().size() + 7) / 8)
       throw new CommandException(
           "Invalid page number specified! "
               + ((Settings.getSettings().size() + 7) / 8)
               + " total pages.");
     sender.sendMessage(
         ChatColor.RED
             + ""
             + ChatColor.STRIKETHROUGH
             + "--------------"
             + ChatColor.YELLOW
             + " Settings (Page "
             + page
             + " of "
             + ((Settings.getSettings().size() + 7) / 8)
             + ") "
             + ChatColor.RED
             + ""
             + ChatColor.STRIKETHROUGH
             + "--------------");
     for (int i = (page - 1) * 8; i < page * 8; i++) {
       if (i < Settings.getSettings().size())
         sender.sendMessage(
             ChatColor.YELLOW
                 + Settings.getSettings().get(i).getNames().get(0)
                 + ": "
                 + ChatColor.WHITE
                 + Settings.getSettings().get(i).getDescription());
     }
   }
 }
예제 #14
0
  public Location getRandomSpawn(ChatColor color) {

    try {
      List<GameSpawns> coords = this.getTeamCoords(color);

      GameSpawns coordSpawn = null;

      if (coords.size() == 1) {
        coordSpawn = coords.get(0);
      } else {
        coordSpawn = coords.get(HyperPVP.getRandom().nextInt(coords.size()));
      }

      Location gameSpawn =
          new Location(this.world, coordSpawn.getX(), coordSpawn.getY(), coordSpawn.getZ());
      return gameSpawn;
    } catch (Exception e) {
      Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "reload");
    }
    return null;
  }
예제 #15
0
  /** Plugin onEnable() event, enables all custom plugins that are on the current server */
  public void onEnable() {
    log("Diamond Dominion Custom Plugin ENABLING!");
    Bukkit.getServer().getPluginManager().registerEvents(this, this);

    this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);

    String server = detectedServer();
    log("Detected Server: " + server);

    DataManager dm = new DataManager();
    dm.reloaddata();
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex set default group Player");
    log("Loading Custom Items:");
    /*
     * Start Loading all Custom Plugin Classes
     */
    if (shouldEnable("EndDragonRespawn")) {
      log(" - EndDragonRespawn:");
      try {
        endDragonRespawn = new EndDragonRespawn(this);
        endDragonRespawn.enable();
      } catch (Exception e) {
        pluginFailed();
      }
    }

    if (shouldEnable("HeartBeat"))
      try {
        heartBeat = new HeartBeat(this);
        heartBeat.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("FairGod"))
      try {
        fairGod = new FairGod(this);
        fairGod.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("LegitWarzone"))
    //			try {
    //				legitWarzone = new LegitWarzone(this);
    //				legitWarzone.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    if (shouldEnable("TopPvPers"))
      try {
        topPvPers = new TopPvPers(this);
        topPvPers.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("VoteRewards"))
      try {
        voteRewards = new VoteRewards(this);
        voteRewards.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("VoteReceiver"))
      try {
        voteReceiver = new VoteReceiver(this);
        voteReceiver.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("DemiGodPackage"))
      try {
        demiGod = new DemiGodPackage(this);
        demiGod.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("DirectionBook"))
    //			try {
    //				directionBook = new DirectionBook(this);
    //				directionBook.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    //		if (shouldEnable("GameTime"))
    //			try {
    //				gameTime = new GameTime(this);
    //				gameTime.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    if (shouldEnable("CustomRecipies"))
      try {
        customRecipies = new CustomRecipies(this);
        customRecipies.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("SpawnerSwitch"))
      try {
        spawnerSwitch = new SpawnerSwitch(this);
        spawnerSwitch.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("JailSigns"))
    //		jailSigns.enable();

    //		if (shouldEnable("AutoConfiscate"))
    //		autoConfiscate.enable();

    if (shouldEnable("ModAppWall"))
      try {
        modAppWall = new ModAppWall(this);
        modAppWall.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("ModListWall"))
      try {
        modListWall = new ModListWall(this);
        modListWall.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("WebRanks"))
    //			try {
    //				webRanks = new WebRanks(this);
    //				webRanks.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    if (shouldEnable("Trampoline"))
      try {
        trampoline = new Trampoline(this);
        trampoline.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("PlotMeOverride"))
      try {
        plotMeOverride = new PlotMeOverride(this);
        plotMeOverride.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("Chat"))
      try {
        chat = new Chat(this);
        chat.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("ChatPrefix"))
      try {
        chatPrefix = new ChatPrefix(this);
        chatPrefix.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("FullMute"))
      try {
        fullMute = new FullMute(this);
        fullMute.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("LaunchPad"))
      try {
        launchPad = new LaunchPad(this);
        launchPad.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("ColorArmor"))
      try {
        colorArmor = new ColorArmor(this);
        colorArmor.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("DrunkenWizard"))
    //		drunkenWizard.enable();

    if (shouldEnable("CreativeEntityRemover"))
      try {
        creativeEntityRemover = new CreativeEntityRemover(this);
        creativeEntityRemover.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("WelcomeBook"))
      try {
        welcomeBook = new WelcomeBook(this);
        welcomeBook.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("IpRecorder"))
      try {
        ipRecorder = new IpRecorder(this);
        ipRecorder.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("WelcomeSign"))
      try {
        welcomeSign = new WelcomeSign(this);
        welcomeSign.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("PeacefulGriefFree"))
    //		peacefulGriefFree.enable();

    //		if (shouldEnable("ForumActivation"))
    //			try {
    //				forumActivation = new ForumActivation(this);
    //				forumActivation.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    if (shouldEnable("VirtualChest"))
      try {
        virtualChest = new VirtualChest(this);
        virtualChest.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    //		if (shouldEnable("WorldBlocks"))
    //			try {
    //				worldBlocks = new WorldBlocks(this);
    //				worldBlocks.enable();
    //			} catch (Exception e) {
    //				pluginFailed();
    //			}

    if (shouldEnable("DonorShop"))
      try {
        donorShop = new DonorShop(this);
        donorShop.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("SpawnMusic"))
      try {
        spawnMusic = new SpawnMusic(this);
        spawnMusic.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("CrashPlayer"))
      try {
        crashPlayer = new CrashPlayer(this);
        crashPlayer.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("BeastSprint"))
      try {
        beastSprint = new BeastSprint(this);
        beastSprint.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("Nameless"))
      try {
        nameless = new Nameless(this);
        nameless.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("TnTPunch"))
      try {
        tntpunch = new TnTPunch(this);
        tntpunch.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("RestartWarning"))
      try {
        restartWarning = new RestartWarning(this);
        restartWarning.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("UnderCover"))
      try {
        underCover = new UnderCover(this);
        underCover.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("SignEdit"))
      try {
        signEdit = new SignEdit(this);
        signEdit.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("WarpWild"))
      try {
        warpWild = new WarpWild(this);
        warpWild.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("EWButtons"))
      try {
        ewButtons = new EWButtons(this);
        ewButtons.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("SkyBlockTP"))
      try {
        skyBlockTP = new SkyBlockTP(this);
        skyBlockTP.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("EnderEggCollection"))
      try {
        enderEggCollection = new EnderEggCollection(this);
        enderEggCollection.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("Voodoo"))
      try {
        voodoo = new Voodoo(this);
        voodoo.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("ExtraMiningLoot"))
      try {
        extraMiningLoot = new ExtraMiningLoot(this);
        extraMiningLoot.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("EWBlockFenceWalk"))
      try {
        ewBlockFenceWalk = new EWBlockFenceWalk(this);
        ewBlockFenceWalk.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("CommandModifier"))
      try {
        commandModifier = new CommandModifier(this);
        commandModifier.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("SkyBlockPortalReward"))
      try {
        sbPortalReward = new SkyBlockPortalReward(this);
        sbPortalReward.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("HubPortals"))
      try {
        hubPortals = new HubPortals(this);
        hubPortals.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("BungeeGlobalCommand"))
      try {
        bungeeGBCMD = new BungeeGlobalCommand(this);
        bungeeGBCMD.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("StaffVotes"))
      try {
        staffVotes = new StaffVotes(this);
        staffVotes.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("RespectedAutoPromote"))
      try {
        respectedAutoPromote = new RespectedAutoPromote(this);
        respectedAutoPromote.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("Homes"))
      try {
        homes = new Homes(this);
        homes.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("FairFly"))
      try {
        fly = new FairFly(this);
        fly.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    if (shouldEnable("ServerRestart"))
      try {
        serverRestart = new ServerRestart(this);
        serverRestart.enable();
      } catch (Exception e) {
        pluginFailed();
      }

    /*
     * Complete loading all custom plugin classes
     */
    log("Fully Enabled!");
  }
예제 #16
0
  public void performCommand(final Player player, final String[] args) {
    if (args.length == 1) {
      String kitName = args[0];

      if (TheBasics.getGeneralConfig().contains("Kits." + kitName)) {
        if (player.hasPermission("TheBasics.Kit." + kitName)) {
          PlayerData data = BasicUtils.getData(player);

          try {
            if (data.contains("Kits." + kitName)) {
              double time = data.getDouble("Kits." + kitName);

              if (time <= System.currentTimeMillis()) {
                data.set("Kits." + kitName, null);
              } else {
                DecimalFormat format = new DecimalFormat("#.#");
                String formatedTime = String.valueOf(time);
                String unit;

                time = time - System.currentTimeMillis();

                if ((time / 1000) <= 60) {
                  unit = "s";
                  formatedTime = format.format(time / 1000);
                } else if (((time / 1000) / 60) <= 60) {
                  unit = "m";
                  formatedTime = format.format((time / 1000) / 60);
                } else {
                  unit = "h";
                  formatedTime = format.format(((time / 1000) / 60) / 60);
                }

                BasicUtils.sendMessage(
                    player, BasicUtils.getMessage("KitTime").replace("%a", formatedTime + unit));
                return;
              }
            }

            for (String items :
                TheBasics.getGeneralConfig().getStringList("Kits." + kitName + ".Items")) {
              String[] split = items.split(" ");
              List<String> list = Arrays.asList(split);
              ItemStack item = BasicUtils.getItem(split[0], split[1]);

              if (items.contains("Name:")) {
                StringBuilder sb = new StringBuilder();

                for (int i = BasicUtils.getIndex(list, "Name:") + 1; i < split.length; i++) {
                  if (split[i].equalsIgnoreCase("Enchant:")) {
                    break;
                  } else {
                    sb.append(split[i] + " ");
                  }
                }

                ItemMeta meta = item.getItemMeta();
                meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', sb.toString()));
                item.setItemMeta(meta);
              }

              if (items.contains("Enchant:")) {
                int index = BasicUtils.getIndex(list, "Enchant:") + 1;
                Enchantment enchant = BasicUtils.getEnchantment(split[index]);
                int level = Integer.parseInt(split[index + 1]);

                item.addUnsafeEnchantment(enchant, level);
              }

              BasicUtils.addItem(player, item);
            }

            for (String command :
                TheBasics.getGeneralConfig().getStringList("Kits." + kitName + ".Commands")) {
              Bukkit.dispatchCommand(
                  Bukkit.getConsoleSender(), command.replace("%p", player.getName()));
            }

            data.set(
                "Kits." + kitName,
                System.currentTimeMillis()
                    + (1000 * TheBasics.getGeneralConfig().getDouble("Kits." + kitName + ".Time")));
            BasicUtils.sendMessage(player, BasicUtils.getMessage("KitUse").replace("%a", args[0]));
          } catch (Exception e) {
            TheBasics.getLog()
                .severe(
                    "The kit " + kitName + " has an error. Please make sure all values are valid.");
            BasicUtils.sendMessage(player, BasicUtils.getMessage("KitError"));
          }
        } else {
          BasicUtils.sendMessage(player, BasicUtils.getMessage("NoPermission"));
        }
      } else {
        BasicUtils.sendMessage(player, BasicUtils.getMessage("KitExist"));
      }
    } else {
      StringBuilder sb = new StringBuilder();

      for (String kit :
          TheBasics.getGeneralConfig().getConfigurationSection("Kits").getKeys(false)) {
        if (player.hasPermission("TheBasics.Kit." + kit)) {
          sb.append(", " + kit);
        }
      }

      BasicUtils.sendMessage(
          player,
          BasicUtils.getMessage("KitList").replace("%a", sb.toString().replaceFirst(", ", "")));
    }
  }
예제 #17
0
  public void expandItems(final User user, final List<String> items) throws Exception {
    try {
      IText input = new SimpleTextInput(items);
      IText output = new KeywordReplacer(input, user.getSource(), ess);

      boolean spew = false;
      final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
      for (String kitItem : output.getLines()) {
        if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) {
          BigDecimal value =
              new BigDecimal(
                  kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
          Trade t = new Trade(value, ess);
          t.pay(user, OverflowType.DROP);
          continue;
        }

        if (kitItem.startsWith("/")) {
          String command = kitItem.substring(1);
          String name = user.getName();
          command = command.replace("{player}", name);
          Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
          continue;
        }

        final String[] parts = kitItem.split(" +");
        final ItemStack parseStack =
            ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

        if (parseStack.getType() == Material.AIR) {
          continue;
        }

        final MetaItemStack metaStack = new MetaItemStack(parseStack);

        if (parts.length > 2) {
          // We pass a null sender here because kits should not do perm checks
          metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
        }

        final Map<Integer, ItemStack> overfilled;
        final boolean allowOversizedStacks = user.isAuthorized("essentials.oversizedstacks");
        if (allowOversizedStacks) {
          overfilled =
              InventoryWorkaround.addOversizedItems(
                  user.getBase().getInventory(),
                  ess.getSettings().getOversizedStackSize(),
                  metaStack.getItemStack());
        } else {
          overfilled =
              InventoryWorkaround.addItems(user.getBase().getInventory(), metaStack.getItemStack());
        }
        for (ItemStack itemStack : overfilled.values()) {
          int spillAmount = itemStack.getAmount();
          if (!allowOversizedStacks) {
            itemStack.setAmount(
                spillAmount < itemStack.getMaxStackSize()
                    ? spillAmount
                    : itemStack.getMaxStackSize());
          }
          while (spillAmount > 0) {
            user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
            spillAmount -= itemStack.getAmount();
          }
          spew = true;
        }
      }
      user.getBase().updateInventory();
      if (spew) {
        user.sendMessage(tl("kitInvFull"));
      }
    } catch (Exception e) {
      user.getBase().updateInventory();
      ess.getLogger().log(Level.WARNING, e.getMessage());
      throw new Exception(tl("kitError2"), e);
    }
  }
예제 #18
0
 public String execute(String name, String executor) {
   String command = this.cmd.replace("%p", name).replace("%e", executor);
   Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
   return command;
 }
예제 #19
0
 public static void handleNotify(byte[] bytes) {
   try {
     DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
     String subChannel = in.readUTF();
     if (subChannel.equals("ReportRTS")) {
       short len = in.readShort();
       byte[] msgbytes = new byte[len];
       in.readFully(msgbytes);
       DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
       String function = msgin.readUTF();
       if (function.equals("NotifyAndSync")) {
         int ticketId = msgin.readInt();
         NotificationType notifType = NotificationType.getTypeByCode(msgin.readInt());
         String msg = msgin.readUTF();
         if (notifType.getCode() == 0 || notifType.getCode() == 1) {
           if (RTSFunctions.syncTicket(ticketId)) {
             RTSFunctions.messageMods(msg, (notifType.getCode() == 0));
           }
         } else if (notifType.getCode() == 3 || notifType.getCode() == 4) {
           RTSFunctions.messageMods(msg, false);
         } else if (notifType.getCode() == 2 || notifType.getCode() == 5) {
           if (RTSFunctions.syncTicket(ticketId)) {
             if (notifType.getCode() == 2)
               ReportRTS.getPlugin()
                   .notificationMap
                   .put(ticketId, ReportRTS.getPlugin().requestMap.get(ticketId).getName());
             ReportRTS.getPlugin().requestMap.remove(ticketId);
             RTSFunctions.messageMods(msg, (notifType.getCode() == 0));
           }
         } else if (notifType.getCode() == 6) {
           ReportRTS.getPlugin().requestMap.remove(ticketId);
           RTSFunctions.messageMods(msg, (notifType.getCode() == 0));
         }
       } else if (function.equals("NotifyUserAndSync")) {
         int ticketId = msgin.readInt();
         String username = msgin.readUTF();
         String msg = msgin.readUTF();
         if (RTSFunctions.syncTicket(ticketId)) {
           Player player = Bukkit.getPlayerExact(username);
           if (player != null) {
             player.sendMessage(msg);
             if (!DatabaseManager.getDatabase().setNotificationStatus(ticketId, 1))
               ReportRTS.getPlugin()
                   .getLogger()
                   .warning("Unable to set notification status to 1.");
           }
         }
       } else if (function.equals("TeleportNotify")) {
         int ticketId = msgin.readInt();
         String username = msgin.readUTF();
         if (RTSFunctions.isUserOnline(username)) {
           Player player = Bukkit.getPlayerExact(username);
           if (player != null) {
             player.sendMessage(
                 Message.parse("teleportedUser", "/tp-id " + Integer.toString(ticketId)));
             Bukkit.dispatchCommand(player, "tp-id " + Integer.toString(ticketId));
           } else {
             ReportRTS.getPlugin().teleportMap.put(username, ticketId);
           }
         } else {
           ReportRTS.getPlugin().teleportMap.put(username, ticketId);
         }
       }
     } else if (subChannel.equals("GetServer")) {
       String serverName = in.readUTF();
       setServer(serverName);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #20
0
  // sync
  public static void handleHack(Player player, HackType type) {
    if (player == null) return;

    String message = "";

    switch (type) {
      case fly:
        if (Hacks.fly.useCommand) {
          Integer cur = cmdFly.get(player.getName());
          if (cur == null) cur = 0;
          cur++;

          if (cur >= Hacks.fly.triggerAfter) {
            try {
              Bukkit.dispatchCommand(
                  Bukkit.getConsoleSender(),
                  Hacks.fly.command.replace("{PLAYER}", player.getName()).replace("{TYPE}", "fly"));
            } catch (Exception ex) {
              Warning.config("The command set for Anti-Hacks.Fly returned an error!", false);
            }
            cmdFly.remove(player.getName());
          } else {
            cmdFly.put(player.getName(), cur);
          }
        }
        message = convert(Hacks.broadcastFormat, "Fly", player);
        if (Hacks.fly.kick) Util.kick(player, "[TRHack] Kicked for Fly-hacking!");
        if (Hacks.fly.broadcast)
          Util.broadcastNoConsole("[TRHack] " + message, "tekkitrestrict.notify.hack");
        break;
      case forcefield:
        if (Hacks.forcefield.useCommand) {
          Integer cur = cmdForcefield.get(player.getName());
          if (cur == null) cur = 0;
          cur++;

          if (cur >= Hacks.forcefield.triggerAfter) {
            try {
              Bukkit.dispatchCommand(
                  Bukkit.getConsoleSender(),
                  Hacks.forcefield
                      .command
                      .replace("{PLAYER}", player.getName())
                      .replace("{TYPE}", "forcefield"));
            } catch (Exception ex) {
              Warning.config("The command set for Anti-Hacks.Forcefield returned an error!", false);
            }
            cmdForcefield.remove(player.getName());
          } else {
            cmdForcefield.put(player.getName(), cur);
          }
        }
        message = convert(Hacks.broadcastFormat, "Forcefield", player);
        if (Hacks.forcefield.kick) Util.kick(player, "[TRHack] Kicked for Forcefield-hacking!");
        if (Hacks.forcefield.broadcast)
          Util.broadcastNoConsole("[TRHack] " + message, "tekkitrestrict.notify.hack");
        break;
      case speed:
        if (Hacks.speed.useCommand) {
          Integer cur = cmdSpeed.get(player.getName());
          if (cur == null) cur = 0;
          cur++;

          if (cur >= Hacks.speed.triggerAfter) {
            try {
              Bukkit.dispatchCommand(
                  Bukkit.getConsoleSender(),
                  Hacks.speed
                      .command
                      .replace("{PLAYER}", player.getName())
                      .replace("{TYPE}", "movespeed"));
            } catch (Exception ex) {
              Warning.config("The command set for Anti-Hacks.MoveSpeed returned an error!", false);
            }
            cmdSpeed.remove(player.getName());
          } else {
            cmdSpeed.put(player.getName(), cur);
          }
        }
        message = convert(Hacks.broadcastFormat, "Speed", player);
        if (Hacks.speed.kick) Util.kick(player, "[TRHack] Kicked for speed-hacking!");
        if (Hacks.speed.broadcast)
          Util.broadcastNoConsole("[TRHack] " + message, "tekkitrestrict.notify.hack");
        break;
    }

    Log.Hack(message);
  }
예제 #21
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerJoin(PlayerJoinEvent e) {
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    Boolean iswhitelisted = null;

    try {
      preparedStatement =
          connection.prepareStatement(
              "SELECT UUID, twKey, twSecret, twName, twID from twitterWhitelist WHERE UUID=? LIMIT 1");
      preparedStatement.setString(1, e.getPlayer().getUniqueId().toString());
      resultSet = preparedStatement.executeQuery();

      if (resultSet.isBeforeFirst()) {
        iswhitelisted = true;
        plugin.getLogger().info("Player " + e.getPlayer().getName() + " is already in DB.");
        resultSet.next();
        if (resultSet.getString("UUID") != null) {
          TwitterAPI.updateAccount(
              resultSet.getString("twKey"), resultSet.getString("twSecret"), e.getPlayer());
          if (resultSet.getBoolean("banned")) {
            // ban the player
            // force the server to run ban command
            String commandLine = "ban " + e.getPlayer().getName() + " Multiaccount-Ban.";
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandLine);
          }
        }
      } else {
        // nicht gewhitelistet, also sperren und nur tww befehle erlauben.
        iswhitelisted = false;
      }
    } catch (SQLException err) {
      plugin.getLogger().warning("Couldn't fetch user from db: " + err.getMessage());
    } finally {
      try {
        if (preparedStatement != null) preparedStatement.close();
      } catch (SQLException e1) {
      }
    }

    if (iswhitelisted != null && !iswhitelisted) {
      plugin
          .getLogger()
          .info(
              "Player"
                  + e.getPlayer().getName()
                  + " is NOT whitelisted, sending message to player.");
      e.getPlayer()
          .sendMessage(
              (Object) ChatColor.DARK_RED
                  + chatPrefix
                  + (Object) ChatColor.WHITE
                  + "Um auf diesem Server spielen zu können, musst du dich mithilfe eines Twitter Accounts freischalten. Dies kannst du wie folgt tun:\n"
                  + (Object) ChatColor.GOLD
                  + "/tww r");
      e.getPlayer().setGameMode(GameMode.SPECTATOR);
      unwhitelisteds.add(e.getPlayer().getUniqueId());
    } else {
      plugin.getLogger().info("Player" + e.getPlayer().getName() + " is whitelisted");
    }
  }