use of dev.espi.protectionstones.PSRegion in project ProtectionStones by espidev.
the class ArgList method executeArgument.
@Override
public boolean executeArgument(CommandSender s, String[] args, HashMap<String, String> flags) {
if (!s.hasPermission("protectionstones.list"))
return PSL.msg(s, PSL.NO_PERMISSION_LIST.msg());
if (args.length == 2 && !s.hasPermission("protectionstones.list.others"))
return PSL.msg(s, PSL.NO_PERMISSION_LIST_OTHERS.msg());
if (args.length == 2 && !UUIDCache.containsName(args[1]))
return PSL.msg(s, PSL.PLAYER_NOT_FOUND.msg());
PSPlayer psp = PSPlayer.fromPlayer((Player) s);
// run query async to reduce load
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
if (args.length == 1) {
List<PSRegion> regions = psp.getPSRegionsCrossWorld(psp.getPlayer().getWorld(), true);
display(s, regions, psp.getUuid(), true);
} else if (args.length == 2) {
UUID uuid = UUIDCache.getUUIDFromName(args[1]);
List<PSRegion> regions = PSPlayer.fromUUID(uuid).getPSRegionsCrossWorld(psp.getPlayer().getWorld(), true);
display(s, regions, uuid, false);
} else {
PSL.msg(s, PSL.LIST_HELP.msg());
}
});
return true;
}
use of dev.espi.protectionstones.PSRegion in project ProtectionStones by espidev.
the class ArgList method display.
private void display(CommandSender s, List<PSRegion> regions, UUID pUUID, boolean isCurrentPlayer) {
List<String> ownerOf = new ArrayList<>(), memberOf = new ArrayList<>();
for (PSRegion r : regions) {
if (r.isOwner(pUUID)) {
if (r.getName() == null) {
ownerOf.add(ChatColor.GRAY + "> " + ChatColor.AQUA + r.getId());
} else {
ownerOf.add(ChatColor.GRAY + "> " + ChatColor.AQUA + r.getName() + " (" + r.getId() + ")");
}
}
if (r.isMember(pUUID)) {
if (r.getName() == null) {
memberOf.add(ChatColor.GRAY + "> " + ChatColor.AQUA + r.getId());
} else {
memberOf.add(ChatColor.GRAY + "> " + ChatColor.AQUA + r.getName() + " (" + r.getId() + ")");
}
}
}
if (ownerOf.isEmpty() && memberOf.isEmpty()) {
if (isCurrentPlayer) {
PSL.msg(s, PSL.LIST_NO_REGIONS.msg());
} else {
PSL.msg(s, PSL.LIST_NO_REGIONS_PLAYER.msg().replace("%player%", UUIDCache.getNameFromUUID(pUUID)));
}
return;
}
PSL.msg(s, PSL.LIST_HEADER.msg().replace("%player%", UUIDCache.getNameFromUUID(pUUID)));
if (!ownerOf.isEmpty()) {
PSL.msg(s, PSL.LIST_OWNER.msg());
for (String str : ownerOf) s.sendMessage(str);
}
if (!memberOf.isEmpty()) {
PSL.msg(s, PSL.LIST_MEMBER.msg());
for (String str : memberOf) s.sendMessage(str);
}
}
use of dev.espi.protectionstones.PSRegion in project ProtectionStones by espidev.
the class ArgName method executeArgument.
@Override
public boolean executeArgument(CommandSender s, String[] args, HashMap<String, String> flags) {
if (!s.hasPermission("protectionstones.name")) {
PSL.msg(s, PSL.NO_PERMISSION_NAME.msg());
return true;
}
Player p = (Player) s;
PSRegion r = PSRegion.fromLocationGroup(p.getLocation());
if (r == null) {
PSL.msg(s, PSL.NOT_IN_REGION.msg());
return true;
}
if (WGUtils.hasNoAccess(r.getWGRegion(), p, WorldGuardPlugin.inst().wrapPlayer(p), false)) {
PSL.msg(s, PSL.NO_ACCESS.msg());
return true;
}
if (args.length < 2) {
PSL.msg(s, PSL.NAME_HELP.msg());
return true;
}
if (args[1].equals("none")) {
r.setName(null);
PSL.msg(p, PSL.NAME_REMOVED.msg().replace("%id%", r.getId()));
} else {
if (!ProtectionStones.getInstance().getConfigOptions().allowDuplicateRegionNames && ProtectionStones.isPSNameAlreadyUsed(args[1])) {
PSL.msg(p, PSL.NAME_TAKEN.msg().replace("%name%", args[1]));
return true;
}
r.setName(args[1]);
PSL.msg(p, PSL.NAME_SET_NAME.msg().replace("%id%", r.getId()).replace("%name%", r.getName()));
}
return true;
}
use of dev.espi.protectionstones.PSRegion in project ProtectionStones by espidev.
the class ArgAdminSetTaxAutopayers method argumentAdminSetTaxAutopayers.
static boolean argumentAdminSetTaxAutopayers(CommandSender s, String[] args) {
if (!ProtectionStones.getInstance().getConfigOptions().taxEnabled) {
return PSL.msg(s, ChatColor.RED + "Taxes are disabled! Enable it in the config.");
}
PSL.msg(s, ChatColor.GRAY + "Scanning through regions, and setting tax autopayers for regions that don't have one...");
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
WGUtils.getAllRegionManagers().forEach((w, rgm) -> {
for (ProtectedRegion r : rgm.getRegions().values()) {
PSRegion psr = PSRegion.fromWGRegion(w, r);
if (psr != null && psr.getTypeOptions() != null && psr.getTypeOptions().taxPeriod != -1 && psr.getTaxAutopayer() == null) {
if (psr.getOwners().size() >= 1) {
PSL.msg(s, ChatColor.GRAY + "Configured tax autopayer to be " + psr.getOwners().get(0).toString() + " for region " + psr.getId());
psr.setTaxAutopayer(psr.getOwners().get(0));
}
}
}
});
PSL.msg(s, ChatColor.GREEN + "Complete!");
});
return true;
}
use of dev.espi.protectionstones.PSRegion in project ProtectionStones by espidev.
the class ArgBuySell method executeArgument.
@Override
public boolean executeArgument(CommandSender s, String[] args, HashMap<String, String> flags) {
Player p = (Player) s;
if (!p.hasPermission("protectionstones.buysell")) {
PSL.msg(p, PSL.NO_PERMISSION_BUYSELL.msg());
return true;
}
if (!ProtectionStones.getInstance().isVaultSupportEnabled()) {
Bukkit.getLogger().info(ChatColor.RED + "Vault is required, but is not enabled on this server. Contact an administrator.");
s.sendMessage(ChatColor.RED + "Vault is required, but is not enabled on this server. Contact an administrator.");
return true;
}
PSRegion r = PSRegion.fromLocationGroup(p.getLocation());
if (r == null)
return PSL.msg(p, PSL.NOT_IN_REGION.msg());
if (args[0].equals("buy")) {
if (!r.forSale())
return PSL.msg(p, PSL.BUY_NOT_FOR_SALE.msg());
if ((!r.getTypeOptions().permission.equals("") && !p.hasPermission(r.getTypeOptions().permission)))
return PSL.msg(p, PSL.NO_PERMISSION_REGION_TYPE.msg());
// check if player reached region limit
if (!LimitUtil.check(p, r.getTypeOptions()))
return PSL.msg(p, PSL.REACHED_REGION_LIMIT.msg().replace("%limit%", "" + PSPlayer.fromPlayer(p).getGlobalRegionLimits()));
if (!PSPlayer.fromPlayer(p).hasAmount(r.getPrice()))
return PSL.msg(p, PSL.NOT_ENOUGH_MONEY.msg().replace("%price%", new DecimalFormat("#.##").format(r.getPrice())));
PSL.msg(p, PSL.BUY_SOLD_BUYER.msg().replace("%region%", r.getName() == null ? r.getId() : r.getName()).replace("%price%", String.format("%.2f", r.getPrice())).replace("%player%", UUIDCache.getNameFromUUID(r.getLandlord())));
if (Bukkit.getPlayer(r.getLandlord()) != null) {
PSL.msg(Bukkit.getPlayer(r.getLandlord()), PSL.BUY_SOLD_SELLER.msg().replace("%region%", r.getName() == null ? r.getId() : r.getName()).replace("%price%", String.format("%.2f", r.getPrice())).replace("%player%", p.getName()));
}
r.sell(p.getUniqueId());
} else if (args[0].equals("sell")) {
if (!r.isOwner(p.getUniqueId()))
return PSL.msg(p, PSL.NOT_OWNER.msg());
if (args.length != 2)
return PSL.msg(p, PSL.SELL_HELP.msg());
if (r.getRentStage() != PSRegion.RentStage.NOT_RENTING)
return PSL.msg(p, PSL.SELL_RENTED_OUT.msg());
if (args[1].equals("stop")) {
r.setSellable(false, null, 0);
PSL.msg(p, PSL.BUY_STOP_SELL.msg());
} else {
if (!NumberUtils.isNumber(args[1]))
return PSL.msg(p, PSL.SELL_HELP.msg());
PSL.msg(p, PSL.SELL_FOR_SALE.msg().replace("%price%", String.format("%.2f", Double.parseDouble(args[1]))));
r.setSellable(true, p.getUniqueId(), Double.parseDouble(args[1]));
}
}
return true;
}
Aggregations