mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Typing /list or /who will show an improved playerlist
This commit is contained in:
parent
637868a12b
commit
30f144b21b
@ -1,7 +1,6 @@
|
|||||||
package com.bukkit.nossr50.vPlayersOnline;
|
package com.bukkit.nossr50.vPlayersOnline;
|
||||||
|
|
||||||
import org.bukkit.Block;
|
|
||||||
import org.bukkit.BlockFace;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.bukkit.nossr50.vPlayersOnline;
|
package com.bukkit.nossr50.vPlayersOnline;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.Player;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
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;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle events for all Player related events
|
* Handle events for all Player related events
|
||||||
@ -14,18 +14,42 @@ import org.bukkit.ChatColor;
|
|||||||
*/
|
*/
|
||||||
public class vPlayerListener extends PlayerListener {
|
public class vPlayerListener extends PlayerListener {
|
||||||
private final vPlayersOnline plugin;
|
private final vPlayersOnline plugin;
|
||||||
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
public vPlayerListener(vPlayersOnline instance) {
|
public vPlayerListener(vPlayersOnline instance) {
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
}
|
}
|
||||||
|
//Function to count the players
|
||||||
public void onPlayerJoin(PlayerEvent event) {
|
public int playerCount(){
|
||||||
Player player = event.getPlayer();
|
|
||||||
Player players[] = plugin.getServer().getOnlinePlayers();
|
Player players[] = plugin.getServer().getOnlinePlayers();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for(Player hurrdurr: players){
|
for(Player hurrdurr: players){
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
player.sendMessage(ChatColor.GREEN + "There are " + x + " players online");
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Message to be sent when a player joins
|
||||||
|
public void onPlayerJoin(PlayerEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
player.sendMessage(ChatColor.GREEN + "There are " + playerCount() + " players online");
|
||||||
|
}
|
||||||
|
//Message to be sent when a player uses /list
|
||||||
|
public void onPlayerCommand(PlayerChatEvent event) {
|
||||||
|
log.log(Level.INFO, event.getMessage() + "|" + event.getPlayer().getName());
|
||||||
|
String[] split = event.getMessage().split(" ");
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if(split[0].equalsIgnoreCase("/list") || split[0].equalsIgnoreCase("/who")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
String tempList = "";
|
||||||
|
for(Player p : plugin.getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if(p != null){
|
||||||
|
tempList+= p.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Output the player list
|
||||||
|
player.sendMessage(ChatColor.RED + "Player List (" + tempList +")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package com.bukkit.nossr50.vPlayersOnline;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.bukkit.Player;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -10,6 +10,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||||||
import org.bukkit.plugin.PluginLoader;
|
import org.bukkit.plugin.PluginLoader;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vPlayersOnline for Bukkit
|
* vPlayersOnline for Bukkit
|
||||||
@ -30,25 +31,13 @@ public class vPlayersOnline extends JavaPlugin {
|
|||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||||
//Displays a message when plugin is loaded
|
//Displays a message when plugin is loaded
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
PluginDescriptionFile pdfFile = this.getDescription();
|
||||||
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
||||||
}
|
}
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
System.out.println("vPlayersOnline disabled.");
|
System.out.println("vPlayersOnline disabled.");
|
||||||
}
|
}
|
||||||
public boolean isDebugging(final Player player) {
|
|
||||||
if (debugees.containsKey(player)) {
|
|
||||||
return debugees.get(player);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDebugging(final Player player, final boolean value) {
|
|
||||||
debugees.put(player, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user