Cooldown uses extra data, remove onLeaveEvent for cooldown persistance, add join cooldown

This commit is contained in:
Tomasz Piowczyk 2020-04-06 22:36:46 +02:00
parent 414835a690
commit f61ac373a4
4 changed files with 526 additions and 403 deletions

View File

@ -33,8 +33,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private HashSet<String> ignoreExtras = new HashSet<>(Arrays.asList("command.1", "permission")); private HashSet<String> ignoreExtras = new HashSet<>(Arrays.asList("command.1", "permission"));
// TODO recode the portal args to be put into a hashmap and use a string array // TODO recode the portal args to be put into a hashmap and use a string array
// to store all possible portal arguments. Makes code shorter and possibly more efficient. // to store all possible portal arguments. Makes code shorter and possibly more
//private HashMap<String, String> portalArgs = new HashMap<>(); // efficient.
// private HashMap<String, String> portalArgs = new HashMap<>();
public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) { public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -48,10 +49,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
//System.out.printf("%s %s %s %s%n", sender, cmd, command, args ); // System.out.printf("%s %s %s %s%n", sender, cmd, command, args );
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
if(!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(PluginMessages.customPrefixFail + " You cannot use commands with the console."); sender.sendMessage(PluginMessages.customPrefixFail + " You cannot use commands with the console.");
return true; return true;
} }
@ -59,28 +60,31 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
PlayerInventory inventory = player.getInventory(); PlayerInventory inventory = player.getInventory();
if (sender.hasPermission("advancedportals.portal")) { if (sender.hasPermission("advancedportals.portal")) {
if (args.length > 0) { switch (args[0].toLowerCase()) { if (args.length > 0) {
switch (args[0].toLowerCase()) {
case "warp": case "warp":
if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){ if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")) {
for (AdvancedPortal portal: Portal.portals){ for (AdvancedPortal portal : Portal.portals) {
if (args[1].equalsIgnoreCase(portal.getName())){ if (args[1].equalsIgnoreCase(portal.getName())) {
if (portal.inPortal.contains(player.getUniqueId())) return true; if (portal.inPortal.contains(player.getUniqueId()))
return true;
WarpEvent warpEvent = new WarpEvent(player, portal); WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent); plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!warpEvent.isCancelled()) Portal.activate(player, portal); if (!warpEvent.isCancelled())
Portal.activate(player, portal);
break; break;
} }
} }
} }
sendMenu(player, "Help Menu: Warp", "\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name"); sendMenu(player, "Help Menu: Warp",
"\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name");
break; break;
case "wand": case "wand":
case "selector": case "selector":
String ItemID = config.getConfig().getString("AxeItemId"); String ItemID = config.getConfig().getString("AxeItemId");
Material WandMaterial = Material.getMaterial(ItemID); Material WandMaterial = Material.getMaterial(ItemID);
if (WandMaterial == null) { if (WandMaterial == null) {
@ -90,30 +94,35 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ItemStack regionselector = new ItemStack(WandMaterial); ItemStack regionselector = new ItemStack(WandMaterial);
ItemMeta selectorname = regionselector.getItemMeta(); ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName("\u00A7ePortal Region Selector"); selectorname.setDisplayName("\u00A7ePortal Region Selector");
selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help" selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help",
, "\u00A7r create portals bestowed upon it!")); "\u00A7r create portals bestowed upon it!"));
regionselector.setItemMeta(selectorname); regionselector.setItemMeta(selectorname);
inventory.addItem(regionselector); inventory.addItem(regionselector);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); sender.sendMessage(PluginMessages.customPrefix
+ " You have been given a \u00A7ePortal Region Selector\u00A7a!");
break; break;
case "portalblock": case "portalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. // TODO change this to a purple wool block and give it a name with a color. Then
// Also do this for other blocks such as gateways and end portals just in case they want it. // 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 Wool(DyeColor.PURPLE).toItemStack(1); ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1);
ItemMeta blockName = portalBlock.getItemMeta(); ItemMeta blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A75Portal Block Placer"); blockName.setDisplayName("\u00A75Portal Block Placer");
blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block", "\u00A7rRight Click: Place portal block", "\u00A7rLeft Click: Rotate portal block"));
"\u00A7rLeft Click: Rotate portal block"));
portalBlock.setItemMeta(blockName); portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock); inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); sender.sendMessage(
PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
break; break;
case "endportalblock": case "endportalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. // TODO change this to a purple wool block and give it a name with a color. Then
// Also do this for other blocks such as gateways and end portals just in case they want it. // 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); portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta(); blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78End Portal Block Placer"); blockName.setDisplayName("\u00A78End Portal Block Placer");
@ -121,11 +130,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
"\u00A7rRight Click: Place portal block")); "\u00A7rRight Click: Place portal block"));
portalBlock.setItemMeta(blockName); portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock); inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); sender.sendMessage(
PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
break; break;
case "gatewayblock": case "gatewayblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. // TODO change this to a purple wool block and give it a name with a color. Then
// Also do this for other blocks such as gateways and end portals just in case they want it. // 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); portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta(); blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78Gateway Block Placer"); blockName.setDisplayName("\u00A78Gateway Block Placer");
@ -134,13 +146,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
portalBlock.setItemMeta(blockName); portalBlock.setItemMeta(blockName);
inventory.addItem(portalBlock); inventory.addItem(portalBlock);
sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); sender.sendMessage(
PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!");
break; break;
case "create": case "create":
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) if (player.getMetadata("Pos1World").get(0).asString()
&& player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { .equals(player.getMetadata("Pos2World").get(0).asString())
if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something && 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
// TODO change system to use arrays and hashmaps // TODO change system to use arrays and hashmaps
boolean hasName = false; boolean hasName = false;
boolean hasTriggerBlock = false; boolean hasTriggerBlock = false;
@ -148,23 +164,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean isBungeePortal = false; boolean isBungeePortal = false;
boolean needsPermission = false; boolean needsPermission = false;
boolean executesCommand = false; boolean executesCommand = false;
boolean hasCooldownDelay = false;
String destination = null; String destination = null;
String portalName = null; String portalName = null;
String triggerBlock = null; String triggerBlock = null;
String serverName = null; String serverName = null;
String permission = null; String permission = null;
String portalCommand = null; String portalCommand = null;
String cooldownDelay = null;
ArrayList<PortalArg> extraData = new ArrayList<>(); ArrayList<PortalArg> extraData = new ArrayList<>();
// Is completely changed in the recode but for now im leaving it as this horrible mess... // Is completely changed in the recode but for now im leaving it as this
// horrible mess...
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
if (startsWithPortalArg("name:", args[i])) { if (startsWithPortalArg("name:", args[i])) {
portalName = args[i].replaceFirst("name:", ""); portalName = args[i].replaceFirst("name:", "");
if(portalName.equals("")) { if (portalName.equals("")) {
player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that isnt nothing!"); player.sendMessage(PluginMessages.customPrefixFail
+ " You must include a name for the portal that isnt nothing!");
return true; return true;
} }
hasName = true; hasName = true;
@ -189,55 +205,74 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
permission = args[i].toLowerCase().replaceFirst("permission:", ""); permission = args[i].toLowerCase().replaceFirst("permission:", "");
extraData.add(new PortalArg("permission", permission)); extraData.add(new PortalArg("permission", permission));
} else if (startsWithPortalArg("delayed:", args[i])) { } else if (startsWithPortalArg("delayed:", args[i])) {
boolean delayed = Boolean.parseBoolean(args[i].toLowerCase().replaceFirst("delayed:", "")); boolean delayed = Boolean
.parseBoolean(args[i].toLowerCase().replaceFirst("delayed:", ""));
extraData.add(new PortalArg("delayed", Boolean.toString(delayed))); extraData.add(new PortalArg("delayed", Boolean.toString(delayed)));
} else if(startsWithPortalArg("message:", args[i])) { } else if (startsWithPortalArg("message:", args[i])) {
String message = parseArgVariable(args, i, "message:"); String message = parseArgVariable(args, i, "message:");
if(message == null) { if (message == null) {
player.sendMessage(PluginMessages.customPrefixFail + " Message quotes not closed!"); player.sendMessage(
PluginMessages.customPrefixFail + " Message quotes not closed!");
return true; return true;
} }
extraData.add(new PortalArg("message", message )); extraData.add(new PortalArg("message", message));
} else if (startsWithPortalArg("command:", args[i])) { } else if (startsWithPortalArg("command:", args[i])) {
executesCommand = true; executesCommand = true;
portalCommand = parseArgVariable(args, i, "command:"); portalCommand = parseArgVariable(args, i, "command:");
if(portalCommand == null) { if (portalCommand == null) {
player.sendMessage(PluginMessages.customPrefixFail + " Command quotes not closed!"); player.sendMessage(
PluginMessages.customPrefixFail + " Command quotes not closed!");
return true; return true;
} }
i += this.portalArgsStringLength - 1; i += this.portalArgsStringLength - 1;
if(portalCommand.startsWith("#") && !(this.plugin.getSettings().hasCommandLevel("c") if (portalCommand.startsWith("#")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.console")) && !(this.plugin.getSettings().hasCommandLevel("c")
|| (this.plugin.getSettings().hasCommandLevel("k") && sender.isOp()))) { && (sender.hasPermission(
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a console command portal!"); "advancedportals.createportal.commandlevel.console"))
|| (this.plugin.getSettings().hasCommandLevel("k")
&& sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You need permission to make a console command portal!");
return true; return true;
} } else if (portalCommand.startsWith("!")
else if(portalCommand.startsWith("!") && !(this.plugin.getSettings().hasCommandLevel("o") && !(this.plugin.getSettings().hasCommandLevel("o")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.op")) && (sender.hasPermission(
|| (this.plugin.getSettings().hasCommandLevel("p") && sender.isOp()))) { "advancedportals.createportal.commandlevel.op"))
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a op command portal!"); || (this.plugin.getSettings().hasCommandLevel("p")
&& sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You need permission to make a op command portal!");
return true; return true;
} } else if (portalCommand.startsWith("^")
else if(portalCommand.startsWith("^") && !(this.plugin.getSettings().hasCommandLevel("p") && !(this.plugin.getSettings().hasCommandLevel("p")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.perms")) && (sender.hasPermission(
|| (this.plugin.getSettings().hasCommandLevel("e") && sender.isOp()))) { "advancedportals.createportal.commandlevel.perms"))
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a all perms command portal!"); || (this.plugin.getSettings().hasCommandLevel("e")
&& sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You need permission to make a all perms command portal!");
return true; return true;
} }
extraData.add(new PortalArg("command.1", portalCommand)); extraData.add(new PortalArg("command.1", portalCommand));
} else if (startsWithPortalArg("cooldowndelay:", args[i])) { } else if (startsWithPortalArg("cooldowndelay:", args[i])) {
hasCooldownDelay = true; String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:");
cooldownDelay = args[i].toLowerCase().replaceFirst("cooldowndelay:", ""); extraData.add(new PortalArg("cooldowndelay", cooldownDelay));
} }
} }
if (!hasName) { if (!hasName) {
player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that you are creating in the variables!"); player.sendMessage(PluginMessages.customPrefixFail
+ " You must include a name for the portal that you are creating in the variables!");
return true; return true;
} }
World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString()); World world = org.bukkit.Bukkit
Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt()); .getWorld(player.getMetadata("Pos1World").get(0).asString());
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt()); Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(),
player.getMetadata("Pos1Y").get(0).asInt(),
player.getMetadata("Pos1Z").get(0).asInt());
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(),
player.getMetadata("Pos2Y").get(0).asInt(),
player.getMetadata("Pos2Z").get(0).asInt());
ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml");
String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X");
@ -245,19 +280,21 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (!Portal.portalExists(portalName)) { if (!Portal.portalExists(portalName)) {
player.sendMessage(""); player.sendMessage("");
player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); player.sendMessage(PluginMessages.customPrefix
+ "\u00A7e You have created a new portal with the following details:");
player.sendMessage("\u00A7aname: \u00A7e" + portalName); player.sendMessage("\u00A7aname: \u00A7e" + portalName);
if (hasDestination) { if (hasDestination) {
if (!isBungeePortal && destiPosX == null) { if (!isBungeePortal && destiPosX == null) {
player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); player.sendMessage("\u00A7cdestination: \u00A7e" + destination
+ " (destination does not exist)");
return true; return true;
} } else {
else{
player.sendMessage("\u00A7adestination: \u00A7e" + destination); player.sendMessage("\u00A7adestination: \u00A7e" + destination);
} }
} else { } else {
player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); player.sendMessage(
"\u00A7cdestination: \u00A7eN/A (will not teleport to a location)");
} }
if (isBungeePortal) { if (isBungeePortal) {
@ -270,9 +307,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); player.sendMessage("\u00A7apermission: \u00A7e(none needed)");
} }
for(PortalArg portalArg : extraData) { for (PortalArg portalArg : extraData) {
if(!ignoreExtras.contains(portalArg.argName)) { if (!ignoreExtras.contains(portalArg.argName)) {
player.sendMessage("\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value); player.sendMessage(
"\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value);
} }
} }
@ -280,58 +318,62 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand);
} }
int cooldown = 0;
if(hasCooldownDelay) {
try {
cooldown = Integer.parseInt(cooldownDelay);
} catch (Exception e) {
}
}
player.sendMessage("\u00A7acooldowndelay: \u00A7e" + cooldown);
if (hasTriggerBlock) { if (hasTriggerBlock) {
Set<Material> materialSet = Portal.getMaterialSet(triggerBlock.toUpperCase().split(",")); Set<Material> materialSet = Portal
.getMaterialSet(triggerBlock.toUpperCase().split(","));
if (materialSet.size() != 0) { if (materialSet.size() != 0) {
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); player.sendMessage(
"\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs); portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, materialSet, serverName, cooldown, portalArgs)); player.sendMessage(Portal.create(pos1, pos2, portalName, destination,
materialSet, serverName, portalArgs));
} else { } else {
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault("
+ Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
player.sendMessage("\u00A7c" + triggerBlock.toUpperCase() + " no valid blocks were listed so the default has been set."); player.sendMessage("\u00A7c" + triggerBlock.toUpperCase()
+ " no valid blocks were listed so the default has been set.");
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs); portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, cooldown, portalArgs)); player.sendMessage(Portal.create(pos1, pos2, portalName, destination,
serverName, portalArgs));
} }
} else { } else {
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); player.sendMessage("\u00A7atriggerBlock: \u00A7edefault("
+ Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs); portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, cooldown, portalArgs)); player.sendMessage(Portal.create(pos1, pos2, portalName, destination,
serverName, portalArgs));
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " A portal by that name already exists!"); sender.sendMessage(
PluginMessages.customPrefixFail + " A portal by that name already exists!");
} }
// add code to save the portal to the portal config and reload the portals // add code to save the portal to the portal config and reload the portals
player.sendMessage(""); player.sendMessage("");
} else { } else {
player.sendMessage(PluginMessages.customPrefixFail + " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" player.sendMessage(PluginMessages.customPrefixFail
+ " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c"
+ " for a full list of currently available variables and an example command!"); + " for a full list of currently available variables and an example command!");
} }
} else { } else {
player.sendMessage(PluginMessages.customPrefixFail + " The points you have selected need to be in the same world!"); player.sendMessage(PluginMessages.customPrefixFail
+ " The points you have selected need to be in the same world!");
} }
} else { } else {
player.sendMessage(PluginMessages.customPrefixFail + " You need to have two points selected to make a portal!"); player.sendMessage(PluginMessages.customPrefixFail
+ " You need to have two points selected to make a portal!");
} }
break; break;
case "variables" : case "variables":
sender.sendMessage(PluginMessages.customPrefix + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay"); sender.sendMessage(PluginMessages.customPrefix
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay");
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
break; break;
@ -341,12 +383,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (args.length > 1) { if (args.length > 1) {
if (Portal.portalExists(args[1])) { if (Portal.portalExists(args[1])) {
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1] + "\u00A7a."); player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1]
+ "\u00A7a.");
} else { } else {
player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e"
+ args[1]
+ "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!");
} }
} else { } else {
player.sendMessage(PluginMessages.customPrefix + " Hit a block inside the portal region to select the portal!"); player.sendMessage(PluginMessages.customPrefix
+ " Hit a block inside the portal region to select the portal!");
player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true));
} }
@ -356,23 +402,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
break; break;
case "unselect": case "unselect":
if(player.getMetadata("selectedPortal").size() != 0){ if (player.getMetadata("selectedPortal").size() != 0) {
player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + player.getMetadata("selectedPortal").get(0).asString() player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e"
+ "\u00A7a."); + player.getMetadata("selectedPortal").get(0).asString() + "\u00A7a.");
} } else {
else{
player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!");
} }
case "gui" : case "gui":
if (args.length > 1) { if (args.length > 1) {
if (args[1].toLowerCase().equals("remove") && args.length > 2) { if (args[1].toLowerCase().equals("remove") && args.length > 2) {
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); sender.sendMessage(PluginMessages.customPrefixFail
+ " Are you sure you would like to remove the portal \u00A7e" + args[2]
+ "\u00A7c?");
sender.sendMessage(""); sender.sendMessage("");
plugin.compat.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\"," + plugin.compat.sendRawMessage(
"\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + "{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\","
"{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}" + + "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove "
",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); + args[2] + "\"}}, "
+ "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}"
+ ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit "
+ args[2] + "\"}}]}",
player);
sender.sendMessage(""); sender.sendMessage("");
} }
} }
@ -383,7 +434,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
portalEditMenu(sender, portalConfig, args[1]); portalEditMenu(sender, portalConfig, args[1]);
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e"
+ args[1] + "\u00A7c exists!");
} }
} else { } else {
if (player.getMetadata("selectedPortal").size() != 0) { if (player.getMetadata("selectedPortal").size() != 0) {
@ -392,11 +444,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (posX != null) { if (posX != null) {
portalEditMenu(sender, portalConfig, portalName); portalEditMenu(sender, portalConfig, portalName);
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin); player.removeMetadata("selectedPortal", plugin);
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
} }
} }
break; break;
@ -412,22 +466,29 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if (posX != null && newPortalPosX == null) { if (posX != null && newPortalPosX == null) {
Portal.rename(portalName, args[1]); Portal.rename(portalName, args[1]);
sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName
+ "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a.");
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
} else if (newPortalPosX != null) { } else if (newPortalPosX != null) {
sender.sendMessage(PluginMessages.customPrefixFail + " There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " There is already a portal with the name \u00A7e" + args[1]
+ "\u00A7c!");
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin); player.removeMetadata("selectedPortal", plugin);
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " The portal you have selected is already called that!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " The portal you have selected is already called that!");
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!");
} }
break; break;
case "command": case "command":
@ -442,23 +503,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
portalCommand += args[i]; portalCommand += args[i];
} }
if (Portal.addCommand(portalName, portalCommand)) { if (Portal.addCommand(portalName, portalCommand)) {
sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!"); sender.sendMessage(
PluginMessages.customPrefixFail + " Command added to portal!");
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!"); sender.sendMessage(
PluginMessages.customPrefixFail + " Failed to add command to portal!");
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " You must actually specify a command to execute!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " You must actually specify a command to execute!");
} }
} else if (args[1].toLowerCase().equals("remove")) { } else if (args[1].toLowerCase().equals("remove")) {
// Specify what line to remove // Specify what line to remove
} else if (args[1].toLowerCase().equals("show")) { } else if (args[1].toLowerCase().equals("show")) {
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!");
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!");
} }
} else { } else {
@ -469,7 +535,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if (posX != null) { if (posX != null) {
Portal.remove(args[1]); Portal.remove(args[1]);
sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1]
+ "\u00A7c has been removed!");
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!");
} }
@ -479,13 +546,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
if (posX != null) { if (posX != null) {
Portal.remove(portalName); Portal.remove(portalName);
sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + "\u00A7c has been removed!"); sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName
+ "\u00A7c has been removed!");
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); sender.sendMessage(PluginMessages.customPrefixFail
+ " The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin); player.removeMetadata("selectedPortal", plugin);
} }
} else { } else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
} }
} }
break; break;
@ -502,12 +572,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
} else { } else {
if (player.getMetadata("selectedPortal").size() != 0) { if (player.getMetadata("selectedPortal").size() != 0) {
player.sendMessage(PluginMessages.customPrefix + " Your currently selected portal has been shown, it will dissapear shortly!"); player.sendMessage(PluginMessages.customPrefix
+ " Your currently selected portal has been shown, it will dissapear shortly!");
Selection.show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString()); Selection.show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString());
} else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { } else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) if (player.getMetadata("Pos1World").get(0).asString()
&& player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { .equals(player.getMetadata("Pos2World").get(0).asString())
player.sendMessage(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); && player.getMetadata("Pos1World").get(0).asString()
.equals(player.getLocation().getWorld().getName())) {
player.sendMessage(PluginMessages.customPrefix
+ " Your currently selected area has been shown, it will dissapear shortly!");
Selection.show(player, this.plugin, null); Selection.show(player, this.plugin, null);
} }
} else { } else {
@ -520,7 +594,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Listeners.reloadValues(plugin); Listeners.reloadValues(plugin);
Portal.loadPortals(); Portal.loadPortals();
break; break;
case "list" : case "list":
String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a";
LinkedList<String> portals = new LinkedList<>(); LinkedList<String> portals = new LinkedList<>();
for (AdvancedPortal portal : Portal.portals) { for (AdvancedPortal portal : Portal.portals) {
@ -534,7 +608,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
break; break;
default: default:
PluginMessages.UnknownCommand(sender, command); PluginMessages.UnknownCommand(sender, command);
} }
} else { } else {
PluginMessages.UnknownCommand(sender, command); PluginMessages.UnknownCommand(sender, command);
} }
@ -551,9 +625,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private void helpCommand(CommandSender sender, String command, String[] args) { private void helpCommand(CommandSender sender, String command, String[] args) {
// Add pages if there starts to become too many // Add pages if there starts to become too many
if(args.length == 1) { if (args.length == 1) {
sendMenu(sender, "Help Menu", sendMenu(sender, "Help Menu", "\u00A76/" + command + " selector \u00A7a- gives you a region selector",
"\u00A76/" + command + " selector \u00A7a- gives you a region selector",
"\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection ", "\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection ",
"\u00A76/" + command + " portalblock \u00A7a- gives you a portal block", "\u00A76/" + command + " portalblock \u00A7a- gives you a portal block",
"\u00A76/" + command + " endportalblock \u00A7a- gives you an end portal block", "\u00A76/" + command + " endportalblock \u00A7a- gives you an end portal block",
@ -567,34 +640,24 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
"\u00A76/" + command + " list \u00A7a- lists all the current portals", "\u00A76/" + command + " list \u00A7a- lists all the current portals",
"\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name", "\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name",
"\u00A76/" + command + " variables \u00A7a- lists all available tags"); "\u00A76/" + command + " variables \u00A7a- lists all available tags");
} } else if (args.length > 1) {
else if(args.length > 1){ if (args[1].toLowerCase().equals("help")) {
if(args[1].toLowerCase().equals("help")) {
sendMenu(sender, "Help Command", sendMenu(sender, "Help Command",
"Shows the help section. You can also use a single argument after it to show the " + "Shows the help section. You can also use a single argument after it to show the "
"help section for the corresponding command."); + "help section for the corresponding command.");
} } else if (args[1].toLowerCase().equals("portalblock")) {
else if(args[1].toLowerCase().equals("portalblock")) { sendMenu(sender, "Help Command", "Gives you a special wool block to place portal blocks.", "",
sendMenu(sender, "Help Command",
"Gives you a special wool block to place portal blocks.",
"",
"\u00A7eLeft Click: \u00A76Rotates the hit portal block", "\u00A7eLeft Click: \u00A76Rotates the hit portal block",
"\u00A7eRight Click: \u00A76Placed a portal block"); "\u00A7eRight Click: \u00A76Placed a portal block");
} } else if (args[1].toLowerCase().equals("endportalblock")) {
else if(args[1].toLowerCase().equals("endportalblock")) { sendMenu(sender, "Help Command", "Gives you a special wool block to place end portal blocks.", "",
sendMenu(sender, "Help Command",
"Gives you a special wool block to place end portal blocks.",
"",
"\u00A7eRight Click: \u00A76Placed a end portal block"); "\u00A7eRight Click: \u00A76Placed a end portal block");
} } else if (args[1].toLowerCase().equals("gatewayblock")) {
else if(args[1].toLowerCase().equals("gatewayblock")) { sendMenu(sender, "Help Command", "Gives you a special wool block to place gateway blocks.", "",
sendMenu(sender, "Help Command",
"Gives you a special wool block to place gateway blocks.",
"",
"\u00A7eRight Click: \u00A76Placed a gateway block"); "\u00A7eRight Click: \u00A76Placed a gateway block");
} } else {
else{ sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1]
sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1] + "\u00A7a is not a command or a help page has not been added yet."); + "\u00A7a is not a command or a help page has not been added yet.");
} }
} }
} }
@ -602,7 +665,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private void sendMenu(CommandSender sender, String title, String... lines) { private void sendMenu(CommandSender sender, String title, String... lines) {
sender.sendMessage(PluginMessages.customPrefix + " " + title); sender.sendMessage(PluginMessages.customPrefix + " " + title);
sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); sender.sendMessage("\u00A7e\u00A7m-----------------------------------");
for(String line : lines){ for (String line : lines) {
sender.sendMessage("\u00A7a" + line); sender.sendMessage("\u00A7a" + line);
} }
sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); sender.sendMessage("\u00A7e\u00A7m-----------------------------------");
@ -616,7 +679,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (variableString.length() == 0 || variableString.charAt(variableString.length() - 1) != '"') { if (variableString.length() == 0 || variableString.charAt(variableString.length() - 1) != '"') {
currentArg++; currentArg++;
for (; currentArg <= args.length; currentArg++) { for (; currentArg <= args.length; currentArg++) {
if(currentArg == args.length) { if (currentArg == args.length) {
return null; return null;
} }
variableString += " " + args[currentArg]; variableString += " " + args[currentArg];
@ -635,19 +698,24 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
private void portalEditMenu(CommandSender sender, ConfigAccessor portalConfig, String portalName) { private void portalEditMenu(CommandSender sender, ConfigAccessor portalConfig, String portalName) {
// make the text gui with the json message for a list of edit commands to be clicked or hovered // make the text gui with the json message for a list of edit commands to be
// clicked or hovered
// put \" for a " in the json messages // put \" for a " in the json messages
// sadly there is no newline code so these three lines will have to be copied and pasted for each line // sadly there is no newline code so these three lines will have to be copied
// and pasted for each line
// use the usual messages for normal lines but anything that needs special features make sure you use the // use the usual messages for normal lines but anything that needs special
// chat steriliser // features make sure you use the
// chat steriliser
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(PluginMessages.customPrefix + " Editing: \u00A7e" + portalName); sender.sendMessage(PluginMessages.customPrefix + " Editing: \u00A7e" + portalName);
sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + ", "
+ ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z")); + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", "
sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + portalConfig.getConfig().getString(portalName + ".pos1.Z"));
+ ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z")); sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + ", "
+ portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", "
+ portalConfig.getConfig().getString(portalName + ".pos2.Z"));
String destination = portalConfig.getConfig().getString(portalName + ".destination"); String destination = portalConfig.getConfig().getString(portalName + ".destination");
if (destination != null) { if (destination != null) {
@ -666,7 +734,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) { if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) {
int commands = 0; int commands = 0;
String command = portalConfig.getConfig().getString(portalName + ".portalArgs.command.1"); String command = portalConfig.getConfig().getString(portalName + ".portalArgs.command.1");
// TODO possibly change code so it counds number of subvalues rather than a loop. // TODO possibly change code so it counds number of subvalues rather than a
// loop.
while (command != null) { while (command != null) {
command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands); command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands);
} }
@ -682,11 +751,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Player player = (Player) sender; Player player = (Player) sender;
plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \"," + plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \","
"\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove " + portalName + "\"}}" + "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove "
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal show " + portalName + "\"}}" + portalName + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal show "
+ portalName + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp " + destination + "\"}}]}", player); + ",{\"text\":\" \"},{\"text\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp "
+ destination + "\"}}]}", player);
sender.sendMessage(""); sender.sendMessage("");
@ -697,8 +769,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
LinkedList<String> autoComplete = new LinkedList<String>(); LinkedList<String> autoComplete = new LinkedList<String>();
if (sender.hasPermission("advancedportals.createportal")) { if (sender.hasPermission("advancedportals.createportal")) {
if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) { if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) {
autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command", "selector" autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command",
, "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage", "warp")); "selector", "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename",
"help", "bukkitpage", "helppage", "warp"));
} else if (args[0].toLowerCase().equals("create")) { } else if (args[0].toLowerCase().equals("create")) {
boolean hasName = false; boolean hasName = false;
@ -710,40 +783,40 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasCommand = false; boolean hasCommand = false;
boolean hasCooldownDelay = false; boolean hasCooldownDelay = false;
// TODO change auto complete when quotes are opened and closed. Such as
// TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands // autocomplete @Player and stuff when specifying commands
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String argTag = getTag(args[i].toLowerCase()); String argTag = getTag(args[i].toLowerCase());
if (argTag.length() + 1 < args[i].length()) { if (argTag.length() + 1 < args[i].length()) {
switch (argTag) { switch (argTag) {
case "name": case "name":
hasName = true; hasName = true;
break; break;
case "destination": case "destination":
hasDestination = true; hasDestination = true;
break; break;
case "desti": case "desti":
hasDestination = true; hasDestination = true;
break; break;
case "triggerblock": case "triggerblock":
hasTriggerBlock = true; hasTriggerBlock = true;
break; break;
case "bungee": case "bungee":
isBungeePortal = true; isBungeePortal = true;
break; break;
case "permission": case "permission":
needsPermission = true; needsPermission = true;
break; break;
case "delayed": case "delayed":
hasDelay = true; hasDelay = true;
break; break;
case "command": case "command":
hasCommand = true; hasCommand = true;
break; break;
case "cooldowndelay": case "cooldowndelay":
hasCooldownDelay = true; hasCooldownDelay = true;
break; break;
} }
} }
@ -776,32 +849,32 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
} }
} }
if (args.length == 2 && args[0].equalsIgnoreCase("warp")){ if (args.length == 2 && args[0].equalsIgnoreCase("warp")) {
for (AdvancedPortal portal :Portal.portals){ for (AdvancedPortal portal : Portal.portals) {
String perm = portal.getArg("permission"); String perm = portal.getArg("permission");
if (perm == null || sender.hasPermission(perm)){ if (perm == null || sender.hasPermission(perm)) {
autoComplete.add(portal.getName()); autoComplete.add(portal.getName());
} }
} }
} }
String triggerBlock = "triggerblock:"; String triggerBlock = "triggerblock:";
if(args[args.length-1].toLowerCase().startsWith(triggerBlock)) { if (args[args.length - 1].toLowerCase().startsWith(triggerBlock)) {
String currentArg = args[args.length-1]; String currentArg = args[args.length - 1];
int length = currentArg.lastIndexOf(','); int length = currentArg.lastIndexOf(',');
String startString; String startString;
if(triggerBlock.length() > length) { if (triggerBlock.length() > length) {
startString = triggerBlock; startString = triggerBlock;
} else {
startString = currentArg.substring(0, length + 1);
} }
else { autoComplete
startString = currentArg.substring(0, length+1); .addAll(blockMaterialList.stream().map(value -> startString + value).collect(Collectors.toList()));
}
autoComplete.addAll(blockMaterialList.stream().map(value -> startString + value).collect(Collectors.toList()));
} }
if(args[args.length-1].startsWith("delayed:")) { if (args[args.length - 1].startsWith("delayed:")) {
autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false")); autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false"));
} }
if(args[args.length-1].startsWith("desti:") || args[args.length-1].startsWith("destination:")) { if (args[args.length - 1].startsWith("desti:") || args[args.length - 1].startsWith("destination:")) {
String tagStart = args[args.length-1].startsWith("desti:") ? "desti:" : "destination:"; String tagStart = args[args.length - 1].startsWith("desti:") ? "desti:" : "destination:";
ConfigAccessor destiConfig = new ConfigAccessor(plugin, "destinations.yml"); ConfigAccessor destiConfig = new ConfigAccessor(plugin, "destinations.yml");
List<Object> destiObj = Arrays.asList(destiConfig.getConfig().getKeys(false).toArray()); List<Object> destiObj = Arrays.asList(destiConfig.getConfig().getKeys(false).toArray());
for (Object object : destiObj) { for (Object object : destiObj) {

View File

@ -22,6 +22,7 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class Listeners implements Listener { public class Listeners implements Listener {
@ -40,14 +41,12 @@ public class Listeners implements Listener {
String ItemID = config.getConfig().getString("AxeItemId"); String ItemID = config.getConfig().getString("AxeItemId");
if(ItemID == null){ if (ItemID == null) {
WandMaterial = Material.IRON_AXE; WandMaterial = Material.IRON_AXE;
} } else {
else{
WandMaterial = Material.getMaterial(ItemID); WandMaterial = Material.getMaterial(ItemID);
} }
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
@ -62,45 +61,29 @@ public class Listeners implements Listener {
WandMaterial = Material.getMaterial(ItemID); WandMaterial = Material.getMaterial(ItemID);
} }
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
// TODO: make relability
// Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
/* if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) {
String desti = plugin.PlayerDestiMap.get(event.getPlayer());
Destination.warp(event.getPlayer(), desti);
} */
}
@EventHandler
public void onWorldChangeEvent(PlayerChangedWorldEvent event) {
// TODO: make relability
// Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
@EventHandler(ignoreCancelled = true)
public void onTeleportEvent(PlayerTeleportEvent event) {
// TODO: make relability
// Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void spawnMobEvent(CreatureSpawnEvent event) { public void spawnMobEvent(CreatureSpawnEvent event) {
if(event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL && Portal.inPortalRegion(event.getLocation(), Portal.getPortalProtectionRadius())) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL
&& Portal.inPortalRegion(event.getLocation(), Portal.getPortalProtectionRadius())) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler
public void onLeaveEvent(PlayerQuitEvent event) { public void onWorldChangeEvent(PlayerChangedWorldEvent event) {
Portal.cooldown.remove(event.getPlayer().getName()); Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
UUID uuid = event.getPlayer().getUniqueId(); @EventHandler
for (AdvancedPortal portal : Portal.portals) { public void onJoinEvent(PlayerJoinEvent event) {
portal.inPortal.remove(uuid); Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
/*
* if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) { String desti =
* plugin.PlayerDestiMap.get(event.getPlayer());
*
* Destination.warp(event.getPlayer(), desti); }
*/
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -124,7 +107,8 @@ public class Listeners implements Listener {
boolean delayed = portal.hasArg("delayed") && portal.getArg("delayed").equalsIgnoreCase("true"); boolean delayed = portal.hasArg("delayed") && portal.getArg("delayed").equalsIgnoreCase("true");
for (Location loc : locations) { for (Location loc : locations) {
if (delayed == useDelayed) { if (delayed == useDelayed) {
if (delayed ? Portal.locationInPortal(portal, loc, 1) : Portal.locationInPortalTrigger(portal, loc)) { if (delayed ? Portal.locationInPortal(portal, loc, 1)
: Portal.locationInPortalTrigger(portal, loc)) {
if (portal.getTriggers().contains(Material.NETHER_PORTAL)) { if (portal.getTriggers().contains(Material.NETHER_PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) { if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
@ -135,26 +119,30 @@ public class Listeners implements Listener {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
} }
if (portal.inPortal.contains(player.getUniqueId())) return; if (portal.inPortal.contains(player.getUniqueId()))
return;
WarpEvent warpEvent = new WarpEvent(player, portal); WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent); plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!warpEvent.isCancelled()) Portal.activate(player, portal); if (!warpEvent.isCancelled())
Portal.activate(player, portal);
if (!delayed) portal.inPortal.add(player.getUniqueId()); if (!delayed)
portal.inPortal.add(player.getUniqueId());
return; return;
} else if (!delayed) portal.inPortal.remove(player.getUniqueId()); } else if (!delayed)
portal.inPortal.remove(player.getUniqueId());
} }
} }
} }
} }
// 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 {
private Player player; private Player player;
public RemoveLavaData(Player player){ public RemoveLavaData(Player player) {
this.player = player; this.player = player;
} }
@ -165,12 +153,11 @@ public class Listeners implements Listener {
} }
}; };
class RemoveWarpData implements Runnable{ class RemoveWarpData implements Runnable {
private Player player; private Player player;
public RemoveWarpData(Player player){ public RemoveWarpData(Player player) {
this.player = player; this.player = player;
} }
@ -188,11 +175,13 @@ public class Listeners implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onDamEvent(EntityDamageEvent event) { public void onDamEvent(EntityDamageEvent event) {
if (event.getEntity() instanceof Player && (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) { if (event.getEntity() instanceof Player && (event.getCause() == EntityDamageEvent.DamageCause.LAVA
if (event.getEntity().hasMetadata("lavaWarped") | Portal.inPortalTriggerRegion(event.getEntity().getLocation())) || event.getCause() == EntityDamageEvent.DamageCause.FIRE
|| event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) {
if (event.getEntity().hasMetadata("lavaWarped")
| Portal.inPortalTriggerRegion(event.getEntity().getLocation()))
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -211,28 +200,37 @@ public class Listeners implements Listener {
checkTriggerLocations(player, true, loc, eyeLoc); checkTriggerLocations(player, true, loc, eyeLoc);
} }
if (player.hasMetadata("hasWarped") | Portal.inPortalRegion(event.getFrom(),1)) if (player.hasMetadata("hasWarped") | Portal.inPortalRegion(event.getFrom(), 1))
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onItemInteract(PlayerInteractEvent event) { public void onItemInteract(PlayerInteractEvent event) {
// will detect if the player is using an axe so the points of a portal can be set // 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 // also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { if (player.hasMetadata("selectingPortal")
&& (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
for (AdvancedPortal portal : Portal.portals) { for (AdvancedPortal portal : Portal.portals) {
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) { if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7a You have selected: \u00A7e" + portal.getName()); player.sendMessage(
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.getName())); // adds the name to the metadata of the character PluginMessages.customPrefix + "\u00A7a You have selected: \u00A7e" + portal.getName());
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.getName())); // adds the
// name to
// the
// metadata
// of the
// character
event.setCancelled(true); event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin); player.removeMetadata("selectingPortal", plugin);
return; return;
} }
} }
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); player.sendMessage(PluginMessages.customPrefixFail
+ "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -240,45 +238,54 @@ public class Listeners implements Listener {
if (player.hasPermission("advancedportals.createportal")) { if (player.hasPermission("advancedportals.createportal")) {
if (event.getItem() != null && event.getItem().getType() == WandMaterial // was type id if (event.getItem() != null && event.getItem().getType() == WandMaterial // was type id
&& (!UseOnlyServerAxe || (checkItemForName(event.getItem()) && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) { && (!UseOnlyServerAxe || (checkItemForName(event.getItem()) && event.getItem().getItemMeta()
.getDisplayName().equals("\u00A7ePortal Region Selector")))) {
// This checks if the action was a left or right click and if it was directly effecting a block. // 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) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation(); 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 // stores the selection as metadata on the character so then it isn't saved
// have to be selected again if the player joins, also it does not affect any other players. // 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("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() player.sendMessage(
+ " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); "\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 // Stops the event so the block is not damaged
event.setCancelled(true); event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed) // Returns the event so no more code is executed(stops unnecessary code being
// executed)
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation(); Location blockloc = event.getClickedBlock().getLocation();
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() player.sendMessage(
+ " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); "\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 // Stops the event so the block is not interacted with
event.setCancelled(true); event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed) // Returns the event so no more code is executed(stops unnecessary code being
// executed)
} }
} else if (checkItemForName(event.getItem()) && event.getItem().getItemMeta().getDisplayName().equals("\u00A75Portal Block Placer") && } else if (checkItemForName(event.getItem())
event.getAction() == Action.LEFT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.NETHER_PORTAL) { && event.getItem().getItemMeta().getDisplayName().equals("\u00A75Portal Block Placer")
&& event.getAction() == Action.LEFT_CLICK_BLOCK
&& event.getClickedBlock().getType() == Material.NETHER_PORTAL) {
BlockData block = event.getClickedBlock().getBlockData(); BlockData block = event.getClickedBlock().getBlockData();
if (block instanceof Orientable) {
if(block instanceof Orientable) {
Orientable rotatable = (Orientable) block; Orientable rotatable = (Orientable) block;
if (rotatable.getAxis() == Axis.X) { if (rotatable.getAxis() == Axis.X) {
rotatable.setAxis(Axis.Z); rotatable.setAxis(Axis.Z);
@ -293,9 +300,8 @@ public class Listeners implements Listener {
} }
private boolean checkItemForName(ItemStack item){ private boolean checkItemForName(ItemStack item) {
return item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName(); return item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName();
} }
} }

View File

@ -21,8 +21,6 @@ public class AdvancedPortal {
private String portalName = null; private String portalName = null;
private int cooldownDelay = 0;
// TODO store destinations also as variables like portals // TODO store destinations also as variables like portals
private String destiation = null; // Could possibly store the destination name to stop the server having to read the config file private String destiation = null; // Could possibly store the destination name to stop the server having to read the config file
@ -35,32 +33,31 @@ public class AdvancedPortal {
public HashSet<UUID> inPortal = new HashSet<UUID>(); public HashSet<UUID> inPortal = new HashSet<UUID>();
// TODO think of relaying out the data input to a more logical format. // TODO think of relaying out the data input to a more logical format.
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, int cooldown, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), cooldown, portalArgs); this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination; this.destiation = destination;
} }
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, int cooldown, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), cooldown, portalArgs); this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
} }
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, int cooldown, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, worldName, cooldown, portalArgs); this(portalName, trigger, pos1, pos2, worldName, portalArgs);
this.destiation = destination; this.destiation = destination;
} }
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, int cooldown, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, new HashSet<>(Collections.singletonList(trigger)), pos1, pos2, worldName, cooldown, portalArgs); this(portalName, new HashSet<>(Collections.singletonList(trigger)), pos1, pos2, worldName, portalArgs);
} }
public AdvancedPortal(String portalName, Set<Material> triggers, Location pos1, Location pos2, String worldName, int cooldown, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Set<Material> triggers, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this.portalName = portalName; this.portalName = portalName;
this.triggers = triggers; this.triggers = triggers;
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
this.worldName = worldName; this.worldName = worldName;
this.portalArgs = portalArgs; this.portalArgs = portalArgs;
this.cooldownDelay = cooldown;
} }
public String getArg(String arg) { public String getArg(String arg) {
@ -100,14 +97,6 @@ public class AdvancedPortal {
return this.portalName; return this.portalName;
} }
public int getCooldownDelay() {
return this.cooldownDelay;
}
public void setCooldownDelay(int cooldownDelay) {
this.cooldownDelay = cooldownDelay;
}
public String getDestiation() { public String getDestiation() {
return this.destiation; return this.destiation;
} }

View File

@ -20,6 +20,7 @@ import java.util.stream.Collectors;
public class Portal { public class Portal {
public static HashMap<String, Long> joinCooldown = new HashMap<String, Long>();
public static HashMap<String, HashMap<String, Long>> cooldown = new HashMap<String, HashMap<String, Long>>(); public static HashMap<String, HashMap<String, Long>> cooldown = new HashMap<String, HashMap<String, Long>>();
// Config values // Config values
public static boolean portalsActive = false; public static boolean portalsActive = false;
@ -31,7 +32,7 @@ public class Portal {
private static Sound portalSound; private static Sound portalSound;
private static int portalProtectionRadius; private static int portalProtectionRadius;
private static boolean blockSpectatorMode; private static boolean blockSpectatorMode;
private static int joinCooldownDelay;
private static Random random = new Random(); private static Random random = new Random();
public Portal(AdvancedPortalsPlugin plugin) { public Portal(AdvancedPortalsPlugin plugin) {
@ -45,6 +46,8 @@ public class Portal {
this.portalSound = WarpEffects.findSound(plugin, "BLOCK_PORTAL_TRAVEL", "PORTAL_TRAVEL"); this.portalSound = WarpEffects.findSound(plugin, "BLOCK_PORTAL_TRAVEL", "PORTAL_TRAVEL");
this.blockSpectatorMode = config.getConfig().getBoolean("BlockSpectatorMode", false); this.blockSpectatorMode = config.getConfig().getBoolean("BlockSpectatorMode", false);
this.joinCooldownDelay = config.getConfig().getInt("PortalCooldown", 5);
Portal.plugin = plugin; Portal.plugin = plugin;
Portal.loadPortals(); Portal.loadPortals();
} }
@ -63,14 +66,16 @@ public class Portal {
if (PortalSet.size() > 0) { if (PortalSet.size() > 0) {
portals = new AdvancedPortal[PortalSet.toArray().length]; portals = new AdvancedPortal[PortalSet.toArray().length];
/*for(int i = 0; i <= PortalSet.toArray().length - 1; i++){ /*
portals[i] = new AdvancedPortal(); * for(int i = 0; i <= PortalSet.toArray().length - 1; i++){ portals[i] = new
}*/ * AdvancedPortal(); }
*/
int portalId = 0; int portalId = 0;
for (Object portal : PortalSet.toArray()) { for (Object portal : PortalSet.toArray()) {
ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString()); ConfigurationSection portalConfigSection = portalData.getConfig()
.getConfigurationSection(portal.toString());
String blockTypesRaw = portalConfigSection.getString("triggerblock"); String blockTypesRaw = portalConfigSection.getString("triggerblock");
@ -78,7 +83,7 @@ public class Portal {
HashSet<Material> blockTypes = getMaterialSet(blockTypesString); HashSet<Material> blockTypes = getMaterialSet(blockTypesString);
if(blockTypes.isEmpty()) { if (blockTypes.isEmpty()) {
blockTypes.add(Material.NETHER_PORTAL); blockTypes.add(Material.NETHER_PORTAL);
} }
@ -91,31 +96,34 @@ public class Portal {
for (Object argName : argsSet.toArray()) { for (Object argName : argsSet.toArray()) {
if (portalArgsConf.isString(argName.toString())) { if (portalArgsConf.isString(argName.toString())) {
extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString()))); extraData.add(
new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
} }
} }
} }
String worldName = portalData.getConfig().getString(portal.toString() + ".world"); String worldName = portalData.getConfig().getString(portal.toString() + ".world");
if(worldName != null) { if (worldName != null) {
World world = Bukkit.getWorld(worldName); World world = Bukkit.getWorld(worldName);
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z")); Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"),
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z")); portalData.getConfig().getInt(portal.toString() + ".pos1.Y"),
int cooldown = portalData.getConfig().getInt(portal.toString() + ".cooldowndelay"); portalData.getConfig().getInt(portal.toString() + ".pos1.Z"));
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"),
portalData.getConfig().getInt(portal.toString() + ".pos2.Y"),
portalData.getConfig().getInt(portal.toString() + ".pos2.Z"));
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs); extraData.toArray(portalArgs);
portals[portalId] = new AdvancedPortal(portal.toString(), blockTypes, pos1, pos2, worldName, cooldown, portalArgs); portals[portalId] = new AdvancedPortal(portal.toString(), blockTypes, pos1, pos2, worldName,
portalArgs);
portals[portalId].setBungee(portalConfigSection.getString("bungee")); portals[portalId].setBungee(portalConfigSection.getString("bungee"));
portals[portalId].setDestiation(portalConfigSection.getString("destination")); portals[portalId].setDestiation(portalConfigSection.getString("destination"));
portalId++; portalId++;
} } else {
else{
AdvancedPortal[] tempPortals = portals; AdvancedPortal[] tempPortals = portals;
portals = new AdvancedPortal[portals.length - 1]; portals = new AdvancedPortal[portals.length - 1];
@ -134,9 +142,9 @@ public class Portal {
HashSet<Material> blockTypes = new HashSet<>(); HashSet<Material> blockTypes = new HashSet<>();
if (blockTypesString != null) { if (blockTypesString != null) {
for(String blockType : blockTypesString) { for (String blockType : blockTypesString) {
Material material = Material.getMaterial(blockType); Material material = Material.getMaterial(blockType);
if(material != null) { if (material != null) {
blockTypes.add(material); blockTypes.add(material);
} }
} }
@ -145,11 +153,13 @@ public class Portal {
return blockTypes; return blockTypes;
} }
public static String create(Location pos1, Location pos2, String name, String destination, Set<Material> triggerBlocks, int cooldown, PortalArg... extraData) { public static String create(Location pos1, Location pos2, String name, String destination,
return create(pos1, pos2, name, destination, triggerBlocks, null, cooldown, extraData); Set<Material> triggerBlocks, PortalArg... extraData) {
return create(pos1, pos2, name, destination, triggerBlocks, null, extraData);
} }
public static String create(Location pos1, Location pos2, String name, String destination, Set<Material> triggerBlocks, String serverName, int cooldown, PortalArg... portalArgs) { public static String create(Location pos1, Location pos2, String name, String destination,
Set<Material> triggerBlocks, String serverName, PortalArg... portalArgs) {
if (!pos1.getWorld().equals(pos2.getWorld())) { if (!pos1.getWorld().equals(pos2.getWorld())) {
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
@ -189,10 +199,11 @@ public class Portal {
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ); Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ); Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
/*if (checkPortalOverlap(checkpos1, checkpos2)) { /*
plugin.getLogger().log(Level.WARNING, "portals must not overlap!"); * if (checkPortalOverlap(checkpos1, checkpos2)) {
return "\u00A7cPortal creation error, portals must not overlap!"; * plugin.getLogger().log(Level.WARNING, "portals must not overlap!"); return
}*/ * "\u00A7cPortal creation error, portals must not overlap!"; }
*/
portalData.getConfig().set(name + ".world", pos1.getWorld().getName()); portalData.getConfig().set(name + ".world", pos1.getWorld().getName());
@ -201,8 +212,6 @@ public class Portal {
portalData.getConfig().set(name + ".destination", destination); portalData.getConfig().set(name + ".destination", destination);
portalData.getConfig().set(name + ".cooldowndelay", cooldown);
portalData.getConfig().set(name + ".bungee", serverName); portalData.getConfig().set(name + ".bungee", serverName);
portalData.getConfig().set(name + ".pos1.X", HighX); portalData.getConfig().set(name + ".pos1.X", HighX);
@ -228,37 +237,49 @@ public class Portal {
if (portalsActive) { if (portalsActive) {
int portalId = 0; int portalId = 0;
for (@SuppressWarnings("unused") Object portal : Portal.portals) { for (@SuppressWarnings("unused")
if (portals[portalId].getWorldName().equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another Object portal : Portal.portals) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) { if (portals[portalId].getWorldName().equals(pos2.getWorld().getName())) { // checks that the cubes arnt
// overlapping by seeing if
// all 4 corners are not in
// side another
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
return true; return true;
} }
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) { if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
return true; return true;
} }
} }
@ -277,7 +298,8 @@ public class Portal {
return false; return false;
} }
public static String create(Location pos1, Location pos2, String name, String destination, String serverName, int cooldown, PortalArg... extraData) { // add stuff for destination names or coordinates public static String create(Location pos1, Location pos2, String name, String destination, String serverName,
PortalArg... extraData) { // add stuff for destination names or coordinates
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
Material triggerBlockType; Material triggerBlockType;
@ -288,7 +310,8 @@ public class Portal {
triggerBlockType = Material.NETHER_PORTAL; triggerBlockType = Material.NETHER_PORTAL;
} }
return create(pos1, pos2, name, destination, new HashSet<>(Collections.singletonList(triggerBlockType)), serverName, cooldown, extraData); return create(pos1, pos2, name, destination, new HashSet<>(Collections.singletonList(triggerBlockType)),
serverName, extraData);
} }
public static void redefine(Location pos1, Location pos2, String name) { public static void redefine(Location pos1, Location pos2, String name) {
@ -322,31 +345,32 @@ public class Portal {
} }
portalData.getConfig().set(name, null); portalData.getConfig().set(name, null);
// TODO add code to check if people have the portal selected and notify if removed. // TODO add code to check if people have the portal selected and notify if
// removed.
/**Set<String> keys = portalData.getConfig().getKeys(true); /**
for(String key: keys){ * Set<String> keys = portalData.getConfig().getKeys(true); for(String key:
if(key.startsWith(name)){ * keys){ if(key.startsWith(name)){ portalData.getConfig().set(key, null); } }
portalData.getConfig().set(key, null); */
}
}*/
/**portalData.getConfig().set(name + ".world", null); /**
portalData.getConfig().set(name + ".triggerblock", null); * portalData.getConfig().set(name + ".world", null);
portalData.getConfig().set(name + ".destination", null); * portalData.getConfig().set(name + ".triggerblock", null);
* portalData.getConfig().set(name + ".destination", null);
portalData.getConfig().set(name + ".pos1.X", null); *
portalData.getConfig().set(name + ".pos1.Y", null); * portalData.getConfig().set(name + ".pos1.X", null);
portalData.getConfig().set(name + ".pos1.Z", null); * portalData.getConfig().set(name + ".pos1.Y", null);
* portalData.getConfig().set(name + ".pos1.Z", null);
portalData.getConfig().set(name + ".pos2.X", null); *
portalData.getConfig().set(name + ".pos2.Y", null); * portalData.getConfig().set(name + ".pos2.X", null);
portalData.getConfig().set(name + ".pos2.Z", null); * portalData.getConfig().set(name + ".pos2.Y", null);
* portalData.getConfig().set(name + ".pos2.Z", null);
portalData.getConfig().set(name + ".pos1", null); *
portalData.getConfig().set(name + ".getPos2()", null); * portalData.getConfig().set(name + ".pos1", null);
* portalData.getConfig().set(name + ".getPos2()", null);
portalData.getConfig().set(name, null);*/ *
* portalData.getConfig().set(name, null);
*/
portalData.saveConfig(); portalData.saveConfig();
@ -360,10 +384,10 @@ public class Portal {
return posX != null; return posX != null;
} }
public static boolean activate(Player player, String portalName) { public static boolean activate(Player player, String portalName) {
for (AdvancedPortal portal : Portal.portals) { for (AdvancedPortal portal : Portal.portals) {
if (portal.getName().equals(portalName)) return activate(player, portal); if (portal.getName().equals(portalName))
return activate(player, portal);
} }
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName); plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
return false; return false;
@ -371,50 +395,73 @@ public class Portal {
public static boolean activate(Player player, AdvancedPortal portal) { public static boolean activate(Player player, AdvancedPortal portal) {
if(blockSpectatorMode && player.getGameMode() == GameMode.SPECTATOR) { if (blockSpectatorMode && player.getGameMode() == GameMode.SPECTATOR) {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c You cannot enter a portal in spectator mode!"); player.sendMessage(
PluginMessages.customPrefixFail + "\u00A7c You cannot enter a portal in spectator mode!");
return false; return false;
} }
String permission = portal.getArg("permission"); String permission = portal.getArg("permission");
if (!(permission == null || player.hasPermission(permission) || player.isOp())) { if (!(permission == null || player.hasPermission(permission) || player.isOp())) {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!"); player.sendMessage(
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
failSound(player, portal); failSound(player, portal);
throwPlayerBack(player); throwPlayerBack(player);
return false; return false;
} }
Long joinCD = joinCooldown.get(player.getName());
if (joinCD != null) {
int diff = (int) ((System.currentTimeMillis() - joinCD) / 1000);
if (diff < joinCooldownDelay) {
int time = (joinCooldownDelay - diff);
player.sendMessage(ChatColor.RED + "There is " + ChatColor.YELLOW + time + ChatColor.RED + (time == 1 ? " second" : " seconds") + " join cooldown protection left.");
failSound(player, portal);
throwPlayerBack(player);
return false;
}
joinCooldown.remove(player.getName());
}
HashMap<String, Long> cds = cooldown.get(player.getName()); HashMap<String, Long> cds = cooldown.get(player.getName());
if (cds != null) { if (cds != null) {
if (cds.get(portal.getName()) != null) { if (cds.get(portal.getName()) != null) {
long cd = cds.get(portal.getName()); long portalCD = cds.get(portal.getName());
int diff = (int) ((System.currentTimeMillis() - cd) / 1000); int diff = (int) ((System.currentTimeMillis() - portalCD) / 1000);
if (diff < portal.getCooldownDelay()) { int portalCooldown = 0; // default cooldowndelay when cooldowndelay is not specified
int time = (portal.getCooldownDelay() - diff); try {
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + time + ChatColor.RED + (time == 1 ? " second" : " seconds") + " until attempting to enter this portal again."); portalCooldown = Integer.parseInt(portal.getArg("cooldowndelay"));
} catch (Exception e) {
}
if (diff < portalCooldown) {
int time = (portalCooldown - diff);
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + time + ChatColor.RED
+ (time == 1 ? " second" : " seconds") + " until attempting to enter this portal again.");
failSound(player, portal); failSound(player, portal);
throwPlayerBack(player); throwPlayerBack(player);
return false; return false;
} }
} }
} }
if(cds == null) { if (cds == null) {
cds = new HashMap<String, Long>(); cds = new HashMap<String, Long>();
} }
cds.put(portal.getName(), System.currentTimeMillis()); cds.put(portal.getName(), System.currentTimeMillis());
cooldown.put(player.getName(), cds); cooldown.put(player.getName(), cds);
boolean showFailMessage = !portal.hasArg("command.1"); boolean showFailMessage = !portal.hasArg("command.1");
boolean hasMessage = portal.getArg("message") != null; boolean hasMessage = portal.getArg("message") != null;
//plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation()); // plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation());
boolean warped = false; boolean warped = false;
if (portal.getBungee() != null) { if (portal.getBungee() != null) {
String[] bungeeServers = portal.getBungee().split(","); String[] bungeeServers = portal.getBungee().split(",");
String bungeeServer = bungeeServers[random.nextInt(bungeeServers.length)]; String bungeeServer = bungeeServers[random.nextInt(bungeeServers.length)];
if (showBungeeMessage) { if (showBungeeMessage) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + bungeeServer + "\u00A7a."); player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + bungeeServer
+ "\u00A7a.");
} }
if (portal.getDestiation() != null) { if (portal.getDestiation() != null) {
@ -433,19 +480,20 @@ public class Portal {
portal.inPortal.add(player.getUniqueId()); portal.inPortal.add(player.getUniqueId());
player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray()); player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray());
// Down to bungee to sort out the teleporting but yea theoretically they should warp. // Down to bungee to sort out the teleporting but yea theoretically they should
} // warp.
else if (portal.getDestiation() != null) { } else if (portal.getDestiation() != null) {
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) { if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) {
warped = Destination.warp(player, portal.getDestiation(), hasMessage); warped = Destination.warp(player, portal.getDestiation(), hasMessage);
if(!warped){ if (!warped) {
throwPlayerBack(player); throwPlayerBack(player);
} }
} }
} else { } else {
if (showFailMessage) { if (showFailMessage) {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The portal you are trying to use doesn't have a destination!"); player.sendMessage(PluginMessages.customPrefixFail
+ "\u00A7c The portal you are trying to use doesn't have a destination!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.getName() + "' has just had a warp " plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.getName() + "' has just had a warp "
+ "attempt and either the data is corrupt or portal doesn't exist!"); + "attempt and either the data is corrupt or portal doesn't exist!");
throwPlayerBack(player); throwPlayerBack(player);
@ -456,7 +504,8 @@ public class Portal {
if (portal.hasArg("command.1")) { if (portal.hasArg("command.1")) {
warped = true; warped = true;
int commandLine = 1; int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.getName()+ ".portalArgs.command." + commandLine); String command = portal.getArg("command." + commandLine);// portalData.getConfig().getString(portal.getName()+
// ".portalArgs.command." + commandLine);
do { do {
// (?i) makes the search case insensitive // (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName()); command = command.replaceAll("@player", player.getName());
@ -464,10 +513,9 @@ public class Portal {
if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) { if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) {
command = command.substring(1); command = command.substring(1);
plugin.getLogger().log(Level.INFO, "Portal command: " + command); plugin.getLogger().log(Level.INFO, "Portal command: " + command);
try{ try {
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} } catch (Exception e) {
catch(Exception e){
plugin.getLogger().warning("Error while executing: " + command); plugin.getLogger().warning("Error while executing: " + command);
} }
} else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) { } else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) {
@ -476,7 +524,7 @@ public class Portal {
try { try {
player.setOp(true); player.setOp(true);
player.chat("/" + command); player.chat("/" + command);
//player.performCommand(command); // player.performCommand(command);
} finally { } finally {
player.setOp(wasOp); player.setOp(wasOp);
} }
@ -486,21 +534,22 @@ public class Portal {
try { try {
permissionAttachment = player.addAttachment(plugin, "*", true); permissionAttachment = player.addAttachment(plugin, "*", true);
player.chat("/" + command); player.chat("/" + command);
//player.performCommand(command); // player.performCommand(command);
} finally { } finally {
player.removeAttachment(permissionAttachment); player.removeAttachment(permissionAttachment);
} }
} else { } else {
player.chat("/" + command); player.chat("/" + command);
//player.performCommand(command); // player.performCommand(command);
} }
command = portal.getArg("command." + ++commandLine); command = portal.getArg("command." + ++commandLine);
} while (command != null); } while (command != null);
} }
if(warped) { if (warped) {
if(hasMessage) { if (hasMessage) {
plugin.compat.sendActionBarMessage(portal.getArg("message").replaceAll("&(?=[0-9a-fk-or])", "\u00A7"), player); plugin.compat.sendActionBarMessage(portal.getArg("message").replaceAll("&(?=[0-9a-fk-or])", "\u00A7"),
player);
} }
} }
@ -508,7 +557,7 @@ public class Portal {
} }
private static void failSound(Player player, AdvancedPortal portal) { private static void failSound(Player player, AdvancedPortal portal) {
if(!(portal.getTriggers().contains(Material.NETHER_PORTAL) && player.getGameMode() == GameMode.CREATIVE)){ if (!(portal.getTriggers().contains(Material.NETHER_PORTAL) && player.getGameMode() == GameMode.CREATIVE)) {
player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F); player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F);
} }
} }
@ -527,7 +576,8 @@ public class Portal {
int intData = Integer.parseInt(config.getConfig().getString(key)); int intData = Integer.parseInt(config.getConfig().getString(key));
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData); config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
} catch (Exception e) { } catch (Exception e) {
config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key)); config.getConfig().set(key.replace(oldName + ".", newName + "."),
config.getConfig().getString(key));
} }
} }
@ -540,12 +590,12 @@ public class Portal {
} }
public static boolean addCommand(String portalName, String portalCommand) { public static boolean addCommand(String portalName, String portalCommand) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
if (portalExists(portalName)) { if (portalExists(portalName)) {
int commandLine = 0; int commandLine = 0;
while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null); //Loops increasing commandLine till 1 is null while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null)
; // Loops increasing commandLine till 1 is null
config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand); config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand);
config.saveConfig(); config.saveConfig();
loadPortals(); loadPortals();
@ -592,14 +642,19 @@ public class Portal {
if (!portalsActive) if (!portalsActive)
return false; return false;
if (loc.getWorld() != null && portal.getWorldName().equals(loc.getWorld().getName())) if (loc.getWorld() != null && portal.getWorldName().equals(loc.getWorld().getName()))
if ((portal.getPos1().getX() + 1 + additionalArea) >= loc.getX() && (portal.getPos1().getY() + 1 + additionalArea) > loc.getY() && (portal.getPos1().getZ() + 1 + additionalArea) >= loc.getZ()) if ((portal.getPos1().getX() + 1 + additionalArea) >= loc.getX()
if (portal.getPos2().getX() - additionalArea <= loc.getX() && portal.getPos2().getY() - additionalArea <= loc.getY() && portal.getPos2().getZ() - additionalArea <= loc.getZ()) && (portal.getPos1().getY() + 1 + additionalArea) > loc.getY()
&& (portal.getPos1().getZ() + 1 + additionalArea) >= loc.getZ())
if (portal.getPos2().getX() - additionalArea <= loc.getX()
&& portal.getPos2().getY() - additionalArea <= loc.getY()
&& portal.getPos2().getZ() - additionalArea <= loc.getZ())
return true; return true;
return false; return false;
} }
public static void throwPlayerBack(Player player){ public static void throwPlayerBack(Player player) {
// Not ensured to remove them out of the portal but it makes it feel nicer for the player. // Not ensured to remove them out of the portal but it makes it feel nicer for
// the player.
if (throwback > 0) { if (throwback > 0) {
Vector velocity = player.getLocation().getDirection(); Vector velocity = player.getLocation().getDirection();
player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(throwback)); player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(throwback));