total unstable

This commit is contained in:
Paul Schulze 2013-03-18 22:22:47 +01:00
parent ba3f8bfe98
commit 1335b437b7
6 changed files with 162 additions and 31 deletions

View File

@ -0,0 +1,58 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
package de.craftinc.replicator;
import java.util.Arrays;
import java.util.HashSet;
public class BlockUtil
{
/**
* List of blocks considered transparent. Not complete.
*/
public static final HashSet<Byte> transparentBlocks = new HashSet<Byte>(Arrays.asList(new Byte[] {
6, // Sapling
8, // Flowing Water
9, // Still Water
20, // Glass
30, // Cobweb
37, // Dandelion
38, // Rose
39, // Brown Mushrooom
40, // Red Mushroom
44, // Slabs
50, // Torch
70, // Stone Pressure Plate
72, // Wooden Pressure Plate
75, // Redstone Torch (inactive)
76, // Redstone Torch (active)
78, // Snow
79, // Ice
102, // Window
104, // Pumpkin Stem
105, // Melon Stem
126, // Wooden Slab
(byte) 131, // Tripwire Hook
(byte) 132, // Tripwire
(byte) 147, // Weighted Pressure Plate (Light)
(byte) 148, // Weighted Pressure Plate (Heavy)
(byte) 149, // Redstone Comparator (inactive)
(byte) 150, // Redstone Comparator (active)
(byte) 151, // Daylight Sensor
}));
}

View File

@ -16,11 +16,15 @@
*/ */
package de.craftinc.replicator; package de.craftinc.replicator;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
public class Commands implements CommandExecutor public class Commands implements CommandExecutor
{ {
@Override @Override
@ -32,5 +36,57 @@ public class Commands implements CommandExecutor
sender.sendMessage(Messages.commandIssuedByNonPlayer); sender.sendMessage(Messages.commandIssuedByNonPlayer);
return true; return true;
} }
// commands
if ( command.getName().equalsIgnoreCase("replicate") || command.getAliases().get(0).equalsIgnoreCase("repli") )
{
Player player = ( (Player) sender ).getPlayer();
// help
if ( args.length == 0 || ( args.length > 0 && args[0].equalsIgnoreCase("help") ) )
{
sender.sendMessage(Messages.helpGeneral(player));
return true;
}
// info
if ( args.length > 0 && args[0].equalsIgnoreCase("info") )
{
// looking at replicator
if ( args.length == 1 )
{
// get block where the player is looking at
Block potentialReplicatorBlock = player.getTargetBlock(BlockUtil.transparentBlocks, 100);
// get zero or more valid replicator centers
ArrayList<Location> replicatorCenters = Replicator
.getReplicators(potentialReplicatorBlock.getLocation());
if ( replicatorCenters.size() == 0 )
{
sender.sendMessage(Messages.noReplicatorInSight);
return true;
}
ArrayList<Replicator> replicators = new ArrayList<Replicator>();
for ( Location replicatorCenter : replicatorCenters )
{
replicators.add(Replicator.getOrCreate(replicatorCenter));
}
sender.sendMessage(Messages.info(replicators));
return true;
}
// replicator specified as argument
else if ( args.length == 2 )
{
}
}
}
// if some unknown argument has been given, show help message
sender.sendMessage(Messages.helpGeneral(( (Player) sender ).getPlayer()));
return true;
} }
} }

View File

