mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-08 00:24:43 +02:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
@ -37,11 +37,14 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
public static boolean isIn(CuboidRegion region, int x, int z) {
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region.getMinimumPoint().getZ() && z <= region
|
||||
.getMaximumPoint().getZ();
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region
|
||||
.getMinimumPoint()
|
||||
.getZ() && z <= region
|
||||
.getMaximumPoint().getZ();
|
||||
}
|
||||
|
||||
@Override public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
||||
@Override
|
||||
public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
||||
return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world), chunkLoc.getX(), chunkLoc.getZ(), force);
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,17 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@Singleton public class BukkitEconHandler extends EconHandler {
|
||||
@Singleton
|
||||
public class BukkitEconHandler extends EconHandler {
|
||||
|
||||
private Economy econ;
|
||||
|
||||
@Override public boolean init() {
|
||||
private static OfflinePlayer getBukkitOfflinePlayer(PlotPlayer<?> plotPlayer) {
|
||||
return ((BukkitPlayer) plotPlayer).player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
if (this.econ == null) {
|
||||
setupEconomy();
|
||||
}
|
||||
@ -54,13 +60,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
return;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> economyProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
this.econ = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public double getMoney(PlotPlayer<?> player) {
|
||||
@Override
|
||||
public double getMoney(PlotPlayer<?> player) {
|
||||
double bal = super.getMoney(player);
|
||||
if (Double.isNaN(bal)) {
|
||||
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
||||
@ -68,15 +75,18 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
return bal;
|
||||
}
|
||||
|
||||
@Override public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
||||
@Override
|
||||
public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
||||
this.econ.withdrawPlayer(getBukkitOfflinePlayer(player), amount);
|
||||
}
|
||||
|
||||
@Override public void depositMoney(PlotPlayer<?> player, double amount) {
|
||||
@Override
|
||||
public void depositMoney(PlotPlayer<?> player, double amount) {
|
||||
this.econ.depositPlayer(getBukkitOfflinePlayer(player), amount);
|
||||
}
|
||||
|
||||
@Override public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||
@Override
|
||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@ -95,12 +105,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public double getBalance(PlotPlayer<?> player) {
|
||||
@Override
|
||||
public double getBalance(PlotPlayer<?> player) {
|
||||
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
||||
}
|
||||
|
||||
private static OfflinePlayer getBukkitOfflinePlayer(PlotPlayer<?> plotPlayer) {
|
||||
return ((BukkitPlayer) plotPlayer).player;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ import java.util.Objects;
|
||||
public class BukkitEntityUtil {
|
||||
|
||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||
|
||||
public static boolean entityDamage(Entity damager, Entity victim) {
|
||||
return entityDamage(damager, victim, null);
|
||||
@ -152,7 +152,7 @@ public class BukkitEntityUtil {
|
||||
} else { // shooter is not player
|
||||
if (shooter instanceof BlockProjectileSource) {
|
||||
Location sLoc = BukkitUtil
|
||||
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
dplot = dArea.getPlot(sLoc);
|
||||
}
|
||||
player = null;
|
||||
@ -174,13 +174,13 @@ public class BukkitEntityUtil {
|
||||
|
||||
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
||||
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@ -189,79 +189,79 @@ public class BukkitEntityUtil {
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
||||
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName()
|
||||
+ " could not break armor stand because misc-break = false");
|
||||
+ " could not break armor stand because misc-break = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR hostile-attack = false");
|
||||
+ " because pve = false OR hostile-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR tamed-attack = false");
|
||||
+ " because pve = false OR tamed-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||
);
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
+ " because pve = false");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@ -271,31 +271,31 @@ public class BukkitEntityUtil {
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR animal-attack = false");
|
||||
+ " because pve = false OR animal-attack = false");
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
.getFlag(PveFlag.class))) {
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (EntityCategories.VEHICLE
|
||||
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||
return true;
|
||||
} else { // victim is something else
|
||||
if (isPlot) {
|
||||
@ -307,25 +307,25 @@ public class BukkitEntityUtil {
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
+ " because pve = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||
}
|
||||
//disable the firework damage. too much of a headache to support at the moment.
|
||||
if (vplot != null) {
|
||||
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
||||
&& damager.getType() == EntityType.FIREWORK) {
|
||||
&& damager.getType() == EntityType.FIREWORK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -333,46 +333,50 @@ public class BukkitEntityUtil {
|
||||
return true;
|
||||
}
|
||||
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
||||
&& !(victim instanceof Creature)));
|
||||
&& !(victim instanceof Creature)));
|
||||
}
|
||||
|
||||
public static boolean checkEntity(Entity entity, Plot plot) {
|
||||
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
||||
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
MiscCapFlag.MISC_CAP_UNLIMITED);
|
||||
MiscCapFlag.MISC_CAP_UNLIMITED
|
||||
);
|
||||
}
|
||||
|
||||
// Has to go go before vehicle as horses are both
|
||||
// animals and vehicles
|
||||
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
AnimalCapFlag.ANIMAL_CAP_UNLIMITED
|
||||
);
|
||||
}
|
||||
|
||||
if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
HostileCapFlag.HOSTILE_CAP_UNLIMITED
|
||||
);
|
||||
}
|
||||
|
||||
if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||
VehicleCapFlag.VEHICLE_CAP_UNLIMITED
|
||||
);
|
||||
}
|
||||
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||
|
@ -47,39 +47,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Singleton public class BukkitInventoryUtil extends InventoryUtil {
|
||||
|
||||
@Override public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.getLines() * 9,
|
||||
ChatColor.translateAlternateColorCodes('&', inv.getTitle()));
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.getLines() * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
}
|
||||
bp.player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
bp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
opened.setItem(index, getItem(item));
|
||||
bp.player.updateInventory();
|
||||
}
|
||||
@Singleton
|
||||
public class BukkitInventoryUtil extends InventoryUtil {
|
||||
|
||||
private static ItemStack getItem(PlotItemStack item) {
|
||||
if (item == null) {
|
||||
@ -108,6 +77,42 @@ import java.util.stream.IntStream;
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.getLines() * 9,
|
||||
ChatColor.translateAlternateColorCodes('&', inv.getTitle())
|
||||
);
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.getLines() * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
}
|
||||
bp.player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
bp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
opened.setItem(index, getItem(item));
|
||||
bp.player.updateInventory();
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
@ -132,14 +137,16 @@ import java.util.stream.IntStream;
|
||||
return new PlotItemStack(id.name(), amount, name, lore);
|
||||
}
|
||||
|
||||
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
@Override
|
||||
public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
BukkitPlayer bp = (BukkitPlayer) player;
|
||||
PlayerInventory inv = bp.player.getInventory();
|
||||
return IntStream.range(0, 36).mapToObj(i -> getItem(inv.getItem(i)))
|
||||
.toArray(PlotItemStack[]::new);
|
||||
.toArray(PlotItemStack[]::new);
|
||||
}
|
||||
|
||||
@Override public boolean isOpen(PlotInventory plotInventory) {
|
||||
@Override
|
||||
public boolean isOpen(PlotInventory plotInventory) {
|
||||
if (!plotInventory.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
@ -152,4 +159,5 @@ import java.util.stream.IntStream;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,9 +55,9 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -75,18 +75,27 @@ public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue, @Nonnull
|
||||
ProgressSubscriberFactory subscriberFactory) {
|
||||
@Inject
|
||||
public BukkitRegionManager(
|
||||
@NonNull WorldUtil worldUtil, @NonNull GlobalBlockQueue blockQueue, @NonNull
|
||||
ProgressSubscriberFactory subscriberFactory
|
||||
) {
|
||||
super(worldUtil, blockQueue, subscriberFactory);
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager, @Nullable PlotPlayer<?> player) {
|
||||
public boolean handleClear(
|
||||
@NonNull Plot plot,
|
||||
@Nullable Runnable whenDone,
|
||||
@NonNull PlotManager manager,
|
||||
@Nullable PlotPlayer<?> player
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public int[] countEntities(@Nonnull Plot plot) {
|
||||
@Override
|
||||
public int[] countEntities(@NonNull Plot plot) {
|
||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
||||
return existing;
|
||||
@ -160,10 +169,13 @@ public class BukkitRegionManager extends RegionManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override public boolean regenerateRegion(@Nonnull final Location pos1,
|
||||
@Nonnull final Location pos2,
|
||||
final boolean ignoreAugment,
|
||||
@Nullable final Runnable whenDone) {
|
||||
@Override
|
||||
public boolean regenerateRegion(
|
||||
final @NonNull Location pos1,
|
||||
final @NonNull Location pos2,
|
||||
final boolean ignoreAugment,
|
||||
final @Nullable Runnable whenDone
|
||||
) {
|
||||
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
||||
|
||||
final int p1x = pos1.getX();
|
||||
@ -251,35 +263,39 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||
@Override public void run(ScopedQueueCoordinator value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
AugmentedUtils.bypass(
|
||||
ignoreAugment,
|
||||
() -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||
@Override
|
||||
public void run(ScopedQueueCoordinator value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world.getName(), chunk));
|
||||
}, world.getName(), chunk)
|
||||
);
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
||||
});
|
||||
@ -289,7 +305,8 @@ public class BukkitRegionManager extends RegionManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void clearAllEntities(@Nonnull Location pos1, @Nonnull Location pos2) {
|
||||
@Override
|
||||
public void clearAllEntities(@NonNull Location pos1, @NonNull Location pos2) {
|
||||
String world = pos1.getWorldName();
|
||||
|
||||
final World bukkitWorld = BukkitUtil.getWorld(world);
|
||||
@ -317,16 +334,16 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void count(int[] count, @Nonnull Entity entity) {
|
||||
private void count(int[] count, @NonNull Entity entity) {
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return;
|
||||
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER.contains(entityType) || EntityCategories.HANGING
|
||||
.contains(entityType)) {
|
||||
.contains(entityType)) {
|
||||
count[CAP_MISC]++;
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER.contains(entityType) || EntityCategories.TAMEABLE
|
||||
.contains(entityType)) {
|
||||
.contains(entityType)) {
|
||||
count[CAP_MOB]++;
|
||||
count[CAP_ANIMAL]++;
|
||||
} else if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
@ -337,4 +354,5 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
count[CAP_ENTITY]++;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,29 +48,34 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
@Singleton public class BukkitSetupUtils extends SetupUtils {
|
||||
@Singleton
|
||||
public class BukkitSetupUtils extends SetupUtils {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final YamlConfiguration worldConfiguration;
|
||||
private final File worldFile;
|
||||
|
||||
@Inject public BukkitSetupUtils(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile) {
|
||||
@Inject
|
||||
public BukkitSetupUtils(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||
@WorldFile final @NonNull File worldFile
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
}
|
||||
|
||||
@Override public void updateGenerators() {
|
||||
@Override
|
||||
public void updateGenerators() {
|
||||
if (!SetupUtils.generators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -97,7 +102,8 @@ import java.util.Objects;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void unload(String worldName, boolean save) {
|
||||
@Override
|
||||
public void unload(String worldName, boolean save) {
|
||||
TaskManager.runTask(() -> {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
@ -120,7 +126,8 @@ import java.util.Objects;
|
||||
});
|
||||
}
|
||||
|
||||
@Override public String setupWorld(PlotAreaBuilder builder) {
|
||||
@Override
|
||||
public String setupWorld(PlotAreaBuilder builder) {
|
||||
this.updateGenerators();
|
||||
ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
|
||||
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
|
||||
@ -233,7 +240,8 @@ import java.util.Objects;
|
||||
return builder.worldName();
|
||||
}
|
||||
|
||||
@Override public String getGenerator(PlotArea plotArea) {
|
||||
@Override
|
||||
public String getGenerator(PlotArea plotArea) {
|
||||
if (SetupUtils.generators.isEmpty()) {
|
||||
updateGenerators();
|
||||
}
|
||||
@ -253,4 +261,5 @@ import java.util.Objects;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -94,12 +94,12 @@ import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.entity.WaterMob;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
@ -113,12 +113,10 @@ import java.util.stream.Stream;
|
||||
@Singleton
|
||||
public class BukkitUtil extends WorldUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||
|
||||
public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitPlatform.getPlugin(BukkitPlatform.class));
|
||||
public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
||||
|
||||
/**
|
||||
@ -127,7 +125,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @param player Bukkit player
|
||||
* @return PlotSquared player
|
||||
*/
|
||||
@Nonnull public static BukkitPlayer adapt(@Nonnull final Player player) {
|
||||
public @NonNull static BukkitPlayer adapt(final @NonNull Player player) {
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.platform().playerManager();
|
||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||
}
|
||||
@ -139,10 +137,13 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @param location Bukkit location
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
|
||||
public @NonNull static Location adapt(final org.bukkit.@NonNull Location location) {
|
||||
return Location
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()));
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,10 +153,15 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @param location Bukkit location
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) {
|
||||
public @NonNull static Location adaptComplete(final org.bukkit.@NonNull Location location) {
|
||||
return Location
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch());
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()),
|
||||
location.getYaw(),
|
||||
location.getPitch()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,8 +171,13 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @param location PlotSquared location
|
||||
* @return Bukkit location
|
||||
*/
|
||||
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(), location.getY(), location.getZ());
|
||||
public static org.bukkit.@NonNull Location adapt(final @NonNull Location location) {
|
||||
return new org.bukkit.Location(
|
||||
(World) location.getWorld().getPlatformWorld(),
|
||||
location.getX(),
|
||||
location.getY(),
|
||||
location.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,20 +186,25 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @param string World name
|
||||
* @return World if it exists, or {@code null}
|
||||
*/
|
||||
@Nullable public static World getWorld(@Nonnull final String string) {
|
||||
public @Nullable static World getWorld(final @NonNull String string) {
|
||||
return Bukkit.getWorld(string);
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
private static void ensureLoaded(
|
||||
final @NonNull String world,
|
||||
final int x,
|
||||
final int z,
|
||||
final @NonNull Consumer<Chunk> chunkConsumer
|
||||
) {
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final Location location, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
private static void ensureLoaded(final @NonNull Location location, final @NonNull Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(adapt(location), true).thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer, @Nonnull final T value) {
|
||||
private static <T> void ensureMainThread(final @NonNull Consumer<T> consumer, final @NonNull T value) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
@ -196,7 +212,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
|
||||
@Override
|
||||
public boolean isBlockSame(final @NonNull BlockState block1, final @NonNull BlockState block2) {
|
||||
if (block1.equals(block2)) {
|
||||
return true;
|
||||
}
|
||||
@ -205,19 +222,23 @@ public class BukkitUtil extends WorldUtil {
|
||||
return mat1 == mat2;
|
||||
}
|
||||
|
||||
@Override public boolean isWorld(@Nonnull final String worldName) {
|
||||
@Override
|
||||
public boolean isWorld(final @NonNull String worldName) {
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
|
||||
@Override public void getBiome(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<BiomeType> result) {
|
||||
@Override
|
||||
public void getBiome(final @NonNull String world, final int x, final int z, final @NonNull Consumer<BiomeType> result) {
|
||||
ensureLoaded(world, x, z, chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
||||
}
|
||||
|
||||
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
@Override
|
||||
public @NonNull BiomeType getBiomeSynchronous(final @NonNull String world, final int x, final int z) {
|
||||
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z));
|
||||
}
|
||||
|
||||
@Override public void getHighestBlock(@Nonnull final String world, final int x, final int z, @Nonnull final IntConsumer result) {
|
||||
@Override
|
||||
public void getHighestBlock(final @NonNull String world, final int x, final int z, final @NonNull IntConsumer result) {
|
||||
ensureLoaded(world, x, z, chunk -> {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
@ -243,7 +264,9 @@ public class BukkitUtil extends WorldUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int getHighestBlockSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
@Override
|
||||
@NonNegative
|
||||
public int getHighestBlockSynchronous(final @NonNull String world, final int x, final int z) {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
@ -265,8 +288,13 @@ public class BukkitUtil extends WorldUtil {
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override @Nonnull public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
@Override
|
||||
public @NonNull String[] getSignSynchronous(final @NonNull Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(
|
||||
location.getX(),
|
||||
location.getY(),
|
||||
location.getZ()
|
||||
);
|
||||
try {
|
||||
return TaskManager.getPlatformImplementation().sync(() -> {
|
||||
if (block.getState() instanceof Sign) {
|
||||
@ -281,28 +309,34 @@ public class BukkitUtil extends WorldUtil {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override @Nonnull public Location getSpawn(@Nonnull final String world) {
|
||||
@Override
|
||||
public @NonNull Location getSpawn(final @NonNull String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
||||
}
|
||||
|
||||
@Override public void setSpawn(@Nonnull final Location location) {
|
||||
@Override
|
||||
public void setSpawn(final @NonNull Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
if (world != null) {
|
||||
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void saveWorld(@Nonnull final String worldName) {
|
||||
@Override
|
||||
public void saveWorld(final @NonNull String worldName) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world != null) {
|
||||
world.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("deprecation")
|
||||
public void setSign(@Nonnull final Location location, @Nonnull final Caption[] lines,
|
||||
@Nonnull final Template ... replacements) {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setSign(
|
||||
final @NonNull Location location, final @NonNull Caption[] lines,
|
||||
final @NonNull Template... replacements
|
||||
) {
|
||||
ensureLoaded(location.getWorldName(), location.getX(), location.getZ(), chunk -> {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
@ -334,19 +368,25 @@ public class BukkitUtil extends WorldUtil {
|
||||
final Sign sign = (Sign) blockstate;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sign.setLine(i, LEGACY_COMPONENT_SERIALIZER
|
||||
.serialize(MINI_MESSAGE.parse(lines[i].getComponent(LocaleHolder.console()), replacements)));
|
||||
.serialize(MINI_MESSAGE.parse(lines[i].getComponent(LocaleHolder.console()), replacements)));
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnull public StringComparison<BlockState>.ComparisonResult getClosestBlock(@Nonnull String name) {
|
||||
@Override
|
||||
public @NonNull StringComparison<BlockState>.ComparisonResult getClosestBlock(@NonNull String name) {
|
||||
BlockState state = BlockUtil.get(name);
|
||||
return new StringComparison<BlockState>().new ComparisonResult(1, state);
|
||||
}
|
||||
|
||||
@Override public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region, @Nonnull final BiomeType biomeType) {
|
||||
@Override
|
||||
public void setBiomes(
|
||||
final @NonNull String worldName,
|
||||
final @NonNull CuboidRegion region,
|
||||
final @NonNull BiomeType biomeType
|
||||
) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == null) {
|
||||
logger.warn("An error occurred while setting the biome because the world was null", new RuntimeException());
|
||||
@ -362,15 +402,18 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWeWorld(@Nonnull final String world) {
|
||||
@Override
|
||||
public com.sk89q.worldedit.world.@NonNull World getWeWorld(final @NonNull String world) {
|
||||
return new BukkitWorld(Bukkit.getWorld(world));
|
||||
}
|
||||
|
||||
@Override public void refreshChunk(int x, int z, String world) {
|
||||
@Override
|
||||
public void refreshChunk(int x, int z, String world) {
|
||||
Bukkit.getWorld(world).refreshChunk(x, z);
|
||||
}
|
||||
|
||||
@Override public void getBlock(@Nonnull final Location location, @Nonnull final Consumer<BlockState> result) {
|
||||
@Override
|
||||
public void getBlock(final @NonNull Location location, final @NonNull Consumer<BlockState> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
@ -378,29 +421,37 @@ public class BukkitUtil extends WorldUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnull public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
||||
@Override
|
||||
public @NonNull BlockState getBlockSynchronous(final @NonNull Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
|
||||
@Override
|
||||
@NonNegative
|
||||
public double getHealth(final @NonNull PlotPlayer player) {
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getHealth();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) {
|
||||
@Override
|
||||
@NonNegative
|
||||
public int getFoodLevel(final @NonNull PlotPlayer<?> player) {
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getFoodLevel();
|
||||
}
|
||||
|
||||
@Override public void setHealth(@Nonnull final PlotPlayer<?> player, @Nonnegative final double health) {
|
||||
@Override
|
||||
public void setHealth(final @NonNull PlotPlayer<?> player, @NonNegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).setHealth(health);
|
||||
}
|
||||
|
||||
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player, @Nonnegative final int foodLevel) {
|
||||
@Override
|
||||
public void setFoodLevel(final @NonNull PlotPlayer<?> player, @NonNegative final int foodLevel) {
|
||||
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
||||
}
|
||||
|
||||
@Override @Nonnull public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(@Nonnull final String category) {
|
||||
@Override
|
||||
public @NonNull Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(final @NonNull String category) {
|
||||
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
||||
switch (category) {
|
||||
case "animal": {
|
||||
@ -480,7 +531,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override @Nonnull public Collection<BlockType> getTileEntityTypes() {
|
||||
@Override
|
||||
public @NonNull Collection<BlockType> getTileEntityTypes() {
|
||||
if (this.tileEntityTypes.isEmpty()) {
|
||||
// Categories
|
||||
tileEntityTypes.addAll(BlockCategories.BANNERS.getAll());
|
||||
@ -489,22 +541,59 @@ public class BukkitUtil extends WorldUtil {
|
||||
tileEntityTypes.addAll(BlockCategories.FLOWER_POTS.getAll());
|
||||
// Individual Types
|
||||
// Add these from strings
|
||||
Stream.of("barrel", "beacon", "beehive", "bee_nest", "bell", "blast_furnace", "brewing_stand", "campfire", "chest", "ender_chest",
|
||||
"trapped_chest", "command_block", "end_gateway", "hopper", "jigsaw", "jubekox", "lectern", "note_block", "black_shulker_box",
|
||||
"blue_shulker_box", "brown_shulker_box", "cyan_shulker_box", "gray_shulker_box", "green_shulker_box", "light_blue_shulker_box",
|
||||
"light_gray_shulker_box", "lime_shulker_box", "magenta_shulker_box", "orange_shulker_box", "pink_shulker_box", "purple_shulker_box",
|
||||
"red_shulker_box", "shulker_box", "white_shulker_box", "yellow_shulker_box", "smoker", "structure_block", "structure_void")
|
||||
.map(BlockTypes::get).filter(Objects::nonNull).forEach(tileEntityTypes::add);
|
||||
Stream.of("barrel",
|
||||
"beacon",
|
||||
"beehive",
|
||||
"bee_nest",
|
||||
"bell",
|
||||
"blast_furnace",
|
||||
"brewing_stand",
|
||||
"campfire",
|
||||
"chest",
|
||||
"ender_chest",
|
||||
"trapped_chest",
|
||||
"command_block",
|
||||
"end_gateway",
|
||||
"hopper",
|
||||
"jigsaw",
|
||||
"jubekox",
|
||||
"lectern",
|
||||
"note_block",
|
||||
"black_shulker_box",
|
||||
"blue_shulker_box",
|
||||
"brown_shulker_box",
|
||||
"cyan_shulker_box",
|
||||
"gray_shulker_box",
|
||||
"green_shulker_box",
|
||||
"light_blue_shulker_box",
|
||||
"light_gray_shulker_box",
|
||||
"lime_shulker_box",
|
||||
"magenta_shulker_box",
|
||||
"orange_shulker_box",
|
||||
"pink_shulker_box",
|
||||
"purple_shulker_box",
|
||||
"red_shulker_box",
|
||||
"shulker_box",
|
||||
"white_shulker_box",
|
||||
"yellow_shulker_box",
|
||||
"smoker",
|
||||
"structure_block",
|
||||
"structure_void"
|
||||
)
|
||||
.map(BlockTypes::get).filter(Objects::nonNull).forEach(tileEntityTypes::add);
|
||||
}
|
||||
return this.tileEntityTypes;
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int getTileEntityCount(@Nonnull final String world, @Nonnull final BlockVector2 chunk) {
|
||||
@Override
|
||||
@NonNegative
|
||||
public int getTileEntityCount(final @NonNull String world, final @NonNull BlockVector2 chunk) {
|
||||
return Objects.requireNonNull(getWorld(world)).
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ()).getTileEntities().length;
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ()).getTileEntities().length;
|
||||
}
|
||||
|
||||
@Override public Set<BlockVector2> getChunkChunks(String world) {
|
||||
@Override
|
||||
public Set<BlockVector2> getChunkChunks(String world) {
|
||||
Set<BlockVector2> chunks = super.getChunkChunks(world);
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
||||
|
@ -28,8 +28,8 @@ package com.plotsquared.bukkit.util;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.plotsquared.core.location.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -49,7 +49,7 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
* @param worldName World name
|
||||
* @return World instance
|
||||
*/
|
||||
@Nonnull public static BukkitWorld of(@Nonnull final String worldName) {
|
||||
public @NonNull static BukkitWorld of(final @NonNull String worldName) {
|
||||
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
||||
if (bukkitWorld == null) {
|
||||
throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName));
|
||||
@ -63,7 +63,7 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
* @param world Bukkit world
|
||||
* @return World instance
|
||||
*/
|
||||
@Nonnull public static BukkitWorld of(final org.bukkit.World world) {
|
||||
public @NonNull static BukkitWorld of(final org.bukkit.World world) {
|
||||
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
||||
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
||||
return bukkitWorld;
|
||||
@ -73,11 +73,13 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
return bukkitWorld;
|
||||
}
|
||||
|
||||
@Override public org.bukkit.World getPlatformWorld() {
|
||||
@Override
|
||||
public org.bukkit.World getPlatformWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override @Nonnull public String getName() {
|
||||
@Override
|
||||
public @NonNull String getName() {
|
||||
return this.world.getName();
|
||||
}
|
||||
|
||||
@ -113,4 +115,5 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
public String toString() {
|
||||
return "BukkitWorld(world=" + this.world + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,8 +96,10 @@ public class ContentMap {
|
||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||
}
|
||||
|
||||
void saveEntitiesIn(Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
||||
boolean delete) {
|
||||
void saveEntitiesIn(
|
||||
Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
||||
boolean delete
|
||||
) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
int x = location.getX();
|
||||
@ -143,4 +145,5 @@ public class ContentMap {
|
||||
PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ);
|
||||
this.allBlocks.put(loc, ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -75,4 +75,5 @@ public class JavaVersionCheck {
|
||||
logger.error("************************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,9 +69,10 @@ public class SetGenCB {
|
||||
}
|
||||
if (!set) {
|
||||
world.getPopulators()
|
||||
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
||||
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
||||
}
|
||||
PlotSquared.get()
|
||||
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
||||
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ public class UpdateUtility implements Listener {
|
||||
public final JavaPlugin javaPlugin;
|
||||
private boolean notify = true;
|
||||
|
||||
@Inject public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||
@Inject
|
||||
public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
internalVersion = PlotSquared.get().getVersion();
|
||||
}
|
||||
@ -64,12 +65,12 @@ public class UpdateUtility implements Listener {
|
||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
|
||||
try {
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
||||
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
|
||||
.openConnection();
|
||||
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
|
||||
.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
JsonObject result = (new JsonParser())
|
||||
.parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
|
||||
.getAsJsonObject();
|
||||
.parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
|
||||
.getAsJsonObject();
|
||||
spigotVersion = result.get("current_version").getAsString();
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to check for updates. Error: {}", e.getMessage());
|
||||
@ -79,7 +80,8 @@ public class UpdateUtility implements Listener {
|
||||
if (internalVersion.isLaterVersion(spigotVersion)) {
|
||||
logger.info("There appears to be a PlotSquared update available!");
|
||||
logger.info("You are running version {}, the latest version is {}",
|
||||
internalVersion.versionString(), spigotVersion);
|
||||
internalVersion.versionString(), spigotVersion
|
||||
);
|
||||
logger.info("https://www.spigotmc.org/resources/77506/updates");
|
||||
hasUpdate = true;
|
||||
if (Settings.UpdateChecker.NOTIFY_ONCE) {
|
||||
@ -95,4 +97,5 @@ public class UpdateUtility implements Listener {
|
||||
private void cancelTask() {
|
||||
Bukkit.getScheduler().runTaskLater(javaPlugin, () -> task.cancel(), 20L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,21 +27,22 @@ package com.plotsquared.bukkit.util.task;
|
||||
|
||||
import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Bukkit implementation of {@link PlotSquaredTask}
|
||||
*/
|
||||
public final class BukkitPlotSquaredTask extends BukkitRunnable implements PlotSquaredTask {
|
||||
|
||||
@Nonnull private final Runnable runnable;
|
||||
@NonNull
|
||||
private final Runnable runnable;
|
||||
|
||||
public BukkitPlotSquaredTask(@Nonnull final Runnable runnable) {
|
||||
public BukkitPlotSquaredTask(final @NonNull Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override public void runTask() {
|
||||
@Override
|
||||
public void runTask() {
|
||||
this.runnable.run();
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -43,20 +43,26 @@ import java.util.concurrent.TimeUnit;
|
||||
* Bukkit implementation of {@link TaskManager} using
|
||||
* by {@link org.bukkit.scheduler.BukkitScheduler} and {@link BukkitPlotSquaredTask}
|
||||
*/
|
||||
@Singleton public class BukkitTaskManager extends TaskManager {
|
||||
@Singleton
|
||||
public class BukkitTaskManager extends TaskManager {
|
||||
|
||||
private final BukkitPlatform bukkitMain;
|
||||
private final TaskTime.TimeConverter timeConverter;
|
||||
|
||||
@Inject public BukkitTaskManager(@Nonnull final BukkitPlatform bukkitMain,
|
||||
@Nonnull final TaskTime.TimeConverter timeConverter) {
|
||||
@Inject
|
||||
public BukkitTaskManager(
|
||||
final @NonNull BukkitPlatform bukkitMain,
|
||||
final TaskTime.@NonNull TimeConverter timeConverter
|
||||
) {
|
||||
this.bukkitMain = bukkitMain;
|
||||
this.timeConverter = timeConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotSquaredTask taskRepeat(@Nonnull final Runnable runnable,
|
||||
@Nonnull final TaskTime taskTime) {
|
||||
public PlotSquaredTask taskRepeat(
|
||||
final @NonNull Runnable runnable,
|
||||
final @NonNull TaskTime taskTime
|
||||
) {
|
||||
final long ticks = this.timeConverter.toTicks(taskTime);
|
||||
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
||||
bukkitPlotSquaredTask.runTaskTimer(this.bukkitMain, ticks, ticks);
|
||||
@ -64,15 +70,18 @@ import java.util.concurrent.TimeUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotSquaredTask taskRepeatAsync(@Nonnull final Runnable runnable,
|
||||
@Nonnull final TaskTime taskTime) {
|
||||
public PlotSquaredTask taskRepeatAsync(
|
||||
final @NonNull Runnable runnable,
|
||||
final @NonNull TaskTime taskTime
|
||||
) {
|
||||
final long ticks = this.timeConverter.toTicks(taskTime);
|
||||
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
||||
bukkitPlotSquaredTask.runTaskTimerAsynchronously(this.bukkitMain, ticks, ticks);
|
||||
return bukkitPlotSquaredTask;
|
||||
}
|
||||
|
||||
@Override public void taskAsync(@Nonnull final Runnable runnable) {
|
||||
@Override
|
||||
public void taskAsync(final @NonNull Runnable runnable) {
|
||||
if (this.bukkitMain.isEnabled()) {
|
||||
new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain);
|
||||
} else {
|
||||
@ -80,29 +89,38 @@ import java.util.concurrent.TimeUnit;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public <T> T sync(@Nonnull final Callable<T> function, final int timeout) throws Exception {
|
||||
@Override
|
||||
public <T> T sync(final @NonNull Callable<T> function, final int timeout) throws Exception {
|
||||
if (PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||
return function.call();
|
||||
}
|
||||
return this.callMethodSync(function).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override public <T> Future<T> callMethodSync(@Nonnull final Callable<T> method) {
|
||||
@Override
|
||||
public <T> Future<T> callMethodSync(final @NonNull Callable<T> method) {
|
||||
return Bukkit.getScheduler().callSyncMethod(this.bukkitMain, method);
|
||||
}
|
||||
|
||||
@Override public void task(@Nonnull final Runnable runnable) {
|
||||
@Override
|
||||
public void task(final @NonNull Runnable runnable) {
|
||||
new BukkitPlotSquaredTask(runnable).runTask(this.bukkitMain);
|
||||
}
|
||||
|
||||
@Override public void taskLater(@Nonnull final Runnable runnable,
|
||||
@Nonnull final TaskTime taskTime) {
|
||||
@Override
|
||||
public void taskLater(
|
||||
final @NonNull Runnable runnable,
|
||||
final @NonNull TaskTime taskTime
|
||||
) {
|
||||
final long delay = this.timeConverter.toTicks(taskTime);
|
||||
new BukkitPlotSquaredTask(runnable).runTaskLater(this.bukkitMain, delay);
|
||||
}
|
||||
|
||||
@Override public void taskLaterAsync(@Nonnull final Runnable runnable,
|
||||
@Nonnull final TaskTime taskTime) {
|
||||
@Override
|
||||
public void taskLaterAsync(
|
||||
final @NonNull Runnable runnable,
|
||||
final @NonNull TaskTime taskTime
|
||||
) {
|
||||
final long delay = this.timeConverter.toTicks(taskTime);
|
||||
new BukkitPlotSquaredTask(runnable).runTaskLaterAsynchronously(this.bukkitMain, delay);
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ package com.plotsquared.bukkit.util.task;
|
||||
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
|
||||
/**
|
||||
* Time converter that uses the server MSPT count to convert between
|
||||
@ -38,11 +37,13 @@ public final class PaperTimeConverter implements TaskTime.TimeConverter {
|
||||
|
||||
private static final long MIN_MS_PER_TICKS = 50L;
|
||||
|
||||
@Override public long msToTicks(@Nonnegative final long ms) {
|
||||
@Override
|
||||
public long msToTicks(@NonNegative final long ms) {
|
||||
return Math.max(1L, (long) (ms / Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
||||
}
|
||||
|
||||
@Override public long ticksToMs(@Nonnegative final long ticks) {
|
||||
@Override
|
||||
public long ticksToMs(@NonNegative final long ticks) {
|
||||
return Math.max(1L, (long) (ticks * Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,7 @@
|
||||
package com.plotsquared.bukkit.util.task;
|
||||
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
|
||||
/**
|
||||
* Naive time converter that assumes that all ticks are 50 milliseconds
|
||||
@ -36,11 +35,13 @@ public final class SpigotTimeConverter implements TaskTime.TimeConverter {
|
||||
|
||||
private static final long MS_PER_TICKS = 50L;
|
||||
|
||||
@Override public long msToTicks(@Nonnegative final long ms) {
|
||||
@Override
|
||||
public long msToTicks(@NonNegative final long ms) {
|
||||
return Math.max(1L, ms / MS_PER_TICKS);
|
||||
}
|
||||
|
||||
@Override public long ticksToMs(@Nonnegative final long ticks) {
|
||||
@Override
|
||||
public long ticksToMs(@NonNegative final long ticks) {
|
||||
return Math.max(1L, ticks * MS_PER_TICKS);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user