mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Use PaperLib and make command task return completable futures
This commit is contained in:
@ -3,6 +3,10 @@ repositories {
|
||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
maven { url "http://nexus.hc.to/content/repositories/pub_releases" }
|
||||
maven { url = "https://repo.codemc.org/repository/maven-public" }
|
||||
maven {
|
||||
name 'papermc'
|
||||
url 'https://papermc.io/repo/repository/maven-public/'
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
@ -12,6 +16,7 @@ dependencies {
|
||||
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
||||
compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0-SNAPSHOT')
|
||||
compile(group: 'org.bstats', name: 'bstats-bukkit', version: '1.4')
|
||||
compile "io.papermc:paperlib:1.0.1"
|
||||
compile("net.milkbowl.vault:VaultAPI:1.7") {
|
||||
exclude module: 'bukkit'
|
||||
}
|
||||
@ -37,7 +42,9 @@ shadowJar {
|
||||
dependencies {
|
||||
include(dependency(':Core'))
|
||||
include(dependency('org.bstats:bstats-bukkit:1.4'))
|
||||
include(dependency("io.papermc:paperlib:1.0.1"))
|
||||
}
|
||||
relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib'
|
||||
// relocate('org.mcstats', 'com.plotsquared.stats')
|
||||
archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
|
||||
destinationDir = file '../target'
|
||||
|
@ -1,36 +1,11 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.*;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitBlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitCommand;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEconHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitLegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.SendChunk;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.*;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.*;
|
||||
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
@ -41,57 +16,23 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridGen;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChatManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ConsoleColors;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
||||
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -104,6 +45,13 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
@ -170,23 +118,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
getServer().getName();
|
||||
|
||||
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
|
||||
|
||||
if (Bukkit.getVersion().contains("git-Spigot")) {
|
||||
// Uses System.out.println because the logger isn't initialized yet
|
||||
System.out
|
||||
.println("[P2] ========================== USE PAPER ==========================");
|
||||
System.out.println("[P2] Paper offers a more complete API for us to work with");
|
||||
System.out.println("[P2] and we may come to rely on it in the future.");
|
||||
System.out.println("[P2] It is also recommended out of a performance standpoint as");
|
||||
System.out
|
||||
.println("[P2] it contains many improvements missing from Spigot and Bukkit.");
|
||||
System.out.println("[P2] DOWNLOAD: https://papermc.io/downloads");
|
||||
System.out.println("[P2] GUIDE: https://www.spigotmc.org/threads/21726/");
|
||||
System.out.println("[P2] NOTE: This is only a recommendation");
|
||||
System.out.println("[P2] both Spigot and CraftBukkit are still supported.");
|
||||
System.out
|
||||
.println("[P2] ===============================================================");
|
||||
}
|
||||
PaperLib.suggestPaper(this);
|
||||
|
||||
new PlotSquared(this, "Bukkit");
|
||||
if (Settings.Enabled_Components.METRICS) {
|
||||
|
@ -6,10 +6,6 @@ import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -7,15 +7,20 @@ import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import org.bukkit.*;
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.WeatherType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -24,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
public boolean offline;
|
||||
private boolean offline;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
@ -32,21 +37,23 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
* <p>Please do not use this method. Instead use
|
||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||
*
|
||||
* @param player
|
||||
* @param player Bukkit player instance
|
||||
*/
|
||||
public BukkitPlayer(Player player) {
|
||||
public BukkitPlayer(@Nonnull final Player player) {
|
||||
Preconditions.checkNotNull(player, "Bukkit player instance cannot be null");
|
||||
this.player = player;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
|
||||
public BukkitPlayer(Player player, boolean offline) {
|
||||
public BukkitPlayer(@Nonnull final Player player, final boolean offline) {
|
||||
Preconditions.checkNotNull(player, "Bukkit player instance cannot be null");
|
||||
this.player = player;
|
||||
this.offline = offline;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
|
||||
@Override public Location getLocation() {
|
||||
Location location = super.getLocation();
|
||||
final Location location = super.getLocation();
|
||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||
}
|
||||
|
||||
@ -61,9 +68,10 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return this.player.getLastPlayed();
|
||||
}
|
||||
|
||||
@Override public boolean canTeleport(Location loc) {
|
||||
org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
||||
org.bukkit.Location from = player.getLocation();
|
||||
@Override public boolean canTeleport(@Nonnull final Location loc) {
|
||||
Preconditions.checkNotNull(loc, "Bukkit location cannot be null");
|
||||
final org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
||||
final org.bukkit.Location from = player.getLocation();
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||
callEvent(event);
|
||||
if (event.isCancelled() || !event.getTo().equals(to)) {
|
||||
@ -75,32 +83,34 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
|
||||
private void callEvent(final Event event) {
|
||||
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
||||
for (RegisteredListener listener : listeners) {
|
||||
Preconditions.checkNotNull(event, "Event cannot be null");
|
||||
|
||||
final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
||||
for (final RegisteredListener listener : listeners) {
|
||||
if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
listener.callEvent(event);
|
||||
} catch (EventException e) {
|
||||
} catch (final EventException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(String permission) {
|
||||
@Override public boolean hasPermission(final String permission) {
|
||||
if (this.offline && EconHandler.manager != null) {
|
||||
return EconHandler.manager.hasPermission(getName(), permission);
|
||||
}
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override public int hasPermissionRange(String stub, int range) {
|
||||
@Override public int hasPermissionRange(final String stub, final int range) {
|
||||
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
String[] nodes = stub.split("\\.");
|
||||
StringBuilder n = new StringBuilder();
|
||||
final String[] nodes = stub.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (!stub.equals(n + C.PERMISSION_STAR.s())) {
|
||||
@ -114,7 +124,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
int max = 0;
|
||||
String stubPlus = stub + ".";
|
||||
Set<PermissionAttachmentInfo> effective = player.getEffectivePermissions();
|
||||
final Set<PermissionAttachmentInfo> effective = player.getEffectivePermissions();
|
||||
if (!effective.isEmpty()) {
|
||||
for (PermissionAttachmentInfo attach : effective) {
|
||||
String perm = attach.getPermission();
|
||||
@ -139,12 +149,12 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override public boolean isPermissionSet(String permission) {
|
||||
@Override public boolean isPermissionSet(final String permission) {
|
||||
return this.player.isPermissionSet(permission);
|
||||
}
|
||||
|
||||
@Override public void sendMessage(String message) {
|
||||
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (
|
||||
@Override public void sendMessage(final String message) {
|
||||
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (
|
||||
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
||||
setMeta("lastMessage", message);
|
||||
setMeta("lastMessageTime", System.currentTimeMillis());
|
||||
@ -152,14 +162,13 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void teleport(Location location) {
|
||||
@Override public void teleport(@Nonnull final Location location) {
|
||||
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||
return;
|
||||
}
|
||||
this.player.teleport(
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
|
||||
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()),
|
||||
TeleportCause.COMMAND);
|
||||
final org.bukkit.Location bukkitLocation = new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
|
||||
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch());
|
||||
PaperLib.teleportAsync(player, bukkitLocation);
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
@ -177,14 +186,14 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
this.player.setCompassTarget(
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(),
|
||||
location.getY(), location.getZ()));
|
||||
|
||||
}
|
||||
|
||||
@Override public Location getLocationFull() {
|
||||
return BukkitUtil.getLocationFull(this.player);
|
||||
}
|
||||
|
||||
@Override public void setWeather(PlotWeather weather) {
|
||||
@Override public void setWeather(@Nonnull final PlotWeather weather) {
|
||||
Preconditions.checkNotNull(weather, "Specified weather cannot be null");
|
||||
switch (weather) {
|
||||
case CLEAR:
|
||||
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||
@ -201,7 +210,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public PlotGameMode getGameMode() {
|
||||
@Nonnull @Override public PlotGameMode getGameMode() {
|
||||
switch (this.player.getGameMode()) {
|
||||
case ADVENTURE:
|
||||
return PlotGameMode.ADVENTURE;
|
||||
@ -216,7 +225,8 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setGameMode(PlotGameMode gameMode) {
|
||||
@Override public void setGameMode(@Nonnull final PlotGameMode gameMode) {
|
||||
Preconditions.checkNotNull(gameMode, "Specified gamemode cannot be null");
|
||||
switch (gameMode) {
|
||||
case ADVENTURE:
|
||||
this.player.setGameMode(GameMode.ADVENTURE);
|
||||
@ -236,7 +246,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setTime(long time) {
|
||||
@Override public void setTime(final long time) {
|
||||
if (time != Long.MAX_VALUE) {
|
||||
this.player.setPlayerTime(time, false);
|
||||
} else {
|
||||
@ -252,7 +262,9 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
this.player.setAllowFlight(fly);
|
||||
}
|
||||
|
||||
@Override public void playMusic(Location location, PlotBlock id) {
|
||||
@Override public void playMusic(@Nonnull final Location location, @Nonnull final PlotBlock id) {
|
||||
Preconditions.checkNotNull(location, "Specified location cannot be null");
|
||||
Preconditions.checkNotNull(id, "Specified block cannot be null");
|
||||
if (PlotBlock.isEverything(id) || id.isAir()) {
|
||||
// Let's just stop all the discs because why not?
|
||||
for (final Sound sound : Arrays.stream(Sound.values()).filter(sound -> sound.name().contains("DISC")).collect(
|
||||
@ -266,7 +278,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void kick(String message) {
|
||||
@Override public void kick(final String message) {
|
||||
this.player.kickPlayer(message);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user