Added new sign structure

Signed-off-by: Grafe <flingelfrank@hotmail.com>
This commit is contained in:
Grafe 2013-03-19 19:07:41 +01:00
parent c96225bf57
commit e9bad81bb5
20 changed files with 537 additions and 185 deletions

View File

@ -39,6 +39,7 @@ import com.dre.dungeonsxl.listener.EntityListener;
import com.dre.dungeonsxl.listener.HangingListener;
import com.dre.dungeonsxl.listener.PlayerListener;
import com.dre.dungeonsxl.listener.WorldListener;
import com.dre.dungeonsxl.signs.DSignTypeRoot;
public class P extends JavaPlugin{
public static P p;
@ -80,6 +81,9 @@ public class P extends JavaPlugin{
//Init Commands
new DCommandRoot();
//Init Signtypes
DSignTypeRoot.init();;
//InitFolders
this.initFolders();

View File

@ -46,6 +46,4 @@ public class DCommandRoot {
this.commands.add(cmdHelp);
this.commands.add(cmdReload);
}
}

View File

@ -1,13 +0,0 @@
package com.dre.dungeonsxl.game;
public class DSign {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -1,13 +0,0 @@
package com.dre.dungeonsxl.game;
public class DSignType {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -7,7 +7,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
@ -23,11 +22,11 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
import com.dre.dungeonsxl.DClass;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.DGSign;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.signs.DSignType;
import com.dre.dungeonsxl.signs.DSignTypeRoot;
public class GameWorld {
private static P p=P.p;
@ -79,160 +78,9 @@ public class GameWorld {
Sign sign = (Sign) block.getState();
String[] lines=sign.getLines();
if(!isPlaying){
if (lines[1].equalsIgnoreCase("lobby")) {
this.locLobby=block.getLocation();
block.setTypeId(0);
} else if (lines[1].equalsIgnoreCase("ready")) {
this.blocksReady.add(block);
sign.setLine(0, ChatColor.BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"Ready");
sign.setLine(2, "");
sign.setLine(3, ChatColor.BLUE+"############");
sign.update();
} else if (lines[1].equalsIgnoreCase("leave")){
this.blocksLeave.add(block);
sign.setLine(0, ChatColor.BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"Leave");
sign.setLine(2, "");
sign.setLine(3, ChatColor.BLUE+"############");
sign.update();
} else if (lines[1].equalsIgnoreCase("start")){
this.locStart=block.getLocation();
block.setTypeId(0);
} else if (lines[1].equalsIgnoreCase("end")){
this.blocksEnd.add(block);
sign.setLine(0, ChatColor.DARK_BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"End");
sign.setLine(2, "");
sign.setLine(3, ChatColor.DARK_BLUE+"############");
sign.update();
} else if (lines[1].equalsIgnoreCase("classes")){
if(!config.isLobbyDisabled()){
int[] direction=DGSign.getDirection(block.getData());
int directionX=direction[0];
int directionZ=direction[1];
int xx=0,zz=0;
for(DClass dclass:this.config.getClasses()){
//Check existing signs
boolean isContinued=true;
for(Sign isusedsign:this.signClass){
if(dclass.name.equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))){
isContinued=false;
}
}
if(isContinued){
Block classBlock=block.getRelative(xx,0,zz);
if(classBlock.getData()==sign.getData().getData()&&classBlock.getTypeId()==68&&(classBlock.getState() instanceof Sign)){
Sign classSign = (Sign) classBlock.getState();
classSign.setLine(0, ChatColor.DARK_BLUE+"############");
classSign.setLine(1, ChatColor.DARK_GREEN+dclass.name);
classSign.setLine(2, "");
classSign.setLine(3, ChatColor.DARK_BLUE+"############");
classSign.update();
this.signClass.add(classSign);
}else{
break;
}
xx=xx+directionX;
zz=zz+directionZ;
}
}
}
else{
block.setTypeId(0);
}
} else if (lines[1].equalsIgnoreCase("chunkupdater")){
Chunk chunk = this.world.getChunkAt(block);
if(!lines[2].equals("")){
Integer radius = p.parseInt(lines[2]);
for(int x = -radius; x<radius; x++){
for(int z = -radius; z<radius; z++){
Chunk chunk1 = this.world.getChunkAt(chunk.getX()-x,chunk.getZ()-z);
chunk1.load();
this.loadedChunks.add(chunk1);
}
}
} else {
chunk.load();
this.loadedChunks.add(chunk);
}
block.setTypeId(0);
}
}else{
if(lines[1].equalsIgnoreCase("mob")){
if(lines[2]!=""&&lines[3]!=""){
String mob=lines[2];
if(mob!=null){
String[] atributes=lines[3].split(",");
if(atributes.length==3){
new MobSpawner(block, mob, p.parseInt(atributes[0]), p.parseInt(atributes[1]), p.parseInt(atributes[2]),0);
}
if(atributes.length==4){
new MobSpawner(block, mob, p.parseInt(atributes[0]), p.parseInt(atributes[1]), p.parseInt(atributes[2]),p.parseInt(atributes[3]));
}
}
}
block.setTypeId(0);
}
if(lines[1].equalsIgnoreCase("place")){
placeableBlocks.add(new GamePlaceableBlock(block, lines[2], lines[3]) );
block.setTypeId(0);
}
if(lines[1].equalsIgnoreCase("msg")){
if(lines[2]!=""&&lines[3]!=""){
String msg = config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),false));
block.setTypeId(0);
}
}
}
if(lines[1].equalsIgnoreCase("soundmsg")){
if(lines[2]!=""&&lines[3]!=""){
String msg = config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),true));
block.setTypeId(0);
}
}
}
if(lines[1].equalsIgnoreCase("checkpoint")){
int radius=0;
if(lines[2]!=null ){
if(lines[2].length()>0){
radius=p.parseInt(lines[2]);
}
}
new GameCheckpoint(this,block.getLocation(),radius);
block.setTypeId(0);
}
if(lines[1].equalsIgnoreCase("chest")){
if(sign.getTypeId()==63){
for(int x=-1;x<=1;x++){
if(sign.getBlock().getRelative(x, 0, 0).getTypeId()==54){
new GameChest(sign.getBlock().getRelative(x, 0, 0),this);
}
}
for(int z=-1;z<=1;z++){
if(sign.getBlock().getRelative(0, 0, z).getTypeId()==54){
if(sign.getBlock().getRelative(0, 0, z)!=null){
new GameChest(sign.getBlock().getRelative(0, 0, z),this);
}
}
}
}
block.setTypeId(0);
for(DSignType signType : DSignTypeRoot.get()){
if(lines[0].equalsIgnoreCase("["+signType.name+"]")){
signType.onDungeonInit(sign, this);
}
}
}