@ -19,14 +19,25 @@ package de.craftinc.replicator;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
public class Messages public class Messages
{ {
private static final String NEWLINE = "\n"; private static final String NEWLINE = "\n";
private static final String pluginName = Plugin.instance.getDescription().getName(); private static final String pluginName = Plugin.instance.getDescription().getName();
private static String makeCmd( Player player, String command, String explanation, String[] permissions, String... args ) private static String makeCmd( Player player, String command, String explanation, String[] permissions,
String... args )
{ {
for ( String perm : permissions )
{
if ( !player.hasPermission(perm) )
{
return "";
}
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// command // command
@ -56,21 +67,16 @@ public class Messages
return sb.toString(); return sb.toString();
} }
public static String helpGeneral(Player player) = public static String helpGeneral( Player player )
ChatColor.GREEN + pluginName + " - Usage:" + NEWLINE + {
makeCmd("help", "shows this help", null) + return ChatColor.GREEN + pluginName + " - Usage:" + NEWLINE +
makeCmd("adduser | deluser", makeCmd(player, "help", "shows this help", null) +
"Add or remove a player's right to use the replicator in front of you or the replicator given by \"id\".", makeCmd(player, "adduser | deluser", "Add or remove a player's right to use the replicator in front of you or the replicator given by \"id\".", null, "<player>", "[id]") +
null, "<player>", "[id]") + makeCmd(player, "addowner | delowner", "Add or remove a player's right to use AND add or remove other users and owners to the replicator in front of you or the replicator given by \"id\".", null, "<player>", "[id]") +
makeCmd("addowner | delowner", makeCmd(player, "list", "Lists all your replicators.", null) +
"Add or remove a player's right to use AND add or remove other users and owners to the replicator in front of you or the replicator given by \"id\".", makeCmd(player, "info", "Get information about the replicator in front of you or the replicator given by \"id\".", null, "[id]") +
null, "<player>", "[id]") + makeCmd(player, "checkversion", "Checks for a newer version.", new String[] { "craftinc.replicator.update" });
makeCmd("checkversion", "Checks for a newer version.", new String[]{"craftinc.replicator.update"}); }
public static String borderCreationSuccessful
= ChatColor.YELLOW + "New border was set " +
ChatColor.GREEN + "successfully" +
ChatColor.YELLOW + "!";
public static String commandIssuedByNonPlayer public static String commandIssuedByNonPlayer
= ChatColor.RED + "Only a player can use " + pluginName + " commands!"; = ChatColor.RED + "Only a player can use " + pluginName + " commands!";
@ -81,6 +87,9 @@ public class Messages
public static String noPermissionCheckversion = public static String noPermissionCheckversion =
ChatColor.RED + "Sorry, you don't have permission to check for new versions."; ChatColor.RED + "Sorry, you don't have permission to check for new versions.";
public static String noReplicatorInSight =
ChatColor.RED + "You are not looking at an replicator.";
public static String updateMessage( String newVersion, String curVersion ) public static String updateMessage( String newVersion, String curVersion )
{ {
return ChatColor.RED + pluginName + ": New version available!" + NEWLINE + return ChatColor.RED + pluginName + ": New version available!" + NEWLINE +
@ -93,4 +102,26 @@ public class Messages
public static String noUpdateAvailable = public static String noUpdateAvailable =
ChatColor.YELLOW + "No updates available."; ChatColor.YELLOW + "No updates available.";
public static String info( ArrayList<Replicator> replicators )
{
StringBuilder sb = new StringBuilder();
sb.append(ChatColor.YELLOW + "The following replicators have been found:" + NEWLINE);
for (Replicator r: replicators)
{
sb.append(ChatColor.GOLD + r.id + " @ " + r.center.getX() + "," + r.center.getZ() + NEWLINE);
sb.append(ChatColor.GREEN + "Owners:" + NEWLINE);
for (String owner: r.getOwners())
{
sb.append(ChatColor.WHITE + owner + " ");
}
sb.append(NEWLINE + ChatColor.GREEN + "Users:" + NEWLINE);
for (String user: r.getUsers())
{
sb.append(ChatColor.WHITE + user + " ");
}
sb.append(NEWLINE);
}
return sb.toString();
}
} }

View File

@ -19,13 +19,6 @@ package de.craftinc.replicator;
import org.bukkit.Material; import org.bukkit.Material;
/**
* Created with IntelliJ IDEA.
* User: Mochaccino
* Date: 18.03.13
* Time: 20:33
* To change this template use File | Settings | File Templates.
*/
public class Pattern { public class Pattern {
private static final Material[][][] repPattern = {{{Material.OBSIDIAN,Material.OBSIDIAN,null},{Material.MOSSY_COBBLESTONE,Material.OBSIDIAN,null},{Material.GLOWSTONE,Material.OBSIDIAN,null}}, private static final Material[][][] repPattern = {{{Material.OBSIDIAN,Material.OBSIDIAN,null},{Material.MOSSY_COBBLESTONE,Material.OBSIDIAN,null},{Material.GLOWSTONE,Material.OBSIDIAN,null}},
{{Material.GOLD_BLOCK,Material.DIAMOND_BLOCK,Material.OBSIDIAN},{Material.AIR,Material.JACK_O_LANTERN,Material.OBSIDIAN},{Material.MOSSY_COBBLESTONE,Material.OBSIDIAN,null}}, {{Material.GOLD_BLOCK,Material.DIAMOND_BLOCK,Material.OBSIDIAN},{Material.AIR,Material.JACK_O_LANTERN,Material.OBSIDIAN},{Material.MOSSY_COBBLESTONE,Material.OBSIDIAN,null}},

View File

@ -23,13 +23,6 @@ import org.bukkit.Material;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Created with IntelliJ IDEA.
* User: starback
* Date: 18.03.13
* Time: 16:26
* To change this template use File | Settings | File Templates.
*/
public class Replicator { public class Replicator {
private ArrayList<String> owners; private ArrayList<String> owners;

View File

@ -21,10 +21,10 @@ softdepend: [Multiverse-Core]
authors: [ddidderr, beuth_el_max] authors: [ddidderr, beuth_el_max]
website: http://www.craftinc.de/craftinc-replicator website: http://www.craftinc.de/craftinc-replicator
commands: commands:
replicate: replicate:
description: Shows help for Craft Inc. Replicate description: Shows help for Craft Inc. Replicate
aliases: [repli]
permissions: permissions:
craftinc.replicator.update: craftinc.replicator.update: