More basics... Configurations, PlayerSessions, Events etc...

This commit is contained in:
Simon Rigby 2011-02-26 06:26:13 +00:00
parent 3f678fcd36
commit 23c695b3a2
8 changed files with 282 additions and 10 deletions

Binary file not shown.

View File

@ -1,5 +1,33 @@
package com.onarandombox.MultiVerseCore;
public class MVBlockListener {
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRightClickEvent;
public class MVBlockListener implements Listener {
MultiVerseCore plugin;
public MVBlockListener(MultiVerseCore plugin) {
this.plugin = plugin;
}
public void onBlockRightClicked(BlockRightClickEvent event){
}
public void onBlockDamage(BlockDamageEvent event){
}
public void onBlockFlow(BlockFromToEvent event){
}
public void onBlockPlaced(BlockPlaceEvent event){
}
}

View File

@ -1,5 +1,18 @@
package com.onarandombox.MultiVerseCore;
public class MVEntityListener {
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
public class MVEntityListener implements Listener {
MultiVerseCore plugin;
public MVEntityListener(MultiVerseCore plugin) {
this.plugin = plugin;
}
public void onEntityDamaged(EntityDamageEvent event){
}
}

View File

@ -1,5 +1,36 @@
package com.onarandombox.MultiVerseCore;
public class MVPlayerListener {
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
public class MVPlayerListener implements Listener {
MultiVerseCore plugin;
public MVPlayerListener(MultiVerseCore plugin) {
this.plugin = plugin;
}
public void onPlayerMove(PlayerMoveEvent event){
}
public void onPlayerChat(PlayerChatEvent event){
}
public void onPlayerRespawn(PlayerRespawnEvent event){
}
public void onPlayerJoin(PlayerEvent event){
}
public void onPlayerQuit(PlayerEvent event){
}
}

View File

@ -0,0 +1,11 @@
package com.onarandombox.MultiVerseCore;
import org.bukkit.entity.Player;
public class MVPlayerSession {
public MVPlayerSession(Player player, MultiVerseCore multiVerseCore) {
// TODO Auto-generated constructor stub
}
}

View File

@ -1,5 +1,11 @@
package com.onarandombox.MultiVerseCore;
public class MVPluginListener {
import org.bukkit.event.Listener;
public class MVPluginListener implements Listener {
public MVPluginListener(MultiVerseCore multiVerseCore) {
// TODO Auto-generated constructor stub
}
}

View File

@ -11,17 +11,21 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.iConomy.iConomy;
import com.onarandombox.MultiVerseCore.configuration.defaultConfiguration;
@SuppressWarnings("unused")
public class MultiVerseCore extends JavaPlugin {
// Variable to state whether we are displaying Debug Messages or not.
public boolean debug = false;
public boolean debug = true;
// Useless stuff to keep us going.
private final Logger log = Logger.getLogger("Minecraft");
@ -38,13 +42,22 @@ public class MultiVerseCore extends JavaPlugin {
public static Configuration configWorlds;
// Setup the block/player/entity listener.
private MVPlayerListener playerListener;
private MVBlockListener blockListener;
private MVEntityListener entityListener;
private MVPluginListener pluginListener;
private MVPlayerListener playerListener = new MVPlayerListener(this);;
private MVBlockListener blockListener = new MVBlockListener(this);
private MVEntityListener entityListener = new MVEntityListener(this);
private MVPluginListener pluginListener = new MVPluginListener(this);
// HashMap to contain all the Worlds which this Plugin will manage.
public HashMap<String,MVWorld> mvWorlds = new HashMap<String,MVWorld>();
// HashMap to contain information relating to the Players.
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
/**
* Constructor... Perform the Necessary tasks here.
*/
public MultiVerseCore(){
}
/**
* What happens when the plugin gets around to be enabled...
@ -55,19 +68,90 @@ public class MultiVerseCore extends JavaPlugin {
* Output a little snippet to state that the plugin is now enabled.
*/
log.info(logPrefix + "- Version " + this.getDescription().getVersion() + " Enabled");
/**
* Quick check for the Permissions Plugin, if we don't find it here
* we'll have to check Plugin onEnable Events.
*/
if(getServer().getPluginManager().getPlugin("Permissions")==null){
log.info(logPrefix + "Commands have been DISABLED until Permissions has been found.");
} else {
Permissions = com.nijikokun.bukkit.Permissions.Permissions.Security;
}
/**
* If the Configuration Files don't exist then create them.
*/
if(!(new File(this.getDataFolder(), "MultiVerse.yml").exists())){
new defaultConfiguration().setupMultiVerseConfig(new File(this.getDataFolder(), "MultiVerse.yml"));
}
if(!(new File(this.getDataFolder(), "Worlds.yml").exists())){
new defaultConfiguration().setupMultiVerseConfig(new File(this.getDataFolder(), "Worlds.yml"));
}
/**
* Grab the Configuration Files & Load them.
*/
configMV = new Configuration(new File(this.getDataFolder(), "MultiVerse.yml"));
configMV.load();
configWorlds = new Configuration(new File(this.getDataFolder(), "Worlds.yml"));
configWorlds.load();
/**
* Setup all the events which we will be listening.
*/
/*
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Low,this); // Low so it acts above any other.
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener,Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener,Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener,Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener,Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.High,this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.High,this);
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High,this);
*/
/**
* In case of a /reload we need to make sure every player online gets
* setup with a player session.
*/
Player[] p = this.getServer().getOnlinePlayers();
for (int i = 0; i < p.length; i++) {
debugMsg("Player Sessions - Player " + i + " Out of " + p.length + " Name - " + p[i].getName(), null);
this.playerSessions.put(p[i].getName(), new MVPlayerSession(p[i],this));
}
/**
* Load up the Worlds & their Settings.
*/
loadWorlds();
}
/**
/**
* Load the Worlds & Settings from the configuration file.
*/
private void loadWorlds() {
// TODO Auto-generated method stub
}
/**
* What happens when the plugin gets disabled...
*/
public void onDisable() {
log.info(logPrefix + "- Disabled");
}
/**
* onCommand
*/
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if(Permissions==null || this.isEnabled()==false){
return false;
}
return false;
}
/**
* Basic Debug Output function, if we've enabled debugging we'll output more information.
*/

View File

@ -0,0 +1,99 @@
package com.onarandombox.MultiVerseCore.configuration;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class defaultConfiguration {
public void setupMultiVerseConfig(File config) {
try {
config.createNewFile();
FileWriter fstream = new FileWriter(config);
BufferedWriter out = new BufferedWriter(fstream);
// TODO: Format Layout, remove unnecessary crap etc...
out.write("#Prefix Chat with World Name.\n");
out.write("prefix: true\n");
out.write("\n");
out.write("#Choose whether or not Players have to pay to use the portals.\n");
out.write("iconomy: false\n");
out.write("\n");
out.write("#True/False - Whether MultiVerse should handle all respawns on every World including the Default.\n");
out.write("#Disable this if you have a form of Respawn Teleportation plugin.\n");
out.write("globalrespawn: false\n");
out.write("#True/False - Whether MultiVerse should handle all respawns on the MultiVerse Worlds.\n");
out.write("#If 'globalrespawn:true' then this will have no effect.\n");
out.write("alternaterespawn: true\n");
out.write("\n");
out.write("#How long a player has to wait before using another portal.\n");
out.write("#In Milliseconds - Default is '5000' which is 5 Seconds.\n");
out.write("tpcooldown: 5000\n");
out.write("#How long to leave in between sending an alert to the player.\n");
out.write("#In Milliseconds - Default is '5000' which is 5 Seconds.\n");
out.write("alertcooldown: 5000\n");
out.write("#How long the player has to wait before they can get more information from a portal.\n");
out.write("#In Milliseconds - Default is '5000' which is 5 Seconds.\n");
out.write("infocooldown: 5000\n");
out.write("\n");
out.write("#The Item a player has to use to get information from a portal.\n");
out.write("#Default is 49 - Obsidian\n");
out.write("infowand: 49\n");
out.write("\n");
out.write("#The Item a player has to use to set the coordinates to create a portal\n");
out.write("#Default is 270 - Wood Pickaxe\n");
out.write("setwand: 270\n");
out.write("\n");
out.write("#SinglePlayer Styled Nether - You still have to \"/mvimport\" the World for Nether.\n");
out.write("#The settings below only affect the SPLike portals.\n");
out.write("#SPLike - True/False - Portals without a Destination or Sign will act like a SinglePlayer portal.\n");
out.write("#AutoBuild - True/False - AutoBuild a destination portal if none are found nearby?\n");
out.write("#Nether - Folder/WorldName of the Nether world.\n");
out.write("#Default - Folder/WorldName of the default world setup in server.properties.\n");
out.write("#RespawnToDefault - True/False - When a player dies do we respawn them back to the default world.\n");
out.write("splike: false\n");
out.write("autobuild: false\n");
out.write("nether: nether\n");
out.write("default: world\n");
out.write("respawntodefault: false\n");
out.close();
fstream.close();
} catch (IOException ex) {
System.out.print("Error creating MultiVerse.yml");
}
}
public void setupWorldConfig(File config){
if (!config.exists()) {
try {
config.createNewFile();
FileWriter fstream = new FileWriter(config);
BufferedWriter out = new BufferedWriter(fstream);
// TODO: Implement an Example.
// out.write("\n");
// out.write("###############################\n");
// out.write("########### Example ###########\n");
// out.write("###############################\n");
// out.write("# worlds:\n");
// out.write("# hellworld:\n");
// out.write("# environment: NETHER\n");
// out.write("# creative:\n");
// out.write("# environment: NORMAL\n");
// out.write("###############################\n");
// out.write("\n");
out.write("worlds:\n");
out.close();
fstream.close();
} catch (IOException ex) {
System.out.print("Error creating Worlds.yml");
}
}
}
}