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"));
// 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.
//private HashMap<String, String> portalArgs = new HashMap<>();
// to store all possible portal arguments. Makes code shorter and possibly more
// efficient.
// private HashMap<String, String> portalArgs = new HashMap<>();
public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
@ -48,10 +49,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@SuppressWarnings("deprecation")
@Override
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 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.");
return true;
}
@ -59,28 +60,31 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
PlayerInventory inventory = player.getInventory();
if (sender.hasPermission("advancedportals.portal")) {
if (args.length > 0) { switch (args[0].toLowerCase()) {
if (args.length > 0) {
switch (args[0].toLowerCase()) {
case "warp":
if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){
for (AdvancedPortal portal: Portal.portals){
if (args[1].equalsIgnoreCase(portal.getName())){
if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")) {
for (AdvancedPortal portal : Portal.portals) {
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);
plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!warpEvent.isCancelled()) Portal.activate(player, portal);
if (!warpEvent.isCancelled())
Portal.activate(player, portal);
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;
case "wand":
case "selector":
String ItemID = config.getConfig().getString("AxeItemId");
Material WandMaterial = Material.getMaterial(ItemID);
if (WandMaterial == null) {
@ -90,30 +94,35 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ItemStack regionselector = new ItemStack(WandMaterial);
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName("\u00A7ePortal Region Selector");
selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help"
, "\u00A7r create portals bestowed upon it!"));
selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help",
"\u00A7r create portals bestowed upon it!"));
regionselector.setItemMeta(selectorname);
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;
case "portalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
// TODO change this to a purple wool block and give it a name with a color. Then
// listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case
// they want it.
ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1);
ItemMeta blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A75Portal Block Placer");
blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block",
"\u00A7rLeft Click: Rotate portal block"));
"\u00A7rRight Click: Place portal block", "\u00A7rLeft Click: Rotate portal block"));
portalBlock.setItemMeta(blockName);
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;
case "endportalblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
// TODO change this to a purple wool block and give it a name with a color. Then
// listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case
// they want it.
portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78End Portal Block Placer");
@ -121,11 +130,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
"\u00A7rRight Click: Place portal block"));
portalBlock.setItemMeta(blockName);
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;
case "gatewayblock":
// TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case they want it.
// TODO change this to a purple wool block and give it a name with a color. Then
// listen to when its placed.
// Also do this for other blocks such as gateways and end portals just in case
// they want it.
portalBlock = new Wool(DyeColor.BLACK).toItemStack(1);
blockName = portalBlock.getItemMeta();
blockName.setDisplayName("\u00A78Gateway Block Placer");
@ -134,13 +146,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
portalBlock.setItemMeta(blockName);
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;
case "create":
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString())
&& player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something
if (player.getMetadata("Pos1World").get(0).asString()
.equals(player.getMetadata("Pos2World").get(0).asString())
&& player.getMetadata("Pos1World").get(0).asString()
.equals(player.getLocation().getWorld().getName())) {
if (args.length >= 2) { // may make this next piece of code more efficient, maybe check
// against a list of available variables or something
// TODO change system to use arrays and hashmaps
boolean hasName = false;
boolean hasTriggerBlock = false;
@ -148,23 +164,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean isBungeePortal = false;
boolean needsPermission = false;
boolean executesCommand = false;
boolean hasCooldownDelay = false;
String destination = null;
String portalName = null;
String triggerBlock = null;
String serverName = null;
String permission = null;
String portalCommand = null;
String cooldownDelay = null;
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++) {
if (startsWithPortalArg("name:", args[i])) {
portalName = args[i].replaceFirst("name:", "");
if(portalName.equals("")) {
player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that isnt nothing!");
if (portalName.equals("")) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You must include a name for the portal that isnt nothing!");
return true;
}
hasName = true;
@ -189,55 +205,74 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
permission = args[i].toLowerCase().replaceFirst("permission:", "");
extraData.add(new PortalArg("permission", permission));
} 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)));
} else if(startsWithPortalArg("message:", args[i])) {
} else if (startsWithPortalArg("message:", args[i])) {
String message = parseArgVariable(args, i, "message:");
if(message == null) {
player.sendMessage(PluginMessages.customPrefixFail + " Message quotes not closed!");
if (message == null) {
player.sendMessage(
PluginMessages.customPrefixFail + " Message quotes not closed!");
return true;
}
extraData.add(new PortalArg("message", message ));
extraData.add(new PortalArg("message", message));
} else if (startsWithPortalArg("command:", args[i])) {
executesCommand = true;
portalCommand = parseArgVariable(args, i, "command:");
if(portalCommand == null) {
player.sendMessage(PluginMessages.customPrefixFail + " Command quotes not closed!");
if (portalCommand == null) {
player.sendMessage(
PluginMessages.customPrefixFail + " Command quotes not closed!");
return true;
}
i += this.portalArgsStringLength - 1;
if(portalCommand.startsWith("#") && !(this.plugin.getSettings().hasCommandLevel("c")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.console"))
|| (this.plugin.getSettings().hasCommandLevel("k") && sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a console command portal!");
if (portalCommand.startsWith("#")
&& !(this.plugin.getSettings().hasCommandLevel("c")
&& (sender.hasPermission(
"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;
}
else if(portalCommand.startsWith("!") && !(this.plugin.getSettings().hasCommandLevel("o")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.op"))
|| (this.plugin.getSettings().hasCommandLevel("p") && sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a op command portal!");
} else if (portalCommand.startsWith("!")
&& !(this.plugin.getSettings().hasCommandLevel("o")
&& (sender.hasPermission(
"advancedportals.createportal.commandlevel.op"))
|| (this.plugin.getSettings().hasCommandLevel("p")
&& sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You need permission to make a op command portal!");
return true;
}
else if(portalCommand.startsWith("^") && !(this.plugin.getSettings().hasCommandLevel("p")
&& (sender.hasPermission("advancedportals.createportal.commandlevel.perms"))
|| (this.plugin.getSettings().hasCommandLevel("e") && sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a all perms command portal!");
} else if (portalCommand.startsWith("^")
&& !(this.plugin.getSettings().hasCommandLevel("p")
&& (sender.hasPermission(
"advancedportals.createportal.commandlevel.perms"))
|| (this.plugin.getSettings().hasCommandLevel("e")
&& sender.isOp()))) {
player.sendMessage(PluginMessages.customPrefixFail
+ " You need permission to make a all perms command portal!");
return true;
}
extraData.add(new PortalArg("command.1", portalCommand));
} else if (startsWithPortalArg("cooldowndelay:", args[i])) {
hasCooldownDelay = true;
cooldownDelay = args[i].toLowerCase().replaceFirst("cooldowndelay:", "");
String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:");
extraData.add(new PortalArg("cooldowndelay", cooldownDelay));
}
}
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;
}
World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString());
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());
World world = org.bukkit.Bukkit
.getWorld(player.getMetadata("Pos1World").get(0).asString());
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");
String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X");
@ -245,19 +280,21 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (!Portal.portalExists(portalName)) {
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);
if (hasDestination) {
if (!isBungeePortal && destiPosX == null) {
player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)");
player.sendMessage("\u00A7cdestination: \u00A7e" + destination
+ " (destination does not exist)");
return true;
}
else{
} else {
player.sendMessage("\u00A7adestination: \u00A7e" + destination);
}
} 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) {
@ -270,9 +307,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7apermission: \u00A7e(none needed)");
}
for(PortalArg portalArg : extraData) {
if(!ignoreExtras.contains(portalArg.argName)) {
player.sendMessage("\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value);
for (PortalArg portalArg : extraData) {
if (!ignoreExtras.contains(portalArg.argName)) {
player.sendMessage(
"\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value);
}
}
@ -280,58 +318,62 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
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) {
Set<Material> materialSet = Portal.getMaterialSet(triggerBlock.toUpperCase().split(","));
Set<Material> materialSet = Portal
.getMaterialSet(triggerBlock.toUpperCase().split(","));
if (materialSet.size() != 0) {
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
player.sendMessage(
"\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
PortalArg[] portalArgs = new PortalArg[extraData.size()];
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 {
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()];
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 {
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()];
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 {
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
player.sendMessage("");
} 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!");
}
} 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 {
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;
case "variables" :
sender.sendMessage(PluginMessages.customPrefix + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay");
case "variables":
sender.sendMessage(PluginMessages.customPrefix
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay");
sender.sendMessage("");
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
break;
@ -341,12 +383,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (args.length > 1) {
if (Portal.portalExists(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 {
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 {
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));
}
@ -356,23 +402,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
break;
case "unselect":
if(player.getMetadata("selectedPortal").size() != 0){
player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + player.getMetadata("selectedPortal").get(0).asString()
+ "\u00A7a.");
}
else{
if (player.getMetadata("selectedPortal").size() != 0) {
player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e"
+ player.getMetadata("selectedPortal").get(0).asString() + "\u00A7a.");
} else {
player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!");
}
case "gui" :
case "gui":
if (args.length > 1) {
if (args[1].toLowerCase().equals("remove") && args.length > 2) {
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("");
plugin.compat.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\"," +
"\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + 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);
plugin.compat.sendRawMessage(
"{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\","
+ "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove "
+ 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("");
}
}
@ -383,7 +434,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
portalEditMenu(sender, portalConfig, args[1]);
} 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 {
if (player.getMetadata("selectedPortal").size() != 0) {
@ -392,11 +444,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (posX != null) {
portalEditMenu(sender, portalConfig, portalName);
} 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);
}
} else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!");
sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
}
}
break;
@ -412,22 +466,29 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if (posX != null && newPortalPosX == null) {
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]));
} 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 {
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);
}
} 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 {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!");
sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
}
} 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;
case "command":
@ -442,23 +503,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
portalCommand += args[i];
}
if (Portal.addCommand(portalName, portalCommand)) {
sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!");
sender.sendMessage(
PluginMessages.customPrefixFail + " Command added to portal!");
} else {
sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!");
sender.sendMessage(
PluginMessages.customPrefixFail + " Failed to add command to portal!");
}
} 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")) {
// Specify what line to remove
} else if (args[1].toLowerCase().equals("show")) {
} 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 {
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 {
@ -469,7 +535,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if (posX != null) {
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 {
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");
if (posX != null) {
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 {
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);
}
} else {
sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!");
sender.sendMessage(
PluginMessages.customPrefixFail + " No portal has been defined or selected!");
}
}
break;
@ -502,12 +572,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
} else {
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());
} else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString())
&& player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
player.sendMessage(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!");
if (player.getMetadata("Pos1World").get(0).asString()
.equals(player.getMetadata("Pos2World").get(0).asString())
&& player.getMetadata("Pos1World").get(0).asString()
.equals(player.getLocation().getWorld().getName())) {
player.sendMessage(PluginMessages.customPrefix
+ " Your currently selected area has been shown, it will dissapear shortly!");
Selection.show(player, this.plugin, null);
}
} else {
@ -520,7 +594,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Listeners.reloadValues(plugin);
Portal.loadPortals();
break;
case "list" :
case "list":
String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a";
LinkedList<String> portals = new LinkedList<>();
for (AdvancedPortal portal : Portal.portals) {
@ -551,9 +625,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private void helpCommand(CommandSender sender, String command, String[] args) {
// Add pages if there starts to become too many
if(args.length == 1) {
sendMenu(sender, "Help Menu",
"\u00A76/" + command + " selector \u00A7a- gives you a region selector",
if (args.length == 1) {
sendMenu(sender, "Help Menu", "\u00A76/" + command + " selector \u00A7a- gives you a region selector",
"\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection ",
"\u00A76/" + command + " portalblock \u00A7a- gives you a 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 + " warp <name> \u00A7a- teleport to warp name",
"\u00A76/" + command + " variables \u00A7a- lists all available tags");
}
else if(args.length > 1){
if(args[1].toLowerCase().equals("help")) {
} else if (args.length > 1) {
if (args[1].toLowerCase().equals("help")) {
sendMenu(sender, "Help Command",
"Shows the help section. You can also use a single argument after it to show the " +
"help section for the corresponding command.");
}
else if(args[1].toLowerCase().equals("portalblock")) {
sendMenu(sender, "Help Command",
"Gives you a special wool block to place portal blocks.",
"",
"Shows the help section. You can also use a single argument after it to show the "
+ "help section for the corresponding command.");
} else if (args[1].toLowerCase().equals("portalblock")) {
sendMenu(sender, "Help Command", "Gives you a special wool block to place portal blocks.", "",
"\u00A7eLeft Click: \u00A76Rotates the hit portal block",
"\u00A7eRight Click: \u00A76Placed a portal block");
}
else if(args[1].toLowerCase().equals("endportalblock")) {
sendMenu(sender, "Help Command",
"Gives you a special wool block to place end portal blocks.",
"",
} else if (args[1].toLowerCase().equals("endportalblock")) {
sendMenu(sender, "Help Command", "Gives you a special wool block to place end portal blocks.", "",
"\u00A7eRight Click: \u00A76Placed a end portal block");
}
else if(args[1].toLowerCase().equals("gatewayblock")) {
sendMenu(sender, "Help Command",
"Gives you a special wool block to place gateway blocks.",
"",
} else if (args[1].toLowerCase().equals("gatewayblock")) {
sendMenu(sender, "Help Command", "Gives you a special wool block to place gateway blocks.", "",
"\u00A7eRight Click: \u00A76Placed a gateway block");
}
else{
sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1] + "\u00A7a is not a command or a help page has not been added yet.");
} else {
sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1]
+ "\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) {
sender.sendMessage(PluginMessages.customPrefix + " " + title);
sender.sendMessage("\u00A7e\u00A7m-----------------------------------");
for(String line : lines){
for (String line : lines) {
sender.sendMessage("\u00A7a" + line);
}
sender.sendMessage("\u00A7e\u00A7m-----------------------------------");
@ -616,7 +679,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (variableString.length() == 0 || variableString.charAt(variableString.length() - 1) != '"') {
currentArg++;
for (; currentArg <= args.length; currentArg++) {
if(currentArg == args.length) {
if (currentArg == args.length) {
return null;
}
variableString += " " + args[currentArg];
@ -635,19 +698,24 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
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
// 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
// features make sure you use the
// chat steriliser
sender.sendMessage("");
sender.sendMessage(PluginMessages.customPrefix + " Editing: \u00A7e" + portalName);
sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X")
+ ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z"));
sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X")
+ ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z"));
sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + ", "
+ portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", "
+ portalConfig.getConfig().getString(portalName + ".pos1.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");
if (destination != null) {
@ -666,7 +734,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) {
int commands = 0;
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) {
command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands);
}
@ -682,11 +751,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Player player = (Player) sender;
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 + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal show " + portalName + "\"}}"
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 + "\"}}"
+ ",{\"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\":\"\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("");
@ -697,8 +769,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
LinkedList<String> autoComplete = new LinkedList<String>();
if (sender.hasPermission("advancedportals.createportal")) {
if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) {
autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command", "selector"
, "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage", "warp"));
autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command",
"selector", "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename",
"help", "bukkitpage", "helppage", "warp"));
} else if (args[0].toLowerCase().equals("create")) {
boolean hasName = false;
@ -710,8 +783,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasCommand = false;
boolean hasCooldownDelay = false;
// TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands
// TODO change auto complete when quotes are opened and closed. Such as
// autocomplete @Player and stuff when specifying commands
for (int i = 1; i < args.length; i++) {
String argTag = getTag(args[i].toLowerCase());
@ -776,32 +849,32 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
}
}
if (args.length == 2 && args[0].equalsIgnoreCase("warp")){
for (AdvancedPortal portal :Portal.portals){
if (args.length == 2 && args[0].equalsIgnoreCase("warp")) {
for (AdvancedPortal portal : Portal.portals) {
String perm = portal.getArg("permission");
if (perm == null || sender.hasPermission(perm)){
if (perm == null || sender.hasPermission(perm)) {
autoComplete.add(portal.getName());
}
}
}
String triggerBlock = "triggerblock:";
if(args[args.length-1].toLowerCase().startsWith(triggerBlock)) {
String currentArg = args[args.length-1];
if (args[args.length - 1].toLowerCase().startsWith(triggerBlock)) {
String currentArg = args[args.length - 1];
int length = currentArg.lastIndexOf(',');
String startString;
if(triggerBlock.length() > length) {
if (triggerBlock.length() > length) {
startString = triggerBlock;
} else {
startString = currentArg.substring(0, length + 1);
}
else {
startString = currentArg.substring(0, length+1);
autoComplete
.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"));
}
if(args[args.length-1].startsWith("desti:") || args[args.length-1].startsWith("destination:")) {
String tagStart = args[args.length-1].startsWith("desti:") ? "desti:" : "destination:";
if (args[args.length - 1].startsWith("desti:") || args[args.length - 1].startsWith("destination:")) {
String tagStart = args[args.length - 1].startsWith("desti:") ? "desti:" : "destination:";
ConfigAccessor destiConfig = new ConfigAccessor(plugin, "destinations.yml");
List<Object> destiObj = Arrays.asList(destiConfig.getConfig().getKeys(false).toArray());
for (Object object : destiObj) {

View File

@ -22,6 +22,7 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.HashMap;
import java.util.UUID;
public class Listeners implements Listener {
@ -40,14 +41,12 @@ public class Listeners implements Listener {
String ItemID = config.getConfig().getString("AxeItemId");
if(ItemID == null){
if (ItemID == null) {
WandMaterial = Material.IRON_AXE;
}
else{
} else {
WandMaterial = Material.getMaterial(ItemID);
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@ -62,45 +61,29 @@ public class Listeners implements Listener {
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)
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);
}
}
@EventHandler(ignoreCancelled = true)
public void onLeaveEvent(PlayerQuitEvent event) {
Portal.cooldown.remove(event.getPlayer().getName());
UUID uuid = event.getPlayer().getUniqueId();
for (AdvancedPortal portal : Portal.portals) {
portal.inPortal.remove(uuid);
@EventHandler
public void onWorldChangeEvent(PlayerChangedWorldEvent event) {
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
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)
@ -124,7 +107,8 @@ public class Listeners implements Listener {
boolean delayed = portal.hasArg("delayed") && portal.getArg("delayed").equalsIgnoreCase("true");
for (Location loc : locations) {
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 (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
@ -135,26 +119,30 @@ public class Listeners implements Listener {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
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);
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;
} 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
class RemoveLavaData implements Runnable{
class RemoveLavaData implements Runnable {
private Player player;
public RemoveLavaData(Player player){
public RemoveLavaData(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;
public RemoveWarpData(Player player){
public RemoveWarpData(Player player) {
this.player = player;
}
@ -188,11 +175,13 @@ public class Listeners implements Listener {
event.setCancelled(true);
}
@EventHandler(ignoreCancelled = true)
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().hasMetadata("lavaWarped") | Portal.inPortalTriggerRegion(event.getEntity().getLocation()))
if (event.getEntity() instanceof Player && (event.getCause() == EntityDamageEvent.DamageCause.LAVA
|| event.getCause() == EntityDamageEvent.DamageCause.FIRE
|| event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) {
if (event.getEntity().hasMetadata("lavaWarped")
| Portal.inPortalTriggerRegion(event.getEntity().getLocation()))
event.setCancelled(true);
}
}
@ -211,28 +200,37 @@ public class Listeners implements Listener {
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);
}
@EventHandler(ignoreCancelled = true)
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
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) {
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
player.sendMessage(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
player.sendMessage(
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);
player.removeMetadata("selectingPortal", plugin);
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);
return;
}
@ -240,45 +238,54 @@ public class Listeners implements Listener {
if (player.hasPermission("advancedportals.createportal")) {
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) {
Location blockloc = event.getClickedBlock().getLocation();
// stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will
// have to be selected again if the player joins, also it does not affect any other players.
// stores the selection as metadata on the character so then it isn't saved
// anywhere, if the player logs out it will
// have to be selected again if the player joins, also it does not affect any
// other players.
player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY()
player.sendMessage(
"\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY()
+ " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// Stops the event so the block is not damaged
event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed)
// Returns the event so no more code is executed(stops unnecessary code being
// executed)
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY()
player.sendMessage(
"\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY()
+ " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// Stops the event so the block is not interacted with
event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed)
// 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") &&
event.getAction() == Action.LEFT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.NETHER_PORTAL) {
} else if (checkItemForName(event.getItem())
&& 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();
if(block instanceof Orientable) {
if (block instanceof Orientable) {
Orientable rotatable = (Orientable) block;
if (rotatable.getAxis() == Axis.X) {
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();
}
}

View File

@ -21,8 +21,6 @@ public class AdvancedPortal {
private String portalName = null;
private int cooldownDelay = 0;
// 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
@ -35,32 +33,31 @@ public class AdvancedPortal {
public HashSet<UUID> inPortal = new HashSet<UUID>();
// 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) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), cooldown, portalArgs);
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, int cooldown, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), cooldown, portalArgs);
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... 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) {
this(portalName, trigger, pos1, pos2, worldName, cooldown, portalArgs);
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, worldName, portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, int cooldown, PortalArg... portalArgs) {
this(portalName, new HashSet<>(Collections.singletonList(trigger)), pos1, pos2, worldName, cooldown, 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, 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.triggers = triggers;
this.pos1 = pos1;
this.pos2 = pos2;
this.worldName = worldName;
this.portalArgs = portalArgs;
this.cooldownDelay = cooldown;
}
public String getArg(String arg) {
@ -100,14 +97,6 @@ public class AdvancedPortal {
return this.portalName;
}
public int getCooldownDelay() {
return this.cooldownDelay;
}
public void setCooldownDelay(int cooldownDelay) {
this.cooldownDelay = cooldownDelay;
}
public String getDestiation() {
return this.destiation;
}

View File

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