mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 18:24:43 +02:00
mcMMO -> All changes up to 0.6.2
vStopFire -> All changes up to 1.1 WoolPlus -> All changes up to 1.2 vPlayersOnline -> All changes up to 1.5
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
package com.gmail.nossr50.vPlayersOnline;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.ChatColor;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Handle events for all Player related events
|
||||
* @author nossr50
|
||||
*/
|
||||
public class vPlayerListener extends PlayerListener {
|
||||
private final vPlayersOnline plugin;
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
public vPlayerListener(vPlayersOnline instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
//Function to count the players
|
||||
public int playerCount(){
|
||||
Player players[] = plugin.getServer().getOnlinePlayers();
|
||||
int x = 0;
|
||||
for(Player hurrdurr: players){
|
||||
x++;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
//Message to be sent when a player joins
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
//English Version
|
||||
player.sendMessage(ChatColor.GREEN + "There are " + playerCount() + " players online.");
|
||||
}
|
||||
//Message to be sent when a player uses /list
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
Player player = event.getPlayer();
|
||||
if(split[0].equalsIgnoreCase("/list") || split[0].equalsIgnoreCase("/who")){
|
||||
event.setCancelled(true);
|
||||
String tempList = "";
|
||||
int x = 0;
|
||||
for(Player p : plugin.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p != null && x+1 >= playerCount()){
|
||||
tempList+= p.getName();
|
||||
x++;
|
||||
}
|
||||
if(p != null && x < playerCount()){
|
||||
tempList+= p.getName() +", ";
|
||||
x++;
|
||||
}
|
||||
}
|
||||
//Output the player list
|
||||
player.sendMessage(ChatColor.RED + "Player List"+ChatColor.WHITE+" ("+ChatColor.WHITE + tempList+")");
|
||||
player.sendMessage(ChatColor.RED + "Total Players: " + ChatColor.GREEN + playerCount());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.gmail.nossr50.vPlayersOnline;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* vPlayersOnline for Bukkit
|
||||
*
|
||||
* @author nossr50
|
||||
*/
|
||||
public class vPlayersOnline extends JavaPlugin {
|
||||
private final vPlayerListener playerListener = new vPlayerListener(this);
|
||||
private final String name = "vPlayersOnline";
|
||||
|
||||
public void onEnable() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||
//Displays a message when plugin is loaded
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
||||
}
|
||||
public void onDisable() {
|
||||
System.out.println("vPlayersOnline disabled.");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user