Fixed portal error and also added new block place features

This commit is contained in:
Alastair 2017-06-11 18:32:53 +01:00
parent de46b0846e
commit 9099f2367b
4 changed files with 76 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import com.sekwah.advancedportals.api.portaldata.PortalArg;
import com.sekwah.advancedportals.listeners.Listeners;
import com.sekwah.advancedportals.portals.AdvancedPortal;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -15,6 +16,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.material.Wool;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.*;
@ -57,7 +59,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ItemStack regionselector = new ItemStack(WandMaterial);
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName("\u00A7ePortal Region Selector");
selectorname.setDisplayName("\u00A5ePortal Region Selector");
selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help"
, "\u00A7r create portals bistowed upon it!"));
regionselector.setItemMeta(selectorname);
@ -68,8 +70,38 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
case "portalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
ItemStack portalBlock = new ItemStack(Material.PORTAL, 1);
ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1);
ItemMeta blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A75Portal Block Placer");
blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance\n" +
"Right Click: Place portal block\n" +
"Left Click: Rotate portal block"));
portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
break;
case "endportalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78End Portal Block Placer");
blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance\n" +
"Right Click: Place portal block"));
portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
break;
case "gatewayblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78Gateway Block Placer");
blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance\n" +
"Right Click: Place portal block"));
portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
@ -535,7 +567,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (sender.hasPermission("AdvancedPortals.CreatePortal")) {
if (args.length == 1) {
autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "selector"
, "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage"));
, "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage"));
} else if (args[0].toLowerCase().equals("create")) {
boolean hasName = false;

View File

@ -10,6 +10,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;
@ -150,12 +151,10 @@ public class Listeners implements Listener {
}
}
// https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html
// Also listen to this possibly.
@EventHandler
public void onPortalEvent(PlayerPortalEvent event) {
Player player = event.getPlayer();
if (player.hasMetadata("hasWarped") | Portal.inPortalTriggerRegion(player.getLocation()))
if (player.hasMetadata("hasWarped") | Portal.inPortalRegion(event.getFrom(),1))
event.setCancelled(true);
}
@ -181,7 +180,7 @@ public class Listeners implements Listener {
return;
}
if (player.hasPermission("AdvancedPortals.CreatePortal")) {
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,
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
@ -205,7 +204,8 @@ public class Listeners implements Listener {
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("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
player.sendMessage("\u00A7eYou 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);
@ -217,7 +217,8 @@ public class Listeners implements Listener {
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("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
player.sendMessage("\u00A7eYou 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);
@ -226,7 +227,17 @@ public class Listeners implements Listener {
}
}
else if(event.getItem() != null && event.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals("\u00A75Portal Block Placer") &&
event.getAction() == Action.LEFT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.PORTAL){
Block block = event.getClickedBlock();
if(block.getData() == 1){
block.setData((byte) 2);
}
else{
block.setData((byte) 1);
}
event.setCancelled(true);
}
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class PortalPlacer implements Listener {
@ -34,11 +35,24 @@ public class PortalPlacer implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer().hasPermission("advancedportals.build") && event.getItemInHand().getItemMeta().getDisplayName().equals("\u00A75Portal Block Placer")){
event.getBlockPlaced().setType(Material.PORTAL);
}
else if (event.getPlayer().hasPermission("advancedportals.build") && event.getItemInHand().getItemMeta().getDisplayName().equals("\u00A78End Portal Block Placer")){
event.getBlockPlaced().setType(Material.ENDER_PORTAL);
}
else if (event.getPlayer().hasPermission("advancedportals.build") && event.getItemInHand().getItemMeta().getDisplayName().equals("\u00A78Gateway Block Placer")){
event.getBlockPlaced().setType(Material.END_GATEWAY);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
Material material = block.getType();
if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius))
//Material material = block.getType();
if (event.getChangedType() == Material.PORTAL/*(material == Material.PORTAL)*/ && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius))
event.setCancelled(true);
}
}

View File

@ -529,6 +529,13 @@ public class Portal {
return false;
}
public static boolean locationInPortal(Location loc, int additionalArea) {
for (AdvancedPortal portal : Portal.portals)
if (Portal.locationInPortal(portal, loc, additionalArea))
return true;
return false;
}
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
if (!portalsActive)
return false;