Update to gradle 8.14.2, add formatting
This commit is contained in:
1 parent
309dc0e588
commit
27110ee2f5
10 files changed
+247
-227
No files matched your search
+26
-20
@@ -1,8 +1,9 @@
|
||||
plugins {
|
||||
id("java") // Tell gradle this is a java project.
|
||||
id("java-library") // Import helper for source-based libraries.
|
||||
id("com.diffplug.spotless") version "7.0.4" // Import auto-formatter.
|
||||
id("com.gradleup.shadow") version "8.3.6" // Import shadow API.
|
||||
java // Tell gradle this is a java project.
|
||||
eclipse // Import eclipse plugin for IDE integration.
|
||||
kotlin("jvm") version "2.1.21" // Import kotlin jvm plugin for kotlin/java integration.
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -11,20 +12,17 @@ java {
|
||||
}
|
||||
|
||||
group = "net.trueog.horsetpog" // Declare bundle identifier.
|
||||
|
||||
version = "1.1" // Declare plugin version (will be in .jar).
|
||||
|
||||
val apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
tasks.named<ProcessResources>("processResources") {
|
||||
val props = mapOf(
|
||||
"version" to version,
|
||||
"apiVersion" to apiVersion
|
||||
)
|
||||
val props = mapOf("version" to version, "apiVersion" to apiVersion)
|
||||
|
||||
inputs.properties(props) // Indicates to rerun if version changes.
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
filesMatching("plugin.yml") { expand(props) }
|
||||
from("LICENSE") { // Bundle license into .jars.
|
||||
into("/")
|
||||
}
|
||||
@@ -37,7 +35,7 @@ repositories {
|
||||
url = uri("https://repo.purpurmc.org/snapshots") // Get purpur API from Purpur maven repository.
|
||||
}
|
||||
maven {
|
||||
url = uri("https://maven.enginehub.org/repo/") // Get the WorldGuard API from EngineHub maven repository.
|
||||
url = uri("https://maven.enginehub.org/repo/") // Get the WorldGuard API from EngineHub maven repository.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +44,12 @@ dependencies {
|
||||
compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare purpur API version to be packaged.
|
||||
compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API.
|
||||
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT") // Import WorldEdit.
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9") { // Import WorldGuard but without its bundled WorldEdit.
|
||||
compileOnly(
|
||||
"com.sk89q.worldguard:worldguard-bukkit:7.0.9"
|
||||
) { // Import WorldGuard but without its bundled WorldEdit.
|
||||
exclude(group = "com.sk89q.worldedit")
|
||||
}
|
||||
compileOnly(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG API.
|
||||
compileOnlyApi(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG API.
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
|
||||
@@ -58,18 +58,17 @@ tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .ja
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveClassifier.set("") // Use empty string instead of null.
|
||||
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
|
||||
archiveClassifier.set("") // Use empty string instead of null.
|
||||
minimize()
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.spotlessApply)
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveClassifier.set("part")
|
||||
}
|
||||
tasks.jar { archiveClassifier.set("part") }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.compilerArgs.add("-parameters")
|
||||
@@ -78,13 +77,20 @@ tasks.withType<JavaCompile>().configureEach {
|
||||
options.isFork = true
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
vendor = JvmVendorSpec.GRAAL_VM
|
||||
}
|
||||
}
|
||||
|
||||
spotless {
|
||||
java {
|
||||
removeUnusedImports()
|
||||
palantirJavaFormat()
|
||||
}
|
||||
kotlinGradle {
|
||||
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) }
|
||||
target("build.gradle.kts", "settings.gradle.kts")
|
||||
}
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -86,8 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -115,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -206,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+2
-2
@@ -70,11 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
+1
-1
Submodule libs/Utilities-OG updated: 6151b2de7f...e68d3fec7a.
+2
-3
@@ -1,11 +1,10 @@
|
||||
rootProject.name = "HorseTp-OG"
|
||||
|
||||
// Run the bootstrap at configuration time.
|
||||
val process = ProcessBuilder("sh", "bootstrap.sh")
|
||||
.directory(rootDir)
|
||||
.start()
|
||||
val process = ProcessBuilder("sh", "bootstrap.sh").directory(rootDir).start()
|
||||
|
||||
val exitValue = process.waitFor()
|
||||
|
||||
if (exitValue != 0) {
|
||||
throw GradleException("bootstrap.sh failed with exit code $exitValue")
|
||||
}
|
||||
|
||||
@@ -1,68 +1,63 @@
|
||||
package net.trueog.horsetpog;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import net.trueog.horsetpog.Listeners.OnEntityDismount;
|
||||
import net.trueog.horsetpog.Listeners.OnPlayerTeleport;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class HorseTpOG extends JavaPlugin {
|
||||
|
||||
private static StateFlag HorseTpFlag;
|
||||
private static HorseTpOG plugin;
|
||||
private static HashMap<Player, Entity> vehicleCache = new HashMap<>();
|
||||
private static StateFlag HorseTpFlag;
|
||||
private static HorseTpOG plugin;
|
||||
private static HashMap<Player, Entity> vehicleCache = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onLoad(){
|
||||
// add the WorldGuard flag for an area where HorseTp will not work
|
||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||
try {
|
||||
// create a flag with the name "my-custom-flag", defaulting to true
|
||||
StateFlag flag = new StateFlag("allow-boat-tp", true);
|
||||
registry.register(flag);
|
||||
HorseTpFlag = flag; // only set our field if there was no error
|
||||
} catch (FlagConflictException e) {
|
||||
// some other plugin registered a flag by the same name already.
|
||||
// you can use the existing flag, but this may cause conflicts - be sure to check type
|
||||
Flag<?> existing = registry.get("allow-boat-tp");
|
||||
if (existing instanceof StateFlag) {
|
||||
HorseTpFlag = (StateFlag) existing;
|
||||
} else {
|
||||
// types don't match - this is bad news! some other plugin conflicts with you
|
||||
// hopefully this never actually happens
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// add the WorldGuard flag for an area where HorseTp will not work
|
||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||
try {
|
||||
// create a flag with the name "my-custom-flag", defaulting to true
|
||||
StateFlag flag = new StateFlag("allow-boat-tp", true);
|
||||
registry.register(flag);
|
||||
HorseTpFlag = flag; // only set our field if there was no error
|
||||
} catch (FlagConflictException e) {
|
||||
// some other plugin registered a flag by the same name already.
|
||||
// you can use the existing flag, but this may cause conflicts - be sure to check type
|
||||
Flag<?> existing = registry.get("allow-boat-tp");
|
||||
if (existing instanceof StateFlag) {
|
||||
HorseTpFlag = (StateFlag) existing;
|
||||
} else {
|
||||
// types don't match - this is bad news! some other plugin conflicts with you
|
||||
// hopefully this never actually happens
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
// Plugin startup logic
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
// Plugin startup logic
|
||||
|
||||
getServer().getPluginManager().registerEvents(new OnEntityDismount(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerTeleport(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnEntityDismount(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerTeleport(), this);
|
||||
}
|
||||
|
||||
}
|
||||
public static HorseTpOG getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static HorseTpOG getPlugin(){
|
||||
return plugin;
|
||||
}
|
||||
public static StateFlag getHorseTpFlag() {
|
||||
return HorseTpFlag;
|
||||
}
|
||||
|
||||
public static StateFlag getHorseTpFlag(){
|
||||
return HorseTpFlag;
|
||||
}
|
||||
|
||||
public static HashMap<Player, Entity> getVehicleCache(){
|
||||
return vehicleCache;
|
||||
}
|
||||
|
||||
}
|
||||
public static HashMap<Player, Entity> getVehicleCache() {
|
||||
return vehicleCache;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.trueog.horsetpog.Listeners;
|
||||
|
||||
import net.trueog.horsetpog.HorseTpOG;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -8,28 +9,29 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
|
||||
import net.trueog.horsetpog.HorseTpOG;
|
||||
|
||||
public class OnEntityDismount implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
// when a player teleports, they are dismounted from their vehicle
|
||||
// so when they get dismounted, teleport the vehicle to them
|
||||
public void onEntityDismount(EntityDismountEvent event){
|
||||
if(event.getEntity() instanceof Player){
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
// when a player teleports, they are dismounted from their vehicle
|
||||
// so when they get dismounted, teleport the vehicle to them
|
||||
public void onEntityDismount(EntityDismountEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
|
||||
// When a player dismounts, add them and the vehicle
|
||||
// to a cache, which is read on a teleport event to tp them
|
||||
Player player = (Player) event.getEntity();
|
||||
// When a player dismounts, add them and the vehicle
|
||||
// to a cache, which is read on a teleport event to tp them
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
Entity vehicle = event.getDismounted();
|
||||
HorseTpOG.getVehicleCache().put(player, vehicle);
|
||||
Entity vehicle = event.getDismounted();
|
||||
HorseTpOG.getVehicleCache().put(player, vehicle);
|
||||
|
||||
// 5 ticks later, remove them from the cache
|
||||
Bukkit.getScheduler().runTaskLater(HorseTpOG.getPlugin(), () -> {
|
||||
HorseTpOG.getVehicleCache().remove(player);
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 5 ticks later, remove them from the cache
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
HorseTpOG.getPlugin(),
|
||||
() -> {
|
||||
HorseTpOG.getVehicleCache().remove(player);
|
||||
},
|
||||
5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
package net.trueog.horsetpog.Listeners;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.trueog.horsetpog.HorseTpOG;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@@ -16,145 +23,157 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.trueog.horsetpog.HorseTpOG;
|
||||
|
||||
public class OnPlayerTeleport implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
|
||||
// run all of this 1 tick after the teleport so that the players location gets updated
|
||||
// and the dismount event is guaranteed to have been called
|
||||
Bukkit.getScheduler().runTaskLater(HorseTpOG.getPlugin(), () -> {
|
||||
// run all of this 1 tick after the teleport so that the players location gets updated
|
||||
// and the dismount event is guaranteed to have been called
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
HorseTpOG.getPlugin(),
|
||||
() -> {
|
||||
|
||||
// if the player did not have a vehicle prior to the teleport
|
||||
// ignore this handler
|
||||
if (HorseTpOG.getVehicleCache().get(event.getPlayer()) == null) {
|
||||
return;
|
||||
}
|
||||
// if the player did not have a vehicle prior to the teleport
|
||||
// ignore this handler
|
||||
if (HorseTpOG.getVehicleCache().get(event.getPlayer()) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this checks to see if the teleport was a result of a dismount, or a /tp
|
||||
// TeleportCause.UNKNOWN is a dismount
|
||||
if (!event.getCause().equals(TeleportCause.UNKNOWN)) {
|
||||
|
||||
// this checks to see if the teleport was a result of a dismount, or a /tp
|
||||
// TeleportCause.UNKNOWN is a dismount
|
||||
if (! event.getCause().equals(TeleportCause.UNKNOWN)) {
|
||||
// I have no idea why this works, but it does
|
||||
// I reset the player's pitch/yaw and then teleport them back
|
||||
event.getPlayer()
|
||||
.teleport(new Location(
|
||||
event.getPlayer().getWorld(),
|
||||
event.getPlayer().getLocation().getX(),
|
||||
event.getPlayer().getLocation().getY(),
|
||||
event.getPlayer().getLocation().getZ()));
|
||||
event.getPlayer().teleport(event.getTo());
|
||||
|
||||
// I have no idea why this works, but it does
|
||||
// I reset the player's pitch/yaw and then teleport them back
|
||||
event.getPlayer().teleport(new Location(event.getPlayer().getWorld(), event.getPlayer().getLocation().getX(), event.getPlayer().getLocation().getY(), event.getPlayer().getLocation().getZ()));
|
||||
event.getPlayer().teleport(event.getTo());
|
||||
Player player = event.getPlayer();
|
||||
// get the vehicle from the vehicle cache
|
||||
Entity vehicle = HorseTpOG.getVehicleCache().get(player);
|
||||
// remove the player and vehicle from the cache
|
||||
// this is necessary to prevent the WorldGuard teleport
|
||||
// from triggering this event again
|
||||
HorseTpOG.getVehicleCache().remove(player);
|
||||
|
||||
Player player = event.getPlayer();
|
||||
// get the vehicle from the vehicle cache
|
||||
Entity vehicle = HorseTpOG.getVehicleCache().get(player);
|
||||
// remove the player and vehicle from the cache
|
||||
// this is necessary to prevent the WorldGuard teleport
|
||||
// from triggering this event again
|
||||
HorseTpOG.getVehicleCache().remove(player);
|
||||
// check if the area that the player teleported to is a banned area
|
||||
RegionContainer container =
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
com.sk89q.worldedit.util.Location worldGuardPlayerLocation =
|
||||
BukkitAdapter.adapt(event.getTo());
|
||||
|
||||
// check if the area that the player teleported to is a banned area
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
com.sk89q.worldedit.util.Location worldGuardPlayerLocation = BukkitAdapter.adapt(event.getTo());
|
||||
RegionQuery query = container.createQuery();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(worldGuardPlayerLocation);
|
||||
|
||||
RegionQuery query = container.createQuery();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(worldGuardPlayerLocation);
|
||||
// check if the horse-can-tp flag is set to DENY
|
||||
if (!set.testState(null, HorseTpOG.getHorseTpFlag())) {
|
||||
// only stop the tp if the player is in a minecart or boat
|
||||
// Otherwise, a protected area could be flooded with boats and minecarts
|
||||
// that can't be destroyed by non-admins
|
||||
if (vehicle instanceof Boat || vehicle instanceof Minecart) {
|
||||
player.sendMessage(Component.text("[HorseTp]")
|
||||
.color(TextColor.color(0, 255, 0))
|
||||
.append(Component.text(" You can't teleport boats here")
|
||||
.color(TextColor.color(255, 0, 0))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// get a list of all the passengers the vehicle had
|
||||
// use try-catch to see if the vehicle still exists
|
||||
// as it may have been removed by another plugin
|
||||
List<Entity> passengerList = null;
|
||||
try {
|
||||
passengerList = vehicle.getPassengers();
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
// remove the player from the passenger list
|
||||
passengerList.remove(player);
|
||||
// eject all of the passengers
|
||||
vehicle.eject();
|
||||
|
||||
// check if the horse-can-tp flag is set to DENY
|
||||
if (!set.testState(null, HorseTpOG.getHorseTpFlag())) {
|
||||
// only stop the tp if the player is in a minecart or boat
|
||||
// Otherwise, a protected area could be flooded with boats and minecarts
|
||||
// that can't be destroyed by non-admins
|
||||
if(vehicle instanceof Boat || vehicle instanceof Minecart) {
|
||||
player.sendMessage(Component.text("[HorseTp]")
|
||||
.color(TextColor.color(0, 255, 0))
|
||||
.append(Component.text(" You can't teleport boats here")
|
||||
.color(TextColor.color(255, 0, 0))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// get a list of all the passengers the vehicle had
|
||||
// use try-catch to see if the vehicle still exists
|
||||
// as it may have been removed by another plugin
|
||||
List<Entity> passengerList = null;
|
||||
try {
|
||||
passengerList = vehicle.getPassengers();
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
// remove the player from the passenger list
|
||||
passengerList.remove(player);
|
||||
// eject all of the passengers
|
||||
vehicle.eject();
|
||||
// load the chunk that the vehicle is in
|
||||
World vehicleWorld = vehicle.getWorld();
|
||||
Chunk vehicleChunk = vehicle.getChunk();
|
||||
vehicleWorld.loadChunk(vehicleChunk);
|
||||
|
||||
// load the chunk that the vehicle is in
|
||||
World vehicleWorld = vehicle.getWorld();
|
||||
Chunk vehicleChunk = vehicle.getChunk();
|
||||
vehicleWorld.loadChunk(vehicleChunk);
|
||||
// wait 1 tick before teleporting the entity
|
||||
List<Entity> finalPassengerList =
|
||||
passengerList; // apparently this is required for the compiler to be happy ?
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
HorseTpOG.getPlugin(),
|
||||
() -> {
|
||||
// teleport the vehicle and all of the passengers
|
||||
// use try-catch to see if the vehicle still exists
|
||||
try {
|
||||
vehicle.teleport(player.getLocation());
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// wait 1 tick before teleporting the entity
|
||||
List<Entity> finalPassengerList = passengerList; // apparently this is required for the compiler to be happy ?
|
||||
Bukkit.getScheduler().runTaskLater(HorseTpOG.getPlugin(), () -> {
|
||||
// teleport the vehicle and all of the passengers
|
||||
// use try-catch to see if the vehicle still exists
|
||||
try {
|
||||
vehicle.teleport(player.getLocation());
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
finalPassengerList.forEach(entity -> {
|
||||
entity.teleport(player.getLocation());
|
||||
vehicle.addPassenger(entity);
|
||||
});
|
||||
|
||||
finalPassengerList.forEach(entity -> {
|
||||
entity.teleport(player.getLocation());
|
||||
vehicle.addPassenger(entity);
|
||||
});
|
||||
// simply hide and show the vehicle
|
||||
// so that the vehicle is not invisible
|
||||
player.hideEntity(HorseTpOG.getPlugin(), vehicle);
|
||||
player.showEntity(HorseTpOG.getPlugin(), vehicle);
|
||||
|
||||
// simply hide and show the vehicle
|
||||
// so that the vehicle is not invisible
|
||||
player.hideEntity(HorseTpOG.getPlugin(), vehicle);
|
||||
player.showEntity(HorseTpOG.getPlugin(), vehicle);
|
||||
// add the player back to the vehicle
|
||||
vehicle.addPassenger(player);
|
||||
|
||||
// add the player back to the vehicle
|
||||
vehicle.addPassenger(player);
|
||||
// unload the chunk that the vehicle was in one tick later
|
||||
// also add the player back to the vehicle
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
HorseTpOG.getPlugin(),
|
||||
() -> {
|
||||
vehicleWorld.unloadChunk(vehicleChunk);
|
||||
},
|
||||
1);
|
||||
},
|
||||
1);
|
||||
}
|
||||
},
|
||||
1);
|
||||
}
|
||||
|
||||
// unload the chunk that the vehicle was in one tick later
|
||||
// also add the player back to the vehicle
|
||||
Bukkit.getScheduler().runTaskLater(HorseTpOG.getPlugin(), () -> {
|
||||
vehicleWorld.unloadChunk(vehicleChunk);
|
||||
}, 1);
|
||||
}, 1);
|
||||
}
|
||||
}, 1);
|
||||
// this method is used for teleporting players back when the region
|
||||
// that they teleported to is restricted
|
||||
// this is necessary because if someone is laggy, we need to load the
|
||||
// chunk that they are in
|
||||
// This is mostly a problem for 1.8 players
|
||||
|
||||
}
|
||||
|
||||
|
||||
// this method is used for teleporting players back when the region
|
||||
// that they teleported to is restricted
|
||||
// this is necessary because if someone is laggy, we need to load the
|
||||
// chunk that they are in
|
||||
// This is mostly a problem for 1.8 players
|
||||
|
||||
// It just recursively calls itself, loading the chunk until
|
||||
// the player is teleported back
|
||||
public void loadChunksUntilTeleportComplete(World world, Location teleportFrom, Player player){
|
||||
if(! Arrays.stream(world.getChunkAt(teleportFrom).getEntities()).toList().contains(player)){
|
||||
loadChunksUntilTeleportComplete(world, teleportFrom, player);
|
||||
}
|
||||
else{
|
||||
for(int i = 0; i < (int) Math.ceil(((double) player.getPing()) / 50) + 10; i++){
|
||||
Bukkit.getScheduler().runTaskLater(HorseTpOG.getPlugin(), () -> {
|
||||
world.getChunkAt(teleportFrom).load();
|
||||
player.sendBlockChange(player.getLocation(), world.getBlockData(player.getLocation()));
|
||||
}, i);
|
||||
}
|
||||
}
|
||||
world.getChunkAt(teleportFrom).load();
|
||||
}
|
||||
|
||||
}
|
||||
// It just recursively calls itself, loading the chunk until
|
||||
// the player is teleported back
|
||||
public void loadChunksUntilTeleportComplete(World world, Location teleportFrom, Player player) {
|
||||
if (!Arrays.stream(world.getChunkAt(teleportFrom).getEntities())
|
||||
.toList()
|
||||
.contains(player)) {
|
||||
loadChunksUntilTeleportComplete(world, teleportFrom, player);
|
||||
} else {
|
||||
for (int i = 0; i < (int) Math.ceil(((double) player.getPing()) / 50) + 10; i++) {
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
HorseTpOG.getPlugin(),
|
||||
() -> {
|
||||
world.getChunkAt(teleportFrom).load();
|
||||
player.sendBlockChange(
|
||||
player.getLocation(), world.getBlockData(player.getLocation()));
|
||||
},
|
||||
i);
|
||||
}
|
||||
}
|
||||
world.getChunkAt(teleportFrom).load();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user