Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial work upgrading waypoints to bukkit API

  • Loading branch information...
commit 45100fd1c85766db676aed56d8797993b463b106 1 parent 59563f1
@duaiwe authored
View
BIN  lib/bukkit-0.0.1-SNAPSHOT.jar
Binary file not shown
View
BIN  lib/sqlitejdbc-v056.jar
Binary file not shown
View
6 nbproject/project.properties
@@ -27,10 +27,14 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.API.jar=lib/API.jar
+file.reference.bukkit-0.0.1-SNAPSHOT.jar=lib/bukkit-0.0.1-SNAPSHOT.jar
+file.reference.sqlitejdbc-v056.jar=lib/sqlitejdbc-v056.jar
includes=**
jar.compress=false
javac.classpath=\
- ${file.reference.API.jar}
+ ${file.reference.API.jar}:\
+ ${file.reference.bukkit-0.0.1-SNAPSHOT.jar}:\
+ ${file.reference.sqlitejdbc-v056.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
View
52 src/com/asylumsw/bukkit/waypoints/Home.java
@@ -0,0 +1,52 @@
+package com.asylumsw.bukkit.waypoints;
+
+import org.bukkit.Location;
+import org.bukkit.Player;
+import org.bukkit.World;
+
+/**
+ *
+ * @author jonathan
+ */
+public class Home {
+ private String name;
+ private int x;
+ private int y;
+ private int z;
+ private int pitch;
+ private int yaw;
+
+ public Home(String player, int x, int y, int z, int pitch, int yaw) {
+ this.name = player;
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.pitch = pitch;
+ this.yaw = yaw;
+ }
+
+ public Home(Player player) {
+ this.name = player.getName();
+ this.x = player.getLocation().getBlockX();
+ this.y = player.getLocation().getBlockY();
+ this.z = player.getLocation().getBlockZ();
+ this.pitch = (int)player.getLocation().getPitch();
+ this.yaw = (int)player.getLocation().getYaw();
+ }
+
+ public Home(String player, Location loc) {
+ this.name = player;
+ this.x = loc.getBlockX();
+ this.y = loc.getBlockY();
+ this.z = loc.getBlockZ();
+ this.pitch = (int)loc.getPitch();
+ this.yaw = (int)loc.getYaw();
+ }
+
+ public void warp(Player player) {
+ World world = player.getWorld();
+ Location loc = new Location(world, x, y, z, yaw, pitch);
+ player.teleportTo(loc);
+ }
+
+}
View
254 src/com/asylumsw/bukkit/waypoints/HomeData.java
@@ -0,0 +1,254 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.asylumsw.bukkit.waypoints;
+
+import java.sql.Statement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.bukkit.Arrow;
+import org.bukkit.Block;
+import org.bukkit.Boat;
+import org.bukkit.Chunk;
+import org.bukkit.ItemDrop;
+import org.bukkit.ItemStack;
+import org.bukkit.Location;
+import org.bukkit.Minecart;
+import org.bukkit.PoweredMinecart;
+import org.bukkit.StorageMinecart;
+import org.bukkit.Vector;
+import org.bukkit.World;
+
+/**
+ *
+ * @author jonathan
+ */
+public class HomeData {
+
+ public final static String HOME_TABLE = "CREATE TABLE `homeList` ("
+ + "`id` INTEGER PRIMARY KEY,"
+ + "`player` varchar(255) NOT NULL UNIQUE,"
+ + "x int NOT NULL, y int NOT NULL, z int NOT NULL"
+ + "pitch smallint NOT NULL DEFAULT '0',"
+ + "yaw smallint NOT NULL DEFAULT '0'";
+
+ public static void initTable() {
+ if (!tableExists()) {
+ createTable();
+ }
+ }
+
+ public static HashMap<String, Location> getHomes() {
+ HashMap<String, Location> homeList = new HashMap<String, Location>();
+ Connection conn = null;
+ Statement statement = null;
+ ResultSet set = null;
+ Logger log = Logger.getLogger("Minecraft");
+
+ try {
+ Class.forName("org.sqlite.JDBC");
+ conn = DriverManager.getConnection(Waypoints.DATABASE);
+
+ statement = conn.createStatement();
+ set = statement.executeQuery("SELECT player,x,y,z,pitch,yaw FROM homeList");
+ int size = 0;
+ Location thisLoc = null;
+
+ while (set.next()) {
+ thisLoc = new Location(null, set.getInt("x"), set.getInt("y"), set.getInt("z"), set.getInt("yaw"), set.getInt("pitch"));
+
+ size++;
+ int index = set.getInt("id");
+ String name = set.getString("name");
+ String creator = set.getString("creator");
+ int world = set.getInt("world");
+ int x = set.getInt("x");
+ int y = set.getInt("y");
+ int z = set.getInt("z");
+ int yaw = set.getInt("yaw");
+ int pitch = set.getInt("pitch");
+ boolean publicAll = set.getBoolean("publicAll");
+ String permissions = set.getString("permissions");
+ String welcomeMessage = set.getString("welcomeMessage");
+ Warp warp = new Warp(index, name, creator, world, x, y, z, yaw, pitch, publicAll, permissions, welcomeMessage);
+ ret.put(name, warp);
+ }
+ log.info("[MYWARP]: " + size + " warps loaded");
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[MYWARP]: Warp Load Exception");
+ }
+ catch (ClassNotFoundException e) {
+ log.log(Level.SEVERE, "[MYWARP]: Error loading org.sqlite.JDBC");
+ }
+ finally {
+ try {
+ if (statement != null) {
+ statement.close();
+ }
+ if (set != null) {
+ set.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[MYWARP]: Warp Load Exception (on close)");
+ }
+ }
+ return homeList;
+ }
+
+ private static boolean tableExists() {
+ Connection conn = null;
+ ResultSet rs = null;
+
+ try {
+ Class.forName("org.sqlite.JDBC");
+ conn = DriverManager.getConnection(Waypoints.DATABASE);
+ DatabaseMetaData dbm = conn.getMetaData();
+ rs = dbm.getTables(null, null, "homeList", null);
+ return (!rs.next() ? false : true);
+ }
+ catch (SQLException ex) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS:HOMES]: Table Check Exception");
+ return false;
+ }
+ catch (ClassNotFoundException ex2) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS]: Table Check Exception");
+ return false;
+ }
+ finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ catch (SQLException ex) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS]: Table Check Exception (on closing)");
+ }
+ }
+ }
+
+ private static void createTable() {
+ Connection conn = null;
+ Statement st = null;
+ try {
+ Class.forName("org.sqlite.JDBC");
+ conn = DriverManager.getConnection(Waypoints.DATABASE);
+ st = conn.createStatement();
+ st.executeUpdate(HOME_TABLE);
+ }
+ catch (SQLException e) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS:HOMES]: Create Table Exception", e);
+ }
+ catch (ClassNotFoundException e) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS]: Error loading org.sqlite.JDBC");
+ }
+ finally {
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ if (st != null) {
+ st.close();
+ }
+ }
+ catch (SQLException e) {
+ Logger log = Logger.getLogger("Minecraft");
+ log.log(Level.SEVERE, "[WAYPOINTS]: Could not create the table (on close)");
+ }
+ }
+ }
+
+ public static void addHome(String playerName, Location loc) {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ Logger log = Logger.getLogger("Minecraft");
+ try {
+ Class.forName("org.sqlite.JDBC");
+ conn = DriverManager.getConnection(Waypoints.DATABASE);
+ ps = conn.prepareStatement("INSERT INTO homeList (player, x, y, z, pitch, yaw) "
+ + "VALUES (?,?,?,?,?,?)");
+ ps.setString(1, playerName);
+ ps.setInt(2, loc.getBlockX());
+ ps.setInt(3, loc.getBlockY());
+ ps.setInt(4, loc.getBlockZ());
+ ps.setInt(5, (int) loc.getPitch());
+ ps.setInt(6, (int) loc.getYaw());
+
+ ps.executeUpdate();
+
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[WAYPOINTS:HOME]: Warp Insert Exception", ex);
+ }
+ catch (ClassNotFoundException ex2) {
+ log.log(Level.SEVERE, "[WAYPOINTS]: Error loading org.sqlite.JDBC");
+ }
+ finally {
+ try {
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[WAYPOINTS]: Warp Insert Exception (on close)", ex);
+ }
+ }
+ }
+
+ public static void deleteHome(String playerName) {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ Logger log = Logger.getLogger("Minecraft");
+ try {
+ Class.forName("org.sqlite.JDBC");
+ conn = DriverManager.getConnection(Waypoints.DATABASE);
+ ps = conn.prepareStatement("DELETE FROM homeList WHERE player = ?");
+ ps.setString(1, playerName);
+ ps.executeUpdate();
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[WAYPOINTS:HOME]: Warp Insert Exception", ex);
+ }
+ catch (ClassNotFoundException ex2) {
+ log.log(Level.SEVERE, "[WAYPOINTS]: Error loading org.sqlite.JDBC");
+ }
+ finally {
+ try {
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ catch (SQLException ex) {
+ log.log(Level.SEVERE, "[WAYPOINTS]: Warp Insert Exception (on close)", ex);
+ }
+ }
+
+ }
+}
View
120 src/com/asylumsw/bukkit/waypoints/Structure.java
@@ -0,0 +1,120 @@
+package com.asylumsw.bukkit.waypoints;
+
+import org.bukkit.Block;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+
+/**
+ *
+ * @author jonathan
+ */
+public class Structure {
+ private static int getX(Location loc) {
+ return loc.getBlockZ();
+ }
+ private static int getY(Location loc) {
+ return loc.getBlockX();
+ }
+ private static int getZ(Location loc) {
+ return loc.getBlockY()-1;
+ }
+ public static Material nonEvalBlock = Material.BEDROCK;
+
+ public interface Actor {
+ public boolean doBlockAction(Material structureBlockMaterial,
+ Block worldBlock, boolean debug);
+ public boolean doBlockAction(Material structureBlockMaterial,
+ Block worldBlock);
+
+ }
+
+ public static class Validator implements Actor {
+ public int invalidBlockCount;
+ public Validator() {
+ invalidBlockCount = 0;
+ }
+ public boolean doBlockAction(Material structureBlockType,
+ Block worldBlock, boolean debug) {
+ if( worldBlock.getType() != structureBlockType &&
+ structureBlockType != Structure.nonEvalBlock ) {
+ if( debug ) {
+ Server.log(String.format("Invalid Home Block: Found %s, Expecting %s.",
+ worldBlock.getBlockType().getName(), structureBlockType.getName())
+ );
+ }
+ invalidBlockCount += 1;
+ return false;
+ }
+ return true;
+ }
+ public boolean doBlockAction(Material structureBlockType, Block worldBlock) {
+ return this.doBlockAction(structureBlockType, worldBlock, false);
+ }
+ }
+
+ /**
+ * NOTE:
+ * Altitude -> Y
+ * Latitude -> X
+ * Longitude -> Z
+ *
+ *
+ * @param pattern
+ * @param startPosition
+ * @param playerLocation
+ * @return
+ */
+ public static void parse(Material[][][] pattern,
+ int[] startPosition,
+ Location loc, Actor callBack, boolean debug) {
+ int thisZ, thisX, thisY;
+ Location thisLocation = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
+
+ Waypoints.loadChunkAtLocation(thisLocation);
+
+ /**
+ * This ugly loop iterates over every value of the pattern.
+ * We'll use the startPosition to calculate it's relative location from the
+ * player's location. We grab the block at that location, and compare it to
+ * the block we're expecting in the pattern, if it's false, we return out
+ * early, otherwise we keep looping.
+ *
+ * If we make it through the loop, we've got a valid pattern.
+ *
+ * There probably is a WAY smarter way to do this, I'm just too dumb to
+ * figure it out.
+ */
+ for( int z = 0; z < pattern.length; z++ ){
+ for( int y = 0; y < pattern[z].length; y++ ) {
+ for( int x = 0; x < pattern[z][y].length; x++ ) {
+ thisZ = Structure.getZ(loc)+(z-startPosition[0]);
+ thisY = Structure.getY(loc)+(y-startPosition[1]);
+ thisX = Structure.getX(loc)+(x-startPosition[2]);
+ thisLocation.setX(thisY);
+ thisLocation.setY(thisZ);
+ thisLocation.setZ(thisX);
+
+ thisLocation.getWorld().getChunkAt(
+ thisLocation.getWorld().getBlockAt(thisLocation.getBlockX(),
+ thisLocation.getBlockY(), thisLocation.getBlockZ()));
+ //World.loadChunk(thisLocation);
+ boolean continueLoop = (null == callBack) ? true :
+ callBack.doBlockAction(pattern[z][y][x],
+ thisLocation.getWorld().getBlockAt(thisLocation.getBlockX(), thisLocation.getBlockY(), thisLocation.getBlockZ()),
+ debug);
+
+ if( !continueLoop ) return;
+ }
+ }
+ }
+ }
+
+ public static void parse(Material[][][] pattern,
+ int[] startPosition,
+ Location playerLocation, Actor callBack) {
+ Structure.parse(pattern, startPosition, playerLocation, callBack, false);
+ }
+
+
+}
View
48 src/com/asylumsw/bukkit/waypoints/WaypointPlayerListener.java
@@ -0,0 +1,48 @@
+package com.asylumsw.bukkit.waypoints;
+
+import org.bukkit.event.player.PlayerListener;
+import org.bukkit.Player;
+import org.bukkit.Location;
+import org.bukkit.event.player.PlayerChatEvent;
+import org.bukkit.ChatColor;
+
+/**
+ *
+ * @author jonathan
+ */
+public class WaypointPlayerListener extends PlayerListener {
+ private final Waypoints plugin;
+
+ public WaypointPlayerListener(Waypoints instance) {
+ plugin = instance;
+ }
+
+ /**
+ * home
+ * gateto <gate>
+ * gates
+ * track <mark>
+ * marks
+ * setmark
+ * sethome
+ * unsethome
+ * setgate
+ * @param event
+ */
+ @Override
+ public void onPlayerCommand(PlayerChatEvent event) {
+ String[] split = event.getMessage().split(" ");
+ String command = split[0];
+ Player player = event.getPlayer();
+
+ if( command.equalsIgnoreCase("/home")) {
+ event.setCancelled(true);
+ }
+ else if( command.equalsIgnoreCase("/sethome") ) {
+ event.setCancelled(true);
+ }
+
+ }
+
+
+}
View
25 src/com/asylumsw/bukkit/waypoints/Waypoints.java
@@ -0,0 +1,25 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.asylumsw.bukkit.waypoints;
+
+import java.io.File;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.PluginLoader;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.Server;
+import org.bukkit.event.Event.Priority;
+import org.bukkit.event.Event;
+
+/**
+ *
+ * @author jonathan
+ */
+public class Waypoints extends JavaPlugin {
+ public final static String DATABASE = "jdbc:sqlite:waypoints.db";
+
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.