Gliding activation and ToggleEvent cancelling control
This commit is contained in:
parent
c488af138e
commit
631c817382
@ -18,12 +18,6 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.kske.spawnfly;
|
package dev.kske.spawnfly;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class SpawnFly extends JavaPlugin {
|
public final class SpawnFly extends JavaPlugin {
|
||||||
@ -7,6 +8,7 @@ public final class SpawnFly extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().info("onEnable has been invoked!");
|
getLogger().info("onEnable has been invoked!");
|
||||||
|
Bukkit.getPluginManager().registerEvents(new SpawnListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
54
src/main/java/dev/kske/spawnfly/SpawnListener.java
Normal file
54
src/main/java/dev/kske/spawnfly/SpawnListener.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package dev.kske.spawnfly;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.*;
|
||||||
|
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||||
|
import org.bukkit.event.player.*;
|
||||||
|
|
||||||
|
public class SpawnListener implements Listener {
|
||||||
|
|
||||||
|
Map<String, Boolean> activePlayers = new HashMap<>();
|
||||||
|
Map<String, Boolean> canceledEvents = new HashMap<>();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMove(PlayerMoveEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
Location location = player.getLocation();
|
||||||
|
if(isInSpawn(location)) activePlayers.put(player.getName(), true);
|
||||||
|
else if(activePlayers.get(player.getName()) && player.getVelocity().getY() < 0) {
|
||||||
|
player.setGliding(true);
|
||||||
|
canceledEvents.put(player.getName(), true);
|
||||||
|
activePlayers.put(player.getName(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
|
activePlayers.put(e.getPlayer().getName(), isInSpawn(e.getPlayer().getLocation()));
|
||||||
|
canceledEvents.put(e.getPlayer().getName(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
|
activePlayers.remove(e.getPlayer().getName());
|
||||||
|
canceledEvents.remove(e.getPlayer().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInSpawn(Location location) {
|
||||||
|
return (location.getX() <= -277 && location.getX() >= -302)
|
||||||
|
&& (location.getZ() <= -172 && location.getZ() >= -191);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void cancelEvent(EntityToggleGlideEvent e) {
|
||||||
|
if(canceledEvents.get(e.getEntity().getName()) && e.getEntity().getVelocity().getY() != 0 && !e.getEntity().isOnGround())
|
||||||
|
e.setCancelled(true);
|
||||||
|
else {
|
||||||
|
e.setCancelled(false);
|
||||||
|
canceledEvents.put(e.getEntity().getName(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user