use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.
the class SignsFeature method onSignChange.
@EventHandler(priority = EventPriority.MONITOR)
public void onSignChange(SignChangeEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (!plugin.isReady()) {
plugin.message(player, "general-notReady");
return;
}
// Check if the sign is meant for this plugin
if (event.getLine(0).contains(plugin.getConfig().getString("signTags.rent"))) {
if (!player.hasPermission("areashop.createrent") && !player.hasPermission("areashop.createrent.member") && !player.hasPermission("areashop.createrent.owner")) {
plugin.message(player, "setup-noPermissionRent");
return;
}
// Get the other lines
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
String fourthLine = event.getLine(3);
// Get the regionManager for accessing regions
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
// If the secondLine does not contain a name try to find the region by location
if (secondLine == null || secondLine.length() == 0) {
Set<ProtectedRegion> regions = plugin.getWorldGuardHandler().getApplicableRegionsSet(event.getBlock().getLocation());
if (regions != null) {
boolean first = true;
ProtectedRegion candidate = null;
for (ProtectedRegion pr : regions) {
if (first) {
candidate = pr;
first = false;
} else {
if (pr.getPriority() > candidate.getPriority()) {
candidate = pr;
} else if (pr.getPriority() < candidate.getPriority()) {
// Already got the correct one
} else if (pr.getParent() != null && pr.getParent().equals(candidate)) {
candidate = pr;
} else if (candidate.getParent() != null && candidate.getParent().equals(pr)) {
// Already got the correct one
} else {
plugin.message(player, "setup-couldNotDetect", candidate.getId(), pr.getId());
return;
}
}
}
if (candidate != null) {
secondLine = candidate.getId();
}
}
}
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;
}
ProtectedRegion region = regionManager.getRegion(secondLine);
if (region == null) {
plugin.message(player, "cmd-noRegion", secondLine);
return;
}
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), GeneralRegion.RegionType.RENT);
if (addResult == FileManager.AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
} else if (addResult == FileManager.AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
} else if (addResult == FileManager.AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
} else if (thirdLine != null && thirdLine.length() != 0 && !Utils.checkTimeFormat(thirdLine)) {
plugin.message(player, "setup-wrongDuration");
} else {
double price = 0.0;
if (priceSet) {
// Check the fourth line
try {
price = Double.parseDouble(fourthLine);
} catch (NumberFormatException e) {
plugin.message(player, "setup-wrongPrice");
return;
}
}
// Add rent to the FileManager
final RentRegion rent = new RentRegion(secondLine, event.getPlayer().getWorld());
boolean isMember = plugin.getWorldGuardHandler().containsMember(rent.getRegion(), player.getUniqueId());
boolean isOwner = plugin.getWorldGuardHandler().containsOwner(rent.getRegion(), 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(), player.getName());
}
if (priceSet) {
rent.setPrice(price);
}
if (durationSet) {
rent.setDuration(thirdLine);
}
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);
// Run commands
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addRent(rent);
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
plugin.message(player, "setup-rentSuccess", rent);
// Update the region after the event has written its lines
Do.sync(rent::update);
// Run commands
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
}
} else if (event.getLine(0).contains(plugin.getConfig().getString("signTags.buy"))) {
// Check for permission
if (!player.hasPermission("areashop.createbuy") && !player.hasPermission("areashop.createbuy.member") && !player.hasPermission("areashop.createbuy.owner")) {
plugin.message(player, "setup-noPermissionBuy");
return;
}
// Get the other lines
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
// Get the regionManager for accessing regions
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
// If the secondLine does not contain a name try to find the region by location
if (secondLine == null || secondLine.length() == 0) {
Set<ProtectedRegion> regions = plugin.getWorldGuardHandler().getApplicableRegionsSet(event.getBlock().getLocation());
if (regions != null) {
boolean first = true;
ProtectedRegion candidate = null;
for (ProtectedRegion pr : regions) {
if (first) {
candidate = pr;
first = false;
} else {
if (pr.getPriority() > candidate.getPriority()) {
candidate = pr;
} else if (pr.getPriority() < candidate.getPriority()) {
// Already got the correct one
} else if (pr.getParent() != null && pr.getParent().equals(candidate)) {
candidate = pr;
} else if (candidate.getParent() != null && candidate.getParent().equals(pr)) {
// Already got the correct one
} else {
plugin.message(player, "setup-couldNotDetect", candidate.getId(), pr.getId());
return;
}
}
}
if (candidate != null) {
secondLine = candidate.getId();
}
}
}
boolean priceSet = thirdLine != null && thirdLine.length() != 0;
// Check if all the lines are correct
if (secondLine == null || secondLine.length() == 0) {
plugin.message(player, "setup-noRegion");
return;
}
ProtectedRegion region = regionManager.getRegion(secondLine);
if (region == null) {
plugin.message(player, "cmd-noRegion", secondLine);
return;
}
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, GeneralRegion.RegionType.BUY);
if (addResult == FileManager.AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
} else if (addResult == FileManager.AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
} else if (addResult == FileManager.AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
} else {
double price = 0.0;
if (priceSet) {
// Check the fourth line
try {
price = Double.parseDouble(thirdLine);
} catch (NumberFormatException e) {
plugin.message(player, "setup-wrongPrice");
return;
}
}
// Add buy to the FileManager
final BuyRegion buy = new BuyRegion(secondLine, event.getPlayer().getWorld());
boolean isMember = plugin.getWorldGuardHandler().containsMember(buy.getRegion(), player.getUniqueId());
boolean isOwner = plugin.getWorldGuardHandler().containsOwner(buy.getRegion(), 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(), player.getName());
}
if (priceSet) {
buy.setPrice(price);
}
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);
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addBuy(buy);
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
plugin.message(player, "setup-buySuccess", buy);
// Update the region after the event has written its lines
Do.sync(buy::update);
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
}
} else if (event.getLine(0).contains(plugin.getConfig().getString("signTags.add"))) {
// Check for permission
if (!player.hasPermission("areashop.addsign")) {
plugin.message(player, "addsign-noPermission");
return;
}
// Get the other lines
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
GeneralRegion region;
if (secondLine != null && secondLine.length() != 0) {
// Get region by secondLine of the sign
region = plugin.getFileManager().getRegion(secondLine);
if (region == null) {
plugin.message(player, "addSign-notRegistered", secondLine);
return;
}
} else {
// Get region by sign position
List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(event.getBlock().getWorld(), event.getBlock().getLocation(), event.getBlock().getLocation()));
if (regions.isEmpty()) {
plugin.message(player, "addsign-noRegions");
return;
} else if (regions.size() > 1) {
plugin.message(player, "addsign-couldNotDetectSign", regions.get(0).getName(), regions.get(1).getName());
return;
}
region = regions.get(0);
}
org.bukkit.material.Sign sign = (org.bukkit.material.Sign) event.getBlock().getState().getData();
if (thirdLine == null || thirdLine.length() == 0) {
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
plugin.message(player, "addsign-success", region);
} else {
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), thirdLine);
plugin.message(player, "addsign-successProfile", thirdLine, region);
}
// Update the region later because this event will do it first
Do.sync(region::update);
}
}
use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.
the class SchematiceventCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.schematicevents")) {
plugin.message(sender, "schemevent-noPermission");
return;
}
if (args.length < 3 || args[1] == null || args[2] == null) {
plugin.message(sender, "schemevent-help");
return;
}
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(sender, "cmd-notRegistered", args[1]);
return;
}
if (region.getRegion() == null) {
plugin.message(sender, "general-noRegion", region);
return;
}
GeneralRegion.RegionEvent event = null;
boolean exception = false;
try {
event = GeneralRegion.RegionEvent.valueOf(args[2].toUpperCase());
} catch (IllegalArgumentException e) {
exception = true;
}
// Check for a totally wrong event or a non matching event
if (exception) {
ArrayList<String> values = new ArrayList<>();
for (GeneralRegion.RegionEvent value : GeneralRegion.RegionEvent.values()) {
values.add(value.getValue().toLowerCase());
}
plugin.message(sender, "schemevent-wrongEvent", args[2], Utils.createCommaSeparatedList(values), region);
return;
}
region.handleSchematicEvent(event);
region.update();
plugin.message(sender, "schemevent-success", args[2], region);
}
use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.
the class TeleportCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
plugin.message(sender, "teleport-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
if (args.length <= 1 || args[1] == null) {
plugin.message(sender, "teleport-help");
return;
}
Player player = (Player) sender;
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(player, "teleport-noRentOrBuy", args[1]);
return;
}
if (args.length >= 3 && (args[2].equalsIgnoreCase("sign") || args[2].equalsIgnoreCase("yes") || args[2].equalsIgnoreCase("true"))) {
region.getTeleportFeature().teleportPlayer(player, true);
} else {
region.getTeleportFeature().teleportPlayer(player, false);
}
}
use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.
the class SetlandlordCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.setlandlord")) {
plugin.message(sender, "setlandlord-noPermission");
return;
}
if (args.length < 2) {
plugin.message(sender, "setlandlord-help");
return;
}
@SuppressWarnings("deprecation") OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
GeneralRegion region;
if (args.length < 3) {
if (sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player) sender).getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = plugin.getFileManager().getRegion(args[2]);
}
if (region == null) {
plugin.message(sender, "cmd-notRegistered", args[2]);
return;
}
String playerName = player.getName();
if (playerName == null || playerName.isEmpty()) {
playerName = args[1];
}
region.setLandlord(player.getUniqueId(), playerName);
region.update();
plugin.message(sender, "setlandlord-success", playerName, region);
}
use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.
the class SetteleportCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.setteleport") && !sender.hasPermission("areashop.setteleportall")) {
plugin.message(sender, "setteleport-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "onlyByPlayer");
return;
}
Player player = (Player) sender;
GeneralRegion region;
if (args.length < 2) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player) sender).getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
region = plugin.getFileManager().getRegion(args[1]);
}
boolean owner;
if (region == null) {
plugin.message(player, "setteleport-noRentOrBuy", args[1]);
return;
}
if (region instanceof RentRegion) {
owner = player.getUniqueId().equals(((RentRegion) region).getRenter());
} else {
owner = player.getUniqueId().equals(((BuyRegion) region).getBuyer());
}
if (!player.hasPermission("areashop.setteleport")) {
plugin.message(player, "setteleport-noPermission", region);
return;
} else if (!owner && !player.hasPermission("areashop.setteleportall")) {
plugin.message(player, "setteleport-noPermissionOther", region);
return;
}
ProtectedRegion wgRegion = region.getRegion();
if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("reset") || args[2].equalsIgnoreCase("yes") || args[2].equalsIgnoreCase("true"))) {
region.getTeleportFeature().setTeleport(null);
region.update();
plugin.message(player, "setteleport-reset", region);
return;
}
if (!player.hasPermission("areashop.setteleportoutsideregion") && (wgRegion == null || !wgRegion.contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
plugin.message(player, "setteleport-notInside", region);
return;
}
region.getTeleportFeature().setTeleport(player.getLocation());
region.update();
plugin.message(player, "setteleport-success", region);
}
Aggregations