Skip to content

Commit 25a609b

Browse files
committed
Initial commit
0 parents  commit 25a609b

File tree

8 files changed

+302
-0
lines changed

8 files changed

+302
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Eclipse stuff
2+
/.classpath
3+
/.project
4+
/.settings
5+
6+
# netbeans
7+
/nbproject
8+
9+
# maven
10+
/target
11+
12+
# ant
13+
/bin
14+
/dist
15+
16+
# vim
17+
.*.sw[a-p]

build.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<project name="BukkitSamplePlugin" default="dist" basedir=".">
2+
<property name="pluginname" value="BukkitSamplePlugin"/>
3+
<property name="bukkit.jar" location="../Bukkit/dist/Bukkit.jar"/>
4+
<property name="plugins" location="../../plugins/"/>
5+
6+
<property name="src" location="src"/>
7+
<property name="bin" location="bin"/>
8+
<property name="dist" location="dist"/>
9+
10+
<target name="init">
11+
<mkdir dir="${bin}"/>
12+
</target>
13+
14+
<target name="compile" depends="init">
15+
<javac srcdir="${src}/main/java" destdir="${bin}" includeantruntime="false">
16+
<classpath>
17+
<pathelement location="${bukkit.jar}"/>
18+
</classpath>
19+
</javac>
20+
</target>
21+
22+
<target name="dist" depends="compile">
23+
<mkdir dir="${dist}"/>
24+
<jar jarfile="${dist}/${pluginname}.jar">
25+
<fileset dir="${bin}"/>
26+
<fileset file="${src}/main/resources/plugin.yml"/>
27+
</jar>
28+
</target>
29+
30+
<target name="deploy" depends="dist">
31+
<copy file="${dist}/${pluginname}.jar" todir="${plugins}"/>
32+
</target>
33+
34+
<target name="clean">
35+
<delete dir="${bin}"/>
36+
<delete dir="${dist}"/>
37+
</target>
38+
</project>

