mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-23 16:08:18 -05:00
Preserve pitch and yaw when teleporting
This commit is contained in:
parent
cf138a561b
commit
3b29ee5dc0
7 changed files with 77 additions and 40 deletions
2
pom.xml
2
pom.xml
|
@ -15,7 +15,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pw.kaboom.extras;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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.PlayerConnection;
|
||||||
import pw.kaboom.extras.modules.player.PlayerDamage;
|
import pw.kaboom.extras.modules.player.PlayerDamage;
|
||||||
import pw.kaboom.extras.modules.player.PlayerInteract;
|
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.player.PlayerTeleport;
|
||||||
import pw.kaboom.extras.modules.server.ServerCommand;
|
import pw.kaboom.extras.modules.server.ServerCommand;
|
||||||
import pw.kaboom.extras.modules.server.ServerPing;
|
import pw.kaboom.extras.modules.server.ServerPing;
|
||||||
|
import pw.kaboom.extras.modules.server.ServerTick;
|
||||||
|
|
||||||
public final class Main extends JavaPlugin {
|
public final class Main extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,10 +108,19 @@ public final class Main extends JavaPlugin {
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
|
||||||
|
this.getServer().getPluginManager().registerEvents(new PlayerRecipe(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
|
||||||
|
|
||||||
/* Server-related modules */
|
/* Server-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerPing(), 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,10 @@ public final class CommandUsername implements CommandExecutor {
|
||||||
} else if (millisDifference <= 2000) {
|
} else if (millisDifference <= 2000) {
|
||||||
player.sendMessage("Please wait a few seconds before changing your username");
|
player.sendMessage("Please wait a few seconds before changing your username");
|
||||||
} else {
|
} else {
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
if (Bukkit.getPlayer(name) != null
|
||||||
if (name.equals(onlinePlayer.getName())) {
|
&& Bukkit.getPlayer(name).isOnline()) {
|
||||||
player.sendMessage("A player with that username is already logged in");
|
player.sendMessage("A player with that username is already logged in");
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerProfile profile = player.getPlayerProfile();
|
final PlayerProfile profile = player.getPlayerProfile();
|
||||||
|
@ -44,7 +43,6 @@ public final class CommandUsername implements CommandExecutor {
|
||||||
profile.setName(name);
|
profile.setName(name);
|
||||||
|
|
||||||
player.setPlayerProfile(profile);
|
player.setPlayerProfile(profile);
|
||||||
player.setOp(true);
|
|
||||||
|
|
||||||
millis = System.currentTimeMillis();
|
millis = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|
|
@ -15,25 +15,25 @@ public final class EntityTeleport implements Listener {
|
||||||
final int minValue = -30000000;
|
final int minValue = -30000000;
|
||||||
|
|
||||||
if (x > maxValue) {
|
if (x > maxValue) {
|
||||||
x = maxValue;
|
location.setX(maxValue);
|
||||||
}
|
}
|
||||||
if (x < minValue) {
|
if (x < minValue) {
|
||||||
x = minValue;
|
location.setX(minValue);
|
||||||
}
|
}
|
||||||
if (y > maxValue) {
|
if (y > maxValue) {
|
||||||
y = maxValue;
|
location.setY(maxValue);
|
||||||
}
|
}
|
||||||
if (y < minValue) {
|
if (y < minValue) {
|
||||||
y = minValue;
|
location.setY(minValue);
|
||||||
}
|
}
|
||||||
if (z > maxValue) {
|
if (z > maxValue) {
|
||||||
z = maxValue;
|
location.setZ(maxValue);
|
||||||
}
|
}
|
||||||
if (z < minValue) {
|
if (z < minValue) {
|
||||||
z = minValue;
|
location.setZ(minValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Location(location.getWorld(), x, y, z);
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -4,8 +4,6 @@ import java.util.HashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameRule;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
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;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
||||||
|
@ -27,7 +24,8 @@ import pw.kaboom.extras.Main;
|
||||||
public final class PlayerConnection implements Listener {
|
public final class PlayerConnection implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
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");
|
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());
|
//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
|
@EventHandler
|
||||||
void onPreLookupProfile(final PreLookupProfileEvent event) {
|
void onPreLookupProfile(final PreLookupProfileEvent event) {
|
||||||
// Disable Mojang API calls, we don't need them
|
// Disable Mojang API calls, we don't need them
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue