Preserve pitch and yaw when teleporting

This commit is contained in:
mathiascode 2020-05-10 16:23:33 +03:00
parent cf138a561b
commit 3b29ee5dc0
7 changed files with 77 additions and 40 deletions

View file

@ -15,7 +15,7 @@
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<version>1.15.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>

View file

@ -2,6 +2,7 @@ package pw.kaboom.extras;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.java.JavaPlugin;
@ -37,9 +38,11 @@ import pw.kaboom.extras.modules.player.PlayerCommand;
import pw.kaboom.extras.modules.player.PlayerConnection;
import pw.kaboom.extras.modules.player.PlayerDamage;
import pw.kaboom.extras.modules.player.PlayerInteract;
import pw.kaboom.extras.modules.player.PlayerRecipe;
import pw.kaboom.extras.modules.player.PlayerTeleport;
import pw.kaboom.extras.modules.server.ServerCommand;
import pw.kaboom.extras.modules.server.ServerPing;
import pw.kaboom.extras.modules.server.ServerTick;
public final class Main extends JavaPlugin {
@Override
@ -105,10 +108,19 @@ public final class Main extends JavaPlugin {
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
this.getServer().getPluginManager().registerEvents(new PlayerRecipe(), this);
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
/* Server-related modules */
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
this.getServer().getPluginManager().registerEvents(new ServerPing(), this);
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
}
@Override
public void onDisable() {
if (Bukkit.isStopping()) {
System.exit(1);
}
}
}

View file

@ -32,11 +32,10 @@ public final class CommandUsername implements CommandExecutor {
} else if (millisDifference <= 2000) {
player.sendMessage("Please wait a few seconds before changing your username");
} else {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (name.equals(onlinePlayer.getName())) {
player.sendMessage("A player with that username is already logged in");
return true;
}
if (Bukkit.getPlayer(name) != null
&& Bukkit.getPlayer(name).isOnline()) {
player.sendMessage("A player with that username is already logged in");
return true;
}
final PlayerProfile profile = player.getPlayerProfile();
@ -44,7 +43,6 @@ public final class CommandUsername implements CommandExecutor {
profile.setName(name);
player.setPlayerProfile(profile);
player.setOp(true);
millis = System.currentTimeMillis();

View file

@ -15,25 +15,25 @@ public final class EntityTeleport implements Listener {
final int minValue = -30000000;
if (x > maxValue) {
x = maxValue;
location.setX(maxValue);
}
if (x < minValue) {
x = minValue;
location.setX(minValue);
}
if (y > maxValue) {
y = maxValue;
location.setY(maxValue);
}
if (y < minValue) {
y = minValue;
location.setY(minValue);
}
if (z > maxValue) {
z = maxValue;
location.setZ(maxValue);
}
if (z < minValue) {
z = minValue;
location.setZ(minValue);
}
return new Location(location.getWorld(), x, y, z);
return location;
}
@EventHandler

View file

@ -4,8 +4,6 @@ import java.util.HashSet;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -15,7 +13,6 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
@ -27,7 +24,8 @@ import pw.kaboom.extras.Main;
public final class PlayerConnection implements Listener {
@EventHandler
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
if (Bukkit.getPlayer(event.getName()) != null) {
if (Bukkit.getPlayer(event.getName()) != null
&& Bukkit.getPlayer(event.getName()).isOnline()) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "A player with that username is already logged in");
}
@ -109,28 +107,6 @@ public final class PlayerConnection implements Listener {
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
}
@EventHandler
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
final World world = event.getPlayer().getWorld();
final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED);
if (randomTickSpeed > 6) {
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6);
}
final Integer spawnRadius = world.getGameRuleValue(GameRule.SPAWN_RADIUS);
if (spawnRadius > 100) {
world.setGameRule(GameRule.SPAWN_RADIUS, 100);
}
if (!world.isAutoSave()) {
world.setAutoSave(true);
}
event.setCancelled(true);
}
@EventHandler
void onPreLookupProfile(final PreLookupProfileEvent event) {
// Disable Mojang API calls, we don't need them

View file

@ -0,0 +1,20 @@
package pw.kaboom.extras.modules.player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
public final class PlayerRecipe implements Listener {
private long recipeMillis;
@EventHandler
void onPlayerRecipeDiscover(final PlayerRecipeDiscoverEvent event) {
final long millisDifference = System.currentTimeMillis() - recipeMillis;
if (millisDifference < 75) {
event.setCancelled(true);
}
recipeMillis = System.currentTimeMillis();
}
}

View file

@ -0,0 +1,31 @@
package pw.kaboom.extras.modules.server;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
public final class ServerTick implements Listener {
@EventHandler
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
final World world = event.getPlayer().getWorld();
final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED);
if (randomTickSpeed > 6) {
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6);
}
final Integer spawnRadius = world.getGameRuleValue(GameRule.SPAWN_RADIUS);
if (spawnRadius > 100) {
world.setGameRule(GameRule.SPAWN_RADIUS, 100);
}
if (!world.isAutoSave()) {
world.setAutoSave(true);
}
event.setCancelled(true);
}
}