Пример #1
0
 public JSONMessage bankItemTooltip(BankItem item) {
   String itemName;
   if (item.getItem().getItemMeta().hasDisplayName())
     itemName = item.getItem().getItemMeta().getDisplayName();
   else itemName = Items.itemByStack(item.getItem()).getName();
   ItemMeta meta = item.getItem().getItemMeta();
   String loreString = "{id:" + item.getItem().getTypeId() + ",tag:";
   loreString = loreString + "{display:{Name:" + Messaging.colorize(itemName);
   if (meta.hasLore()) {
     loreString = loreString + ",Lore:[\"";
     List<String> loreData = meta.getLore();
     Iterator<String> lore = loreData.iterator();
     while (lore.hasNext()) {
       String loreline = lore.next();
       loreString = loreString + loreline.replace("\"", "\\\"");
       if (lore.hasNext()) {
         loreString = loreString + "\",\"";
       } else {
         loreString = loreString + "\"]";
       }
     }
   }
   loreString = loreString + "}}}";
   loreString = loreString.replace("'", "");
   return itemTooltip(loreString);
 }
  @Override
  public boolean execute(CommandSender executor, String identifier, String[] args) {
    if (!(executor instanceof Player)) {
      Messaging.send(executor, "Can not create sub regions through console!");
      return false;
    }
    String redefineRegion = args[0];
    Player player = (Player) executor;
    Citizen citizen = getCitizen(player);
    // Get and validate the region ID
    String id = validateRegionId(redefineRegion, false);

    // Can't replace regions with this command
    RegionManager regionManager = wgp.getGlobalRegionManager().get(player.getWorld());
    if (!regionManager.hasRegion(id)) {
      Messaging.send(
          executor,
          "That region doesn't exist, use  "
              + "/town region create <childRegion> <parentRegion>"
              + id);
      return true;
    }
    ChildRegion foundRegion = null;
    if (manager.get(redefineRegion) != null
        && manager.get(redefineRegion).getName().equalsIgnoreCase(redefineRegion)) {
      Messaging.send(executor, "You can not redefine your Town region!");
      return true;
    } else {
      ChildRegion temp =
          plugin.getWorldGuardManager().getChildRegion(regionManager.getRegion(redefineRegion));
      if (temp != null && temp.getParent() instanceof Town) foundRegion = temp;
    }

    Town town = citizen.getTown();
    if (foundRegion != null && foundRegion.getParent() instanceof Town) {
      // Means we found a child region belonging to a Town
      if (!foundRegion.getParent().equals(town)) {
        town = (Town) foundRegion.getParent();
      }
    } else {
      Messaging.send(executor, "The region you want to redefine isn't part of a Town!");
      return true;
    }

    if (!manager.getRegionManager().checkOwner(player, foundRegion)) {
      Messaging.send(
          executor,
          "You aren't a Region Owner! only Region Owners or Town Mayors can redefine regions!");
      return true;
    }
    ChildRegion newRegion =
        manager.getRegionManager().redefineChildRegion(getSelection(player), foundRegion, town);

    // Delete old region
    manager.getRegionManager().addChildRegion(town, newRegion);
    plugin.getStorageManager().getStorage().saveCitizenGroup(town, false);
    plugin.getStorageManager().getStorage().saveManagerData(manager);
    Messaging.send(executor, "You have successfully redefined the region: " + id);
    return true;
  }