Refactor, begin Spout implementation

Signed-off-by: aPunch <theapunch@yahoo.com>
This commit is contained in:
aPunch 2012-05-31 15:49:57 -05:00
parent 3d8e797251
commit 577814d57b
22 changed files with 341 additions and 62 deletions

97
pom.xml
View File

@ -1,51 +1,17 @@
<!-- Citizens build file -->
<!-- Citizens2 Build File -->
<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>
<!-- Project Properties -->
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens</artifactId>
<version>2.0-SNAPSHOT</version>
<name>Citizens</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>1.2.5-R1.2-SNAPSHOT</craftbukkit.version>
<citizensapi.version>2.0-SNAPSHOT</citizensapi.version>
<build.number>Unknown</build.number>
</properties>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<id>everything</id>
<url>http://repo.citizensnpcs.net</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>${craftbukkit.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>${citizensapi.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<url>http://www.citizensnpcs.net</url>
<!-- Web Information -->
<ciManagement>
<system>jenkins</system>
<url>http://ci.citizensnpcs.net</url>
@ -55,6 +21,61 @@
<developerConnection>scm:git:git:@github.com:CitizensDev/Citizens2.git</developerConnection>
<url>https://github.com/CitizensDev/Citizens2/tree/master/</url>
</scm>
<!-- Global Properties -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Repositories -->
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<id>spout-repo</id>
<url>http://nexus.spout.org/content/groups/public/</url>
</repository>
<repository>
<id>everything</id>
<url>http://repo.citizensnpcs.net</url>
</repository>
</repositories>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.2.5-R1.4-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spout</groupId>
<artifactId>spoutapi</artifactId>
<version>dev-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spout</groupId>
<artifactId>vanilla</artifactId>
<version>1.2.5-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- Build Information -->
<build>
<defaultGoal>clean package install</defaultGoal>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>

View File

@ -1,6 +1,7 @@
package net.citizensnpcs;
import java.io.File;
import java.util.logging.Logger;
import net.citizensnpcs.api.CitizensPlugin;
import net.citizensnpcs.api.abstraction.Server;
@ -10,6 +11,7 @@ import net.citizensnpcs.npc.CitizensAttachmentFactory;
import net.citizensnpcs.npc.NPCSelector;
public class Citizens implements CitizensPlugin {
private static final Logger logger = Logger.getLogger("Minecraft");
private final CitizensAttachmentFactory attachmentFactory = new CitizensAttachmentFactory();
private final File dataFolder;
private final Server server;
@ -50,4 +52,8 @@ public class Citizens implements CitizensPlugin {
public Server getServer() {
return server;
}
public static Logger getLogger() {
return logger;
}
}

View File

@ -1,20 +1,19 @@
package net.citizensnpcs;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.abstraction.bukkit.BukkitConverter;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.Chunk;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.Listener;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.event.CitizensImplementationChangedEvent;
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
import net.citizensnpcs.api.event.NPCDamageEvent;
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.bukkit.BukkitConverter;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.trait.CurrentLocation;
@ -45,12 +44,6 @@ public class EventListen implements Listener {
private final NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
private final ListMultimap<ChunkCoord, Integer> toRespawn = ArrayListMultimap.create();
@EventHandler
public void onImplementationChanged(CitizensImplementationChangedEvent event) {
Messaging.severe("Citizens implementation changed, disabling plugin.");
Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("Citizens"));
}
/*
* Chunk events
*/
@ -223,4 +216,4 @@ public class EventListen implements Listener {
return x == other.x && z == other.z;
}
}
}
}

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.MobType;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import java.util.List;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import javassist.CannotCompileException;
import javassist.ClassPool;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.entity.LivingEntity;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.abstraction.bukkit;
package net.citizensnpcs.bukkit;
import net.citizensnpcs.api.abstraction.Server;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs;
package net.citizensnpcs.bukkit;
import java.io.File;
import java.io.IOException;
@ -7,8 +7,13 @@ import java.util.Iterator;
import javassist.ClassPool;
import javassist.Loader;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.CitizensDisableEvent;
import net.citizensnpcs.EventListen;
import net.citizensnpcs.Metrics;
import net.citizensnpcs.Settings;
import net.citizensnpcs.Metrics.Plotter;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.abstraction.bukkit.BukkitEventConverter;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.entity.Player;

View File