pom.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.bukkit</groupId>
4+
<artifactId>bukkit-chat</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<name>ChatBukkit</name>
7+
<url>http://www.bukkit.org</url>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>org.apache.maven.plugins</groupId>
12+
<artifactId>maven-compiler-plugin</artifactId>
13+
<version>2.0.2</version>
14+
<configuration>
15+
<source>1.5</source>
16+
<target>1.5</target>
17+
</configuration>
18+
</plugin>
19+
</plugins>
20+
</build>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.bukkit</groupId>
24+
<artifactId>bukkit</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<type>jar</type>
27+
<scope>compile</scope>
28+
</dependency>
29+
</dependencies>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
package com.dinnerbone.bukkit.chat;
3+
4+
import com.dinnerbone.bukkit.chat.commands.WhoisCommand;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandSender;
9+
import org.bukkit.plugin.PluginDescriptionFile;
10+
import org.bukkit.plugin.java.JavaPlugin;
11+
12+
/**
13+
* Basic chat functionality
14+
*
15+
* @author Dinnerbone
16+
*/
17+
public class ChatBukkit extends JavaPlugin {
18+
private Map<String, CommandHandler> commands = new HashMap<String, CommandHandler>();
19+
20+
public void onDisable() {}
21+
22+
public void onEnable() {
23+
PluginDescriptionFile pdfFile = this.getDescription();
24+
System.out.println( pdfFile.getFullName() + " is enabled!" );
25+
26+
commands.put("whois", new WhoisCommand(this));
27+
}
28+
29+
@Override
30+
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
31+
CommandHandler handler = commands.get(command.getName().toLowerCase());
32+
33+
if (handler != null) {
34+
return handler.perform(sender, args);
35+
} else {
36+
return false;
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.dinnerbone.bukkit.chat;
2+
3+
import java.util.List;
4+
import org.bukkit.command.CommandSender;
5+
import org.bukkit.entity.Player;
6+
7+
public abstract class CommandHandler {
8+
protected final ChatBukkit plugin;
9+
10+
public CommandHandler(ChatBukkit plugin) {
11+
this.plugin = plugin;
12+
}
13+
14+
public abstract boolean perform(CommandSender sender, String[] args);
15+
16+
protected static boolean anonymousCheck(CommandSender sender) {
17+
if (!(sender instanceof Player)) {
18+
sender.sendMessage("Cannot execute that command, I don't know who you are!");
19+
return true;
20+
} else {
21+
return false;
22+
}
23+
}
24+
25+
protected static Player getPlayer(CommandSender sender, String[] args, int index) {
26+
if (args.length >= index) {
27+
List<Player> players = sender.getServer().matchPlayer(args[index]);
28+
29+
if (players.isEmpty()) {
30+
sender.sendMessage("I don't know who '" + args[index] + "' is!");
31+
return null;
32+
} else {
33+
return players.get(0);
34+
}
35+
} else {
36+
if (anonymousCheck(sender)) {
37+
return null;
38+
} else {
39+
return (Player)sender;
40+
}
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.dinnerbone.bukkit.chat.commands;
2+
3+
import com.dinnerbone.bukkit.chat.ChatBukkit;
4+
import com.dinnerbone.bukkit.chat.CommandHandler;
5+
import com.dinnerbone.bukkit.chat.events.WhoisRequestEvent;
6+
import java.util.Set;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.command.CommandSender;
9+
import org.bukkit.entity.Player;
10+
11+
public class WhoisCommand extends CommandHandler {
12+
public WhoisCommand(ChatBukkit plugin) {
13+
super(plugin);
14+
}
15+
16+
@Override
17+
public boolean perform(CommandSender sender, String[] args) {
18+
if (args.length > 1) {
19+
return false;
20+
}
21+
22+
Player player = getPlayer(sender, args, 0);
23+
24+
if (player != null) {
25+
WhoisRequestEvent report = new WhoisRequestEvent(sender, player);
26+
27+
report.setField("Display Name", player.getDisplayName());
28+
report.setField("World", player.getWorld().getName());
29+
30+
if (!ChatColor.stripColor(player.getDisplayName()).equalsIgnoreCase(player.getName())) {
31+
report.setField("Username", player.getName());
32+
}
33+
34+
player.getServer().getPluginManager().callEvent(report);
35+
36+
sender.sendMessage("------ WHOIS report ------");
37+
Set<String> keys = report.getFields().keySet();
38+
for (String key : keys) {
39+
sender.sendMessage(key + ": " + report.getField(key));
40+
}
41+
} else {
42+
return true;
43+
}
44+
45+
return false;
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.dinnerbone.bukkit.chat.events;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
import org.bukkit.event.Event;
8+
9+
/**
10+
* Thrown when someone requests a WHOIS on a player
11+
*/
12+
public class WhoisRequestEvent extends Event {
13+
private final CommandSender sender;
14+
private final Player player;
15+
private final Map<String, String> result = new HashMap<String, String>();
16+
17+
public WhoisRequestEvent(CommandSender sender, Player player) {
18+
super("WHOIS_REQUEST");
19+
this.sender = sender;
20+
this.player = player;
21+
}
22+
23+
/**
24+
* Gets the target player to display details about
25+
*
26+
* @return Player target of this event
27+
*/
28+
public Player getPlayer() {
29+
return player;
30+
}
31+
32+
/**
33+
* Gets the {@link CommandSender} who requested the WHOIS report
34+
*
35+
* @return The origin of this request
36+
*/
37+
public CommandSender getSender() {
38+
return sender;
39+
}
40+
41+
/**
42+
* Sets the specified field of this report to the given value.
43+
* Use null if you wish to remove that field.
44+
*
45+
* @param field Name of the field to set
46+
* @param value New value of the field (or null to remove)
47+
*/
48+
public void setField(String field, String value) {
49+
if (value == null) {
50+
result.remove(field);
51+
} else {
52+
result.put(field, value);
53+
}
54+
}
55+
56+
/**
57+
* Gets a field which is already collected by this report.
58+
*
59+
* @param field Name of the field to retrieve
60+
* @return Value contained in that field, or null if none exist
61+
*/
62+
public String getField(String field) {
63+
return result.get(field);
64+
}
65+
66+
/**
67+
* Returns all fields collected by this report so far
68+
*
69+
* @return Map<Name, Value> of all collected fields
70+
*/
71+
public Map<String, String> getFields() {
72+
return result;
73+
}
74+
}

src/main/resources/plugin.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: ChatBukkit
2+
main: com.dinnerbone.bukkit.chat.ChatBukkit
3+
version: 0.0.1
4+
website: http://www.bukkit.org
5+
author: The Bukkit Team
6+
description: >
7+
Basic chat functionality.
8+
This plugin is one of the default plugins shipped with Bukkit.
9+
commands:
10+
clear:
11+
description: Sends the target player a message
12+
usage: |
13+
/<command> <player> <message>
14+
Example: /<command> Walrus I found your bukkit!

0 commit comments

Comments
 (0)