archive update
This commit is contained in:
parent
2bdcb66388
commit
7bde8ac1a7
@ -47,12 +47,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import us.camin.api.ValidationResponse;
|
||||
import us.camin.api.ClientEvent;
|
||||
import us.camin.api.BlockEvent;
|
||||
import us.camin.api.ChatEvent;
|
||||
import us.camin.api.DeathEvent;
|
||||
import us.camin.api.MurderEvent;
|
||||
import us.camin.api.WeatherEvent;
|
||||
import us.camin.api.events.*;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
Logger log = Logger.getLogger("Caminus.Join");
|
||||
@ -151,7 +146,7 @@ public class JoinListener implements Listener {
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player target = event.getEntity();
|
||||
Entity source = target.getKiller();
|
||||
ClientEvent evt = new DeathEvent(target.getName(), event.getDeathMessage());
|
||||
Event evt = new DeathEvent(target.getName(), event.getDeathMessage());
|
||||
m_plugin.sendEvent(evt);
|
||||
if (source instanceof Player) {
|
||||
Player killer = (Player)source;
|
||||
|
@ -52,14 +52,7 @@ import java.util.ListIterator;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import us.camin.api.Server;
|
||||
import us.camin.api.ServerEvent;
|
||||
import us.camin.api.BroadcastEvent;
|
||||
import us.camin.api.PlayerMessageEvent;
|
||||
import us.camin.api.ClientEvent;
|
||||
import us.camin.api.VaultModifyEvent;
|
||||
import us.camin.api.PlayerVaultSlot;
|
||||
import us.camin.api.HeartbeatEvent;
|
||||
import us.camin.api.KickEvent;
|
||||
import us.camin.api.events.*;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class Plugin extends JavaPlugin {
|
||||
@ -89,7 +82,7 @@ public class Plugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleEvent(ServerEvent e) {
|
||||
public void handleEvent(us.camin.api.events.Event e) {
|
||||
if (e instanceof BroadcastEvent) {
|
||||
final BroadcastEvent evt = (BroadcastEvent)(e);
|
||||
getServer().getScheduler().callSyncMethod(this, new Callable<Void>() {
|
||||
@ -106,8 +99,8 @@ public class Plugin extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else if (e instanceof VaultModifyEvent) {
|
||||
final VaultModifyEvent evt = (VaultModifyEvent)(e);
|
||||
} else if (e instanceof VaultContentsEvent) {
|
||||
final VaultContentsEvent evt = (VaultContentsEvent)(e);
|
||||
getServer().getScheduler().callSyncMethod(this, new Callable<Void>() {
|
||||
public Void call() {
|
||||
Inventory inv;
|
||||
@ -116,33 +109,35 @@ public class Plugin extends JavaPlugin {
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
for (PlayerVaultSlot s : evt.contents) {
|
||||
for (VaultSlot s : evt.items) {
|
||||
if (s.quantity == -1) {
|
||||
inv.clear(s.position);
|
||||
} else {
|
||||
inv.setItem(s.position, new ItemStack(s.item, s.quantity, s.damage, s.data));
|
||||
inv.setItem(s.position, new ItemStack(s.material, s.quantity, (short)s.damage, (byte)s.data));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else if (e instanceof KickEvent) {
|
||||
final KickEvent evt = (KickEvent)(e);
|
||||
} else if (e instanceof PlayerKickEvent) {
|
||||
final PlayerKickEvent evt = (PlayerKickEvent)(e);
|
||||
log.info("Got kick event for "+evt.player+": "+evt.message);
|
||||
Player p = getServer().getPlayer(evt.player);
|
||||
if (p != null) {
|
||||
p.kickPlayer(evt.message);
|
||||
}
|
||||
}
|
||||
try {
|
||||
m_api.notifyEventHandled(e);
|
||||
} catch (IOException ex) {
|
||||
log.severe("Could not close out event. Duplicates will happen!!!");
|
||||
if (e != null) {
|
||||
try {
|
||||
m_api.notifyEventHandled(e);
|
||||
} catch (IOException ex) {
|
||||
log.severe("Could not close out event. Duplicates will happen!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendEvent(ClientEvent event) {
|
||||
ClientEvent[] events = new ClientEvent[1];
|
||||
public void sendEvent(us.camin.api.events.Event event) {
|
||||
us.camin.api.events.Event[] events = new us.camin.api.events.Event[1];
|
||||
events[0] = event;
|
||||
try {
|
||||
api().sendEvents(events);
|
||||
@ -195,10 +190,10 @@ public class Plugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void sendHeartbeat() {
|
||||
HeartbeatEvent evt = new HeartbeatEvent();
|
||||
ServerHeartbeatEvent evt = new ServerHeartbeatEvent();
|
||||
evt.port = getServer().getPort();
|
||||
evt.name = getServer().getName();
|
||||
HashMap<String, Long> times = new HashMap<String, Long>();
|
||||
HashMap<String, Object> times = new HashMap<String, Object>();
|
||||
for (World w : getServer().getWorlds()) {
|
||||
times.put(w.getName(), w.getTime());
|
||||
}
|
||||
@ -280,14 +275,14 @@ public class Plugin extends JavaPlugin {
|
||||
|
||||
public void saveVault(Player p, Inventory inv) throws IOException {
|
||||
ListIterator<ItemStack> items = inv.iterator();
|
||||
PlayerVaultSlot[] vault = new PlayerVaultSlot[inv.getSize()];
|
||||
VaultSlot[] vault = new VaultSlot[inv.getSize()];
|
||||
int i = 0;
|
||||
while(items.hasNext()) {
|
||||
ItemStack item = items.next();
|
||||
PlayerVaultSlot slot = new PlayerVaultSlot();
|
||||
VaultSlot slot = new VaultSlot();
|
||||
slot.position = i;
|
||||
if (item != null) {
|
||||
slot.item = item.getTypeId();
|
||||
slot.material = item.getTypeId();
|
||||
slot.quantity = item.getAmount();
|
||||
slot.damage = item.getDurability();
|
||||
slot.data = item.getData().getData();
|
||||
@ -313,9 +308,9 @@ public class Plugin extends JavaPlugin {
|
||||
if (!m_vaultInventories.containsKey(p.getName())) {
|
||||
Inventory inv = p.getServer().createInventory(p, InventoryType.CHEST);
|
||||
m_vaultInventories.put(p.getName(), inv);
|
||||
PlayerVaultSlot[] vault = m_api.loadVault(p.getName());
|
||||
VaultSlot[] vault = m_api.loadVault(p.getName());
|
||||
for(int i = 0;i<vault.length;i++) {
|
||||
inv.setItem(vault[i].position, new ItemStack(vault[i].item, vault[i].quantity, vault[i].damage, vault[i].data));
|
||||
inv.setItem(vault[i].position, new ItemStack(vault[i].material, vault[i].quantity, (short)vault[i].damage, (byte)vault[i].data));
|
||||
}
|
||||
}
|
||||
return m_vaultInventories.get(p.getName());
|
||||
|
@ -21,8 +21,9 @@ import java.lang.Runnable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
import us.camin.api.ServerEvent;
|
||||
import us.camin.api.events.Event;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
@ -39,14 +40,18 @@ public class ServerEventPoller implements Runnable {
|
||||
|
||||
public void run() {
|
||||
log.info("Poll events");
|
||||
ServerEvent[] events = new ServerEvent[0];
|
||||
Event[] events = new Event[0];
|
||||
try {
|
||||
events = m_plugin.api().pollEventQueue();
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "Could not poll events.", e);
|
||||
}
|
||||
if (m_running) {
|
||||
for(ServerEvent e : events) {
|
||||
m_plugin.handleEvent(e);
|
||||
for(Event e : events) {
|
||||
if (e != null) {
|
||||
log.info("Handling event "+e.jsonName());
|
||||
m_plugin.handleEvent(e);
|
||||
}
|
||||
}
|
||||
final BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
m_taskid = scheduler.scheduleAsyncDelayedTask(m_plugin, this);
|
||||
|
@ -1,68 +0,0 @@
|
||||
package us.camin.api;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class BlockEvent extends ClientEvent {
|
||||
public String sender;
|
||||
public Block block;
|
||||
public Type type;
|
||||
|
||||
public enum Type {
|
||||
BREAK, PLACE
|
||||
}
|
||||
|
||||
public BlockEvent(String player, Block block, Type type) {
|
||||
this.sender = player;
|
||||
this.block = block;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("sender").value(sender);
|
||||
String evtType;
|
||||
switch(type) {
|
||||
case BREAK:
|
||||
evtType = "break";
|
||||
break;
|
||||
case PLACE:
|
||||
evtType = "place";
|
||||
break;
|
||||
default:
|
||||
evtType = "unknown";
|
||||
}
|
||||
writer.key("type").value(evtType);
|
||||
writer.key("location");
|
||||
writer.object();
|
||||
Location loc = block.getLocation();
|
||||
writer.key("x").value(loc.getBlockX());
|
||||
writer.key("y").value(loc.getBlockY());
|
||||
writer.key("z").value(loc.getBlockZ());
|
||||
writer.endObject();
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "block";
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
package us.camin.api;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
import java.util.Map;
|
||||
|
||||
public class HeartbeatEvent extends ClientEvent {
|
||||
public Map<String, Long> worldTimes;
|
||||
public int port;
|
||||
public String name;
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("port").value(port);
|
||||
writer.key("name").value(name);
|
||||
writer.key("worlds").object();
|
||||
for (String world : worldTimes.keySet()) {
|
||||
writer.key(world).object();
|
||||
writer.key("time").value(worldTimes.get(world));
|
||||
writer.endObject();
|
||||
}
|
||||
writer.endObject();
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "heartbeat";
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package us.camin.api;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class MurderEvent extends ClientEvent {
|
||||
public String player;
|
||||
public String killer;
|
||||
public String message;
|
||||
|
||||
public MurderEvent(String player, String killer) {
|
||||
this.player = player;
|
||||
this.killer = killer;
|
||||
}
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(player);
|
||||
writer.key("killer").value(killer);
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "player-murder";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,9 @@ import org.json.JSONStringer;
|
||||
import java.util.Random;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
import us.camin.api.events.VaultSlot;
|
||||
import us.camin.api.events.Event;
|
||||
|
||||
public class Server {
|
||||
Logger log = Logger.getLogger("Caminus.API");
|
||||
private String m_url;
|
||||
@ -105,7 +108,18 @@ public class Server {
|
||||
}
|
||||
|
||||
public JSONObject readJSON(HttpURLConnection conn) throws IOException {
|
||||
BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
|
||||
BufferedInputStream in;
|
||||
try{
|
||||
in = new BufferedInputStream(conn.getInputStream());
|
||||
} catch (IOException e) {
|
||||
String errorStr;
|
||||
try {
|
||||
errorStr = new java.util.Scanner(new BufferedInputStream(conn.getErrorStream())).useDelimiter("\\A").next();
|
||||
throw new IOException("Got bad data from server: "+errorStr, e);
|
||||
} catch (java.util.NoSuchElementException errExc) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
String jsonStr;
|
||||
try {
|
||||
jsonStr = new java.util.Scanner(in).useDelimiter("\\A").next();
|
||||
@ -117,7 +131,7 @@ public class Server {
|
||||
JSONObject jsonObj = new JSONObject(jsonStr);
|
||||
return jsonObj;
|
||||
} catch (JSONException e) {
|
||||
throw new IOException("JSON parse error", e);
|
||||
throw new IOException("JSON parse error: "+jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,20 +249,20 @@ public class Server {
|
||||
get("server/session/"+player+"/close");
|
||||
}
|
||||
|
||||
public void notifyEventHandled(ServerEvent event) throws IOException {
|
||||
log.info("Closing event "+event.id);
|
||||
public void notifyEventHandled(Event event) throws IOException {
|
||||
log.info("Closing event "+event._id);
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("job", Integer.toString(event.id));
|
||||
params.put("job", Integer.toString(event._id));
|
||||
post("server/events", params);
|
||||
}
|
||||
|
||||
public void sendEvents(ClientEvent[] event) throws JSONException, IOException {
|
||||
public void sendEvents(Event[] event) throws JSONException, IOException {
|
||||
log.info("Submitting events");
|
||||
JSONStringer out = new JSONStringer();
|
||||
out.object();
|
||||
out.key("events");
|
||||
out.array();
|
||||
for (ClientEvent evt : event) {
|
||||
for (Event evt : event) {
|
||||
out.value(evt.toJSON());
|
||||
}
|
||||
out.endArray();
|
||||
@ -258,20 +272,20 @@ public class Server {
|
||||
put("server/events", params);
|
||||
}
|
||||
|
||||
public ServerEvent[] pollEventQueue() throws IOException {
|
||||
public Event[] pollEventQueue() throws IOException {
|
||||
log.info("Polling server for events");
|
||||
JSONObject jsonObj = get("server/events");
|
||||
JSONArray eventList;
|
||||
try {
|
||||
eventList = jsonObj.getJSONArray("events");
|
||||
} catch (JSONException e) {
|
||||
return new ServerEvent[0];
|
||||
return new Event[0];
|
||||
}
|
||||
|
||||
ServerEvent[] events = new ServerEvent[eventList.length()];
|
||||
Event[] events = new Event[eventList.length()];
|
||||
for (int i = 0;i<eventList.length();i++) {
|
||||
try{
|
||||
events[i] = ServerEvent.fromJSON(eventList.getJSONObject(i));
|
||||
events[i] = Event.fromJSON(eventList.getJSONObject(i));
|
||||
} catch (JSONException e) {
|
||||
log.log(Level.SEVERE, "Bad JSON", e);
|
||||
events[i] = null;
|
||||
@ -302,21 +316,15 @@ public class Server {
|
||||
return resp;
|
||||
}
|
||||
|
||||
public PlayerVaultSlot[] loadVault(String player) throws IOException {
|
||||
public VaultSlot[] loadVault(String player) throws IOException {
|
||||
log.info("Opening vault for "+player);
|
||||
PlayerVaultSlot[] vault;
|
||||
VaultSlot[] vault;
|
||||
JSONObject jsonObj = get("server/vault/"+player);
|
||||
try {
|
||||
JSONArray items = jsonObj.getJSONArray("items");
|
||||
vault = new PlayerVaultSlot[items.length()];
|
||||
vault = new VaultSlot[items.length()];
|
||||
for(int i = 0;i<items.length();i++) {
|
||||
JSONObject slot = items.getJSONObject(i);
|
||||
vault[i] = new PlayerVaultSlot();
|
||||
vault[i].item = slot.optInt("item");
|
||||
vault[i].quantity = slot.optInt("quantity");
|
||||
vault[i].damage = (short)slot.optInt("damage");
|
||||
vault[i].data = (byte)slot.optInt("data");
|
||||
vault[i].position = slot.optInt("position");
|
||||
vault[i] = VaultSlot.fromJSON(items.getJSONObject(i));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new IOException("JSON parse error", e);
|
||||
@ -324,15 +332,15 @@ public class Server {
|
||||
return vault;
|
||||
}
|
||||
|
||||
public void saveVault(String player, PlayerVaultSlot[] vault) throws IOException, JSONException {
|
||||
public void saveVault(String player, VaultSlot[] vault) throws IOException, JSONException {
|
||||
log.info("Saving vault for "+player);
|
||||
JSONStringer out = new JSONStringer();
|
||||
out.object();
|
||||
out.key("items");
|
||||
out.array();
|
||||
for (PlayerVaultSlot item : vault) {
|
||||
for (VaultSlot item : vault) {
|
||||
out.object();
|
||||
out.key("item").value(item.item);
|
||||
out.key("item").value(item.material);
|
||||
out.key("quantity").value(item.quantity);
|
||||
out.key("damage").value(item.damage);
|
||||
out.key("data").value(item.data);
|
||||
|
@ -1,59 +0,0 @@
|
||||
package us.camin.api;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ServerEvent {
|
||||
public int id;
|
||||
static Logger log = Logger.getLogger("Caminus.api");
|
||||
public static ServerEvent fromJSON(JSONObject obj) {
|
||||
int id = obj.optInt("id");
|
||||
JSONObject event;
|
||||
try {
|
||||
event = obj.getJSONObject("event");
|
||||
} catch (JSONException e) {
|
||||
log.log(Level.SEVERE, "Bad JSON", e);
|
||||
return null;
|
||||
}
|
||||
String type = event.optString("type");
|
||||
JSONObject payload;
|
||||
try {
|
||||
payload = event.getJSONObject("payload");
|
||||
} catch (JSONException e) {
|
||||
log.log(Level.SEVERE, "Bad JSON ", e);
|
||||
return null;
|
||||
}
|
||||
if (type.equals("broadcast")) {
|
||||
return BroadcastEvent.fromJSON(payload, id);
|
||||
} else if (type.equals("player-message")) {
|
||||
return PlayerMessageEvent.fromJSON(payload, id);
|
||||
} else if (type.equals("vault-contents")) {
|
||||
return VaultModifyEvent.fromJSON(payload, id);
|
||||
} else if (type.equals("player-kick")) {
|
||||
return KickEvent.fromJSON(payload, id);
|
||||
} else {
|
||||
log.log(Level.SEVERE, "Unhandled event type: "+type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package us.camin.api;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class VaultModifyEvent extends ServerEvent {
|
||||
public PlayerVaultSlot[] contents;
|
||||
public String player;
|
||||
public static VaultModifyEvent fromJSON(JSONObject obj, int id) {
|
||||
VaultModifyEvent ret = new VaultModifyEvent();
|
||||
ret.player = obj.optString("player");
|
||||
ret.id = id;
|
||||
JSONArray items;
|
||||
try {
|
||||
items = obj.getJSONArray("items");
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
ret.contents = new PlayerVaultSlot[items.length()];
|
||||
for(int i = 0;i<items.length();i++) {
|
||||
JSONObject slot;
|
||||
try {
|
||||
slot = items.getJSONObject(i);
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
ret.contents[i] = new PlayerVaultSlot();
|
||||
ret.contents[i].item = slot.optInt("item");
|
||||
ret.contents[i].quantity = slot.optInt("quantity");
|
||||
ret.contents[i].damage = (short)slot.optInt("damage");
|
||||
ret.contents[i].data = (byte)slot.optInt("data");
|
||||
ret.contents[i].position = slot.optInt("position");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
47
src/main/java/us/camin/api/events/BlockBreakEvent.java
Normal file
47
src/main/java/us/camin/api/events/BlockBreakEvent.java
Normal file
@ -0,0 +1,47 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class BlockBreakEvent extends Event {
|
||||
public int y;
|
||||
public String player;
|
||||
public int material;
|
||||
public int z;
|
||||
public int x;
|
||||
public static BlockBreakEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
BlockBreakEvent ret = new BlockBreakEvent();
|
||||
ret.y = obj.getInt("y");
|
||||
ret.player = obj.getString("player");
|
||||
ret.material = obj.getInt("material");
|
||||
ret.z = obj.getInt("z");
|
||||
ret.x = obj.getInt("x");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("y").value(this.y);
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("material").value(this.material);
|
||||
writer.key("z").value(this.z);
|
||||
writer.key("x").value(this.x);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "block-break"; }
|
||||
static { Event.registerHandler("block-break", BlockBreakEvent.class); }
|
||||
}
|
47
src/main/java/us/camin/api/events/BlockPlaceEvent.java
Normal file
47
src/main/java/us/camin/api/events/BlockPlaceEvent.java
Normal file
@ -0,0 +1,47 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class BlockPlaceEvent extends Event {
|
||||
public int y;
|
||||
public String player;
|
||||
public int material;
|
||||
public int z;
|
||||
public int x;
|
||||
public static BlockPlaceEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
BlockPlaceEvent ret = new BlockPlaceEvent();
|
||||
ret.y = obj.getInt("y");
|
||||
ret.player = obj.getString("player");
|
||||
ret.material = obj.getInt("material");
|
||||
ret.z = obj.getInt("z");
|
||||
ret.x = obj.getInt("x");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("y").value(this.y);
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("material").value(this.material);
|
||||
writer.key("z").value(this.z);
|
||||
writer.key("x").value(this.x);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "block-place"; }
|
||||
static { Event.registerHandler("block-place", BlockPlaceEvent.class); }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,26 +17,19 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class DeathEvent extends ClientEvent {
|
||||
public String player;
|
||||
public String message;
|
||||
|
||||
public DeathEvent(String player, String message) {
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(player);
|
||||
writer.key("message").value(message);
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "player-death";
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class BroadcastEvent extends Event {
|
||||
public String message;
|
||||
public static BroadcastEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
BroadcastEvent ret = new BroadcastEvent();
|
||||
ret.message = obj.getString("message");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("message").value(this.message);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "broadcast"; }
|
||||
static { Event.registerHandler("broadcast", BroadcastEvent.class); }
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,20 +17,22 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class KickEvent extends ServerEvent {
|
||||
public String message;
|
||||
public String player;
|
||||
|
||||
public static KickEvent fromJSON(JSONObject obj, int id) {
|
||||
KickEvent ret = new KickEvent ();
|
||||
ret.player = obj.optString("player");
|
||||
ret.message = obj.optString("message");
|
||||
ret.id = id;
|
||||
return ret;
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class ChatEvent extends Event {
|
||||
public String message;
|
||||
public String sender;
|
||||
public static ChatEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
ChatEvent ret = new ChatEvent();
|
||||
ret.message = obj.getString("message");
|
||||
ret.sender = obj.getString("sender");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("message").value(this.message);
|
||||
writer.key("sender").value(this.sender);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "chat"; }
|
||||
static { Event.registerHandler("chat", ChatEvent.class); }
|
||||
}
|
||||
|
55
src/main/java/us/camin/api/events/Event.java
Normal file
55
src/main/java/us/camin/api/events/Event.java
Normal file
@ -0,0 +1,55 @@
|
||||
package us.camin.api.events;
|
||||
import java.util.*;
|
||||
import org.json.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class Event {
|
||||
public int _id;
|
||||
public static Logger log;
|
||||
public static Map<String, Class> s_types;
|
||||
|
||||
static {
|
||||
s_types = new HashMap<String, Class>();
|
||||
log = Logger.getLogger("CaminusEvents");
|
||||
}
|
||||
|
||||
public static void registerHandler(String name, Class cls) {
|
||||
log.info("Registering event type "+name);
|
||||
s_types.put(name, cls);
|
||||
}
|
||||
|
||||
public static Event fromJSON(JSONObject obj) throws JSONException {
|
||||
if (!s_types.containsKey(obj.getString("type"))) {
|
||||
log.log(Level.SEVERE, "Ignoring unknown event type "+obj.getString("type"));
|
||||
return null;
|
||||
}
|
||||
Class prototype = s_types.get(obj.getString("type"));
|
||||
Event ret = null;
|
||||
try {
|
||||
ret = (Event)prototype.getMethod("fromJSON").invoke(null, obj.getJSONObject("properties"));
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Could not instantiate event", e);
|
||||
return null;
|
||||
}
|
||||
ret._id = obj.getInt("id");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
JSONWriter s = new JSONStringer();
|
||||
s.object();
|
||||
s.key("type");
|
||||
s.value(jsonName());
|
||||
s.key("payload");
|
||||
s.object();
|
||||
s = toJSON(s);
|
||||
s.endObject();
|
||||
s.endObject();
|
||||
return new JSONObject(((JSONStringer)s).toString());
|
||||
}
|
||||
|
||||
public abstract JSONWriter toJSON(JSONWriter writer) throws JSONException;
|
||||
|
||||
public abstract String jsonName();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,19 +17,19 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class PlayerMessageEvent extends ServerEvent {
|
||||
public String message;
|
||||
public String player;
|
||||
public static PlayerMessageEvent fromJSON(JSONObject obj, int id) {
|
||||
PlayerMessageEvent ret = new PlayerMessageEvent();
|
||||
ret.message = obj.optString("message");
|
||||
ret.player = obj.optString("player");
|
||||
ret.id = id;
|
||||
return ret;
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class JoinEvent extends Event {
|
||||
public String player;
|
||||
public static JoinEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
JoinEvent ret = new JoinEvent();
|
||||
ret.player = obj.getString("player");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "join"; }
|
||||
static { Event.registerHandler("join", JoinEvent.class); }
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,25 +17,19 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class ChatEvent extends ClientEvent {
|
||||
public String sender;
|
||||
public String message;
|
||||
|
||||
public ChatEvent(String sender, String message) {
|
||||
this.sender = sender;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("sender").value(sender);
|
||||
writer.key("message").value(message);
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "chat";
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class MarketOrderEvent extends Event {
|
||||
public int orderID;
|
||||
public static MarketOrderEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
MarketOrderEvent ret = new MarketOrderEvent();
|
||||
ret.orderID = obj.getInt("orderID");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("orderID").value(this.orderID);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "market-order"; }
|
||||
static { Event.registerHandler("market-order", MarketOrderEvent.class); }
|
||||
}
|
38
src/main/java/us/camin/api/events/PlayerDeathEvent.java
Normal file
38
src/main/java/us/camin/api/events/PlayerDeathEvent.java
Normal file
@ -0,0 +1,38 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class PlayerDeathEvent extends Event {
|
||||
public String player;
|
||||
public String message;
|
||||
public static PlayerDeathEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
PlayerDeathEvent ret = new PlayerDeathEvent();
|
||||
ret.player = obj.getString("player");
|
||||
ret.message = obj.getString("message");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("message").value(this.message);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "player-death"; }
|
||||
static { Event.registerHandler("player-death", PlayerDeathEvent.class); }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,26 +17,22 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONStringer;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class ClientEvent {
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
JSONWriter s = new JSONStringer();
|
||||
s.object();
|
||||
s.key("type");
|
||||
s.value(jsonName());
|
||||
s.key("payload");
|
||||
s.object();
|
||||
s = toJSON(s);
|
||||
s.endObject();
|
||||
s.endObject();
|
||||
return new JSONObject(((JSONStringer)s).toString());
|
||||
}
|
||||
|
||||
public abstract String jsonName();
|
||||
|
||||
public abstract JSONWriter toJSON(JSONWriter writer) throws JSONException;
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class PlayerKickEvent extends Event {
|
||||
public String player;
|
||||
public String message;
|
||||
public static PlayerKickEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
PlayerKickEvent ret = new PlayerKickEvent();
|
||||
ret.player = obj.getString("player");
|
||||
ret.message = obj.getString("message");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("message").value(this.message);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "player-kick"; }
|
||||
static { Event.registerHandler("player-kick", PlayerKickEvent.class); }
|
||||
}
|
38
src/main/java/us/camin/api/events/PlayerMessageEvent.java
Normal file
38
src/main/java/us/camin/api/events/PlayerMessageEvent.java
Normal file
@ -0,0 +1,38 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class PlayerMessageEvent extends Event {
|
||||
public String player;
|
||||
public String message;
|
||||
public static PlayerMessageEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
PlayerMessageEvent ret = new PlayerMessageEvent();
|
||||
ret.player = obj.getString("player");
|
||||
ret.message = obj.getString("message");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("message").value(this.message);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "player-message"; }
|
||||
static { Event.registerHandler("player-message", PlayerMessageEvent.class); }
|
||||
}
|
41
src/main/java/us/camin/api/events/PlayerMurderEvent.java
Normal file
41
src/main/java/us/camin/api/events/PlayerMurderEvent.java
Normal file
@ -0,0 +1,41 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class PlayerMurderEvent extends Event {
|
||||
public String player;
|
||||
public String message;
|
||||
public String killer;
|
||||
public static PlayerMurderEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
PlayerMurderEvent ret = new PlayerMurderEvent();
|
||||
ret.player = obj.getString("player");
|
||||
ret.message = obj.getString("message");
|
||||
ret.killer = obj.getString("killer");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("message").value(this.message);
|
||||
writer.key("killer").value(this.killer);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "player-murder"; }
|
||||
static { Event.registerHandler("player-murder", PlayerMurderEvent.class); }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,16 +17,19 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class BroadcastEvent extends ServerEvent {
|
||||
public String message;
|
||||
public static BroadcastEvent fromJSON(JSONObject obj, int id) {
|
||||
BroadcastEvent ret = new BroadcastEvent();
|
||||
ret.message = obj.optString("message");
|
||||
ret.id = id;
|
||||
return ret;
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class QuitEvent extends Event {
|
||||
public String player;
|
||||
public static QuitEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
QuitEvent ret = new QuitEvent();
|
||||
ret.player = obj.getString("player");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "quit"; }
|
||||
static { Event.registerHandler("quit", QuitEvent.class); }
|
||||
}
|
46
src/main/java/us/camin/api/events/ServerHeartbeatEvent.java
Normal file
46
src/main/java/us/camin/api/events/ServerHeartbeatEvent.java
Normal file
@ -0,0 +1,46 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class ServerHeartbeatEvent extends Event {
|
||||
public Map<String, Object> worldTimes;
|
||||
public int port;
|
||||
public String name;
|
||||
public static ServerHeartbeatEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
ServerHeartbeatEvent ret = new ServerHeartbeatEvent();
|
||||
|
||||
JSONObject worldTimes_obj = obj.getJSONObject("worldTimes");
|
||||
for(String name : JSONObject.getNames(worldTimes_obj)) {
|
||||
ret.worldTimes.put(name, worldTimes_obj.get(name));
|
||||
}
|
||||
|
||||
ret.port = obj.getInt("port");
|
||||
ret.name = obj.getString("name");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("worldTimes").value(this.worldTimes);
|
||||
writer.key("port").value(this.port);
|
||||
writer.key("name").value(this.name);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "server-heartbeat"; }
|
||||
static { Event.registerHandler("server-heartbeat", ServerHeartbeatEvent.class); }
|
||||
}
|
43
src/main/java/us/camin/api/events/VaultContentsEvent.java
Normal file
43
src/main/java/us/camin/api/events/VaultContentsEvent.java
Normal file
@ -0,0 +1,43 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class VaultContentsEvent extends Event {
|
||||
public String player;
|
||||
public List<VaultSlot> items;
|
||||
public static VaultContentsEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
VaultContentsEvent ret = new VaultContentsEvent();
|
||||
ret.player = obj.getString("player");
|
||||
|
||||
JSONArray items_list = obj.getJSONArray("items");
|
||||
ret.items = new ArrayList<VaultSlot>();
|
||||
for(int i = 0;i<items_list.length();i++) {
|
||||
ret.items.add(VaultSlot.fromJSON(items_list.getJSONObject(i)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("player").value(this.player);
|
||||
writer.key("items").value(this.items);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "vault-contents"; }
|
||||
static { Event.registerHandler("vault-contents", VaultContentsEvent.class); }
|
||||
}
|
45
src/main/java/us/camin/api/events/VaultSlot.java
Normal file
45
src/main/java/us/camin/api/events/VaultSlot.java
Normal file
@ -0,0 +1,45 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class VaultSlot {
|
||||
public String name;
|
||||
public int durability;
|
||||
public int position;
|
||||
public int material;
|
||||
public int data;
|
||||
public int damage;
|
||||
public int quantity;
|
||||
public static VaultSlot fromJSON(JSONObject obj) throws JSONException {
|
||||
VaultSlot ret = new VaultSlot();
|
||||
try {
|
||||
ret.name = obj.getString("name");
|
||||
} catch (JSONException e) {}
|
||||
try {
|
||||
ret.durability = obj.getInt("durability");
|
||||
} catch (JSONException e) {}
|
||||
ret.position = obj.getInt("position");
|
||||
ret.material = obj.getInt("material");
|
||||
ret.data = obj.getInt("data");
|
||||
ret.damage = obj.getInt("damage");
|
||||
ret.quantity = obj.getInt("quantity");
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.api;
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
@ -17,27 +17,22 @@ package us.camin.api;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class WeatherEvent extends ClientEvent {
|
||||
public String world;
|
||||
public boolean isRaining;
|
||||
|
||||
public WeatherEvent(String world, boolean rain) {
|
||||
this.world = world;
|
||||
this.isRaining = rain;
|
||||
}
|
||||
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("world").value(world);
|
||||
writer.key("isRaining").value(isRaining);
|
||||
return writer;
|
||||
}
|
||||
|
||||
public String jsonName() {
|
||||
return "weather";
|
||||
}
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class WeatherEvent extends Event {
|
||||
public String world;
|
||||
public boolean isRaining;
|
||||
public static WeatherEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
WeatherEvent ret = new WeatherEvent();
|
||||
ret.world = obj.getString("world");
|
||||
ret.isRaining = obj.getBoolean("isRaining");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("world").value(this.world);
|
||||
writer.key("isRaining").value(this.isRaining);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "weather"; }
|
||||
static { Event.registerHandler("weather", WeatherEvent.class); }
|
||||
}
|
||||
|
||||
|
49
src/main/java/us/camin/api/events/WebHeartbeatEvent.java
Normal file
49
src/main/java/us/camin/api/events/WebHeartbeatEvent.java
Normal file
@ -0,0 +1,49 @@
|
||||
package us.camin.api.events;
|
||||
|
||||
/*
|
||||
This file is part of Caminus
|
||||
|
||||
Caminus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Caminus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
public class WebHeartbeatEvent extends Event {
|
||||
public Map<String, Object> heartbeat;
|
||||
public int server;
|
||||
public String dayPeriod;
|
||||
public int time;
|
||||
public static WebHeartbeatEvent fromJSON(JSONObject obj) throws JSONException {
|
||||
WebHeartbeatEvent ret = new WebHeartbeatEvent();
|
||||
|
||||
JSONObject heartbeat_obj = obj.getJSONObject("heartbeat");
|
||||
for(String name : JSONObject.getNames(heartbeat_obj)) {
|
||||
ret.heartbeat.put(name, heartbeat_obj.get(name));
|
||||
}
|
||||
|
||||
ret.server = obj.getInt("server");
|
||||
ret.dayPeriod = obj.getString("dayPeriod");
|
||||
ret.time = obj.getInt("time");
|
||||
return ret;
|
||||
}
|
||||
public JSONWriter toJSON(JSONWriter writer) throws JSONException {
|
||||
writer.key("heartbeat").value(this.heartbeat);
|
||||
writer.key("server").value(this.server);
|
||||
writer.key("day-period").value(this.dayPeriod);
|
||||
writer.key("time").value(this.time);
|
||||
return writer;
|
||||
}
|
||||
public String jsonName() { return "web-heartbeat"; }
|
||||
static { Event.registerHandler("web-heartbeat", WebHeartbeatEvent.class); }
|
||||
}
|
Loading…
Reference in New Issue
Block a user