Minor fixes and performance improvement

This commit is contained in:
MattBDev 2019-12-02 17:07:57 -05:00
parent d8933afb50
commit 7e58f4341e
6 changed files with 32 additions and 16 deletions

View File

@ -2211,12 +2211,12 @@ import java.util.regex.Pattern;
}
break;
}
case LEFT_CLICK_BLOCK:
Block block = event.getClickedBlock();
location = BukkitUtil.getLocation(block.getLocation());
eventType = PlayerBlockEventType.BREAK_BLOCK;
lazyItem = BukkitBlockUtil.supplyItem(block);
break;
// case LEFT_CLICK_BLOCK:
// Block block = event.getClickedBlock();
// location = BukkitUtil.getLocation(block.getLocation());
// eventType = PlayerBlockEventType.BREAK_BLOCK;
// lazyItem = BukkitBlockUtil.supplyItem(block);
// break;
default:
return;
}

View File

@ -10,7 +10,11 @@ import java.util.function.Supplier;
public class BukkitBlockUtil {
public static Supplier<ItemType> supplyItem(Block block) {
return () -> BukkitAdapter.asItemType(block.getType());
return new Supplier<ItemType>() {
@Override public ItemType get() {
return BukkitAdapter.asItemType(block.getType());
}
};
}
public static Supplier<ItemType> supplyItem(Material type) {

View File

@ -40,9 +40,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static com.google.common.base.Preconditions.checkNotNull;
public class BukkitChunkManager extends ChunkManager {
public static boolean isIn(CuboidRegion region, int x, int z) {
@ -111,7 +114,7 @@ public class BukkitChunkManager extends ChunkManager {
@Override public Set<BlockVector2> getChunkChunks(String world) {
Set<BlockVector2> chunks = super.getChunkChunks(world);
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
chunks.add(loc);
}
@ -269,6 +272,7 @@ public class BukkitChunkManager extends ChunkManager {
}
}
final World worldObj = Bukkit.getWorld(world);
checkNotNull(worldObj, "Critical error during regeneration.");
final BukkitWorld bukkitWorldObj = new BukkitWorld(worldObj);
TaskManager.runTask(new Runnable() {
@Override public void run() {
@ -398,7 +402,7 @@ public class BukkitChunkManager extends ChunkManager {
return true;
}
@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);
}
@ -440,8 +444,9 @@ public class BukkitChunkManager extends ChunkManager {
CuboidRegion region2 =
RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
final World world1 = Bukkit.getWorld(bot1.getWorld());
World world2 = Bukkit.getWorld(bot2.getWorld());
final World world2 = Bukkit.getWorld(bot2.getWorld());
checkNotNull(world1,"Critical error during swap.");
checkNotNull(world2,"Critical error during swap.");
int relX = bot2.getX() - bot1.getX();
int relZ = bot2.getZ() - bot1.getZ();

View File

@ -48,12 +48,12 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
if (args.length == 0) {
return Collections.singletonList("plots");
}
Collection objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
Collection<com.github.intellectualsites.plotsquared.commands.Command> objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
if (objects == null) {
return null;
}
List<String> result = new ArrayList<>();
for (Object o : objects) {
for (com.github.intellectualsites.plotsquared.commands.Command o : objects) {
result.add(o.toString());
}
return result.isEmpty() ? null : result;

View File

@ -96,6 +96,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
}
if (meta.hasLore()) {
List<String> itemLore = meta.getLore();
assert itemLore != null;
lore = itemLore.toArray(new String[0]);
}
}

View File

@ -174,10 +174,16 @@ public class Auto extends SubCommand {
if (Permissions.hasPermission(player, Captions.PERMISSION_AUTO_MEGA)) {
try {
String[] split = args[0].split(",|;");
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
if (split[1] == null) {
MainUtil.sendMessage(player,"Correct use /plot auto [length,width]");
size_x = 1;
size_z = 1;
} else {
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
}
if (size_x < 1 || size_z < 1) {
MainUtil.sendMessage(player, "&cError: size<=0");
MainUtil.sendMessage(player, "Error: size<=0");
}
if (args.length > 1) {
schematic = args[1];