mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
Added /portal show, some checks for pos 1 and 2 and also fixed some
bugs.
This commit is contained in:
parent
4aca087656
commit
0eba0ccf41
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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!");
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
191
Advanced Portals/src/com/sekwah/advancedportals/Selection.java
Normal file
191
Advanced Portals/src/com/sekwah/advancedportals/Selection.java
Normal file
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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: /<command>
|
||||
destination:
|
||||
description: Can be used to access portal destinations.
|
||||
|
Loading…
Reference in New Issue
Block a user