Exemplo n.º 1
0
 @Subscribe
 public void onRedstoneEvent(BlockRedstoneUpdateEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Location loc = SpongeUtil.getLocation(block);
   if (loc == null || !PS.get().isPlotWorld(loc.getWorld())) {
     return;
   }
   Plot plot = MainUtil.getPlot(loc);
   if (plot == null || !plot.hasOwner()) {
     return;
   }
   if (event.getOldSignalStrength() > event.getNewSignalStrength()) {
     return;
   }
   if (Settings.REDSTONE_DISABLER) {
     if (UUIDHandler.getPlayer(plot.owner) == null) {
       boolean disable = true;
       for (UUID trusted : plot.getTrusted()) {
         if (UUIDHandler.getPlayer(trusted) != null) {
           disable = false;
           break;
         }
       }
       if (disable) {
         event.setNewSignalStrength(0);
         return;
       }
     }
   }
   Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
   if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
     event.setNewSignalStrength(0);
     // TODO only disable clocks
   }
 }
Exemplo n.º 2
0
 @Override
 public PlotPlayer wrapPlayer(Object obj) {
   if (obj instanceof Player) {
     return SpongeUtil.getPlayer((Player) obj);
   }
   //        else if (obj instanceof OfflinePlayer) {
   //            return BukkitUtil.getPlayer((OfflinePlayer) obj);
   //        }
   else if (obj instanceof String) {
     return UUIDHandler.getPlayer((String) obj);
   } else if (obj instanceof UUID) {
     return UUIDHandler.getPlayer((UUID) obj);
   }
   return null;
 }
Exemplo n.º 3
0
  public static boolean plotEntry(final PlotPlayer pp, final Plot plot) {
    if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
      return false;
    }
    Plot last = pp.getMeta("lastplot");
    if ((last != null) && !last.getId().equals(plot.getId())) {
      plotExit(pp, last);
    }
    if (ExpireManager.IMP != null) {
      ExpireManager.IMP.handleEntry(pp, plot);
    }
    pp.setMeta("lastplot", plot);
    EventUtil.manager.callEntry(pp, plot);
    if (plot.hasOwner()) {
      HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
      int size = flags.size();
      boolean titles = Settings.TITLES;
      final String greeting;

      if (size != 0) {
        Flag titleFlag = flags.get("titles");
        if (titleFlag != null) {
          titles = (Boolean) titleFlag.getValue();
        }
        Flag greetingFlag = flags.get("greeting");
        if (greetingFlag != null) {
          greeting = (String) greetingFlag.getValue();
          MainUtil.format(
              C.PREFIX_GREETING.s() + greeting,
              plot,
              pp,
              false,
              new RunnableVal<String>() {
                @Override
                public void run(String value) {
                  MainUtil.sendMessage(pp, value);
                }
              });
        } else {
          greeting = "";
        }
        Flag enter = flags.get("notify-enter");
        if (enter != null && (Boolean) enter.getValue()) {
          if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
            for (UUID uuid : plot.getOwners()) {
              PlotPlayer owner = UUIDHandler.getPlayer(uuid);
              if (owner != null && !owner.getUUID().equals(pp.getUUID())) {
                MainUtil.sendMessage(
                    owner,
                    C.NOTIFY_ENTER
                        .s()
                        .replace("%player", pp.getName())
                        .replace("%plot", plot.getId().toString()));
              }
            }
          }
        }
        Flag gamemodeFlag = flags.get("gamemode");
        if (gamemodeFlag != null) {
          if (pp.getGameMode() != gamemodeFlag.getValue()) {
            if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
              pp.setGameMode((PlotGameMode) gamemodeFlag.getValue());
            } else {
              MainUtil.sendMessage(
                  pp,
                  StringMan.replaceAll(
                      C.GAMEMODE_WAS_BYPASSED.s(),
                      "{plot}",
                      plot.getId(),
                      "{gamemode}",
                      gamemodeFlag.getValue()));
            }
          }
        }
        Flag flyFlag = flags.get("fly");
        if (flyFlag != null) {
          pp.setFlight((boolean) flyFlag.getValue());
        }
        Flag timeFlag = flags.get("time");
        if (timeFlag != null) {
          try {
            long time = (long) timeFlag.getValue();
            pp.setTime(time);
          } catch (Exception e) {
            FlagManager.removePlotFlag(plot, "time");
          }
        }
        Flag weatherFlag = flags.get("weather");
        if (weatherFlag != null) {
          pp.setWeather((PlotWeather) weatherFlag.getValue());
        }

        Flag musicFlag = flags.get("music");
        if (musicFlag != null) {
          Integer id = (Integer) musicFlag.getValue();
          if ((id >= 2256 && id <= 2267) || (id == 0)) {
            Location loc = pp.getLocation();
            Location lastLoc = pp.getMeta("music");
            if (lastLoc != null) {
              pp.playMusic(lastLoc, 0);
              if (id == 0) {
                pp.deleteMeta("music");
              }
            }
            if (id != 0) {
              try {
                pp.setMeta("music", loc);
                pp.playMusic(loc, id);
              } catch (Exception ignored) {
              }
            }
          }
        } else {
          Location lastLoc = pp.getMeta("music");
          if (lastLoc != null) {
            pp.deleteMeta("music");
            pp.playMusic(lastLoc, 0);
          }
        }
        CommentManager.sendTitle(pp, plot);
      } else if (titles) {
        greeting = "";
      } else {
        return true;
      }
      if (titles) {
        if (!C.TITLE_ENTERED_PLOT.s().isEmpty() || !C.TITLE_ENTERED_PLOT_SUB.s().isEmpty()) {
          TaskManager.runTaskLaterAsync(
              new Runnable() {
                @Override
                public void run() {
                  Plot lastPlot = pp.getMeta("lastplot");
                  if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
                    Map<String, String> replacements = new HashMap<>();
                    replacements.put("%x%", lastPlot.getId().x + "");
                    replacements.put("%z%", lastPlot.getId().y + "");
                    replacements.put("%world%", plot.getArea().toString());
                    replacements.put("%greeting%", greeting);
                    replacements.put("%alias", plot.toString());
                    replacements.put("%s", MainUtil.getName(plot.owner));
                    String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements);
                    String sub =
                        StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements);
                    AbstractTitle.sendTitle(pp, main, sub);
                  }
                }
              },
              20);
        }
      }
      return true;
    }
    return true;
  }
Exemplo n.º 4
0
 public static boolean plotExit(final PlotPlayer pp, Plot plot) {
   pp.deleteMeta("lastplot");
   EventUtil.manager.callLeave(pp, plot);
   if (plot.hasOwner()) {
     PlotArea pw = plot.getArea();
     if (pw == null) {
       return true;
     }
     if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) {
       if (pp.getGameMode() != pw.GAMEMODE) {
         if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
           pp.setGameMode(pw.GAMEMODE);
         } else {
           MainUtil.sendMessage(
               pp,
               StringMan.replaceAll(
                   C.GAMEMODE_WAS_BYPASSED.s(),
                   "{plot}",
                   plot.toString(),
                   "{gamemode}",
                   pw.GAMEMODE.name().toLowerCase()));
         }
       }
     }
     Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell");
     if (farewell != null) {
       MainUtil.format(
           C.PREFIX_FAREWELL.s() + farewell.getValueString(),
           plot,
           pp,
           false,
           new RunnableVal<String>() {
             @Override
             public void run(String value) {
               MainUtil.sendMessage(pp, value);
             }
           });
     }
     Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
     if ((leave != null) && (Boolean) leave.getValue()) {
       if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
         for (UUID uuid : plot.getOwners()) {
           PlotPlayer owner = UUIDHandler.getPlayer(uuid);
           if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
             MainUtil.sendMessage(
                 pp,
                 C.NOTIFY_LEAVE
                     .s()
                     .replace("%player", pp.getName())
                     .replace("%plot", plot.getId().toString()));
           }
         }
       }
     }
     if (FlagManager.getPlotFlagRaw(plot, "fly") != null) {
       PlotGameMode gamemode = pp.getGameMode();
       if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
         pp.setFlight(false);
       }
     }
     if (FlagManager.getPlotFlagRaw(plot, "time") != null) {
       pp.setTime(Long.MAX_VALUE);
     }
     if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
       pp.setWeather(PlotWeather.RESET);
     }
     Location lastLoc = pp.getMeta("music");
     if (lastLoc != null) {
       pp.deleteMeta("music");
       pp.playMusic(lastLoc, 0);
     }
   }
   return true;
 }
Exemplo n.º 5
0
  @Override
  public boolean onCommand(final PlotPlayer plr, final String[] args) {

    final Location loc = plr.getLocationFull();
    final Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      return !sendMessage(plr, C.NOT_IN_PLOT);
    }
    if ((plot == null) || !plot.hasOwner()) {
      MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
      return false;
    }
    final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
    if (!plot.isOwner(plr.getUUID()) && !admin) {
      MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
      return false;
    }
    int direction = -1;
    if (args.length == 0) {
      switch (direction(plr.getLocationFull().getYaw())) {
        case "NORTH":
          direction = 0;
          break;
        case "EAST":
          direction = 1;
          break;
        case "SOUTH":
          direction = 2;
          break;
        case "WEST":
          direction = 3;
          break;
      }
    } else {
      for (int i = 0; i < values.length; i++) {
        if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
          direction = i;
          break;
        }
      }
    }
    if (direction == -1) {
      MainUtil.sendMessage(
          plr,
          C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
      MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
      return false;
    }
    PlotId bot = MainUtil.getBottomPlot(plot).id;
    PlotId top = MainUtil.getTopPlot(plot).id;
    ArrayList<PlotId> selPlots;
    final String world = loc.getWorld();
    switch (direction) {
      case 0: // north = -y
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
        break;
      case 1: // east = +x
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
        break;
      case 2: // south = +y
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
        break;
      case 3: // west = -x
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
        break;
      default:
        return false;
    }
    int size = selPlots.size();
    if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
      MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
      return false;
    }
    final PlotId botId = selPlots.get(0);
    final PlotId topId = selPlots.get(selPlots.size() - 1);
    final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
    final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
    final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
    final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
    bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
    top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
    final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
    boolean multiMerge = false;
    final HashSet<UUID> multiUUID = new HashSet<UUID>();
    HashSet<PlotId> multiPlots = new HashSet<>();
    final UUID u1 = plot.owner;
    for (final PlotId myid : plots) {
      final Plot myplot = PS.get().getPlot(world, myid);
      if (myplot == null || myplot.owner == null) {
        MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
        return false;
      }
      UUID u2 = myplot.owner;
      if (u2.equals(u1)) {
        continue;
      }
      PlotPlayer p2 = UUIDHandler.getPlayer(u2);
      if (p2 == null) {
        MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
        return false;
      }
      multiMerge = true;
      multiPlots.add(myid);
      multiUUID.add(u2);
    }
    if (multiMerge) {
      if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
        MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
        return false;
      }
      for (final UUID uuid : multiUUID) {
        PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
        CmdConfirm.addPending(
            accepter,
            C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()),
            new Runnable() {
              @Override
              public void run() {
                PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
                multiUUID.remove(uuid);
                if (multiUUID.size() == 0) {
                  PlotPlayer pp = UUIDHandler.getPlayer(u1);
                  if (pp == null) {
                    sendMessage(accepter, C.MERGE_NOT_VALID);
                    return;
                  }
                  final PlotWorld plotWorld = PS.get().getPlotWorld(world);
                  if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
                    double cost = plotWorld.MERGE_PRICE;
                    cost = plots.size() * cost;
                    if (cost > 0d) {
                      if (EconHandler.manager.getMoney(plr) < cost) {
                        sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
                        return;
                      }
                      EconHandler.manager.withdrawMoney(plr, cost);
                      sendMessage(plr, C.REMOVED_BALANCE, cost + "");
                    }
                  }
                  final boolean result = EventUtil.manager.callMerge(world, plot, plots);
                  if (!result) {
                    MainUtil.sendMessage(plr, "&cMerge has been cancelled");
                    return;
                  }
                  MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
                  MainUtil.mergePlots(world, plots, true, true);
                  MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
                }
                MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
              }
            });
      }
      MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
      return true;
    }
    final PlotWorld plotWorld = PS.get().getPlotWorld(world);
    if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
      double cost = plotWorld.MERGE_PRICE;
      cost = plots.size() * cost;
      if (cost > 0d) {
        if (EconHandler.manager.getMoney(plr) < cost) {
          sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
          return false;
        }
        EconHandler.manager.withdrawMoney(plr, cost);
        sendMessage(plr, C.REMOVED_BALANCE, cost + "");
      }
    }
    final boolean result = EventUtil.manager.callMerge(world, plot, plots);
    if (!result) {
      MainUtil.sendMessage(plr, "&cMerge has been cancelled");
      return false;
    }
    MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
    MainUtil.mergePlots(world, plots, true, true);
    MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
    return true;
  }