Skip to content

Instantly share code, notes, and snippets.

@Spottedleaf
Created December 2, 2018 04:08
Show Gist options
  • Save Spottedleaf/5d47f67c55a9fb870251ff344bfeb6b3 to your computer and use it in GitHub Desktop.
Save Spottedleaf/5d47f67c55a9fb870251ff344bfeb6b3 to your computer and use it in GitHub Desktop.
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