Permalink
Browse files

Full changelog from the sample plugin to the pickup plugin

  • Loading branch information...
DonnEssime committed Jun 15, 2016
1 parent b833b81 commit b5ecec55005ee5128eb9e7bf4cfb8647bdb640e5
View
@@ -0,0 +1,24 @@
Setting up the project
1. clone the sample repo
2. load the project in netbeans (suggested) or your favorite IDE. I will assume Netbeans in subsequent steps, but note where this made a difference.
[Netbeans-specific] Resolve an issue: the plug-in needs to point at lsalem.jar in netbeans settings for the auto-suggest to work.
Making the application aware of your plug-in
3. Refactor the SamplePlugin to whatever you want your plug-in to be called.
4. Edit manifest/META-INF.services/haven.plugins.Plugin to contain the name of your plugin class.
Giving your plug-in a resource file for the menu
5. Rename ./resources/src/paginae/add/hello.res to whatever you want to resource file to be called.
6. Open ./resources/src/paginae/add/<name>.res/action/action_0.data and change the following fields:
6a) name (the tooltip when hovering over your plugin button)
6b) hk (the ASCII code for your hotkey. don't bother with it if you're not going to use hotkeys)
6c) ad[1] (this is the characteristic String the client will receive when the action button is clicked)
7. Edit in a nice icon to ./resources/src/paginae/add/<name>.res/image/image_0.data. Stick to a 40x40 image to be safe
8. Run the compile_resources.bat script (for windows - linux users should be able to figure out how to run the single line it calls)
And implementing the plug-in itself!
9. Write the Java code for your plug-in.
10. Build the project
11. [Netbeans] copy the .jar from ./dist to ~/Salem/plugins.
And, finally, launch the client and enjoy your plug-in!
View
@@ -7,8 +7,8 @@
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="SamplePlugin" default="default" basedir=".">
<description>Builds, tests, and runs the project SamplePlugin.</description>
<project name="PickupPlugin" default="default" basedir=".">
<description>Builds, tests, and runs the project PickupPlugin.</description>
<import file="nbproject/build-impl.xml"/>
<!--
@@ -58,7 +58,7 @@
An example of overriding the target for project execution could look like this:
<target name="run" depends="SamplePlugin-impl.jar">
<target name="run" depends="PickupPlugin-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
@@ -1,4 +1,4 @@
#Sun, 13 Mar 2016 16:28:13 +0100
#Wed, 15 Jun 2016 22:45:02 +0200
E\:\\Installs\\Games\\Salem\\Plugins\\MyFirstPlugin=
/scratch/private/games/salem/SalemPickupPlugin=
@@ -1 +1 @@
haven.plugins.MyFirstPlugin
haven.plugins.PickupPlugin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
@@ -11,7 +11,7 @@ JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "SamplePlugin.jar"
java -jar "PickupPlugin.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
View
Binary file not shown.
View
Binary file not shown.
@@ -1 +1 @@
haven.plugins.MyFirstPlugin
haven.plugins.PickupPlugin
View
@@ -19,7 +19,7 @@ is divided into following sections:
- cleanup
-->
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="SamplePlugin-impl">
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="PickupPlugin-impl">
<fail message="Please build using Ant 1.8.0 or higher.">
<condition>
<not>
@@ -447,7 +447,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="SamplePlugin" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="PickupPlugin" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@@ -598,7 +598,7 @@ is divided into following sections:
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
<condition else="-suitename SamplePlugin -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<condition else="-suitename PickupPlugin -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
@@ -890,7 +890,7 @@ is divided into following sections:
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
<echo level="warn" message="Cycle detected: SamplePlugin was already built"/>
<echo level="warn" message="Cycle detected: PickupPlugin was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
@@ -1389,7 +1389,7 @@ is divided into following sections:
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
<echo level="warn" message="Cycle detected: SamplePlugin was already built"/>
<echo level="warn" message="Cycle detected: PickupPlugin was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>
@@ -1,8 +1,8 @@
build.xml.data.CRC32=7c550deb
build.xml.script.CRC32=f61b4da5
build.xml.data.CRC32=0256b665
build.xml.script.CRC32=bc9d3222
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=7c550deb
nbproject/build-impl.xml.script.CRC32=6a70ec03
nbproject/build-impl.xml.data.CRC32=0256b665
nbproject/build-impl.xml.script.CRC32=05be6021
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
@@ -1,6 +1,7 @@
compile.on.save=true
do.depend=false
do.jar=true
file.reference.lsalem.jar=/scratch/private/games/salem/Custom-Salem/build/lsalem.jar
javac.debug=true
javadoc.preview=true
user.properties.file=C:\\Users\\Simon\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
user.properties.file=/home/sdonn/.netbeans/8.0.2/build.properties
@@ -3,5 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group name="Salem"/>
<group>
<file>file:/scratch/private/games/salem/SalemPickupPlugin/src/haven/plugins/PickupPlugin.java</file>
</group>
</open-files>
</project-private>
@@ -3,7 +3,7 @@ annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=SamplePlugin
application.title=PickupPlugin
application.vendor=Simon
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
@@ -25,7 +25,7 @@ debug.test.classpath=\
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/SamplePlugin.jar
dist.jar=${dist.dir}/PickupPlugin.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
View
@@ -3,7 +3,7 @@
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>SamplePlugin</name>
<name>PickupPlugin</name>
<source-roots>
<root id="src.manifest.dir"/>
<root id="src.dir"/>
View
3 resources/compile_resources.bat 100644 → 100755
@@ -1 +1,2 @@
java -jar LayerUtil.jar -re src compiled/res
#!/bin/bash
java -jar LayerUtil.jar -re src compiled/res
Binary file not shown.
Binary file not shown.

This file was deleted.

Oops, something went wrong.
Binary file not shown.
@@ -0,0 +1,17 @@
#ABUTTON LAYER FOR RES src//\paginae\add\pickup.res
#String pr
paginae/act/add
#uint16 pver
2
#String name
Pick up the closest item, if it is within one tile of your location.
#String preq
#uint16 hk
112
#uint16 ad length
2
#String ad[0]
@
#String ad[1]
pickup
@@ -1,4 +1,4 @@
#IMAGE LAYER FOR RES src//\paginae\add\hello.res
#IMAGE LAYER FOR RES src//\paginae\add\pickup.res
#int16 z
0
#int16 subz
Binary file not shown.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,52 @@
package haven.plugins;
import haven.*;
import java.awt.Color;
import java.util.Collection;
import java.util.Iterator;
public class PickupPlugin extends Plugin{
public void load(UI ui)
{
Glob glob = ui.sess.glob;
Collection<Glob.Pagina> p = glob.paginae;
p.add(glob.paginafor(Resource.load("paginae/add/pickup")));
XTendedPaginae.registerPlugin("pickup",this);
}
public void execute(UI ui){
//we find the closest item on the ground
Collection<Gob> gobs = ui.sess.glob.oc.getGobs();
double distance = 0.0;
Gob closest_gob = null;
Iterator<Gob> gobs_iterator = gobs.iterator();
Gob current_gob = null;
Coord player_location = ui.gui.map.player().rc;
while(gobs_iterator.hasNext()) {
current_gob = gobs_iterator.next();
Coord gob_location = current_gob.rc;
ResDrawable rd = null;
String nm = "";
try{
rd = current_gob.getattr(ResDrawable.class);
if(rd!=null)
nm = rd.res.get().name;
}catch(Loading l){}
if(nm.contains("terobjs/herbs") || nm.contains("terobjs/item"))
{
double this_distance = gob_location.dist(player_location);
if((this_distance < distance)||closest_gob==null) {
closest_gob = current_gob;
distance = this_distance;
}
}
}
//and right click it if one was found
if(closest_gob!=null){
ui.wdgmsg(ui.gui.map, "click", closest_gob.sc, closest_gob.rc, 3, 0, 0, (int) closest_gob.id, closest_gob.rc, 0, -1);
}
else{
ui.message("[PickupPlugin] No forageable items found in the vicinity!", GameUI.MsgType.INFO);
}
}
}

0 comments on commit b5ecec5

Please sign in to comment.