@Override
 public void execute(final Player p, final String[] args) {
   if (args.length != 1) {
     p.sendMessage("§c/team ff <on/off>");
     return;
   }
   if (!TeamManager.getInstance().isOnTeam(p.getName())) {
     p.sendMessage("§cYou are not on a team.");
     return;
   }
   if (!TeamManager.getInstance().isLeader(p) && !TeamManager.getInstance().isManager(p)) {
     p.sendMessage("§cYou must be at least a manager to perform this command.");
     return;
   }
   final Team team = TeamManager.getInstance().getPlayerTeam(p);
   if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("true")) {
     if (team.isFriendlyFire()) {
       p.sendMessage("§eFriendly fire is already turned on!");
       return;
     }
     team.setFriendlyFire(true);
     TeamManager.getInstance()
         .messageTeam(team, "§6" + p.getName() + " §ehas §cenabled §efriendly fire!");
   } else {
     if (!args[0].equalsIgnoreCase("off") && !args[0].equalsIgnoreCase("false")) {
       p.sendMessage("§c/team ff <on/off>");
       return;
     }
     TeamManager.getInstance()
         .messageTeam(team, "§6" + p.getName() + " §ehas §adisabled §efriendly fire!");
   }
 }
Esempio n. 2
0
 /**
  * @param p - The player buying an item.
  * @param item - The item the player wants to buy.
  */
 public static void buyItem(Player p, Item item) {
   String key = item.getItemId() + ":" + item.getDamage();
   int amount = ITEMS.getInt(key, 0);
   if (amount == -1) {
     p.sendMessage(WShop.PRE + "The server does not sell that item at this time.");
     return;
   }
   if (amount < item.getAmount()) {
     p.sendMessage(WShop.PRE + "The server does not have that much of " + key);
     return;
   } // end if
   double price = PRICES.getDouble(key + "_buy", -1);
   if (price == -1) {
     p.sendMessage(WShop.PRE + "The server does not sell that item at this time." + key);
     return;
   }
   if (canPay(p, price)) {
     payPlayer(p, -price); // Make sure we charge them here, not pay them. Negate the price.
     p.giveItem(item);
     ITEMS.setInt(key, amount - item.getAmount());
     p.sendMessage(
         WShop.PRE
             + "Bought an item. ID:"
             + item.getItemId()
             + ", Damage:"
             + item.getDamage()
             + ", Amount:"
             + item.getAmount()
             + ", Cost:"
             + price);
   } else {
     p.sendMessage(WShop.PRE + "You do not have enough money to buy " + key);
     return;
   }
 } // end buyItem
  public boolean cast(Player player, String[] command) {
    if (removeReagents(player, reagents)) {
      // reagents removed - cast spell

      // get targeted block
      HitBlox hit = new HitBlox(player);
      Block target = hit.getTargetBlock();

      // remove blocks around target block
      Server s = etc.getServer();
      for (int x = target.getX() - BLAST_RADIUS; x <= target.getX() + BLAST_RADIUS; x++) {
        for (int y = target.getY() - BLAST_RADIUS; y <= target.getY() + BLAST_RADIUS; y++) {
          for (int z = target.getZ() - BLAST_RADIUS; z <= target.getZ() + BLAST_RADIUS; z++) {
            s.setBlockAt(0, x, y, z);
          }
        }
      }

      // send alerts
      player.sendMessage(TEXT_COLOR + STR_CAST);
      sendMessageToPlayersInRange(player, STR_CAST_OTHERS);

      return true;
    } else {
      // reagents missing
      player.sendMessage(TEXT_COLOR + STR_NO_REAGENTS);
      return false;
    }
  }
Esempio n. 4
0
 private void displayCommand(Command c, Player p) {
   p.sendMessage("-------------Command Arguments---------------");
   p.sendMessage("--------------------------------------------");
   for (Argument arg : c.listArguments()) {
     p.sendMessage(arg.toString());
   }
 }
Esempio n. 5
0
 public static void sendInfo(Player p, Item item) {
   String key = item.getItemId() + ":" + item.getDamage();
   p.sendMessage(WShop.PRE + key);
   p.sendMessage(WShop.PRE + "Price (sell): " + PRICES.getDouble(key + "_sell", -1));
   p.sendMessage(WShop.PRE + "Price (buy): " + PRICES.getDouble(key + "_buy", -1));
   p.sendMessage(WShop.PRE + "Amount: " + ITEMS.getInt(key, 0));
 }
 public boolean onCommand(Player player, String[] split) {
   if (!player.canUseCommand(split[0])) {
     return false;
   }
   if (split[0].equalsIgnoreCase("/saveStargate")) {
     if (split.length == 5) {
       StargateData.Savestargate(player, split);
     }
     return true;
   } else if (split[0].equalsIgnoreCase("/listStargates")) {
     // world.setBlockAt(20,(int)Math.floor(player.getX()),(int)Math.floor(player.getY()),(int)Math.floor(player.getZ()));
     return true;
   } else if (split[0].equalsIgnoreCase("/removeStargate")) {
     boolean worked = false;
     if (split.length > 1) {}
     if (worked) {
       player.sendMessage("Stargate removed");
     } else {
       player.sendMessage("Failed to remove Stargate");
     }
     return true;
   } else {
     return false;
   }
 }
