Fixed issue with auto tilling.

Added a feature where you can set permissions for the amount of farms a player can have.
This commit is contained in:
Brianna O'Keefe 2018-10-11 22:30:31 -04:00
parent 5f97cc646c
commit fb3d6742f0
3 changed files with 20 additions and 2 deletions

View File

@ -243,7 +243,7 @@ public class EFarm implements Farm {
public boolean tillLand(Location location) {
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
if (!instance.getConfig().getBoolean("Main.Disable Auto Til Land")) return true;
if (instance.getConfig().getBoolean("Main.Disable Auto Til Land")) return true;
Block block = location.getBlock();
int radius = level.getRadius();
int bx = block.getX();

View File

@ -25,6 +25,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.SheepRegrowWoolEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.util.Collection;
import java.util.List;
@ -77,6 +78,22 @@ public class BlockListeners implements Listener {
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
int amt = 0;
for (Farm farmm : instance.getFarmManager().getFarms().values()) {
if (!farmm.getPlacedBy().equals(e.getPlayer().getUniqueId())) continue;
amt ++;
}
int limit = -1;
for (PermissionAttachmentInfo permissionAttachmentInfo : e.getPlayer().getEffectivePermissions()) {
if (!permissionAttachmentInfo.getPermission().toLowerCase().startsWith("epicfarming.limit")) continue;
limit = Integer.parseInt(permissionAttachmentInfo.getPermission().split("\\.")[2]);
}
if (limit != -1 && amt >= limit) {
e.setCancelled(true);
Bukkit.broadcastMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.limit.hit", limit));
return;
}
Location location = e.getBlock().getLocation();
Bukkit.getScheduler().runTaskLater(instance, () -> {

View File

@ -29,3 +29,4 @@ event.upgrade.cannotafford = "&cYou cannot afford this upgrade."
event.upgrade.success = "&7You successfully upgraded this farm to &6level %level%&7!"
event.upgrade.maxed = "&6This farm is maxed out."
event.upgrade.successmaxed = "&7You maxed out this farm at &6%level%x&7."
event.limit.hit = "&7You can only have &6%limit% &7farms at a single time."