@ -1,9 +1,9 @@
package net.citizensnpcs.command.command;
import net.citizensnpcs.CitizensBukkit;
import net.citizensnpcs.api.abstraction.CommandSender;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.bukkit.CitizensBukkit;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements;

View File

@ -5,9 +5,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.citizensnpcs.CitizensBukkit;
import net.citizensnpcs.api.abstraction.CommandSender;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.bukkit.CitizensBukkit;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements;

View File

@ -4,7 +4,6 @@ import java.security.acl.Owner;
import java.util.ArrayList;
import java.util.List;
import net.citizensnpcs.CitizensBukkit;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.CommandSender;
@ -13,6 +12,7 @@ import net.citizensnpcs.api.abstraction.entity.Ageable;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.bukkit.CitizensBukkit;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements;

View File

@ -2,13 +2,13 @@ package net.citizensnpcs.command.command;
import java.io.File;
import net.citizensnpcs.CitizensBukkit;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.CommandSender;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.scripting.CompileCallback;
import net.citizensnpcs.api.scripting.Script;
import net.citizensnpcs.api.scripting.ScriptFactory;
import net.citizensnpcs.bukkit.CitizensBukkit;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.exception.CommandException;

View File

@ -1,10 +1,10 @@
package net.citizensnpcs.editor;
import net.citizensnpcs.abstraction.bukkit.BukkitPlayer;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.bukkit.BukkitPlayer;
import net.citizensnpcs.util.Messaging;
import org.bukkit.event.Event.Result;

View File

@ -0,0 +1,18 @@
package net.citizensnpcs.spout;
import net.citizensnpcs.util.Messaging;
import org.spout.api.plugin.CommonPlugin;
public class CitizensSpout extends CommonPlugin {
@Override
public void onDisable() {
Messaging.logF("v%s disabled.", getDescription().getVersion());
}
@Override
public void onEnable() {
Messaging.logF("v%s enabled.", getDescription().getVersion());
}
}

View File

@ -0,0 +1,40 @@
package net.citizensnpcs.spout;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity;
public class SpoutConverter {
public static Entity toEntity(org.spout.api.entity.Entity entity) {
// TODO Auto-generated method stub
return null;
}
public static WorldVector toWorldVector(org.spout.api.geo.discrete.Point location) {
// TODO Auto-generated method stub
return null;
}
public static World toWorld(org.spout.api.geo.World world) {
// TODO Auto-generated method stub
return null;
}
public static MobType toMobType(org.spout.vanilla.controller.VanillaControllerType type) {
// TODO Auto-generated method stub
return null;
}
public static org.spout.api.inventory.ItemStack fromItemStack(ItemStack itemStack) {
// TODO Auto-generated method stub
return null;
}
public static ItemStack toItemStack(org.spout.api.inventory.ItemStack itemInHand) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,41 @@
package net.citizensnpcs.spout;
import java.util.List;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity;
public class SpoutEntity implements Entity {
protected final org.spout.api.entity.Entity entity;
public SpoutEntity(org.spout.api.entity.Entity entity) {
this.entity = entity;
}
@Override
public List<Entity> getNearbyEntities(double dX, double dY, double dZ) {
// TODO Auto-generated method stub
return null;
}
@Override
public WorldVector getLocation() {
return SpoutConverter.toWorldVector(entity.getPosition());
}
@Override
public World getWorld() {
return SpoutConverter.toWorld(entity.getWorld());
}
@Override
public void remove() {
entity.kill();
}
@Override
public void setRotation(double yaw, double pitch) {
entity.setRotation(entity.getRotation().rotate((float) pitch, entity.getPosition().getX(), entity.getPosition().getY(), entity.getPosition().getZ()));
}
}

View File

@ -0,0 +1,101 @@
package net.citizensnpcs.spout;
import org.spout.vanilla.controller.VanillaControllerTypes;
import org.spout.vanilla.controller.living.player.VanillaPlayer;
import org.spout.vanilla.controller.source.HealthChangeReason;
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.entity.Player;
public class SpoutPlayer extends SpoutEntity implements Player {
private final VanillaPlayer player;
public SpoutPlayer(VanillaPlayer player) {
super(player.getParent());
this.player = player;
}
@Override
public int getHealth() {
return player.getHealth();
}
@Override
public MobType getType() {
return SpoutConverter.toMobType(VanillaControllerTypes.PLAYER);
}
@Override
public void setHealth(int health) {
player.setHealth(health, HealthChangeReason.UNKNOWN);
}
@Override
public String getName() {
return player.getPlayer().getName();
}
@Override
public boolean hasPermission(String perm) {
return player.getPlayer().hasPermission(perm);
}
@Override
public void sendMessage(String message) {
player.getPlayer().sendMessage(message);
}
@Override
public void useCommand(String cmd) {
// TODO Auto-generated method stub
}
@Override
public ItemStack getEquipment(Equipment slot) {
switch (slot) {
case CARRIED:
return SpoutConverter.toItemStack(player.getInventory().getCurrentItem());
case HELMET:
return SpoutConverter.toItemStack(player.getInventory().getHelmet());
case BOOTS:
return SpoutConverter.toItemStack(player.getInventory().getBoots());
case CHESTPLATE:
return SpoutConverter.toItemStack(player.getInventory().getChestPlate());
case LEGGINGS:
return SpoutConverter.toItemStack(player.getInventory().getLeggings());
default:
return null;
}
}
@Override
public void setEquipment(Equipment slot, ItemStack item) {
switch (slot) {
case CARRIED:
player.getInventory().setCurrentItem(SpoutConverter.fromItemStack(item));
case HELMET:
player.getInventory().setItem(0, SpoutConverter.fromItemStack(item));
case BOOTS:
player.getInventory().setItem(3, SpoutConverter.fromItemStack(item));
case CHESTPLATE:
player.getInventory().setItem(1, SpoutConverter.fromItemStack(item));
case LEGGINGS:
player.getInventory().setItem(2, SpoutConverter.fromItemStack(item));
}
}
@Override
public boolean isOnline() {
return player.getPlayer().isOnline();
}
@Override
public void setArmor(ItemStack[] armor) {
for (int i = 0; i < armor.length; i++) {
player.getInventory().setItem(i, SpoutConverter.fromItemStack(armor[i]));
}
}
}

View File

@ -0,0 +1,51 @@
package net.citizensnpcs.spout;
import org.spout.api.event.Event;
import org.spout.api.event.HandlerList;
import org.spout.api.event.Listener;
import org.spout.api.scheduler.TaskPriority;
import net.citizensnpcs.api.abstraction.Server;
public class SpoutServer implements Server {
private final CitizensSpout plugin;
public SpoutServer(CitizensSpout plugin) {
this.plugin = plugin;
}
@Override
public void callEvent(Object event) {
plugin.getGame().getEventManager().callEvent((Event) event);
}
@Override
public void registerEvents(Object listener) {
plugin.getGame().getEventManager().registerEvents((Listener) listener, plugin);
}
@Override
public void schedule(Runnable task) {
plugin.getGame().getScheduler().scheduleSyncDelayedTask(plugin, task);
}
@Override
public void schedule(Runnable task, long delay) {
plugin.getGame().getScheduler().scheduleSyncDelayedTask(plugin, task, delay, TaskPriority.NORMAL);
}
@Override
public void scheduleRepeating(Runnable task, long delay) {
plugin.getGame().getScheduler().scheduleSyncRepeatingTask(plugin, task, 0, delay, TaskPriority.NORMAL);
}
@Override
public void scheduleRepeating(Runnable task, long initialDelay, long repeatDelay) {
plugin.getGame().getScheduler().scheduleSyncRepeatingTask(plugin, task, initialDelay, repeatDelay, TaskPriority.NORMAL);
}
@Override
public void unregisterAll(Object listener) {
HandlerList.unregisterAll();
}
}

View File

@ -4,6 +4,7 @@ import java.security.acl.Owner;
import java.util.Arrays;
import java.util.logging.Level;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.abstraction.CommandSender;
import net.citizensnpcs.api.abstraction.entity.Player;
@ -20,7 +21,7 @@ public class Messaging {
}
public static void log(Level level, Object... msg) {
Bukkit.getLogger().log(level, "[Citizens] " + SPACE.join(msg));
Citizens.getLogger().log(level, "[Citizens] " + SPACE.join(msg));
}
public static void log(Object... msg) {
@ -79,4 +80,4 @@ public class Messaging {
public static void severeF(Object... messages) {
log(Level.SEVERE, getFormatted(messages));
}
}
}

View File

@ -8,6 +8,8 @@ import java.util.Map;
import javax.xml.stream.Location;
import org.apache.commons.lang.Validate;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.World;