From 0eba0ccf41a0c64a002144902b2da083b013afe8 Mon Sep 17 00:00:00 2001 From: sekwah41 Date: Tue, 15 Oct 2013 21:45:44 +0100 Subject: [PATCH] Added /portal show, some checks for pos 1 and 2 and also fixed some bugs. --- Advanced Portals/src/Config.yml | 8 + .../AdvancedPortalsCommand.java | 18 +- .../AdvancedPortalsPlugin.java | 2 + .../com/sekwah/advancedportals/Listeners.java | 7 +- .../com/sekwah/advancedportals/Selection.java | 191 ++++++++++++++++++ Advanced Portals/src/plugin.yml | 2 +- 6 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 Advanced Portals/src/com/sekwah/advancedportals/Selection.java diff --git a/Advanced Portals/src/Config.yml b/Advanced Portals/src/Config.yml index f44e38d..e5ed88f 100644 --- a/Advanced Portals/src/Config.yml +++ b/Advanced Portals/src/Config.yml @@ -6,3 +6,11 @@ # Set to true if you want the normal axes to work normally but the ones gived with /portals selector or wand will still work though UseOnlyServerMadeAxe: false + + +ShowSelectionBlockID: WOOL +ShowSelectionBlockData: 14 + + +# This changes how long the show seletion lasts in seconds +ShowSelectionShowDuration: 3 diff --git a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 81ba631..ab877e5 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -2,6 +2,8 @@ package com.sekwah.advancedportals; import java.util.Arrays; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -10,6 +12,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.CreatePortal; @@ -40,7 +43,7 @@ public class AdvancedPortalsCommand implements CommandExecutor { regionselector.setItemMeta(selectorname); inventory.addItem(regionselector); - sender.sendMessage("§a[§7AdvancedPortals§a] You have been given a §ePortal Region Selector§a!"); + sender.sendMessage("§a[§eAdvancedPortals§a] You have been given a §ePortal Region Selector§a!"); } else{ PluginMessages.NoPermission(sender, command); @@ -49,6 +52,19 @@ public class AdvancedPortalsCommand implements CommandExecutor { else if(args[0].toLowerCase().equals("create")) { // CreatePortal.CreatePortal(pos1, pos2); need to get pos 1 and 2 } + else if(args[0].toLowerCase().equals("show")){ + if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){ + if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){ + Selection.Show(player, this.plugin); + } + else{ + player.sendMessage("§a[§eAdvancedPortals§a] Your currently selected area has been shown, it will dissapear shortly!"); + } + } + else{ + player.sendMessage("§c[§7AdvancedPortals§c] You need to have both points selected!"); + } + } else{ PluginMessages.UnknownCommand(sender, command); } diff --git a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 50baff5..a3f7abb 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -19,6 +19,8 @@ public class AdvancedPortalsPlugin extends JavaPlugin { // These register the listeners new Listeners(this); + Selection.LoadData(this); + this.getServer().getConsoleSender().sendMessage("§aAdvanced portals have been sucsessfully enabled!"); } diff --git a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java index b6ab723..b2ca3bb 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java @@ -40,7 +40,6 @@ 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(); - Location blockloc = event.getClickedBlock().getLocation(); 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, @@ -50,13 +49,14 @@ public class Listeners implements Listener { // This checks if the action was a left or right click and if it was directly effecting a block. if(event.getAction() == Action.LEFT_CLICK_BLOCK) { + Location blockloc = event.getClickedBlock().getLocation(); // stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will // have to be selected again if the player joins, also it does not affect any other players. player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX())); player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("§eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World:" + blockloc.getWorld().getName()); + player.sendMessage("§eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); // Stops the event so the block is not damaged event.setCancelled(true); @@ -65,11 +65,12 @@ public class Listeners implements Listener { return; } else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Location blockloc = event.getClickedBlock().getLocation(); player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("§eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World:" + blockloc.getWorld().getName()); + player.sendMessage("§eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); // Stops the event so the block is not interacted with event.setCancelled(true); diff --git a/Advanced Portals/src/com/sekwah/advancedportals/Selection.java b/Advanced Portals/src/com/sekwah/advancedportals/Selection.java new file mode 100644 index 0000000..310ac8d --- /dev/null +++ b/Advanced Portals/src/com/sekwah/advancedportals/Selection.java @@ -0,0 +1,191 @@ +package com.sekwah.advancedportals; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class Selection { + + public static Material blockType; + public static int timeout; + public static byte metadata; + + public static void LoadData(AdvancedPortalsPlugin plugin) { + ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml"); + + Material blockType; + + timeout = config.getConfig().getInt("ShowSelectionBlockID"); + + String BlockID = config.getConfig().getString("ShowSelectionBlockID"); + try + { + blockType = Material.getMaterial(Integer.parseInt(BlockID)); + } + catch(Exception e) + { + blockType = Material.getMaterial(BlockID); + } + + metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData"); + } + + public static void Show(final Player player, final AdvancedPortalsPlugin plugin) { + + int LowX = 0; + int LowY = 0; + int LowZ = 0; + + int HighX = 0; + int HighY = 0; + int HighZ = 0; + + if(player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()){ + LowX = player.getMetadata("Pos2X").get(0).asInt(); + HighX = player.getMetadata("Pos1X").get(0).asInt(); + } + else{ + LowX = player.getMetadata("Pos1X").get(0).asInt(); + HighX = player.getMetadata("Pos2X").get(0).asInt(); + } + if(player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()){ + LowY = player.getMetadata("Pos2Y").get(0).asInt(); + HighY = player.getMetadata("Pos1Y").get(0).asInt(); + } + else{ + LowY = player.getMetadata("Pos1Y").get(0).asInt(); + HighY = player.getMetadata("Pos2Y").get(0).asInt(); + } + if(player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()){ + LowZ = player.getMetadata("Pos2Z").get(0).asInt(); + HighZ = player.getMetadata("Pos1Z").get(0).asInt(); + } + else{ + LowZ = player.getMetadata("Pos1Z").get(0).asInt(); + HighZ = player.getMetadata("Pos2Z").get(0).asInt(); + } + + final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); + final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); + + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, LowY, LowZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, LowY, HighZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), LowX, LowY, z); + player.sendBlockChange(loc, blockType, metadata); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), HighX, LowY, z); + player.sendBlockChange(loc, blockType, metadata); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), LowX, y, LowZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), LowX, y, HighZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), HighX, y, LowZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), HighX, y, HighZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, HighY, HighZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, HighY, LowZ); + player.sendBlockChange(loc, blockType, metadata); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), LowX, HighY, z); + player.sendBlockChange(loc, blockType, metadata); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), HighX, HighY, z); + player.sendBlockChange(loc, blockType, metadata); + } + + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + Selection.Hide(player, plugin, pos1, pos2); + } + }, timeout * 20); + + } + + protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) { + + int LowX = pos1.getBlockX(); + int LowY = pos1.getBlockY(); + int LowZ = pos1.getBlockZ(); + + int HighX = pos2.getBlockX(); + int HighY = pos2.getBlockY(); + int HighZ = pos2.getBlockZ(); + + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, LowY, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, LowY, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), LowX, LowY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), HighX, LowY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), LowX, y, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), LowX, y, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), HighX, y, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int y = LowY; y <= HighY; y++){ + Location loc = new Location(player.getWorld(), HighX, y, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, HighY, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int x = LowX; x <= HighX; x++){ + Location loc = new Location(player.getWorld(), x, HighY, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), LowX, HighY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + for(int z = LowZ; z <= HighZ; z++){ + Location loc = new Location(player.getWorld(), HighX, HighY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), (byte) loc.getBlock().getData()); + } + + } + +} diff --git a/Advanced Portals/src/plugin.yml b/Advanced Portals/src/plugin.yml index d93021f..56ffff1 100644 --- a/Advanced Portals/src/plugin.yml +++ b/Advanced Portals/src/plugin.yml @@ -6,7 +6,7 @@ description: An advanced portals plugin for bukkit. commands: advancedportals: description: The main command for the advanced portals - aliases: [portals, aportals] + aliases: [portals, aportals, portal] usage: / destination: description: Can be used to access portal destinations.