Rework event processor, start javadoc rechecking
parent
311a3d0d81
commit
3cfcc150fd
|
@ -31,17 +31,34 @@ import javax.swing.SwingConstants;
|
|||
import java.awt.Point;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GUIBugReportDialog.
|
||||
*/
|
||||
public class GUIBugReportDialog extends JDialog {
|
||||
|
||||
/** The content panel. */
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/** The reporter name. */
|
||||
private JTextField reporterName;
|
||||
|
||||
/** The email. */
|
||||
private JTextField email;
|
||||
|
||||
/** The problem summary. */
|
||||
private JTextField problemSummary;
|
||||
|
||||
/** The chckbx include technical information. */
|
||||
private JCheckBox chckbxIncludeTechnicalInformation;
|
||||
|
||||
/** The lbl name. */
|
||||
private JLabel lblName;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
@ -55,6 +72,8 @@ public class GUIBugReportDialog extends JDialog {
|
|||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*
|
||||
* @param traceback the traceback
|
||||
*/
|
||||
public GUIBugReportDialog(String traceback) {
|
||||
setModal(true);
|
||||
|
|
|
@ -33,19 +33,42 @@ import net.mosstest.servercore.MossDebugUtils;
|
|||
import net.mosstest.servercore.MossWorld;
|
||||
import net.mosstest.servercore.MosstestSecurityManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GUIClientsideLauncher.
|
||||
*/
|
||||
public class GUIClientsideLauncher {
|
||||
|
||||
/** The logger. */
|
||||
static Logger logger = Logger.getLogger(GUIClientsideLauncher.class);
|
||||
|
||||
/** The mdl. */
|
||||
private SingleplayerListTableModel mdl;
|
||||
static {
|
||||
System.setSecurityManager(MosstestSecurityManager.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class SingleplayerListEntry.
|
||||
*/
|
||||
public static class SingleplayerListEntry {
|
||||
|
||||
/** The name. */
|
||||
public String name;
|
||||
|
||||
/** The description. */
|
||||
public String description;
|
||||
|
||||
/** The game preset. */
|
||||
public String gamePreset;
|
||||
|
||||
/**
|
||||
* Instantiates a new singleplayer list entry.
|
||||
*
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
* @param gamePreset the game preset
|
||||
*/
|
||||
public SingleplayerListEntry(String name, String description,
|
||||
String gamePreset) {
|
||||
this.name = name;
|
||||
|
@ -55,13 +78,18 @@ public class GUIClientsideLauncher {
|
|||
|
||||
}
|
||||
|
||||
/** The frm mosstest client launcher. */
|
||||
private JDialog frmMosstestClientLauncher;
|
||||
|
||||
/** The table. */
|
||||
private JTable table;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
* @throws InterruptedException
|
||||
* @throws InvocationTargetException
|
||||
*
|
||||
* @param args the arguments
|
||||
* @throws InvocationTargetException the invocation target exception
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
|
||||
logger.info("Mosstest client starting...");
|
||||
|
@ -95,6 +123,8 @@ public class GUIClientsideLauncher {
|
|||
|
||||
/**
|
||||
* Create the application.
|
||||
*
|
||||
* @param singleplayerEntries the singleplayer entries
|
||||
*/
|
||||
public GUIClientsideLauncher(
|
||||
ArrayList<SingleplayerListEntry> singleplayerEntries) {
|
||||
|
@ -103,8 +133,8 @@ public class GUIClientsideLauncher {
|
|||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*
|
||||
* @param singleplayerEntries
|
||||
*
|
||||
* @param singleplayerEntries the singleplayer entries
|
||||
*/
|
||||
private void initialize(ArrayList<SingleplayerListEntry> singleplayerEntries) {
|
||||
this.frmMosstestClientLauncher = new JDialog();
|
||||
|
@ -325,24 +355,43 @@ public class GUIClientsideLauncher {
|
|||
frmMosstestClientLauncher.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class SingleplayerListTableModel.
|
||||
*/
|
||||
class SingleplayerListTableModel extends AbstractTableModel {
|
||||
|
||||
/** The column names. */
|
||||
private String[] columnNames = {
|
||||
Messages.getString("GUIClientsideLauncher.COL_WORLD_NAME"), Messages.getString("GUIClientsideLauncher.COL_WORLD_DESC"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Messages.getString("GUIClientsideLauncher.COL_GAME_PRESET") }; //$NON-NLS-1$
|
||||
|
||||
/** The entries. */
|
||||
private ArrayList<SingleplayerListEntry> entries = new ArrayList<>();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.TableModel#getColumnCount()
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
return this.columnNames.length;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.TableModel#getRowCount()
|
||||
*/
|
||||
public int getRowCount() {
|
||||
return this.entries.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.AbstractTableModel#getColumnName(int)
|
||||
*/
|
||||
public String getColumnName(int col) {
|
||||
return this.columnNames[col];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.TableModel#getValueAt(int, int)
|
||||
*/
|
||||
public Object getValueAt(int row, int col) {
|
||||
SingleplayerListEntry entry = this.entries.get(row);
|
||||
switch (col) {
|
||||
|
@ -360,6 +409,9 @@ public class GUIClientsideLauncher {
|
|||
/*
|
||||
* All entries are strings *at the moment*.
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.AbstractTableModel#getColumnClass(int)
|
||||
*/
|
||||
public Class getColumnClass(int c) {
|
||||
return String.class;
|
||||
}
|
||||
|
@ -367,12 +419,17 @@ public class GUIClientsideLauncher {
|
|||
/*
|
||||
* Don't need to implement this method unless your table's editable.
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
|
||||
*/
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entries
|
||||
* Instantiates a new singleplayer list table model.
|
||||
*
|
||||
* @param entries the entries
|
||||
*/
|
||||
public SingleplayerListTableModel(
|
||||
ArrayList<SingleplayerListEntry> entries) {
|
||||
|
|
|
@ -22,15 +22,31 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.GridLayout;
|
||||
import java.awt.Dimension;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GUIWorldCreationDialog.
|
||||
*/
|
||||
public class GUIWorldCreationDialog extends JDialog {
|
||||
|
||||
/** The dlg result. */
|
||||
boolean dlgResult= false;
|
||||
|
||||
/** The content panel. */
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/** The combo box. */
|
||||
JComboBox<String> comboBox;
|
||||
|
||||
/** The input desc. */
|
||||
JTextField inputDesc;
|
||||
|
||||
/** The name field. */
|
||||
JTextField nameField;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
|
|
@ -13,12 +13,22 @@ import javax.swing.JPanel;
|
|||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GUIWorldDeletionDialog.
|
||||
*/
|
||||
public class GUIWorldDeletionDialog extends JDialog {
|
||||
|
||||
/** The dlg result. */
|
||||
boolean dlgResult=false;
|
||||
|
||||
/** The content panel. */
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
@ -32,6 +42,8 @@ public class GUIWorldDeletionDialog extends JDialog {
|
|||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*
|
||||
* @param worldName the world name
|
||||
*/
|
||||
public GUIWorldDeletionDialog(String worldName) {
|
||||
setTitle(Messages.getString("GUIWorldDeletionDialog.DLG_TITLE")); //$NON-NLS-1$
|
||||
|
|
|
@ -4,19 +4,40 @@ package net.mosstest.launcher;
|
|||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Messages.
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
/** The Constant BUNDLE_NAME. */
|
||||
private static final String BUNDLE_NAME = "net.mosstest.launcher.messages"; //$NON-NLS-1$
|
||||
|
||||
/** The res bundle. */
|
||||
private static ResourceBundle resBundle = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
/**
|
||||
* Change language.
|
||||
*
|
||||
* @param identifier the identifier
|
||||
*/
|
||||
public static void changeLanguage(String identifier) {
|
||||
resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new messages.
|
||||
*/
|
||||
private Messages() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the string
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return resBundle.getString(key);
|
||||
|
|
|
@ -4,10 +4,29 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class SandboxClass.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
*/
|
||||
public class SandboxClass<T> {
|
||||
|
||||
/** The clazz. */
|
||||
Class<T> clazz;
|
||||
|
||||
/** The iface. */
|
||||
final boolean allowStatic, instantiable, deny, iface;
|
||||
|
||||
/**
|
||||
* Instantiates a new sandbox class.
|
||||
*
|
||||
* @param clazz the clazz
|
||||
* @param allowStatic the allow static
|
||||
* @param instantiable the instantiable
|
||||
* @param deny the deny
|
||||
* @param iface the iface
|
||||
*/
|
||||
public SandboxClass(Class<T> clazz, boolean allowStatic,
|
||||
boolean instantiable, boolean deny, boolean iface) {
|
||||
this.clazz = clazz;
|
||||
|
@ -17,6 +36,9 @@ public class SandboxClass<T> {
|
|||
this.iface = iface;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -26,6 +48,9 @@ public class SandboxClass<T> {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -48,6 +73,18 @@ public class SandboxClass<T> {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke static.
|
||||
*
|
||||
* @param method the method
|
||||
* @param params the params
|
||||
* @return the object
|
||||
* @throws NoSuchMethodException the no such method exception
|
||||
* @throws SecurityException the security exception
|
||||
* @throws IllegalAccessException the illegal access exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws InvocationTargetException the invocation target exception
|
||||
*/
|
||||
public Object invokeStatic(String method, Object... params)
|
||||
throws NoSuchMethodException, SecurityException,
|
||||
IllegalAccessException, IllegalArgumentException,
|
||||
|
@ -61,6 +98,18 @@ public class SandboxClass<T> {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance of SandboxClass.
|
||||
*
|
||||
* @param params the params
|
||||
* @return single instance of SandboxClass
|
||||
* @throws NoSuchMethodException the no such method exception
|
||||
* @throws SecurityException the security exception
|
||||
* @throws InstantiationException the instantiation exception
|
||||
* @throws IllegalAccessException the illegal access exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws InvocationTargetException the invocation target exception
|
||||
*/
|
||||
public T getInstance(Object... params) throws NoSuchMethodException,
|
||||
SecurityException, InstantiationException, IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException {
|
||||
|
|
|
@ -1,28 +1,61 @@
|
|||
package net.mosstest.sandbox.lang;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Runtime.
|
||||
*/
|
||||
public class Runtime {
|
||||
|
||||
/** The runtime. */
|
||||
private java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
|
||||
|
||||
/**
|
||||
* Available processors.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int availableProcessors() {
|
||||
return this.runtime.availableProcessors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long freeMemory() {
|
||||
return this.runtime.freeMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Total memory.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long totalMemory() {
|
||||
return this.runtime.totalMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Max memory.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long maxMemory() {
|
||||
return this.runtime.maxMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gc.
|
||||
*/
|
||||
public void gc() {
|
||||
this.runtime.gc();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new runtime.
|
||||
*/
|
||||
public Runtime() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,35 +3,81 @@ package net.mosstest.sandbox.lang;
|
|||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class System.
|
||||
*/
|
||||
public final class System {
|
||||
|
||||
/**
|
||||
* Instantiates a new system.
|
||||
*/
|
||||
private System() {
|
||||
};
|
||||
|
||||
/** The Constant err. */
|
||||
public static final PrintStream err = java.lang.System.err;
|
||||
|
||||
/** The Constant out. */
|
||||
public static final PrintStream out = java.lang.System.out;
|
||||
|
||||
/** The Constant in. */
|
||||
public static final InputStream in = java.lang.System.in;
|
||||
|
||||
/**
|
||||
* Arraycopy.
|
||||
*
|
||||
* @param src the src
|
||||
* @param srcPos the src pos
|
||||
* @param dest the dest
|
||||
* @param destPos the dest pos
|
||||
* @param length the length
|
||||
*/
|
||||
public static void arraycopy(Object src, int srcPos, Object dest,
|
||||
int destPos, int length) {
|
||||
java.lang.System.arraycopy(src, srcPos, dest, destPos, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Current time millis.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public static long currentTimeMillis() {
|
||||
return java.lang.System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gc.
|
||||
*/
|
||||
public static void gc() {
|
||||
java.lang.System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Identity hash code.
|
||||
*
|
||||
* @param o the o
|
||||
* @return the int
|
||||
*/
|
||||
public static int identityHashCode(Object o) {
|
||||
return java.lang.System.identityHashCode(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Line separator.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public static String lineSeparator() {
|
||||
return java.lang.System.lineSeparator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Nano time.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public static long nanoTime() {
|
||||
return java.lang.System.nanoTime();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,17 @@ package net.mosstest.sandbox.lang;
|
|||
|
||||
import net.mosstest.scripting.ScriptRunnable;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Thread.
|
||||
*/
|
||||
public class Thread {
|
||||
|
||||
/**
|
||||
* Spawn thread.
|
||||
*
|
||||
* @param r the r
|
||||
*/
|
||||
static void spawnThread(ScriptRunnable r) {
|
||||
//todo todo
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.lang;
|
||||
|
||||
/**
|
||||
* The Class ThreadGroup.
|
||||
*/
|
||||
public class ThreadGroup {
|
||||
//todo sandbox
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.lang;
|
||||
|
||||
/**
|
||||
* The Class ThreadLocal.
|
||||
*/
|
||||
public class ThreadLocal {
|
||||
//todo sandbox--probably discard, in fact.
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.util;
|
||||
|
||||
/**
|
||||
* The Class Collections.
|
||||
*/
|
||||
public class Collections {
|
||||
//todo sandbox
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.util;
|
||||
|
||||
/**
|
||||
* The Class Enumeration.
|
||||
*/
|
||||
public class Enumeration {
|
||||
//todo sandbox
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.util;
|
||||
|
||||
/**
|
||||
* The Class ResourceBundle.
|
||||
*/
|
||||
public class ResourceBundle {
|
||||
//todo sandbox
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.sandbox.util.concurrent.atomic;
|
||||
|
||||
/**
|
||||
* The Class AtomicReferenceFieldUpdater.
|
||||
*/
|
||||
public class AtomicReferenceFieldUpdater {
|
||||
//todo sandbox
|
||||
}
|
||||
|
|
|
@ -3,8 +3,15 @@ package net.mosstest.scripting;
|
|||
import net.mosstest.scripting.MossTool.InteractType;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class AirNodeParams.
|
||||
*/
|
||||
public class AirNodeParams implements INodeParams {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onPunch(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onPunch(Player player, MossItem tool,
|
||||
NodePosition target, Face punchedFace)
|
||||
|
@ -13,6 +20,9 @@ public class AirNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onDig(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onDig(Player player, MossItem tool, NodePosition target,
|
||||
Face punchedFace) throws EventProcessingCompletedSignal {
|
||||
|
@ -20,6 +30,9 @@ public class AirNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onPlaceNextTo(net.mosstest.scripting.Player, net.mosstest.scripting.NodePosition, net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public void onPlaceNextTo(Player player, NodePosition target,
|
||||
NodePosition placed) throws EventProcessingCompletedSignal {
|
||||
|
@ -27,6 +40,9 @@ public class AirNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onRightClick(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onRightClick(Player player, MossItem tool,
|
||||
NodePosition target, Face clickedFace)
|
||||
|
@ -35,6 +51,9 @@ public class AirNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onStepOn(net.mosstest.scripting.Player, net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public boolean onStepOn(Player player, NodePosition pos)
|
||||
throws EventProcessingCompletedSignal {
|
||||
|
@ -42,46 +61,73 @@ public class AirNodeParams implements INodeParams {
|
|||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#jumpOffHeight(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double jumpOffHeight(Player player) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcBounceHeight(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcBounceHeight(Player player, double fallheight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkIn(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkIn(Player player, double fallheight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkEscape(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkEscape(Player player, double sinkheight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcWalkSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcWalkSpeed(Player player) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSprintSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcSprintSpeed(Player player) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcFallDamage(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcFallDamage(Player player, double height) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#shouldContinueFall(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldContinueFall(Player player, double height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#shouldHitAimRay(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldHitAimRay(Player player, double distance) {
|
||||
return false;
|
||||
|
@ -89,12 +135,18 @@ public class AirNodeParams implements INodeParams {
|
|||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkActive(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkActive(Player player, double fallheight) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcInteractProperties(net.mosstest.scripting.MossTool.InteractType, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcInteractProperties(InteractType key, double strength) {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
@ -6,33 +6,72 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
import net.mosstest.servercore.SessionManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class AntiCheatController.
|
||||
*/
|
||||
public class AntiCheatController {
|
||||
|
||||
/** The checks. */
|
||||
protected ArrayList<AntiCheatCheck> checks = new ArrayList<>();
|
||||
|
||||
/** The handlers. */
|
||||
protected ArrayList<AntiCheatHandler> handlers = new ArrayList<>();
|
||||
|
||||
/** The env. */
|
||||
protected MossScriptEnv env;
|
||||
|
||||
/** The sess. */
|
||||
protected SessionManager sess;
|
||||
|
||||
/** The run. */
|
||||
protected volatile boolean run = false;
|
||||
|
||||
/** The need deaths from. */
|
||||
protected AtomicInteger needDeathsFrom = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* Instantiates a new anti cheat controller.
|
||||
*
|
||||
* @param env the env
|
||||
* @param sess the sess
|
||||
*/
|
||||
public AntiCheatController(MossScriptEnv env, SessionManager sess) {
|
||||
this.env = env;
|
||||
this.sess = sess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register check.
|
||||
*
|
||||
* @param chk the chk
|
||||
*/
|
||||
public void registerCheck(AntiCheatCheck chk) {
|
||||
synchronized (this.checks) {
|
||||
this.checks.add(chk);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register handler.
|
||||
*
|
||||
* @param hdl the hdl
|
||||
*/
|
||||
public void registerHandler(AntiCheatHandler hdl) {
|
||||
synchronized (this.handlers) {
|
||||
this.handlers.add(hdl);
|
||||
}
|
||||
}
|
||||
|
||||
/** The threads. */
|
||||
private ArrayList<Thread> threads = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Start threads.
|
||||
*
|
||||
* @param threads the threads
|
||||
* @param priority the priority
|
||||
*/
|
||||
public void startThreads(int threads, int priority) {
|
||||
this.run = true;
|
||||
for (int i = 0; i < threads; i++) {
|
||||
|
@ -44,12 +83,20 @@ public class AntiCheatController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill threads.
|
||||
*
|
||||
* @param threads the threads
|
||||
*/
|
||||
public void killThreads(int threads) {
|
||||
|
||||
this.needDeathsFrom.addAndGet(threads);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Interface AntiCheatCheck.
|
||||
*/
|
||||
public static interface AntiCheatCheck {
|
||||
/**
|
||||
* Check that a player is compliant with this anti-cheat check. This
|
||||
|
@ -70,6 +117,9 @@ public class AntiCheatController {
|
|||
public int check(Player p, MossScriptEnv env);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Interface AntiCheatHandler.
|
||||
*/
|
||||
public static interface AntiCheatHandler {
|
||||
|
||||
/**
|
||||
|
@ -89,8 +139,14 @@ public class AntiCheatController {
|
|||
public void handleViolation(Player p, int severity, MossScriptEnv env);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class AntiCheatRunnable.
|
||||
*/
|
||||
private class AntiCheatRunnable implements Runnable {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
|
|
@ -3,13 +3,23 @@ package net.mosstest.scripting;
|
|||
import net.mosstest.scripting.MossTool.InteractType;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class DefaultNodeParams.
|
||||
*/
|
||||
public class DefaultNodeParams implements INodeParams {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onStepOn(net.mosstest.scripting.Player, net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public boolean onStepOn(Player player, NodePosition pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onRightClick(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onRightClick(Player player, MossItem tool,
|
||||
NodePosition target, Face clickedFace) {
|
||||
|
@ -17,6 +27,9 @@ public class DefaultNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onPunch(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onPunch(Player player, MossItem tool,
|
||||
NodePosition target, Face punchedFace) {
|
||||
|
@ -24,69 +37,108 @@ public class DefaultNodeParams implements INodeParams {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onPlaceNextTo(net.mosstest.scripting.Player, net.mosstest.scripting.NodePosition, net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public void onPlaceNextTo(Player player, NodePosition target,
|
||||
NodePosition placed) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#onDig(net.mosstest.scripting.Player, net.mosstest.scripting.MossItem, net.mosstest.scripting.NodePosition, net.mosstest.scripting.Face)
|
||||
*/
|
||||
@Override
|
||||
public void onDig(Player player, MossItem tool, NodePosition target,
|
||||
Face punchedFace) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#jumpOffHeight(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double jumpOffHeight(Player player) {
|
||||
return 1.125;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcWalkSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcWalkSpeed(Player player) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSprintSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcSprintSpeed(Player player) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkIn(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkIn(Player player, double fallheight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkEscape(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkEscape(Player player, double fallheight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcBounceHeight(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcBounceHeight(Player player, double fallheight) {
|
||||
return 0.125;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcFallDamage(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcFallDamage(Player player, double height) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#shouldContinueFall(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldContinueFall(Player player, double height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#shouldHitAimRay(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldHitAimRay(Player player, double distance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcSinkActive(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkActive(Player player, double fallheight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//FIXME move to interact params
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.INodeParams#calcInteractProperties(net.mosstest.scripting.MossTool.InteractType, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcInteractProperties(InteractType key, double strength) {
|
||||
return 1;
|
||||
|
|
|
@ -1,14 +1,37 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Entity.
|
||||
*/
|
||||
public class Entity {
|
||||
|
||||
/** The id. */
|
||||
int id;
|
||||
|
||||
/** The name. */
|
||||
public String name;
|
||||
|
||||
/** The hp. */
|
||||
int hp;
|
||||
|
||||
/** The max health. */
|
||||
int maxHealth;
|
||||
|
||||
/**
|
||||
* Destroy.
|
||||
*/
|
||||
public void destroy() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new entity.
|
||||
*
|
||||
* @param name the name
|
||||
* @param maxHealth the max health
|
||||
*/
|
||||
protected Entity(String name, int maxHealth) {
|
||||
//TODO DB lookup for entities
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
/**
|
||||
* The Class EventProcessingCompletedSignal.
|
||||
*/
|
||||
public class EventProcessingCompletedSignal extends Throwable {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
/*
|
||||
*
|
||||
*/
|
||||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Enum Face.
|
||||
*/
|
||||
public enum Face {
|
||||
TOP, BOTTOM, N, S, E, W
|
||||
|
||||
/** The top. */
|
||||
TOP,
|
||||
/** The bottom. */
|
||||
BOTTOM,
|
||||
/** The n. */
|
||||
N,
|
||||
/** The s. */
|
||||
S,
|
||||
/** The e. */
|
||||
E,
|
||||
/** The w. */
|
||||
W
|
||||
}
|
||||
|
|
|
@ -3,9 +3,21 @@ package net.mosstest.scripting;
|
|||
import net.mosstest.servercore.INodeManager;
|
||||
import net.mosstest.servercore.MapGeneratorException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class FlatMapGenerator.
|
||||
*/
|
||||
public class FlatMapGenerator implements IMapGenerator {
|
||||
|
||||
/** The seed. */
|
||||
long seed;
|
||||
|
||||
/** The nm. */
|
||||
INodeManager nm;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void init(long seed, INodeManager nm, Object... params)
|
||||
throws MapGeneratorException {
|
||||
|
@ -13,6 +25,9 @@ public class FlatMapGenerator implements IMapGenerator {
|
|||
this.nm=nm;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public MapChunk generateChunk(Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -37,6 +52,9 @@ public class FlatMapGenerator implements IMapGenerator {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public void fillInChunk(int[][][] lightNodes, Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -59,6 +77,9 @@ public class FlatMapGenerator implements IMapGenerator {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void registerOre(MapNode oreNode, double minDepth,
|
||||
double rarity, double clumping, int seed, Object... params) {
|
||||
|
|
|
@ -3,10 +3,29 @@ package net.mosstest.scripting;
|
|||
import net.mosstest.servercore.INodeManager;
|
||||
import net.mosstest.servercore.MapGeneratorException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface IMapGenerator.
|
||||
*/
|
||||
public interface IMapGenerator {
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*
|
||||
* @param seed the seed
|
||||
* @param nm the nm
|
||||
* @param params the params
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
*/
|
||||
void init(long seed, INodeManager nm, Object... params) throws MapGeneratorException;
|
||||
|
||||
/**
|
||||
* Generate chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return the map chunk
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
*/
|
||||
public MapChunk generateChunk(Position pos) throws MapGeneratorException;
|
||||
|
||||
/**
|
||||
|
@ -27,22 +46,18 @@ public interface IMapGenerator {
|
|||
/**
|
||||
* Register an ore for future generation of chunks. The values given here
|
||||
* are hints to the map generator and need not be exact.
|
||||
*
|
||||
* @param oreNode
|
||||
* The ore to generate.
|
||||
* @param minDepth
|
||||
* The minimum depth(as a positive integer number of nodes below
|
||||
*
|
||||
* @param oreNode The ore to generate.
|
||||
* @param minDepth The minimum depth(as a positive integer number of nodes below
|
||||
* sea level.
|
||||
* @param rarity
|
||||
* How rare the ore should be. Rarity 1 corresponds to virtually
|
||||
* @param rarity How rare the ore should be. Rarity 1 corresponds to virtually
|
||||
* every ore-containing node, and rarity 100 would correspond to
|
||||
* approximately one out of 100 nodes being this ore.
|
||||
* @param clumping
|
||||
* Defines how clumped the ore should be. Generally corresponds
|
||||
* @param clumping Defines how clumped the ore should be. Generally corresponds
|
||||
* to 0=uniform and 1=most strongly clumped(solid spheres of ore
|
||||
* clumps to meet rarity goal)
|
||||
* @param params
|
||||
* Miscellaneous params for the map generator.
|
||||
* @param seed the seed
|
||||
* @param params Miscellaneous params for the map generator.
|
||||
*/
|
||||
public void registerOre(MapNode oreNode, double minDepth, double rarity,
|
||||
double clumping, int seed, Object... params);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* Interface to specify handlers to be called when various actions are taken by
|
||||
* players directed at a node. These handlers are called after the ones defined
|
||||
|
@ -11,29 +12,25 @@ package net.mosstest.scripting;
|
|||
*
|
||||
*/
|
||||
public interface INodeParams {
|
||||
|
||||
/**
|
||||
* Function that is called when a node is punched.
|
||||
*
|
||||
* @param player
|
||||
* The player punching the node.
|
||||
* @param tool
|
||||
* The tool being used to punch the node.
|
||||
* @param target
|
||||
* The position of the targeted node.
|
||||
* @param punchedFace
|
||||
* The face being punched.
|
||||
*
|
||||
* @param player The player punching the node.
|
||||
* @param tool The tool being used to punch the node.
|
||||
* @param target The position of the targeted node.
|
||||
* @param punchedFace The face being punched.
|
||||
* @throws EventProcessingCompletedSignal the event processing completed signal
|
||||
*/
|
||||
public abstract void onPunch(Player player, MossItem tool,
|
||||
NodePosition target, Face punchedFace)
|
||||
throws EventProcessingCompletedSignal;
|
||||
|
||||
/**
|
||||
* Determines if a fall should continue
|
||||
*
|
||||
* @param player
|
||||
* The player.
|
||||
* @param height
|
||||
* The height.
|
||||
* Determines if a fall should continue.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param height The height.
|
||||
* @return A boolean representing whether the fall should continue or be
|
||||
* marked as a fall.
|
||||
*/
|
||||
|
@ -41,19 +38,15 @@ public interface INodeParams {
|
|||
|
||||
/**
|
||||
* Called when a node is fully dug.
|
||||
*
|
||||
* @param player
|
||||
* The player digging the node.
|
||||
* @param tool
|
||||
* The tool used to dig the node.
|
||||
* @param target
|
||||
* The position of the node that has been dug.
|
||||
* @param punchedFace
|
||||
* The face on which the the tool was pointed when digging was
|
||||
*
|
||||
* @param player The player digging the node.
|
||||
* @param tool The tool used to dig the node.
|
||||
* @param target The position of the node that has been dug.
|
||||
* @param punchedFace The face on which the the tool was pointed when digging was
|
||||
* complete. Note that if a dig begins on one face but the player
|
||||
* moves the aim to another face the onPunch handler may receive
|
||||
* a different face than this handler.
|
||||
* @throws EventProcessingCompletedSignal
|
||||
* @throws EventProcessingCompletedSignal the event processing completed signal
|
||||
*/
|
||||
public abstract void onDig(Player player, MossItem tool,
|
||||
NodePosition target, Face punchedFace)
|
||||
|
@ -62,12 +55,11 @@ public interface INodeParams {
|
|||
/**
|
||||
* Called when a node is placed directly above, below, left, right, in front
|
||||
* of, or behind this node.
|
||||
*
|
||||
* @param player
|
||||
* The player placing the node.
|
||||
* @param target
|
||||
* @param placed
|
||||
* @throws EventProcessingCompletedSignal
|
||||
*
|
||||
* @param player The player placing the node.
|
||||
* @param target the target
|
||||
* @param placed the placed
|
||||
* @throws EventProcessingCompletedSignal the event processing completed signal
|
||||
*/
|
||||
public abstract void onPlaceNextTo(Player player, NodePosition target,
|
||||
NodePosition placed) throws EventProcessingCompletedSignal;
|
||||
|
@ -76,16 +68,12 @@ public interface INodeParams {
|
|||
* Called when a right-click is done on a node. Note that this is called
|
||||
* even if no node is placed, such as if the player is not holding anything,
|
||||
* or is holding a tool.
|
||||
*
|
||||
* @param player
|
||||
* Player performing the action.
|
||||
* @param tool
|
||||
* Tool held by user in active slot during this action.
|
||||
* @param target
|
||||
* Position of targeted node
|
||||
* @param clickedFace
|
||||
* Face which was right-clicked.
|
||||
* @throws EventProcessingCompletedSignal
|
||||
*
|
||||
* @param player Player performing the action.
|
||||
* @param tool Tool held by user in active slot during this action.
|
||||
* @param target Position of targeted node
|
||||
* @param clickedFace Face which was right-clicked.
|
||||
* @throws EventProcessingCompletedSignal the event processing completed signal
|
||||
*/
|
||||
public abstract void onRightClick(Player player, MossItem tool,
|
||||
NodePosition target, Face clickedFace)
|
||||
|
@ -94,13 +82,11 @@ public interface INodeParams {
|
|||
/**
|
||||
* Called when a player steps on a node either from jumping, falling, or
|
||||
* walking forward.
|
||||
*
|
||||
* @param player
|
||||
* Player that steps on this node.
|
||||
* @param pos
|
||||
* Position of node that is stepped on.
|
||||
*
|
||||
* @param player Player that steps on this node.
|
||||
* @param pos Position of node that is stepped on.
|
||||
* @return Currently unused.
|
||||
* @throws EventProcessingCompletedSignal
|
||||
* @throws EventProcessingCompletedSignal the event processing completed signal
|
||||
*/
|
||||
public abstract boolean onStepOn(Player player, NodePosition pos)
|
||||
throws EventProcessingCompletedSignal;
|
||||
|
@ -108,18 +94,17 @@ public interface INodeParams {
|
|||
/**
|
||||
* Calculates the height a player may jump off of this node. One node is
|
||||
* equal to 1.0.
|
||||
*
|
||||
* @param player
|
||||
*
|
||||
* @param player the player
|
||||
* @return The height the player may jump off this node.
|
||||
*/
|
||||
public abstract double jumpOffHeight(Player player);
|
||||
|
||||
/**
|
||||
* Calculates the height a player will bounce when landing on this node.
|
||||
*
|
||||
* @param player
|
||||
* @param fallheight
|
||||
* The height from which the player has fallen.
|
||||
*
|
||||
* @param player the player
|
||||
* @param fallheight The height from which the player has fallen.
|
||||
* @return A double value representing the height the player is to bounce.
|
||||
*/
|
||||
public abstract double calcBounceHeight(Player player, double fallheight);
|
||||
|
|
|
@ -82,6 +82,7 @@ import net.mosstest.sandbox.util.Enumeration;
|
|||
import net.mosstest.sandbox.util.ResourceBundle;
|
||||
import net.mosstest.sandbox.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* Class for scripts to instantiate and access the static methods of various approved classes.
|
||||
* @author rarkenin
|
||||
|
@ -89,6 +90,7 @@ import net.mosstest.sandbox.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
|||
*/
|
||||
public class JavaApi {
|
||||
|
||||
/** The Constant qualifiedClasses. */
|
||||
private static final HashMap<String, SandboxClass> qualifiedClasses=new HashMap<String, SandboxClass>(){{
|
||||
put("java.lang.Object", new SandboxClass<Object>(java.lang.Object.class, true, true, false, false)); //$NON-NLS-1$
|
||||
put("java.lang.String", new SandboxClass<String>(java.lang.String.class, true, true, false, false)); //$NON-NLS-1$
|
||||
|
@ -222,11 +224,37 @@ public class JavaApi {
|
|||
put("java.util.EnumMap", new SandboxClass<EnumMap>(java.util.EnumMap.class, true, true, false, false)); //$NON-NLS-1$
|
||||
}};
|
||||
|
||||
/**
|
||||
* Gets the single instance of JavaApi.
|
||||
*
|
||||
* @param clazz the clazz
|
||||
* @param constructorParams the constructor params
|
||||
* @return single instance of JavaApi
|
||||
* @throws NoSuchMethodException the no such method exception
|
||||
* @throws SecurityException the security exception
|
||||
* @throws InstantiationException the instantiation exception
|
||||
* @throws IllegalAccessException the illegal access exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws InvocationTargetException the invocation target exception
|
||||
*/
|
||||
public static Object getInstance(String clazz, Object... constructorParams) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
SandboxClass<?> sc=qualifiedClasses.get(clazz);
|
||||
return sc.getInstance(constructorParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke static.
|
||||
*
|
||||
* @param clazz the clazz
|
||||
* @param method the method
|
||||
* @param parameters the parameters
|
||||
* @return the object
|
||||
* @throws NoSuchMethodException the no such method exception
|
||||
* @throws SecurityException the security exception
|
||||
* @throws IllegalAccessException the illegal access exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws InvocationTargetException the invocation target exception
|
||||
*/
|
||||
public static Object invokeStatic(String clazz, String method,
|
||||
Object... parameters) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
SandboxClass<?> sc=qualifiedClasses.get(clazz);
|
||||
|
|
|
@ -1,64 +1,104 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class LiquidFlowingNodeParams.
|
||||
*/
|
||||
public class LiquidFlowingNodeParams extends DefaultNodeParams implements
|
||||
LiquidNodeParams {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#calcFlowRate(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public double calcFlowRate(NodePosition pos) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#onLiquidFlow(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public void onLiquidFlow(NodePosition pos) {
|
||||
// pass
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#calcDrainRate(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public double calcDrainRate(NodePosition pos) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#shouldFill(int, int)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldFill(int contacting, int flowing) {
|
||||
return (contacting>=2);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#jumpOffHeight(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double jumpOffHeight(Player player) {
|
||||
return 1.125;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcWalkSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcWalkSpeed(Player player) {
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSprintSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcSprintSpeed(Player player) {
|
||||
return 0.8;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSinkIn(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkIn(Player player, double fallheight) {
|
||||
return 0.4;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSinkEscape(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkEscape(Player player, double fallheight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcBounceHeight(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcBounceHeight(Player player, double fallheight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcFallDamage(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcFallDamage(Player player, double height) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#shouldContinueFall(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldContinueFall(Player player, double height) {
|
||||
return false;
|
||||
|
|
|
@ -1,10 +1,30 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class LiquidNode.
|
||||
*/
|
||||
public class LiquidNode extends MapNode {
|
||||
|
||||
/** The node params. */
|
||||
public final LiquidNodeParams nodeParams;
|
||||
|
||||
/** The liquid levels. */
|
||||
public LiquidNode[] liquidLevels = new LiquidNode[8];
|
||||
|
||||
/** The level. */
|
||||
public int level;
|
||||
|
||||
/**
|
||||
* Instantiates a new liquid node.
|
||||
*
|
||||
* @param nodeparams the nodeparams
|
||||
* @param texture the texture
|
||||
* @param nodeName the node name
|
||||
* @param userFacingName the user facing name
|
||||
* @param lightEmission the light emission
|
||||
*/
|
||||
public LiquidNode(LiquidNodeParams nodeparams, String texture,
|
||||
String nodeName, String userFacingName, int lightEmission) {
|
||||
super(nodeparams, texture, nodeName, userFacingName, lightEmission);
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface LiquidNodeParams.
|
||||
*/
|
||||
public interface LiquidNodeParams extends INodeParams {
|
||||
|
||||
/**
|
||||
* Calculates the liquid output from this liquid
|
||||
*
|
||||
* @param pos
|
||||
* The NodePosition of the liquid's location.
|
||||
* Calculates the liquid output from this liquid.
|
||||
*
|
||||
* @param pos The NodePosition of the liquid's location.
|
||||
* @return A double representing the flow rate, in a fully filled node in 1
|
||||
* second for 1.0
|
||||
*/
|
||||
|
@ -15,8 +18,8 @@ public interface LiquidNodeParams extends INodeParams {
|
|||
/**
|
||||
* Calculate how quickly this liquid should disappear. For
|
||||
* flowRate=drainRate the liquid will be effectively finite.
|
||||
*
|
||||
* @param pos
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return How many full nodes should be filled by a flow in one second.
|
||||
*/
|
||||
public double calcDrainRate(NodePosition pos);
|
||||
|
@ -30,11 +33,10 @@ public interface LiquidNodeParams extends INodeParams {
|
|||
public void onLiquidFlow(NodePosition pos);
|
||||
|
||||
/**
|
||||
* Tell if a liquid area should fill with source(level 0)
|
||||
*
|
||||
* Tell if a liquid area should fill with source(level 0).
|
||||
*
|
||||
* @param contactingSources Number of source nodes contacting.
|
||||
* @param contactingFlowings
|
||||
* Number of flowing nodes contacting.
|
||||
* @param contactingFlowings Number of flowing nodes contacting.
|
||||
* @return Boolean, true if it should fill, and false otherwise.
|
||||
*/
|
||||
public boolean shouldFill(int contactingSources, int contactingFlowings);
|
||||
|
|
|
@ -1,64 +1,104 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class LiquidSourceNodeParams.
|
||||
*/
|
||||
public class LiquidSourceNodeParams extends DefaultNodeParams implements
|
||||
LiquidNodeParams {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#calcFlowRate(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public double calcFlowRate(NodePosition pos) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#onLiquidFlow(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public void onLiquidFlow(NodePosition pos) {
|
||||
// pass
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#calcDrainRate(net.mosstest.scripting.NodePosition)
|
||||
*/
|
||||
@Override
|
||||
public double calcDrainRate(NodePosition pos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.LiquidNodeParams#shouldFill(int, int)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldFill(int contacting, int flowing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#jumpOffHeight(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double jumpOffHeight(Player player) {
|
||||
return 1.125;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcWalkSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcWalkSpeed(Player player) {
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSprintSpeed(net.mosstest.scripting.Player)
|
||||
*/
|
||||
@Override
|
||||
public double calcSprintSpeed(Player player) {
|
||||
return 0.8;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSinkIn(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkIn(Player player, double fallheight) {
|
||||
return 0.4;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcSinkEscape(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcSinkEscape(Player player, double fallheight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcBounceHeight(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcBounceHeight(Player player, double fallheight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#calcFallDamage(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public double calcFallDamage(Player player, double height) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.DefaultNodeParams#shouldContinueFall(net.mosstest.scripting.Player, double)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldContinueFall(Player player, double height) {
|
||||
return false;
|
||||
|
|
|
@ -13,12 +13,28 @@ import net.mosstest.servercore.MapGeneratorException;
|
|||
import net.mosstest.servercore.Messages;
|
||||
import net.mosstest.servercore.MossWorldLoadException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapChunk.
|
||||
*/
|
||||
public class MapChunk {
|
||||
|
||||
/** The pos. */
|
||||
public Position pos;
|
||||
|
||||
/** The light nodes. */
|
||||
int[][][] lightNodes = new int[16][16][16];
|
||||
|
||||
/** The modified. */
|
||||
boolean[][][] modified = new boolean[16][16][16];
|
||||
|
||||
/** The compressed. */
|
||||
boolean compressed;
|
||||
|
||||
/** The db. */
|
||||
transient MapDatabase db;
|
||||
|
||||
/** The Constant MAPCHUNK_SERIALIZATION_VERSION. */
|
||||
static final int MAPCHUNK_SERIALIZATION_VERSION = 1;
|
||||
|
||||
/*
|
||||
|
@ -29,6 +45,14 @@ public class MapChunk {
|
|||
* the start of a new node/run 1: This is repeating a *changed* node. Next
|
||||
* short value identifies node type
|
||||
*/
|
||||
/**
|
||||
* Instantiates a new map chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param light the light
|
||||
* @param db the db
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public MapChunk(Position pos, byte[] light, MapDatabase db)
|
||||
throws IOException {
|
||||
this.db = db;
|
||||
|
@ -86,17 +110,35 @@ public class MapChunk {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load heavies.
|
||||
*/
|
||||
private void loadHeavies() {
|
||||
// TODO Heavies not here yet
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new map chunk.
|
||||
*
|
||||
* @param pos2 the pos2
|
||||
* @param nodes the nodes
|
||||
* @param modified the modified
|
||||
*/
|
||||
public MapChunk(Position pos2, int[][][] nodes, boolean[][][] modified) {
|
||||
this.pos = pos2;
|
||||
this.lightNodes = Arrays.copyOf(nodes, nodes.length);
|
||||
this.modified = modified==null?new boolean[16][16][16]:Arrays.copyOf(modified, modified.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node id.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @return the node id
|
||||
*/
|
||||
public int getNodeId(byte x, byte y, byte z) {
|
||||
return this.lightNodes[x][y][z];
|
||||
}
|
||||
|
@ -104,16 +146,22 @@ public class MapChunk {
|
|||
/**
|
||||
* Updates the chunk to set a node. The chunk is not written to the database
|
||||
* or committed across the network.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param node
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param node the node
|
||||
*/
|
||||
public void setNode(byte x, byte y, byte z, short node) {
|
||||
this.lightNodes[x][y][z] = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write light.
|
||||
*
|
||||
* @param compressed the compressed
|
||||
* @return the byte[]
|
||||
*/
|
||||
public byte[] writeLight(boolean compressed) {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
|
|
@ -9,9 +9,24 @@ import net.mosstest.servercore.INodeManager;
|
|||
import net.mosstest.servercore.MapGeneratorException;
|
||||
import toxi.math.noise.SimplexNoise;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapGenerators.
|
||||
*/
|
||||
public class MapGenerators {
|
||||
|
||||
/** The mg. */
|
||||
private static volatile IMapGenerator mg;
|
||||
|
||||
/**
|
||||
* Sets the default map generator.
|
||||
*
|
||||
* @param g the g
|
||||
* @param nm the nm
|
||||
* @param seed the seed
|
||||
* @param params the params
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
*/
|
||||
public static void setDefaultMapGenerator(IMapGenerator g, INodeManager nm, long seed,
|
||||
Object... params) throws MapGeneratorException {
|
||||
synchronized (MapGenerators.class) {
|
||||
|
@ -20,13 +35,29 @@ public class MapGenerators {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default mapgen.
|
||||
*
|
||||
* @return the default mapgen
|
||||
*/
|
||||
public static IMapGenerator getDefaultMapgen() {
|
||||
return mg;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class FlatMapGenerator.
|
||||
*/
|
||||
public static class FlatMapGenerator implements IMapGenerator {
|
||||
|
||||
/** The seed. */
|
||||
long seed;
|
||||
|
||||
/** The nm. */
|
||||
INodeManager nm;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void init(long seed, INodeManager nm, Object... params)
|
||||
throws MapGeneratorException {
|
||||
|
@ -34,6 +65,9 @@ public class MapGenerators {
|
|||
this.nm=nm;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public MapChunk generateChunk(Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -58,6 +92,9 @@ public class MapGenerators {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public void fillInChunk(int[][][] lightNodes, Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -80,6 +117,9 @@ public class MapGenerators {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void registerOre(MapNode oreNode, double minDepth,
|
||||
double rarity, double clumping, int seed, Object... params) {
|
||||
|
@ -89,22 +129,54 @@ public class MapGenerators {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class SimplexMapGenerator.
|
||||
*/
|
||||
public static class SimplexMapGenerator implements IMapGenerator {
|
||||
|
||||
/** The Constant HEIGHT_AVG. */
|
||||
public static final int HEIGHT_AVG = 0;
|
||||
|
||||
/** The Constant HEIGHT_JITTER. */
|
||||
public static final int HEIGHT_JITTER = 100;
|
||||
|
||||
/** The Constant SIMPLEX_SCALE_FACTOR. */
|
||||
public static final double SIMPLEX_SCALE_FACTOR = 1;
|
||||
|
||||
/** The Constant SIMPLEX_LOCAL_SCALE_FACTOR. */
|
||||
public static final double SIMPLEX_LOCAL_SCALE_FACTOR = 10 * SIMPLEX_SCALE_FACTOR;
|
||||
|
||||
/** The Constant SIMPLEX_ROOT_DEGREE. */
|
||||
public static final double SIMPLEX_ROOT_DEGREE = 2;
|
||||
|
||||
/** The Constant SEA_LEVEL. */
|
||||
public static final int SEA_LEVEL = 0;
|
||||
// todo tweak parameters
|
||||
// TODO finish simplex generator including ores
|
||||
/** The base seed. */
|
||||
long baseSeed;
|
||||
|
||||
/** The elevation seed. */
|
||||
double elevationSeed;
|
||||
|
||||
/** The dirt seed. */
|
||||
double dirtSeed;
|
||||
|
||||
/** The humidity seed. */
|
||||
double humiditySeed;
|
||||
|
||||
/** The elevation noise. */
|
||||
SimplexNoise elevationNoise = new SimplexNoise();
|
||||
|
||||
/** The ores. */
|
||||
ArrayList<Ore> ores = new ArrayList<>();
|
||||
|
||||
/** The nm. */
|
||||
INodeManager nm;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void init(long seed, INodeManager nm,Object... params)
|
||||
throws MapGeneratorException {
|
||||
|
@ -119,6 +191,9 @@ public class MapGenerators {
|
|||
this.humiditySeed = rand.nextInt();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public MapChunk generateChunk(Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -179,6 +254,9 @@ public class MapGenerators {
|
|||
return new MapChunk(pos, lightNodes, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public void fillInChunk(int[][][] lightNodes, Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -237,6 +315,9 @@ public class MapGenerators {
|
|||
} //x
|
||||
} //method
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void registerOre(MapNode oreNode, double minDepth,
|
||||
double rarity, double clumping, int seed, Object... params) {
|
||||
|
@ -244,14 +325,37 @@ public class MapGenerators {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class Ore.
|
||||
*/
|
||||
private class Ore {
|
||||
|
||||
/** The node. */
|
||||
MapNode node;
|
||||
|
||||
/** The noise. */
|
||||
SimplexNoise noise;
|
||||
|
||||
/** The min depth. */
|
||||
double minDepth;
|
||||
|
||||
/** The cutoff. */
|
||||
double cutoff;
|
||||
|
||||
/** The simplex seed position. */
|
||||
double simplexSeedPosition;
|
||||
|
||||
/** The ore seed. */
|
||||
int oreSeed;
|
||||
|
||||
/**
|
||||
* Instantiates a new ore.
|
||||
*
|
||||
* @param node the node
|
||||
* @param seed the seed
|
||||
* @param minDepth the min depth
|
||||
* @param rarity the rarity
|
||||
*/
|
||||
public Ore(MapNode node, int seed, double minDepth, double rarity) {
|
||||
Random random = new Random(seed);
|
||||
this.simplexSeedPosition = 10 * Integer.MAX_VALUE
|
||||
|
@ -263,6 +367,14 @@ public class MapGenerators {
|
|||
this.cutoff = 1.0 / rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check ore.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkOre(long x, long y, long z) {
|
||||
Random r = new Random(SimplexMapGenerator.this.baseSeed
|
||||
- this.oreSeed - x + y - z);
|
||||
|
|
|
@ -2,16 +2,40 @@ package net.mosstest.scripting;
|
|||
|
||||
import net.mosstest.servercore.ItemManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapNode.
|
||||
*/
|
||||
public class MapNode {
|
||||
|
||||
/** The node id. */
|
||||
private short nodeId = 0;
|
||||
|
||||
/** The nodeparams. */
|
||||
public final transient INodeParams nodeparams;
|
||||
|
||||
/** The texture. */
|
||||
public final transient String texture;
|
||||
|
||||
/** The node name. */
|
||||
public String nodeName;
|
||||
|
||||
/** The user facing name. */
|
||||
public String userFacingName;
|
||||
|
||||
/** The light emission. */
|
||||
public int lightEmission;
|
||||
|
||||
/** The drop item. */
|
||||
public MossItem dropItem;
|
||||
|
||||
/** The is buildable to. */
|
||||
public boolean isBuildableTo = true;
|
||||
|
||||
/** The draw type. */
|
||||
public DrawType drawType = DrawType.DRAW_BLOCK;
|
||||
|
||||
/** The box origin z. */
|
||||
public float boxOriginX = 0, boxOriginY = 0, boxOriginZ = 0;
|
||||
/**
|
||||
* Each of these is 0.5 for the unit box, since each vertex is +/-0.5 from
|
||||
|
@ -19,6 +43,15 @@ public class MapNode {
|
|||
*/
|
||||
public float lengthX = 0.5f, lengthY = 0.5f, lengthZ = 0.5f;
|
||||
|
||||
/**
|
||||
* Instantiates a new map node.
|
||||
*
|
||||
* @param nodeparams the nodeparams
|
||||
* @param texture the texture
|
||||
* @param nodeName the node name
|
||||
* @param userFacingName the user facing name
|
||||
* @param lightEmission the light emission
|
||||
*/
|
||||
public MapNode(INodeParams nodeparams, String texture, String nodeName,
|
||||
String userFacingName, int lightEmission) {
|
||||
this.nodeparams = nodeparams;
|
||||
|
@ -31,6 +64,16 @@ public class MapNode {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the by bounds.
|
||||
*
|
||||
* @param x1 the x1
|
||||
* @param x2 the x2
|
||||
* @param y1 the y1
|
||||
* @param y2 the y2
|
||||
* @param z1 the z1
|
||||
* @param z2 the z2
|
||||
*/
|
||||
public void setByBounds(float x1, float x2, float y1, float y2, float z1,
|
||||
float z2) {
|
||||
this.boxOriginX = (x1 + x2) / 2;
|
||||
|
@ -41,6 +84,16 @@ public class MapNode {
|
|||
this.lengthZ = Math.abs(z2 - z1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the by size.
|
||||
*
|
||||
* @param originX the origin x
|
||||
* @param originY the origin y
|
||||
* @param originZ the origin z
|
||||
* @param lengthX the length x
|
||||
* @param lengthY the length y
|
||||
* @param lengthZ the length z
|
||||
*/
|
||||
public void setBySize(float originX, float originY, float originZ,
|
||||
float lengthX, float lengthY, float lengthZ) {
|
||||
this.boxOriginX = originX;
|
||||
|
@ -51,6 +104,14 @@ public class MapNode {
|
|||
this.lengthZ = lengthZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new map node.
|
||||
*
|
||||
* @param textures the textures
|
||||
* @param nodeName the node name
|
||||
* @param userFacingName the user facing name
|
||||
* @param lightEmission the light emission
|
||||
*/
|
||||
public MapNode(String textures, String nodeName, String userFacingName,
|
||||
int lightEmission) {
|
||||
this.nodeparams = new DefaultNodeParams();
|
||||
|
@ -62,6 +123,11 @@ public class MapNode {
|
|||
this.dropItem = ItemManager.getForNode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node id.
|
||||
*
|
||||
* @return the node id
|
||||
*/
|
||||
public short getNodeId() {
|
||||
return this.nodeId;
|
||||
}
|
||||
|
@ -69,13 +135,16 @@ public class MapNode {
|
|||
/**
|
||||
* Sets node ID. Scripts should not call this except under special
|
||||
* circumstances.
|
||||
*
|
||||
* @param nodeId
|
||||
*
|
||||
* @param nodeId the new node id
|
||||
*/
|
||||
public void setNodeId(short nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -84,6 +153,9 @@ public class MapNode {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -102,19 +174,23 @@ public class MapNode {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new map node.
|
||||
*/
|
||||
protected MapNode() {
|
||||
this.texture = null;
|
||||
this.nodeparams = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Enum DrawType.
|
||||
*/
|
||||
public enum DrawType {
|
||||
/**
|
||||
* Standard appearance for blocks
|
||||
*/
|
||||
|
||||
/** Standard appearance for blocks. */
|
||||
DRAW_BLOCK,
|
||||
/**
|
||||
* Drawtype for liquids
|
||||
*/
|
||||
|
||||
/** Drawtype for liquids. */
|
||||
DRAW_LIQUID,
|
||||
/**
|
||||
* Drawtype for plantlike materials. In this draw, two planes with the
|
||||
|
|
|
@ -2,21 +2,56 @@ package net.mosstest.scripting;
|
|||
|
||||
import net.mosstest.scripting.MapNode.DrawType;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapNodeBuilder.
|
||||
*/
|
||||
public class MapNodeBuilder {
|
||||
|
||||
/** The name. */
|
||||
private String name;
|
||||
|
||||
/** The ui name. */
|
||||
private String uiName;
|
||||
|
||||
/** The params. */
|
||||
private INodeParams params;
|
||||
|
||||
/** The light emission. */
|
||||
private int lightEmission = 0;
|
||||
|
||||
/** The drop item. */
|
||||
private MossItem dropItem;
|
||||
|
||||
/** The is buildable to. */
|
||||
private boolean isBuildableTo = true;
|
||||
|
||||
/** The draw type. */
|
||||
private DrawType drawType = DrawType.DRAW_BLOCK;
|
||||
|
||||
/** The box origin z. */
|
||||
private float boxOriginX = 0, boxOriginY = 0, boxOriginZ = 0;
|
||||
|
||||
/** The length z. */
|
||||
private float lengthX = 0.5f, lengthY = 0.5f, lengthZ = 0.5f;
|
||||
|
||||
/**
|
||||
* Instantiates a new map node builder.
|
||||
*
|
||||
* @param name the name
|
||||
* @param uiName the ui name
|
||||
*/
|
||||
public MapNodeBuilder(String name, String uiName) {
|
||||
this.name = name;
|
||||
this.uiName = uiName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Params.
|
||||
*
|
||||
* @param params the params
|
||||
* @return the map node builder
|
||||
*/
|
||||
public MapNodeBuilder params(INodeParams params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapStructure.
|
||||
*/
|
||||
public abstract class MapStructure {
|
||||
|
||||
/** The mse. */
|
||||
protected final MossScriptEnv mse;
|
||||
|
||||
/** The seed. */
|
||||
protected final long seed;
|
||||
/**
|
||||
* Gets a node at a certain position relative to the offset.
|
||||
|
@ -42,8 +50,10 @@ public abstract class MapStructure {
|
|||
public abstract int getZOffset();
|
||||
|
||||
/**
|
||||
* @param mse
|
||||
* @param seed
|
||||
* Instantiates a new map structure.
|
||||
*
|
||||
* @param mse the mse
|
||||
* @param seed the seed
|
||||
*/
|
||||
public MapStructure(MossScriptEnv mse, long seed) {
|
||||
this.mse = mse;
|
||||
|
|
|
@ -3,19 +3,40 @@ package net.mosstest.scripting;
|
|||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Messages.
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
/** The Constant BUNDLE_NAME. */
|
||||
private static final String BUNDLE_NAME = "net.mosstest.scripting.messages"; //$NON-NLS-1$
|
||||
|
||||
/** The res bundle. */
|
||||
private static ResourceBundle resBundle = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
/**
|
||||
* Change language.
|
||||
*
|
||||
* @param identifier the identifier
|
||||
*/
|
||||
public static void changeLanguage(String identifier) {
|
||||
resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new messages.
|
||||
*/
|
||||
private Messages() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the string
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return resBundle.getString(key);
|
||||
|
|
|
@ -2,7 +2,27 @@ package net.mosstest.scripting;
|
|||
|
||||
import net.mosstest.servercore.ScriptSandboxBorderToken;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossEvent.
|
||||
*/
|
||||
public class MossEvent {
|
||||
|
||||
/**
|
||||
* Instantiates a new moss event.
|
||||
*
|
||||
* @param type the type
|
||||
* @param actor the actor
|
||||
* @param pos the pos
|
||||
* @param nodeBefore the node before
|
||||
* @param nodeAfter the node after
|
||||
* @param recvEntity the recv entity
|
||||
* @param fspec the fspec
|
||||
* @param action the action
|
||||
* @param damage the damage
|
||||
* @param initiatingMessage the initiating message
|
||||
* @param tok the tok
|
||||
*/
|
||||
public MossEvent(EvtType type, Player actor, NodePosition pos, MapNode nodeBefore, MapNode nodeAfter,
|
||||
Entity recvEntity, MossFormspec fspec, MossInventoryAction action, double damage,
|
||||
String initiatingMessage, ScriptSandboxBorderToken tok) {
|
||||
|
@ -20,18 +40,76 @@ public class MossEvent {
|
|||
this.initiatingMessage = initiatingMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Enum EvtType.
|
||||
*/
|
||||
public enum EvtType {
|
||||
EVT_DIEPLAYER, EVT_DIGNODE, EVT_GENERATE, EVT_JOINPLAYER, EVT_QUITPLAYER, EVT_NEWPLAYER, EVT_PLACENODE, EVT_FSPEC_OPEN, EVT_FSPEC_SUBMIT, EVT_FSPEC_INVACTION, EVT_THREADSTOP, EVT_ENTITY_PUNCH, EVT_ENTITY_DEATH, EVT_CHATMESSAGE, EVT_SHUTDOWN, EVT_CHATCOMMAND, EVT_NODEMOVE, EVT_PLAYERDAMAGE
|
||||
|
||||
/** The evt dieplayer. */
|
||||
EVT_DIEPLAYER,
|
||||
/** The evt dignode. */
|
||||
EVT_DIGNODE,
|
||||
/** The evt generate. */
|
||||
EVT_GENERATE,
|
||||
/** The evt joinplayer. */
|
||||
EVT_JOINPLAYER,
|
||||
/** The evt quitplayer. */
|
||||
EVT_QUITPLAYER,
|
||||
/** The evt newplayer. */
|
||||
EVT_NEWPLAYER,
|
||||
/** The evt placenode. */
|
||||
EVT_PLACENODE,
|
||||
/** The evt fspec open. */
|
||||
EVT_FSPEC_OPEN,
|
||||
/** The evt fspec submit. */
|
||||
EVT_FSPEC_SUBMIT,
|
||||
/** The evt fspec invaction. */
|
||||
EVT_FSPEC_INVACTION,
|
||||
/** The evt threadstop. */
|
||||
EVT_THREADSTOP,
|
||||
/** The evt entity punch. */
|
||||
EVT_ENTITY_PUNCH,
|
||||
/** The evt entity death. */
|
||||
EVT_ENTITY_DEATH,
|
||||
/** The evt chatmessage. */
|
||||
EVT_CHATMESSAGE,
|
||||
/** The evt shutdown. */
|
||||
EVT_SHUTDOWN,
|
||||
/** The evt chatcommand. */
|
||||
EVT_CHATCOMMAND,
|
||||
/** The evt nodemove. */
|
||||
EVT_NODEMOVE,
|
||||
/** The evt playerdamage. */
|
||||
EVT_PLAYERDAMAGE
|
||||
}
|
||||
|
||||
/** The type. */
|
||||
public final MossEvent.EvtType type;
|
||||
|
||||
/** The actor. */
|
||||
public final Player actor; // Player no longer extends entity
|
||||
|
||||
/** The pos. */
|
||||
public final NodePosition pos;
|
||||
|
||||
/** The node before. */
|
||||
public final MapNode nodeBefore;
|
||||
|
||||
/** The node after. */
|
||||
public final MapNode nodeAfter;
|
||||
|
||||
/** The recv entity. */
|
||||
public final Entity recvEntity;
|
||||
|
||||
/** The damage. */
|
||||
public final double damage;
|
||||
|
||||
/** The fspec. */
|
||||
public final MossFormspec fspec;
|
||||
|
||||
/** The action. */
|
||||
public final MossInventoryAction action;
|
||||
|
||||
/** The initiating message. */
|
||||
public final String initiatingMessage;
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use net.mosstest.scripting.handlers.* instead.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MossEventHandler {
|
||||
/**
|
||||
* Process an event
|
||||
*
|
||||
* @param myEvent
|
||||
* The event
|
||||
* @return `true` to skip all future handlers for this event, false to run
|
||||
* the next handler.
|
||||
* @throws MossScriptException
|
||||
*/
|
||||
|
||||
boolean processEvent(MossEvent myEvent) throws MossScriptException;
|
||||
}
|
|
@ -4,6 +4,9 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
|
||||
/**
|
||||
* The Class MossFormspec.
|
||||
*/
|
||||
public class MossFormspec {
|
||||
|
||||
}
|
||||
|
|
|
@ -4,15 +4,36 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossInventory.
|
||||
*/
|
||||
public class MossInventory {
|
||||
|
||||
/** The max stack size. */
|
||||
final int maxStackSize;
|
||||
|
||||
/** The stacks. */
|
||||
final MossItem.Stack[][] stacks;
|
||||
|
||||
/**
|
||||
* Instantiates a new moss inventory.
|
||||
*
|
||||
* @param maxStackSize the max stack size
|
||||
* @param rows the rows
|
||||
* @param cols the cols
|
||||
*/
|
||||
public MossInventory(int maxStackSize, int rows, int cols) {
|
||||
this.maxStackSize = maxStackSize;
|
||||
this.stacks = new MossItem.Stack[rows][cols];
|
||||
}
|
||||
|
||||
/**
|
||||
* To bytes.
|
||||
*
|
||||
* @return the byte[]
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public byte[] toBytes() throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
|
@ -29,6 +50,12 @@ public class MossInventory {
|
|||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the item.
|
||||
*
|
||||
* @param stack the stack
|
||||
* @return the double
|
||||
*/
|
||||
public synchronized double addItem(MossItem.Stack stack) {
|
||||
double added = 0;
|
||||
double maxAddable = stack.item.mayStack ? this.maxStackSize : 1;
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossInventoryAction.
|
||||
*/
|
||||
public class MossInventoryAction {
|
||||
|
||||
/** The from. */
|
||||
MossInventory from;
|
||||
|
||||
/** The to. */
|
||||
MossInventory to;
|
||||
|
||||
/** The moved. */
|
||||
MossItem.Stack moved;
|
||||
|
||||
/**
|
||||
* Accept as stated.
|
||||
*/
|
||||
public void acceptAsStated() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
|
|
@ -2,17 +2,43 @@ package net.mosstest.scripting;
|
|||
|
||||
import net.mosstest.servercore.MossFile;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossItem.
|
||||
*/
|
||||
public class MossItem {
|
||||
|
||||
/** The item id. */
|
||||
private short itemId = 0;
|
||||
|
||||
/**
|
||||
* Sets the item id.
|
||||
*
|
||||
* @param itemId the new item id
|
||||
*/
|
||||
public void setItemId(short itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item id.
|
||||
*
|
||||
* @return the item id
|
||||
*/
|
||||
public short getItemId() {
|
||||
return this.itemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new moss item.
|
||||
*
|
||||
* @param invTex the inv tex
|
||||
* @param wieldTex the wield tex
|
||||
* @param invWeight the inv weight
|
||||
* @param mayStack the may stack
|
||||
* @param displayName the display name
|
||||
* @param technicalName the technical name
|
||||
*/
|
||||
public MossItem(String invTex, String wieldTex, double invWeight,
|
||||
boolean mayStack, String displayName, String technicalName) {
|
||||
this.invTex = invTex;
|
||||
|
@ -23,19 +49,41 @@ public class MossItem {
|
|||
this.technicalName = technicalName;
|
||||
}
|
||||
|
||||
/** The inv tex. */
|
||||
final String invTex;
|
||||
|
||||
/** The wield tex. */
|
||||
final String wieldTex;
|
||||
|
||||
/** The inv weight. */
|
||||
final double invWeight;
|
||||
|
||||
/** The may stack. */
|
||||
boolean mayStack;
|
||||
|
||||
/** The display name. */
|
||||
final String displayName;
|
||||
|
||||
/** The technical name. */
|
||||
final String technicalName;
|
||||
|
||||
/**
|
||||
* The Class Stack.
|
||||
*/
|
||||
public static class Stack {
|
||||
|
||||
/**
|
||||
* Instantiates a new stack.
|
||||
*
|
||||
* @param item the item
|
||||
* @param amount the amount
|
||||
*/
|
||||
public Stack(MossItem item, double amount) {
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/** The item. */
|
||||
final MossItem item;
|
||||
/**
|
||||
* If amount is not an integer then it is a stack with wear. Once zero
|
||||
|
@ -44,6 +92,9 @@ public class MossItem {
|
|||
double amount;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -55,6 +106,9 @@ public class MossItem {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
|
@ -72,10 +126,20 @@ public class MossItem {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name.
|
||||
*
|
||||
* @return the display name
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the technical name.
|
||||
*
|
||||
* @return the technical name
|
||||
*/
|
||||
public String getTechnicalName() {
|
||||
return technicalName;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.iq80.leveldb.DB;
|
||||
|
||||
import net.mosstest.scripting.MossItem.Stack;
|
||||
import net.mosstest.scripting.events.IMossEvent;
|
||||
import net.mosstest.scripting.handlers.MossEventHandler;
|
||||
import net.mosstest.scripting.handlers.MossNodeChangeHandler;
|
||||
import net.mosstest.servercore.FuturesProcessor;
|
||||
import net.mosstest.servercore.INodeManager;
|
||||
import net.mosstest.servercore.MapGeneratorException;
|
||||
|
@ -13,8 +13,8 @@ import net.mosstest.servercore.MossWorldLoadException;
|
|||
import net.mosstest.servercore.NodeCache;
|
||||
import net.mosstest.servercore.ScriptSandboxBorderToken;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
*
|
||||
* This class is used by scripts and script-facing portions of Mosstest. Methods
|
||||
* restricted to be called from trusted Java-side shall pass a
|
||||
* {@link ScriptSandboxBorderToken}. Each event fired will run in the thread
|
||||
|
@ -35,276 +35,33 @@ import net.mosstest.servercore.ScriptSandboxBorderToken;
|
|||
* An event handler may interrupt handling of the event so that no further event
|
||||
* handlers nor the default are ever called, by throwing an instance of
|
||||
* {@link EventProcessingCompletedSignal}.
|
||||
*
|
||||
*
|
||||
* @author rarkenin
|
||||
* @since 0.0
|
||||
* @version 0.0
|
||||
* @since 0.0
|
||||
*/
|
||||
public class MossScriptEnv {
|
||||
|
||||
/*
|
||||
* IMPORTANT, IMPORTANT, IMPORTANT. VERY IMPORTANT. THIS CLASS IS THE ONLY
|
||||
* CLASS THAT SCRIPTS CAN ACCESS. MAKE ALL FIELDS AND METHODS PRIVATE UNLESS
|
||||
* IT IS INTENDED TO FACE UNTRUSTED SCRIPTS.
|
||||
/**
|
||||
* Register node change handler.
|
||||
*
|
||||
* @param h the h
|
||||
*/
|
||||
private EnumMap<MossEvent.EvtType, ArrayList<MossEventHandler>> registeredScriptEvents = new EnumMap<>(
|
||||
MossEvent.EvtType.class);
|
||||
public void registerNodeChangeHandler(MossNodeChangeHandler h) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private HashMap<Class<? extends IMossEvent>, ArrayList<MossEventHandler>> eventHandlers;
|
||||
|
||||
private ScriptableDatabase db;
|
||||
|
||||
private NodeCache nc;
|
||||
|
||||
private FuturesProcessor fp;
|
||||
|
||||
private INodeManager nm;
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a player death. This will be run in
|
||||
* the event processor thread pool. The default handler shall respawn the
|
||||
* player at the spawnpoint and set health to default.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnDieplayer(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_DIEPLAYER).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a node being dug. This will be run
|
||||
* in the event processor thread pool. The default handler will remove the
|
||||
* node and add its drop to the inventory of the digger if possible.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnDignode(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_DIGNODE).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on map generation. This will be run in
|
||||
* the event processor thread pool before the default map generator. The
|
||||
* default map generator shall create the chunk to be a recreation of a
|
||||
* landscape.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnGenerate(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_GENERATE).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a player joining. This will be run
|
||||
* in the event processor thread pool. The default handler will be called
|
||||
* before any script-specified handlers.
|
||||
* {@link EventProcessingCompletedSignal} will still bypass future handlers
|
||||
* but not default ones. The default handler initializes player data in
|
||||
* memory from the database.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnJoinplayer(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_JOINPLAYER)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a player quitting. This will be run
|
||||
* in the event processor thread pool.
|
||||
* {@link EventProcessingCompletedSignal} will bypass future handlers but
|
||||
* the default handler will be run even if the signal is thrown. The default
|
||||
* handler will clean up the player in memory.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnQuitplayer(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_QUITPLAYER)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a new player registering and
|
||||
* entering. This will be run in the event processor thread pool. The
|
||||
* default handler will be called before any script-specified handlers.
|
||||
* {@link EventProcessingCompletedSignal} will still bypass future handlers
|
||||
* but not default ones. The default handler initializes player data in
|
||||
* memory and the database. No items are given by default.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnNewplayer(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_NEWPLAYER).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a node being placed. This will be
|
||||
* run in the event processor thread pool. The default handler removes the
|
||||
* item from the placer's inventory and puts down a node or entity.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnPlacenode(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_PLACENODE).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a formspec being opened. This will
|
||||
* be run in the event processor thread pool. A formspec is an XML-based 2D
|
||||
* script-specified UI. The default handler is defined in the formspec. This
|
||||
* is a way of catch-all for formspecs and shouldn't be used for
|
||||
* implementing one formspec.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnFspecOpen(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_FSPEC_OPEN)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a formspec being submitted. This
|
||||
* will be run in the event processor thread pool. This is a catch-all
|
||||
* method and the default handler created in the formspec should be used for
|
||||
* implementing behavior.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnFspecSubmit(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_FSPEC_SUBMIT)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on an inventory action. This will be
|
||||
* run in the event processor thread pool. The default handler performs the
|
||||
* action as-is.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnInvAction(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_FSPEC_INVACTION)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on an entity punch. This will be run in
|
||||
* the event processor thread pool. The default handler performs no action.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnEntityPunch(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_ENTITY_PUNCH)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a player taking damage. This will be
|
||||
* run in the event processor thread pool. The default handler causes the
|
||||
* player to take the damage.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnPlayerDamage(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_PLAYERDAMAGE)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on entity death. This will be run in
|
||||
* the event processor thread pool. The default handler performs no action
|
||||
* aside from the removal of said entity.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnEntityDeath(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_ENTITY_DEATH)
|
||||
.add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a chat message from a client. This
|
||||
* will be run in the event processor thread pool. The default handler sends
|
||||
* the message to all players.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnChatMessage(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_CHATMESSAGE).add(
|
||||
r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on server shutdown. This will be run in
|
||||
* the event processor thread pool. The default handler calls internal
|
||||
* shutdown functions and cannot be bypassed.
|
||||
*
|
||||
* Note that in the case of an error causing shutdown of the server the
|
||||
* script API may be unavailable or in an inconsistent state so shutdown
|
||||
* actions cannot be guaranteed to run. They will always be run on a clean
|
||||
* shutdown.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnShutdown(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_SHUTDOWN).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a chat command. This will be run in
|
||||
* the event processor thread pool. The default handler will display an
|
||||
* invalid command message. Handlers should <b>always</b> override the
|
||||
* default except in special circumstances.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnChatCommand(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_CHATCOMMAND).add(
|
||||
r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event hander to fire on a node move. This will be run in the
|
||||
* event processor thread pool. The default handler moves the node.
|
||||
*
|
||||
* @param r
|
||||
* The event handler to register.
|
||||
*/
|
||||
void registerOnNodeMove(MossEventHandler r) {
|
||||
this.registeredScriptEvents.get(MossEvent.EvtType.EVT_NODEMOVE).add(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets handlers for an event type in the form of an {@link ArrayList} for
|
||||
* Mosstest internal use. At this time due to limited identification of each
|
||||
* event there is no support for scripts accessing this directly.
|
||||
*
|
||||
* @param type
|
||||
* A {@link MossEvent.EvtType} enumerable value specifying the
|
||||
* event type to retrieve.
|
||||
* @param tok
|
||||
* A {@link ScriptSandboxBorderToken} to be used for ensuring
|
||||
* that scripts cannot call this method.
|
||||
* @return An {@link ArrayList} of {@link MossEventHandler} objects.
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public ArrayList<MossEventHandler> getHandlers(MossEvent.EvtType type,
|
||||
ScriptSandboxBorderToken tok) throws SecurityException {
|
||||
if (!(tok instanceof ScriptSandboxBorderToken) || tok == null)
|
||||
throw new SecurityException(
|
||||
"Attempt to access controlled resources in the script DMZ."); //$NON-NLS-1$
|
||||
return this.registeredScriptEvents.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a chat message to a player.
|
||||
|
@ -377,9 +134,9 @@ public class MossScriptEnv {
|
|||
* default inventory, adding to the first available partial stack. If no
|
||||
* partial stacks are available the item is added to the first open slot in
|
||||
* the inventory.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*
|
||||
* @param player the player
|
||||
* @param item the item
|
||||
* @return True if the item could be added, false if the item could not be
|
||||
* added due to insufficient space.
|
||||
*/
|
||||
|
@ -391,12 +148,9 @@ public class MossScriptEnv {
|
|||
* Sets a node of the world to a given type. This cannot be called on a
|
||||
* NodePosition with an existing solid node; use
|
||||
* {@link #removeNode(NodePosition)} first.
|
||||
*
|
||||
* @param pos
|
||||
* The position at which to set a node.
|
||||
* @param node
|
||||
* The node to place at that position.
|
||||
* @throws MapGeneratorException
|
||||
*
|
||||
* @param pos The position at which to set a node.
|
||||
* @param node The node to place at that position.
|
||||
*/
|
||||
public void setNode(NodePosition pos, MapNode node) {
|
||||
MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk);
|
||||
|
@ -408,10 +162,8 @@ public class MossScriptEnv {
|
|||
/**
|
||||
* Removes a node, setting it to air. This may be called on a NodePosition
|
||||
* with an existing solid node.
|
||||
*
|
||||
* @param pos
|
||||
* The NodePosition at which to remove the node.
|
||||
* @throws MapGeneratorException
|
||||
*
|
||||
* @param pos The NodePosition at which to remove the node.
|
||||
*/
|
||||
public void removeNode(NodePosition pos) {
|
||||
MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk);
|
||||
|
@ -423,12 +175,11 @@ public class MossScriptEnv {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the MapNode at a certain location
|
||||
*
|
||||
* @param pos
|
||||
* The location at which to get the node
|
||||
* Get the MapNode at a certain location.
|
||||
*
|
||||
* @param pos The location at which to get the node
|
||||
* @return A MapNode object representing the node at that location.
|
||||
* @throws MapGeneratorException
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
*/
|
||||
public MapNode getNode(NodePosition pos) throws MapGeneratorException {
|
||||
return this.nm.getNode((short) this.nc.getChunk(pos.chunk).getNodeId(
|
||||
|
@ -438,26 +189,21 @@ public class MossScriptEnv {
|
|||
|
||||
/**
|
||||
* Register a new MapNode in the node manager.
|
||||
*
|
||||
* @param sysname
|
||||
* The name such as default:dirt to set. The prefix mg: is used
|
||||
*
|
||||
* @param sysname The name such as default:dirt to set. The prefix mg: is used
|
||||
* for mapgen-specific nodes, and should be done by creating a
|
||||
* node with a different prefix and aliasing mg:foo to it.
|
||||
* @param userFacingName
|
||||
* The name to display in the UI, such as Dirt or Iron Ore
|
||||
* @param params
|
||||
* An implementation of the {@link LiquidNodeParams} interface
|
||||
* @param userFacingName The name to display in the UI, such as Dirt or Iron Ore
|
||||
* @param params An implementation of the {@link LiquidNodeParams} interface
|
||||
* detailing the action of the node.
|
||||
* {@link LiquidSourceNodeParams} is a default that is
|
||||
* applicable to most liquids with near-water viscosity.
|
||||
* @param textures
|
||||
* A string stating the filename of the textures image.
|
||||
* @param light
|
||||
* The amount of light from 0 to 255 to be emitted.
|
||||
* @param textures A string stating the filename of the textures image.
|
||||
* @param isLiquid the is liquid
|
||||
* @param light The amount of light from 0 to 255 to be emitted.
|
||||
* @return The MapNode object that has been created and added to the
|
||||
* manager.
|
||||
* @throws MossWorldLoadException
|
||||
* If an exception occurs during the execution of the
|
||||
* @throws MossWorldLoadException If an exception occurs during the execution of the
|
||||
* registering.
|
||||
*/
|
||||
public MapNode registerNode(String sysname, String userFacingName,
|
||||
|
@ -471,26 +217,21 @@ public class MossScriptEnv {
|
|||
|
||||
/**
|
||||
* Register a new MapNode in the node manager.
|
||||
*
|
||||
* @param sysname
|
||||
* The name such as default:lava to set. The prefix mg: is used
|
||||
*
|
||||
* @param sysname The name such as default:lava to set. The prefix mg: is used
|
||||
* for mapgen-specific nodes, and should be done by creating a
|
||||
* node with a different prefix and aliasing mg:foo to it.
|
||||
* @param userFacingName
|
||||
* The name to display in the UI, such as Lava or Iron Ore
|
||||
* @param params
|
||||
* An implementation of the {@link INodeParams} interface
|
||||
* @param userFacingName The name to display in the UI, such as Lava or Iron Ore
|
||||
* @param params An implementation of the {@link INodeParams} interface
|
||||
* detailing the action of the node. {@link AirNodeParams} and
|
||||
* {@link DefaultNodeParams} are valid for air-like(display only)
|
||||
* and standard solid blocks, respectively.
|
||||
* @param textures
|
||||
* A string stating the filename of the textures image.
|
||||
* @param light
|
||||
* The amount of light from 0 to 255 to be emitted.
|
||||
* @param sourceParams the source params
|
||||
* @param textures A string stating the filename of the textures image.
|
||||
* @param light The amount of light from 0 to 255 to be emitted.
|
||||
* @return The MapNode object that has been created and added to the
|
||||
* manager.
|
||||
* @throws MossWorldLoadException
|
||||
* If an exception occurs during the execution of the
|
||||
* @throws MossWorldLoadException If an exception occurs during the execution of the
|
||||
* registering.
|
||||
*/
|
||||
public LiquidNode registerLiquid(String sysname, String userFacingName,
|
||||
|
@ -593,26 +334,65 @@ public class MossScriptEnv {
|
|||
return nd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inv by name.
|
||||
*
|
||||
* @param player the player
|
||||
* @param name the name
|
||||
* @return the inv by name
|
||||
*/
|
||||
public MossInventory getInvByName(Player player, String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the inv by name.
|
||||
*
|
||||
* @param p the p
|
||||
* @param name the name
|
||||
* @return the moss inventory
|
||||
*/
|
||||
public MossInventory createInvByName(Player p, String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player by name.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the player by name
|
||||
*/
|
||||
public Player getPlayerByName(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node by name.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the node by name
|
||||
*/
|
||||
public MapNode getNodeByName(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the db.
|
||||
*
|
||||
* @return the db
|
||||
*/
|
||||
public ScriptableDatabase getDb() {
|
||||
return this.db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new moss script env.
|
||||
*
|
||||
* @param db the db
|
||||
* @param nc the nc
|
||||
* @param fp the fp
|
||||
* @param nm the nm
|
||||
*/
|
||||
public MossScriptEnv(ScriptableDatabase db, NodeCache nc,
|
||||
FuturesProcessor fp, INodeManager nm) {
|
||||
this.db = db;
|
||||
|
@ -621,8 +401,19 @@ public class MossScriptEnv {
|
|||
this.nm = nm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the futures processor.
|
||||
*
|
||||
* @return the futures processor
|
||||
*/
|
||||
public FuturesProcessor getFuturesProcessor() {
|
||||
return this.fp;
|
||||
}
|
||||
|
||||
public ArrayList<MossEventHandler> getEventHandlers(
|
||||
Class<? extends IMossEvent> class1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
/**
|
||||
* The Class MossScriptException.
|
||||
*/
|
||||
public class MossScriptException extends Exception {
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,22 @@ package net.mosstest.scripting;
|
|||
|
||||
import net.mosstest.servercore.MossFile;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossTool.
|
||||
*/
|
||||
public class MossTool extends MossItem {
|
||||
|
||||
/**
|
||||
* Instantiates a new moss tool.
|
||||
*
|
||||
* @param invTex the inv tex
|
||||
* @param wieldTex the wield tex
|
||||
* @param invWeight the inv weight
|
||||
* @param mayStack the may stack
|
||||
* @param displayName the display name
|
||||
* @param technicalName the technical name
|
||||
*/
|
||||
public MossTool(String invTex, String wieldTex, double invWeight,
|
||||
boolean mayStack, String displayName, String technicalName) {
|
||||
super(invTex, wieldTex, invWeight, mayStack, displayName, technicalName);
|
||||
|
@ -11,6 +25,9 @@ public class MossTool extends MossItem {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* The Enum InteractType.
|
||||
*/
|
||||
public enum InteractType {
|
||||
/**
|
||||
* Interact by cracking, i.e. by a pickaxe.
|
||||
|
@ -37,15 +54,23 @@ public class MossTool extends MossItem {
|
|||
*/
|
||||
INTERACT_FLESHY,
|
||||
|
||||
/**
|
||||
* Interact as a hard block
|
||||
*/
|
||||
/** Interact as a hard block. */
|
||||
INTERACT_BLOCKY,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Interface IToolParams.
|
||||
*/
|
||||
public interface IToolParams {
|
||||
|
||||
/**
|
||||
* Wear tool dig.
|
||||
*
|
||||
* @param dug the dug
|
||||
* @return the double
|
||||
*/
|
||||
public double wearToolDig(MapNode dug);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,29 @@ import java.io.DataInputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class NodePosition.
|
||||
*/
|
||||
public class NodePosition {
|
||||
|
||||
/** The zl. */
|
||||
public final byte xl, yl, zl;
|
||||
|
||||
/** The chunk. */
|
||||
public final Position chunk;
|
||||
|
||||
/**
|
||||
* Instantiates a new node position.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param realm the realm
|
||||
* @param xl the xl
|
||||
* @param yl the yl
|
||||
* @param zl the zl
|
||||
*/
|
||||
public NodePosition(int x, int y, int z, int realm, byte xl, byte yl,
|
||||
byte zl) {
|
||||
chunk = new Position(x, y, z, realm);
|
||||
|
@ -18,6 +37,12 @@ public class NodePosition {
|
|||
this.zl = zl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new node position.
|
||||
*
|
||||
* @param bytes the bytes
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public NodePosition(byte[] bytes) throws IOException {
|
||||
super();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
|
@ -30,6 +55,9 @@ public class NodePosition {
|
|||
// this.isValid = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -41,6 +69,9 @@ public class NodePosition {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -74,6 +105,11 @@ public class NodePosition {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* To bytes.
|
||||
*
|
||||
* @return the byte[]
|
||||
*/
|
||||
public byte[] toBytes() {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
|
|
|
@ -13,37 +13,94 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import net.mosstest.servercore.PlayerCommunicator;
|
||||
import net.mosstest.servercore.RenderProcessor;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Player.
|
||||
*/
|
||||
public class Player {
|
||||
|
||||
/** The inventories. */
|
||||
private HashMap<String, MossInventory> inventories = new HashMap<>();
|
||||
|
||||
/** The name. */
|
||||
public final String name;
|
||||
|
||||
/** The xoffset. */
|
||||
public volatile double xoffset;
|
||||
|
||||
/** The yoffset. */
|
||||
public volatile double yoffset;
|
||||
|
||||
/** The zoffset. */
|
||||
public volatile double zoffset;
|
||||
|
||||
/** The xchk. */
|
||||
public volatile int xchk;
|
||||
|
||||
/** The ychk. */
|
||||
public volatile int ychk;
|
||||
|
||||
/** The zchk. */
|
||||
public volatile int zchk;
|
||||
|
||||
/** The x velocity. */
|
||||
public volatile double xVelocity;
|
||||
|
||||
/** The y velocity. */
|
||||
public volatile double yVelocity;
|
||||
|
||||
/** The z velocity. */
|
||||
public volatile double zVelocity;
|
||||
|
||||
/** The oldx. */
|
||||
public volatile double oldx;
|
||||
|
||||
/** The oldy. */
|
||||
public volatile double oldy;
|
||||
|
||||
/** The oldz. */
|
||||
public volatile double oldz;
|
||||
|
||||
/** The oldxchk. */
|
||||
public volatile int oldxchk;
|
||||
|
||||
/** The oldychk. */
|
||||
public volatile int oldychk;
|
||||
|
||||
/** The oldzchk. */
|
||||
public volatile int oldzchk;
|
||||
|
||||
/** The last anticheat millis. */
|
||||
public volatile long lastAnticheatMillis;
|
||||
|
||||
/** The comm. */
|
||||
private PlayerCommunicator comm;
|
||||
|
||||
/** The privs. */
|
||||
private HashSet<String> privs;
|
||||
/**
|
||||
* Object to be synchronized on for
|
||||
*/
|
||||
|
||||
/** Object to be synchronized on for. */
|
||||
public final Object antiCheatDataLock = new Object();
|
||||
|
||||
/**
|
||||
* Instantiates a new player.
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
public Player(String name) {
|
||||
this.name = name;
|
||||
this.inventories.put("default", new MossInventory(96, 8, 6));
|
||||
} //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Creates the inventory.
|
||||
*
|
||||
* @param name the name
|
||||
* @param rows the rows
|
||||
* @param cols the cols
|
||||
* @param maxStack the max stack
|
||||
* @return the moss inventory
|
||||
*/
|
||||
public MossInventory createInventory(String name, int rows, int cols,
|
||||
int maxStack) {
|
||||
MossInventory inv = new MossInventory(maxStack, rows, cols);
|
||||
|
@ -51,6 +108,9 @@ public class Player {
|
|||
return inv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respawn.
|
||||
*/
|
||||
public void respawn() {
|
||||
synchronized (this.antiCheatDataLock) {
|
||||
|
||||
|
@ -58,6 +118,11 @@ public class Player {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant privilege.
|
||||
*
|
||||
* @param privs the privs
|
||||
*/
|
||||
public void grantPrivilege(String... privs) {
|
||||
for (String priv : privs)
|
||||
if (priv.matches("^[a-zA-Z0-9]*$") && priv.length() > 0)
|
||||
|
@ -65,6 +130,11 @@ public class Player {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke privilege.
|
||||
*
|
||||
* @param privs the privs
|
||||
*/
|
||||
public void revokePrivilege(String... privs) {
|
||||
for (String priv : privs)
|
||||
if (priv.matches("^[a-zA-Z0-9]*$") && priv.length() > 0)
|
||||
|
@ -72,22 +142,46 @@ public class Player {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chunk position.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
*/
|
||||
public synchronized void setChunkPosition(int x, int y, int z) {
|
||||
this.xchk = x;
|
||||
this.ychk = y;
|
||||
this.zchk = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position offsets.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
*/
|
||||
public synchronized void setPositionOffsets(double x, double y, double z) {
|
||||
this.xoffset = x;
|
||||
this.yoffset = y;
|
||||
this.zoffset = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Privs to string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String privsToString() {
|
||||
return StringUtils.join(this.privs, ':');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the privs from string.
|
||||
*
|
||||
* @param serPrivs the new privs from string
|
||||
*/
|
||||
public void setPrivsFromString(String serPrivs) {
|
||||
this.privs.clear();
|
||||
for (String priv : serPrivs.split(":"))
|
||||
|
@ -96,11 +190,28 @@ public class Player {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Force set position.
|
||||
*
|
||||
* @param offsetx the offsetx
|
||||
* @param offsety the offsety
|
||||
* @param offsetz the offsetz
|
||||
* @param cx the cx
|
||||
* @param cy the cy
|
||||
* @param cz the cz
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public void forceSetPosition(double offsetx, double offsety,
|
||||
double offsetz, int cx, int cy, int cz) throws InterruptedException {
|
||||
this.comm.forceSetPosition(this, cx, cy, cz, offsetx, offsety, offsetz);
|
||||
}
|
||||
|
||||
/**
|
||||
* To byte array.
|
||||
*
|
||||
* @return the byte[]
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public byte[] toByteArray() throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
|
@ -117,6 +228,14 @@ public class Player {
|
|||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new player.
|
||||
*
|
||||
* @param comm_ the comm_
|
||||
* @param buf the buf
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public Player(PlayerCommunicator comm_, byte[] buf) throws IOException,
|
||||
InterruptedException {
|
||||
this.comm = comm_;
|
||||
|
|
|
@ -6,14 +6,35 @@ import java.io.DataInputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Position.
|
||||
*/
|
||||
public class Position {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int realm;
|
||||
/** The x. */
|
||||
public final int x;
|
||||
|
||||
/** The y. */
|
||||
public final int y;
|
||||
|
||||
/** The z. */
|
||||
public final int z;
|
||||
|
||||
/** The realm. */
|
||||
public final int realm;
|
||||
|
||||
/** The is valid. */
|
||||
transient boolean isValid = true;
|
||||
|
||||
/**
|
||||
* Instantiates a new position.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param realm the realm
|
||||
*/
|
||||
public Position(int x, int y, int z, int realm) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -22,6 +43,12 @@ public class Position {
|
|||
this.isValid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new position.
|
||||
*
|
||||
* @param bytes the bytes
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public Position(byte[] bytes) throws IOException {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
|
@ -32,12 +59,14 @@ public class Position {
|
|||
this.isValid = true;
|
||||
}
|
||||
|
||||
public Position() {
|
||||
this.isValid = false;
|
||||
}
|
||||
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
static final long serialVersionUID = 1128980133700001337L;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -65,6 +94,9 @@ public class Position {
|
|||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -76,6 +108,11 @@ public class Position {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To bytes.
|
||||
*
|
||||
* @return the byte[]
|
||||
*/
|
||||
public byte[] toBytes() {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
|
@ -94,15 +131,30 @@ public class Position {
|
|||
return new byte[] {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x.
|
||||
*
|
||||
* @return the x
|
||||
*/
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y.
|
||||
*
|
||||
* @return the y
|
||||
*/
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the z.
|
||||
*
|
||||
* @return the z
|
||||
*/
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface ScriptRunnable.
|
||||
*/
|
||||
public interface ScriptRunnable {
|
||||
|
||||
/**
|
||||
* Run.
|
||||
*/
|
||||
public void run();
|
||||
}
|
||||
|
|
|
@ -11,14 +11,32 @@ import org.apache.commons.lang.ArrayUtils;
|
|||
import org.iq80.leveldb.DB;
|
||||
import org.iq80.leveldb.Options;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ScriptableDatabase.
|
||||
*/
|
||||
public class ScriptableDatabase {
|
||||
|
||||
/** The base dir. */
|
||||
File baseDir;
|
||||
|
||||
/**
|
||||
* Instantiates a new scriptable database.
|
||||
*
|
||||
* @param baseDir the base dir
|
||||
*/
|
||||
public ScriptableDatabase(File baseDir) {
|
||||
this.baseDir = baseDir;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the db.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the db
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public DBase getDb(String name) throws IOException {
|
||||
if (!name.matches("[a-zA-Z]{1,32}")) { //$NON-NLS-1$
|
||||
throw new IllegalArgumentException(Messages.getString("ScriptableDatabase.DB_NAME_INVALID")); //$NON-NLS-1$
|
||||
|
@ -30,10 +48,20 @@ public class ScriptableDatabase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class DBase.
|
||||
*/
|
||||
public class DBase {
|
||||
// this class will contain a database that scripts may access.
|
||||
/** The inner db. */
|
||||
private final DB innerDb;
|
||||
|
||||
/**
|
||||
* Instantiates a new d base.
|
||||
*
|
||||
* @param innerDb the inner db
|
||||
* @param name the name
|
||||
*/
|
||||
DBase(DB innerDb, String name) {
|
||||
this.innerDb = innerDb;
|
||||
}
|
||||
|
@ -42,8 +70,8 @@ public class ScriptableDatabase {
|
|||
* Get a piece of string data with a string key, or <code>null</code> if
|
||||
* the datum cannot be found. String keys are exclusive from all other
|
||||
* key types.
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @param key the key
|
||||
* @return A string representing the stored data.
|
||||
*/
|
||||
public String getDatum(String key) {
|
||||
|
@ -68,8 +96,9 @@ public class ScriptableDatabase {
|
|||
* Get a piece of string data with a position and string key, or
|
||||
* <code>null</code> if the datum cannot be found. Position keys are
|
||||
* exclusive from all other key types.
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param key the key
|
||||
* @return The found data.
|
||||
*/
|
||||
public String getPositionDatum(NodePosition pos, String key) {
|
||||
|
|
|
@ -10,26 +10,58 @@ import net.mosstest.servercore.MapGeneratorException;
|
|||
import net.mosstest.servercore.MossDebugUtils;
|
||||
import toxi.math.noise.SimplexNoise;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class SimplexMapGenerator.
|
||||
*/
|
||||
public class SimplexMapGenerator implements IMapGenerator {
|
||||
|
||||
/** The logger. */
|
||||
static Logger logger = Logger.getLogger(SimplexMapGenerator.class);
|
||||
|
||||
/** The Constant HEIGHT_AVG. */
|
||||
public static final double HEIGHT_AVG = 0;
|
||||
|
||||
/** The Constant HEIGHT_JITTER. */
|
||||
public static final double HEIGHT_JITTER = 10;
|
||||
|
||||
/** The Constant SIMPLEX_SCALE_FACTOR. */
|
||||
public static final double SIMPLEX_SCALE_FACTOR = 0.03;
|
||||
|
||||
/** The Constant SIMPLEX_LOCAL_SCALE_FACTOR. */
|
||||
public static final double SIMPLEX_LOCAL_SCALE_FACTOR = 10 * SIMPLEX_SCALE_FACTOR;
|
||||
|
||||
/** The Constant SIMPLEX_ROOT_DEGREE. */
|
||||
public static final double SIMPLEX_ROOT_DEGREE = 2;
|
||||
|
||||
/** The Constant SEA_LEVEL. */
|
||||
public static final int SEA_LEVEL = 0;
|
||||
// todo tweak parameters
|
||||
// TODO finish simplex generator including ores
|
||||
/** The base seed. */
|
||||
long baseSeed;
|
||||
|
||||
/** The elevation seed. */
|
||||
double elevationSeed;
|
||||
|
||||
/** The dirt seed. */
|
||||
double dirtSeed;
|
||||
|
||||
/** The humidity seed. */
|
||||
double humiditySeed;
|
||||
|
||||
/** The elevation noise. */
|
||||
SimplexNoise elevationNoise = new SimplexNoise();
|
||||
|
||||
/** The ores. */
|
||||
ArrayList<Ore> ores = new ArrayList<>();
|
||||
|
||||
/** The nm. */
|
||||
INodeManager nm;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void init(long seed, INodeManager nm, Object... params)
|
||||
throws MapGeneratorException {
|
||||
|
@ -44,6 +76,9 @@ public class SimplexMapGenerator implements IMapGenerator {
|
|||
this.humiditySeed = rand.nextInt(1 << 16) + rand.nextDouble();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public MapChunk generateChunk(Position pos) throws MapGeneratorException {
|
||||
int[][][] lightNodes = new int[16][16][16];
|
||||
|
@ -109,6 +144,9 @@ public class SimplexMapGenerator implements IMapGenerator {
|
|||
return new MapChunk(pos, lightNodes, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public void fillInChunk(int[][][] lightNodes, Position pos)
|
||||
throws MapGeneratorException {
|
||||
|
@ -171,6 +209,9 @@ public class SimplexMapGenerator implements IMapGenerator {
|
|||
} // x
|
||||
} // method
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public void registerOre(MapNode oreNode, double minDepth, double rarity,
|
||||
double clumping, int seed, Object... params) {
|
||||
|
@ -178,14 +219,37 @@ public class SimplexMapGenerator implements IMapGenerator {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class Ore.
|
||||
*/
|
||||
private class Ore {
|
||||
|
||||
/** The node. */
|
||||
MapNode node;
|
||||
|
||||
/** The noise. */
|
||||
SimplexNoise noise;
|
||||
|
||||
/** The min depth. */
|
||||
double minDepth;
|
||||
|
||||
/** The cutoff. */
|
||||
double cutoff;
|
||||
|
||||
/** The simplex seed position. */
|
||||
double simplexSeedPosition;
|
||||
|
||||
/** The ore seed. */
|
||||
int oreSeed;
|
||||
|
||||
/**
|
||||
* Instantiates a new ore.
|
||||
*
|
||||
* @param node the node
|
||||
* @param seed the seed
|
||||
* @param minDepth the min depth
|
||||
* @param rarity the rarity
|
||||
*/
|
||||
public Ore(MapNode node, int seed, double minDepth, double rarity) {
|
||||
Random random = new Random(seed);
|
||||
this.simplexSeedPosition = 10 * Integer.MAX_VALUE
|
||||
|
@ -197,6 +261,14 @@ public class SimplexMapGenerator implements IMapGenerator {
|
|||
this.cutoff = 1.0 / rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check ore.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkOre(long x, long y, long z) {
|
||||
Random r = new Random(SimplexMapGenerator.this.baseSeed
|
||||
- this.oreSeed - x + y - z);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.scripting;
|
||||
|
||||
/**
|
||||
* The Class UtilityClassSandbox.
|
||||
*/
|
||||
public class UtilityClassSandbox {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package net.mosstest.scripting.events;
|
||||
|
||||
/**
|
||||
* Marker interface for all events.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IMossEvent {
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package net.mosstest.scripting.events;
|
||||
|
||||
import net.mosstest.scripting.MapNode;
|
||||
import net.mosstest.scripting.MossItem;
|
||||
import net.mosstest.scripting.NodePosition;
|
||||
import net.mosstest.scripting.Player;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossNodeChangeEvent.
|
||||
*/
|
||||
public class MossNodeChangeEvent implements IMossEvent{
|
||||
|
||||
/**
|
||||
* The Enum NodeActionType.
|
||||
*/
|
||||
public enum NodeActionType {
|
||||
/**
|
||||
* Fired when the user fully digs a node.
|
||||
*/
|
||||
NODE_ACTION_DIG,
|
||||
|
||||
/** Fired when the user punches (left-clicks) a node. */
|
||||
NODE_ACTION_PUNCH,
|
||||
/**
|
||||
* Fired when the user punches a node with a right-click. The default
|
||||
* action is to place a node; onDig should return false to avoid this.
|
||||
*/
|
||||
NODE_ACTION_RIGHTPUNCH,
|
||||
/**
|
||||
* Fired when the user punches a node with a middle-click.
|
||||
*/
|
||||
NODE_ACTION_MIDDLE_MOUSE_PUNCH,
|
||||
/**
|
||||
* Fired when the user right-clicks the node while pressing shift. This
|
||||
* is generally a sign of attempting to place a node as opposed to
|
||||
* right-punching it.
|
||||
*/
|
||||
NODE_ACTION_PLACE,
|
||||
/**
|
||||
* Currently unused.
|
||||
*/
|
||||
NODE_ACTION_REPLACE
|
||||
}
|
||||
|
||||
/**
|
||||
* The player performing the action, or null for none (e.g. a plugin raising
|
||||
* a dig event, for example via a node that is designed to dig another node
|
||||
* with a ceratin tool and is raising the event to be evaluated as if it
|
||||
* occurs with that tool.
|
||||
*/
|
||||
public final Player pl;
|
||||
/**
|
||||
* The NodePosition of the node in question.
|
||||
*/
|
||||
public final NodePosition pos;
|
||||
/**
|
||||
* A sequence number for this event. Refer to {@link net.mosstest.scripting.events}.
|
||||
*/
|
||||
public final long seqnum;
|
||||
|
||||
/** The type. */
|
||||
public final NodeActionType type;
|
||||
|
||||
/** The node before. */
|
||||
public final MapNode nodeBefore;
|
||||
|
||||
/** The wield item. */
|
||||
public final MossItem wieldItem;
|
||||
|
||||
/**
|
||||
* Instantiates a new moss node change event.
|
||||
*
|
||||
* @param pl the pl
|
||||
* @param pos the pos
|
||||
* @param seqnum the seqnum
|
||||
* @param type the type
|
||||
* @param nodeBefore the node before
|
||||
* @param wieldItem the wield item
|
||||
*/
|
||||
public MossNodeChangeEvent(Player pl, NodePosition pos, long seqnum,
|
||||
NodeActionType type, MapNode nodeBefore, MossItem wieldItem) {
|
||||
this.pl = pl;
|
||||
this.pos = pos;
|
||||
this.seqnum = seqnum;
|
||||
this.type = type;
|
||||
this.nodeBefore = nodeBefore;
|
||||
this.wieldItem = wieldItem;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.mosstest.scripting.events;
|
||||
|
||||
import net.mosstest.servercore.MosstestSecurityManager;
|
||||
|
||||
|
||||
/**
|
||||
* Empty class, but has a security-oriented constructor.
|
||||
*
|
||||
*/
|
||||
public class ThreadStopEvent implements IMossEvent {
|
||||
|
||||
/**
|
||||
* Instantiates a new thread stop event.
|
||||
*
|
||||
* @throws SecurityException the security exception
|
||||
*/
|
||||
public ThreadStopEvent() throws SecurityException {
|
||||
MosstestSecurityManager.instance.checkMosstestControl();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* @author rarkenin
|
||||
*
|
||||
* This package contains various immutable Java objects to contain the parameters of events which scripts shall handle.
|
||||
* <p>
|
||||
* <b>Sequence numbers, aka <code>seqnum</code>s</b> are serial IDs given to events with certain ordering guarantees, which include guarantees that:
|
||||
* <ul>
|
||||
* <li>Seqnums are unique until wraparound occurs at 18446744073709551616.</li>
|
||||
* <li>A seqnum with a higher value was received at the server after one with a lower value, even if the seqnums differ between sessions.</li>
|
||||
* <li>Within a given session between the server and a compliant client, a lower-value seqnum is assigned to an event arising from an earlier client action than a higher-value seqnum.
|
||||
*
|
||||
* </ul>
|
||||
*/
|
||||
package net.mosstest.scripting.events;
|
|
@ -0,0 +1,10 @@
|
|||
package net.mosstest.scripting.handlers;
|
||||
|
||||
|
||||
/**
|
||||
* Marker interface for event handlers
|
||||
*
|
||||
*/
|
||||
public interface MossEventHandler {
|
||||
|
||||
}
|
|
@ -4,65 +4,22 @@ import net.mosstest.scripting.MapNode;
|
|||
import net.mosstest.scripting.MossItem;
|
||||
import net.mosstest.scripting.NodePosition;
|
||||
import net.mosstest.scripting.Player;
|
||||
import net.mosstest.scripting.events.MossNodeChangeEvent;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface MossNodeChangeHandler.
|
||||
*/
|
||||
public interface MossNodeChangeHandler extends MossEventHandler {
|
||||
|
||||
public interface MossNodeChangeHandler {
|
||||
public enum NodeActionType {
|
||||
/**
|
||||
* Fired when the user fully digs a node.
|
||||
*/
|
||||
NODE_ACTION_DIG,
|
||||
/**
|
||||
* Fired when the user punches (left-clicks) a node
|
||||
*/
|
||||
NODE_ACTION_PUNCH,
|
||||
/**
|
||||
* Fired when the user punches a node with a right-click. The default
|
||||
* action is to place a node; onDig should return false to avoid this.
|
||||
*/
|
||||
NODE_ACTION_RIGHTPUNCH,
|
||||
/**
|
||||
* Fired when the user punches a node with a middle-click.
|
||||
*/
|
||||
NODE_ACTION_MIDDLE_MOUSE_PUNCH,
|
||||
/**
|
||||
* Fired when the user right-clicks the node while pressing shift. This
|
||||
* is generally a sign of attempting to place a node as opposed to
|
||||
* right-punching it.
|
||||
*/
|
||||
NODE_ACTION_PLACE,
|
||||
/**
|
||||
* Currently unused.
|
||||
*/
|
||||
NODE_ACTION_REPLACE
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a node is acted upon.
|
||||
*
|
||||
* @param pl
|
||||
* The player performing the action, null if none can be
|
||||
* determined.
|
||||
* @param pos
|
||||
* The position of the node in question.
|
||||
* @param before
|
||||
* The node existing before this action.
|
||||
* @param wieldItem
|
||||
* The item wielded by the player, null for the hand. If this is
|
||||
* a node place event the item will correspond to the node being
|
||||
* placed.
|
||||
* @param type
|
||||
* The type of action performed.
|
||||
* @param timestamp
|
||||
* A game timestamp that is assigned to events in a consistent
|
||||
* order. This means that each event will have a differing
|
||||
* timestamp, and any event received by the server or at the
|
||||
* client after another will have a greater timestamp. This value
|
||||
* is <i>not</i> a real-time clock.
|
||||
* @param evt A NodeChangeEvent object describing the event.
|
||||
* @return True if this event should be processed by other subscribed and
|
||||
* registered handlers, false otherwise.
|
||||
*/
|
||||
public abstract boolean onAction(Player pl, NodePosition pos,
|
||||
MapNode before, MossItem wieldItem, NodeActionType type,
|
||||
long timestamp);
|
||||
|
||||
public abstract boolean onAction(MossNodeChangeEvent evt);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,22 @@ import org.iq80.leveldb.DB;
|
|||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class AbstractNodeManager.
|
||||
*/
|
||||
public abstract class AbstractNodeManager implements INodeManager {
|
||||
|
||||
/** The defined nodes. */
|
||||
protected ArrayList<MapNode> definedNodes = new ArrayList<>();
|
||||
|
||||
/** The def node by name. */
|
||||
protected HashMap<String, MapNode> defNodeByName = new HashMap<>();
|
||||
|
||||
/** The pending. */
|
||||
protected HashBiMap<Short, String> pending = HashBiMap.create();
|
||||
|
||||
/** The Constant MAPNODE_UNKNOWN. */
|
||||
public static final MapNode MAPNODE_UNKNOWN = new MapNode("unknown.png", //$NON-NLS-1$
|
||||
"sys:unknown", Messages.getString("AbstractNodeManager.DESC_UNKNOWN_NODE"), 1); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
static {
|
||||
|
@ -24,21 +35,39 @@ public abstract class AbstractNodeManager implements INodeManager {
|
|||
this.definedNodes.add(this.MAPNODE_UNKNOWN);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#getNode(short)
|
||||
*/
|
||||
@Override
|
||||
public abstract MapNode getNode(short nodeId);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#putNode(net.mosstest.scripting.MapNode)
|
||||
*/
|
||||
@Override
|
||||
public abstract short putNode(MapNode node) throws MossWorldLoadException;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#putNodeAlias(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public abstract void putNodeAlias(String alias, String dst);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#getNode(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public abstract MapNode getNode(String string, boolean isModified);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#getNode(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public abstract MapNode getNode(String string);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.INodeManager#init()
|
||||
*/
|
||||
@Override
|
||||
public abstract void init();
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class AntiCheatException.
|
||||
*/
|
||||
public class AntiCheatException extends PlayerSecurityException {
|
||||
|
||||
}
|
||||
|
|
|
@ -2,19 +2,39 @@ package net.mosstest.servercore;
|
|||
|
||||
import net.mosstest.scripting.Position;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ApplicationLevelNetworkingManager.
|
||||
*/
|
||||
public class ApplicationLevelNetworkingManager {
|
||||
|
||||
/** The net. */
|
||||
ClientNetworkingManager net;
|
||||
|
||||
/** The Constant PROTOCOL_VERSION_MAJOR. */
|
||||
static final int PROTOCOL_VERSION_MAJOR = 1;
|
||||
|
||||
/** The Constant PROTOCOL_VERSION_MINOR. */
|
||||
static final int PROTOCOL_VERSION_MINOR = 1; // change for
|
||||
// backward-compatible
|
||||
// changes such as changes
|
||||
// in timing that do not
|
||||
// break older versions
|
||||
|
||||
public ApplicationLevelNetworkingManager(ClientNetworkingManager net) {
|
||||
/**
|
||||
* Instantiates a new application level networking manager.
|
||||
*
|
||||
* @param net the net
|
||||
*/
|
||||
public ApplicationLevelNetworkingManager(ClientNetworkingManager net) {
|
||||
this.net = net;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send chunk request.
|
||||
*
|
||||
* @param pos the pos
|
||||
*/
|
||||
public void sendChunkRequest(Position pos) {
|
||||
// TODO create generated code
|
||||
|
||||
|
|
|
@ -1,7 +1,45 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Enum Biome.
|
||||
*/
|
||||
public enum Biome {
|
||||
MG_LAKE, MG_ICE, MG_OCEAN, MG_SWAMP, MG_FOREST, MG_PLAIN, MG_DELTA, MG_DESERT, MG_RAINFOREST, MG_JUNGLE, MG_VOLCANIC, MG_DEFAULT;
|
||||
|
||||
/** The mg lake. */
|
||||
MG_LAKE,
|
||||
/** The mg ice. */
|
||||
MG_ICE,
|
||||
/** The mg ocean. */
|
||||
MG_OCEAN,
|
||||
/** The mg swamp. */
|
||||
MG_SWAMP,
|
||||
/** The mg forest. */
|
||||
MG_FOREST,
|
||||
/** The mg plain. */
|
||||
MG_PLAIN,
|
||||
/** The mg delta. */
|
||||
MG_DELTA,
|
||||
/** The mg desert. */
|
||||
MG_DESERT,
|
||||
/** The mg rainforest. */
|
||||
MG_RAINFOREST,
|
||||
/** The mg jungle. */
|
||||
MG_JUNGLE,
|
||||
/** The mg volcanic. */
|
||||
MG_VOLCANIC,
|
||||
/** The mg default. */
|
||||
MG_DEFAULT;
|
||||
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
* @param humidity the humidity
|
||||
* @param elevation the elevation
|
||||
* @param geo_age the geo_age
|
||||
* @param temperature the temperature
|
||||
* @return the biome
|
||||
*/
|
||||
public Biome select(double humidity, double elevation, double geo_age, double temperature){
|
||||
return MG_DEFAULT;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,33 @@ package net.mosstest.servercore;
|
|||
|
||||
import net.mosstest.scripting.Position;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ChunkNotFoundException.
|
||||
*/
|
||||
public class ChunkNotFoundException extends Exception {
|
||||
|
||||
/** The z. */
|
||||
long x, y, z;
|
||||
|
||||
/**
|
||||
* Instantiates a new chunk not found exception.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
*/
|
||||
public ChunkNotFoundException(long x, long y, long z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new chunk not found exception.
|
||||
*
|
||||
* @param pos the pos
|
||||
*/
|
||||
public ChunkNotFoundException(Position pos) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ClientMain.
|
||||
*/
|
||||
public class ClientMain {
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO Initialize the client here.
|
||||
|
||||
|
|
|
@ -3,32 +3,73 @@ package net.mosstest.servercore;
|
|||
import java.io.IOException;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ClientManager.
|
||||
*/
|
||||
public class ClientManager {
|
||||
|
||||
/** The state. */
|
||||
volatile static int state=0;
|
||||
|
||||
/** The Constant STATE_DISCONNECTED. */
|
||||
static final int STATE_DISCONNECTED=0;
|
||||
|
||||
/** The Constant STATE_FETCHING_SCRIPTS. */
|
||||
static final int STATE_FETCHING_SCRIPTS=1;
|
||||
|
||||
/** The Constant STATE_FETCHING_TEXTURES. */
|
||||
static final int STATE_FETCHING_TEXTURES=2;
|
||||
|
||||
/** The Constant STATE_FETCHING_MESHES. */
|
||||
static final int STATE_FETCHING_MESHES=3;
|
||||
|
||||
/** The Constant STATE_PLAYABLE. */
|
||||
static final int STATE_PLAYABLE=4;
|
||||
|
||||
/** The Constant STATE_INVALID. */
|
||||
static final int STATE_INVALID=-1;
|
||||
|
||||
/** The net. */
|
||||
static ClientNetworkingManager net;
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*
|
||||
* @param host the host
|
||||
* @param port the port
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
static void init(String host, int port, String username, char[] password) throws IOException{
|
||||
net=new ClientNetworkingManager(host, port, EngineSettings.getBool("client_udp", true)); //$NON-NLS-1$
|
||||
net.beginConnectHandshake();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the networking manager.
|
||||
*
|
||||
* @return the networking manager
|
||||
*/
|
||||
public static ClientNetworkingManager getNetworkingManager() {
|
||||
return net;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application level networking manager.
|
||||
*
|
||||
* @return the application level networking manager
|
||||
*/
|
||||
public static ApplicationLevelNetworkingManager getApplicationLevelNetworkingManager() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error screen on the client
|
||||
* Show an error screen on the client.
|
||||
*
|
||||
* @param title The title to show
|
||||
* @param msg The message to show
|
||||
* @param disconnect Whether to disconnect from the current server, if any.
|
||||
|
|
|
@ -18,36 +18,79 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ClientNetworkingManager.
|
||||
*/
|
||||
public class ClientNetworkingManager {
|
||||
|
||||
/** The logger. */
|
||||
static Logger logger = Logger.getLogger(ClientNetworkingManager.class);
|
||||
// There's a potential DoS attack here but it can only be mounted by the
|
||||
// server, so you might as well just not use that server. No security
|
||||
// threat except small client hang, won't fix.
|
||||
/** The run threads. */
|
||||
protected AtomicBoolean runThreads = new AtomicBoolean(true);
|
||||
|
||||
/** The bulk data socket. */
|
||||
protected Socket bulkDataSocket = new Socket();
|
||||
|
||||
/** The low latency stream socket. */
|
||||
protected Socket lowLatencyStreamSocket = new Socket();
|
||||
|
||||
/** The udp socket. */
|
||||
protected DatagramSocket udpSocket;
|
||||
|
||||
/** The bulk data out. */
|
||||
protected DataOutputStream bulkDataOut;
|
||||
|
||||
/** The lowlatency data out. */
|
||||
protected DataOutputStream lowlatencyDataOut;
|
||||
|
||||
/** The bulk data in. */
|
||||
protected DataInputStream bulkDataIn;
|
||||
|
||||
/** The lowlatency data in. */
|
||||
protected DataInputStream lowlatencyDataIn;
|
||||
|
||||
/** The udp on. */
|
||||
protected boolean udpOn = false;
|
||||
|
||||
/** The fast link ackd. */
|
||||
protected AtomicBoolean fastLinkAckd = new AtomicBoolean(false);
|
||||
|
||||
/** The endpoint. */
|
||||
protected final InetAddress endpoint;
|
||||
|
||||
/** The port. */
|
||||
protected int port;
|
||||
|
||||
/** The last bulk out. */
|
||||
protected AtomicLong lastBulkOut = new AtomicLong();
|
||||
|
||||
/** The last bulk in. */
|
||||
protected AtomicLong lastBulkIn = new AtomicLong();
|
||||
|
||||
/** The last fast out. */
|
||||
protected AtomicLong lastFastOut = new AtomicLong();
|
||||
|
||||
/** The last fast in. */
|
||||
protected AtomicLong lastFastIn = new AtomicLong();
|
||||
|
||||
/** The last udp out. */
|
||||
protected AtomicLong lastUdpOut = new AtomicLong();
|
||||
|
||||
/** The last udp in. */
|
||||
protected AtomicLong lastUdpIn = new AtomicLong();
|
||||
/*
|
||||
* Should be no need for another lowlatency queue unless we find poor
|
||||
* performance
|
||||
*/
|
||||
/** The packets. */
|
||||
public ArrayBlockingQueue<MossNetPacket> packets = new ArrayBlockingQueue<>(
|
||||
1024);
|
||||
|
||||
/** The bulk read handler. */
|
||||
protected Thread bulkReadHandler = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -93,6 +136,8 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
}, "ClientBulkRecv"); //$NON-NLS-1$
|
||||
|
||||
/** The fast read handler. */
|
||||
protected Thread fastReadHandler = new Thread(new Runnable() {
|
||||
// TODO
|
||||
@Override
|
||||
|
@ -132,8 +177,14 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
}, "ClientBulkRecv"); //$NON-NLS-1$
|
||||
|
||||
/** The party quenched. */
|
||||
protected AtomicBoolean partyQuenched = new AtomicBoolean(false);
|
||||
|
||||
/** The quenched since. */
|
||||
AtomicLong quenchedSince = new AtomicLong(0);
|
||||
|
||||
/** The dgram read handler. */
|
||||
protected Thread dgramReadHandler = new Thread(new Runnable() {
|
||||
// TODO--spanish for "all"
|
||||
@Override
|
||||
|
@ -181,11 +232,26 @@ public class ClientNetworkingManager {
|
|||
}
|
||||
}, "ClientDgramRecv"); //$NON-NLS-1$
|
||||
|
||||
/** The bulk stream in. */
|
||||
protected InputStream bulkStreamIn;
|
||||
|
||||
/** The bulk stream out. */
|
||||
protected OutputStream bulkStreamOut;
|
||||
|
||||
/** The fast stream in. */
|
||||
protected InputStream fastStreamIn;
|
||||
|
||||
/** The fast stream out. */
|
||||
protected OutputStream fastStreamOut;
|
||||
|
||||
/**
|
||||
* Instantiates a new client networking manager.
|
||||
*
|
||||
* @param endpoint the endpoint
|
||||
* @param port the port
|
||||
* @param useUdp the use udp
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public ClientNetworkingManager(String endpoint, int port, boolean useUdp)
|
||||
throws IOException {
|
||||
this.endpoint = InetAddress.getByName(endpoint);
|
||||
|
@ -228,16 +294,27 @@ public class ClientNetworkingManager {
|
|||
this.netTimeoutThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ack.
|
||||
*
|
||||
* @param seqnum the seqnum
|
||||
*/
|
||||
protected void sendAck(int seqnum) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send tos udp conn.
|
||||
*/
|
||||
protected void sendTosUdpConn() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send quench.
|
||||
*/
|
||||
protected void sendQuench() {
|
||||
// TODO Sends a request for the server to back off with data and skip
|
||||
// non-essential data.
|
||||
|
@ -246,13 +323,9 @@ public class ClientNetworkingManager {
|
|||
|
||||
/**
|
||||
* Send a packet, dispatching to the correct socket.
|
||||
*
|
||||
* @param commandId
|
||||
* Byte representing command ID.
|
||||
* @param payload
|
||||
* The data to send.
|
||||
* @param latencyPrio
|
||||
* @throws IOException
|
||||
*
|
||||
* @param p the p
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendPacket(MossNetPacket p) throws IOException {
|
||||
if(this.partyQuenched.get()&&!p.isImportant) return;
|
||||
|
@ -268,6 +341,13 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send packet default.
|
||||
*
|
||||
* @param commandId the command id
|
||||
* @param payload the payload
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendPacketDefault(int commandId, byte[] payload)
|
||||
throws IOException {
|
||||
this.lastBulkOut.set(System.currentTimeMillis());
|
||||
|
@ -289,6 +369,11 @@ public class ClientNetworkingManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default reinit.
|
||||
*
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void defaultReinit() throws IOException {
|
||||
this.bulkDataIn.close();
|
||||
this.bulkDataOut.close();
|
||||
|
@ -307,6 +392,9 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bulk reconnect.
|
||||
*/
|
||||
protected void performBulkReconnect() {
|
||||
synchronized (this.bulkDataOut) {
|
||||
// PERFORM RECONNECTION
|
||||
|
@ -314,6 +402,13 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send packet low latency.
|
||||
*
|
||||
* @param commandId the command id
|
||||
* @param payload the payload
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendPacketLowLatency(int commandId, byte[] payload)
|
||||
throws IOException {
|
||||
if (!this.fastLinkAckd.get()) {
|
||||
|
@ -340,6 +435,14 @@ public class ClientNetworkingManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send packet udp.
|
||||
*
|
||||
* @param commandId the command id
|
||||
* @param payload the payload
|
||||
* @param needsAck the needs ack
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendPacketUdp(int commandId, byte[] payload, boolean needsAck)
|
||||
throws IOException {
|
||||
this.lastUdpOut.set(System.currentTimeMillis());
|
||||
|
@ -351,29 +454,59 @@ public class ClientNetworkingManager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue packet.
|
||||
*
|
||||
* @param p the p
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public void enqueuePacket(MossNetPacket p) throws InterruptedException {
|
||||
this.sendQueue.put(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class StateMachine.
|
||||
*/
|
||||
protected class StateMachine {
|
||||
|
||||
/** The Constant DISCONNECTED. */
|
||||
static final int DISCONNECTED = 0;
|
||||
|
||||
/** The Constant LINK. */
|
||||
static final int LINK = 1;
|
||||
|
||||
/** The Constant AUTH. */
|
||||
static final int AUTH = 2;
|
||||
|
||||
/** The Constant RESOURCE_XFER. */
|
||||
static final int RESOURCE_XFER = 3;
|
||||
|
||||
/** The Constant ESTABLISHED. */
|
||||
static final int ESTABLISHED = 4;
|
||||
|
||||
/** The Constant DENIED. */
|
||||
static final int DENIED = 5;
|
||||
|
||||
/** The Constant TIMEDOUT. */
|
||||
static final int TIMEDOUT = 6;
|
||||
|
||||
/** The cur status. */
|
||||
int curStatus = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin connect handshake.
|
||||
*/
|
||||
public void beginConnectHandshake() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/** The send queue. */
|
||||
final ArrayBlockingQueue<MossNetPacket> sendQueue = new ArrayBlockingQueue<>(
|
||||
1024);
|
||||
|
||||
/** The send queue thread. */
|
||||
private Thread sendQueueThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -389,6 +522,7 @@ public class ClientNetworkingManager {
|
|||
}
|
||||
}, Messages.getString("ClientNetworkingManager.THREAD_QUEUEING")); //$NON-NLS-1$
|
||||
|
||||
/** The net timeout thread. */
|
||||
private Thread netTimeoutThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommonNetworking.
|
||||
*/
|
||||
public class CommonNetworking {
|
||||
|
||||
/** The Constant magic. */
|
||||
static final int magic=0xfa7d2e4a;
|
||||
|
||||
/** The Constant magicNoAck. */
|
||||
static final int magicNoAck=0xfa7d2e4f;
|
||||
|
||||
/** The Constant magicAck. */
|
||||
static final int magicAck=0xfa7d2740;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class DatabaseWriteEvent.
|
||||
*/
|
||||
public class DatabaseWriteEvent {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,77 +5,23 @@ import net.mosstest.scripting.MossItem;
|
|||
import net.mosstest.scripting.MossScriptEnv;
|
||||
import net.mosstest.scripting.MossScriptException;
|
||||
import net.mosstest.scripting.Player;
|
||||
import net.mosstest.scripting.events.IMossEvent;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class DefaultEventHandlers.
|
||||
*/
|
||||
public class DefaultEventHandlers {
|
||||
|
||||
public static void processEvent(final MossEvent evt, MossScriptEnv env) throws MossScriptException {
|
||||
switch (evt.type) {
|
||||
case EVT_CHATCOMMAND:
|
||||
env.sendChatMessage((Player) evt.actor, null,
|
||||
Messages.getString("DefaultEventHandlers.NO_SUCH_CMD")); //$NON-NLS-1$
|
||||
break;
|
||||
case EVT_CHATMESSAGE:
|
||||
env.sendChatAll((Player) evt.actor,
|
||||
evt.initiatingMessage);
|
||||
break;
|
||||
case EVT_DIEPLAYER:
|
||||
env.setHp(evt.actor, 64); // Max HP=64
|
||||
evt.actor.respawn();
|
||||
// FIXME rarkenin env.moveEntity(myEvent.actor,
|
||||
// Mapgen.getSpawnPoint);
|
||||
break;
|
||||
case EVT_DIGNODE:
|
||||
try {
|
||||
env.damageTool(evt.actor,
|
||||
evt.nodeBefore);
|
||||
env.givePlayer(evt.actor,
|
||||
new MossItem.Stack(evt.nodeBefore.dropItem, 1));
|
||||
env.removeNode(evt.pos);
|
||||
} catch (MossScriptException e) {
|
||||
//FIXME MossSecurityManager.log(e);
|
||||
}
|
||||
break;
|
||||
case EVT_ENTITY_DEATH:
|
||||
env.getFuturesProcessor().runOnce(8000, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
evt.actor.respawn();
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
case EVT_ENTITY_PUNCH:
|
||||
//No default action
|
||||
break;
|
||||
case EVT_FSPEC_INVACTION:
|
||||
evt.action.acceptAsStated();
|
||||
break;
|
||||
case EVT_FSPEC_OPEN:
|
||||
break;
|
||||
case EVT_FSPEC_SUBMIT:
|
||||
break;
|
||||
case EVT_GENERATE:
|
||||
break;
|
||||
case EVT_JOINPLAYER:
|
||||
break;
|
||||
case EVT_NEWPLAYER:
|
||||
break;
|
||||
case EVT_NODEMOVE:
|
||||
break;
|
||||
case EVT_PLACENODE:
|
||||
env.setNode(evt.pos, evt.nodeAfter);
|
||||
break;
|
||||
case EVT_QUITPLAYER:
|
||||
break;
|
||||
case EVT_SHUTDOWN:
|
||||
break;
|
||||
case EVT_THREADSTOP:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
/**
|
||||
* Process event.
|
||||
*
|
||||
* @param myEvent the evt
|
||||
* @param env the env
|
||||
* @throws MossScriptException the moss script exception
|
||||
*/
|
||||
public static void processEvent(final IMossEvent myEvent, MossScriptEnv env) throws MossScriptException {
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface Drawable2D.
|
||||
*/
|
||||
public interface Drawable2D {
|
||||
|
||||
/**
|
||||
* Draw.
|
||||
*
|
||||
* @param screen the screen
|
||||
*/
|
||||
public void Draw(DrawableHudset screen);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface Drawable3D.
|
||||
*/
|
||||
public interface Drawable3D {
|
||||
|
||||
/**
|
||||
* Draw.
|
||||
*
|
||||
* @param world the world
|
||||
*/
|
||||
public void draw(DrawableWorld world);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class DrawableHudset.
|
||||
*/
|
||||
public class DrawableHudset {
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,18 @@ import net.mosstest.scripting.MapNode;
|
|||
import net.mosstest.scripting.Position;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class DrawableWorld.
|
||||
*/
|
||||
public class DrawableWorld {
|
||||
|
||||
/**
|
||||
* Adds the block mesh.
|
||||
*
|
||||
* @param mapNode the map node
|
||||
* @param pos the pos
|
||||
*/
|
||||
public void addBlockMesh(MapNode mapNode, Position pos) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class DuplicateNodedefException.
|
||||
*/
|
||||
public class DuplicateNodedefException extends Exception {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class EngineSettings.
|
||||
*/
|
||||
public class EngineSettings {
|
||||
|
||||
/**
|
||||
* Gets the int.
|
||||
*
|
||||
* @param name the name
|
||||
* @param def the def
|
||||
* @return the int
|
||||
*/
|
||||
static int getInt(String name, int def){
|
||||
if("forced".equals("false")){ //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return 0; //TODO this case
|
||||
|
@ -8,6 +20,13 @@ public class EngineSettings {
|
|||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bool.
|
||||
*
|
||||
* @param string the string
|
||||
* @param def the def
|
||||
* @return the bool
|
||||
*/
|
||||
public static boolean getBool(String string, boolean def) {
|
||||
if("forced".equals("false")){ //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return false; //TODO this case
|
||||
|
|
|
@ -5,17 +5,20 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import net.mosstest.scripting.EventProcessingCompletedSignal;
|
||||
import net.mosstest.scripting.MossEvent;
|
||||
import net.mosstest.scripting.MossEventHandler;
|
||||
import net.mosstest.scripting.MossScriptEnv;
|
||||
import net.mosstest.scripting.MossScriptException;
|
||||
import net.mosstest.scripting.MossEvent.EvtType;
|
||||
import net.mosstest.scripting.events.IMossEvent;
|
||||
import net.mosstest.scripting.events.MossNodeChangeEvent;
|
||||
import net.mosstest.scripting.events.ThreadStopEvent;
|
||||
import net.mosstest.scripting.handlers.MossEventHandler;
|
||||
import net.mosstest.scripting.handlers.MossNodeChangeHandler;
|
||||
import net.mosstest.servercore.MosstestSecurityManager.ThreadContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class EventProcessor.
|
||||
*
|
||||
* @author rarkenin, hexafraction
|
||||
*
|
||||
|
@ -25,28 +28,39 @@ import net.mosstest.servercore.MosstestSecurityManager.ThreadContext;
|
|||
* Java well, you may want to stick to only accessing the queue as
|
||||
* otherwise asphyxiation, drowning, or chlorine poisoning may occur.
|
||||
* USE ACCESS METHODS OTHER THAN THE QUEUE AT YOUR OWN RISK.
|
||||
*
|
||||
*/
|
||||
public class EventProcessor {
|
||||
|
||||
static Logger logger = Logger.getLogger(EventProcessor.class);
|
||||
ArrayBlockingQueue<MossEvent> eventQueue = new ArrayBlockingQueue<>(
|
||||
|
||||
ArrayBlockingQueue<IMossEvent> eventQueue = new ArrayBlockingQueue<>(
|
||||
EngineSettings.getInt("eventQueueCapacity", 40), false); //$NON-NLS-1$
|
||||
|
||||
protected final int maxEventThreads = EngineSettings.getInt(
|
||||
"maxEventThreads", 8); //$NON-NLS-1$
|
||||
|
||||
protected final int initialEventThreads = EngineSettings.getInt(
|
||||
"initialEventThreads", 8); //$NON-NLS-1$
|
||||
ThreadGroup eventProcessorGroup = new ThreadGroup(Messages.getString("EventProcessor.THREADGROUP")); //$NON-NLS-1$
|
||||
|
||||
ThreadGroup eventProcessorGroup = new ThreadGroup(
|
||||
Messages.getString("EventProcessor.THREADGROUP")); //$NON-NLS-1$
|
||||
|
||||
protected AtomicBoolean runManager = new AtomicBoolean(true);
|
||||
|
||||
protected final int sampleInterval = EngineSettings.getInt(
|
||||
"eventQueueTuneSampleInterval", 100); //$NON-NLS-1$
|
||||
|
||||
protected final int upshift = EngineSettings.getInt(
|
||||
"eventQueueTuneUpshift", 90); //$NON-NLS-1$
|
||||
|
||||
protected final int downshift = EngineSettings.getInt(
|
||||
"eventQueueTuneDownshift", 10); //$NON-NLS-1$
|
||||
|
||||
protected final int samples = EngineSettings.getInt(
|
||||
"eventQueueTuneSamples", 100); //$NON-NLS-1$
|
||||
|
||||
protected final AtomicInteger currentThreads = new AtomicInteger(0);
|
||||
|
||||
private Thread manager = new Thread(this.eventProcessorGroup,
|
||||
new Runnable() {
|
||||
/**
|
||||
|
@ -74,7 +88,8 @@ public class EventProcessor {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug(Messages.getString("EventProcessor.MSG_THREAD_START")); //$NON-NLS-1$
|
||||
logger.debug(Messages
|
||||
.getString("EventProcessor.MSG_THREAD_START")); //$NON-NLS-1$
|
||||
processEvents();
|
||||
}
|
||||
|
||||
|
@ -98,8 +113,8 @@ public class EventProcessor {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out
|
||||
.println(Messages.getString("EventProcessor.MSG_ADD_DYNAMIC")); //$NON-NLS-1$
|
||||
System.out.println(Messages
|
||||
.getString("EventProcessor.MSG_ADD_DYNAMIC")); //$NON-NLS-1$
|
||||
processEvents();
|
||||
}
|
||||
|
||||
|
@ -109,15 +124,10 @@ public class EventProcessor {
|
|||
|
||||
}
|
||||
if (((float) ticksBusy / (float) ticks) < ((float) lDownshift / (float) lSamples)) {
|
||||
logger.info((Messages.getString("EventProcessor.MSG_STOP_ONE_THREAD"))); //$NON-NLS-1$
|
||||
logger.info((Messages
|
||||
.getString("EventProcessor.MSG_STOP_ONE_THREAD"))); //$NON-NLS-1$
|
||||
EventProcessor.this.eventQueue
|
||||
.add(new MossEvent(
|
||||
MossEvent.EvtType.EVT_THREADSTOP,
|
||||
null, null, null, null, null,
|
||||
null, null, 0, null,
|
||||
new ScriptSandboxBorderToken(
|
||||
84,
|
||||
EventProcessor.class)));
|
||||
.add(new ThreadStopEvent());
|
||||
|
||||
}
|
||||
ticks = 0;
|
||||
|
@ -131,33 +141,26 @@ public class EventProcessor {
|
|||
}
|
||||
}
|
||||
}, Messages.getString("EventProcessor.THREAD_NAME_MGR")); //$NON-NLS-1$
|
||||
|
||||
private final MossScriptEnv ev;
|
||||
|
||||
private final ThreadContext tc;
|
||||
|
||||
/**
|
||||
* Process events.
|
||||
*/
|
||||
void processEvents() {
|
||||
MosstestSecurityManager.instance.setThreadContext(this.tc);
|
||||
boolean run = true; // Not synchronized as only used locally
|
||||
queueLoop: while (run) {
|
||||
try {
|
||||
MossEvent myEvent = this.eventQueue.take();
|
||||
IMossEvent myEvent = this.eventQueue.take();
|
||||
{// Section for actually handling the events
|
||||
if (myEvent.type == EvtType.EVT_THREADSTOP) {
|
||||
if (myEvent instanceof ThreadStopEvent) {
|
||||
this.currentThreads.decrementAndGet();
|
||||
return;
|
||||
}
|
||||
ArrayList<MossEventHandler> evtHandlerList = this.ev
|
||||
.getHandlers(myEvent.type,
|
||||
new ScriptSandboxBorderToken(84,
|
||||
EventProcessor.class));
|
||||
try {
|
||||
for (MossEventHandler ourHandler : evtHandlerList) {
|
||||
if (ourHandler.processEvent(myEvent))
|
||||
continue queueLoop;
|
||||
}
|
||||
DefaultEventHandlers.processEvent(myEvent, this.ev);
|
||||
} catch (MossScriptException e) {
|
||||
// Event processing complete, pass
|
||||
}
|
||||
dispatchEvent(myEvent);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -169,17 +172,53 @@ public class EventProcessor {
|
|||
|
||||
}
|
||||
|
||||
private void dispatchEvent(IMossEvent evt) {
|
||||
ArrayList<MossEventHandler> evtHandlerList = this.ev
|
||||
.getEventHandlers(evt.getClass());
|
||||
try {
|
||||
for (MossEventHandler ourHandler : evtHandlerList) {
|
||||
if (dispatchEventInner(ourHandler, evt)) {
|
||||
// continue loop
|
||||
}
|
||||
}
|
||||
DefaultEventHandlers.processEvent(evt, this.ev);
|
||||
} catch (MossScriptException | IllegalArgumentException e) {
|
||||
logger.warn(e.getClass().getName() + " upon processing event: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean dispatchEventInner(MossEventHandler ourHandler,
|
||||
IMossEvent evt) throws IllegalArgumentException {
|
||||
try {
|
||||
if (evt instanceof MossNodeChangeEvent) {
|
||||
|
||||
return ((MossNodeChangeHandler) ourHandler)
|
||||
.onAction((MossNodeChangeEvent) evt);
|
||||
|
||||
} else
|
||||
throw new IllegalArgumentException(
|
||||
"The event passed in was not a type that Mosstest is equipped to handle.");
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"The event handler did not match in type with the event.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new event processor.
|
||||
*
|
||||
* @param ev
|
||||
* A script environment populated with event handlers.
|
||||
* @param tc
|
||||
* the tc
|
||||
*/
|
||||
public EventProcessor(MossScriptEnv ev, ThreadContext tc) {
|
||||
this.ev = ev;
|
||||
this.tc = tc;
|
||||
this.manager.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ExceptionHandler.
|
||||
*/
|
||||
public class ExceptionHandler {
|
||||
|
||||
/**
|
||||
* Register exception.
|
||||
*
|
||||
* @param e the e
|
||||
*/
|
||||
public static void registerException(Exception e){
|
||||
//pass
|
||||
}
|
||||
|
|
|
@ -7,13 +7,30 @@ import java.util.Map.Entry;
|
|||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class FuturesProcessor.
|
||||
*/
|
||||
public class FuturesProcessor {
|
||||
|
||||
/** The r. */
|
||||
Random r = new Random();
|
||||
|
||||
/** The jobs. */
|
||||
TreeMap<Long, Job> jobs = new TreeMap<>();
|
||||
|
||||
/** The next wakeup. */
|
||||
volatile long nextWakeup = System.currentTimeMillis();
|
||||
|
||||
/** The futures thread. */
|
||||
public Thread futuresThread = new Thread(new FuturesRunnable(), Messages.getString("FuturesProcessor.FUTURES_THREAD")); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Run once.
|
||||
*
|
||||
* @param delayMillis the delay millis
|
||||
* @param runnable the runnable
|
||||
*/
|
||||
public synchronized void runOnce(long delayMillis, Runnable runnable) {
|
||||
Job tJob = new Job(System.currentTimeMillis() + delayMillis, 0, 0, 1.0,
|
||||
false, runnable);
|
||||
|
@ -23,6 +40,14 @@ public class FuturesProcessor {
|
|||
this.futuresThread.interrupt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register abm.
|
||||
*
|
||||
* @param delayMillis the delay millis
|
||||
* @param delayJitterMillis the delay jitter millis
|
||||
* @param probability the probability
|
||||
* @param runnable the runnable
|
||||
*/
|
||||
public synchronized void registerAbm(long delayMillis,
|
||||
long delayJitterMillis, double probability, Runnable runnable) {
|
||||
Job tJob = new Job(System.currentTimeMillis(), delayMillis,
|
||||
|
@ -35,14 +60,24 @@ public class FuturesProcessor {
|
|||
// the lock
|
||||
}
|
||||
|
||||
/**
|
||||
* Start.
|
||||
*/
|
||||
public void start() {
|
||||
this.futuresThread.start();
|
||||
}
|
||||
|
||||
/** The run. */
|
||||
private volatile boolean run = true;
|
||||
|
||||
/**
|
||||
* The Class FuturesRunnable.
|
||||
*/
|
||||
public class FuturesRunnable implements Runnable {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (FuturesProcessor.this.run) {
|
||||
|
@ -85,22 +120,41 @@ public class FuturesProcessor {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class Job.
|
||||
*/
|
||||
public class Job {
|
||||
|
||||
/** The first invocation. */
|
||||
long firstInvocation;
|
||||
|
||||
/** The delay. */
|
||||
long delay;
|
||||
|
||||
/** The delay jitter. */
|
||||
long delayJitter;
|
||||
|
||||
/** The probability. */
|
||||
double probability;
|
||||
|
||||
/** The renew. */
|
||||
boolean renew;
|
||||
|
||||
/** The r. */
|
||||
Runnable r;
|
||||
|
||||
/** The next invocation. */
|
||||
volatile long nextInvocation;
|
||||
|
||||
/**
|
||||
* @param firstInvocation
|
||||
* @param delay
|
||||
* @param delayJitter
|
||||
* @param probability
|
||||
* @param renew
|
||||
* @param r
|
||||
* Instantiates a new job.
|
||||
*
|
||||
* @param firstInvocation the first invocation
|
||||
* @param delay the delay
|
||||
* @param delayJitter the delay jitter
|
||||
* @param probability the probability
|
||||
* @param renew the renew
|
||||
* @param r the r
|
||||
*/
|
||||
public Job(long firstInvocation, long delay, long delayJitter,
|
||||
double probability, boolean renew, Runnable r) {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class GameMesh.
|
||||
*/
|
||||
public class GameMesh {
|
||||
|
||||
}
|
||||
|
|
|
@ -16,12 +16,28 @@ import org.iq80.leveldb.DB;
|
|||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GenericManager.
|
||||
*
|
||||
* @param <E> the element type
|
||||
* @param <B> the generic type
|
||||
*/
|
||||
public class GenericManager<E, B> {
|
||||
|
||||
/** The def items. */
|
||||
private ArrayList<MossItem> defItems = new ArrayList<>();
|
||||
|
||||
/** The def items by name. */
|
||||
private HashMap<String, MossItem> defItemsByName = new HashMap<>();
|
||||
|
||||
/** The pending. */
|
||||
private HashBiMap<Short, String> pending = HashBiMap.create();
|
||||
|
||||
/** The item db. */
|
||||
private DB itemDb;
|
||||
|
||||
/** The unknown fallback item. */
|
||||
private final MossItem unknownFallbackItem = new MossItem(
|
||||
"item_unknown.png", "sys_hand.png", 1, true,
|
||||
"An unidentifiable item", "sys:unknown");
|
||||
|
@ -32,10 +48,23 @@ public class GenericManager<E, B> {
|
|||
this.unknownFallbackItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node.
|
||||
*
|
||||
* @param nodeId the node id
|
||||
* @return the node
|
||||
*/
|
||||
public MossItem getNode(short nodeId) {
|
||||
return this.defItems.get(nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put node.
|
||||
*
|
||||
* @param item the item
|
||||
* @return the short
|
||||
* @throws MossWorldLoadException the moss world load exception
|
||||
*/
|
||||
public short putNode(MossItem item) throws MossWorldLoadException {
|
||||
if (this.pending.containsValue(item.getTechnicalName())) {
|
||||
item.setItemId(this.pending.inverse().get(item.getTechnicalName()));
|
||||
|
@ -58,16 +87,35 @@ public class GenericManager<E, B> {
|
|||
return item.getItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put node alias.
|
||||
*
|
||||
* @param alias the alias
|
||||
* @param dst the dst
|
||||
*/
|
||||
public void putNodeAlias(String alias, String dst) {
|
||||
MossItem dstItem = this.defItemsByName.get(dst);
|
||||
this.defItemsByName.put(alias, dstItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
* @param string the string
|
||||
* @param isModified the is modified
|
||||
* @return the item
|
||||
*/
|
||||
public MossItem getItem(String string, boolean isModified) {
|
||||
MossItem r = this.defItemsByName.get(string);
|
||||
return r == null ? this.unknownFallbackItem : r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
* @param string the string
|
||||
* @return the item
|
||||
*/
|
||||
public MossItem getItem(String string) {
|
||||
|
||||
MossItem r = this.defItemsByName.get(string);
|
||||
|
@ -75,7 +123,9 @@ public class GenericManager<E, B> {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new generic manager.
|
||||
*
|
||||
* @param itemdb the itemdb
|
||||
*/
|
||||
public GenericManager(DB itemdb) {
|
||||
this.itemDb = itemdb;
|
||||
|
@ -86,8 +136,15 @@ public class GenericManager<E, B> {
|
|||
}
|
||||
}
|
||||
|
||||
/** The items for node. */
|
||||
private static HashMap<MapNode, MossItem> itemsForNode = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the for node.
|
||||
*
|
||||
* @param nd the nd
|
||||
* @return the for node
|
||||
*/
|
||||
public static MossItem getForNode(MapNode nd) {
|
||||
MossItem item = itemsForNode.get(nd);
|
||||
if (item == null) {
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
/*
|
||||
*
|
||||
*/
|
||||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GenericTexture.
|
||||
*/
|
||||
public abstract class GenericTexture {
|
||||
|
||||
/** The last allocated tex id. */
|
||||
static long lastAllocatedTexId;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,18 +2,57 @@ package net.mosstest.servercore;
|
|||
|
||||
import net.mosstest.scripting.MapNode;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface INodeManager.
|
||||
*/
|
||||
public interface INodeManager {
|
||||
|
||||
/**
|
||||
* Gets the node.
|
||||
*
|
||||
* @param nodeId the node id
|
||||
* @return the node
|
||||
*/
|
||||
public abstract MapNode getNode(short nodeId);
|
||||
|
||||
/**
|
||||
* Put node.
|
||||
*
|
||||
* @param node the node
|
||||
* @return the short
|
||||
* @throws MossWorldLoadException the moss world load exception
|
||||
*/
|
||||
public abstract short putNode(MapNode node) throws MossWorldLoadException;
|
||||
|
||||
/**
|
||||
* Put node alias.
|
||||
*
|
||||
* @param alias the alias
|
||||
* @param dst the dst
|
||||
*/
|
||||
public abstract void putNodeAlias(String alias, String dst);
|
||||
|
||||
/**
|
||||
* Gets the node.
|
||||
*
|
||||
* @param string the string
|
||||
* @param isModified the is modified
|
||||
* @return the node
|
||||
*/
|
||||
public abstract MapNode getNode(String string, boolean isModified);
|
||||
|
||||
/**
|
||||
* Gets the node.
|
||||
*
|
||||
* @param string the string
|
||||
* @return the node
|
||||
*/
|
||||
public abstract MapNode getNode(String string);
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
public abstract void init();
|
||||
|
||||
}
|
|
@ -2,7 +2,18 @@ package net.mosstest.servercore;
|
|||
|
||||
import net.mosstest.scripting.Player;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface IPlayerManager.
|
||||
*/
|
||||
public interface IPlayerManager extends PlayerCommunicator {
|
||||
|
||||
/**
|
||||
* Gets the or create.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the or create
|
||||
*/
|
||||
public abstract Player getOrCreate(String name);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,18 +3,52 @@ package net.mosstest.servercore;
|
|||
import net.mosstest.scripting.MapChunk;
|
||||
import net.mosstest.scripting.Position;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface IRenderPreparator.
|
||||
*/
|
||||
public interface IRenderPreparator extends PlayerCommunicator{
|
||||
|
||||
/**
|
||||
* Sets the render processor.
|
||||
*
|
||||
* @param rend the new render processor
|
||||
*/
|
||||
public abstract void setRenderProcessor(RenderProcessor rend);
|
||||
|
||||
/**
|
||||
* Request chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return the map chunk
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public abstract MapChunk requestChunk(Position pos)
|
||||
throws MapGeneratorException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Recv outstanding chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param chk the chk
|
||||
*/
|
||||
public abstract void recvOutstandingChunk(Position pos, MapChunk chk);
|
||||
|
||||
/**
|
||||
* Shutdown.
|
||||
*/
|
||||
public abstract void shutdown();
|
||||
|
||||
/**
|
||||
* Start.
|
||||
*/
|
||||
public abstract void start();
|
||||
|
||||
/**
|
||||
* Sets the node manager.
|
||||
*
|
||||
* @param nm the new node manager
|
||||
*/
|
||||
public abstract void setNodeManager(INodeManager nm);
|
||||
}
|
|
@ -16,12 +16,25 @@ import org.iq80.leveldb.DB;
|
|||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ItemManager.
|
||||
*/
|
||||
public class ItemManager {
|
||||
|
||||
/** The def items. */
|
||||
private ArrayList<MossItem> defItems = new ArrayList<>();
|
||||
|
||||
/** The def items by name. */
|
||||
private HashMap<String, MossItem> defItemsByName = new HashMap<>();
|
||||
|
||||
/** The pending. */
|
||||
private HashBiMap<Short, String> pending = HashBiMap.create();
|
||||
|
||||
/** The item db. */
|
||||
private DB itemDb;
|
||||
|
||||
/** The unknown fallback item. */
|
||||
private final MossItem unknownFallbackItem = new MossItem(
|
||||
"item_unknown.png", "sys_hand.png", 1, true,
|
||||
"An unidentifiable item", "sys:unknown");
|
||||
|
@ -32,10 +45,23 @@ public class ItemManager {
|
|||
this.unknownFallbackItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node.
|
||||
*
|
||||
* @param nodeId the node id
|
||||
* @return the node
|
||||
*/
|
||||
public MossItem getNode(short nodeId) {
|
||||
return this.defItems.get(nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put node.
|
||||
*
|
||||
* @param item the item
|
||||
* @return the short
|
||||
* @throws MossWorldLoadException the moss world load exception
|
||||
*/
|
||||
public short putNode(MossItem item) throws MossWorldLoadException {
|
||||
if (this.pending.containsValue(item.getTechnicalName())) {
|
||||
item.setItemId(this.pending.inverse().get(item.getTechnicalName()));
|
||||
|
@ -58,16 +84,35 @@ public class ItemManager {
|
|||
return item.getItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put node alias.
|
||||
*
|
||||
* @param alias the alias
|
||||
* @param dst the dst
|
||||
*/
|
||||
public void putNodeAlias(String alias, String dst) {
|
||||
MossItem dstItem = this.defItemsByName.get(dst);
|
||||
this.defItemsByName.put(alias, dstItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
* @param string the string
|
||||
* @param isModified the is modified
|
||||
* @return the item
|
||||
*/
|
||||
public MossItem getItem(String string, boolean isModified) {
|
||||
MossItem r = this.defItemsByName.get(string);
|
||||
return r == null ? this.unknownFallbackItem : r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
* @param string the string
|
||||
* @return the item
|
||||
*/
|
||||
public MossItem getItem(String string) {
|
||||
|
||||
MossItem r = this.defItemsByName.get(string);
|
||||
|
@ -75,7 +120,9 @@ public class ItemManager {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new item manager.
|
||||
*
|
||||
* @param itemdb the itemdb
|
||||
*/
|
||||
public ItemManager(DB itemdb) {
|
||||
this.itemDb = itemdb;
|
||||
|
@ -86,8 +133,15 @@ public class ItemManager {
|
|||
}
|
||||
}
|
||||
|
||||
/** The items for node. */
|
||||
private static HashMap<MapNode, MossItem> itemsForNode = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the for node.
|
||||
*
|
||||
* @param nd the nd
|
||||
* @return the for node
|
||||
*/
|
||||
public static MossItem getForNode(MapNode nd) {
|
||||
MossItem item = itemsForNode.get(nd);
|
||||
if (item == null) {
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Launcher.
|
||||
*/
|
||||
public class Launcher {
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args){
|
||||
//real todo
|
||||
}
|
||||
|
|
|
@ -14,7 +14,13 @@ import org.iq80.leveldb.DB;
|
|||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class LocalNodeManager.
|
||||
*/
|
||||
public class LocalNodeManager extends AbstractNodeManager {
|
||||
|
||||
/** The node db. */
|
||||
private DB nodeDb;
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -80,7 +86,9 @@ public class LocalNodeManager extends AbstractNodeManager {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new local node manager.
|
||||
*
|
||||
* @param nodedb the nodedb
|
||||
*/
|
||||
public LocalNodeManager(DB nodedb) {
|
||||
this.nodeDb = nodedb;
|
||||
|
|
|
@ -10,11 +10,23 @@ import net.mosstest.scripting.Player;
|
|||
import net.mosstest.scripting.Position;
|
||||
import net.mosstest.scripting.SimplexMapGenerator;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class LocalRenderPreparator.
|
||||
*/
|
||||
public class LocalRenderPreparator implements IRenderPreparator {
|
||||
|
||||
/** The logger. */
|
||||
static Logger logger = Logger.getLogger(LocalRenderPreparator.class);
|
||||
|
||||
/**
|
||||
* The Class ChunkLookupRunnable.
|
||||
*/
|
||||
public class ChunkLookupRunnable implements Runnable {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (LocalRenderPreparator.this.run) {
|
||||
|
@ -41,17 +53,32 @@ public class LocalRenderPreparator implements IRenderPreparator {
|
|||
|
||||
}
|
||||
|
||||
/** The local player. */
|
||||
private Player localPlayer;
|
||||
|
||||
/** The rend. */
|
||||
private RenderProcessor rend;
|
||||
|
||||
/** The nc. */
|
||||
private NodeCache nc;
|
||||
|
||||
/** The run. */
|
||||
private volatile boolean run = true;
|
||||
|
||||
/** The chunk requests. */
|
||||
public ArrayBlockingQueue<Position> chunkRequests = new ArrayBlockingQueue<>(
|
||||
1024);
|
||||
// private HashMap<Position, Position> outstandingChunks = new HashMap<>();
|
||||
|
||||
/** The lookup thread. */
|
||||
private Thread lookupThread = new Thread(new ChunkLookupRunnable());
|
||||
|
||||
/** The nm. */
|
||||
private INodeManager nm;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#requestChunk(net.mosstest.scripting.Position)
|
||||
*/
|
||||
@Override
|
||||
public MapChunk requestChunk(Position pos) throws MapGeneratorException,
|
||||
InterruptedException {
|
||||
|
@ -69,21 +96,36 @@ public class LocalRenderPreparator implements IRenderPreparator {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new local render preparator.
|
||||
*
|
||||
* @param rp the rp
|
||||
* @param nc the nc
|
||||
*/
|
||||
public LocalRenderPreparator(RenderProcessor rp, NodeCache nc) {
|
||||
this.rend = rp;
|
||||
this.nc = nc;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#shutdown()
|
||||
*/
|
||||
@Override
|
||||
public void shutdown() {
|
||||
this.run = false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#recvOutstandingChunk(net.mosstest.scripting.Position, net.mosstest.scripting.MapChunk)
|
||||
*/
|
||||
@Override
|
||||
public void recvOutstandingChunk(Position pos, MapChunk chk) {
|
||||
// pass
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#start()
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
try {
|
||||
|
@ -98,17 +140,26 @@ public class LocalRenderPreparator implements IRenderPreparator {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#setRenderProcessor(net.mosstest.servercore.RenderProcessor)
|
||||
*/
|
||||
@Override
|
||||
public void setRenderProcessor(RenderProcessor rend) {
|
||||
this.rend = rend;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.IRenderPreparator#setNodeManager(net.mosstest.servercore.INodeManager)
|
||||
*/
|
||||
@Override
|
||||
public void setNodeManager(INodeManager nm) {
|
||||
this.nm = nm;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.PlayerCommunicator#forceSetPosition(net.mosstest.scripting.Player, int, int, int, double, double, double)
|
||||
*/
|
||||
@Override
|
||||
public void forceSetPosition(Player pl, int cx, int cy, int cz,
|
||||
double offsetx, double offsety, double offsetz) throws InterruptedException {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class MapChangeEvent.
|
||||
*/
|
||||
public class MapChangeEvent {
|
||||
|
||||
}
|
||||
|
|
|
@ -15,15 +15,40 @@ import org.iq80.leveldb.DB;
|
|||
import org.iq80.leveldb.DBComparator;
|
||||
import org.iq80.leveldb.Options;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapDatabase.
|
||||
*/
|
||||
public class MapDatabase {
|
||||
|
||||
/** The map. */
|
||||
DB map;
|
||||
|
||||
/** The entities. */
|
||||
DB entities;
|
||||
|
||||
/** The metadata. */
|
||||
DB metadata;
|
||||
|
||||
/** The map heavies. */
|
||||
DB mapHeavies;
|
||||
|
||||
/** The landclaims. */
|
||||
DB landclaims;
|
||||
|
||||
/** The players. */
|
||||
DB players;
|
||||
|
||||
/** The nodes. */
|
||||
public DB nodes;
|
||||
|
||||
/**
|
||||
* Instantiates a new map database.
|
||||
*
|
||||
* @param basedir the basedir
|
||||
* @throws MapDatabaseException the map database exception
|
||||
* @throws MossWorldLoadException the moss world load exception
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public MapDatabase(File basedir) throws MapDatabaseException,
|
||||
MossWorldLoadException {
|
||||
|
@ -47,6 +72,11 @@ public class MapDatabase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Close.
|
||||
*
|
||||
* @throws MapDatabaseException the map database exception
|
||||
*/
|
||||
public void close() throws MapDatabaseException {
|
||||
try {
|
||||
this.map.close();
|
||||
|
@ -60,6 +90,13 @@ public class MapDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return the chunk
|
||||
* @throws MapGeneratorException the map generator exception
|
||||
*/
|
||||
public MapChunk getChunk(final Position pos) throws MapGeneratorException {
|
||||
|
||||
byte[] chunk = this.map.get(pos.toBytes());
|
||||
|
@ -78,9 +115,10 @@ public class MapDatabase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws MossWorldLoadException
|
||||
* @throws MapDatabaseException
|
||||
* Adds the map chunk.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param mapChunk the map chunk
|
||||
*/
|
||||
|
||||
void addMapChunk(Position pos, MapChunk mapChunk) {
|
||||
|
@ -88,6 +126,12 @@ public class MapDatabase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the heavy.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return the heavy
|
||||
*/
|
||||
public byte[] getHeavy(Position pos) {
|
||||
return this.mapHeavies.get(pos.toBytes());
|
||||
}
|
||||
|
|
|
@ -1,15 +1,44 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapDatabaseException.
|
||||
*/
|
||||
public class MapDatabaseException extends Exception{
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -1261363696203853384L;
|
||||
|
||||
/** The Constant SEVERITY_CORRUPT. */
|
||||
public static final int SEVERITY_CORRUPT = 0;
|
||||
|
||||
/** The Constant SEVERITY_CORRUPT_REPARABLE. */
|
||||
public static final int SEVERITY_CORRUPT_REPARABLE = 1;
|
||||
|
||||
/** The Constant SEVERITY_FATAL_TRANSIENT. */
|
||||
public static final int SEVERITY_FATAL_TRANSIENT = 2;
|
||||
|
||||
/** The Constant SEVERITY_WARNING. */
|
||||
public static final int SEVERITY_WARNING = 4;
|
||||
|
||||
/** The Constant SEVERITY_NOTFOUND. */
|
||||
public static final int SEVERITY_NOTFOUND = 8;
|
||||
|
||||
/** The Constant SEVERITY_UNKNOWN. */
|
||||
public static final int SEVERITY_UNKNOWN = 16;
|
||||
|
||||
/** The desc. */
|
||||
public String desc;
|
||||
|
||||
/** The severity. */
|
||||
public int severity;
|
||||
|
||||
/**
|
||||
* Instantiates a new map database exception.
|
||||
*
|
||||
* @param severity the severity
|
||||
* @param desc the desc
|
||||
*/
|
||||
public MapDatabaseException(int severity, String desc) {
|
||||
super();
|
||||
this.desc = desc;
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MapGeneratorException.
|
||||
*/
|
||||
public class MapGeneratorException extends Exception {
|
||||
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -8402982836293707854L;
|
||||
//marker type
|
||||
}
|
||||
|
|
|
@ -3,19 +3,40 @@ package net.mosstest.servercore;
|
|||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Messages.
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
/** The Constant BUNDLE_NAME. */
|
||||
private static final String BUNDLE_NAME = "net.mosstest.servercore.messages"; //$NON-NLS-1$
|
||||
|
||||
/** The res bundle. */
|
||||
private static ResourceBundle resBundle = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
/**
|
||||
* Change language.
|
||||
*
|
||||
* @param identifier the identifier
|
||||
*/
|
||||
public static void changeLanguage(String identifier) {
|
||||
resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new messages.
|
||||
*/
|
||||
private Messages() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the string
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return resBundle.getString(key);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class MossChunkDrawEvent.
|
||||
*/
|
||||
public class MossChunkDrawEvent extends MossRenderEvent {
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,16 @@ import java.util.Properties;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossDebugUtils.
|
||||
*/
|
||||
public class MossDebugUtils {
|
||||
|
||||
/** The logger. */
|
||||
static Logger logger = Logger.getLogger(MossDebugUtils.class);
|
||||
|
||||
/** The Constant propertiesToGet. */
|
||||
private static final String[] propertiesToGet = { "awt.toolkit", //$NON-NLS-1$
|
||||
"file.encoding", "file.separator", "java.class.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"java.home", "java.runtime.name", "java.runtime.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
@ -21,6 +28,12 @@ public class MossDebugUtils {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Write stracktrace.
|
||||
*
|
||||
* @param e the e
|
||||
* @return the string
|
||||
*/
|
||||
public static String writeStracktrace(Exception e) {
|
||||
String fName = Integer.toString(System.identityHashCode(e), 16) + "@"
|
||||
+ System.currentTimeMillis();
|
||||
|
@ -37,6 +50,12 @@ public class MossDebugUtils {
|
|||
return write.getAbsolutePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the debug information.
|
||||
*
|
||||
* @param e the e
|
||||
* @return the debug information
|
||||
*/
|
||||
public static String getDebugInformation(Exception e) {
|
||||
StringBuilder s = new StringBuilder(
|
||||
MossDebugUtils.getGitConfig("git.commit.id") + " on " + MossDebugUtils.getGitConfig("git.branch") + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
|
@ -50,6 +69,11 @@ public class MossDebugUtils {
|
|||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the os details.
|
||||
*
|
||||
* @return the os details
|
||||
*/
|
||||
public static String getOsDetails() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
|
||||
|
@ -82,6 +106,12 @@ public class MossDebugUtils {
|
|||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the git config.
|
||||
*
|
||||
* @param cfgKey the cfg key
|
||||
* @return the git config
|
||||
*/
|
||||
private static String getGitConfig(String cfgKey) {
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
|
|
@ -5,13 +5,18 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossFile.
|
||||
*/
|
||||
public abstract class MossFile {
|
||||
|
||||
/**
|
||||
* Get a local copy of the file. This may be either a direct local file or a
|
||||
* cached file.
|
||||
*
|
||||
*
|
||||
* @return A valid RandomAccessFile.
|
||||
* @throws FileNotFoundException
|
||||
* @throws FileNotFoundException the file not found exception
|
||||
*/
|
||||
public abstract RandomAccessFile getRandAccessCopy() throws FileNotFoundException;
|
||||
|
||||
|
@ -21,6 +26,13 @@ public abstract class MossFile {
|
|||
*/
|
||||
public final String dirName;
|
||||
|
||||
/**
|
||||
* Read chunk.
|
||||
*
|
||||
* @param chk the chk
|
||||
* @return the byte[]
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public abstract byte[] readChunk(int chk) throws IOException;
|
||||
|
||||
/**
|
||||
|
@ -29,18 +41,30 @@ public abstract class MossFile {
|
|||
public final String resourceName;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the size.
|
||||
*
|
||||
* @return the size
|
||||
*/
|
||||
public abstract long getSize();
|
||||
|
||||
/**
|
||||
* @param author
|
||||
* @param plugin
|
||||
* @param resourceName
|
||||
* Instantiates a new moss file.
|
||||
*
|
||||
* @param dirName the dir name
|
||||
* @param resourceName the resource name
|
||||
*/
|
||||
public MossFile(String dirName, String resourceName) {
|
||||
this.dirName=dirName;
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file.
|
||||
*
|
||||
* @return the file
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public abstract File getFile() throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,18 @@ import java.util.ArrayList;
|
|||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.commons.configuration.XMLConfiguration;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossGame.
|
||||
*/
|
||||
public class MossGame {
|
||||
|
||||
/**
|
||||
* Instantiates a new moss game.
|
||||
*
|
||||
* @param name the name
|
||||
* @throws MossWorldLoadException the moss world load exception
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public MossGame(String name) throws MossWorldLoadException {
|
||||
this.baseDir = new File("data/games/" + name); //$NON-NLS-1$
|
||||
|
@ -34,11 +45,23 @@ public class MossGame {
|
|||
}
|
||||
}
|
||||
|
||||
/** The base dir. */
|
||||
private File baseDir;
|
||||
|
||||
/** The game cfg. */
|
||||
private XMLConfiguration gameCfg;
|
||||
|
||||
/** The cfg file. */
|
||||
private File cfgFile;
|
||||
|
||||
/** The scripts. */
|
||||
private ArrayList<MossScript> scripts;
|
||||
|
||||
/**
|
||||
* Gets the scripts.
|
||||
*
|
||||
* @return the scripts
|
||||
*/
|
||||
public ArrayList<MossScript> getScripts() {
|
||||
return this.scripts;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
/**
|
||||
* The Class MossGenericEvent.
|
||||
*/
|
||||
public class MossGenericEvent {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,23 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossLocalFile.
|
||||
*/
|
||||
public class MossLocalFile extends MossFile {
|
||||
|
||||
/** The Constant CHUNK_LENGTH. */
|
||||
public static final int CHUNK_LENGTH = 65536;
|
||||
|
||||
/**
|
||||
* Instantiates a new moss local file.
|
||||
*
|
||||
* @param baseDir the base dir
|
||||
* @param dirName the dir name
|
||||
* @param resourceName the resource name
|
||||
* @throws FileNotFoundException the file not found exception
|
||||
*/
|
||||
public MossLocalFile(File baseDir, String dirName, String resourceName) throws FileNotFoundException {
|
||||
// super call to establish fields.
|
||||
super(dirName, resourceName);
|
||||
|
@ -17,13 +31,20 @@ public class MossLocalFile extends MossFile {
|
|||
this.file = new File(this.file, resourceName);
|
||||
}
|
||||
|
||||
/** The file. */
|
||||
private File file;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.MossFile#getRandAccessCopy()
|
||||
*/
|
||||
@Override
|
||||
public RandomAccessFile getRandAccessCopy() throws FileNotFoundException {
|
||||
return new RandomAccessFile(this.file, "r"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.MossFile#readChunk(int)
|
||||
*/
|
||||
public byte[] readChunk(int chk) throws IOException {
|
||||
if ((chk < 0) || (chk > 65535))
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -36,6 +57,9 @@ public class MossLocalFile extends MossFile {
|
|||
return buf;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.MossFile#getSize()
|
||||
*/
|
||||
@Override
|
||||
public long getSize() {
|
||||
|
||||
|
@ -43,6 +67,9 @@ public class MossLocalFile extends MossFile {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.mosstest.servercore.MossFile#getFile()
|
||||
*/
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class MossNetPacket.
|
||||
*/
|
||||
public class MossNetPacket {
|
||||
|
||||
/** The command id. */
|
||||
int commandId;
|
||||
|
||||
/** The payload. */
|
||||
byte[] payload;
|
||||
|
||||
/** The needs fast. */
|
||||
boolean needsFast;
|
||||
|
||||
/** The needs ack. */
|
||||
boolean needsAck;
|
||||
|
||||
/** The is important. */
|
||||
boolean isImportant;
|
||||
|
||||
/** The sess. */
|
||||
ServerSession sess;
|
||||
/**
|
||||
* Constructs a packet, for either sending or from receiving.
|
||||
|
@ -19,6 +35,16 @@ public class MossNetPacket {
|
|||
this.needsFast = false;
|
||||
this.isImportant = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new moss net packet.
|
||||
*
|
||||
* @param commandId the command id
|
||||
* @param payload the payload
|
||||
* @param needsFast the needs fast
|
||||
* @param needsAck the needs ack
|
||||
* @param isImportant the is important
|
||||
*/
|
||||
public MossNetPacket(int commandId, byte[] payload, boolean needsFast,
|
||||
boolean needsAck, boolean isImportant) {
|
||||
this.commandId = commandId;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
package net.mosstest.servercore;
|
||||
|
||||
import net.mosstest.scripting.Position;
|
||||
|
||||
public class MossNodeAddEvent extends MossRenderEvent {
|
||||
private int x, y, z; //position in chunk
|
||||
private short definition;
|
||||
private Position parentChunkPosition;
|
||||
public MossNodeAddEvent (int x, int y, int z, Position parentChunkPosition, short definition) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.definition = definition;
|
||||
this.parentChunkPosition = parentChunkPosition;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
public short getDef() {
|
||||
return definition;
|
||||
}
|
||||
public Position getPosition () {
|
||||
return parentChunkPosition;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue