public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
   Player player = null;
   if (sender instanceof Player) {
     player = (Player) sender;
   }
   if (player == null) {
     sender.sendMessage("Sorry, only Players can use such commands!");
     return true;
   } else if (cmd.getName().equalsIgnoreCase("tk")) {
     if (args.length < 2 || !hasAdminAccess(sender)) {
       return false;
     }
     Player target = Bukkit.getPlayer(args[0]);
     String message = args[1];
     for (Player players : getServer().getOnlinePlayers()) {
       if (target.isOnline()) {
         String s;
         if (target.isOp()) {
           String pname = ChatColor.DARK_RED + target.getDisplayName();
           s = "[" + target.getWorld().getName() + "]<" + pname + ChatColor.WHITE + "> " + message;
           players.sendMessage(s);
         } else {
           s = "[" + target.getWorld().getName() + "]<" + target.getDisplayName() + "> " + message;
           players.sendMessage(s);
         }
         return true;
       } else {
         players.sendMessage("[world]<" + args[0] + "> " + message);
         return true;
       }
     }
   }
   return false;
 }
  public void play(byte instrument, byte note) {
    if (!player.isOnline()) {
      return;
    }

    player.playNote(loc, instrument, note);
  }
Example #3
0
 public static void clearTab(Player p) {
   if (!p.isOnline()) return;
   int a;
   String msg;
   WrappedGameProfile gameProfile;
   if (protocolManager.getProtocolVersion(p) >= 47) {
     TabHolder47 tabold = (TabHolder47) playerTabLast47.get(p.getName());
     if (tabold != null) {
       for (int b = 0; b < tabold.maxv; b++) {
         for (a = 0; a < tabold.maxh; a++) {
           msg = tabold.tabs[a][b];
           gameProfile = tabold.tabGameProfiles[a][b];
           addPacket(
               p,
               msg.substring(0, Math.min(msg.length(), 16)),
               getSlotId(b, a),
               gameProfile,
               false,
               0);
         }
       }
     }
   } else {
     TabHolder tabold = (TabHolder) playerTabLast.get(p.getName());
     if (tabold != null) {
       for (String[] s : tabold.tabs) {
         for (String message : s) {
           if (message != null) {
             addPacket(p, message.substring(0, Math.min(message.length(), 16)), 0, null, false, 0);
           }
         }
       }
     }
   }
 }
  void confiscateInventory(Player player, int ticks) {
    if (ticks < 1) {
      return;
    }

    if (player.getName().startsWith("[") || !player.isOnline() || isInventoryEmpty(player)) {
      return;
    }

    if (confiscatedInventories == null) {
      confiscatedInventories = new ArrayList<ConfiscatedInventory>();

      new BukkitRunnable() {
        @Override
        public void run() {
          for (ConfiscatedInventory cis : EventListener.confiscatedInventories) {
            cis.release();
          }

          EventListener.confiscatedInventories = null;
        }
      }.runTaskLater(this.instance, ticks);
    } else {
      // check if this player has his inventory already confiscated
      for (ConfiscatedInventory ci : confiscatedInventories) {
        if (player == ci.getPlayer()) {
          return;
        }
      }
    }
    this.instance
        .getLogger()
        .info("Confiscated " + player.getName() + " items for " + ticks + " ticks");
    confiscatedInventories.add(new ConfiscatedInventory(player));
  }
  private boolean needFirstspawn() {
    if (player.hasPlayedBefore()) return false;
    if (Spawn.getInstance().getFirstSpawn() == null
        || Spawn.getInstance().getFirstSpawn().getWorld() == null) return false;
    FirstSpawnTeleportEvent tpEvent =
        new FirstSpawnTeleportEvent(
            player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
    plugin.getServer().getPluginManager().callEvent(tpEvent);
    if (!tpEvent.isCancelled()) {
      if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
        final Location fLoc = tpEvent.getTo();
        Bukkit.getScheduler()
            .scheduleSyncDelayedTask(
                plugin,
                new Runnable() {

                  @Override
                  public void run() {
                    player.teleport(fLoc);
                  }
                });
      }
    }
    return true;
  }
