Move event commands to a feature class, add two events
- Move eventCommandProfile code to a separate class - Add AddingRegionEvent - Add DeletingRegionEvent - Cleanup a couple of duplicate code paths (merge RentRegion/BuyRegion branches)
This commit is contained in:
parent
e0bad7397c
commit
1035b6b41b
|
@ -2,6 +2,11 @@ package me.wiefferink.areashop.commands;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.BoughtRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.RentedRegionEvent;
|
||||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||||
import me.wiefferink.areashop.managers.FileManager;
|
import me.wiefferink.areashop.managers.FileManager;
|
||||||
import me.wiefferink.areashop.regions.BuyRegion;
|
import me.wiefferink.areashop.regions.BuyRegion;
|
||||||
|
@ -10,6 +15,7 @@ import me.wiefferink.areashop.regions.RentRegion;
|
||||||
import me.wiefferink.areashop.tools.Utils;
|
import me.wiefferink.areashop.tools.Utils;
|
||||||
import me.wiefferink.bukkitdo.Do;
|
import me.wiefferink.bukkitdo.Do;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -120,8 +126,11 @@ public class AddCommand extends CommandAreaShop {
|
||||||
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
|
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||||
TreeSet<GeneralRegion> regionsAlready = new TreeSet<>();
|
TreeSet<GeneralRegion> regionsAlready = new TreeSet<>();
|
||||||
TreeSet<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
|
TreeSet<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
|
||||||
|
TreeSet<GeneralRegion> regionsRentCancelled = new TreeSet<>(); // Denied by an event listener
|
||||||
|
TreeSet<GeneralRegion> regionsBuyCancelled = new TreeSet<>(); // Denied by an event listener
|
||||||
TreeSet<String> namesBlacklisted = new TreeSet<>();
|
TreeSet<String> namesBlacklisted = new TreeSet<>();
|
||||||
TreeSet<String> namesNoPermission = new TreeSet<>();
|
TreeSet<String> namesNoPermission = new TreeSet<>();
|
||||||
|
TreeSet<String> namesAddCancelled = new TreeSet<>(); // Denied by an event listener
|
||||||
Do.forAll(
|
Do.forAll(
|
||||||
plugin.getConfig().getInt("adding.regionsPerTick"),
|
plugin.getConfig().getInt("adding.regionsPerTick"),
|
||||||
regions.entrySet(),
|
regions.entrySet(),
|
||||||
|
@ -170,40 +179,40 @@ public class AddCommand extends CommandAreaShop {
|
||||||
if(landlord) {
|
if(landlord) {
|
||||||
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
||||||
}
|
}
|
||||||
// Run commands
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
AddingRegionEvent event = plugin.getFileManager().addRegion(rent);
|
||||||
plugin.getFileManager().addRent(rent);
|
if (event.isCancelled()) {
|
||||||
|
namesAddCancelled.add(rent.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||||
|
|
||||||
rent.update();
|
rent.update();
|
||||||
|
|
||||||
// Run commands
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
|
|
||||||
// Add existing owners/members if any
|
// Add existing owners/members if any
|
||||||
if(!landlord && !existing.isEmpty()) {
|
if(!landlord && !existing.isEmpty()) {
|
||||||
// TODO also execute rent events to notify other plugins?
|
UUID rentBy = existing.remove(0);
|
||||||
|
OfflinePlayer rentByPlayer = Bukkit.getOfflinePlayer(rentBy);
|
||||||
|
|
||||||
// Run commands
|
RentingRegionEvent rentingRegionEvent = new RentingRegionEvent(rent, rentByPlayer, false);
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.RENTED, true);
|
Bukkit.getPluginManager().callEvent(rentingRegionEvent);
|
||||||
|
if(rentingRegionEvent.isCancelled()) {
|
||||||
|
regionsRentCancelled.add(rent);
|
||||||
|
} else {
|
||||||
|
// Add values to the rent and send it to FileManager
|
||||||
|
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||||
|
rent.setRenter(rentBy);
|
||||||
|
rent.updateLastActiveTime();
|
||||||
|
|
||||||
// Add values to the rent and send it to FileManager
|
// Fire schematic event and updated times extended
|
||||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
|
||||||
rent.setRenter(existing.remove(0));
|
|
||||||
rent.updateLastActiveTime();
|
|
||||||
|
|
||||||
// Add others as friends
|
// Add others as friends
|
||||||
for(UUID friend : existing) {
|
for(UUID friend : existing) {
|
||||||
rent.getFriendsFeature().addFriend(friend, null);
|
rent.getFriendsFeature().addFriend(friend, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
rent.notifyAndUpdate(new RentedRegionEvent(rent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire schematic event and updated times extended
|
|
||||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
|
|
||||||
|
|
||||||
// Notify about updates
|
|
||||||
rent.update();
|
|
||||||
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.RENTED, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regionsSuccess.add(rent);
|
regionsSuccess.add(rent);
|
||||||
|
@ -213,40 +222,40 @@ public class AddCommand extends CommandAreaShop {
|
||||||
if(landlord) {
|
if(landlord) {
|
||||||
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
||||||
}
|
}
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
|
||||||
|
|
||||||
plugin.getFileManager().addBuy(buy);
|
AddingRegionEvent event = plugin.getFileManager().addRegion(buy);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
namesAddCancelled.add(buy.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||||
|
|
||||||
buy.update();
|
buy.update();
|
||||||
|
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
|
|
||||||
// Add existing owners/members if any
|
// Add existing owners/members if any
|
||||||
if(!landlord && !existing.isEmpty()) {
|
if(!landlord && !existing.isEmpty()) {
|
||||||
// TODO also execute buy events to notify for other plugins?
|
UUID buyBy = existing.remove(0);
|
||||||
|
OfflinePlayer buyByPlayer = Bukkit.getOfflinePlayer(buyBy);
|
||||||
|
|
||||||
// Run commands
|
BuyingRegionEvent buyingRegionEvent = new BuyingRegionEvent(buy, buyByPlayer);
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.BOUGHT, true);
|
Bukkit.getPluginManager().callEvent(buyingRegionEvent);
|
||||||
|
if(buyingRegionEvent.isCancelled()) {
|
||||||
|
regionsBuyCancelled.add(buy);
|
||||||
|
} else {
|
||||||
|
// Set the owner
|
||||||
|
buy.setBuyer(buyBy);
|
||||||
|
buy.updateLastActiveTime();
|
||||||
|
|
||||||
// Set the owner
|
// Update everything
|
||||||
buy.setBuyer(existing.remove(0));
|
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
|
||||||
buy.updateLastActiveTime();
|
|
||||||
// Add others as friends
|
// Add others as friends
|
||||||
for(UUID friend : existing) {
|
for (UUID friend : existing) {
|
||||||
buy.getFriendsFeature().addFriend(friend, null);
|
buy.getFriendsFeature().addFriend(friend, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
buy.notifyAndUpdate(new BoughtRegionEvent(buy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify about updates
|
|
||||||
buy.update();
|
|
||||||
|
|
||||||
// Update everything
|
|
||||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
|
|
||||||
|
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.BOUGHT, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regionsSuccess.add(buy);
|
regionsSuccess.add(buy);
|
||||||
|
@ -263,6 +272,12 @@ public class AddCommand extends CommandAreaShop {
|
||||||
if(!regionsAlreadyOtherWorld.isEmpty()) {
|
if(!regionsAlreadyOtherWorld.isEmpty()) {
|
||||||
plugin.message(sender, "add-failedOtherWorld", Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
|
plugin.message(sender, "add-failedOtherWorld", Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
|
||||||
}
|
}
|
||||||
|
if(!regionsRentCancelled.isEmpty()) {
|
||||||
|
plugin.message(sender, "add-rentCancelled", Utils.combinedMessage(regionsRentCancelled, "region"));
|
||||||
|
}
|
||||||
|
if(!regionsBuyCancelled.isEmpty()) {
|
||||||
|
plugin.message(sender, "add-buyCancelled", Utils.combinedMessage(regionsBuyCancelled, "region"));
|
||||||
|
}
|
||||||
if(!namesBlacklisted.isEmpty()) {
|
if(!namesBlacklisted.isEmpty()) {
|
||||||
plugin.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
|
plugin.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
|
||||||
}
|
}
|
||||||
|
@ -270,6 +285,9 @@ public class AddCommand extends CommandAreaShop {
|
||||||
plugin.message(sender, "add-noPermissionRegions", Utils.createCommaSeparatedList(namesNoPermission));
|
plugin.message(sender, "add-noPermissionRegions", Utils.createCommaSeparatedList(namesNoPermission));
|
||||||
plugin.message(sender, "add-noPermissionOwnerMember");
|
plugin.message(sender, "add-noPermissionOwnerMember");
|
||||||
}
|
}
|
||||||
|
if(!namesAddCancelled.isEmpty()) {
|
||||||
|
plugin.message(sender, "add-rentCancelled", Utils.createCommaSeparatedList(namesAddCancelled));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package me.wiefferink.areashop.commands;
|
package me.wiefferink.areashop.commands;
|
||||||
|
|
||||||
|
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||||
import me.wiefferink.areashop.regions.BuyRegion;
|
import me.wiefferink.areashop.regions.BuyRegion;
|
||||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||||
|
@ -56,31 +57,39 @@ public class DelCommand extends CommandAreaShop {
|
||||||
}
|
}
|
||||||
// Start removing the regions that he has permission for
|
// Start removing the regions that he has permission for
|
||||||
ArrayList<String> namesSuccess = new ArrayList<>();
|
ArrayList<String> namesSuccess = new ArrayList<>();
|
||||||
TreeSet<GeneralRegion> namesFailed = new TreeSet<>();
|
TreeSet<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||||
|
TreeSet<GeneralRegion> regionsCancelled = new TreeSet<>();
|
||||||
for(GeneralRegion region : regions) {
|
for(GeneralRegion region : regions) {
|
||||||
boolean isLandlord = region.isLandlord(((Player)sender).getUniqueId());
|
boolean isLandlord = region.isLandlord(((Player)sender).getUniqueId());
|
||||||
if(region instanceof RentRegion) {
|
if(region instanceof RentRegion) {
|
||||||
if(!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
if(!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||||
namesFailed.add(region);
|
regionsFailed.add(region);
|
||||||
} else {
|
continue;
|
||||||
plugin.getFileManager().removeRent((RentRegion)region, true);
|
|
||||||
namesSuccess.add(region.getName());
|
|
||||||
}
|
}
|
||||||
} else if(region instanceof BuyRegion) {
|
} else if(region instanceof BuyRegion) {
|
||||||
if(!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
if(!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||||
namesFailed.add(region);
|
regionsFailed.add(region);
|
||||||
} else {
|
continue;
|
||||||
plugin.getFileManager().removeBuy((BuyRegion)region, true);
|
|
||||||
namesSuccess.add(region.getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
regionsCancelled.add(region);
|
||||||
|
} else {
|
||||||
|
namesSuccess.add(region.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// send messages
|
|
||||||
|
// Send messages
|
||||||
if(!namesSuccess.isEmpty()) {
|
if(!namesSuccess.isEmpty()) {
|
||||||
plugin.message(sender, "del-success", Utils.createCommaSeparatedList(namesSuccess));
|
plugin.message(sender, "del-success", Utils.createCommaSeparatedList(namesSuccess));
|
||||||
}
|
}
|
||||||
if(!namesFailed.isEmpty()) {
|
if(!regionsFailed.isEmpty()) {
|
||||||
plugin.message(sender, "del-failed", Utils.combinedMessage(namesFailed, "region"));
|
plugin.message(sender, "del-failed", Utils.combinedMessage(regionsFailed, "region"));
|
||||||
|
}
|
||||||
|
if(!regionsCancelled.isEmpty()) {
|
||||||
|
plugin.message(sender, "del-cancelled", Utils.combinedMessage(regionsCancelled, "region"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
|
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
|
||||||
|
@ -92,16 +101,24 @@ public class DelCommand extends CommandAreaShop {
|
||||||
if(region instanceof RentRegion) {
|
if(region instanceof RentRegion) {
|
||||||
// Remove the rent if the player has permission
|
// Remove the rent if the player has permission
|
||||||
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||||
plugin.getFileManager().removeRent((RentRegion)region, true);
|
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||||
plugin.message(sender, "destroy-successRent", region);
|
if (event.isCancelled()) {
|
||||||
|
plugin.message(sender, "general-cancelled", event.getReason());
|
||||||
|
} else {
|
||||||
|
plugin.message(sender, "destroy-successRent", region);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
plugin.message(sender, "destroy-noPermissionRent", region);
|
plugin.message(sender, "destroy-noPermissionRent", region);
|
||||||
}
|
}
|
||||||
} else if(region instanceof BuyRegion) {
|
} else if(region instanceof BuyRegion) {
|
||||||
// Remove the buy if the player has permission
|
// Remove the buy if the player has permission
|
||||||
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||||
plugin.getFileManager().removeBuy((BuyRegion)region, true);
|
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||||
plugin.message(sender, "destroy-successBuy", region);
|
if (event.isCancelled()) {
|
||||||
|
plugin.message(sender, "general-cancelled", event.getReason());
|
||||||
|
} else {
|
||||||
|
plugin.message(sender, "destroy-successBuy", region);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
plugin.message(sender, "destroy-noPermissionBuy", region);
|
plugin.message(sender, "destroy-noPermissionBuy", region);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.common.base.Charsets;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||||
import me.wiefferink.areashop.features.signs.SignsFeature;
|
import me.wiefferink.areashop.features.signs.SignsFeature;
|
||||||
import me.wiefferink.areashop.regions.BuyRegion;
|
import me.wiefferink.areashop.regions.BuyRegion;
|
||||||
|
@ -240,10 +241,13 @@ public class ImportJob {
|
||||||
GeneralRegion region;
|
GeneralRegion region;
|
||||||
if(rentable || (owner != null && !isBought)) {
|
if(rentable || (owner != null && !isBought)) {
|
||||||
region = new RentRegion(regionKey, world);
|
region = new RentRegion(regionKey, world);
|
||||||
plugin.getFileManager().addRent((RentRegion)region);
|
|
||||||
} else {
|
} else {
|
||||||
region = new BuyRegion(regionKey, world);
|
region = new BuyRegion(regionKey, world);
|
||||||
plugin.getFileManager().addBuy((BuyRegion)region);
|
}
|
||||||
|
AddingRegionEvent event = plugin.getFileManager().addRegion(region);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
messageNoPrefix("general-cancelled", event.getReason());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import settings
|
// Import settings
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.wiefferink.areashop.commands;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||||
import me.wiefferink.areashop.regions.BuyRegion;
|
import me.wiefferink.areashop.regions.BuyRegion;
|
||||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||||
|
@ -179,27 +180,24 @@ public class StackCommand extends CommandAreaShop {
|
||||||
manager.addRegion(region);
|
manager.addRegion(region);
|
||||||
|
|
||||||
// Add the region to AreaShop
|
// Add the region to AreaShop
|
||||||
|
GeneralRegion newRegion;
|
||||||
if(rentRegions) {
|
if(rentRegions) {
|
||||||
RentRegion rent = new RentRegion(regionName, selection.getWorld());
|
newRegion = new RentRegion(regionName, selection.getWorld());
|
||||||
if(finalGroup != null) {
|
|
||||||
finalGroup.addMember(rent);
|
|
||||||
}
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
|
||||||
plugin.getFileManager().addRent(rent);
|
|
||||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
rent.update();
|
|
||||||
} else {
|
} else {
|
||||||
BuyRegion buy = new BuyRegion(regionName, selection.getWorld());
|
newRegion = new BuyRegion(regionName, selection.getWorld());
|
||||||
if(finalGroup != null) {
|
|
||||||
finalGroup.addMember(buy);
|
|
||||||
}
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
|
||||||
plugin.getFileManager().addBuy(buy);
|
|
||||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
buy.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(finalGroup != null) {
|
||||||
|
finalGroup.addMember(newRegion);
|
||||||
|
}
|
||||||
|
AddingRegionEvent event = plugin.getFileManager().addRegion(newRegion);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
plugin.message(player, "general-cancelled", event.getReason());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newRegion.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||||
|
newRegion.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(current >= amount) {
|
if(current >= amount) {
|
||||||
|
|
|
@ -16,6 +16,11 @@ public class RegionEvent<T> extends Event {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit/Spigot
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the region of this event.
|
* Get the region of this event.
|
||||||
* @return The region the event is about
|
* @return The region the event is about
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package me.wiefferink.areashop.events.ask;
|
||||||
|
|
||||||
|
import me.wiefferink.areashop.events.CancellableRegionEvent;
|
||||||
|
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcasted when a region has been added to AreaShop.
|
||||||
|
*/
|
||||||
|
public class AddingRegionEvent extends CancellableRegionEvent<GeneralRegion> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param region The region that has been added
|
||||||
|
*/
|
||||||
|
public AddingRegionEvent(GeneralRegion region) {
|
||||||
|
super(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package me.wiefferink.areashop.events.ask;
|
||||||
|
|
||||||
|
import me.wiefferink.areashop.events.CancellableRegionEvent;
|
||||||
|
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcasted when a region has been added to AreaShop.
|
||||||
|
*/
|
||||||
|
public class DeletingRegionEvent extends CancellableRegionEvent<GeneralRegion> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param region The region that has been added
|
||||||
|
*/
|
||||||
|
public DeletingRegionEvent(GeneralRegion region) {
|
||||||
|
super(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
package me.wiefferink.areashop.features;
|
||||||
|
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.ResellingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.SellingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.UnrentingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.AddedRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.BoughtRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.RentedRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.ResoldRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.SoldRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
|
||||||
|
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandsFeature extends RegionFeature {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run command for a certain event.
|
||||||
|
* @param region Region to execute the events for
|
||||||
|
* @param event The event
|
||||||
|
* @param before The 'before' or 'after' commands
|
||||||
|
*/
|
||||||
|
public void runEventCommands(GeneralRegion region, GeneralRegion.RegionEvent event, boolean before) {
|
||||||
|
ConfigurationSection eventCommandProfileSection = region.getConfigurationSectionSetting("general.eventCommandProfile", "eventCommandProfiles");
|
||||||
|
if(eventCommandProfileSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> commands = eventCommandProfileSection.getStringList(event.getValue() + "." + (before ? "before" : "after"));
|
||||||
|
if(commands == null || commands.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
region.runCommands(Bukkit.getConsoleSender(), commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void addingRegion(AddingRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.CREATED, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void addedRegion(AddedRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.CREATED, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void deletingRegion(DeletingRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.DELETED, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void deletedRegion(DeletedRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.DELETED, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void rentingRegion(RentingRegionEvent event) {
|
||||||
|
// Technically the rent can still be cancelled if the payment fails...
|
||||||
|
runEventCommands(event.getRegion(), event.isExtending() ? GeneralRegion.RegionEvent.EXTENDED : GeneralRegion.RegionEvent.RENTED, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void rentedRegion(RentedRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), event.hasExtended() ? GeneralRegion.RegionEvent.EXTENDED : GeneralRegion.RegionEvent.RENTED, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void buyingRegion(BuyingRegionEvent event) {
|
||||||
|
// Technically the buy can still be cancelled if the payment fails...
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.BOUGHT, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void boughtRegion(BoughtRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.BOUGHT, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void resellingRegion(ResellingRegionEvent event) {
|
||||||
|
// Technically the resell can still be cancelled if the payment fails...
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.RESELL, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void resoldRegion(ResoldRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.RESELL, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void sellingRegion(SellingRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.SOLD, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void soldRegion(SoldRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.SOLD, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void unrentingRegion(UnrentingRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.UNRENTED, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void unrentedRegion(UnrentedRegionEvent event) {
|
||||||
|
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.UNRENTED, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,27 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Possible future feature classes:
|
||||||
|
- RestrictedToRegion feature
|
||||||
|
- rent/buy restricted to the region itself
|
||||||
|
- RestrictedToWorld feature
|
||||||
|
- rent/buy restricted to the world of the region
|
||||||
|
- CountLimitsFeature:
|
||||||
|
- Check region limits
|
||||||
|
- TimeLimitsFeatures:
|
||||||
|
- maxExtends
|
||||||
|
- maxRentTime
|
||||||
|
- SchematicFeature
|
||||||
|
- save/load schematics
|
||||||
|
- CommandsFeature
|
||||||
|
- execute commands after extend/rent/etc
|
||||||
|
- LandlordFeature
|
||||||
|
- manage landlords
|
||||||
|
- ExpirationWarningsFeature
|
||||||
|
- sending rental expiration warnings
|
||||||
|
*/
|
||||||
|
|
||||||
public abstract class RegionFeature implements Listener {
|
public abstract class RegionFeature implements Listener {
|
||||||
public static final AreaShop plugin = AreaShop.getInstance();
|
public static final AreaShop plugin = AreaShop.getInstance();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.wiefferink.areashop.features.signs;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
||||||
import me.wiefferink.areashop.features.RegionFeature;
|
import me.wiefferink.areashop.features.RegionFeature;
|
||||||
import me.wiefferink.areashop.managers.FileManager;
|
import me.wiefferink.areashop.managers.FileManager;
|
||||||
|
@ -280,16 +281,16 @@ public class SignsFeature extends RegionFeature {
|
||||||
org.bukkit.material.Sign sign = (org.bukkit.material.Sign)event.getBlock().getState().getData();
|
org.bukkit.material.Sign sign = (org.bukkit.material.Sign)event.getBlock().getState().getData();
|
||||||
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
|
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
|
||||||
|
|
||||||
// Run commands
|
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(rent);
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
if (addingRegionEvent.isCancelled()) {
|
||||||
|
plugin.message(player, "general-cancelled", addingRegionEvent.getReason());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getFileManager().addRent(rent);
|
|
||||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||||
plugin.message(player, "setup-rentSuccess", rent);
|
plugin.message(player, "setup-rentSuccess", rent);
|
||||||
// Update the region after the event has written its lines
|
// Update the region after the event has written its lines
|
||||||
Do.sync(rent::update);
|
Do.sync(rent::update);
|
||||||
// Run commands
|
|
||||||
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
}
|
}
|
||||||
} else if(event.getLine(0).contains(plugin.getConfig().getString("signTags.buy"))) {
|
} else if(event.getLine(0).contains(plugin.getConfig().getString("signTags.buy"))) {
|
||||||
// Check for permission
|
// Check for permission
|
||||||
|
@ -384,17 +385,17 @@ public class SignsFeature extends RegionFeature {
|
||||||
}
|
}
|
||||||
org.bukkit.material.Sign sign = (org.bukkit.material.Sign)event.getBlock().getState().getData();
|
org.bukkit.material.Sign sign = (org.bukkit.material.Sign)event.getBlock().getState().getData();
|
||||||
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
|
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
|
|
||||||
|
|
||||||
plugin.getFileManager().addBuy(buy);
|
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(buy);
|
||||||
|
if (addingRegionEvent.isCancelled()) {
|
||||||
|
plugin.message(player, "general-cancelled", addingRegionEvent.getReason());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||||
plugin.message(player, "setup-buySuccess", buy);
|
plugin.message(player, "setup-buySuccess", buy);
|
||||||
// Update the region after the event has written its lines
|
// Update the region after the event has written its lines
|
||||||
Do.sync(buy::update);
|
Do.sync(buy::update);
|
||||||
|
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
|
|
||||||
}
|
}
|
||||||
} else if(event.getLine(0).contains(plugin.getConfig().getString("signTags.add"))) {
|
} else if(event.getLine(0).contains(plugin.getConfig().getString("signTags.add"))) {
|
||||||
// Check for permission
|
// Check for permission
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.wiefferink.areashop.managers;
|
package me.wiefferink.areashop.managers;
|
||||||
|
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.features.CommandsFeature;
|
||||||
import me.wiefferink.areashop.features.DebugFeature;
|
import me.wiefferink.areashop.features.DebugFeature;
|
||||||
import me.wiefferink.areashop.features.FriendsFeature;
|
import me.wiefferink.areashop.features.FriendsFeature;
|
||||||
import me.wiefferink.areashop.features.RegionFeature;
|
import me.wiefferink.areashop.features.RegionFeature;
|
||||||
|
@ -25,7 +26,8 @@ public class FeatureManager extends Manager {
|
||||||
SignsFeature.class,
|
SignsFeature.class,
|
||||||
FriendsFeature.class,
|
FriendsFeature.class,
|
||||||
WorldGuardRegionFlagsFeature.class,
|
WorldGuardRegionFlagsFeature.class,
|
||||||
TeleportFeature.class
|
TeleportFeature.class,
|
||||||
|
CommandsFeature.class
|
||||||
));
|
));
|
||||||
// One instance of each feature, registered for event handling
|
// One instance of each feature, registered for event handling
|
||||||
private final Set<RegionFeature> globalFeatures;
|
private final Set<RegionFeature> globalFeatures;
|
||||||
|
@ -78,7 +80,7 @@ public class FeatureManager extends Manager {
|
||||||
try {
|
try {
|
||||||
return regionFeatureConstructors.get(featureClazz).newInstance(region);
|
return regionFeatureConstructors.get(featureClazz).newInstance(region);
|
||||||
} catch(InstantiationException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
|
} catch(InstantiationException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
|
||||||
AreaShop.error("Failed to instanciate feature", featureClazz, "for region", region, e, e.getCause());
|
AreaShop.error("Failed to instantiate feature", featureClazz, "for region", region, e, e.getCause());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.google.common.io.Files;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import me.wiefferink.areashop.AreaShop;
|
import me.wiefferink.areashop.AreaShop;
|
||||||
|
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||||
|
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||||
import me.wiefferink.areashop.events.notify.AddedRegionEvent;
|
import me.wiefferink.areashop.events.notify.AddedRegionEvent;
|
||||||
import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
|
import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
|
||||||
import me.wiefferink.areashop.regions.BuyRegion;
|
import me.wiefferink.areashop.regions.BuyRegion;
|
||||||
|
@ -288,26 +290,39 @@ public class FileManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a rent to the list without saving it to disk (useful for loading at startup).
|
* Add a region to the list and mark it as to-be-saved.
|
||||||
* @param rent The rental region to add
|
* @param region Then region to add
|
||||||
|
* @return true when successful, otherwise false (denied by an event listener)
|
||||||
*/
|
*/
|
||||||
public void addRentNoSave(RentRegion rent) {
|
public AddingRegionEvent addRegion(GeneralRegion region) {
|
||||||
if(rent == null) {
|
AddingRegionEvent event = addRegionNoSave(region);
|
||||||
AreaShop.debug("Tried adding a null rent!");
|
if (event.isCancelled()) {
|
||||||
return;
|
return event;
|
||||||
}
|
}
|
||||||
regions.put(rent.getName().toLowerCase(), rent);
|
region.saveRequired();
|
||||||
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(rent));
|
markGroupsAutoDirty();
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a rent to the list and mark it as to-be-saved.
|
* Add a region to the list without saving it to disk (useful for loading at startup).
|
||||||
* @param rent Then rental region to add
|
* @param region The region to add
|
||||||
|
* @return true when successful, otherwise false (denied by an event listener)
|
||||||
*/
|
*/
|
||||||
public void addRent(RentRegion rent) {
|
public AddingRegionEvent addRegionNoSave(GeneralRegion region) {
|
||||||
addRentNoSave(rent);
|
AddingRegionEvent event = new AddingRegionEvent(region);
|
||||||
rent.saveRequired();
|
if(region == null) {
|
||||||
markGroupsAutoDirty();
|
AreaShop.debug("Tried adding a null region!");
|
||||||
|
event.cancel("null region");
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
regions.put(region.getName().toLowerCase(), region);
|
||||||
|
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(region));
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,29 +334,6 @@ public class FileManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a buy to the list without saving it to disk (useful for loading at startup).
|
|
||||||
* @param buy The buy region to add
|
|
||||||
*/
|
|
||||||
public void addBuyNoSave(BuyRegion buy) {
|
|
||||||
if(buy == null) {
|
|
||||||
AreaShop.debug("Tried adding a null buy!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
regions.put(buy.getName().toLowerCase(), buy);
|
|
||||||
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(buy));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a buy to the list and mark it as to-be-saved.
|
|
||||||
* @param buy The buy region to add
|
|
||||||
*/
|
|
||||||
public void addBuy(BuyRegion buy) {
|
|
||||||
addBuyNoSave(buy);
|
|
||||||
buy.saveRequired();
|
|
||||||
markGroupsAutoDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a RegionGroup.
|
* Add a RegionGroup.
|
||||||
* @param group The RegionGroup to add
|
* @param group The RegionGroup to add
|
||||||
|
@ -397,113 +389,68 @@ public class FileManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a rent from the list.
|
|
||||||
* @param rent The region to remove
|
|
||||||
* @param giveMoneyBack use true to give money back to the player if someone is currently renting this region, otherwise false
|
|
||||||
* @return true if the rent has been removed, false otherwise
|
|
||||||
*/
|
|
||||||
public boolean removeRent(RentRegion rent, boolean giveMoneyBack) {
|
|
||||||
boolean result = false;
|
|
||||||
if(rent != null) {
|
|
||||||
rent.setDeleted();
|
|
||||||
if(rent.isRented()) {
|
|
||||||
rent.unRent(giveMoneyBack, null);
|
|
||||||
}
|
|
||||||
// Handle schematics and run commands
|
|
||||||
rent.handleSchematicEvent(RegionEvent.DELETED);
|
|
||||||
rent.runEventCommands(RegionEvent.DELETED, true);
|
|
||||||
|
|
||||||
// Delete the signs and the variable
|
|
||||||
if(rent.getWorld() != null) {
|
|
||||||
for(Location sign : rent.getSignsFeature().getSignLocations()) {
|
|
||||||
sign.getBlock().setType(Material.AIR);
|
|
||||||
AreaShop.debug("Removed sign at: " + sign.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RegionGroup[] regionGroups = getGroups().toArray(new RegionGroup[0]);
|
|
||||||
for(RegionGroup group : regionGroups) {
|
|
||||||
group.removeMember(rent);
|
|
||||||
}
|
|
||||||
rent.resetRegionFlags();
|
|
||||||
regions.remove(rent.getLowerCaseName());
|
|
||||||
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + rent.getLowerCaseName() + ".yml");
|
|
||||||
boolean deleted;
|
|
||||||
if(file.exists()) {
|
|
||||||
try {
|
|
||||||
deleted = file.delete();
|
|
||||||
} catch(Exception e) {
|
|
||||||
deleted = false;
|
|
||||||
}
|
|
||||||
if(!deleted) {
|
|
||||||
AreaShop.warn("File could not be deleted: " + file.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
// Broadcast event
|
|
||||||
Bukkit.getPluginManager().callEvent(new DeletedRegionEvent(rent));
|
|
||||||
|
|
||||||
// Run commands
|
|
||||||
rent.runEventCommands(RegionEvent.DELETED, false);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a buy from the list.
|
* Remove a region from the list.
|
||||||
* @param buy The BuyRegion to remove
|
* @param region The region to remove
|
||||||
* @param giveMoneyBack true if money should be given back to the player, otherwise false
|
* @param giveMoneyBack use true to give money back to the player if someone is currently holding this region, otherwise false
|
||||||
* @return true if the buy has been removed, false otherwise
|
* @return true if the region has been removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean removeBuy(BuyRegion buy, boolean giveMoneyBack) {
|
public DeletingRegionEvent deleteRegion(GeneralRegion region, boolean giveMoneyBack) {
|
||||||
boolean result = false;
|
DeletingRegionEvent event = new DeletingRegionEvent(region);
|
||||||
if(buy != null) {
|
if(region == null) {
|
||||||
buy.setDeleted();
|
event.cancel("null region");
|
||||||
if(buy.isSold()) {
|
return event;
|
||||||
buy.sell(giveMoneyBack, null);
|
|
||||||
}
|
|
||||||
// Handle schematics and run commands
|
|
||||||
buy.handleSchematicEvent(RegionEvent.DELETED);
|
|
||||||
buy.runEventCommands(RegionEvent.DELETED, true);
|
|
||||||
|
|
||||||
// Delete the sign and the variable
|
|
||||||
if(buy.getWorld() != null) {
|
|
||||||
for(Location sign : buy.getSignsFeature().getSignLocations()) {
|
|
||||||
sign.getBlock().setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
regions.remove(buy.getLowerCaseName());
|
|
||||||
buy.resetRegionFlags();
|
|
||||||
|
|
||||||
// Removing from groups
|
|
||||||
for(RegionGroup group : getGroups()) {
|
|
||||||
group.removeMember(buy);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deleting the file
|
|
||||||
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + buy.getLowerCaseName() + ".yml");
|
|
||||||
boolean deleted;
|
|
||||||
if(file.exists()) {
|
|
||||||
try {
|
|
||||||
deleted = file.delete();
|
|
||||||
} catch(Exception e) {
|
|
||||||
deleted = false;
|
|
||||||
}
|
|
||||||
if(!deleted) {
|
|
||||||
AreaShop.warn("File could not be deleted: " + file.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
// Broadcast event
|
|
||||||
Bukkit.getPluginManager().callEvent(new DeletedRegionEvent(buy));
|
|
||||||
|
|
||||||
// Run commands
|
|
||||||
buy.runEventCommands(RegionEvent.DELETED, false);
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
region.setDeleted();
|
||||||
|
if(region instanceof RentRegion && ((RentRegion)region).isRented()) {
|
||||||
|
((RentRegion)region).unRent(giveMoneyBack, null);
|
||||||
|
} else if (region instanceof BuyRegion && ((BuyRegion)region).isSold()) {
|
||||||
|
((BuyRegion)region).sell(giveMoneyBack, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle schematics
|
||||||
|
region.handleSchematicEvent(RegionEvent.DELETED);
|
||||||
|
|
||||||
|
// Delete the signs
|
||||||
|
if(region.getWorld() != null) {
|
||||||
|
for(Location sign : region.getSignsFeature().getSignLocations()) {
|
||||||
|
sign.getBlock().setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove from RegionGroups
|
||||||
|
RegionGroup[] regionGroups = getGroups().toArray(new RegionGroup[0]);
|
||||||
|
for(RegionGroup group : regionGroups) {
|
||||||
|
group.removeMember(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
region.resetRegionFlags();
|
||||||
|
regions.remove(region.getLowerCaseName());
|
||||||
|
|
||||||
|
// Remove file
|
||||||
|
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + region.getLowerCaseName() + ".yml");
|
||||||
|
if(file.exists()) {
|
||||||
|
boolean deleted;
|
||||||
|
try {
|
||||||
|
deleted = file.delete();
|
||||||
|
} catch(Exception e) {
|
||||||
|
deleted = false;
|
||||||
|
}
|
||||||
|
if(!deleted) {
|
||||||
|
AreaShop.warn("File could not be deleted: " + file.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Broadcast event
|
||||||
|
Bukkit.getPluginManager().callEvent(new DeletedRegionEvent(region));
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -989,11 +936,7 @@ public class FileManager extends Manager {
|
||||||
incorrectDuration.add(region);
|
incorrectDuration.add(region);
|
||||||
} else {
|
} else {
|
||||||
added = true;
|
added = true;
|
||||||
if(region instanceof RentRegion) {
|
addRegionNoSave(region);
|
||||||
addRentNoSave((RentRegion)region);
|
|
||||||
} else if(region instanceof BuyRegion) {
|
|
||||||
addBuyNoSave((BuyRegion)region);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!added) {
|
if(!added) {
|
||||||
region.destroy();
|
region.destroy();
|
||||||
|
|
|
@ -259,189 +259,186 @@ public class BuyRegion extends GeneralRegion {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean buy(OfflinePlayer offlinePlayer) {
|
public boolean buy(OfflinePlayer offlinePlayer) {
|
||||||
// Check if the player has permission
|
// Check if the player has permission
|
||||||
if(plugin.hasPermission(offlinePlayer, "areashop.buy")) {
|
if(!plugin.hasPermission(offlinePlayer, "areashop.buy")) {
|
||||||
if(plugin.getEconomy() == null) {
|
message(offlinePlayer, "buy-noPermission");
|
||||||
message(offlinePlayer, "general-noEconomy");
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(plugin.getEconomy() == null) {
|
||||||
|
message(offlinePlayer, "general-noEconomy");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isInResellingMode()) {
|
||||||
|
if(!plugin.hasPermission(offlinePlayer, "areashop.buyresell")) {
|
||||||
|
message(offlinePlayer, "buy-noPermissionResell");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(isInResellingMode()) {
|
|
||||||
if(!plugin.hasPermission(offlinePlayer, "areashop.buyresell")) {
|
|
||||||
message(offlinePlayer, "buy-noPermissionResell");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(!plugin.hasPermission(offlinePlayer, "areashop.buynormal")) {
|
|
||||||
message(offlinePlayer, "buy-noPermissionNoResell");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(getWorld() == null) {
|
|
||||||
message(offlinePlayer, "general-noWorld");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(getRegion() == null) {
|
|
||||||
message(offlinePlayer, "general-noRegion");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!isSold() || (isInResellingMode() && !isBuyer(offlinePlayer))) {
|
|
||||||
boolean isResell = isInResellingMode();
|
|
||||||
|
|
||||||
// Only relevant if the player is online
|
|
||||||
Player player = offlinePlayer.getPlayer();
|
|
||||||
if(player != null) {
|
|
||||||
// Check if the players needs to be in the region for buying
|
|
||||||
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
|
||||||
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
|
||||||
message(offlinePlayer, "buy-restrictedToRegion");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Check if the players needs to be in the world for buying
|
|
||||||
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
|
||||||
message(offlinePlayer, "buy-restrictedToWorld", player.getWorld().getName());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check region limits
|
|
||||||
LimitResult limitResult = this.limitsAllow(RegionType.BUY, offlinePlayer);
|
|
||||||
AreaShop.debug("LimitResult: " + limitResult.toString());
|
|
||||||
if(!limitResult.actionAllowed()) {
|
|
||||||
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
|
|
||||||
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(limitResult.getLimitingFactor() == LimitType.BUYS) {
|
|
||||||
message(offlinePlayer, "buy-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Should not be reached, but is safe like this
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the player has enough money
|
|
||||||
if((!isResell && plugin.getEconomy().has(offlinePlayer, getWorldName(), getPrice())) || (isResell && plugin.getEconomy().has(offlinePlayer, getWorldName(), getResellPrice()))) {
|
|
||||||
UUID oldOwner = getBuyer();
|
|
||||||
if(isResell && oldOwner != null) {
|
|
||||||
// Broadcast and check event
|
|
||||||
ResellingRegionEvent event = new ResellingRegionEvent(this, offlinePlayer);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if(event.isCancelled()) {
|
|
||||||
message(offlinePlayer, "general-cancelled", event.getReason());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
getFriendsFeature().clearFriends();
|
|
||||||
double resellPrice = getResellPrice();
|
|
||||||
// Transfer the money to the previous owner
|
|
||||||
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getResellPrice());
|
|
||||||
if(!r.transactionSuccess()) {
|
|
||||||
message(offlinePlayer, "buy-payError");
|
|
||||||
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while buying " + getName() + ": " + r.errorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
r = null;
|
|
||||||
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
|
|
||||||
String oldOwnerName = getPlayerName();
|
|
||||||
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
|
|
||||||
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
|
|
||||||
oldOwnerName = oldOwnerPlayer.getName();
|
|
||||||
} else if(oldOwnerName != null) {
|
|
||||||
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
|
|
||||||
}
|
|
||||||
if(r == null || !r.transactionSuccess()) {
|
|
||||||
AreaShop.warn("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
// Resell is done, disable that now
|
|
||||||
disableReselling();
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.RESELL, true);
|
|
||||||
// Set the owner
|
|
||||||
setBuyer(offlinePlayer.getUniqueId());
|
|
||||||
updateLastActiveTime();
|
|
||||||
|
|
||||||
// Update everything
|
|
||||||
handleSchematicEvent(RegionEvent.RESELL);
|
|
||||||
|
|
||||||
// Notify about updates
|
|
||||||
this.notifyAndUpdate(new ResoldRegionEvent(this, oldOwner));
|
|
||||||
|
|
||||||
// Send message to the player
|
|
||||||
message(offlinePlayer, "buy-successResale", oldOwnerName);
|
|
||||||
Player seller = Bukkit.getPlayer(oldOwner);
|
|
||||||
if(seller != null) {
|
|
||||||
message(seller, "buy-successSeller", resellPrice);
|
|
||||||
}
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.RESELL, false);
|
|
||||||
} else {
|
|
||||||
// Broadcast and check event
|
|
||||||
BuyingRegionEvent event = new BuyingRegionEvent(this, offlinePlayer);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if(event.isCancelled()) {
|
|
||||||
message(offlinePlayer, "general-cancelled", event.getReason());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Substract the money from the players balance
|
|
||||||
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getPrice());
|
|
||||||
if(!r.transactionSuccess()) {
|
|
||||||
message(offlinePlayer, "buy-payError");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Optionally give money to the landlord
|
|
||||||
OfflinePlayer landlordPlayer = null;
|
|
||||||
if(getLandlord() != null) {
|
|
||||||
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
|
|
||||||
}
|
|
||||||
String landlordName = getLandlordName();
|
|
||||||
if(landlordName != null) {
|
|
||||||
if(landlordPlayer != null && landlordPlayer.getName() != null) {
|
|
||||||
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
|
|
||||||
} else {
|
|
||||||
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
|
|
||||||
}
|
|
||||||
if(r != null && !r.transactionSuccess()) {
|
|
||||||
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + getFormattedPrice() + " for his sell of region " + getName() + " to " + offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.BOUGHT, true);
|
|
||||||
// Set the owner
|
|
||||||
setBuyer(offlinePlayer.getUniqueId());
|
|
||||||
updateLastActiveTime();
|
|
||||||
|
|
||||||
// Notify about updates
|
|
||||||
this.notifyAndUpdate(new BoughtRegionEvent(this));
|
|
||||||
|
|
||||||
// Update everything
|
|
||||||
handleSchematicEvent(RegionEvent.BOUGHT);
|
|
||||||
|
|
||||||
// Send message to the player
|
|
||||||
message(offlinePlayer, "buy-succes");
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.BOUGHT, false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// Player has not enough money
|
|
||||||
if(isResell) {
|
|
||||||
message(offlinePlayer, "buy-lowMoneyResell", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "buy-lowMoney", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(isBuyer(offlinePlayer)) {
|
|
||||||
message(offlinePlayer, "buy-yours");
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "buy-someoneElse");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
message(offlinePlayer, "buy-noPermission");
|
if(!plugin.hasPermission(offlinePlayer, "areashop.buynormal")) {
|
||||||
|
message(offlinePlayer, "buy-noPermissionNoResell");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if(getWorld() == null) {
|
||||||
|
message(offlinePlayer, "general-noWorld");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getRegion() == null) {
|
||||||
|
message(offlinePlayer, "general-noRegion");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSold() && !(isInResellingMode() && !isBuyer(offlinePlayer))) {
|
||||||
|
if(isBuyer(offlinePlayer)) {
|
||||||
|
message(offlinePlayer, "buy-yours");
|
||||||
|
} else {
|
||||||
|
message(offlinePlayer, "buy-someoneElse");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isResell = isInResellingMode();
|
||||||
|
|
||||||
|
// Only relevant if the player is online
|
||||||
|
Player player = offlinePlayer.getPlayer();
|
||||||
|
if(player != null) {
|
||||||
|
// Check if the players needs to be in the region for buying
|
||||||
|
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
||||||
|
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
||||||
|
message(offlinePlayer, "buy-restrictedToRegion");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check if the players needs to be in the world for buying
|
||||||
|
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
||||||
|
message(offlinePlayer, "buy-restrictedToWorld", player.getWorld().getName());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check region limits
|
||||||
|
LimitResult limitResult = this.limitsAllow(RegionType.BUY, offlinePlayer);
|
||||||
|
AreaShop.debug("LimitResult: " + limitResult.toString());
|
||||||
|
if(!limitResult.actionAllowed()) {
|
||||||
|
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
|
||||||
|
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(limitResult.getLimitingFactor() == LimitType.BUYS) {
|
||||||
|
message(offlinePlayer, "buy-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Should not be reached, but is safe like this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the player has enough money
|
||||||
|
if (isResell && !plugin.getEconomy().has(offlinePlayer, getWorldName(), getResellPrice())) {
|
||||||
|
message(offlinePlayer, "buy-lowMoneyResell", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isResell && !plugin.getEconomy().has(offlinePlayer, getWorldName(), getPrice())) {
|
||||||
|
message(offlinePlayer, "buy-lowMoney", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID oldOwner = getBuyer();
|
||||||
|
if(isResell && oldOwner != null) {
|
||||||
|
// Broadcast and check event
|
||||||
|
ResellingRegionEvent event = new ResellingRegionEvent(this, offlinePlayer);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
message(offlinePlayer, "general-cancelled", event.getReason());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
getFriendsFeature().clearFriends();
|
||||||
|
double resellPrice = getResellPrice();
|
||||||
|
// Transfer the money to the previous owner
|
||||||
|
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getResellPrice());
|
||||||
|
if(!r.transactionSuccess()) {
|
||||||
|
message(offlinePlayer, "buy-payError");
|
||||||
|
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while buying " + getName() + ": " + r.errorMessage);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
r = null;
|
||||||
|
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
|
||||||
|
String oldOwnerName = getPlayerName();
|
||||||
|
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
|
||||||
|
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
|
||||||
|
oldOwnerName = oldOwnerPlayer.getName();
|
||||||
|
} else if(oldOwnerName != null) {
|
||||||
|
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
|
||||||
|
}
|
||||||
|
if(r == null || !r.transactionSuccess()) {
|
||||||
|
AreaShop.warn("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
// Resell is done, disable that now
|
||||||
|
disableReselling();
|
||||||
|
|
||||||
|
// Set the owner
|
||||||
|
setBuyer(offlinePlayer.getUniqueId());
|
||||||
|
updateLastActiveTime();
|
||||||
|
|
||||||
|
// Update everything
|
||||||
|
handleSchematicEvent(RegionEvent.RESELL);
|
||||||
|
|
||||||
|
// Notify about updates
|
||||||
|
this.notifyAndUpdate(new ResoldRegionEvent(this, oldOwner));
|
||||||
|
|
||||||
|
// Send message to the player
|
||||||
|
message(offlinePlayer, "buy-successResale", oldOwnerName);
|
||||||
|
Player seller = Bukkit.getPlayer(oldOwner);
|
||||||
|
if(seller != null) {
|
||||||
|
message(seller, "buy-successSeller", resellPrice);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Broadcast and check event
|
||||||
|
BuyingRegionEvent event = new BuyingRegionEvent(this, offlinePlayer);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
message(offlinePlayer, "general-cancelled", event.getReason());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Substract the money from the players balance
|
||||||
|
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getPrice());
|
||||||
|
if(!r.transactionSuccess()) {
|
||||||
|
message(offlinePlayer, "buy-payError");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Optionally give money to the landlord
|
||||||
|
OfflinePlayer landlordPlayer = null;
|
||||||
|
if(getLandlord() != null) {
|
||||||
|
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
|
||||||
|
}
|
||||||
|
String landlordName = getLandlordName();
|
||||||
|
if(landlordName != null) {
|
||||||
|
if(landlordPlayer != null && landlordPlayer.getName() != null) {
|
||||||
|
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
|
||||||
|
} else {
|
||||||
|
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
|
||||||
|
}
|
||||||
|
if(r != null && !r.transactionSuccess()) {
|
||||||
|
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + getFormattedPrice() + " for his sell of region " + getName() + " to " + offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the owner
|
||||||
|
setBuyer(offlinePlayer.getUniqueId());
|
||||||
|
updateLastActiveTime();
|
||||||
|
|
||||||
|
// Send message to the player
|
||||||
|
message(offlinePlayer, "buy-succes");
|
||||||
|
|
||||||
|
// Update everything
|
||||||
|
handleSchematicEvent(RegionEvent.BOUGHT);
|
||||||
|
|
||||||
|
// Notify about updates
|
||||||
|
this.notifyAndUpdate(new BoughtRegionEvent(this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,9 +480,6 @@ public class BuyRegion extends GeneralRegion {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.SOLD, true);
|
|
||||||
|
|
||||||
disableReselling();
|
disableReselling();
|
||||||
// Give part of the buying price back
|
// Give part of the buying price back
|
||||||
double moneyBack = getMoneyBackAmount();
|
double moneyBack = getMoneyBackAmount();
|
||||||
|
@ -528,8 +522,6 @@ public class BuyRegion extends GeneralRegion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message(executor, "sell-sold");
|
|
||||||
|
|
||||||
// Handle schematic save/restore (while %uuid% is still available)
|
// Handle schematic save/restore (while %uuid% is still available)
|
||||||
handleSchematicEvent(RegionEvent.SOLD);
|
handleSchematicEvent(RegionEvent.SOLD);
|
||||||
|
|
||||||
|
@ -539,11 +531,10 @@ public class BuyRegion extends GeneralRegion {
|
||||||
setBuyer(null);
|
setBuyer(null);
|
||||||
removeLastActiveTime();
|
removeLastActiveTime();
|
||||||
|
|
||||||
|
message(executor, "sell-sold");
|
||||||
|
|
||||||
// Notify about updates
|
// Notify about updates
|
||||||
this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer, Math.max(moneyBack, 0)));
|
this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer, Math.max(moneyBack, 0)));
|
||||||
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.SOLD, false);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,15 +183,16 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||||
/**
|
/**
|
||||||
* Get a feature of this region.
|
* Get a feature of this region.
|
||||||
* @param clazz The class of the feature to get
|
* @param clazz The class of the feature to get
|
||||||
* @return The feature (either just instanciated or cached)
|
* @param <T> The feature to get
|
||||||
|
* @return The feature (either just instantiated or cached)
|
||||||
*/
|
*/
|
||||||
public RegionFeature getFeature(Class<? extends RegionFeature> clazz) {
|
public <T extends RegionFeature> T getFeature(Class<T> clazz) {
|
||||||
RegionFeature result = features.get(clazz);
|
RegionFeature result = features.get(clazz);
|
||||||
if(result == null) {
|
if(result == null) {
|
||||||
result = plugin.getFeatureManager().getRegionFeature(this, clazz);
|
result = plugin.getFeatureManager().getRegionFeature(this, clazz);
|
||||||
features.put(clazz, result);
|
features.put(clazz, result);
|
||||||
}
|
}
|
||||||
return result;
|
return clazz.cast(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +200,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||||
* @return The FriendsFeature of this region
|
* @return The FriendsFeature of this region
|
||||||
*/
|
*/
|
||||||
public FriendsFeature getFriendsFeature() {
|
public FriendsFeature getFriendsFeature() {
|
||||||
return (FriendsFeature)getFeature(FriendsFeature.class);
|
return getFeature(FriendsFeature.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,7 +208,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||||
* @return The SignsFeature of this region
|
* @return The SignsFeature of this region
|
||||||
*/
|
*/
|
||||||
public SignsFeature getSignsFeature() {
|
public SignsFeature getSignsFeature() {
|
||||||
return (SignsFeature)getFeature(SignsFeature.class);
|
return getFeature(SignsFeature.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,7 +216,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||||
* @return The TeleportFeature
|
* @return The TeleportFeature
|
||||||
*/
|
*/
|
||||||
public TeleportFeature getTeleportFeature() {
|
public TeleportFeature getTeleportFeature() {
|
||||||
return (TeleportFeature)getFeature(TeleportFeature.class);
|
return getFeature(TeleportFeature.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ABSTRACT
|
// ABSTRACT
|
||||||
|
@ -1479,23 +1480,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Run command for a certain event.
|
|
||||||
* @param event The event
|
|
||||||
* @param before The 'before' or 'after' commands
|
|
||||||
*/
|
|
||||||
public void runEventCommands(RegionEvent event, boolean before) {
|
|
||||||
ConfigurationSection eventCommandProfileSection = getConfigurationSectionSetting("general.eventCommandProfile", "eventCommandProfiles");
|
|
||||||
if(eventCommandProfileSection == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> commands = eventCommandProfileSection.getStringList(event.getValue() + "." + (before ? "before" : "after"));
|
|
||||||
if(commands == null || commands.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
runCommands(Bukkit.getConsoleSender(), commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the volume of the region (number of blocks inside it).
|
* Get the volume of the region (number of blocks inside it).
|
||||||
* @return Number of blocks in the region
|
* @return Number of blocks in the region
|
||||||
|
|
|
@ -432,200 +432,189 @@ public class RentRegion extends GeneralRegion {
|
||||||
message(offlinePlayer, "general-noEconomy");
|
message(offlinePlayer, "general-noEconomy");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Check if the player has permission
|
|
||||||
if(plugin.hasPermission(offlinePlayer, "areashop.rent")) {
|
|
||||||
if(getWorld() == null) {
|
|
||||||
message(offlinePlayer, "general-noWorld");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(getRegion() == null) {
|
|
||||||
message(offlinePlayer, "general-noRegion");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean extend = false;
|
|
||||||
if(getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter())) {
|
|
||||||
extend = true;
|
|
||||||
}
|
|
||||||
// Check if the region is available for renting or if the player wants to extend the rent
|
|
||||||
if(!isRented() || extend) {
|
|
||||||
// These checks are only relevant for online players doing the renting/buying themselves
|
|
||||||
Player player = offlinePlayer.getPlayer();
|
|
||||||
if(player != null) {
|
|
||||||
// Check if the players needs to be in the region for renting
|
|
||||||
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
|
||||||
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
|
||||||
message(offlinePlayer, "rent-restrictedToRegion");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the players needs to be in the world for renting
|
// Check if the player has permission
|
||||||
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
if(!plugin.hasPermission(offlinePlayer, "areashop.rent")) {
|
||||||
message(offlinePlayer, "rent-restrictedToWorld", player.getWorld().getName());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check region limits if this is not extending
|
|
||||||
if(!(extend && config.getBoolean("allowRegionExtendsWhenAboveLimits"))) {
|
|
||||||
|
|
||||||
LimitResult limitResult;
|
|
||||||
if(extend) {
|
|
||||||
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer, true);
|
|
||||||
} else {
|
|
||||||
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer);
|
|
||||||
}
|
|
||||||
AreaShop.debug("LimitResult: " + limitResult.toString());
|
|
||||||
if(!limitResult.actionAllowed()) {
|
|
||||||
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
|
|
||||||
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(limitResult.getLimitingFactor() == LimitType.RENTS) {
|
|
||||||
message(offlinePlayer, "rent-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(limitResult.getLimitingFactor() == LimitType.EXTEND) {
|
|
||||||
message(offlinePlayer, "rent-maximumExtend", limitResult.getMaximum(), limitResult.getCurrent() + 1, limitResult.getLimitingGroup());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the player can still extend this rent
|
|
||||||
if(extend && !plugin.hasPermission(offlinePlayer, "areashop.rentextendbypass")) {
|
|
||||||
if(getMaxExtends() >= 0 && getTimesExtended() >= getMaxExtends()) {
|
|
||||||
message(offlinePlayer, "rent-maxExtends");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there is enough time left before hitting maxRentTime
|
|
||||||
boolean extendToMax = false;
|
|
||||||
double price = getPrice();
|
|
||||||
long timeNow = Calendar.getInstance().getTimeInMillis();
|
|
||||||
long timeRented = 0;
|
|
||||||
long maxRentTime = getMaxRentTime();
|
|
||||||
if(isRented()) {
|
|
||||||
timeRented = getRentedUntil() - timeNow;
|
|
||||||
}
|
|
||||||
if((timeRented + getDuration()) > (maxRentTime)
|
|
||||||
&& !plugin.hasPermission(offlinePlayer, "areashop.renttimebypass")
|
|
||||||
&& maxRentTime != -1) {
|
|
||||||
// Extend to the maximum instead of adding a full period
|
|
||||||
if(getBooleanSetting("rent.extendToFullWhenAboveMaxRentTime")) {
|
|
||||||
if(timeRented >= maxRentTime) {
|
|
||||||
message(offlinePlayer, "rent-alreadyAtFull");
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
long toRentPart = maxRentTime - timeRented;
|
|
||||||
extendToMax = true;
|
|
||||||
price = ((double)toRentPart) / getDuration() * price;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "rent-maxRentTime");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(plugin.getEconomy().has(offlinePlayer, getWorldName(), price)) {
|
|
||||||
// Broadcast and check event
|
|
||||||
RentingRegionEvent event = new RentingRegionEvent(this, offlinePlayer, extend);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if(event.isCancelled()) {
|
|
||||||
message(offlinePlayer, "general-cancelled", event.getReason());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Substract the money from the players balance
|
|
||||||
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), price);
|
|
||||||
if(!r.transactionSuccess()) {
|
|
||||||
message(offlinePlayer, "rent-payError");
|
|
||||||
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while renting " + getName() + ": " + r.errorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Optionally give money to the landlord
|
|
||||||
OfflinePlayer landlordPlayer = null;
|
|
||||||
if(getLandlord() != null) {
|
|
||||||
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
|
|
||||||
}
|
|
||||||
String landlordName = getLandlordName();
|
|
||||||
if(landlordName != null) {
|
|
||||||
if(landlordPlayer != null && landlordPlayer.getName() != null) {
|
|
||||||
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), price);
|
|
||||||
} else {
|
|
||||||
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), price);
|
|
||||||
}
|
|
||||||
if(r == null || !r.transactionSuccess()) {
|
|
||||||
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + Utils.formatCurrency(price) + " for his rent of region " + getName() + " to " + offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!extend) {
|
|
||||||
// Run commands
|
|
||||||
runEventCommands(RegionEvent.RENTED, true);
|
|
||||||
} else {
|
|
||||||
// Run commands
|
|
||||||
runEventCommands(RegionEvent.EXTENDED, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the time until the region will be rented
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
if(extendToMax) {
|
|
||||||
calendar.setTimeInMillis(calendar.getTimeInMillis() + getMaxRentTime());
|
|
||||||
} else if(extend) {
|
|
||||||
calendar.setTimeInMillis(getRentedUntil() + getDuration());
|
|
||||||
} else {
|
|
||||||
calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add values to the rent and send it to FileManager
|
|
||||||
setRentedUntil(calendar.getTimeInMillis());
|
|
||||||
setRenter(offlinePlayer.getUniqueId());
|
|
||||||
updateLastActiveTime();
|
|
||||||
|
|
||||||
// Fire schematic event and updated times extended
|
|
||||||
if(!extend) {
|
|
||||||
this.handleSchematicEvent(RegionEvent.RENTED);
|
|
||||||
setTimesExtended(0);
|
|
||||||
} else {
|
|
||||||
setTimesExtended(getTimesExtended() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify about updates
|
|
||||||
this.notifyAndUpdate(new RentedRegionEvent(this, extend));
|
|
||||||
|
|
||||||
// Send message to the player
|
|
||||||
if(extendToMax) {
|
|
||||||
message(offlinePlayer, "rent-extendedToMax");
|
|
||||||
} else if(extend) {
|
|
||||||
message(offlinePlayer, "rent-extended");
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "rent-rented");
|
|
||||||
}
|
|
||||||
if(!extend) {
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.RENTED, false);
|
|
||||||
} else {
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.EXTENDED, false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// Player has not enough money
|
|
||||||
if(extend) {
|
|
||||||
message(offlinePlayer, "rent-lowMoneyExtend", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "rent-lowMoneyRent", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "rent-someoneElse");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message(offlinePlayer, "rent-noPermission");
|
message(offlinePlayer, "rent-noPermission");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
// Check location restrictions
|
||||||
|
if(getWorld() == null) {
|
||||||
|
message(offlinePlayer, "general-noWorld");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(getRegion() == null) {
|
||||||
|
message(offlinePlayer, "general-noRegion");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean extend = false;
|
||||||
|
if(getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter())) {
|
||||||
|
extend = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if available or extending
|
||||||
|
if (isRented() && !extend) {
|
||||||
|
message(offlinePlayer, "rent-someoneElse");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// These checks are only relevant for online players doing the renting/buying themselves
|
||||||
|
Player player = offlinePlayer.getPlayer();
|
||||||
|
if(player != null) {
|
||||||
|
// Check if the players needs to be in the region for renting
|
||||||
|
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
||||||
|
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
||||||
|
message(offlinePlayer, "rent-restrictedToRegion");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the players needs to be in the world for renting
|
||||||
|
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
||||||
|
message(offlinePlayer, "rent-restrictedToWorld", player.getWorld().getName());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check region limits if this is not extending
|
||||||
|
if(!(extend && config.getBoolean("allowRegionExtendsWhenAboveLimits"))) {
|
||||||
|
|
||||||
|
LimitResult limitResult;
|
||||||
|
if(extend) {
|
||||||
|
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer, true);
|
||||||
|
} else {
|
||||||
|
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer);
|
||||||
|
}
|
||||||
|
AreaShop.debug("LimitResult: " + limitResult.toString());
|
||||||
|
if(!limitResult.actionAllowed()) {
|
||||||
|
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
|
||||||
|
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(limitResult.getLimitingFactor() == LimitType.RENTS) {
|
||||||
|
message(offlinePlayer, "rent-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(limitResult.getLimitingFactor() == LimitType.EXTEND) {
|
||||||
|
message(offlinePlayer, "rent-maximumExtend", limitResult.getMaximum(), limitResult.getCurrent() + 1, limitResult.getLimitingGroup());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the player can still extend this rent
|
||||||
|
if(extend && !plugin.hasPermission(offlinePlayer, "areashop.rentextendbypass")) {
|
||||||
|
if(getMaxExtends() >= 0 && getTimesExtended() >= getMaxExtends()) {
|
||||||
|
message(offlinePlayer, "rent-maxExtends");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is enough time left before hitting maxRentTime
|
||||||
|
boolean extendToMax = false;
|
||||||
|
double price = getPrice();
|
||||||
|
long timeNow = Calendar.getInstance().getTimeInMillis();
|
||||||
|
long timeRented = 0;
|
||||||
|
long maxRentTime = getMaxRentTime();
|
||||||
|
if(isRented()) {
|
||||||
|
timeRented = getRentedUntil() - timeNow;
|
||||||
|
}
|
||||||
|
if((timeRented + getDuration()) > (maxRentTime)
|
||||||
|
&& !plugin.hasPermission(offlinePlayer, "areashop.renttimebypass")
|
||||||
|
&& maxRentTime != -1) {
|
||||||
|
// Extend to the maximum instead of adding a full period
|
||||||
|
if(getBooleanSetting("rent.extendToFullWhenAboveMaxRentTime")) {
|
||||||
|
if(timeRented >= maxRentTime) {
|
||||||
|
message(offlinePlayer, "rent-alreadyAtFull");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
long toRentPart = maxRentTime - timeRented;
|
||||||
|
extendToMax = true;
|
||||||
|
price = ((double)toRentPart) / getDuration() * price;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message(offlinePlayer, "rent-maxRentTime");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the player has enough money
|
||||||
|
if(!plugin.getEconomy().has(offlinePlayer, getWorldName(), price)) {
|
||||||
|
if(extend) {
|
||||||
|
message(offlinePlayer, "rent-lowMoneyExtend", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
||||||
|
} else {
|
||||||
|
message(offlinePlayer, "rent-lowMoneyRent", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Broadcast and check event
|
||||||
|
RentingRegionEvent event = new RentingRegionEvent(this, offlinePlayer, extend);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
message(offlinePlayer, "general-cancelled", event.getReason());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Substract the money from the players balance
|
||||||
|
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), price);
|
||||||
|
if(!r.transactionSuccess()) {
|
||||||
|
message(offlinePlayer, "rent-payError");
|
||||||
|
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while renting " + getName() + ": " + r.errorMessage);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Optionally give money to the landlord
|
||||||
|
OfflinePlayer landlordPlayer = null;
|
||||||
|
if(getLandlord() != null) {
|
||||||
|
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
|
||||||
|
}
|
||||||
|
String landlordName = getLandlordName();
|
||||||
|
if(landlordName != null) {
|
||||||
|
if(landlordPlayer != null && landlordPlayer.getName() != null) {
|
||||||
|
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), price);
|
||||||
|
} else {
|
||||||
|
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), price);
|
||||||
|
}
|
||||||
|
if(r == null || !r.transactionSuccess()) {
|
||||||
|
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + Utils.formatCurrency(price) + " for his rent of region " + getName() + " to " + offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the time until the region will be rented
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
if(extendToMax) {
|
||||||
|
calendar.setTimeInMillis(calendar.getTimeInMillis() + getMaxRentTime());
|
||||||
|
} else if(extend) {
|
||||||
|
calendar.setTimeInMillis(getRentedUntil() + getDuration());
|
||||||
|
} else {
|
||||||
|
calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add values to the rent and send it to FileManager
|
||||||
|
setRentedUntil(calendar.getTimeInMillis());
|
||||||
|
setRenter(offlinePlayer.getUniqueId());
|
||||||
|
updateLastActiveTime();
|
||||||
|
|
||||||
|
// Fire schematic event and updated times extended
|
||||||
|
if(!extend) {
|
||||||
|
this.handleSchematicEvent(RegionEvent.RENTED);
|
||||||
|
setTimesExtended(0);
|
||||||
|
} else {
|
||||||
|
setTimesExtended(getTimesExtended() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send message to the player
|
||||||
|
if(extendToMax) {
|
||||||
|
message(offlinePlayer, "rent-extendedToMax");
|
||||||
|
} else if(extend) {
|
||||||
|
message(offlinePlayer, "rent-extended");
|
||||||
|
} else {
|
||||||
|
message(offlinePlayer, "rent-rented");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify about updates
|
||||||
|
this.notifyAndUpdate(new RentedRegionEvent(this, extend));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -660,8 +649,7 @@ public class RentRegion extends GeneralRegion {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run commands
|
// Do a payback
|
||||||
this.runEventCommands(RegionEvent.UNRENTED, true);
|
|
||||||
double moneyBack = getMoneyBackAmount();
|
double moneyBack = getMoneyBackAmount();
|
||||||
if(moneyBack > 0 && giveMoneyBack) {
|
if(moneyBack > 0 && giveMoneyBack) {
|
||||||
boolean noPayBack = false;
|
boolean noPayBack = false;
|
||||||
|
@ -702,9 +690,6 @@ public class RentRegion extends GeneralRegion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send messages
|
|
||||||
message(executor, "unrent-unrented");
|
|
||||||
|
|
||||||
// Handle schematic save/restore (while %uuid% is still available)
|
// Handle schematic save/restore (while %uuid% is still available)
|
||||||
handleSchematicEvent(RegionEvent.UNRENTED);
|
handleSchematicEvent(RegionEvent.UNRENTED);
|
||||||
|
|
||||||
|
@ -716,11 +701,11 @@ public class RentRegion extends GeneralRegion {
|
||||||
setTimesExtended(-1);
|
setTimesExtended(-1);
|
||||||
removeLastActiveTime();
|
removeLastActiveTime();
|
||||||
|
|
||||||
|
// Send messages
|
||||||
|
message(executor, "unrent-unrented");
|
||||||
|
|
||||||
// Notify about updates
|
// Notify about updates
|
||||||
this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
|
this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
|
||||||
|
|
||||||
// Run commands
|
|
||||||
this.runEventCommands(RegionEvent.UNRENTED, false);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,6 +414,9 @@ add-success: "Added as %0%: [gray]%1%."
|
||||||
add-failed: "Already registered: [gray]%0%."
|
add-failed: "Already registered: [gray]%0%."
|
||||||
add-failedOtherWorld: "Already registered from another world: [gray]%0%."
|
add-failedOtherWorld: "Already registered from another world: [gray]%0%."
|
||||||
add-blacklisted: "On the blacklist: [gray]%0%."
|
add-blacklisted: "On the blacklist: [gray]%0%."
|
||||||
|
add-rentCancelled: "Rent cancelled: [gray]%0%."
|
||||||
|
add-buyCancelled: "Buy cancelled: [gray]%0%."
|
||||||
|
add-addCancelled: "Add cancelled: [gray]%0%."
|
||||||
add-specifyWorld: "Specify the world of the region when using from console."
|
add-specifyWorld: "Specify the world of the region when using from console."
|
||||||
add-incorrectWorld: "World '%0%' not found, try again (case-sensitive)."
|
add-incorrectWorld: "World '%0%' not found, try again (case-sensitive)."
|
||||||
add-noPermissionRegions: "No permission to add: [gray]%0%."
|
add-noPermissionRegions: "No permission to add: [gray]%0%."
|
||||||
|
@ -422,6 +425,7 @@ add-noPermissionOwnerMember: "[gray]You either are not a member/owner of these r
|
||||||
del-noPermission: "You don't have permission to remove regions."
|
del-noPermission: "You don't have permission to remove regions."
|
||||||
del-success: "Removed regions: [gray]%0%."
|
del-success: "Removed regions: [gray]%0%."
|
||||||
del-failed: "No permission to remove or not registered: [gray]%0%."
|
del-failed: "No permission to remove or not registered: [gray]%0%."
|
||||||
|
del-cancelled: "Delete cancelled: [gray]%0%."
|
||||||
|
|
||||||
addsign-help: "/as addsign [region] [profile]."
|
addsign-help: "/as addsign [region] [profile]."
|
||||||
addsign-noSign: "You are not looking at a sign."
|
addsign-noSign: "You are not looking at a sign."
|
||||||
|
|
Loading…
Reference in New Issue