View File

@ -0,0 +1,18 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public abstract class DSignType {
public static P p = P.p;
public String name;
public String permissions;
public boolean onInit;
public abstract boolean check(Sign sign);
public abstract void onDungeonInit(Sign sign, GameWorld gworld);
public abstract void onTrigger(Sign sign, GameWorld gworld);
}

View File

@ -0,0 +1,43 @@
package com.dre.dungeonsxl.signs;
import java.util.concurrent.CopyOnWriteArrayList;
public class DSignTypeRoot {
private static CopyOnWriteArrayList<DSignType> signTypes = new CopyOnWriteArrayList<DSignType>();
//SignTypes
private static SIGNCheckpoint signCheckpoint = new SIGNCheckpoint();
private static SIGNChest signChest = new SIGNChest();
private static SIGNChunkUpdater signChunkUpdater = new SIGNChunkUpdater();
private static SIGNClasses signClasses = new SIGNClasses();
private static SIGNEnd signEnd = new SIGNEnd();
private static SIGNLeave signLeave = new SIGNLeave();
private static SIGNLobby signLobby = new SIGNLobby();
private static SIGNMob signMob = new SIGNMob();
private static SIGNMsg signMsg = new SIGNMsg();
private static SIGNPlace signPlace = new SIGNPlace();
private static SIGNReady signReady = new SIGNReady();
private static SIGNSoundMsg signSoundMsg = new SIGNSoundMsg();
private static SIGNStart signStart = new SIGNStart();
//Methods
public static void init(){
signTypes.add(signCheckpoint);
signTypes.add(signChest);
signTypes.add(signChunkUpdater);
signTypes.add(signClasses);
signTypes.add(signEnd);
signTypes.add(signLeave);
signTypes.add(signLobby);
signTypes.add(signMob);
signTypes.add(signMsg);
signTypes.add(signPlace);
signTypes.add(signReady);
signTypes.add(signSoundMsg);
signTypes.add(signStart);
}
public static CopyOnWriteArrayList<DSignType> get(){
return signTypes;
}
}

View File

@ -0,0 +1,37 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameCheckpoint;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNCheckpoint extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
int radius = 0;
if(lines[2] != null ){
if(lines[2].length() > 0){
radius = p.parseInt(lines[2]);
}
}
new GameCheckpoint(gworld, sign.getLocation(), radius);
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,43 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameChest;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNChest extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
if(sign.getTypeId()==63){
for(int x=-1;x<=1;x++){
if(sign.getBlock().getRelative(x, 0, 0).getTypeId()==54){
new GameChest(sign.getBlock().getRelative(x, 0, 0), gworld);
}
}
for(int z=-1;z<=1;z++){
if(sign.getBlock().getRelative(0, 0, z).getTypeId()==54){
if(sign.getBlock().getRelative(0, 0, z)!=null){
new GameChest(sign.getBlock().getRelative(0, 0, z), gworld);
}
}
}
}
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,41 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Chunk;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNChunkUpdater extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
Chunk chunk = gworld.world.getChunkAt(sign.getBlock());
if(!lines[2].equals("")){
Integer radius = p.parseInt(lines[2]);
for(int x = -radius; x<radius; x++){
for(int z = -radius; z<radius; z++){
Chunk chunk1 = gworld.world.getChunkAt(chunk.getX()-x,chunk.getZ()-z);
chunk1.load();
gworld.loadedChunks.add(chunk1);
}
}
} else {
chunk.load();
gworld.loadedChunks.add(chunk);
}
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,67 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.DClass;
import com.dre.dungeonsxl.DGSign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNClasses extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
if(!gworld.config.isLobbyDisabled()){
int[] direction=DGSign.getDirection(sign.getBlock().getData());
int directionX=direction[0];
int directionZ=direction[1];
int xx=0,zz=0;
for(DClass dclass:gworld.config.getClasses()){
//Check existing signs
boolean isContinued=true;
for(Sign isusedsign:gworld.signClass){
if(dclass.name.equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))){
isContinued=false;
}
}
if(isContinued){
Block classBlock=sign.getBlock().getRelative(xx,0,zz);
if(classBlock.getData()==sign.getData().getData()&&classBlock.getTypeId()==68&&(classBlock.getState() instanceof Sign)){
Sign classSign = (Sign) classBlock.getState();
classSign.setLine(0, ChatColor.DARK_BLUE+"############");
classSign.setLine(1, ChatColor.DARK_GREEN+dclass.name);
classSign.setLine(2, "");
classSign.setLine(3, ChatColor.DARK_BLUE+"############");
classSign.update();
gworld.signClass.add(classSign);
}else{
break;
}
xx=xx+directionX;
zz=zz+directionZ;
}
}
} else {
sign.setTypeId(0);
}
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,30 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNEnd extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
gworld.blocksEnd.add(sign.getBlock());
sign.setLine(0, ChatColor.DARK_BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"End");
sign.setLine(2, "");
sign.setLine(3, ChatColor.DARK_BLUE+"############");
sign.update();
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
}
}

View File

@ -0,0 +1,30 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNLeave extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
gworld.blocksLeave.add(sign.getBlock());
sign.setLine(0, ChatColor.BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"Leave");
sign.setLine(2, "");
sign.setLine(3, ChatColor.BLUE+"############");
sign.update();
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
}
}

View File

@ -0,0 +1,25 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNLobby extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
gworld.locLobby = sign.getLocation();
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
}
}

View File

@ -0,0 +1,39 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.game.MobSpawner;
public class SIGNMob extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
if(lines[2]!=""&&lines[3]!=""){
String mob=lines[2];
if(mob!=null){
String[] atributes=lines[3].split(",");
if(atributes.length==3){
new MobSpawner(sign.getBlock(), mob, p.parseInt(atributes[0]), p.parseInt(atributes[1]), p.parseInt(atributes[2]),0);
}
if(atributes.length==4){
new MobSpawner(sign.getBlock(), mob, p.parseInt(atributes[0]), p.parseInt(atributes[1]), p.parseInt(atributes[2]),p.parseInt(atributes[3]));
}
}
}
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,35 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameMessage;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNMsg extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
if(lines[2]!=""&&lines[3]!=""){
String msg = gworld.config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){
gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[3]), false));
sign.setTypeId(0);
}
}
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,29 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GamePlaceableBlock;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNPlace extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
gworld.placeableBlocks.add(new GamePlaceableBlock(sign.getBlock(), lines[2], lines[3]) );
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,30 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNReady extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
gworld.blocksReady.add(sign.getBlock());
sign.setLine(0, ChatColor.BLUE+"############");
sign.setLine(1, ChatColor.DARK_GREEN+"Ready");
sign.setLine(2, "");
sign.setLine(3, ChatColor.BLUE+"############");
sign.update();
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
}
}

View File

@ -0,0 +1,35 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameMessage;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNSoundMsg extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
String lines[] = sign.getLines();
if(lines[2]!=""&&lines[3]!=""){
String msg = gworld.config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){
gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[3]), true));
sign.setTypeId(0);
}
}
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,26 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNStart extends DSignType{
@Override
public boolean check(Sign sign) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDungeonInit(Sign sign, GameWorld gworld) {
gworld.locStart = sign.getLocation();
sign.setTypeId(0);
}
@Override
public void onTrigger(Sign sign, GameWorld gworld) {
// TODO Auto-generated method stub
}
}