mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Boilerplate code for Vault Door
This commit is contained in:
parent
ce0584a49f
commit
9bb0dc9034
@ -15,6 +15,9 @@
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
|
@ -14,6 +14,9 @@
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
|
@ -17,5 +17,8 @@
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -17,5 +17,8 @@
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" />
|
||||
</component>
|
||||
</module>
|
31
Plugin Vault/pom.xml
Normal file
31
Plugin Vault/pom.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.2a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.pluginplant</groupId>
|
||||
<artifactId>plugin-vault</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.2a</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,102 @@
|
||||
package net.simon987.vaultplugin;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import net.simon987.server.game.Enterable;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.Programmable;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class VaultDoor extends GameObject implements Programmable, Enterable, Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x0800;
|
||||
|
||||
/**
|
||||
* Password to open the vault door
|
||||
*/
|
||||
private char[] password;
|
||||
|
||||
/**
|
||||
* Whether or not the vault door is opened
|
||||
*/
|
||||
private boolean opened;
|
||||
|
||||
private int openedTimer;
|
||||
|
||||
/**
|
||||
* Number of ticks to remain the door open
|
||||
*/
|
||||
private static final int OPEN_TIME = 4; //todo load from config
|
||||
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
if (openedTimer <= 0) {
|
||||
|
||||
//Door was opened for OPEN_TIME, close it and regen password
|
||||
password = getRandomPassword();
|
||||
opened = false;
|
||||
|
||||
LogManager.LOGGER.fine("Closed Vault door ID: " + getObjectId());
|
||||
} else {
|
||||
openedTimer--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendMessage(char[] message) {
|
||||
|
||||
System.out.println("VAULT: sendMessage" + new String(message));//todo rmv
|
||||
|
||||
if (!opened) {
|
||||
|
||||
if (Arrays.equals(message, password)) {
|
||||
opened = true;
|
||||
openedTimer = OPEN_TIME;
|
||||
|
||||
LogManager.LOGGER.fine("Opened Vault door ID: " + getObjectId());
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//Can't receive messages when opened
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enter(GameObject object) {
|
||||
|
||||
LogManager.LOGGER.fine("VAULT enter " + opened);
|
||||
|
||||
if (opened) {
|
||||
|
||||
//TODO: Enter in the vault
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static char[] getRandomPassword() {
|
||||
return "12345678".toCharArray();//todo actual random password
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getMapInfo() {
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDBObject mongoSerialise() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.simon987.vaultplugin;
|
||||
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
public class VaultPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(ServerConfiguration config) {
|
||||
|
||||
|
||||
LogManager.LOGGER.info("Initialised Vault plugin");
|
||||
}
|
||||
}
|
3
Plugin Vault/src/main/resources/plugin.properties
Normal file
3
Plugin Vault/src/main/resources/plugin.properties
Normal file
@ -0,0 +1,3 @@
|
||||
classpath=net.simon987.vaultplugin.VaultPlugin
|
||||
name=Vault Plugin
|
||||
version=1.0
|
@ -18,5 +18,6 @@
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
13
Server/src/main/java/net/simon987/server/game/Enterable.java
Normal file
13
Server/src/main/java/net/simon987/server/game/Enterable.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.simon987.server.game;
|
||||
|
||||
public interface Enterable {
|
||||
|
||||
/**
|
||||
* Called when an object attempts to walk directly into a Enterable object
|
||||
*
|
||||
* @param object The game object that attempted to enter
|
||||
* @return true if successful,
|
||||
*/
|
||||
boolean enter(GameObject object);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user