Example #6
0
  public void run() {
    if (!player.isOnline()) {
      return;
    }

    Mailbox mb = plugin.getMailbox(player.getName(), false);
    if (mb != null) {
      int numUnread = mb.numUnread();

      if (numUnread > 0) {
        String s1 = numUnread == 1 ? "" : "s";
        String s2 = numUnread == 1 ? "it" : "them";
        player.sendMessage(
            ChatColor.YELLOW
                + "You have "
                + ChatColor.GREEN
                + Integer.toString(numUnread)
                + ChatColor.YELLOW
                + " unread message"
                + s1
                + ".");
        player.sendMessage(
            ChatColor.YELLOW
                + "Type "
                + ChatColor.DARK_RED
                + "/kmail read next"
                + ChatColor.YELLOW
                + " to begin reading "
                + s2
                + ".");
      }
    }

    plugin.saveMailbox(player.getName());
  }
Example #7
0
  /**
   * Increments karma by two and checks if the Player is now an outlaw
   *
   * @return true if the Player is now an Outlaw
   */
  public boolean incrementKarma(Player player) {
    // Karma does not change if the Player is offline (they logged during battle)
    if (!player.isOnline()) return false;

    karma = karma + 2;

    // Return false if the Player's Outlaw status did not change
    if (karma != outlawLevel + 1 && karma != outlawLevel + 2) return false;

    // Add the Player to the Outlaw group if there is one
    if (!outlawGroup.isEmpty()) {
      if (removeGroup) {
        // Remove the Player from their primary group
        group = PvPReward.permission.getPrimaryGroup(player);
        PvPReward.permission.playerRemoveGroup(player, group);
      }

      // Add the Player to the Outlaw group
      PvPReward.permission.playerAddGroup(player, outlawGroup);
    }

    // Set the Outlaw tag if there is one
    if (!outlawTag.isEmpty()) player.setDisplayName(outlawTag + name);

    return true;
  }
  public void addChunkLoader(ChunkLoader chunkLoader) {
    Block block =
        getServer()
            .getWorld(chunkLoader.getWorld())
            .getBlockAt(chunkLoader.getX(), chunkLoader.getY(), chunkLoader.getZ());

    ChunkLoader existing =
        chunkLoaders.stream().filter(c -> c.getBlock().equals(block)).findFirst().orElse(null);

    if (existing != null) existing.delete();

    chunkLoader.setBlock(block);

    block.setType(getChunkLoaderMaterial(chunkLoader.getChunkType()));

    getChunkLoaders().add(chunkLoader);

    chunkLoader.load();

    data.saveChunkLoader(chunkLoader);

    Player player = getServer().getPlayer(chunkLoader.getOwner());
    if (player != null && player.isOnline())
      player.sendMessage(
          String.format(
              "%sSuccessfully placed %s chunk loader with and ID of %s and %s chunks",
              ChatColor.GOLD,
              chunkLoader.getChunkType(),
              chunkLoader.getId(),
              chunkLoader.getSize()));
  }
Example #9
0
  /**
   * Decrements karma by one and checks if the Player is no longer an outlaw
   *
   * @return true if the Player is no longer an Outlaw
   */
  public boolean decrementKarma(Player player) {
    // Karma does not change if the Player is offline (they logged during battle)
    if (!player.isOnline()) return false;

    karma--;

    // Do not let karma be negative
    if (karma < 0) karma = 0;

    // Return false if the Player's Outlaw status did not change
    if (karma != outlawLevel) return false;

    // Move the Player to their previous group if they are in the Outlaw group
    if (PvPReward.permission.playerInGroup(player, outlawGroup)) {
      PvPReward.permission.playerRemoveGroup(player, outlawGroup);

      if (group != null && removeGroup) {
        PvPReward.permission.playerAddGroup(player, group);
        group = null;
      }
    }

    // Remove the Outlaw tag if being used
    if (!outlawTag.isEmpty()) player.setDisplayName(name);

    return true;
  }
Example #10
0
  public void logSevere(String message) {

    uLogger.severe(String.format("[%d] %s", Thread.currentThread().getId(), message));

    final int maxSevereLogsToDump = 10; // could consider settings, but nah!

    if (currentSevereCnt.incrementAndGet() < maxSevereLogsToDump) {

      final String dumpLogFilename = String.format("%d.dump.log", new Date().getTime());
      final String dumpLogFilePath =
          plugin.getDataFolder().toString() + File.separator + dumpLogFilename;

      try {
        PrintWriter out = new PrintWriter(dumpLogFilePath);
        out.println(String.format("[%d] %s", Thread.currentThread().getId(), message));
        out.flush();
        out.close();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }

    if (plugin.settings.devUser == null) {
      return;
    }

    final Player player = plugin.getServer().getPlayer(plugin.settings.devUser);

    if (player != null && player.isOnline()) {
      player.sendMessage(
          "Omniscient error: " + message.substring(0, Math.min(message.length() - 1, 30)));
    }
  }
Example #11
0
 @Override
 public void run() {
   if (0 < tick) {
     if (!Splatoon.MainTask.getGameStatus().equals("gametime")) {
       if (Splatoon.MainTask.getGameStatus().equals("result")) {
         this.cancel();
         return;
       }
       Utils.Respawn(player);
       this.cancel();
     }
     tick--;
     if (player == null || !player.isOnline()) {
       this.cancel();
     }
     //			double pa = 100-((count-tick)/count) *100;
     //        	setMessage(player,"復活まであと "+tick/20+"秒");
     if (tick % 20 == 0) {
       player.sendMessage(Splatoon.format + "復活まで" + ((int) tick / 20) + "秒");
     }
     //	        setHealth(player, (float) pa);
     player.getInventory().clear();
     player.updateInventory();
   } else {
     Utils.Respawn(player);
     this.cancel();
   }
 }
Example #12
0
  public void removeSpectator(Player p) {
    ArrayList<Player> players = new ArrayList<Player>();
    players.addAll(activePlayers);
    players.addAll(inactivePlayers);

    if (p.isOnline()) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        pl.showPlayer(p);
      }
    }
    // restoreInv(p);
    p.setAllowFlight(false);
    p.setFlying(false);
    p.setFallDistance(0);
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20);
    p.setSaturation(20);
    p.teleport(SettingsManager.getInstance().getLobbySpawn());
    // Bukkit.getServer().broadcastPrefixType("Removing Spec "+p.getName()+" "+spectators.size()+"
    // left");
    spectators.remove(p.getName());
    // Bukkit.getServer().broadcastPrefixType("Removed");

    nextspec.remove(p);
  }
Example #13
0
  // /lot allow <player_name>
  public void allow(Player player, String targetPlayerName) {
    PcData playerData = plugin.players.get(player.getName());
    PcData targetPlayerData = plugin.players.get(targetPlayerName);

    // Check to see if target player exists
    if (targetPlayerData == null) {
      plugin.message.sendNo(player, "Player " + targetPlayerName + " does not exist.");
      return;
    }
    // Check to see if the target player already has permission
    if (playerData.lotPermissions.contains(targetPlayerData.name)) {
      plugin.message.parseNo(
          player,
          targetPlayerData.getCodedName() + " already has permission to build in your lots.");
      return;
    }

    // All checks have succeeded - update the DB
    plugin.database.lotQueries.allow(playerData.id_Player, targetPlayerData.id_Player);

    // Update the playerData
    playerData.lotPermissions.add(targetPlayerData.name);

    // Notify both players
    plugin.message.parse(
        player, targetPlayerData.getCodedName() + " is now allowed to build in your lots.");
    Player targetPlayer = plugin.getServer().getPlayer(targetPlayerData.name);
    if (targetPlayer != null && targetPlayer.isOnline())
      plugin.message.parse(
          targetPlayer,
          playerData.getCodedName() + " has given you permission to build in his/her lots.");
  }
Example #14
0
  /**
   * Gets the region selection for the player.
   *
   * @param player
   * @return the selection or null if there was none
   */
  public Selection getSelection(Player player) {
    if (player == null) {
      throw new IllegalArgumentException("Null player not allowed");
    }
    if (!player.isOnline()) {
      throw new IllegalArgumentException("Offline player not allowed");
    }

    LocalSession session = controller.getSession(wrapPlayer(player));
    RegionSelector selector =
        session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));

    try {
      Region region = selector.getRegion();
      World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();

      if (region instanceof CuboidRegion) {
        return new CuboidSelection(world, selector, (CuboidRegion) region);
      } else if (region instanceof Polygonal2DRegion) {
        return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
      } else {
        return null;
      }
    } catch (IncompleteRegionException e) {
      return null;
    }
  }
Example #15
0
  @Override
  public void run() {

    String message = this.getMessage();

    if (this.scope.equals(ZRScope.REGION)) {

      List<String> players = Zones.getZone(this.tag).getPlayers();
      for (String x : players) {
        if (Bukkit.getPlayer(x).isOnline()) Bukkit.getPlayer(x).sendMessage(message);
      }
    } else if (this.scope.equals(ZRScope.WORLD)) {

      List<Player> players = Bukkit.getWorld(Zones.getZone(this.tag).getWorldName()).getPlayers();
      for (Player p : players) {
        if (p.isOnline()) p.sendMessage(message);
      }

    } else if (this.scope.equals(ZRScope.SERVER)) {
      Player[] players = Bukkit.getServer().getOnlinePlayers();
      for (Player player : players) {
        player.sendMessage(message);
      }
    }
  }
Example #16
0
  @Override
  public void run() {
    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
    long maxAFKTime;
    SinCityPlayer thisPlayer;
    for (Player player : players) {
      if (!player.isOnline() || player.isDead()) continue;
      thisPlayer = this.playerManager.getPlayer(player);
      maxAFKTime = this.dataManager.getMaxAFKTime(thisPlayer.getGroup());

      // WHEN AFK TIMER IS REACHED AND (PLAYER HAS NOT MOVED OR IS INSIDE
      // A VEHICLE) (PREVENT ABUSE!)
      if (maxAFKTime >= 0) {
        if (player.isInsideVehicle() || thisPlayer.hasMoved(player.getLocation())) {
          thisPlayer.setLastLocation(player.getLocation());
          return;
        }
        if (thisPlayer.isTooLongAFK(maxAFKTime)) {
          ConsoleUtils.printInfo(Core.NAME, "Kicked '" + player.getName() + "' for being AFK!");
          player.kickPlayer("Kicked being AFK!");
        }
      } else {
        thisPlayer.setLastLocation(player.getLocation());
      }
    }
  }
Example #17
0
 public void callByDisc(final Player player) {
   AICore.isDiscCalled = false;
   if (player.isOnline()) {
     CancelTarget(Core.CoreType.ANY);
     setHauntTarget(player);
   }
 }
Example #18
0
  public static void updatePlayer(Player p) {
    if (!p.isOnline()) {
      return;
    }
    r = 0;
    e = 0;
    if (protocolManager.getProtocolVersion(p) >= 47) {
      TabObject47 tabo = (TabObject47) playerTab47.get(p.getName());
      TabHolder47 tab = tabo.getTab();
      if (tab == null) {
        return;
      }

      clearTab(p);
      for (int b = 0; b < tab.maxv; b++) {
        for (int a = 0; a < tab.maxh; a++) {
          if (tab.tabs[a][b] == null) {
            tab.tabs[a][b] = nextNull();
          }
          String msg = tab.tabs[a][b];
          int ping = tab.tabPings[a][b];
          WrappedGameProfile gameProfile = tab.tabGameProfiles[a][b];
          addPacket(
              p,
              msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)),
              getSlotId(b, a),
              gameProfile,
              true,
              ping);
        }
      }
      flushPackets(p, tab.getCopy());
    } else {
      TabObject tabo = (TabObject) playerTab.get(p.getName());
      TabHolder tab = tabo.getTab();
      if (tab == null) {
        return;
      }

      clearTab(p);
      for (int b = 0; b < tab.maxv; b++) {
        for (int a = 0; a < tab.maxh; a++) {
          if (tab.tabs[a][b] == null) {
            tab.tabs[a][b] = nextNull();
          }
          String msg = tab.tabs[a][b];
          int ping = tab.tabPings[a][b];
          addPacket(
              p,
              msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)),
              0,
              null,
              true,
              ping);
        }
      }
      flushPackets(p, tab.getCopy());
    }
  }
 @Override
 public void handleKick(UUID uuid, C c) {
   Player player = Bukkit.getPlayer(uuid);
   if (player != null && player.isOnline()) {
     MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
     player.teleport(player.getWorld().getSpawnLocation());
   }
 }
 /**
  * @param temporaryTrigger the trigger used
  * @param message message to send the player if the trigger was ready ("second time used" on the
  *     past seconds)
  * @return true if it was triggered (last use was less than the threshold)
  */
 public boolean sendMessageIfTriggered(
     @NotNull final TemporaryTrigger temporaryTrigger, @Nullable final String message) {
   if (insertTriggerIfReady(temporaryTrigger)) {
     if (message != null && player.isOnline()) player.sendMessage(message);
     return true;
   }
   return false;
 }
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerBanned(final BanHammerPlayerBannedEvent event) {
   logger.log(Level.FINER, "Received " + event.getEventName());
   final Player player = this.server.getPlayerExact(event.getPlayerName());
   if (player != null && player.isOnline()) {
     player.kickPlayer(this.getKickMessage(event.getRecord()));
   }
 }
  /* Makes it so no one can see a specific player */
  public void updateInvisibleForPlayer(Player player) {
    if (player == null || !player.isOnline()) return;

    Player[] playerList = getServer().getOnlinePlayers();
    for (Player p : playerList) {
      invisible(player, p);
    }
  }
Example #23
0
 public static void sendToOnline(Packet... packets) {
   Validate.notNull(packets, "packets cannot be null");
   for (Player player : Bukkit.getOnlinePlayers()) {
     if (player == null || !player.isOnline()) continue;
     for (Packet packet : packets) {
       sendPacket(player, packet);
     }
   }
 }
 public static void notify(Player player, String message) {
   if (player.isOnline()) {
     player.sendMessage(ChatColor.BLUE + message);
   } else {
     List<String> messages = messagingConfig.getConfig().getStringList(player.getName());
     messages.add(message);
     messagingConfig.getConfig().set(player.getName(), messages);
     messagingConfig.saveConfig();
   }
 }
  public void updateChunkLoader(ChunkLoader chunkLoader) {
    data.saveChunkLoader(chunkLoader);

    Player player = getServer().getPlayer(chunkLoader.getOwner());
    if (player != null && player.isOnline())
      player.sendMessage(
          String.format(
              "%sSuccessfully updated your chunk loader. Chunks loaded are now %s",
              ChatColor.GOLD, chunkLoader.getSize()));
  }
  private void progress() {
    if (!hasEmptyWaterBottle()) {
      remove();
      return;
    }

    if (player.isDead() || !player.isOnline()) {
      remove();
      return;
    }

    if (player.getWorld() != location.getWorld()) {
      remove();
      return;
    }

    if (System.currentTimeMillis() < time + interval) return;

    time = System.currentTimeMillis();

    Vector direction = Methods.getDirection(location, player.getEyeLocation()).normalize();
    location = location.clone().add(direction);

    if (location == null || block == null) {
      remove();
      return;
    }

    if (location.getBlock().equals(block.getLocation().getBlock())) return;

    if (Methods.isRegionProtectedFromBuild(player, "WaterManipulation", location)) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation())
        > Methods.waterbendingNightAugment(range, player.getWorld())) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation()) <= 1.5) {
      fillBottle();
      return;
    }

    Block newblock = location.getBlock();
    if (Methods.isTransparentToEarthbending(player, newblock) && !newblock.isLiquid()) {
      block.revertBlock();
      block = new TempBlock(newblock, Material.WATER, full);
    } else {
      remove();
      return;
    }
  }
Example #27
0
  @Override
  protected String runAsConsole(ConsoleCommandSender sender, String[] args) {

    if (args.length == 2) {
      Player from = server.getPlayer(args[0]);
      if (from == null || !from.isOnline()) {
        return (ERROR_COLOR + "Player " + args[0] + " not found");
      }
      Player to = server.getPlayer(args[1]);
      if (to == null || !to.isOnline()) {
        return (ERROR_COLOR + "Player " + args[1] + " not found");
      }
      from.teleport(to);

      return (OK_COLOR + "Teleported " + from.getName() + " to " + to.getName());

    } else if (args.length == 4) {
      // Teleport a player to coords in their current world
      Player from = server.getPlayer(args[0]);
      if (from == null || !from.isOnline()) {
        return (ERROR_COLOR + "Player " + args[0] + " not found");
      }

      Double x;
      Double y;
      Double z;
      try {
        x = new Double(args[1]);
        y = new Double(args[2]);
        z = new Double(args[3]);
      } catch (NumberFormatException e) {
        return (ERROR_COLOR + "Invalid coordinates");
      }

      Location to = new Location(from.getWorld(), x, y, z);
      from.teleport(to);
      return (OK_COLOR + from.getName() + " has been teleported");

    } else {
      return (ERROR_COLOR + "Incorrect number of arguments");
    }
  }
Example #28
0
  public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException {

    if (!player.isOnline()) return;

    // Test and kick any players with invalid names.
    if ((player.getName().trim() == null) || (player.getName().contains(" "))) {
      player.kickPlayer("Invalid name!");
      return;
    }

    Resident resident;

    if (!getDataSource().hasResident(player.getName())) {
      getDataSource().newResident(player.getName());
      resident = getDataSource().getResident(player.getName());

      TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
      resident.setRegistered(System.currentTimeMillis());
      if (!TownySettings.getDefaultTownName().equals(""))
        try {
          Town town = getDataSource().getTown(TownySettings.getDefaultTownName());
          town.addResident(resident);
          getDataSource().saveTown(town);
        } catch (NotRegisteredException e) {
        } catch (AlreadyRegisteredException e) {
        }

      getDataSource().saveResident(resident);
      getDataSource().saveResidentList();

    } else {
      resident = getDataSource().getResident(player.getName());
      resident.setLastOnline(System.currentTimeMillis());

      getDataSource().saveResident(resident);
    }

    try {
      TownyMessaging.sendTownBoard(player, resident.getTown());
    } catch (NotRegisteredException e) {
    }

    if (isWarTime()) getWarEvent().sendScores(player, 3);

    // Schedule to setup default modes when the player has finished loading
    if (getPlugin()
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1)
        == -1)
      TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");

    setChangedNotify(PLAYER_LOGIN);
  }
Example #29
0
 public void removeScoreboard(PropHunt plugin, Player p) {
   if (p == null) {
     return;
   }
   if (!p.isOnline()) {
     return;
   }
   if (playerBoards.containsKey(p)) {
     playerBoards.remove(p);
     p.setScoreboard(plugin.getServer().getScoreboardManager().getNewScoreboard());
   }
 }
	@EventHandler(priority = EventPriority.NORMAL)
	public void onPlayerRespawn(final PlayerRespawnEvent event)
	{
		final Player player = event.getPlayer();
		if (!player.isOnline())
		{
			return;
		}
		final IUser user = userMap.getUser(player);
		user.updateCompass();
		user.updateDisplayName();
	}