diff --git a/LICENSE.md b/LICENSE.md index de69ce9..7826f4d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,10 +1,19 @@ # GPLv3 * src/main/resources/plugin.yml +* src/main/java/de/craftinc/replicator/BlockPlaceListener.java +* src/main/java/de/craftinc/replicator/BlockUtil.java +* src/main/java/de/craftinc/replicator/Commands.java +* src/main/java/de/craftinc/replicator/Messages.java +* src/main/java/de/craftinc/replicator/Pattern.java +* src/main/java/de/craftinc/replicator/PlayerInteractEntityListener.java +* src/main/java/de/craftinc/replicator/Plugin.java +* src/main/java/de/craftinc/replicator/Replicator.java +* src/main/java/de/craftinc/replicator/UpdateHelper.java full text of GPLv3 can be found in the file "GPLv3" # LGPLv3 -* src/main/java/de/craftinc/borderprotection/LocationSerializer.java +* src/main/java/de/craftinc/replicator/LocationSerializer.java full text of LGPLv3 can be found in the file "LGPLv3" diff --git a/brainstorming b/brainstorming deleted file mode 100644 index bcae066..0000000 --- a/brainstorming +++ /dev/null @@ -1,11 +0,0 @@ -eigenschaften global --list replikatoren - - -eigenschaften replikator: --list owner --list user --location rep --location pumpkin - --method: is_valid() diff --git a/pom.xml b/pom.xml index 1e88b9d..87b0758 100644 --- a/pom.xml +++ b/pom.xml @@ -33,23 +33,23 @@ - - - - - - - - - - - - - - - - - + + exec-maven-plugin + org.codehaus.mojo + 1.2.1 + + + Run Test Bukkit Server + package + + exec + + + ${basedir}/scripts/test-deployment.sh + + + + diff --git a/src/main/java/de/craftinc/replicator/BlockPlaceListener.java b/src/main/java/de/craftinc/replicator/BlockPlaceListener.java index ff11ca9..fe6171c 100644 --- a/src/main/java/de/craftinc/replicator/BlockPlaceListener.java +++ b/src/main/java/de/craftinc/replicator/BlockPlaceListener.java @@ -36,10 +36,6 @@ public class BlockPlaceListener implements Listener for ( Location loc : replicators ) { Replicator rep = Replicator.getOrCreate(loc, event.getPlayer()); - if ( rep != null ) - { - - } } } } diff --git a/src/main/java/de/craftinc/replicator/BlockUtil.java b/src/main/java/de/craftinc/replicator/BlockUtil.java index 3cb4dba..041625b 100644 --- a/src/main/java/de/craftinc/replicator/BlockUtil.java +++ b/src/main/java/de/craftinc/replicator/BlockUtil.java @@ -19,6 +19,7 @@ package de.craftinc.replicator; import java.util.Arrays; import java.util.HashSet; +// FIXME: unused at the moment because the HashSet seems not to be working as it is expected here... public class BlockUtil { /** diff --git a/src/main/java/de/craftinc/replicator/Commands.java b/src/main/java/de/craftinc/replicator/Commands.java index b880796..af14d52 100644 --- a/src/main/java/de/craftinc/replicator/Commands.java +++ b/src/main/java/de/craftinc/replicator/Commands.java @@ -1,5 +1,5 @@ /* Craft Inc. Replicator - Copyright (C) 2013 Paul Schulze, Maximilian Häckel + 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 @@ -16,7 +16,6 @@ */ package de.craftinc.replicator; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -39,7 +38,7 @@ public class Commands implements CommandExecutor } // commands - if ( command.getName().equalsIgnoreCase("replicate") || command.getAliases().get(0).equalsIgnoreCase("repli") ) + if ( command.getName().equalsIgnoreCase("replicator") || command.getAliases().get(0).equalsIgnoreCase("repli") ) { Player player = ( (Player) sender ).getPlayer(); @@ -80,9 +79,10 @@ public class Commands implements CommandExecutor { // get block where the player is looking at Block potentialReplicatorBlock = player.getTargetBlock(null, 100); - Replicator.mochaccino.sendMessage("You are looking at "+potentialReplicatorBlock.getLocation().getBlockX()+","+potentialReplicatorBlock.getLocation().getBlockY()+","+potentialReplicatorBlock.getLocation().getBlockZ()); +// Replicator.mochaccino.sendMessage("You are looking at "+potentialReplicatorBlock.getLocation().getBlockX()+","+potentialReplicatorBlock.getLocation().getBlockY()+","+potentialReplicatorBlock.getLocation().getBlockZ()); // get zero or more valid replicator centers - ArrayList replicators = Replicator.getReplicators(potentialReplicatorBlock.getLocation()); + ArrayList replicators = Replicator + .getReplicators(potentialReplicatorBlock.getLocation()); if ( replicators.size() == 0 ) { @@ -95,7 +95,7 @@ public class Commands implements CommandExecutor // replicator specified as argument else if ( args.length == 2 ) { - Replicator rep = Replicator.getByName(args[1], player.getName()); + Replicator rep = Replicator.getByName(args[1]); if ( rep == null ) { sender.sendMessage(Messages.noReplicatorWithName(args[1])); @@ -128,7 +128,7 @@ public class Commands implements CommandExecutor // get zero or more valid replicator centers ArrayList replicators = Replicator - .getOwnReplicators(potentialReplicatorBlock.getLocation(),player.getName()); + .getOwnReplicators(potentialReplicatorBlock.getLocation(), player.getName()); // no replicator in sight if ( replicators.isEmpty() ) @@ -138,30 +138,14 @@ public class Commands implements CommandExecutor } for ( Replicator replicator : replicators ) { - if ( args[0].equalsIgnoreCase("addowner") ) - { - replicator.addOwner(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("delowner") ) - { - replicator.rmOwner(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("adduser") ) - { - replicator.addUser(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("deluser") ) - { - replicator.rmUser(args[1],player.getName()); - } - sender.sendMessage(Messages.addedOwner(args[1], replicator)); + addOrDelOwnerOrUser(player.getName(), args[1], args[0], replicator); } return true; } // replicator name specified as argument else if ( args.length == 3 ) { - Replicator replicator = Replicator.getByName(args[2], player.getName()); + Replicator replicator = Replicator.getOwnByName(args[2], player.getName()); if ( replicator == null ) { @@ -169,24 +153,7 @@ public class Commands implements CommandExecutor return true; } - if ( args[0].equalsIgnoreCase("addowner") ) - { - replicator.addOwner(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("delowner") ) - { - replicator.rmOwner(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("adduser") ) - { - replicator.addUser(args[1],player.getName()); - } - else if ( args[0].equalsIgnoreCase("deluser") ) - { - replicator.rmUser(args[1],player.getName()); - } - - sender.sendMessage(Messages.addedOwner(player.getName(), replicator)); + addOrDelOwnerOrUser(player.getName(), args[1], args[0], replicator); return true; } } @@ -197,4 +164,57 @@ public class Commands implements CommandExecutor sender.sendMessage(Messages.helpGeneral(( (Player) sender ).getPlayer())); return true; } + + private static void addOrDelOwnerOrUser( String playerName, String changedPlayer, String command, + Replicator replicator ) + { + if ( command.equalsIgnoreCase("addowner") ) + { + if ( replicator.addOwner(changedPlayer, playerName) ) + { + Plugin.instance.getServer().getPlayer(playerName) + .sendMessage(Messages.addedOwner(changedPlayer, replicator)); + } + else + { + Plugin.instance.getServer().getPlayer(playerName).sendMessage(Messages.playerAlreadyIs(changedPlayer, "owner")); + } + } + else if ( command.equalsIgnoreCase("delowner") ) + { + if ( replicator.rmOwner(changedPlayer, playerName) ) + { + Plugin.instance.getServer().getPlayer(playerName) + .sendMessage(Messages.deletedOwner(changedPlayer, replicator)); + } + else + { + Plugin.instance.getServer().getPlayer(playerName).sendMessage(Messages.noPlayerWithName(changedPlayer, "owner")); + } + } + else if ( command.equalsIgnoreCase("adduser") ) + { + if ( replicator.addUser(changedPlayer, playerName) ) + { + Plugin.instance.getServer().getPlayer(playerName) + .sendMessage(Messages.addedUser(changedPlayer, replicator)); + } + else + { + Plugin.instance.getServer().getPlayer(playerName).sendMessage(Messages.playerAlreadyIs(changedPlayer, "user")); + } + } + else if ( command.equalsIgnoreCase("deluser") ) + { + if ( replicator.rmUser(changedPlayer, playerName) ) + { + Plugin.instance.getServer().getPlayer(playerName) + .sendMessage(Messages.deletedUser(changedPlayer, replicator)); + } + else + { + Plugin.instance.getServer().getPlayer(playerName).sendMessage(Messages.noPlayerWithName(changedPlayer, "user")); + } + } + } } diff --git a/src/main/java/de/craftinc/replicator/LocationSerializer.java b/src/main/java/de/craftinc/replicator/LocationSerializer.java index 1b285f2..e93c596 100644 --- a/src/main/java/de/craftinc/replicator/LocationSerializer.java +++ b/src/main/java/de/craftinc/replicator/LocationSerializer.java @@ -1,3 +1,19 @@ +/* Craft Inc. Replicator + Copyright (C) 2013 Paul Schulze, Maximilian Häckel, Moritz Kaltofen, Tobias Ottenweller + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ package de.craftinc.replicator; import org.bukkit.Location; diff --git a/src/main/java/de/craftinc/replicator/Messages.java b/src/main/java/de/craftinc/replicator/Messages.java index 11945e6..25f3b14 100644 --- a/src/main/java/de/craftinc/replicator/Messages.java +++ b/src/main/java/de/craftinc/replicator/Messages.java @@ -1,5 +1,5 @@ /* Craft Inc. Replicator - Copyright (C) 2013 Paul Schulze, Maximilian Häckel + 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 @@ -30,7 +30,8 @@ public class Messages private static String makeCmd( Player player, String command, String explanation, String[] permissions, String... args ) { - if (permissions != null) { + if ( permissions != null ) + { for ( String perm : permissions ) { if ( !player.hasPermission(perm) ) @@ -90,9 +91,6 @@ public class Messages public static String commandIssuedByNonPlayer = ChatColor.RED + "Only a player can use " + pluginName + " commands!"; - public static String noPermissionUse = - ChatColor.RED + "Sorry, you don't have permission to use this replicator. Ask .... TODO"; //TODO - public static String noPermissionCheckversion = ChatColor.RED + "Sorry, you don't have permission to check for new versions."; @@ -116,20 +114,20 @@ public class Messages { StringBuilder sb = new StringBuilder(); sb.append(ChatColor.YELLOW + "The following replicators have been found:" + NEWLINE); - if(replicators.size()>0) + if ( replicators.size() > 0 ) { for ( Replicator r : replicators ) { - sb.append(ChatColor.GOLD + r.getName() + ":" + NEWLINE); + sb.append(ChatColor.GOLD).append(r.getName()).append(":").append(NEWLINE); sb.append(ChatColor.GREEN + "Owners:" + NEWLINE); for ( String owner : r.getOwners() ) { - sb.append(ChatColor.WHITE + owner + " "); + sb.append(ChatColor.WHITE).append(owner).append(" "); } sb.append(NEWLINE + ChatColor.GREEN + "Users:" + NEWLINE); for ( String user : r.getUsers() ) { - sb.append(ChatColor.WHITE + user + " "); + sb.append(ChatColor.WHITE).append(user).append(" "); } sb.append(NEWLINE); } @@ -144,14 +142,14 @@ public class Messages sb.append(ChatColor.YELLOW + "Replicators where you are owner:" + NEWLINE); for ( Replicator r : repByOwner ) { - sb.append(ChatColor.WHITE + r.getName() + NEWLINE); + sb.append(ChatColor.WHITE).append(r.getName()).append(NEWLINE); } sb.append(NEWLINE); sb.append(ChatColor.YELLOW + "Replicators where you are user:" + NEWLINE); for ( Replicator r : repByUser ) { - sb.append(ChatColor.WHITE + r.getName() + NEWLINE); + sb.append(ChatColor.WHITE).append(r.getName()).append(NEWLINE); } return sb.toString(); @@ -165,21 +163,55 @@ public class Messages public static String addedOwner( String newOwner, Replicator replicator ) { - return ChatColor.GREEN + "Added " + ChatColor.GOLD + newOwner + " as owner for " + ChatColor.GOLD + - replicator.getName(); + return ChatColor.GREEN + "Added " + ChatColor.GOLD + newOwner + ChatColor.GREEN + " as owner for " + + ChatColor.GOLD + replicator.getName() + ChatColor.GREEN + "."; + } + + public static String deletedOwner( String deletedOwner, Replicator replicator ) + { + return ChatColor.GREEN + "Deleted owner status of " + ChatColor.GOLD + deletedOwner + ChatColor.GREEN + + " for replicator " + + ChatColor.GOLD + replicator.getName() + ChatColor.GREEN + "."; + } + + public static String addedUser( String newUser, Replicator replicator ) + { + return ChatColor.GREEN + "Added " + ChatColor.GOLD + newUser + ChatColor.GREEN + " as user for " + + ChatColor.GOLD + replicator.getName() + ChatColor.GREEN + "."; + } + + public static String deletedUser( String deletedUser, Replicator replicator ) + { + return ChatColor.GREEN + "Deleted user status of " + ChatColor.GOLD + deletedUser + ChatColor.GREEN + + " for replicator " + + ChatColor.GOLD + replicator.getName() + ChatColor.GREEN + "."; } public static String newReplicator( Replicator replicator ) { - return ChatColor.GREEN + "Congratulations!" + ChatColor.YELLOW + " You have just built a working replicator with id: " + + return ChatColor.GREEN + "Congratulations!" + ChatColor.YELLOW + + " You have just built a working replicator with id: " + ChatColor.GREEN + replicator.getName() + NEWLINE + - " Put item frames with items you want to replicate onto the front side and right click them to replicate." + NEWLINE + + " Put item frames with items you want to replicate onto the front side and right click them to replicate." + + NEWLINE + " Use " + ChatColor.GOLD + "/repli adduser|deluser" + ChatColor.YELLOW + " while looking at it to give" + " give other players permission to use your replicator." + NEWLINE + - " Use " + ChatColor.GOLD + "/repli help" + " to see a full list of commands you can use."; + " Use " + ChatColor.GOLD + "/repli help" + ChatColor.YELLOW + + " to see a full list of commands you can use."; } - public static String couldNotSave = ChatColor.RED + "Sorry! Could not save the replicators to disk. After a server " + - "reload or restart the information about this replicator will be lost. You will " + - "still be able to use it. Tell a mod or admin about that problem."; + public static String couldNotSave = + ChatColor.RED + "Sorry! Could not save the replicators to disk. After a server " + + "reload or restart the information about this replicator will be lost. You will " + + "still be able to use it. Tell a mod or admin about that problem."; + + public static String noPlayerWithName( String changedPlayer, String ownerUser ) + { + return ChatColor.RED + "There is no " + ownerUser + " named " + ChatColor.GOLD + changedPlayer + ChatColor.RED + "."; + } + + public static String playerAlreadyIs( String changedPlayer, String ownerUser ) + { + return ChatColor.RED + "Player " + ChatColor.GOLD + changedPlayer + ChatColor.RED + " is already " + ownerUser + "."; + } } diff --git a/src/main/java/de/craftinc/replicator/PlayerInteractEntityListener.java b/src/main/java/de/craftinc/replicator/PlayerInteractEntityListener.java index 52e6680..0658e77 100644 --- a/src/main/java/de/craftinc/replicator/PlayerInteractEntityListener.java +++ b/src/main/java/de/craftinc/replicator/PlayerInteractEntityListener.java @@ -16,7 +16,6 @@ */ package de.craftinc.replicator; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -60,14 +59,16 @@ public class PlayerInteractEntityListener implements Listener } // do nothing if item frame is empty - if (itemFrame.getItem().getType().equals(Material.AIR)) + if ( itemFrame.getItem().getType().equals(Material.AIR) ) { return; } // find replicator centers which are suitable for this item frame //Replicator.mochaccino.sendMessage(itemFrame.getAttachedFace() + ""); - ArrayList replicators = Replicator.getUsableReplicators(event.getRightClicked().getLocation().getBlock().getRelative(itemFrame.getAttachedFace()).getLocation(),event.getPlayer().getName()); + ArrayList replicators = Replicator.getUsableReplicators( + event.getRightClicked().getLocation().getBlock().getRelative(itemFrame.getAttachedFace()).getLocation(), + event.getPlayer().getName()); // do nothing if no replicator centers have been found if ( replicators.isEmpty() ) @@ -88,8 +89,8 @@ public class PlayerInteractEntityListener implements Listener ItemStack stack = itemFrame.getItem(); stack.setAmount(64); event.getPlayer().getWorld().dropItemNaturally( - replicator.getCenter().getBlock().getRelative(Replicator.getDirection(replicator.getCenter())).getLocation(), - stack); + replicator.getCenter().getBlock().getRelative(Replicator.getDirection(replicator.getCenter())) + .getLocation(), stack); } } } diff --git a/src/main/java/de/craftinc/replicator/Plugin.java b/src/main/java/de/craftinc/replicator/Plugin.java index 1ced1ba..1ef9c4d 100644 --- a/src/main/java/de/craftinc/replicator/Plugin.java +++ b/src/main/java/de/craftinc/replicator/Plugin.java @@ -1,5 +1,5 @@ /* Craft Inc. Replicator - Copyright (C) 2013 Paul Schulze, Maximilian Häckel + 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 @@ -49,7 +49,7 @@ public class Plugin extends JavaPlugin // commands Commands commandExecutor = new Commands(); - getCommand("replicate").setExecutor(commandExecutor); + getCommand("replicator").setExecutor(commandExecutor); // register listeners PluginManager pm = this.getServer().getPluginManager(); diff --git a/src/main/java/de/craftinc/replicator/Replicator.java b/src/main/java/de/craftinc/replicator/Replicator.java index ebc004f..cc8cc0f 100644 --- a/src/main/java/de/craftinc/replicator/Replicator.java +++ b/src/main/java/de/craftinc/replicator/Replicator.java @@ -86,7 +86,8 @@ public class Replicator implements ConfigurationSerializable this.users = new HashSet(); this.owners.add(firstOwner); this.center = center; - name = center.getWorld().getName() + "," + center.getBlockX() + "," + center.getBlockY() + "," + center.getBlockZ(); + name = center.getWorld().getName() + "," + center.getBlockX() + "," + center.getBlockY() + "," + + center.getBlockZ(); } @SuppressWarnings("unchecked unused") @@ -117,45 +118,51 @@ public class Replicator implements ConfigurationSerializable return users; } - public void addUser( String user, String player ) + public Boolean addUser( String user, String player ) { - this.users.add(user); - Replicator.saveReplicators(player); - } - - public void addOwner( String owner, String player ) - { - this.owners.add(owner); - Replicator.saveReplicators(player); - } - - public boolean rmUser( String user, String player ) - { - if ( this.users.remove(user) ) + if ( users.add(user) ) { Replicator.saveReplicators(player); return true; } - else - return false; + return false; } - public boolean rmOwner( String owner, String player ) + public Boolean addOwner( String owner, String player ) { - if ( this.owners.remove(owner) ) + if ( owners.add(owner) ) { - if(owners.isEmpty()) + Replicator.saveReplicators(player); + return true; + } + return false; + } + + public Boolean rmUser( String user, String player ) + { + if ( users.remove(user) ) + { + Replicator.saveReplicators(player); + return true; + } + return false; + } + + public Boolean rmOwner( String owner, String player ) + { + if ( owners.remove(owner) ) + { + if ( owners.isEmpty() ) { - allReplicators.remove(this.center); + allReplicators.remove(center); } Replicator.saveReplicators(player); return true; } - else - return false; + return false; } - public boolean isOwner( String player ) + public boolean hasOwner( String player ) { for ( String owner : owners ) { @@ -167,7 +174,7 @@ public class Replicator implements ConfigurationSerializable return false; } - public boolean isUser( String player ) + public boolean hasUser( String player ) { for ( String user : users ) { @@ -179,6 +186,7 @@ public class Replicator implements ConfigurationSerializable return false; } + @SuppressWarnings("UnusedDeclaration") public void setName( String newName, String player ) { this.name = newName; @@ -190,16 +198,12 @@ public class Replicator implements ConfigurationSerializable return name; } - public boolean isUsable(String player) + public boolean isUsable( String player ) { - if ( this.isOwner(player) || this.isUser(player) ) - { - return true; - } - return false; + return this.hasOwner(player) || this.hasUser(player); } - public static ArrayList getReplicatorLocations(Location currentBlock) + public static ArrayList getReplicatorLocations( Location currentBlock ) { //mochaccino.sendMessage("Hello Mochaccino!"); ArrayList replicators = new ArrayList(); @@ -229,13 +233,17 @@ public class Replicator implements ConfigurationSerializable private static Material[][][] getPattern( Location center ) { - if ( getDirection(center).equals(BlockFace.NORTH) ) + BlockFace direction = getDirection(center); + if ( direction == null ) + return null; + + if ( direction.equals(BlockFace.NORTH) ) return Pattern.getNorth(); - if ( getDirection(center).equals(BlockFace.SOUTH) ) + if ( direction.equals(BlockFace.SOUTH) ) return Pattern.getSouth(); - if ( getDirection(center).equals(BlockFace.WEST) ) + if ( direction.equals(BlockFace.WEST) ) return Pattern.getWest(); - if ( getDirection(center).equals(BlockFace.EAST) ) + if ( direction.equals(BlockFace.EAST) ) return Pattern.getEast(); return null; } @@ -294,8 +302,8 @@ public class Replicator implements ConfigurationSerializable * Gets a replicator with the given location. If no replicator exists a new one is created. * Returns null if player is not owner or user of the replicator. * - * @param loc center of the replicator - * @param player the player entity + * @param loc center of the replicator + * @param player the player entity * @return Replicator */ public static Replicator getOrCreate( Location loc, Player player ) @@ -305,7 +313,7 @@ public class Replicator implements ConfigurationSerializable // replicator already exists if ( rep != null ) { - if ( rep.isOwner(player.getName()) || rep.isUser(player.getName()) ) + if ( rep.hasOwner(player.getName()) || rep.hasUser(player.getName()) ) { return rep; } @@ -327,75 +335,111 @@ public class Replicator implements ConfigurationSerializable /** * Returns all Replicators, which includes the Block at Location loc. - * @param loc Location of the current Block + * + * @param loc Location of the current Block * @return ArrayList of Replicators */ - public static ArrayList getReplicators(Location loc) + public static ArrayList getReplicators( Location loc ) { ArrayList locs = getReplicatorLocations(loc); ArrayList reps = new ArrayList(); - for(Location center:locs) + for ( Location center : locs ) { - if(allReplicators.get(center)!=null) + if ( allReplicators.get(center) != null ) reps.add(allReplicators.get(center)); } return reps; } - public static ArrayList getUsableReplicators(Location loc, String player) + public static ArrayList getUsableReplicators( Location loc, String player ) { ArrayList locs = getReplicatorLocations(loc); ArrayList reps = new ArrayList(); - for(Location center:locs) + for ( Location center : locs ) { Replicator rep = allReplicators.get(center); - if(rep!=null&&rep.isUsable(player)) + if ( rep != null && rep.isUsable(player) ) reps.add(rep); } return reps; } - public static ArrayList getOwnReplicators(Location loc, String player) + public static ArrayList getOwnReplicators( Location loc, String player ) { ArrayList locs = getReplicatorLocations(loc); ArrayList reps = new ArrayList(); - for(Location center:locs) + for ( Location center : locs ) { Replicator rep = allReplicators.get(center); - if(rep!=null&&rep.isOwner(player)) + if ( rep != null && rep.hasOwner(player) ) reps.add(rep); } return reps; } + + /** - * Get a replicator with the specified name. Returns null if player - * is not owner or user or if replicator does not exist. + * Get a replicator with the specified name without any permission checks. + * Returns null if replicator with that name does not exist. * - * @param repName name of the replicator - * @param playerName name of the player + * @param repName name of the replicator * @return Replicator */ - public static Replicator getByName( String repName, String playerName ) + public static Replicator getByName( String repName ) { for ( Replicator rep : allReplicators.values() ) { if ( rep.getName().equals(repName) ) { - if(rep.isUsable(playerName)) - { - return rep; - } + return rep; } } return null; } + /** + * Get a replicator with the specified name where the given player is owner + * else returns null. + * + * @param repName name of the replicator + * @param playerName name of the player who has to be owner + * @return Replicator + */ + public static Replicator getOwnByName( String repName, String playerName ) + { + Replicator rep = getByName(repName); + if ( rep.hasOwner(playerName) ) + { + return rep; + } + return null; + } + + /** + * Get a replicator with the specified name where the given player is at least user + * else returns null. + * + * @param repName name of the replicator + * @param playerName name of the player who has to be at least user + * @return Replicator + */ + @SuppressWarnings("UnusedDeclaration") + public static Replicator getUsableByName( String repName, String playerName ) + { + Replicator rep = getByName(repName); + if ( rep.isUsable(playerName) ) + { + return rep; + } + return null; + } + public static ArrayList getReplicatorsByOwner( String playerName ) { ArrayList reps = new ArrayList(); for ( Replicator rep : allReplicators.values() ) { - if ( rep.isOwner(playerName) ) + if ( rep.hasOwner(playerName) ) { reps.add(rep); } @@ -408,7 +452,7 @@ public class Replicator implements ConfigurationSerializable ArrayList reps = new ArrayList(); for ( Replicator rep : allReplicators.values() ) { - if ( rep.isUser(playerName) ) + if ( rep.hasUser(playerName) ) { //mochaccino.sendMessage("You are User for "+rep.getName()); reps.add(rep); @@ -435,9 +479,10 @@ public class Replicator implements ConfigurationSerializable replicatorsFileConf.getList(keyReplicators); } - public static void saveReplicators(String playerName) + public static void saveReplicators( String playerName ) { - try { + try + { replicatorsFileConf.set(keyReplicators, new ArrayList(allReplicators.values())); replicatorsFileConf.save(replicatorsFile); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 74d9055..38e35dc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ # Craft Inc. Replicator -# Copyright (C) 2013 Paul Schulze, Maximilian Häckel +# 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 @@ -22,8 +22,8 @@ authors: [ddidderr, beuth_el_max] website: http://www.craftinc.de/craftinc-replicator commands: - replicate: - description: Shows help for Craft Inc. Replicate + replicator: + description: Shows help for Craft Inc. Replicator aliases: [repli] permissions: