Started the select command, and the warp messages

This commit is contained in:
sekwah41 2014-02-23 21:52:04 +00:00
parent 23d1d2a209
commit d73d5f3f17
6 changed files with 65 additions and 13 deletions

View File

@ -34,4 +34,12 @@ ShowSelectionBlockData: 14
# This changes how long the show seletion lasts in seconds
ShowSelectionShowDuration: 10
ShowSelectionShowDuration: 10
# If a player is riding a entity, warp the entity too?
WarpRiddenEntity: true
# Use plugin name in the warp prefix
useWarpPrefix: true

View File

@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import com.sekwah.advancedportals.portalcontrolls.Portal;
@ -35,7 +36,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
Player player = (Player)sender;
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
if(sender.hasPermission("advancedportals.createportal")){
if(sender.hasPermission("advancedportals.portal")){
if(args.length > 0){
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
PlayerInventory inventory = player.getInventory();
@ -212,17 +213,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("§aExample command: §e/portal create name:test triggerId:portal");
}
else if(args[0].toLowerCase().equals("select")) {
// TODO finish the select command and the hit block to replace!
if(player.hasMetadata("selectingPortal")){
player.sendMessage("§a[§eAdvancedPortals§a] Hit a block inside the portal region to select the portal!");
player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true));
}
else{
player.sendMessage("§c[§7AdvancedPortals§c] You are already selecting a portal!");
}
}
else if(args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Portals.yml");
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
Portal.remove(args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] Portal removed!");
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists!");
if(args.length > 1){
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
Portal.remove(args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] Portal removed!");
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists!");
}
}
}
else if(args[0].toLowerCase().equals("bukkitpage")) {

View File

@ -37,6 +37,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
// These register the commands
new AdvancedPortalsCommand(this);
new DestinationCommand(this);
new WarpCommand(this);
// These register the listeners

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -161,6 +162,34 @@ public class Listeners implements Listener {
// will detect if the player is using an axe so the points of a portal can be set
// also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer();
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
player.removeMetadata("selectingPortal", plugin);
Block block = event.getClickedBlock();
Object[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){
if(Portal.worldName[portalId].equals(block.getWorld().getName())){
if((Portal.pos1[portalId].getX() + 3D) >= block.getX() && (Portal.pos1[portalId].getY() + 3D) >= block.getY() && (Portal.pos1[portalId].getZ() + 3D) >= block.getZ()){
if((Portal.pos2[portalId].getX() - 3D) <= block.getX() && (Portal.pos2[portalId].getY() - 3D) <= block.getY() && (Portal.pos2[portalId].getZ() - 3D) <= block.getZ()){
player.sendMessage("§a[§eAdvancedPortals§a]" + Portal.portalName[portalId]);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, Portal.portalName[portalId]));
event.setCancelled(true);
return;
}
}
}
portalId++;
}
player.sendMessage("§c[§7AdvancedPortals§c] No portal was selected!");
event.setCancelled(true);
return;
}
if(player.hasPermission("AdvancedPortals.CreatePortal")){
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,

View File

@ -21,7 +21,7 @@ public class WarpCommand implements CommandExecutor, TabCompleter {
public WarpCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
plugin.getCommand("destination").setExecutor(this);
plugin.getCommand("warp").setExecutor(this);
}

View File

@ -34,6 +34,8 @@ public class Portal {
public static Location[] pos1;
public static Location[] pos2;
public static String[] portalName;
public Portal(AdvancedPortalsPlugin plugin) {
Portal.plugin = plugin;
@ -55,7 +57,7 @@ public class Portal {
Set<String> PortalSet = config.getConfig().getKeys(false);
if(PortalSet.size() > 0){
Portals = PortalSet.toArray();
portalName = new String[Portals.length];
// allocates the memory for the arrays
worldName = new String[Portals.length];
triggers = new Material[Portals.length];
@ -76,7 +78,7 @@ public class Portal {
blockType = Material.getMaterial(BlockID);
}
triggers[portalId] = blockType;
portalName[portalId] = portal.toString();
worldName[portalId] = config.getConfig().getString(portal.toString() + ".world");
World world = Bukkit.getWorld(config.getConfig().getString(portal.toString() + ".world"));
pos1[portalId] = new Location(world, config.getConfig().getInt(portal.toString() + ".pos1.X"), config.getConfig().getInt(portal.toString() + ".pos1.Y"), config.getConfig().getInt(portal.toString() + ".pos1.Z"));