use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.
the class AbstractManage method create.
@Override
protected void create() {
List<String> regenerateDesc = lm.getStringList("Commands.Manage.Regenerate.description");
List<String> greetDesc = lm.getStringList("Commands.Manage.SetGreet.description");
List<String> farewellDesc = lm.getStringList("Commands.Manage.SetFarewell.description");
int position = 0;
if (regions.size() < 1)
return;
OwnedLand land = regions.get(0);
for (LLFlag iFlag : land.getFlags()) {
// For every IFlag of the land we wanna display an icon in the gui IF the flag is enabled for change
String flagName = iFlag.getWGFlag().getName();
String title = lm.getRawString("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".title");
List<String> description = lm.getStringList("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".description");
if (plugin.getConfig().getBoolean("Manage." + flagName + ".enable")) {
int finalPosition = position;
this.setIcon(position, new Icon(createItem(iFlag.getMaterial(), 1, title, formatList(description, iFlag.getStatus()))).addClickAction((p, icon) -> {
for (OwnedLand region : regions) {
for (LLFlag llFlag : region.getFlags()) {
if (llFlag.getWGFlag().equals(iFlag.getWGFlag())) {
llFlag.toggle();
}
}
}
updateLore(finalPosition, formatList(description, iFlag.getStatus()));
}));
position++;
}
}
// Reminder: Regenerate is not implemented in Manageall, cos it might cos some trouble. Calculating costs might be a bit tedious
if (plugin.getConfig().getBoolean("Manage.regenerate.enable") && regions.size() == 1) {
double cost = plugin.getConfig().getDouble("ResetCost");
this.setIcon(position, new Icon(createItem(Material.BARRIER, 1, lm.getRawString("Commands.Manage.Regenerate.title"), formatList(regenerateDesc, (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")))).addClickAction((p, ic) -> {
if (land.isOwner(player.getUniqueId())) {
ConfirmationGUI confi = new ConfirmationGUI(p, lm.getRawString("Commands.Manage.Regenerate.confirmation").replace("%cost%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")), (p1, ic1) -> {
boolean flag = false;
if (Options.isVaultEnabled())
if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
plugin.getVaultHandler().take(player.getUniqueId(), cost);
flag = true;
} else
player.sendMessage(lm.getString("Commands.Manage.Regenerate.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)).replace("%name%", land.getName()));
else
flag = true;
if (flag) {
if (land.isOwner(player.getUniqueId())) {
player.getWorld().regenerateChunk(land.getChunk().getX(), land.getChunk().getZ());
player.sendMessage(lm.getString("Commands.Manage.Regenerate.success").replace("%land%", land.getName()));
display();
}
}
}, (p2, ic2) -> {
player.sendMessage(lm.getString("Commands.Manage.Regenerate.abort").replace("%land%", land.getName()));
display();
}, this);
confi.setConfirm(lm.getRawString("Confirmation.accept"));
confi.setDecline(lm.getRawString("Confirmation.decline"));
confi.display();
}
}));
position++;
}
// Set greet icon
if (plugin.getConfig().getBoolean("Manage.setgreet.enable")) {
String currentGreet = land.getWGLand().getFlag(DefaultFlag.GREET_MESSAGE);
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setgreet.item")), 1, lm.getRawString("Commands.Manage.SetGreet.title"), formatList(greetDesc, currentGreet))).addClickAction(((p, ic) -> {
p.closeInventory();
ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetGreet.clickMsg"));
if (regions.size() > 1)
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreetall "));
else
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreet "));
p.spigot().sendMessage(builder.create());
})));
position++;
}
// TODO add functionality for manageall
if (plugin.getConfig().getBoolean("Manage.mob-spawning.enable")) {
String title = lm.getRawString("Commands.Manage.AllowMob-spawning.title");
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.mob-spawning.item")), 1, title, lm.getStringList("Commands.Manage.AllowMob-spawning.description"))).addClickAction((p, icon) -> {
// Open a new gui with spawneggs where you can manage the spawns by clicking on them
List<Icon> icons = new ArrayList<>();
EntityType[] types = EntityType.values();
List<String> lore = lm.getStringList("Commands.Manage.AllowMob-spawning.toggleItem.description");
MultiPagedGUI gui = new MultiPagedGUI(p, 4, title, icons, this) {
};
for (EntityType t : types) {
if (t.isAlive() && t.isSpawnable()) {
if (!toggleMobs.contains(t.name()))
continue;
ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
SpawnEggMeta meta = (SpawnEggMeta) spawnEgg.getItemMeta();
meta.setSpawnedType(t);
meta.setDisplayName(lm.getRawString("Commands.Manage.AllowMob-spawning.toggleItem.title").replace("%mob%", t.name()));
Set<EntityType> flag = land.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
String state;
if (flag != null)
state = (flag.contains(t) ? "DENY" : "ALLOW");
else
state = "ALLOW";
List<String> formattedLore = new ArrayList<>();
for (String s : lore) {
formattedLore.add(s.replace("%mob%", t.name()).replace("%value%", state));
}
meta.setLore(formattedLore);
spawnEgg.setItemMeta(meta);
Icon ic = new Icon(spawnEgg).addClickAction((clickingPlayer, ic3) -> {
for (OwnedLand region : regions) {
Set<EntityType> localFlag = region.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
// Toggle spawning of specific mob
if (localFlag != null) {
if (localFlag.contains(t))
localFlag.remove(t);
else
localFlag.add(t);
} else {
Set<EntityType> set = new HashSet<>();
set.add(t);
region.getWGLand().setFlag(DefaultFlag.DENY_SPAWN, set);
}
}
// update icon text
String iconState;
if (flag != null)
iconState = (flag.contains(t) ? "DENY" : "ALLOW");
else
iconState = "ALLOW";
List<String> newLore = new ArrayList<>();
for (String s : lore) {
newLore.add(s.replace("%mob%", t.name()).replace("%value%", iconState));
}
// System.out.println(newLore + " :" + finalIconPos);
ic3.setLore(newLore);
gui.refresh();
});
icons.add(ic);
}
}
gui.display();
}));
position++;
}
// set farewell icon
if (plugin.getConfig().getBoolean("Manage.setfarewell.enable")) {
String currentFarewell = land.getWGLand().getFlag(DefaultFlag.FAREWELL_MESSAGE);
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setfarewell.item")), 1, lm.getRawString("Commands.Manage.SetFarewell.title"), formatList(farewellDesc, currentFarewell))).addClickAction(((p, icon) -> {
p.closeInventory();
ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetFarewell.clickMsg"));
if (regions.size() > 1)
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewellall "));
else
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewell "));
p.spigot().sendMessage(builder.create());
})));
position++;
}
// set friends icon
if (plugin.getConfig().getBoolean("Manage.friends.enable")) {
ItemStack skull = createSkull(player.getName(), lm.getRawString("Commands.Manage.ManageFriends.title"), lm.getStringList("Commands.Manage.ManageFriends.description"));
Set<UUID> friends = land.getWGLand().getMembers().getUniqueIds();
MultiPagedGUI friendsGui = new MultiPagedGUI(player, (int) Math.ceil((double) friends.size() / 9.0), lm.getRawString("Commands.Manage.ManageFriends.title"), new ArrayList<>(), this) {
};
friends.forEach(id -> friendsGui.addIcon(new Icon(createSkull(Bukkit.getOfflinePlayer(id).getName(), Bukkit.getOfflinePlayer(id).getName(), formatFriendsSegment(id))).addClickAction((player, icon) -> {
ConfirmationGUI confirmationGUI = new ConfirmationGUI(player, lm.getRawString("Commands.Manage.ManageFriends.unfriend").replace("%player%", Bukkit.getOfflinePlayer(id).getName()), (p, ic1) -> {
friendsGui.removeIcon(friendsGui.filter(Bukkit.getOfflinePlayer(id).getName()).get(0));
if (regions.size() > 1)
Bukkit.dispatchCommand(player, "land unfriendall " + Bukkit.getOfflinePlayer(id).getName());
else
Bukkit.dispatchCommand(player, "land unfriend " + Bukkit.getOfflinePlayer(id).getName());
player.closeInventory();
friendsGui.display();
}, (p, ic2) -> {
player.closeInventory();
friendsGui.display();
}, friendsGui);
confirmationGUI.setConfirm(lm.getRawString("Confirmation.accept"));
confirmationGUI.setDecline(lm.getRawString("Confirmation.decline"));
confirmationGUI.display();
})));
this.setIcon(position, new Icon(skull).setName(lm.getRawString("Commands.Manage.ManageFriends.title")).addClickAction((p, ic) -> friendsGui.display()));
position++;
}
if (plugin.getConfig().getBoolean("Manage.unclaim.enable")) {
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.unclaim.item")), 1, lm.getRawString("Commands.Manage.Unclaim.title"), lm.getStringList("Commands.Manage.Unclaim.description"))).addClickAction(((player1, icon) -> {
ConfirmationGUI gui = new ConfirmationGUI(player1, lm.getRawString("Commands.Manage.Unclaim.confirmationTitle").replace("%land%", land.getName()), (p, ic2) -> {
if (regions.size() > 1)
Bukkit.dispatchCommand(p, "ll unclaimall");
else
Bukkit.dispatchCommand(p, "ll unclaim " + land.getName());
p.closeInventory();
}, (p, ic) -> {
p.closeInventory();
display();
}, this);
gui.setConfirm(lm.getRawString("Confirmation.accept"));
gui.setDecline(lm.getRawString("Confirmation.decline"));
gui.display();
})));
position++;
}
}
use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.
the class WorldGuardHandler method setDefaultFlags.
public ProtectedCuboidRegion setDefaultFlags(ProtectedCuboidRegion region, Chunk chunk) {
OwnedLand land = new OwnedLand(region, chunk);
region.setFlag(DefaultFlag.FAREWELL_MESSAGE, Landlord.getInstance().getLangManager().getRawString("Alerts.defaultFarewell").replace("%owner%", land.printOwners()));
region.setFlag(DefaultFlag.GREET_MESSAGE, Landlord.getInstance().getLangManager().getRawString("Alerts.defaultGreeting").replace("%owner%", land.printOwners()));
List<String> flaggy = Landlord.getInstance().getConfig().getStringList("Flags");
Set<String> flags = new HashSet<>();
flaggy.forEach(s -> flags.add(s.split(" ")[0]));
// Iterate over all existing flags
for (Flag<?> flag : DefaultFlag.getFlags()) {
if (flag instanceof StateFlag) {
boolean failed = false;
if (flags.contains(flag.getName())) {
// Filters the config list for the right line and split that line in the mid at :
String[] rules = flaggy.stream().filter(s -> s.startsWith(flag.getName())).findFirst().get().split(":");
if (rules.length == 2) {
String[] defSplit = rules[0].split(" ");
if (defSplit.length == 3) {
StateFlag.State state = StateFlag.State.valueOf(defSplit[1].toUpperCase());
if (defSplit[2].equals("nonmembers"))
region.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
region.setFlag((StateFlag) flag, state);
} else {
failed = true;
}
} else {
failed = true;
}
}
if (failed) {
Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
break;
}
}
}
return region;
}
use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.
the class Claim method onClaim.
public void onClaim(Player player) {
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
String landname = chunk.getWorld().getName() + "_" + chunk.getX() + "_" + chunk.getZ();
// Check if there is an overlapping wg-region
if (!plugin.getWgHandler().canClaim(player, chunk)) {
if (plugin.getPlayerManager().getOffer(landname) == null && !Util.isInactive(pr.getOwner())) {
player.sendMessage(lm.getString("Commands.Claim.notAllowed"));
return;
}
}
if (pr != null) {
if (pr.getOwner().equals(player.getUniqueId())) {
// cannot buy own land
player.sendMessage(lm.getString("Commands.Claim.alreadyClaimed").replace("%owner%", pr.printOwners()));
return;
}
Offers offer = plugin.getPlayerManager().getOffer(pr.getName());
if (!Util.isInactive(pr.getOwner()) && offer == null) {
player.sendMessage(lm.getString("Commands.Claim.notYetInactive").replace("%owner%", pr.printOwners()).replace("%days%", "" + Util.getInactiveRemainingDays(pr.getOwner())));
return;
}
}
int regionCount = plugin.getWgHandler().getWG().getRegionManager(player.getWorld()).getRegionCountOfPlayer(plugin.getWgHandler().getWG().wrapPlayer(player));
List<Integer> limitlist = plugin.getConfig().getIntegerList("limits");
if (!player.hasPermission("landlord.limit.override")) {
int highestAllowedLandCount = -1;
for (Integer integer : limitlist) {
if (regionCount <= integer)
if (player.hasPermission("landlord.limit." + integer)) {
highestAllowedLandCount = integer;
}
}
if (regionCount >= highestAllowedLandCount) {
player.sendMessage(lm.getString("Commands.Claim.hardcap").replace("%regions%", highestAllowedLandCount + ""));
return;
}
}
if (plugin.getConfig().getBoolean("Shop.enable") && Options.isVaultEnabled()) {
int claims = plugin.getPlayerManager().get(player.getUniqueId()).getClaims();
if (regionCount >= claims) {
ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Claim.limit").replace("%regions%", regionCount + "").replace("%claims%", claims + "")).color(ChatColor.YELLOW).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ll shop"));
player.spigot().sendMessage(builder.create());
return;
}
}
LandPreClaimEvent event = new LandPreClaimEvent(player, chunk);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (plugin.getConfig().getBoolean("CommandSettings.Claim.claimOnlyAdjacent")) {
// Only allow claiming of adjacent chunks
int amountOfOwnedLands = plugin.getWgHandler().getRegionCountOfPlayer(player.getUniqueId());
if (amountOfOwnedLands > 0) {
// Get adjacent lands of the land, which a player wants to claim.
// Only when one of the 4 adjacent is already owned, allow to claim
World world = player.getWorld();
OwnedLand[] adjLands = new OwnedLand[4];
adjLands[0] = plugin.getLand(world.getChunkAt(chunk.getX() + 1, chunk.getZ()));
adjLands[1] = plugin.getLand(world.getChunkAt(chunk.getX() - 1, chunk.getZ()));
adjLands[2] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() + 1));
adjLands[3] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() - 1));
boolean hasNearbyLand = false;
for (OwnedLand adjLand : adjLands) {
if (adjLand != null) {
if (adjLand.isOwner(player.getUniqueId())) {
hasNearbyLand = true;
break;
}
}
}
if (!hasNearbyLand) {
// no nearby land is already claimed => Display error msg
player.sendMessage(lm.getString("Commands.Claim.onlyClaimAdjacentChunks").replace("%land%", OwnedLand.getName(chunk)));
return;
}
}
}
if (plugin.getConfig().getBoolean("CommandSettings.Claim.needsGapBetweenOwners")) {
// Get adjacent lands of the land, which a player wants to claim.
// Only when all of the 4 adj lands are either owned by the player or are free => allow the claim
World world = player.getWorld();
OwnedLand[] adjLands = new OwnedLand[4];
adjLands[0] = plugin.getLand(world.getChunkAt(chunk.getX() + 1, chunk.getZ()));
adjLands[1] = plugin.getLand(world.getChunkAt(chunk.getX() - 1, chunk.getZ()));
adjLands[2] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() + 1));
adjLands[3] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() - 1));
boolean differentOwner = false;
for (OwnedLand adjLand : adjLands) {
if (adjLand != null) {
if (!adjLand.isOwner(player.getUniqueId())) {
differentOwner = true;
break;
}
}
}
if (differentOwner) {
// one of the nearby lands is not owned by the player nor its free
player.sendMessage(lm.getString("Commands.Claim.needsGap").replace("%land%", OwnedLand.getName(chunk)));
return;
}
}
boolean moneyFlag = false;
// Money stuff
if (Options.isVaultEnabled()) {
if (pr != null && Util.isInactive(pr.getOwner())) {
// Inactive sale
double costForBuyer = plugin.getCostManager().calculateCost(player.getUniqueId());
double payBackForInactive = plugin.getCostManager().calculateCost(pr.getOwner());
String originalOwner = Bukkit.getOfflinePlayer(pr.getOwner()).getName();
if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), costForBuyer)) {
plugin.getVaultHandler().take(player.getUniqueId(), costForBuyer);
plugin.getVaultHandler().give(pr.getOwner(), payBackForInactive);
pr.getWGLand().getOwners().clear();
pr.getWGLand().getOwners().addPlayer(player.getUniqueId());
player.sendMessage(lm.getString("Commands.Claim.boughtUp").replace("%player%", originalOwner).replace("%price%", Util.formatCash(costForBuyer)).replace("%chunk%", pr.getName()));
OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
plugin.getMapManager().updateAll();
return;
} else {
// Not enough money
player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", Util.formatCash(costForBuyer)).replace("%chunk%", OwnedLand.getName(chunk)));
return;
}
}
Offers offer = plugin.getPlayerManager().getOffer(landname);
if (offer != null && pr != null) {
// Player 2 player sale
if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), offer.getPrice())) {
String sellDesc = pr.getName() + " | " + plugin.getVaultHandler().format(offer.getPrice());
ConfirmationGUI confirm = new ConfirmationGUI(player, sellDesc, (player1, icon) -> {
plugin.getVaultHandler().take(player.getUniqueId(), offer.getPrice());
plugin.getVaultHandler().give(offer.getSeller(), offer.getPrice());
plugin.getPlayerManager().removeOffer(offer.getLandname());
pr.getWGLand().getOwners().clear();
pr.getWGLand().getOwners().addPlayer(player.getUniqueId());
player.sendMessage(lm.getString("Commands.Claim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()));
if (Bukkit.getPlayer(offer.getSeller()).isOnline()) {
Bukkit.getPlayer(offer.getSeller()).sendMessage(lm.getString("Commands.Claim.p2pSuccess").replace("%player%", player1.getName()).replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()).replace("%price%", plugin.getVaultHandler().format(offer.getPrice())));
}
OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
plugin.getMapManager().updateAll();
player.closeInventory();
}, (player12, ic2) -> {
player.sendMessage(lm.getString("Commands.Claim.aborted"));
player.closeInventory();
}, null);
confirm.display();
} else {
// Not enough money
player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", plugin.getVaultHandler().format(offer.getPrice())).replace("%chunk%", OwnedLand.getName(chunk)));
return;
}
} else {
// Normal sale
moneyFlag = true;
double calculatedCost = plugin.getCostManager().calculateCost(player.getUniqueId());
if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), calculatedCost)) {
plugin.getVaultHandler().take(player.getUniqueId(), calculatedCost);
if (calculatedCost > 0)
player.sendMessage(lm.getString("Commands.Claim.moneyTook").replace("%money%", plugin.getVaultHandler().format(calculatedCost)).replace("%chunk%", OwnedLand.getName(chunk)));
} else {
// NOT ENOUGH MONEY
player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", plugin.getVaultHandler().format(calculatedCost)).replace("%chunk%", OwnedLand.getName(chunk)));
return;
}
}
} else {
// flag is always true, if eco is disabled
moneyFlag = true;
}
if (moneyFlag) {
plugin.getWgHandler().claim(chunk, player.getUniqueId());
player.sendMessage(lm.getString("Commands.Claim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()));
OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
if (plugin.getConfig().getBoolean("Homes.enable")) {
if (plugin.getPlayerManager().get(player.getUniqueId()).getHome() == null)
Bukkit.dispatchCommand(player, "ll sethome");
}
if (plugin.getConfig().getBoolean("CommandSettings.Claim.enableDelimit")) {
delimit(chunk);
}
plugin.getMapManager().updateAll();
LandPostClaimEvent postEvent = new LandPostClaimEvent(player, plugin.getLand(chunk));
Bukkit.getPluginManager().callEvent(postEvent);
}
}
}
use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.
the class Unclaim method onUnclaim.
public void onUnclaim(Player player, String chunkname) {
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = null;
if (chunkname.equals("null")) {
chunk = player.getWorld().getChunkAt(player.getLocation());
} else {
String[] split = chunkname.split("_");
try {
if (split.length != 3) {
Bukkit.dispatchCommand(player, "/ll help");
return;
}
int x = Integer.valueOf(split[1]);
int z = Integer.valueOf(split[2]);
chunk = Bukkit.getWorld(split[0]).getChunkAt(x, z);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
if (pr == null) {
player.sendMessage(lm.getString("Commands.Unclaim.notOwnFreeLand"));
return;
}
// is admin - allowed to unclaim
boolean isAdmin = false;
if (!player.hasPermission("landlord.admin.unclaim")) {
if (!pr.isOwner(player.getUniqueId())) {
player.sendMessage(lm.getString("Commands.Unclaim.notOwn").replace("%owner%", pr.printOwners()));
return;
}
} else
isAdmin = true;
// Normal unclaim
LandUnclaimEvent event = new LandUnclaimEvent(player, pr);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
double payback = -1;
if (!isAdmin || pr.isOwner(player.getUniqueId())) {
int regionCount = plugin.getWgHandler().getRegionCountOfPlayer(player.getUniqueId());
int freeLands = plugin.getConfig().getInt("Freelands");
if (Options.isVaultEnabled()) {
if (regionCount <= freeLands)
payback = 0;
else {
payback = plugin.getCostManager().calculateCost(player.getUniqueId()) * plugin.getConfig().getDouble("Payback");
// System.out.println(payback);
if (payback > 0)
plugin.getVaultHandler().give(player.getUniqueId(), payback);
}
}
}
plugin.getWgHandler().unclaim(player.getWorld(), pr.getName());
// remove possible homes
LPlayer lPlayer = plugin.getPlayerManager().get(pr.getOwner());
if (lPlayer != null) {
Location home = lPlayer.getHome();
if (home != null) {
if (pr.getWGLand().contains(home.getBlockX(), home.getBlockY(), home.getBlockZ())) {
player.sendMessage(lm.getString("Commands.SetHome.removed"));
plugin.getPlayerManager().get(pr.getOwner()).setHome(null);
}
}
}
// Remove possible advertisements
plugin.getPlayerManager().removeOffer(pr.getName());
player.sendMessage(lm.getString("Commands.Unclaim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()).replace("%money%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(payback) : "-eco disabled-")));
plugin.getMapManager().updateAll();
}
}
use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.
the class Advertise method onAdvertise.
public void onAdvertise(Player player, String landname, double price) {
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = null;
if (landname.equals("this")) {
chunk = player.getWorld().getChunkAt(player.getLocation());
} else {
String[] split = landname.split("_");
try {
int x = Integer.valueOf(split[1]);
int z = Integer.valueOf(split[2]);
chunk = Bukkit.getWorld(split[0]).getChunkAt(x, z);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
if (pr == null) {
player.sendMessage(lm.getString("Commands.Advertise.notOwnFreeLand"));
return;
}
if (!pr.isOwner(player.getUniqueId())) {
player.sendMessage(lm.getString("Commands.Advertise.notOwn").replace("%owner%", pr.printOwners()));
return;
}
Offers offer = new Offers(pr.getName(), price, player.getUniqueId());
plugin.getPlayerManager().addOffer(offer);
player.sendMessage(lm.getString("Commands.Advertise.success").replace("%landname%", pr.getName()).replace("%price%", price + ""));
}
Aggregations