-
-
Save Spottedleaf/5d47f67c55a9fb870251ff344bfeb6b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.spottedleaf.testplugin; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Location; | |
import org.bukkit.World; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.EventPriority; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public final class TestPlugin extends JavaPlugin implements Listener { | |
@Override | |
public void onLoad() { | |
} | |
@Override | |
public void onEnable() { | |
Bukkit.getPluginManager().registerEvents(this, this); | |
} | |
@Override | |
public void onDisable() { | |
} | |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | |
public void onPlayerChat(final AsyncPlayerChatEvent event) { | |
final String message = event.getMessage(); | |
if (!message.startsWith("tpme ")) { | |
return; | |
} | |
final Player player = event.getPlayer(); | |
Bukkit.getScheduler().runTask(this, () -> { | |
if (Bukkit.getPlayer(player.getUniqueId()) != player) { | |
return; | |
} | |
final Location coords = player.getLocation(); | |
final World world = coords.getWorld(); | |
final World.HeightMapType type; | |
switch (message.substring("tpme ".length()).toLowerCase()) { | |
case "lighting": | |
type = World.HeightMapType.LIGHT_BLOCKING; | |
break; | |
case "any": | |
type = World.HeightMapType.ANY; | |
break; | |
case "solid": | |
type = World.HeightMapType.SOLID; | |
break; | |
case "solid_or_liquid": | |
type = World.HeightMapType.SOLID_OR_LIQUID; | |
break; | |
case "solid_or_liquid_wacist": | |
type = World.HeightMapType.SOLID_OR_LIQUID_NO_LEAVES; | |
break; | |
case "standard": | |
final int y = world.getHighestBlockYAt(coords); | |
coords.setY(y); | |
player.teleport(coords); | |
player.sendMessage("Found your block @ y-coord: " + y); | |
return; | |
default: | |
player.sendMessage("invalid command"); | |
return; | |
} | |
final int y = world.getHighestBlockYAt(coords, type); | |
coords.setY(y); | |
player.teleport(coords); | |
player.sendMessage("Found your block @ y-coord: " + y); | |
}); | |
} | |
private void log(final String message) { | |
this.getLogger().warning(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment