diff --git a/src/main/java/de/craftinc/replicator/BlockPlaceListener.java b/src/main/java/de/craftinc/replicator/BlockPlaceListener.java
new file mode 100644
index 0000000..ad99301
--- /dev/null
+++ b/src/main/java/de/craftinc/replicator/BlockPlaceListener.java
@@ -0,0 +1,39 @@
+/* Craft Inc. Replicator
+ Copyright (C) 2013 Paul Schulze, Maximilian Häckel, Moritz Kaltofen
+
+ This program 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.
+
+ This program 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 this program. If not, see .
+*/
+
+package de.craftinc.replicator;
+
+import org.bukkit.Location;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockPlaceEvent;
+
+import java.util.ArrayList;
+
+public class BlockPlaceListener implements Listener {
+
+ public void onBlockPlaced(BlockPlaceEvent event){
+ ArrayList replicators = Replicator.getReplicators(event.getBlockPlaced().getLocation());
+ if(!replicators.isEmpty()){
+ for(Location loc:replicators){
+ Replicator rep = Replicator.getOrCreate(loc,event.getPlayer().getName());
+ if(rep!=null){
+ event.getPlayer().sendMessage(Messages.newReplicator(rep));
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/de/craftinc/replicator/Messages.java b/src/main/java/de/craftinc/replicator/Messages.java
index 1b84488..c7cf7f5 100644
--- a/src/main/java/de/craftinc/replicator/Messages.java
+++ b/src/main/java/de/craftinc/replicator/Messages.java
@@ -124,4 +124,6 @@ public class Messages
}
return sb.toString();
}
+
+
}
diff --git a/src/main/java/de/craftinc/replicator/Plugin.java b/src/main/java/de/craftinc/replicator/Plugin.java
index bab8642..a0fe719 100644
--- a/src/main/java/de/craftinc/replicator/Plugin.java
+++ b/src/main/java/de/craftinc/replicator/Plugin.java
@@ -27,7 +27,7 @@ public class Plugin extends JavaPlugin
@Override
public void onLoad()
{
- ConfigurationSerialization.registerClass(Replicator.class);
+ //ConfigurationSerialization.registerClass(Replicator.class);
}
@Override
diff --git a/src/main/java/de/craftinc/replicator/Replicator.java b/src/main/java/de/craftinc/replicator/Replicator.java
index e35142d..8a175ae 100644
--- a/src/main/java/de/craftinc/replicator/Replicator.java
+++ b/src/main/java/de/craftinc/replicator/Replicator.java
@@ -22,19 +22,23 @@ import org.bukkit.block.BlockFace;
import org.bukkit.Material;
import java.util.ArrayList;
+import java.util.HashMap;
public class Replicator {
private ArrayList owners;
private ArrayList users;
+ private String name;
+ private static HashMap allReplicators;
private Location center;
- public Replicator(String firstOwner, Location spawn, Location center) {
+ public Replicator(String firstOwner, Location center) {
this.owners = new ArrayList();
this.users = new ArrayList();
this.owners.add(firstOwner);
this.center = center;
+ name = center.getWorld()+","+center.getBlockX()+","+center.getBlockY()+","+center.getBlockZ();
}
public void addUser(String user) {
@@ -55,6 +59,33 @@ public class Replicator {
else return false;
}
+ public boolean isOwner(String player){
+ for(String owner:owners){
+ if(owner.equals(player)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isUser(String player){
+ for(String user:users){
+ if(user.equals(player)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void setName(String newName){
+ this.name=newName;
+ //TODO: Save List
+ }
+
+ public String getName(){
+ return name;
+ }
+
public static ArrayList getReplicators(Location currentBlock){
ArrayList replicators = new ArrayList();
ArrayList centers = getCenters(currentBlock);
@@ -76,6 +107,9 @@ public class Replicator {
private static boolean isValid(Location center){
Material[][][] pattern = getPattern(center);
+ if(pattern==null){
+ return false;
+ }
for(int x=0;x<=2;x++){
for(int y=0;y<=2;y++){
for(int z=0;z<=2;z++){
@@ -102,4 +136,49 @@ public class Replicator {
return centers;
}
+ public static Replicator getOrCreate(Location loc, String playerName) { //Returns null, if player is not owner or user of the replicator
+ Replicator rep = allReplicators.get(loc);
+ if(rep!=null){
+ if(rep.isOwner(playerName)||rep.isUser(playerName)){
+ return allReplicators.get(loc);
+ }
+ else return null;
+ }
+ else {
+ rep = new Replicator(playerName,loc);
+ allReplicators.put(loc, rep);
+ return rep;
+ }
+ }
+
+ public static Replicator getByName(String repName, String playerName){ //Returns null, if player is not owner or user or if replicator does not exist
+ for(Replicator rep: allReplicators.values()){
+ if(rep.getName().equals(repName)){
+ if(rep.isOwner(playerName)||rep.isUser(playerName)){
+ return rep;
+ }
+ }
+ }
+ return null;
+ }
+
+ public ArrayList getReplicatorsByOwner(String playerName){
+ ArrayList reps = new ArrayList();
+ for(Replicator rep: allReplicators.values()){
+ if(rep.isOwner(playerName)){
+ reps.add(rep);
+ }
+ }
+ return reps;
+ }
+
+ public ArrayList getReplicatorsByUser(String playerName){
+ ArrayList reps = new ArrayList();
+ for(Replicator rep: allReplicators.values()){
+ if(rep.isUser(playerName)){
+ reps.add(rep);
+ }
+ }
+ return reps;
+ }
}