Skip to content

Commit 71ac696

Browse files
committedJan 2, 2011
Initial sample plugin moved from Bukkit
0 parents  commit 71ac696

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed
 

‎.gitignore

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

‎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-sample-plugin</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<name>BukkitSamplePlugin</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,42 @@
1+
2+
package com.dinnerbone.bukkit.sample;
3+
4+
import org.bukkit.Block;
5+
import org.bukkit.BlockFace;
6+
import org.bukkit.Material;
7+
import org.bukkit.event.block.BlockCanBuildEvent;
8+
import org.bukkit.event.block.BlockListener;
9+
import org.bukkit.event.block.BlockPhysicsEvent;
10+
11+
/**
12+
* Sample block listener
13+
* @author Dinnerbone
14+
*/
15+
public class SampleBlockListener extends BlockListener {
16+
private final SamplePlugin plugin;
17+
18+
public SampleBlockListener(final SamplePlugin plugin) {
19+
this.plugin = plugin;
20+
}
21+
22+
@Override
23+
public void onBlockPhysics(BlockPhysicsEvent event) {
24+
Block block = event.getBlock();
25+
26+
if ((block.getType() == Material.Sand) || (block.getType() == Material.Gravel)) {
27+
Block above = block.getFace(BlockFace.Up);
28+
if (above.getType() == Material.IronBlock) {
29+
event.setCancelled(true);
30+
}
31+
}
32+
}
33+
34+
@Override
35+
public void onBlockCanBuild(BlockCanBuildEvent event) {
36+
Material mat = event.getMaterial();
37+
38+
if (mat.equals(Material.Cactus)) {
39+
event.setBuildable(true);
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
package com.dinnerbone.bukkit.sample;
3+
4+
import org.bukkit.Location;
5+
import org.bukkit.Player;
6+
import org.bukkit.event.player.PlayerChatEvent;
7+
import org.bukkit.event.player.PlayerEvent;
8+
import org.bukkit.event.player.PlayerListener;
9+
import org.bukkit.event.player.PlayerMoveEvent;
10+
11+
/**
12+
* Handle events for all Player related events
13+
* @author Dinnerbone
14+
*/
15+
public class SamplePlayerListener extends PlayerListener {
16+
private final SamplePlugin plugin;
17+
18+
public SamplePlayerListener(SamplePlugin instance) {
19+
plugin = instance;
20+
}
21+
22+
@Override
23+
public void onPlayerJoin(PlayerEvent event) {
24+
System.out.println(event.getPlayer().getName() + " joined the server! :D");
25+
}
26+
27+
@Override
28+
public void onPlayerQuit(PlayerEvent event) {
29+
System.out.println(event.getPlayer().getName() + " left the server! :'(");
30+
}
31+
32+
@Override
33+
public void onPlayerCommand(PlayerChatEvent event) {
34+
String[] split = event.getMessage().split(" ");
35+
Player player = event.getPlayer();
36+
37+
if (split[0].equalsIgnoreCase("/pos")) {
38+
if (split.length == 1) {
39+
Location location = player.getLocation();
40+
player.sendMessage("You are currently at " + location.getX() +"," + location.getY() + "," + location.getZ() +
41+
" with " + location.getYaw() + " yaw and " + location.getPitch() + " pitch");
42+
} else if (split.length == 4) {
43+
try {
44+
double x = Double.parseDouble(split[1]);
45+
double y = Double.parseDouble(split[2]);
46+
double z = Double.parseDouble(split[3]);
47+
48+
player.teleportTo(new Location(player.getWorld(), x, y, z));
49+
} catch (NumberFormatException ex) {
50+
player.sendMessage("Given location is invalid");
51+
}
52+
} else {
53+
player.sendMessage("Usage: '/pos' to get current position, or '/pos x y z' to teleport to x,y,z");
54+
}
55+
56+
event.setCancelled(true);
57+
} else if (split[0].equalsIgnoreCase("/debug")) {
58+
plugin.setDebugging(player, !plugin.isDebugging(player));
59+
60+
event.setCancelled(true);
61+
}
62+
}
63+
64+
@Override
65+
public void onPlayerMove(PlayerMoveEvent event) {
66+
if (plugin.isDebugging(event.getPlayer())) {
67+
Location from = event.getFrom();
68+
Location to = event.getTo();
69+
70+
System.out.println(String.format("From %.2f,%.2f,%.2f to %.2f,%.2f,%.2f", from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ()));
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
package com.dinnerbone.bukkit.sample;
3+
4+
import java.io.File;
5+
import java.util.HashMap;
6+
import org.bukkit.Player;
7+
import org.bukkit.Server;
8+
import org.bukkit.event.Event.Priority;
9+
import org.bukkit.event.Event;
10+
import org.bukkit.plugin.PluginDescriptionFile;
11+
import org.bukkit.plugin.PluginLoader;
12+
import org.bukkit.plugin.java.JavaPlugin;
13+
14+
/**
15+
* Sample plugin for Bukkit
16+
*
17+
* @author Dinnerbone
18+
*/
19+
public class SamplePlugin extends JavaPlugin {
20+
private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
21+
private final SampleBlockListener blockListener = new SampleBlockListener(this);
22+
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
23+
24+
public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
25+
super(pluginLoader, instance, desc, plugin, cLoader);
26+
27+
registerEvents();
28+
}
29+
30+
public void onDisable() {
31+
System.out.println("Goodbye world!");
32+
}
33+
34+
public void onEnable() {
35+
System.out.println("Hello world!");
36+
}
37+
38+
private void registerEvents() {
39+
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
40+
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
41+
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
42+
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
43+
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
44+
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this);
45+
}
46+
47+
public boolean isDebugging(final Player player) {
48+
if (debugees.containsKey(player)) {
49+
return debugees.get(player);
50+
} else {
51+
return false;
52+
}
53+
}
54+
55+
public void setDebugging(final Player player, final boolean value) {
56+
debugees.put(player, value);
57+
}
58+
}

‎src/main/resources/plugin.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: Sample Plugin
2+
main: com.dinnerbone.bukkit.sample.SamplePlugin

0 commit comments

Comments
 (0)
Please sign in to comment.