mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-10-03 09:57:29 +02:00
Add permissions for landlords to add regions
Added things: - "areashop.createrent.owner", "areashop.createrent.member", "areashop.createbuy.owner" and "areashop.createbuy.member" to let players add regions to AreaShop when they are member/owner of the WorldGuard region (because they made the region for example). - "areashop.setprice.landlord" to give landlords access to setting the price for their regions - "areashop.setduration.landlord" to give landlords access to setting the duration for their regions - When "default" or "reset" is given as price then the price will be removed and therefore inherited from a group or default.yml - When "default" or "reset" is given as duration then the duration will be removed and therefore inherited from a group or default.yml
This commit is contained in:
parent
d1a3027e0b
commit
fde60e2a27
@ -97,6 +97,7 @@ limitGroups:
|
||||
## %friends% The names of friends added to this region separated by ', '
|
||||
## %friendsuuid% The UUID's of friends added to this region separated by ', '
|
||||
## %price% The price of the region formatted with the configured characters before and after the number
|
||||
## %rawprice% The price without formatting, like '10.0' or '7.77'
|
||||
## %duration% The duration of a rent region, for example '1 d', '4 minutes' or '2 years'
|
||||
## %world% The name of the world that the region is in
|
||||
## %type% The type of the region, 'rent' or 'buy'
|
||||
@ -108,7 +109,9 @@ limitGroups:
|
||||
## %timeleft% The time left on the rent (uses the unit of time that fits best, minutes used from 121 seconds till 120 minutes)
|
||||
## %clicker% The name of the player that clicked the sign (only to be used in the signProfiles section)
|
||||
## %resellprice% The price of a region when it is in resell mode
|
||||
## %rawresellprice% The resellprice without formatting, like '10.0' or '7.77'
|
||||
## %moneyback% The amount of money the player will get back when unrenting/selling the region (formatted with currency characters)
|
||||
## %rawmoneyback% The moneyback without formatting, like '10.0' or '7.77'
|
||||
## %moneybackpercent% The percentage of the price the player will get back when unrenting (only the number between 0-100)
|
||||
## %maxextends% The maximum number of extends a player can do on the region
|
||||
## %extendsleft% The number of extends that are left (maxextends - timesextended)
|
||||
|
11
lang/EN.yml
11
lang/EN.yml
@ -193,8 +193,10 @@ setprice-noPermission: "You don't have permission to change the price of a regio
|
||||
setprice-help: "/as setprice <price> [region], the region you stand in will be used if not specified."
|
||||
setprice-notRegistered: "The specified region is not registered: %0%."
|
||||
setprice-wrongPrice: "'%0%' is not a valid price."
|
||||
setprice-successRent: "Price of region %0% changed to %1% per %2%."
|
||||
setprice-successBuy: "Price of region %0% changed to %1%."
|
||||
setprice-successRent: "Price of region %region% changed to %price% per %duration%."
|
||||
setprice-successBuy: "Price of region %region% changed to %price%."
|
||||
setprice-successRemoved: "Price of %region% has been removed, it will now use the price from a group or the default.yml file, new price: %price%."
|
||||
setprice-noLandlord: "You don't have permission to change the price because you are not the landlord of %region%."
|
||||
|
||||
setduration-noPermission: "You don't have permission to change the duration of a rent."
|
||||
setduration-help: "/as setduration <amount> <identifier> [region], the region you stand in will be used if not specified."
|
||||
@ -202,6 +204,8 @@ setduration-notRegistered: "%0% is not registered for renting."
|
||||
setduration-wrongAmount: "'%0%' is not a valid amount, use a whole number."
|
||||
setduration-wrongFormat: "'%0%' is not a proper timeformat, check the documentation on Bukkit."
|
||||
setduration-success: "Duration of region %0% changed to '%1%'."
|
||||
setduration-noLandlord: "You don't have permission to change the duration because you are not the landlord of %region%."
|
||||
setduration-successRemoved: "Duration of %region% has been removed, it will now use the duration from a group or the default.yml file, new duration: %duration%."
|
||||
|
||||
setup-noRegion: "You did not specify a region on the second line."
|
||||
setup-wrongRegion: "The region you specified does not exist."
|
||||
@ -217,6 +221,7 @@ setup-noPermissionRent: "You don't have permission for setting up rental regions
|
||||
setup-noPermissionBuy: "You don't have permission for setting up buy regions."
|
||||
setup-couldNotDetect: "Found multiple regions with the same priority and/or parent/child relation, specify one on the second line (2 of the regions that were found: %0% and %1%)."
|
||||
setup-blacklisted: "%0% is on the blacklist and cannot be added to AreaShop."
|
||||
setup-noPermission: "You cannot add the region '%0%', you are not an owner/member or don't have the permission for it."
|
||||
|
||||
destroy-noPermissionRent: "You don't have permission for deregistering a rental region."
|
||||
destroy-noPermissionBuy: "You don't have permission for deregistering a buy region."
|
||||
@ -296,6 +301,8 @@ add-blacklisted: "On the blacklist: &7%0%."
|
||||
add-specifyWorld: "Specify the world of the region when using from console."
|
||||
add-incorrectWorld: "World '%0%' not found, try again (case-sensitive)."
|
||||
add-noRegion: "Region '%0%' does not exist in this world."
|
||||
add-noPermissionRegions: "No permission to add: &7%0%."
|
||||
add-noPermissionOwnerMember: "&7You either are not a member/owner of this region or have no permission to add your regions."
|
||||
|
||||
del-noRegion: "The specified region is not registered: %0%."
|
||||
del-noPermission: "You don't have permission to remove regions."
|
||||
|
29
plugin.yml
29
plugin.yml
@ -52,6 +52,13 @@ permissions:
|
||||
areashop.notifyupdate: true
|
||||
areashop.stack: true
|
||||
areashop.setlandlord: true
|
||||
areashop.landlord.*:
|
||||
description: Give access to all landlord features
|
||||
children:
|
||||
areashop.createrent.owner: true
|
||||
areashop.createbuy.owner: true
|
||||
areashop.setprice.landlord: true
|
||||
areashop.setduration.landlord: true
|
||||
areashop.help:
|
||||
description: Allows you to see the help pages
|
||||
default: true
|
||||
@ -74,11 +81,23 @@ permissions:
|
||||
description: Allows you to sell your own region
|
||||
default: true
|
||||
areashop.createrent:
|
||||
description: Allows you to set up signs for renting regions
|
||||
description: Allows you to add rent regions to AreaShop
|
||||
default: op
|
||||
areashop.createrent.member:
|
||||
description: Allows you to add rent regions to AreaShop for which you are registered as member
|
||||
default: false
|
||||
areashop.createrent.owner:
|
||||
description: Allows you to add rent regions to AreaShop for which you are registered as owner
|
||||
default: false
|
||||
areashop.createbuy:
|
||||
description: Allows you to set up signs for buying regions
|
||||
description: Allows you to add buy regions to AreaShop
|
||||
default: op
|
||||
areashop.createbuy.member:
|
||||
description: Allows you to add buy regions to AreaShop for which you are registered as member
|
||||
default: false
|
||||
areashop.createbuy.owner:
|
||||
description: Allows you to add buy regions to AreaShop for which you are registered as owner
|
||||
default: false
|
||||
areashop.destroyrent:
|
||||
description: Allows you to break signs used for renting regions
|
||||
default: op
|
||||
@ -97,9 +116,15 @@ permissions:
|
||||
areashop.setprice:
|
||||
description: Allows you to change the price
|
||||
default: op
|
||||
areashop.setprice.landlord:
|
||||
description: Allows you to change the price of a region that you are landlord of
|
||||
default: false
|
||||
areashop.setduration:
|
||||
description: Allows you to change the duration of a rent
|
||||
default: op
|
||||
areashop.setduration.landlord:
|
||||
description: Allows you to change the duration of a region that you are landlord of
|
||||
default: false
|
||||
areashop.teleport:
|
||||
description: Teleport to your region
|
||||
default: true
|
||||
|
@ -77,6 +77,7 @@ public final class AreaShop extends JavaPlugin {
|
||||
public static final String tagRegionName = "%region%";
|
||||
public static final String tagRegionType = "%type%";
|
||||
public static final String tagPrice = "%price%";
|
||||
public static final String tagRawPrice = "%rawprice%";
|
||||
public static final String tagDuration = "%duration%";
|
||||
public static final String tagRentedUntil = "%until%";
|
||||
public static final String tagRentedUntilShort = "%untilshort%";
|
||||
@ -86,10 +87,12 @@ public final class AreaShop extends JavaPlugin {
|
||||
public static final String tagTimeLeft = "%timeleft%";
|
||||
public static final String tagClicker = "%clicker%";
|
||||
public static final String tagResellPrice = "%resellprice%";
|
||||
public static final String tagRawResellPrice = "%rawresellprice%";
|
||||
public static final String tagFriends = "%friends%";
|
||||
public static final String tagFriendsUUID = "%friendsuuid%";
|
||||
public static final String tagMoneyBackPercentage = "%moneybackpercent%";
|
||||
public static final String tagMoneyBackAmount = "%moneyback%";
|
||||
public static final String tagRawMoneyBackAmount = "%rawmoneyback%";
|
||||
public static final String tagMaxExtends = "%maxextends%";
|
||||
public static final String tagExtendsLeft = "%extendsleft%";
|
||||
public static final String tagMaxRentTime = "%maxrenttime%";
|
||||
|
@ -5,16 +5,18 @@ import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.managers.FileManager.AddResult;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
@ -39,8 +41,14 @@ public class AddCommand extends CommandAreaShop {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command command, String[] args) {
|
||||
if(!sender.hasPermission("areashop.createrent") && !sender.hasPermission("areashop.createbuy")) {
|
||||
public void execute(final CommandSender sender, Command command, final String[] args) {
|
||||
if( !sender.hasPermission("areashop.createrent")
|
||||
&& !sender.hasPermission("areashop.createrent.member")
|
||||
&& !sender.hasPermission("areashop.createrent.owner")
|
||||
|
||||
&& !sender.hasPermission("areashop.createbuy")
|
||||
&& !sender.hasPermission("areashop.createbuy.member")
|
||||
&& !sender.hasPermission("areashop.createbuy.owner")) {
|
||||
plugin.message(sender, "add-noPermission");
|
||||
return;
|
||||
}
|
||||
@ -49,19 +57,17 @@ public class AddCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "add-help");
|
||||
return;
|
||||
}
|
||||
boolean isRent = "rent".equals(args[1].toLowerCase());
|
||||
if((isRent && !sender.hasPermission("areashop.createrent")) || (!isRent && !sender.hasPermission("areashop.createbuy"))) {
|
||||
plugin.message(sender, "add-noPermission");
|
||||
return;
|
||||
}
|
||||
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>();
|
||||
World world = null;
|
||||
Player player = null;
|
||||
if(sender instanceof Player) {
|
||||
player = (Player)sender;
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(!(sender instanceof Player)) {
|
||||
if(player == null) {
|
||||
plugin.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Selection selection = plugin.getWorldEdit().getSelection(player);
|
||||
if(selection == null) {
|
||||
plugin.message(player, "cmd-noSelection");
|
||||
@ -74,7 +80,7 @@ public class AddCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(sender instanceof Player) {
|
||||
if(player != null) {
|
||||
if(args.length == 4) {
|
||||
world = Bukkit.getWorld(args[3]);
|
||||
if(world == null) {
|
||||
@ -103,20 +109,52 @@ public class AddCommand extends CommandAreaShop {
|
||||
}
|
||||
regions.add(region);
|
||||
}
|
||||
final boolean isRent = "rent".equals(args[1].toLowerCase());
|
||||
final List<ProtectedRegion> finalRegions = regions;
|
||||
final Player finalPlayer = player;
|
||||
final World finalWorld = world;
|
||||
AreaShop.debug("Starting add task with " + regions.size() + " regions");
|
||||
new BukkitRunnable() {
|
||||
private int current = 0;
|
||||
private ArrayList<String> namesSuccess = new ArrayList<String>();
|
||||
private ArrayList<String> namesAlready = new ArrayList<String>();
|
||||
private ArrayList<String> namesBlacklisted = new ArrayList<String>();
|
||||
private ArrayList<String> namesNoPermission = new ArrayList<String>();
|
||||
|
||||
ArrayList<String> namesSuccess = new ArrayList<String>();
|
||||
ArrayList<String> namesAlready = new ArrayList<String>();
|
||||
ArrayList<String> namesBlacklisted = new ArrayList<String>();
|
||||
for(ProtectedRegion region : regions) {
|
||||
GeneralRegion asRegion = plugin.getFileManager().getRegion(region.getId());
|
||||
if(asRegion != null) {
|
||||
@Override
|
||||
public void run() {
|
||||
for(int i=0; i<plugin.getConfig().getInt("adding.regionsPerTick"); i++) {
|
||||
if(current < finalRegions.size()) {
|
||||
ProtectedRegion region = finalRegions.get(current);
|
||||
// Determine if the player is an owner or member of the region
|
||||
boolean isMember = finalPlayer != null && region.getMembers().contains(finalPlayer.getUniqueId());
|
||||
boolean isOwner = finalPlayer != null && region.getOwners().contains(finalPlayer.getUniqueId());
|
||||
String type = null;
|
||||
if(isRent) {
|
||||
type = "rent";
|
||||
} else {
|
||||
type = "buy";
|
||||
}
|
||||
AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, isRent ? RegionType.RENT : RegionType.BUY);
|
||||
if(result == AddResult.ALREADYADDED) {
|
||||
namesAlready.add(region.getId());
|
||||
} else if(plugin.getFileManager().isBlacklisted(region.getId())) {
|
||||
} else if(result == AddResult.BLACKLISTED) {
|
||||
namesBlacklisted.add(region.getId());
|
||||
} else if(result == AddResult.NOPERMISSION) {
|
||||
namesNoPermission.add(region.getId());
|
||||
} else {
|
||||
namesSuccess.add(region.getId());
|
||||
// Check if the player should be landlord
|
||||
boolean landlord = (!sender.hasPermission("areashop.create" + type)
|
||||
&& ((sender.hasPermission("areashop.create" + type + ".owner") && isOwner)
|
||||
|| (sender.hasPermission("areashop.create" + type + ".member") && isMember)));
|
||||
|
||||
if(isRent) {
|
||||
RentRegion rent = new RentRegion(plugin, region.getId(), world);
|
||||
RentRegion rent = new RentRegion(plugin, region.getId(), finalWorld);
|
||||
// Set landlord
|
||||
if(landlord) {
|
||||
rent.setLandlord(finalPlayer.getUniqueId());
|
||||
}
|
||||
// Run commands
|
||||
rent.runEventCommands(RegionEvent.CREATED, true);
|
||||
plugin.getFileManager().addRent(rent);
|
||||
@ -127,7 +165,11 @@ public class AddCommand extends CommandAreaShop {
|
||||
rent.runEventCommands(RegionEvent.CREATED, false);
|
||||
rent.saveRequired();
|
||||
} else {
|
||||
BuyRegion buy = new BuyRegion(plugin, region.getId(), world);
|
||||
BuyRegion buy = new BuyRegion(plugin, region.getId(), finalWorld);
|
||||
// Set landlord
|
||||
if(landlord) {
|
||||
buy.setLandlord(finalPlayer.getUniqueId());
|
||||
}
|
||||
// Run commands
|
||||
buy.runEventCommands(RegionEvent.CREATED, true);
|
||||
|
||||
@ -140,7 +182,10 @@ public class AddCommand extends CommandAreaShop {
|
||||
buy.saveRequired();
|
||||
}
|
||||
}
|
||||
current++;
|
||||
}
|
||||
}
|
||||
if(current >= finalRegions.size()) {
|
||||
if(!namesSuccess.isEmpty()) {
|
||||
plugin.message(sender, "add-success", args[1], Utils.createCommaSeparatedList(namesSuccess));
|
||||
}
|
||||
@ -150,6 +195,14 @@ public class AddCommand extends CommandAreaShop {
|
||||
if(!namesBlacklisted.isEmpty()) {
|
||||
plugin.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
|
||||
}
|
||||
if(!namesNoPermission.isEmpty()) {
|
||||
plugin.message(sender, "add-noPermissionRegions", Utils.createCommaSeparatedList(namesNoPermission));
|
||||
plugin.message(sender, "add-noPermissionOwnerMember");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public class SetdurationCommand extends CommandAreaShop {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command command, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setduration")) {
|
||||
if(!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
|
||||
plugin.message(sender, "setduration-noPermission");
|
||||
return;
|
||||
}
|
||||
@ -39,8 +39,12 @@ public class SetdurationCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "setduration-help");
|
||||
return;
|
||||
}
|
||||
int regionArgument = 3;
|
||||
if(args.length >= 2 && ("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1]))) {
|
||||
regionArgument = 2;
|
||||
}
|
||||
RentRegion rent = null;
|
||||
if(args.length <= 3) {
|
||||
if(args.length <= regionArgument) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = plugin.getFileManager().getApplicableRentRegions(((Player) sender).getLocation());
|
||||
@ -58,10 +62,22 @@ public class SetdurationCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rent = plugin.getFileManager().getRent(args[3]);
|
||||
rent = plugin.getFileManager().getRent(args[regionArgument]);
|
||||
}
|
||||
if(rent == null) {
|
||||
plugin.message(sender, "setduration-notRegistered", args[3]);
|
||||
plugin.message(sender, "setduration-notRegistered", args[regionArgument]);
|
||||
return;
|
||||
}
|
||||
if(!sender.hasPermission("areashop.setduration") && !rent.isLandlord(((Player)sender).getUniqueId())) {
|
||||
plugin.message(sender, "setduration-noLandlord", rent);
|
||||
return;
|
||||
}
|
||||
if("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
|
||||
plugin.message(sender, "setduration-successRemoved", rent);
|
||||
rent.setDuration(null);
|
||||
rent.updateRegionFlags();
|
||||
rent.updateSigns();
|
||||
rent.saveRequired();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -34,7 +34,7 @@ public class SetlandlordCommand extends CommandAreaShop {
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command command, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setlandlord")) {
|
||||
plugin.message(sender, "setteleport-noPermission");
|
||||
plugin.message(sender, "setlandlord-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
|
@ -123,7 +123,7 @@ public class SetownerCommand extends CommandAreaShop {
|
||||
}
|
||||
if(region.isBuyRegion()) {
|
||||
BuyRegion buy = (BuyRegion)region;
|
||||
buy.setLandlord(uuid);
|
||||
buy.setBuyer(uuid);
|
||||
buy.saveRequired();
|
||||
plugin.message(sender, "setowner-succesBuy", region);
|
||||
buy.updateRegionFlags();
|
||||
|
@ -33,7 +33,7 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command command, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setprice")) {
|
||||
if(!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
|
||||
plugin.message(sender, "setprice-noPermission");
|
||||
return;
|
||||
}
|
||||
@ -66,6 +66,22 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "setprice-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
if(!sender.hasPermission("areashop.setprice") && !region.isLandlord(((Player)sender).getUniqueId())) {
|
||||
plugin.message(sender, "setprice-noLandlord", region);
|
||||
return;
|
||||
}
|
||||
if("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
|
||||
if(region.isRentRegion()) {
|
||||
((RentRegion)region).removePrice();
|
||||
} else if(region.isBuyRegion()) {
|
||||
((BuyRegion)region).removePrice();
|
||||
}
|
||||
plugin.message(sender, "setprice-successRemoved", region);
|
||||
region.updateSigns();
|
||||
region.updateRegionFlags();
|
||||
region.saveRequired();
|
||||
return;
|
||||
}
|
||||
double price = 0.0;
|
||||
try {
|
||||
price = Double.parseDouble(args[1]);
|
||||
@ -75,10 +91,10 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
}
|
||||
if(region.isRentRegion()) {
|
||||
((RentRegion)region).setPrice(price);
|
||||
plugin.message(sender, "setprice-successRent", region.getName(), ((RentRegion)region).getFormattedPrice(), ((RentRegion)region).getDurationString());
|
||||
plugin.message(sender, "setprice-successRent", region);
|
||||
} else if(region.isBuyRegion()) {
|
||||
((BuyRegion)region).setPrice(price);
|
||||
plugin.message(sender, "setprice-successBuy", region.getName(), ((BuyRegion)region).getFormattedPrice());
|
||||
plugin.message(sender, "setprice-successBuy", region);
|
||||
}
|
||||
region.updateSigns();
|
||||
region.updateRegionFlags();
|
||||
|
@ -3,10 +3,12 @@ package nl.evolutioncoding.areashop.listeners;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.managers.FileManager.AddResult;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -53,7 +55,7 @@ public final class SignChangeListener implements Listener {
|
||||
|
||||
// Check if the sign is meant for this plugin
|
||||
if(event.getLine(0).contains(plugin.getConfig().getString("signTags.rent"))) {
|
||||
if(!player.hasPermission("areashop.createrent")) {
|
||||
if(!player.hasPermission("areashop.createrent") && !player.hasPermission("areashop.createrent.member") && !player.hasPermission("areashop.createrent.owner")) {
|
||||
plugin.message(player, "setup-noPermissionRent");
|
||||
return;
|
||||
}
|
||||
@ -93,21 +95,31 @@ public final class SignChangeListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
boolean priceSet = fourthLine != null && fourthLine.length() != 0;
|
||||
boolean durationSet = thirdLine != null && thirdLine.length() != 0;
|
||||
// check if all the lines are correct
|
||||
if(secondLine == null || secondLine.length() == 0) {
|
||||
plugin.message(player, "setup-noRegion");
|
||||
return;
|
||||
} else if(regionManager.getRegion(secondLine) == null) {
|
||||
}
|
||||
ProtectedRegion region = regionManager.getRegion(secondLine);
|
||||
if(region == null) {
|
||||
plugin.message(player, "setup-wrongRegion");
|
||||
return;
|
||||
} else if(plugin.getFileManager().isBlacklisted(secondLine)) {
|
||||
}
|
||||
|
||||
AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), RegionType.RENT);
|
||||
if(addResult == AddResult.BLACKLISTED) {
|
||||
plugin.message(player, "setup-blacklisted", secondLine);
|
||||
return;
|
||||
} else if(plugin.getFileManager().getRent(secondLine) != null) {
|
||||
} else if(addResult == AddResult.ALREADYADDED) {
|
||||
plugin.message(player, "setup-alreadyRentSign");
|
||||
return;
|
||||
} else if(addResult == AddResult.NOPERMISSION) {
|
||||
plugin.message(player, "setup-noPermission", secondLine);
|
||||
return;
|
||||
} else if(thirdLine != null && thirdLine.length() != 0 && !plugin.checkTimeFormat(thirdLine)) {
|
||||
plugin.message(player, "setup-wrongDuration");
|
||||
return;
|
||||
@ -125,6 +137,15 @@ public final class SignChangeListener implements Listener {
|
||||
|
||||
// Add rent to the FileManager
|
||||
final RentRegion rent = new RentRegion(plugin, secondLine, event.getPlayer().getWorld());
|
||||
boolean isMember = player != null && region.getMembers().contains(player.getUniqueId());
|
||||
boolean isOwner = player != null && region.getOwners().contains(player.getUniqueId());
|
||||
boolean landlord = (!player.hasPermission("areashop.createrent")
|
||||
&& ((player.hasPermission("areashop.createrent.owner") && isOwner)
|
||||
|| (player.hasPermission("areashop.createrent.member") && isMember)));
|
||||
|
||||
if(landlord) {
|
||||
rent.setLandlord(player.getUniqueId());
|
||||
}
|
||||
if(priceSet) {
|
||||
rent.setPrice(price);
|
||||
}
|
||||
@ -156,7 +177,7 @@ public final class SignChangeListener implements Listener {
|
||||
}
|
||||
} else if (event.getLine(0).contains(plugin.getConfig().getString("signTags.buy"))) {
|
||||
// Check for permission
|
||||
if(!player.hasPermission("areashop.createbuy")) {
|
||||
if(!player.hasPermission("areashop.createbuy") && !player.hasPermission("areashop.createbuy.member") && !player.hasPermission("areashop.createbuy.owner")) {
|
||||
plugin.message(player, "setup-noPermissionBuy");
|
||||
return;
|
||||
}
|
||||
@ -200,14 +221,21 @@ public final class SignChangeListener implements Listener {
|
||||
if(secondLine == null || secondLine.length() == 0) {
|
||||
plugin.message(player, "setup-noRegion");
|
||||
return;
|
||||
} else if(regionManager.getRegion(secondLine) == null) {
|
||||
}
|
||||
ProtectedRegion region = regionManager.getRegion(secondLine);
|
||||
if(region == null) {
|
||||
plugin.message(player, "setup-wrongRegion");
|
||||
return;
|
||||
} else if(plugin.getFileManager().isBlacklisted(secondLine)) {
|
||||
}
|
||||
AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, RegionType.BUY);
|
||||
if(addResult == AddResult.BLACKLISTED) {
|
||||
plugin.message(player, "setup-blacklisted", secondLine);
|
||||
return;
|
||||
} else if(plugin.getFileManager().getBuy(secondLine) != null) {
|
||||
plugin.message(player, "setup-alreadyBuySign");
|
||||
} else if(addResult == AddResult.ALREADYADDED) {
|
||||
plugin.message(player, "setup-alreadyRentSign");
|
||||
return;
|
||||
} else if(addResult == AddResult.NOPERMISSION) {
|
||||
plugin.message(player, "setup-noPermission", secondLine);
|
||||
return;
|
||||
} else {
|
||||
double price = 0.0;
|
||||
@ -223,6 +251,15 @@ public final class SignChangeListener implements Listener {
|
||||
|
||||
// Add buy to the FileManager
|
||||
final BuyRegion buy = new BuyRegion(plugin, secondLine, event.getPlayer().getWorld());
|
||||
boolean isMember = player != null && region.getMembers().contains(player.getUniqueId());
|
||||
boolean isOwner = player != null && region.getOwners().contains(player.getUniqueId());
|
||||
boolean landlord = (!player.hasPermission("areashop.createbuy")
|
||||
&& ((player.hasPermission("areashop.createbuy.owner") && isOwner)
|
||||
|| (player.hasPermission("areashop.createbuy.member") && isMember)));
|
||||
|
||||
if(landlord) {
|
||||
buy.setLandlord(player.getUniqueId());
|
||||
}
|
||||
if(priceSet) {
|
||||
buy.setPrice(price);
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
@ -69,6 +70,22 @@ public class FileManager {
|
||||
private String versionPath = null;
|
||||
private String schemFolder = null;
|
||||
|
||||
/* Enum for region types */
|
||||
public enum AddResult {
|
||||
BLACKLISTED("blacklisted"),
|
||||
NOPERMISSION("nopermission"),
|
||||
ALREADYADDED("alreadyadded"),
|
||||
SUCCESS("success");
|
||||
|
||||
private final String value;
|
||||
private AddResult(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, initialize variabeles
|
||||
* @param plugin
|
||||
@ -230,6 +247,10 @@ public class FileManager {
|
||||
regions.put(buy.getName().toLowerCase(), buy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a RegionGroup
|
||||
* @param group The RegionGroup to add
|
||||
*/
|
||||
public void addGroup(RegionGroup group) {
|
||||
groups.put(group.getName().toLowerCase(), group);
|
||||
String lowGroup = group.getName().toLowerCase();
|
||||
@ -241,6 +262,44 @@ public class FileManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can add a certain region as rent or buy region
|
||||
* @param sender The player/console that wants to add a region
|
||||
* @param region The WorldGuard region to add
|
||||
* @param type The type the region should have in AreaShop
|
||||
* @return The result if a player would want to add this region
|
||||
*/
|
||||
public AddResult checkRegionAdd(CommandSender sender, ProtectedRegion region, RegionType type) {
|
||||
Player player = null;
|
||||
if(sender instanceof Player) {
|
||||
player = (Player)sender;
|
||||
}
|
||||
// Determine if the player is an owner or member of the region
|
||||
boolean isMember = player != null && region.getMembers().contains(player.getUniqueId());
|
||||
boolean isOwner = player != null && region.getOwners().contains(player.getUniqueId());
|
||||
AreaShop.debug("checkRegionAdd: isOwner=" + isOwner + ", isMember=" + isMember);
|
||||
String typeString = null;
|
||||
if(type == RegionType.RENT) {
|
||||
typeString = "rent";
|
||||
} else {
|
||||
typeString = "buy";
|
||||
}
|
||||
AreaShop.debug(" permissions: .create=" + sender.hasPermission("areashop.create" + typeString) + ", .create.owner=" + sender.hasPermission("areashop.create" + typeString + ".owner") + ", .create.member=" + sender.hasPermission("areashop.create" + typeString + ".member"));
|
||||
if(!(sender.hasPermission("areashop.create" + typeString)
|
||||
|| (sender.hasPermission("areashop.create" + typeString + ".owner") && isOwner)
|
||||
|| (sender.hasPermission("areashop.create" + typeString + ".member") && isMember))) {
|
||||
return AddResult.NOPERMISSION;
|
||||
}
|
||||
GeneralRegion asRegion = plugin.getFileManager().getRegion(region.getId());
|
||||
if(asRegion != null) {
|
||||
return AddResult.ALREADYADDED;
|
||||
} else if(plugin.getFileManager().isBlacklisted(region.getId())) {
|
||||
return AddResult.BLACKLISTED;
|
||||
} else {
|
||||
return AddResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a rent from the list
|
||||
* @param rent The region to remove
|
||||
|
@ -78,7 +78,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
* Set the buyer of this region
|
||||
* @param buyer The UUID of the player that should be set as buyer
|
||||
*/
|
||||
public void setLandlord(UUID buyer) {
|
||||
public void setBuyer(UUID buyer) {
|
||||
if(buyer == null) {
|
||||
setSetting("buy.buyer", null);
|
||||
setSetting("buy.buyerName", null);
|
||||
@ -159,6 +159,13 @@ public class BuyRegion extends GeneralRegion {
|
||||
setSetting("buy.price", price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the price so that the price will be taken from a group or the default.yml file
|
||||
*/
|
||||
public void removePrice() {
|
||||
setSetting("buy.price", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the region into resell mode with the given price
|
||||
* @param price The price this region should be put up for sale
|
||||
@ -205,10 +212,13 @@ public class BuyRegion extends GeneralRegion {
|
||||
// Fill the replacements map with things specific to a BuyRegion
|
||||
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||
result.put(AreaShop.tagPrice, getFormattedPrice());
|
||||
result.put(AreaShop.tagRawPrice, getPrice());
|
||||
result.put(AreaShop.tagPlayerName, getPlayerName());
|
||||
result.put(AreaShop.tagPlayerUUID, getBuyer());
|
||||
result.put(AreaShop.tagResellPrice, getFormattedResellPrice());
|
||||
result.put(AreaShop.tagRawResellPrice, getResellPrice());
|
||||
result.put(AreaShop.tagMoneyBackAmount, getFormattedMoneyBackAmount());
|
||||
result.put(AreaShop.tagRawMoneyBackAmount, getMoneyBackAmount());
|
||||
double moneyBackPercent = getMoneyBackPercentage();
|
||||
if((moneyBackPercent%1.0) == 0.0) {
|
||||
result.put(AreaShop.tagMoneyBackPercentage, (int)moneyBackPercent);
|
||||
@ -307,7 +317,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
// Run commands
|
||||
this.runEventCommands(RegionEvent.RESELL, true);
|
||||
// Set the owner
|
||||
setLandlord(player.getUniqueId());
|
||||
setBuyer(player.getUniqueId());
|
||||
|
||||
// Update everything
|
||||
handleSchematicEvent(RegionEvent.RESELL);
|
||||
@ -347,7 +357,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
// Run commands
|
||||
this.runEventCommands(RegionEvent.BOUGHT, true);
|
||||
// Set the owner
|
||||
setLandlord(player.getUniqueId());
|
||||
setBuyer(player.getUniqueId());
|
||||
|
||||
// Update everything
|
||||
handleSchematicEvent(RegionEvent.BOUGHT);
|
||||
@ -421,7 +431,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
|
||||
/* Remove friends and the owner */
|
||||
clearFriends();
|
||||
setLandlord(null);
|
||||
setBuyer(null);
|
||||
|
||||
updateSigns();
|
||||
|
||||
|
@ -386,6 +386,15 @@ public abstract class GeneralRegion {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified player is the landlord of this region
|
||||
* @param landlord The UUID of the players to check for landlord
|
||||
* @return true if the player is the landlord, otherwise false
|
||||
*/
|
||||
public boolean isLandlord(UUID landlord) {
|
||||
return landlord !=null && getLandlord() != null && getLandlord().equals(landlord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldGuard region associated with this AreaShop region
|
||||
* @return The ProtectedRegion of WorldGuard or null if the region does not exist anymore
|
||||
|
@ -137,6 +137,7 @@ public class RentRegion extends GeneralRegion {
|
||||
// Fill the replacements map with things specific to a RentRegion
|
||||
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||
result.put(AreaShop.tagPrice, getFormattedPrice());
|
||||
result.put(AreaShop.tagRawPrice, getPrice());
|
||||
result.put(AreaShop.tagDuration, getDurationString());
|
||||
result.put(AreaShop.tagPlayerName, getPlayerName());
|
||||
result.put(AreaShop.tagPlayerUUID, getRenter());
|
||||
@ -148,6 +149,7 @@ public class RentRegion extends GeneralRegion {
|
||||
result.put(AreaShop.tagRentedUntilShort, dateString);
|
||||
result.put(AreaShop.tagTimeLeft, getTimeLeftString());
|
||||
result.put(AreaShop.tagMoneyBackAmount, getFormattedMoneyBackAmount());
|
||||
result.put(AreaShop.tagRawMoneyBackAmount, getMoneyBackAmount());
|
||||
double moneyBackPercent = getMoneyBackPercentage();
|
||||
if((moneyBackPercent%1.0) == 0.0) {
|
||||
result.put(AreaShop.tagMoneyBackPercentage, (int)moneyBackPercent);
|
||||
@ -319,6 +321,13 @@ public class RentRegion extends GeneralRegion {
|
||||
setSetting("rent.price", price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the price so that the price will be taken from a group or the default.yml file
|
||||
*/
|
||||
public void removePrice() {
|
||||
setSetting("rent.price", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the duration of the rent
|
||||
* @param duration The duration of the rent (as specified on the documentation pages)
|
||||
|
Loading…
Reference in New Issue
Block a user