mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Added sendMessage() to player, added /pos to sample plugin
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
54e61aab10
commit
9e1f814646
3 changed files with 39 additions and 0 deletions
|
@ -1,6 +1,9 @@
|
||||||
|
|
||||||
package com.dinnerbone.bukkit.sample;
|
package com.dinnerbone.bukkit.sample;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Player;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
|
|
||||||
|
@ -24,4 +27,32 @@ public class SamplePlayerListener extends PlayerListener {
|
||||||
public void onPlayerQuit(PlayerEvent event) {
|
public void onPlayerQuit(PlayerEvent event) {
|
||||||
System.out.println(event.getPlayer().getName() + " left the server! :'(");
|
System.out.println(event.getPlayer().getName() + " left the server! :'(");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerCommand(PlayerChatEvent event) {
|
||||||
|
String[] split = event.getMessage().split(" ");
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (split[0].equalsIgnoreCase("/pos")) {
|
||||||
|
if (split.length == 1) {
|
||||||
|
Location location = player.getLocation();
|
||||||
|
player.sendMessage("You are currently at " + location.getX() +"," + location.getY() + "," + location.getZ() +
|
||||||
|
" with " + location.getYaw() + " yaw and " + location.getPitch() + " pitch");
|
||||||
|
} else if (split.length == 4) {
|
||||||
|
try {
|
||||||
|
double x = Double.parseDouble(split[1]);
|
||||||
|
double y = Double.parseDouble(split[2]);
|
||||||
|
double z = Double.parseDouble(split[3]);
|
||||||
|
|
||||||
|
player.teleportTo(new Location(player.getWorld(), x, y, z));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
player.sendMessage("Given location is invalid");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage("Usage: '/pos' to get current position, or '/pos x y z' to teleport to x,y,z");
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,5 +36,6 @@ public class SamplePlugin extends JavaPlugin {
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||||
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,11 @@ public interface Player extends HumanEntity {
|
||||||
* @return true if they are online
|
* @return true if they are online
|
||||||
*/
|
*/
|
||||||
public boolean isOnline();
|
public boolean isOnline();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends this player a message, which will be displayed in their chat
|
||||||
|
*
|
||||||
|
* @param message Message to be displayed
|
||||||
|
*/
|
||||||
|
public void sendMessage(String message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue