mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-12-28 11:04:21 +00:00
Use PaperLib to load chunks and teleport players async (#2409)
* Remove outdated permission plugin handlers, minor test fixes * Re-add PermissionEX handler * Use PaperLib to load chunks async whenever possible * Revert "Use PaperLib to load chunks async whenever possible" This reverts commit db4df6f3cfa82d15d889933711674d02f5d95440. * Use PaperLib to load chunks and teleport players async * Resolve some PR issues * Update PaperLib, return teleport causes * Remove useless PaperLib usage in LocationUtil * Fix FakeServer spacing
This commit is contained in:
parent
f214696664
commit
3856a690eb
9 changed files with 54 additions and 46 deletions
|
@ -36,6 +36,12 @@
|
|||
</executions>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>com.earth2me.essentials.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -48,6 +54,12 @@
|
|||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>NMSProvider</artifactId>
|
||||
|
@ -95,12 +107,6 @@
|
|||
<artifactId>ReflectionProvider</artifactId>
|
||||
<version>2.16.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.earth2me.essentials.textreader.TextPager;
|
|||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
|
||||
import org.bukkit.BanEntry;
|
||||
|
@ -642,7 +643,7 @@ public class EssentialsPlayerListener implements Listener {
|
|||
while (LocationUtil.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())) {
|
||||
loc.setY(loc.getY() + 1d);
|
||||
}
|
||||
user.getBase().teleport(loc, TeleportCause.PLUGIN);
|
||||
PaperLib.teleportAsync(user.getBase(), loc, TeleportCause.PLUGIN);
|
||||
}
|
||||
}
|
||||
ess.scheduleSyncDelayedTask(new DelayedClickJumpTask());
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.earth2me.essentials;
|
|||
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.ITeleport;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.events.UserWarpEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -18,7 +20,7 @@ import java.util.GregorianCalendar;
|
|||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
public class Teleport implements net.ess3.api.ITeleport {
|
||||
public class Teleport implements ITeleport {
|
||||
private final IUser teleportOwner;
|
||||
private final IEssentials ess;
|
||||
private TimedTeleport timedTeleport;
|
||||
|
@ -49,7 +51,7 @@ public class Teleport implements net.ess3.api.ITeleport {
|
|||
final long earliestLong = earliestTime.getTimeInMillis();
|
||||
|
||||
// When was the last teleportPlayer used?
|
||||
final Long lastTime = teleportOwner.getLastTeleportTimestamp();
|
||||
final long lastTime = teleportOwner.getLastTeleportTimestamp();
|
||||
|
||||
if (lastTime > time.getTimeInMillis()) {
|
||||
// This is to make sure time didn't get messed up on last teleportPlayer use.
|
||||
|
@ -124,21 +126,21 @@ public class Teleport implements net.ess3.api.ITeleport {
|
|||
if (LocationUtil.isBlockUnsafeForUser(teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
|
||||
if (ess.getSettings().isTeleportSafetyEnabled()) {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
teleportee.getBase().teleport(loc, cause);
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
teleportee.getBase().teleport(LocationUtil.getSafeDestination(ess, teleportee, loc), cause);
|
||||
PaperLib.teleportAsync(teleportee.getBase(), LocationUtil.getSafeDestination(ess, teleportee, loc), cause);
|
||||
}
|
||||
} else {
|
||||
throw new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
} else {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
teleportee.getBase().teleport(loc, cause);
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
if (ess.getSettings().isTeleportToCenterLocation()) {
|
||||
loc = LocationUtil.getRoundedDestination(loc);
|
||||
}
|
||||
teleportee.getBase().teleport(loc, cause);
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +233,7 @@ public class Teleport implements net.ess3.api.ITeleport {
|
|||
initTimer((long) (delay * 1000.0), teleportOwner, null, chargeFor, cause, true);
|
||||
}
|
||||
|
||||
protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exception {
|
||||
void respawnNow(IUser teleportee, TeleportCause cause) throws Exception {
|
||||
final Player player = teleportee.getBase();
|
||||
Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null) {
|
||||
|
|
|
@ -16,9 +16,9 @@ public class TimedTeleport implements Runnable {
|
|||
private final IEssentials ess;
|
||||
private final Teleport teleport;
|
||||
private final UUID timer_teleportee;
|
||||
private int timer_task = -1;
|
||||
private final long timer_started; // time this task was initiated
|
||||
private final long timer_delay; // how long to delay the teleportPlayer
|
||||
private int timer_task;
|
||||
private final long timer_started; // time this task was initiated
|
||||
private final long timer_delay; // how long to delay the teleportPlayer
|
||||
private double timer_health;
|
||||
// note that I initially stored a clone of the location for reference, but...
|
||||
// when comparing locations, I got incorrect mismatches (rounding errors, looked like)
|
||||
|
@ -32,8 +32,7 @@ public class TimedTeleport implements Runnable {
|
|||
private final Trade timer_chargeFor;
|
||||
private final TeleportCause timer_cause;
|
||||
|
||||
public TimedTeleport(IUser user, IEssentials ess, Teleport teleport, long delay, IUser teleportUser, ITarget target, Trade chargeFor, TeleportCause cause, boolean respawn) {
|
||||
|
||||
TimedTeleport(IUser user, IEssentials ess, Teleport teleport, long delay, IUser teleportUser, ITarget target, Trade chargeFor, TeleportCause cause, boolean respawn) {
|
||||
this.teleportOwner = user;
|
||||
this.ess = ess;
|
||||
this.teleport = teleport;
|
||||
|
@ -111,8 +110,7 @@ public class TimedTeleport implements Runnable {
|
|||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.charge(teleportOwner);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ess.showError(teleportOwner.getSource(), ex, "\\ teleport");
|
||||
|
@ -124,7 +122,7 @@ public class TimedTeleport implements Runnable {
|
|||
}
|
||||
|
||||
//If we need to cancelTimer a pending teleportPlayer call this method
|
||||
public void cancelTimer(boolean notifyUser) {
|
||||
void cancelTimer(boolean notifyUser) {
|
||||
if (timer_task == -1) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import static com.earth2me.essentials.I18n.tl;
|
|||
|
||||
public class LocationUtil {
|
||||
// The player can stand inside these materials
|
||||
public static final Set<Material> HOLLOW_MATERIALS = new HashSet<>();
|
||||
private static final Set<Material> HOLLOW_MATERIALS = new HashSet<>();
|
||||
private static final Set<Material> TRANSPARENT_MATERIALS = new HashSet<>();
|
||||
|
||||
static {
|
||||
|
@ -32,8 +32,7 @@ public class LocationUtil {
|
|||
TRANSPARENT_MATERIALS.add(Material.WATER);
|
||||
try {
|
||||
TRANSPARENT_MATERIALS.add(Material.valueOf("FLOWING_WATER"));
|
||||
} catch (Exception ignored) { // 1.13 WATER uses Levelled
|
||||
}
|
||||
} catch (Exception ignored) {} // 1.13 WATER uses Levelled
|
||||
}
|
||||
|
||||
public static final int RADIUS = 3;
|
||||
|
@ -49,7 +48,7 @@ public class LocationUtil {
|
|||
public int y;
|
||||
public int z;
|
||||
|
||||
public Vector3D(int x, int y, int z) {
|
||||
Vector3D(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
@ -57,7 +56,7 @@ public class LocationUtil {
|
|||
}
|
||||
|
||||
static {
|
||||
List<Vector3D> pos = new ArrayList<Vector3D>();
|
||||
List<Vector3D> pos = new ArrayList<>();
|
||||
for (int x = -RADIUS; x <= RADIUS; x++) {
|
||||
for (int y = -RADIUS; y <= RADIUS; y++) {
|
||||
for (int z = -RADIUS; z <= RADIUS; z++) {
|
||||
|
@ -65,30 +64,22 @@ public class LocationUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(pos, new Comparator<Vector3D>() {
|
||||
@Override
|
||||
public int compare(Vector3D a, Vector3D b) {
|
||||
return (a.x * a.x + a.y * a.y + a.z * a.z) - (b.x * b.x + b.y * b.y + b.z * b.z);
|
||||
}
|
||||
});
|
||||
pos.sort(Comparator.comparingInt(a -> (a.x * a.x + a.y * a.y + a.z * a.z)));
|
||||
VOLUME = pos.toArray(new Vector3D[0]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Location getTarget(final LivingEntity entity) throws Exception {
|
||||
Block block = null;
|
||||
try {
|
||||
block = entity.getTargetBlock(TRANSPARENT_MATERIALS, 300);
|
||||
} catch (NoSuchMethodError e) {
|
||||
// failing now :(
|
||||
}
|
||||
} catch (NoSuchMethodError ignored) {} // failing now :(
|
||||
if (block == null) {
|
||||
throw new Exception("Not targeting a block");
|
||||
}
|
||||
return block.getLocation();
|
||||
}
|
||||
|
||||
static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) {
|
||||
public static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) {
|
||||
return y > world.getMaxHeight() || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType());
|
||||
}
|
||||
|
||||
|
@ -124,8 +115,7 @@ public class LocationUtil {
|
|||
if (below.getType() == Material.valueOf("FLOWING_LAVA")) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ignored) { // 1.13 LAVA uses Levelled
|
||||
}
|
||||
} catch (Exception ignored) {} // 1.13 LAVA uses Levelled
|
||||
|
||||
Material PORTAL = EnumUtil.getMaterial("NETHER_PORTAL", "PORTAL");
|
||||
|
||||
|
@ -159,7 +149,6 @@ public class LocationUtil {
|
|||
user.getBase().setFlying(true);
|
||||
}
|
||||
// ess can be null if old deprecated method is calling it.
|
||||
System.out.println((ess == null) + " " + ess.getSettings().isTeleportToCenterLocation());
|
||||
if (ess == null || ess.getSettings().isTeleportToCenterLocation()) {
|
||||
return getRoundedDestination(loc);
|
||||
} else {
|
||||
|
|
|
@ -445,6 +445,10 @@ public class FakeServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MapView getMap(short i) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
public MapView getMap(int id) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
@ -1050,7 +1054,6 @@ public class FakeServer implements Server {
|
|||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Keyed> Iterable<Tag<T>> getTags(String registry, Class<T> clazz) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
@ -1216,10 +1219,10 @@ public class FakeServer implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public LootTable getLootTable(NamespacedKey arg0) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> selectEntities(CommandSender sender, String selector) throws IllegalArgumentException {
|
||||
|
|
|
@ -21,5 +21,10 @@
|
|||
<artifactId>EssentialsX</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -6,6 +6,7 @@ import com.earth2me.essentials.User;
|
|||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextPager;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -74,8 +75,7 @@ class EssentialsSpawnPlayerListener implements Listener {
|
|||
ess.scheduleSyncDelayedTask(() -> {
|
||||
Location spawn = spawns.getSpawn(user.getGroup());
|
||||
try {
|
||||
// We don't use user.getTeleport() because it stores last location, which is unwanted in this case.
|
||||
user.getBase().teleport(spawn, TeleportCause.PLUGIN);
|
||||
PaperLib.teleportAsync(user.getBase(), spawn, TeleportCause.PLUGIN);
|
||||
} catch (Exception e) {
|
||||
ess.showError(user.getSource(), e, "spawn-on-join");
|
||||
}
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -31,6 +31,10 @@
|
|||
<id>bukkit-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>paper-repo</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<modules>
|
||||
|
|
Loading…
Reference in a new issue