LICENSE updated

messages beautified
small fixes and improvements
This commit is contained in:
Paul Schulze 2013-03-19 21:42:52 +01:00
parent 0f4786958d
commit 085306995b
12 changed files with 276 additions and 167 deletions

View File

@ -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"

View File

@ -1,11 +0,0 @@
eigenschaften global
-list replikatoren
eigenschaften replikator:
-list owner
-list user
-location rep
-location pumpkin
-method: is_valid()

34
pom.xml
View File

@ -33,23 +33,23 @@
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<artifactId>exec-maven-plugin</artifactId>-->
<!--<groupId>org.codehaus.mojo</groupId>-->
<!--<version>1.2.1</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>Run Test Bukkit Server</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>exec</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<executable>${basedir}/scripts/test-deployment.sh</executable>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>Run Test Bukkit Server</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/test-deployment.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -36,10 +36,6 @@ public class BlockPlaceListener implements Listener
for ( Location loc : replicators )
{
Replicator rep = Replicator.getOrCreate(loc, event.getPlayer());
if ( rep != null )
{
}
}
}
}

View File

@ -19,6 +19,7 @@ package de.craftinc.replicator;
import java.util.Arrays;
import java.util.HashSet;
// FIXME: unused at the moment because the HashSet<Byte> seems not to be working as it is expected here...
public class BlockUtil
{
/**

View File

@ -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<Replicator> replicators = Replicator.getReplicators(potentialReplicatorBlock.getLocation());
ArrayList<Replicator> 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]));
@ -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"));
}
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package de.craftinc.replicator;
import org.bukkit.Location;

View File

@ -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.";
@ -120,16 +118,16 @@ public class Messages
{
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 " +
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 + ".";
}
}

View File

@ -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;
@ -67,7 +66,9 @@ public class PlayerInteractEntityListener implements Listener
// find replicator centers which are suitable for this item frame
//Replicator.mochaccino.sendMessage(itemFrame.getAttachedFace() + "");
ArrayList<Replicator> replicators = Replicator.getUsableReplicators(event.getRightClicked().getLocation().getBlock().getRelative(itemFrame.getAttachedFace()).getLocation(),event.getPlayer().getName());
ArrayList<Replicator> 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);
}
}
}

View File

@ -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();

View File

@ -86,7 +86,8 @@ public class Replicator implements ConfigurationSerializable
this.users = new HashSet<String>();
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;
}
public boolean rmOwner( String owner, String player )
public Boolean addOwner( String owner, String player )
{
if ( this.owners.remove(owner) )
if ( owners.add(owner) )
{
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;
}
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;
@ -192,11 +200,7 @@ public class Replicator implements ConfigurationSerializable
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<Location> getReplicatorLocations( Location currentBlock )
@ -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;
}
@ -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,6 +335,7 @@ public class Replicator implements ConfigurationSerializable
/**
* Returns all Replicators, which includes the Block at Location loc.
*
* @param loc Location of the current Block
* @return ArrayList of Replicators
*/
@ -362,30 +371,65 @@ public class Replicator implements ConfigurationSerializable
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
* @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 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;
}
@ -395,7 +439,7 @@ public class Replicator implements ConfigurationSerializable
ArrayList<Replicator> reps = new ArrayList<Replicator>();
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<Replicator> reps = new ArrayList<Replicator>();
for ( Replicator rep : allReplicators.values() )
{
if ( rep.isUser(playerName) )
if ( rep.hasUser(playerName) )
{
//mochaccino.sendMessage("You are User for "+rep.getName());
reps.add(rep);
@ -437,7 +481,8 @@ public class Replicator implements ConfigurationSerializable
public static void saveReplicators( String playerName )
{
try {
try
{
replicatorsFileConf.set(keyReplicators, new ArrayList<Object>(allReplicators.values()));
replicatorsFileConf.save(replicatorsFile);
}

View File

@ -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: