Commits

zzzeek  committed 4bbf0c3

here we go !

  • Participants
  • Parent commits 89d50d5

Comments (0)

Files changed (9)

   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
+  <build>
+    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+    <resources>
+      <resource>
+        <targetPath>.</targetPath>
+        <filtering>true</filtering>
+        <directory>${basedir}/src/main/resources/</directory>
+        <includes>
+          <include>plugin.yml</include>
+        </includes>
+      </resource>
+      <resource>
+        <targetPath>defaults/</targetPath>
+        <filtering>true</filtering>
+        <directory>${basedir}/src/main/resources/</directory>
+        <includes>
+          <include>config.yml</include>
+        </includes>
+      </resource>
+    </resources>      
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <descriptors>
+            <descriptor>src/main/assembly/package.xml</descriptor>
+          </descriptors>
+        </configuration>  			
+        <executions>
+            <execution>
+                <id>build</id>
+                <phase>package</phase>
+                <goals>
+                    <goal>single</goal>
+                </goals>
+            </execution>
+        </executions>		
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+          <encoding>UTF-8</encoding>
+        </configuration>			
+      </plugin>
+  </plugins>
+    <finalName>${project.name}</finalName>
+  </build>
 
   <dependencies>
   	<dependency>

File src/main/assembly/package.xml

+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>bin</id>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <formats>
+        <format>tar.bz2</format>
+        <format>zip</format>
+    </formats>
+    <fileSets>
+        <fileSet>
+            <directory>${project.basedir}</directory>
+            <outputDirectory>/</outputDirectory>
+            <includes>
+                <include>README*</include>
+                <include>LICENSE*</include>
+                <include>NOTICE*</include>
+                <include>CHANGELOG*</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>${project.basedir}/src/main/resources/</directory>
+            <outputDirectory>/ZeekTools/</outputDirectory>
+            <includes>
+                <include>config.yml</include>
+            </includes>
+        </fileSet>
+    </fileSets>		
+    <files>
+        <file>
+            <source>${project.build.directory}/${artifactId}.jar</source>
+            <outputDirectory>/</outputDirectory>
+            <destName>ZeekTools.jar</destName>
+        </file>
+    </files>
+</assembly>

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/Bootstrap.java

+package com.zzzcomputing.bukkit.ZeekTools;
+
+import java.io.File;
+
+import com.zzzcomputing.bukkit.ZeekTools.util.Database;
+import com.zzzcomputing.bukkit.ZeekTools.util.Logger;
+
+public class Bootstrap {
+    static final String PATH = "plugins" + File.separator + "ZeekTools" + File.separator;
+    
+    static void setupEnvironment() throws Exception {
+        File path = new File(PATH);
+        path.mkdirs();
+        createDB();
+    }
+    
+    static void createDB() {
+        Database.init(PATH + "zeektools.db");
+        if (Database.isNew()) {
+            Database.Handle handle = Database.getHandle();
+            try {
+                handle.execStatement("CREATE TABLE waypoints (" +
+                        "id INTEGER PRIMARY KEY, " +
+                        "player_name VARCHAR, " +
+                        "waypoint_name VARCHAR, "+
+                        "world_uid VARCHAR," +
+                        "x FLOAT, " +
+                        "y FLOAT, " +
+                        "z FLOAT)"
+                      );
+            }
+            finally {
+                handle.close();
+            }
+            Logger.info(String.format("Created new database file %s", Database.getPath()));
+        }
+    }
+    
+}

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/ZeekTools.java

         // TODO Auto-generated method stub
         
     }
-
+    
+    @Override
     public void onEnable() {
         Logger.info("ZeekTools online hooray !");
+        try {
+            Bootstrap.setupEnvironment();
+        } catch (Exception e) {
+            Logger.severe("Environment setup failed", e);
+        }
     }
 
 }

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/util/Database.java

+package com.zzzcomputing.bukkit.ZeekTools.util;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class Database {
+    private static String path;
+    private static boolean dbExists;
+    
+    public static void init(String path) throws DatabaseException {
+        try {
+            Class.forName("org.sqlite.JDBC");
+            Database.path = path;
+            File dbFile = new File(path);
+            dbExists = dbFile.exists();
+            getHandle().close();
+        }
+        catch (ClassNotFoundException cnfe) {
+            throw new DatabaseException("Exception occurred initializing database", cnfe);
+        }
+    }
+    
+    public static String getPath() {
+        return path;
+    }
+    public static boolean isNew() {
+        return !dbExists;
+    }
+    public static class Handle {
+        Connection connection;
+        Handle() throws DatabaseException {
+            try {
+                connection = DriverManager.getConnection("jdbc:sqlite:" + path); 
+            }
+            catch (SQLException sqle) {
+                throw new DatabaseException("Exception occurred connecting to database", sqle);
+            }
+        }
+        public boolean execStatement(String statement) throws DatabaseException {
+            try {
+                Statement sql = connection.createStatement();
+                boolean result = sql.execute(statement);
+                return result;
+            }
+            catch (SQLException sqle) {
+                throw new DatabaseException("Exception occurred executing statement", sqle);
+            }
+        }
+        public void close() throws DatabaseException {
+            try {
+                connection.close();
+            }
+            catch (SQLException sqle) {
+                throw new DatabaseException("Exception occurred disconnecting from database", sqle);
+            }
+        }
+    }
+    public static class DatabaseException extends RuntimeException {
+        DatabaseException(String message) {
+            super(message);
+        }
+        DatabaseException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+    
+    public static Handle getHandle() throws DatabaseException {
+        return new Handle();
+    }
+    
+}

File src/main/resources/config.yml

Empty file added.

File src/main/resources/plugin.yml

+name: ZeekTools
+main: com.zzzcomputing.bukkit.ZeekTools.ZeekTools
+version: 0.0.1
+website: www.bukkit.org
+description: Provides some SPC-like features to Bukkit.
+author: zzzeek
+commands:
+    zt:
+        description: ZeekTools commands
+        usage: |
+            /<command> give <name_or_id> [num] [player] - Give item.
+            /<command> goto <x> <y> <z> - goto coordinates
+            /<command> goto <waypoint> - goto saved waypoint
+            /<command> goto spawn - goto spawn point/bed
+            /<command> list waypoints - list waypoints
+            /<command> set <waypoint> - set waypoint
+            /<command> del <waypoint> - delete waypoint
+ 

File src/resources/config.yml

Empty file removed.

File src/resources/plugin.yml

-name: ZeekTools
-main: com.zzzcomputing.bukkit.ZeekTools.ZeekTools
-version: 0.0.1
-website: www.bukkit.org
-description: Provides some SPC-like features to Bukkit.
-author: zzzeek
-commands:
-    zt:
-        description: ZeekTools commands
-        usage: |
-            /<command> give <name_or_id> [num] [player] - Give item.
-            /<command> goto <x> <y> <z> - goto coordinates
-            /<command> goto <waypoint> - goto saved waypoint
-            /<command> goto spawn - goto spawn point/bed
-            /<command> list waypoints - list waypoints
-            /<command> set <waypoint> - set waypoint
-            /<command> del <waypoint> - delete waypoint
-