mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-01-30 03:51:30 +01:00
merged and stuff
This commit is contained in:
parent
ec9e11eb3a
commit
1511016221
@ -30,11 +30,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
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.portal")){
|
||||
if(args.length > 0){
|
||||
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
|
||||
Player player = (Player) sender;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
@ -57,6 +57,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")){
|
||||
Player player = (Player)sender;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
ItemStack portalBlock = new ItemStack(Material.PORTAL, 1);
|
||||
@ -66,6 +67,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("create")) {
|
||||
Player player = (Player)sender;
|
||||
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())){
|
||||
if(args.length >= 2){ // may make this next piece of code more efficient, maybe check against a list of available variables or something
|
||||
@ -206,14 +208,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("variables")) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination");
|
||||
player.sendMessage("");
|
||||
player.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination");
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("select")) {
|
||||
|
||||
// TODO finish the select command and the hit block to replace!
|
||||
|
||||
Player player = (Player)sender;
|
||||
if(!player.hasMetadata("selectingPortal")){
|
||||
if(args.length > 1){
|
||||
if(Portal.portalExists(args[1])){
|
||||
@ -235,6 +237,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("gui")){
|
||||
Player player = (Player)sender;
|
||||
if(args.length > 1){
|
||||
if(args[1].toLowerCase().equals("remove") && args.length > 2){
|
||||
sender.sendMessage("");
|
||||
@ -258,6 +261,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
else{
|
||||
Player player = (Player)sender;
|
||||
if(player.hasMetadata("selectedPortal")){
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
|
||||
@ -279,6 +283,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
// not finished yet /
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
if(args.length > 1){
|
||||
Player player = (Player)sender;
|
||||
if(player.hasMetadata("selectedPortal")){
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
if(portalName.toLowerCase() != args[1].toLowerCase()){
|
||||
@ -323,6 +328,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
else{
|
||||
Player player = (Player)sender;
|
||||
if(player.hasMetadata("selectedPortal")){
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
|
||||
@ -341,13 +347,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("bukkitpage")) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: (insert bitly link)!");
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("helppage")) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: (insert bitly link)!");
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: http://bit.ly/portals-help!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("show")){
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
Player player = (Player) sender;
|
||||
if(args.length > 1){
|
||||
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
|
||||
if(posX != null){
|
||||
@ -372,8 +379,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("help")) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!");
|
||||
else if(args[0].toLowerCase().equals("reload")) {
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
@ -24,7 +26,7 @@ public class Listeners implements Listener {
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
private int PortalMessagesDisplay = 2;
|
||||
|
||||
|
||||
// The needed config values will be stored so they are easier to access later
|
||||
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP...
|
||||
private static boolean UseOnlyServerAxe = false;
|
||||
@ -32,89 +34,90 @@ public class Listeners implements Listener {
|
||||
private static Material WandMaterial;
|
||||
|
||||
private static boolean ShowBungeeMessage;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void reloadValues(AdvancedPortalsPlugin plugin) {
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
// will check if the player is in the portal or not.
|
||||
if(Portal.portalsActive){
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Location fromloc = event.getFrom();
|
||||
Location loc = event.getTo();
|
||||
@SuppressWarnings("deprecation")
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void reloadValues(AdvancedPortalsPlugin plugin) {
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
// will check if the player is in the portal or not.
|
||||
if(Portal.portalsActive){
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Location fromloc = event.getFrom();
|
||||
Location loc = event.getTo();
|
||||
// Potentially fixes that stupid error cauzed by a bukkit update.
|
||||
// Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players.
|
||||
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
// This is probably the culprite of the bloody problem, setting the location its pointing to the event location
|
||||
// rather than sorta making a clone of the object.
|
||||
AdvancedPortal[] portals = Portal.Portals;
|
||||
for(AdvancedPortal portal : portals){
|
||||
if(loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())){
|
||||
if(portal.trigger.equals(loc.getBlock().getType())
|
||||
|| portal.trigger.equals(eyeLoc.getBlock().getType())){
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){
|
||||
|
||||
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal.portalName);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
AdvancedPortal[] portals = Portal.Portals;
|
||||
for(AdvancedPortal portal : portals){
|
||||
if(loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())){
|
||||
if(portal.trigger.equals(loc.getBlock().getType())
|
||||
|| portal.trigger.equals(eyeLoc.getBlock().getType())){
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal.portalName);
|
||||
if(PortalMessagesDisplay == 1 && warped){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
player.sendMessage("");
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\u00A7.");
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal.portalName);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal.portalName);
|
||||
if(PortalMessagesDisplay == 1 && warped){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
player.sendMessage("");
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\u00A7.");
|
||||
player.sendMessage("");
|
||||
}
|
||||
else if(PortalMessagesDisplay == 2 && warped){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
plugin.nmsAccess.sendActionBarMessage("{text:\"\u00A7aYou have been warped to \u00A7e" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\u00A7a.\"}", player);
|
||||
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
|
||||
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||
}
|
||||
|
||||
if(warped){
|
||||
@ -122,144 +125,200 @@ public class Listeners implements Listener {
|
||||
//event.setTo(player.getLocation());
|
||||
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if(portal.trigger.equals(Material.PORTAL)){
|
||||
final Player finalplayer = event.getPlayer();
|
||||
if(player.getGameMode().equals(GameMode.CREATIVE)){
|
||||
player.setMetadata("HasWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
public void run(){
|
||||
finalplayer.removeMetadata("HasWarped", plugin);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPortalEvent(PlayerPortalEvent event) {
|
||||
}
|
||||
|
||||
if(Portal.portalsActive){
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasMetadata("HasWarped")){
|
||||
if(portal.trigger.equals(Material.PORTAL)){
|
||||
final Player finalplayer = event.getPlayer();
|
||||
if(player.getGameMode().equals(GameMode.CREATIVE)){
|
||||
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
public void run(){
|
||||
finalplayer.removeMetadata("hasWarped", plugin);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
else if(portal.trigger.equals(Material.LAVA)){
|
||||
final Player finalplayer = event.getPlayer();
|
||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
public void run(){
|
||||
finalplayer.removeMetadata("lavaWarped", plugin);
|
||||
finalplayer.setFireTicks(-1);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCombustEntityEvent(EntityCombustEvent event) {
|
||||
Location loc = event.getEntity().getLocation();
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(loc.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamEvent(EntityDamageEvent event) {
|
||||
//System.out.println(event.getCause());
|
||||
if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){
|
||||
Location loc = event.getEntity().getLocation();
|
||||
if(event.getEntity().hasMetadata("lavaWarped")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
Object[] portals = Portal.Portals;
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(player.getWorld().getName())){
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(loc.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
|
||||
|
||||
event.setCancelled(true);
|
||||
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onItemInteract(PlayerInteractEvent event) {
|
||||
// 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)){
|
||||
Block block = event.getClickedBlock();
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(block.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPortalEvent(PlayerPortalEvent event) {
|
||||
|
||||
if(Portal.portalsActive){
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasMetadata("hasWarped")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
Object[] portals = Portal.Portals;
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(player.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onItemInteract(PlayerInteractEvent event) {
|
||||
// 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)){
|
||||
Block block = event.getClickedBlock();
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(block.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){
|
||||
|
||||
if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected - if you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
|
||||
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,
|
||||
// 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
|
||||
// as a weapon.
|
||||
if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == WandMaterial.getId()) {
|
||||
|
||||
// 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("\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);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
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("\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);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected - if you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
|
||||
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,
|
||||
// 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
|
||||
// as a weapon.
|
||||
if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == WandMaterial.getId()) {
|
||||
|
||||
// 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("\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);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
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("\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);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ public class Destination {
|
||||
public Destination(AdvancedPortalsPlugin plugin) {
|
||||
Destination.plugin = plugin;
|
||||
}
|
||||
|
||||
// TODO add permissions for destinations.
|
||||
|
||||
public static void create(Location location, String name){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
|
Loading…
Reference in New Issue
Block a user