Esempio n. 7
0
  private void displayCategory(Category c, Player p) {
    p.sendMessage("----Available Commands and Sub-Categories----");
    p.sendMessage("-----------------------------------------");
    for (Command com : c.listCommands()) {
      p.sendMessage(com.toString());
    }

    for (Category subCat : c.listCategories()) {
      p.sendMessage(subCat.toString());
    }
  }
Esempio n. 8
0
	public boolean CrapsSign(Player player, Sign sign){
		String line2string = null;
		double line2 = 0;
		if(sign.getText(3).equalsIgnoreCase("GLOBAL")){
			if(player.canUseCommand("/scplaceglobal") || player.canUseCommand("/scadmin")){
				sign.setText(3, "GLOBAL");
			}
			else{
				if(!SC.SCD.canPlaceSign(2, player.getName())){
					player.sendMessage("[�ign��s�no] You have too many '�RAPS' signs");
					NoPlaceSign(sign);
					return false;
				}
				if(player.getName().length() > 15){
					SC.SCD.setNameFix(player.getName().substring(0, 15), player.getName());
					sign.setText(3, player.getName().substring(0, 15));
				}
				else{
					sign.setText(3, player.getName());
				}
			}
		}
		else{
			if(!SC.SCD.canPlaceSign(2, player.getName())){
				player.sendMessage("[�ign��s�no] You have too many '�RAPS' signs");
				NoPlaceSign(sign);
				return false;
			}
			if(player.getName().length() > 15){
				SC.SCD.setNameFix(player.getName().substring(0, 15), player.getName());
				sign.setText(3, player.getName().substring(0, 15));
			}
			else{
				sign.setText(3, player.getName());
			}
		}
		sign.setText(0, "�CRAPS]");
		if (!sign.getText(1).equals("")) {
			try {
				line2string = sign.getText(1);
				line2 = Double.parseDouble(line2string);
			}catch (NumberFormatException NFE) {
				if(SCD.dCo){
					player.sendMessage("[�ign��s�no]�Invalid '�ET�. Auto-setting 'BET' to '�+SCD.priceForm(SCD.AB)+"�");
					sign.setText(1, "�+SCD.priceForm(SCD.AB));
				}
				else{
					player.sendMessage("[�ign��s�no]�Invalid '�ET�. Auto-setting 'BET' to '�+((int)SCD.AB)+"�");
					sign.setText(1, "�+((int)SCD.AB));
				}
			}
Esempio n. 9
0
  /**
   * Event handler for block placements
   *
   * @param event that happened
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void blockPlace(BlockPlaceEvent event) {

    /*
     *******************************
     * Call getApplicableLand(location)
     * If it's null the action didn't happen on owned land
     * and could be ignored.
     *******************************
     */
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlock().getLocation());
    if (land == null) {
      return;
    }

    // get the player associated with the event. (Might want to check for null if applicable to the
    // event)
    Player p = event.getPlayer();

    /*
     *************************************
     * Finally check if the player has permission for your flag
     * with land.hasPermTo(player, this) ('this' representing this flag of course)
     * If they have permission to do the action you're checking for, you shouldn't
     * have to cancel the event.
     *************************************
     */
    if (!land.hasPermTo(p, this)) {
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.blockPlace"));
      event.setCancelled(true);
    }
  }
Esempio n. 10
0
  @EventHandler(priority = EventPriority.HIGH)
  public void protectBlockStates(PlayerInteractEvent event) {
    Material[] blockedItems = {
      Material.NOTE_BLOCK,
      Material.REDSTONE_COMPARATOR_OFF,
      Material.REDSTONE_COMPARATOR_ON,
      Material.DIODE_BLOCK_OFF,
      Material.DIODE_BLOCK_ON,
      Material.FLOWER_POT,
      Material.CAKE_BLOCK,
      Material.DAYLIGHT_DETECTOR,
      Material.DAYLIGHT_DETECTOR_INVERTED
    };
    if (event.getClickedBlock() == null) {
      return;
    }
    Player p = event.getPlayer();
    // System.out.println(event.getClickedBlock().getType());
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && Arrays.asList(blockedItems).contains(event.getClickedBlock().getType())) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }

      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.blockStateChange"));
      event.setCancelled(true);
    }
  }
Esempio n. 11
0
  @EventHandler(priority = EventPriority.HIGH)
  public void removeItemFromFrame(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();

    if (!victim.getType().equals(EntityType.ITEM_FRAME)) {
      return;
    }
    Player p;
    Entity attacker = event.getDamager();
    // System.out.println("Attacker: "+attacker.getType().toString());
    if (attacker.getType().toString().equals("PLAYER")) {
      p = (Player) attacker;

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithMelee"));
        event.setCancelled(true);
      }

    } else if (attacker.getType().toString().equals("ARROW")) {
      Arrow a = (Arrow) attacker;
      if (a.getShooter() instanceof Player) {
        p = (Player) a.getShooter();
      } else {
        return;
      }

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithArrow"));
        event.setCancelled(true);
      }
    }
  }
Esempio n. 12
0
  @EventHandler(priority = EventPriority.HIGH)
  public void CropTrampleOrFireCharge(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
      return;
    }

    Player p = event.getPlayer();

    // trampling crops
    if (p != null
        && event.getAction().equals(Action.PHYSICAL)
        && event.getClickedBlock().getType().toString().equals("SOIL")) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.cropDestroy"));
      event.setCancelled(true);
      return;
    }

    // Using fire charge
    ItemStack item = event.getItem();
    if (p != null
        && item != null
        && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && event.getItem().getType().equals(Material.FIREBALL)) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.useFireCharge"));
      event.setCancelled(true);
    }
  }
Esempio n. 13
0
 public boolean onBlockCreate(
     Player player, Block blockPlaced, Block blockClicked, int itemInHand) {
   if ((itemInHand == 283) && player.canUseCommand("/saveStargate")) {
     Integer whichPoint =
         StargateData.setPoint(
             player.getName(), blockClicked.getX(), blockClicked.getY(), blockClicked.getZ());
     if (whichPoint == 2) {
       player.sendMessage("First corner of teleport area set");
     } else if (whichPoint == 3) {
       player.sendMessage("Second corner of teleport area set");
     } else if (whichPoint == 4) {
       player.sendMessage("First corner of landing area set");
     } else {
       player.sendMessage("Second corner of landing area set");
     }
     return true;
   }
   return false;
 }
Esempio n. 14
0
    public boolean onCommand(Player player, String[] split) {
      if (!player.canUseCommand(split[0])) return false;
      if (split[0].equalsIgnoreCase("/ion_cannon")) {
        if (cannons.containsKey(player.getName())) {
          player.sendMessage("Ion Cannon has been disabled.");
          cannons.remove(player.getName());
        } else {
          int size = 3;
          if (split.length > 1) size = Integer.parseInt(split[1]);
          if (size < 1) size = 1;
          player.sendMessage(" :: WARNING :: ION CANNON LOADED");
          player.sendMessage(" :: WARNING :: BEAM SIZE: " + size);

          cannons.put(player.getName(), size);
        }
        return true;
      }
      return false;
    }
 public boolean onBlockBreak(Player player, Block block) {
   if (block.blockType == Block.Type.WallSign) {
     // remove sensor with that sign location
     SensorBlock s = GetSensorAt(new Location(block.getX(), block.getY(), block.getZ()));
     if (s != null) {
       mSensorList.remove(s);
       player.sendMessage(mMessagePrefix + "You removed a sensor.");
       Save();
     }
   }
   return false;
 }
Esempio n. 16
0
  @EventHandler(priority = EventPriority.HIGH)
  public void destroyArmorStand(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();
    // System.out.println("Victim: "+victim);
    if (!victim.getType().equals(EntityType.ARMOR_STAND)) {
      return;
    }

    OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
    if (land == null) {
      return;
    }

    if (event.getDamager().getType().equals(EntityType.PLAYER)) {
      Player attacker = (Player) event.getDamager();
      // System.out.println(attacker.getName());
      if (!land.hasPermTo(attacker, this)) {
        attacker.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.breakArmorStandWithMelee"));
        event.setCancelled(true);
      }
    }
    if (event.getDamager().getType().equals(EntityType.ARROW)) {
      Arrow projectile = (Arrow) event.getDamager();
      if (projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        if (!land.hasPermTo(attacker, this)) {
          attacker.sendMessage(
              ChatColor.RED
                  + getPlugin()
                      .getMessageConfig()
                      .getString("event.build.breakArmorStandWithArrow"));
          event.setCancelled(true);
        }
      }
    }
    // System.out.println(event.getDamager().getType());

  }
Esempio n. 17
0
 /**
  * @param p - The player trying to sell.
  * @param item - The item to sell, commonly the players help item.
  */
 public static void sellItem(Player p, Item item) {
   String key = item.getItemId() + ":" + item.getDamage();
   double price = PRICES.getDouble(key + "_sell", -1);
   if (price == -1) {
     p.sendMessage(WShop.PRE + "The server does not buy that item at this time.");
     return;
   }
   int amount = ITEMS.getInt(key, 0);
   p.getInventory().removeItem(item);
   ITEMS.setInt(key, amount + item.getAmount());
   payPlayer(p, price);
   return;
 } // end sellItem
Esempio n. 18
0
  private boolean deductIConomy(Player player) {
    if (!iData.iExist()) {
      Stargate.log(Level.WARNING, "iConomy payment selected but iConomy does not exist");
      return true;
    }

    if (money > 0) {
      iData icon = new iData();
      int balance = icon.getBalance(player.getName());
      String deducted = icon.settings.getString("money-deducted", "");
      String coin = icon.settings.getString("money-name", "");
      String receive = icon.settings.getString("money-receive", "");

      if (balance >= money) {
        String[] recipient = destination.split(" ", 2);
        icon.setBalance(player.getName(), balance - money);
        if (!deducted.isEmpty()) player.sendMessage(String.format(deducted, money + coin));

        if ((recipient.length > 0) && (recipient[0].equalsIgnoreCase("player"))) {
          if ((recipient.length > 1) && (icon.hasBalance(recipient[1]))) {
            balance = icon.getBalance(recipient[1]);
            icon.setBalance(recipient[1], balance + money);

            if (!receive.isEmpty()) player.sendMessage(String.format(receive, money + coin));
          } else {
            Stargate.log(
                Level.WARNING,
                "cost-destination set to player but specified player does not exist or was not defined");
          }
        }

        return true;
      } else {
        return false;
      }
    }

    return true;
  }
Esempio n. 19
0
 public static void sendHelp(Player p) {
   p.sendMessage(WShop.PRE + "=== WShop Help ===");
   p.sendMessage(WShop.PRE + "");
   p.sendMessage(WShop.PRE + "/ws sell - Sell held item.");
   p.sendMessage(WShop.PRE + "/ws buy <amount> <id | name> [damage]");
   p.sendMessage(WShop.PRE + "");
   p.sendMessage(WShop.PRE + "=== WShop Help ===");
 } // end sendHelp
Esempio n. 20
0
  @EventHandler(priority = EventPriority.HIGH)
  public void liquidFill(PlayerBucketFillEvent event) {
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlockClicked().getLocation());
    if (land == null) {
      return;
    }
    Player p = event.getPlayer();

    if (!land.hasPermTo(p, this)) {
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.bucketFill"));
      event.setCancelled(true);
    }
  }
Esempio n. 21
0
  @EventHandler(priority = EventPriority.HIGH)
  public void paintingFramePlace(HangingPlaceEvent event) {
    org.bukkit.entity.Entity placer = event.getPlayer();
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlock().getLocation());
    if (land == null) {
      return;
    }

    if (placer.getType().toString().equals("PLAYER")) {
      Player p = (Player) placer;
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.paintingPlace"));
        event.setCancelled(true);
      }
    }
  }
Esempio n. 22
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
Esempio n. 23
0
  @EventHandler(priority = EventPriority.HIGH)
  public void paintingFrameBreak(HangingBreakByEntityEvent event) {
    org.bukkit.entity.Entity victim = event.getEntity();
    org.bukkit.entity.Entity remover = event.getRemover();
    OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
    if (land == null) {
      return;
    }
    if (remover.getType().toString().equals("PLAYER")) {
      Player p = (Player) remover;
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.hangingBreak"));
        event.setCancelled(true);
      }
      // System.out.println("Attacker Name:" + p.getName());

    }
  }
Esempio n. 24
0
 @EventHandler(priority = EventPriority.HIGH)
 public void removeItemFromFrame(PlayerInteractEntityEvent event) {
   Entity entity = event.getRightClicked();
   Player p = event.getPlayer();
   if (!entity.getType().equals(EntityType.ITEM_FRAME)) {
     return;
   }
   ItemFrame iFrame = (ItemFrame) entity;
   if (iFrame.getItem() != null && !iFrame.getItem().getType().equals(Material.AIR)) return;
   OwnedLand land = OwnedLand.getApplicableLand(entity.getLocation());
   if (land == null) {
     return;
   }
   if (!land.hasPermTo(p, this)) {
     p.sendMessage(
         ChatColor.RED
             + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveDirectly"));
     event.setCancelled(true);
   }
 }
Esempio n. 25
0
    public void runeCreated(Player player, Block blockPlaced, Block blockClicked, int itemInHand) {
      int[][][] steps = {
        {{4, 4, 4, 4, 4}, {4, 0, 0, 4, 4}, {4, 50, 4, 67, 4}, {4, 0, 0, 0, 4}, {4, 4, 4, 4, 4}},
        {{4, 4, 4, 4, 4}, {4, 4, 67, 0, 4}, {4, 0, 4, 0, 4}, {4, 0, 50, 0, 4}, {4, 4, 4, 4, 4}},
        {{4, 4, 4, 4, 4}, {4, 0, 0, 0, 4}, {4, 67, 4, 50, 4}, {4, 4, 0, 0, 4}, {4, 4, 4, 4, 4}},
        {{4, 4, 4, 4, 4}, {4, 0, 50, 0, 4}, {4, 0, 4, 0, 4}, {4, 0, 67, 4, 4}, {4, 4, 4, 4, 4}}
      };

      player.sendMessage("StairTower!");
      for (int y = 0; y < 16; y++)
        for (int x = 0; x < 5; x++)
          for (int z = 0; z < 5; z++) {
            if (y >= 2 || (z != 4 || x != 2))
              etc.getServer()
                  .setBlockAt(
                      steps[y % 4][z][x],
                      blockClicked.getX() + x - 2,
                      blockClicked.getY() + 1 + y,
                      blockClicked.getZ() + z - 2);
          }
    }
Esempio n. 26
0
 public void onArmSwing(Player player) {
   // If holding a block, left click to place anywhere!
   if ((player.canUseCommand("/ion_cannon")) && (cannons.containsKey(player.getName()))) {
     HitBlox blox = new HitBlox(player);
     Block block = blox.getTargetBlock();
     if (block == null) return;
     player.sendMessage("BOOM");
     int size = ((Integer) cannons.get(player.getName())).intValue();
     cannons.remove(player.getName());
     // int beamType = 1;
     int beamType = 46;
     int borderType = 57;
     // int i = block.getY();
     for (int i = 0; i < 128; i++) {
       circleMidpoint(block.getX(), block.getZ(), size, i, borderType);
       circleMidpoint(block.getX(), block.getZ(), size - 1, i, beamType);
     }
     circleMidpoint(block.getX(), block.getZ(), size, 0, 7);
     cylinderModpoint(block.getX(), block.getZ(), size + 1, 0, 7);
     etc.getServer().setBlockAt(51, block.getX(), 127, block.getZ());
   }
 }
  public boolean onSignChange(Player player, Sign sign) {
    int max_length = 10;

    String[] line0split = sign.getText(0).split(" ");
    if (line0split.length >= 1
        && line0split.length <= 3
        && line0split[0].equalsIgnoreCase("[SENSOR]")) {
      // interpret sign
      try {
        // read params
        int length = max_length;
        if (line0split.length >= 2) {
          int l = new Integer(line0split[1]);
          if (l < max_length && l > 0) {
            length = l;
          }
        }

        int duration = 0;
        if (line0split.length >= 3) {
          int d = new Integer(line0split[2]);
          if (d >= -2) duration = d;
        }

        SensorBlock.SignOrientation o = SensorBlock.SignOrientation.SOUTH;
        int data = sign.getBlock().getData();
        if (data == 0x2) o = SensorBlock.SignOrientation.EAST;
        else if (data == 0x3) o = SensorBlock.SignOrientation.WEST;
        else if (data == 0x4) o = SensorBlock.SignOrientation.NORTH;
        else if (data == 0x5) o = SensorBlock.SignOrientation.SOUTH;
        else {
          Logger.getLogger("Minecraft").severe("Invalid sign data: " + data);
          throw new RuntimeException("Invalid sign data.");
        }
        String extra = sign.getText(1) + sign.getText(2) + sign.getText(3);
        SensorBlock s =
            new SensorBlock(
                new Location(sign.getX(), sign.getY(), sign.getZ()), o, length, duration, extra);
        mSensorList.add(s);

        player.sendMessage(mMessagePrefix + "You created a sensor.");
        if (etc.getServer().getBlockAt(sign.getX(), sign.getY() - 1, sign.getZ()).blockType
            != Block.Type.Lever) {
          player.sendMessage(
              mMessagePrefix
                  + "Now place a §fLever "
                  + mMessageColor
                  + "underneath the sign post.");
        }
        sign.setText(0, "[SENSOR] " + length + " " + duration);
        if (s.IsTriggeringAny()) sign.setText(1, "*");
        sign.update();
        Save();
      } catch (NumberFormatException e) {
        player.sendMessage(
            mMessagePrefix
                + "Invalid sign format. See §f/towndefense help sensor "
                + mMessageColor
                + " for help.");
      }
    }
    return false;
  }
Esempio n. 28
0
  public static boolean onCommand(Player player, String[] split) {
    String ItemID;
    String ItemsFilep1 = "plugins/config/iExchange/GroupPrices/";
    String ItemsFilep2 = "sell.txt";

    if (split.length == 2) {
      player.sendMessage("§e[iExchange] §bUsage is /iex sell [Item] [Amount]");
      return true;
    } else {
      String Numberof = null;
      Inventory inventory = player.getInventory();
      if (split.length > 3) {
        Numberof = split[3];
      }
      int amount = 0;

      if (Numberof != null) {
        try {
          amount = Integer.parseInt(Numberof);
        } catch (NumberFormatException localNumberFormatException) {
          player.sendMessage("§e[iExchage] §cERROR 409: CONFLICT");
          player.sendMessage("§c(You didn't enter a proper number)");
          return true;
        }
      } else {
        amount = 1;
      }
      if (amount <= 0) {
        player.sendMessage("§e[iExchage] §cERROR 409: CONFLICT");
        player.sendMessage("§c(You entered a number less than 1)");
        return true;
      }
      ItemID = split[2].toUpperCase();
      ArrayList<String> ITEMPRICES = new ArrayList<String>();
      String[] group = player.getGroups();
      try {
        BufferedReader in =
            new BufferedReader(new FileReader(ItemsFilep1 + group[0] + ItemsFilep2));
        String str;
        while ((str = in.readLine()) != null) {
          String Upped = str.toUpperCase();
          String[] CheckName = Upped.split(":");
          if (CheckName[0].equals(ItemID)) {
            ITEMPRICES.add(str.toString());
          }
        }
        in.close();
      } catch (IOException e) {
        player.sendMessage("§e[iExchange] §cERROR 404: SellPriceList Not Found ");
        player.sendMessage("§c(the SellPriceList for your group does not exist)");
        player.sendMessage("§c(ask a ADMIN or the SERVER OWNER to correct the issue)");
        return true;
      }
      if (!(ITEMPRICES.isEmpty())) {
        String ItemIDS = ITEMPRICES.toString();
        String[] Item = ItemIDS.split(":");
        String PricePrice = Item[2].replace("]", "");
        int ID = 0;
        int price = 0;
        int damage = 0;
        try {
          ID = Integer.parseInt(Item[1]);
        } catch (NumberFormatException localNumberFormatException) {
          player.sendMessage("§e[iExchange] §cERROR 404: ITEM NOT FOUND!");
          player.sendMessage("§c(Props file error! Yell at your ADMIN or SERVER OWNER)");
          ITEMPRICES.clear();
          return true;
        }
        Item itemd = new Item();
        if ((ID == 6)
            || (ID == 17)
            || (ID == 18)
            || (ID == 35)
            || (ID == 44)
            || (ID == 98)
            || (ID == 263)
            || (ID == 351)
            || (ID == 358)) {
          damage = Integer.parseInt(Item[2]);
          if (Item[3].contains(",")) {
            String[] unfuck = Item[3].split(",");
            PricePrice = unfuck[0];
            itemd = new Item(ID, amount, -1, damage);
          } else {
            PricePrice = Item[3].replace("]", "");
            itemd = new Item(ID, amount, -1, damage);
          }
        } else {
          if (Item[2].contains(",")) {
            String[] unfuck = Item[2].split(",");
            PricePrice = unfuck[0];
          } else {
            PricePrice = Item[2].replace("]", "");
          }
          itemd = new Item(ID, amount);
        }
        try {
          price = Integer.parseInt(PricePrice);
        } catch (NumberFormatException localNumberFormatException) {
          player.sendMessage("§e[iExchange] §cERROR 404: PRICE NOT FOUND!");
          player.sendMessage("§c(Props file error! Yell at your ADMIN or SERVER OWNER)");
          ITEMPRICES.clear();
          return true;
        }
        String ItemItem = Item[0].replace("[", "");
        String ItemGave = ItemItem.toUpperCase();
        if (inventory.hasItem(itemd.getItemId())) {
          if ((ID == 6)
              || (ID == 17)
              || (ID == 18)
              || (ID == 35)
              || (ID == 44)
              || (ID == 98)
              || (ID == 263)
              || (ID == 351)
              || (ID == 358)) {
            int i = -1;
            int scan = -1;
            int invamount = 0;
            while (scan < 37) {
              scan++;
              if (inventory.getItemFromSlot(scan) != null) {
                Item itemcheck = inventory.getItemFromSlot(scan);
                int id1 = itemd.getItemId();
                int id2 = itemcheck.getItemId();
                int d1 = itemd.getDamage();
                int d2 = itemcheck.getDamage();
                int icA = itemcheck.getAmount();
                if ((id1 == id2) && (d1 == d2)) {
                  invamount += icA;
                }
              }
            }
            if (invamount < amount) {
              player.sendMessage("§e[iExchange] §cERROR 404: AMOUNT NOT FOUND!");
              player.sendMessage("§cYou don't have that much!");
              ITEMPRICES.clear();
              return true;
            }
            while (i <= 40) {
              i++;
              if (inventory.getItemFromSlot(i) != null) {
                Item item2 = inventory.getItemFromSlot(i);
                int id1 = itemd.getItemId();
                int id2 = item2.getItemId();
                int d1 = itemd.getDamage();
                int d2 = item2.getDamage();
                if ((id1 == id2) && (d1 == d2)) {
                  if (amount > 0) {
                    int oldamount = item2.getAmount();
                    int newamount = (oldamount - amount);
                    if (newamount <= 0) {
                      inventory.removeItem(i);
                      inventory.update();
                      amount -= oldamount;
                    } else {
                      inventory.removeItem(i);
                      inventory.setSlot(itemd.getItemId(), newamount, d1, i);
                      inventory.update();
                      amount -= oldamount;
                    }
                  } else {
                    break;
                  }
                }
              }
            }
            if (Numberof != null) {
              amount = Integer.parseInt(Numberof);
            } else {
              amount = 1;
            }
            etc.getLoader()
                .callCustomHook(
                    "iBalance", new Object[] {"deposit", player.getName(), (price * amount)});
            player.sendMessage(
                "§e[iExchange] §2" + amount + " " + ItemGave + " §bsold for §2$" + price * amount);
            ITEMPRICES.clear();
            return true;
          } else if (ID != 0) {
            int scan = -1;
            int invamount = 0;
            while (scan < 37) {
              scan++;
              if (inventory.getItemFromSlot(scan) != null) {
                Item itemcheck = inventory.getItemFromSlot(scan);
                int id1 = itemd.getItemId();
                int id2 = itemcheck.getItemId();
                int icA = itemcheck.getAmount();
                if (id1 == id2) {
                  invamount += icA;
                }
              }
            }
            if (invamount < amount) {
              player.sendMessage("§e[iExchange] §cERROR 404: AMOUNT NOT FOUND!");
              player.sendMessage("§cYou don't have that much!");
              ITEMPRICES.clear();
              return true;
            }
            int i = -1;
            while (i <= 40) {
              i++;
              if (inventory.getItemFromSlot(i) != null) {
                Item item2 = inventory.getItemFromSlot(i);
                int id1 = itemd.getItemId();
                int id2 = item2.getItemId();
                if ((id1 == id2)) {
                  if (amount > 0) {
                    int oldamount = item2.getAmount();
                    int newamount = (oldamount - amount);
                    if (newamount <= 0) {
                      inventory.removeItem(i);
                      inventory.update();
                      amount -= oldamount;
                    } else {
                      inventory.removeItem(i);
                      inventory.setSlot(itemd.getItemId(), newamount, i);
                      inventory.update();
                      amount -= oldamount;
                    }
                  } else {
                    break;
                  }
                }
              }
            }
            if (Numberof != null) {
              amount = Integer.parseInt(Numberof);
            } else {
              amount = 1;
            }
            etc.getLoader()
                .callCustomHook(
                    "iBalance", new Object[] {"deposit", player.getName(), (price * amount)});
            player.sendMessage(
                "§e[iExchange] §2" + amount + " " + ItemGave + " §bsold for §2$" + price * amount);
            ITEMPRICES.clear();
            return true;
          }
        } else {
          player.sendMessage("§e[iExchange] §cERROR 404: ITEM NOT FOUND!");
          player.sendMessage("§cYou don't have that item!");
          ITEMPRICES.clear();
          return true;
        }
      } else {
        player.sendMessage("§e[iExchange] §cError 400: ITEM NOT ON LIST!");
        player.sendMessage("§c(check your spelling or ask an ADMIN if item is on the list)");
        ITEMPRICES.clear();
        return true;
      }
    }
    return false;
  }
 public void sendMessage(Player player, String message) {
   player.sendMessage(
       String.format("(MSG) <%s%s%s> %s", Colors.Gold, HeroSettings.name, Colors.White, message));
 }
  @Override
  public void run() {
    while (true) {
      try {
        is = new BufferedReader(new InputStreamReader(player.getSocket().getInputStream()));
        line = is.readLine();
        if (line != null) {
          int type = Message.getMessageType(line);
          System.out.println("Message type : " + type);
          List<String> message = Message.getMessage(line);

          switch (type) {

              // USER CONNECT WITH USERNAME
            case 0:
              {
                player.setNickName(message.get(1));
                System.out.println("Player set name " + message.get(1));
                player.sendMessage("user," + player.getId());

                // Client State --> Room Screen, Server Send List Room
                String roomList = "";
                for (Room r : Server.rooms) {
                  roomList +=
                      "," + r.getId() + "," + r.getName() + "," + r.getClients().size() + ", true";
                }
                player.sendMessage("roomlist" + roomList);
                break;
              }

              // USER MOVE
            case 1:
              {
                List<Player> clients = player.getRoom().getClients();
                Room room = player.getRoom();

                int row = Integer.parseInt(message.get(1));
                int col = Integer.parseInt(message.get(2));

                room.Board[row][col] = player.getId();
                List<int[]> res = room.checkWin(row, col, player.getId());

                // This user win
                String converted = "";
                if (!res.isEmpty()) {
                  for (int[] cell : res) {
                    converted += "," + cell[0] + "," + cell[1];
                  }
                  //				room.broadcastMessageWithEx(player, "win," + player.getNickName()+converted
                  // );
                  player.sendMessage("youwin" + converted);
                  player
                      .getRoom()
                      .broadcastMessageWithEx(player, "win," + player.getNickName() + converted);
                  System.out.println("Hasil :" + converted);
                }

                Player turn = clients.get((clients.indexOf(player) + 1) % clients.size());
                room.broadcastMessageToAll(
                    "move,"
                        + message.get(1)
                        + ","
                        + message.get(2)
                        + ","
                        + player.getId()
                        + ","
                        + turn.getId()
                        + ","
                        + turn.getNickName());
                System.out.println(
                    player.getNickName() + " Move to ROW : " + row + " COL : " + col);
                break;
              }

              // USER JOIN ROOM
            case 2:
              {
                Room theRoom = Server.getRoomById(Integer.parseInt(message.get(1)));
                player.setRoom(theRoom);
                player.sendMessage("user," + player.getId());
                theRoom.broadcastMessageWithEx(
                    player, "message,Server," + player.getNickName() + " joins this room ");
                if (theRoom.isStart()) {
                  theRoom.getCreator().sendMessage("canstart");
                }
                System.out.println(
                    "USer  " + player.getNickName() + " join room, room : " + theRoom.getName());
                break;
              }
              // USER CREATE ROOM
            case 3:
              {
                String roomName = message.get(1);
                player.createRoom(roomName);
                player.sendMessage("user," + player.getId());
                System.out.println(player.getNickName() + " create room, room name " + roomName);
                String roomList = "";
                for (Room r : Server.rooms) {
                  roomList +=
                      "," + r.getId() + "," + r.getName() + "," + r.getClients().size() + ", true";
                }
                Server.broadcastMessage("roomlist" + roomList);

                Room theRoom = player.getRoom();
                if (theRoom.isStart()) {
                  theRoom.getCreator().sendMessage("canstart");
                }
                break;
              }
              // PLAYER DISCONNECT
            case 4:
              {
                Room room = player.getRoom();
                try {
                  room.deleteClient(player);
                  room.broadcastMessageToAll("disconnect," + player.getNickName());
                  Server.deleteClient(this);
                  if (room.getClients().isEmpty()) {
                    Server.deletRoom(room);
                    System.out.println("Current Rooms on Server :" + Server.rooms);
                  } else if (message.get(1).equals("ingame")) {
                    List<Player> clients = room.getClients();
                    Player turn = clients.get((clients.indexOf(player) + 1) % clients.size());
                    room.broadcastMessageToAll("turn," + turn.getId() + "," + turn.getNickName());
                  } else if (room.isCreator(player)) {
                    // Change the creator
                    Player newCreator =
                        room.getClients().get(room.getClients().indexOf(player) + 1);
                    room.setCreator(newCreator);
                    newCreator.sendMessage("newcreator");
                  } else {
                    // Check the number to start still sufficient
                    if (room.isStart()) {
                      room.getCreator().sendMessage("canstart");
                    } else {
                      room.getCreator().sendMessage("cantstart");
                    }
                  }

                } catch (NullPointerException ex) {
                  System.out.println(player.getNickName() + " has Disconnected");
                }
                System.out.println(player.getNickName() + " Has DISCONNECTED");
                break;
              }

              // GET START SIGNAL FROM CREATOR
            case 5:
              {
                System.out.println("Get Start Game Signal");
                Room room = player.getRoom();
                room.broadcastMessageToAll("start," + player.getId() + "," + player.getNickName());
                break;
              }

              //			 JOIN ROOM TO SPECTATE
            case 6:
              {
                Room theRoom = Server.getRoomById(Integer.parseInt(message.get(1)));
                player.setRoomAsSpectator(theRoom);
                player.sendMessage("spectate," + player.getId());
                theRoom.broadcastMessageToSpectatorsWithEx(
                    player, "message,Server," + player.getNickName() + " Spectates This Room ");
                System.out.println(
                    "Uuer  "
                        + player.getNickName()
                        + " spectate room, room : "
                        + theRoom.getName());
                break;
              }

              // Spectator Disconnect
            case 7:
              {
                Room room = player.getRoom();
                try {
                  room.deleteSpectator(player);
                  room.broadcastMessageToSpectators("disconnect," + player.getNickName());
                  Server.deleteClient(this);
                } catch (NullPointerException ex) {
                  System.out.println(player.getNickName() + " has Disconnected");
                }
                System.out.println(player.getNickName() + " Has DISCONNECTED");
                break;
              }

              // CHAT WITH OTHER SPECTATORS
            case 8:
              {
                Room room = player.getRoom();
                room.broadcastMessageToSpectators(
                    "message," + player.getNickName() + "," + message.get(1));
                System.out.println("BroadCast Message SPECTATOR " + message.get(1));
                break;
              }

            case -1:
              {
                Room room = player.getRoom();
                room.broadcastMessageToPlayers(
                    "message," + player.getNickName() + "," + message.get(0));
                System.out.println("BroadCast Message " + message.get(0));
                break;
              }
          }
          // Stop thread
          if (type == 4 || type == 7) {
            break;
          }
        }
      } catch (IOException ex) {
        ex.printStackTrace();
        System.out.println("I/O fail");
        System.exit(-1);
      }
    }
  }