Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alastair Hawkes 2016-05-11 11:39:01 +01:00
commit eff5319a9d
5 changed files with 103 additions and 84 deletions

View File

@ -1,5 +1,9 @@
Copyright (c) 2016 sekwah Copyright (c) 2016 sekwah
Note: If anyone has a better solution for licenses please contact me. I want to
make it so if there are major edits you can redistribute but you can't just re-upload
the code somewhere else as I have had my projects stolen before.
The plugin comes with no warranty of any kind. In no event shall I liable for The plugin comes with no warranty of any kind. In no event shall I liable for
any claim, damages or other liability. (Not that it will ever come to that) any claim, damages or other liability. (Not that it will ever come to that)

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals name: AdvancedPortals
version: 0.0.18 version: 0.0.19
author: sekwah41 author: sekwah41
description: An advanced portals plugin for bukkit. description: An advanced portals plugin for bukkit.
commands: commands:

View File

@ -244,16 +244,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
} }
} else if (args[0].toLowerCase().equals("edit")) { } else if (args[0].toLowerCase().equals("edit")) {
Player player = (Player) sender;
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
if (args.length > 1) { if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (Portal.portalExists(args[1])) {
if (posX != null) { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
portalEditMenu(sender, portalConfig, args[1]); portalEditMenu(sender, portalConfig, args[1]);
} else { } else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists!");
} }
} else { } else {
Player player = (Player) sender;
if (player.hasMetadata("selectedPortal")) { if (player.hasMetadata("selectedPortal")) {
String portalName = player.getMetadata("selectedPortal").get(0).asString(); String portalName = player.getMetadata("selectedPortal").get(0).asString();
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");

View File

@ -38,6 +38,8 @@ public class Listeners implements Listener {
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
private int PortalMessagesDisplay = 2; private int PortalMessagesDisplay = 2;
private boolean teleportDuringMove = false;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Listeners(AdvancedPortalsPlugin plugin) { public Listeners(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -77,11 +79,14 @@ public class Listeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onMoveEvent(PlayerMoveEvent event) { public void onMoveEvent(PlayerMoveEvent event) {
// will check if the player is in the portal or not. // will check if the player is in the portal or not.
if (!Portal.portalsActive) { if (!Portal.portalsActive) {
return; return;
} }
teleportDuringMove = false;
Player player = event.getPlayer(); Player player = event.getPlayer();
Location fromloc = event.getFrom(); Location fromloc = event.getFrom();
@ -116,15 +121,18 @@ public class Listeners implements Listener {
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") /**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) { if (warped) {
//event.setFrom(player.getLocation()); //event.setFrom(player.getLocation());
//event.setTo(player.getLocation()); //event.setTo(player.getLocation());
//event.setCancelled(true); //event.setCancelled(true);
} else { } else {
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); //player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
event.setCancelled(true); //plugin.getLogger().info(String.valueOf(teleportDuringMove));
if(!teleportDuringMove){
event.setCancelled(true);
}
} }
} }
if (portal.trigger.equals(Material.PORTAL)) { if (portal.trigger.equals(Material.PORTAL)) {
@ -146,6 +154,33 @@ public class Listeners implements Listener {
} }
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerTeleport(final PlayerTeleportEvent event){
Player player = event.getPlayer();
plugin.getLogger().info(String.valueOf(event.getCause()));
if(event.getCause() != PlayerTeleportEvent.TeleportCause.NETHER_PORTAL && event.getCause() != PlayerTeleportEvent.TeleportCause.END_PORTAL){
teleportDuringMove = true;
}
else{
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);
}
}
}
}
}
}
// These are here because java 7 can only take finals straight into a runnable // These are here because java 7 can only take finals straight into a runnable
class RemoveLavaData implements Runnable{ class RemoveLavaData implements Runnable{

View File

@ -366,6 +366,45 @@ public class Portal {
return false; return false;
} }
boolean showFailMessage = true;
if (portal.getArg("command.1") != null) {
showFailMessage = false;
int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do {
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
if (command.startsWith("#")) {
command = command.substring(1);
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} else if (command.startsWith("!")) {
command = command.substring(1);
boolean wasOp = player.isOp();
try {
player.setOp(true);
player.performCommand(command);
} finally {
player.setOp(wasOp);
}
} else if (command.startsWith("^")) {
command = command.substring(1);
PermissionAttachment permissionAttachment = null;
try {
permissionAttachment = player.addAttachment(plugin, "*", true);
player.performCommand(command);
} finally {
player.removeAttachment(permissionAttachment);
}
} else {
player.performCommand(command);
}
command = portal.getArg("command." + ++commandLine);
} while (command != null);
}
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if (portal.bungee != null) { if (portal.bungee != null) {
if (ShowBungeeMessage) { if (ShowBungeeMessage) {
player.sendMessage(plugin.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a."); player.sendMessage(plugin.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
@ -374,86 +413,27 @@ public class Portal {
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(portal.bungee); out.writeUTF(portal.bungee);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return false; // Down to bungee to sort out the teleporting but yea theoretically they should warp.
return true;
} else { }
boolean showFailMessage = true; else if (portal.destiation != null) {
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (portal.getArg("command.1") != null) { if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
showFailMessage = false; boolean warped = Destination.warp(player, portal.destiation);
int commandLine = 1; return warped;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do {
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
if (command.startsWith("#")) {
command = command.substring(1);
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} else if (command.startsWith("!")) {
command = command.substring(1);
boolean wasOp = player.isOp();
try {
player.setOp(true);
player.performCommand(command);
} finally {
player.setOp(wasOp);
}
} else if (command.startsWith("^")) {
command = command.substring(1);
PermissionAttachment permissionAttachment = null;
try {
permissionAttachment = player.addAttachment(plugin, "*", true);
player.performCommand(command);
} finally {
player.removeAttachment(permissionAttachment);
}
} else {
player.performCommand(command);
}
command = portal.getArg("command." + ++commandLine);
} while (command != null);
}
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if (portal.destiation != null) {
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
boolean warped = Destination.warp(player, portal.destiation);
return warped;
} else {
player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
} else { } else {
if (showFailMessage) { player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!");
player.sendMessage(plugin.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!"); plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " + "attempt and either the data is corrupt or that destination listed doesn't exist!");
+ "attempt and either the data is corrupt or portal doesn't exist!");
}
return false; return false;
} }
} else {
/*if(configDesti.getConfig().getString(destiName + ".world") != null){ if (showFailMessage) {
String permission = portalData.getConfig().getString(portalName + ".portalArgs.permission"); player.sendMessage(plugin.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!");
if(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp()){ plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
boolean warped = Destination.warp(player, destiName); + "attempt and either the data is corrupt or portal doesn't exist!");
return warped; }
} return false;
else{
player.sendMessage(plugin.customPrefix + "\u00A7c You do not have permission to use this portal!");
return false;
}
}
else{
player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}*/
} }
} }