2020-01-20 11:55:18 +01:00
|
|
|
package com.sekwah.advancedportals.bukkit.portals;
|
2015-01-15 20:56:13 +01:00
|
|
|
|
2015-01-15 23:16:16 +01:00
|
|
|
import com.google.common.io.ByteArrayDataOutput;
|
|
|
|
import com.google.common.io.ByteStreams;
|
2020-01-20 11:55:18 +01:00
|
|
|
import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
|
|
|
|
import com.sekwah.advancedportals.bukkit.PluginMessages;
|
|
|
|
import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg;
|
2020-06-26 03:33:38 +02:00
|
|
|
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
|
2020-01-20 11:55:18 +01:00
|
|
|
import com.sekwah.advancedportals.bukkit.destinations.Destination;
|
|
|
|
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
|
2020-06-18 04:37:06 +02:00
|
|
|
import com.sekwah.advancedportals.bungee.BungeeMessages;
|
2020-06-26 01:42:39 +02:00
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
2016-09-01 21:11:07 +02:00
|
|
|
import org.bukkit.*;
|
2016-01-19 23:31:16 +01:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
2015-01-15 20:56:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2020-04-08 18:28:26 +02:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2015-11-15 23:52:29 +01:00
|
|
|
import org.bukkit.permissions.PermissionAttachment;
|
2016-09-01 21:11:07 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2015-01-15 20:56:13 +01:00
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
import java.util.*;
|
2015-01-15 23:16:16 +01:00
|
|
|
import java.util.logging.Level;
|
2019-06-02 05:39:08 +02:00
|
|
|
import java.util.stream.Collectors;
|
2015-01-15 20:56:13 +01:00
|
|
|
|
|
|
|
public class Portal {
|
2016-09-01 21:11:07 +02:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
public static HashMap<String, Long> joinCooldown = new HashMap<String, Long>();
|
2020-04-04 17:12:09 +02:00
|
|
|
public static HashMap<String, HashMap<String, Long>> cooldown = new HashMap<String, HashMap<String, Long>>();
|
2016-07-28 20:13:52 +02:00
|
|
|
// Config values
|
2016-03-29 13:38:03 +02:00
|
|
|
public static boolean portalsActive = false;
|
2017-05-19 07:09:57 +02:00
|
|
|
public static AdvancedPortal[] portals = new AdvancedPortal[0];
|
2016-03-29 13:38:03 +02:00
|
|
|
private static AdvancedPortalsPlugin plugin;
|
|
|
|
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
|
2017-05-19 07:09:57 +02:00
|
|
|
private static boolean showBungeeMessage;
|
2016-09-01 21:11:07 +02:00
|
|
|
private static double throwback;
|
2017-07-08 10:27:05 +02:00
|
|
|
private static Sound portalSound;
|
2017-11-30 19:56:42 +01:00
|
|
|
private static int portalProtectionRadius;
|
2017-11-30 20:13:52 +01:00
|
|
|
private static boolean blockSpectatorMode;
|
2020-04-06 22:36:46 +02:00
|
|
|
private static int joinCooldownDelay;
|
2019-06-02 05:39:08 +02:00
|
|
|
private static Random random = new Random();
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public Portal(AdvancedPortalsPlugin plugin) {
|
|
|
|
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
2017-11-30 20:13:52 +01:00
|
|
|
this.showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage", false);
|
2017-11-30 19:56:42 +01:00
|
|
|
|
2020-06-18 04:37:06 +02:00
|
|
|
this.portalProtectionRadius = config.getConfig().getBoolean("PortalProtection") ?
|
|
|
|
config.getConfig().getInt("PortalProtectionArea") : 0;
|
2017-11-30 19:56:42 +01:00
|
|
|
|
|
|
|
this.throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7);
|
2016-03-29 13:38:03 +02:00
|
|
|
|
2017-07-08 10:27:05 +02:00
|
|
|
this.portalSound = WarpEffects.findSound(plugin, "BLOCK_PORTAL_TRAVEL", "PORTAL_TRAVEL");
|
2017-11-30 20:13:52 +01:00
|
|
|
this.blockSpectatorMode = config.getConfig().getBoolean("BlockSpectatorMode", false);
|
2017-07-08 10:27:05 +02:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
this.joinCooldownDelay = config.getConfig().getInt("PortalCooldown", 5);
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
Portal.plugin = plugin;
|
|
|
|
Portal.loadPortals();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This can be used to move the get keys to different sections
|
|
|
|
* <p>
|
|
|
|
* ConfigurationSection section = portalData.getSection("sectionname");
|
|
|
|
* <p>
|
|
|
|
* section.getKeys(false);
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static void loadPortals() {
|
|
|
|
portalData = new ConfigAccessor(plugin, "portals.yml");
|
|
|
|
Set<String> PortalSet = portalData.getConfig().getKeys(false);
|
|
|
|
if (PortalSet.size() > 0) {
|
2017-05-19 07:09:57 +02:00
|
|
|
portals = new AdvancedPortal[PortalSet.toArray().length];
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
/*
|
|
|
|
* for(int i = 0; i <= PortalSet.toArray().length - 1; i++){ portals[i] = new
|
|
|
|
* AdvancedPortal(); }
|
|
|
|
*/
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
int portalId = 0;
|
|
|
|
for (Object portal : PortalSet.toArray()) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
ConfigurationSection portalConfigSection = portalData.getConfig()
|
|
|
|
.getConfigurationSection(portal.toString());
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2019-08-12 10:40:06 +02:00
|
|
|
String blockTypesRaw = portalConfigSection.getString("triggerblock");
|
|
|
|
|
|
|
|
String[] blockTypesString = blockTypesRaw != null ? blockTypesRaw.split(",") : null;
|
2016-03-29 01:20:04 +02:00
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
HashSet<Material> blockTypes = getMaterialSet(blockTypesString);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (blockTypes.isEmpty()) {
|
2019-06-02 05:39:08 +02:00
|
|
|
blockTypes.add(Material.NETHER_PORTAL);
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
ArrayList<PortalArg> extraData = new ArrayList<>();
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
if (portalArgsConf != null) {
|
|
|
|
Set<String> argsSet = portalArgsConf.getKeys(true);
|
2016-02-29 19:54:24 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
for (Object argName : argsSet.toArray()) {
|
|
|
|
if (portalArgsConf.isString(argName.toString())) {
|
2020-04-06 22:36:46 +02:00
|
|
|
extraData.add(
|
|
|
|
new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
|
2020-04-06 22:36:46 +02:00
|
|
|
if (worldName != null) {
|
2017-05-19 07:09:57 +02:00
|
|
|
World world = Bukkit.getWorld(worldName);
|
2020-04-06 22:36:46 +02:00
|
|
|
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"));
|
2016-02-29 19:54:24 +01:00
|
|
|
|
2017-05-19 07:09:57 +02:00
|
|
|
PortalArg[] portalArgs = new PortalArg[extraData.size()];
|
|
|
|
extraData.toArray(portalArgs);
|
2016-02-29 19:54:24 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
portals[portalId] = new AdvancedPortal(portal.toString(), blockTypes, pos1, pos2, worldName,
|
|
|
|
portalArgs);
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2017-06-13 19:06:48 +02:00
|
|
|
portals[portalId].setBungee(portalConfigSection.getString("bungee"));
|
2016-02-29 19:54:24 +01:00
|
|
|
|
2017-06-13 19:06:48 +02:00
|
|
|
portals[portalId].setDestiation(portalConfigSection.getString("destination"));
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2017-05-19 07:09:57 +02:00
|
|
|
portalId++;
|
2020-04-06 22:36:46 +02:00
|
|
|
} else {
|
2017-05-19 07:09:57 +02:00
|
|
|
AdvancedPortal[] tempPortals = portals;
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2017-05-19 07:09:57 +02:00
|
|
|
portals = new AdvancedPortal[portals.length - 1];
|
|
|
|
|
2017-05-19 07:31:21 +02:00
|
|
|
System.arraycopy(tempPortals, 0, portals, 0, portalId);
|
2017-05-19 07:09:57 +02:00
|
|
|
}
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
|
|
|
portalsActive = true;
|
|
|
|
} else {
|
|
|
|
portalsActive = false;
|
2017-07-14 01:15:08 +02:00
|
|
|
portals = new AdvancedPortal[0];
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
public static HashSet<Material> getMaterialSet(String[] blockTypesString) {
|
|
|
|
HashSet<Material> blockTypes = new HashSet<>();
|
|
|
|
|
2019-08-12 10:40:06 +02:00
|
|
|
if (blockTypesString != null) {
|
2020-04-06 22:36:46 +02:00
|
|
|
for (String blockType : blockTypesString) {
|
2019-08-12 10:40:06 +02:00
|
|
|
Material material = Material.getMaterial(blockType);
|
2020-04-06 22:36:46 +02:00
|
|
|
if (material != null) {
|
2019-08-12 10:40:06 +02:00
|
|
|
blockTypes.add(material);
|
|
|
|
}
|
2019-06-02 05:39:08 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-12 10:40:06 +02:00
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
return blockTypes;
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
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);
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
public static String create(Location pos1, Location pos2, String name, String destination,
|
|
|
|
Set<Material> triggerBlocks, String serverName, PortalArg... portalArgs) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
if (!pos1.getWorld().equals(pos2.getWorld())) {
|
|
|
|
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
|
|
|
|
return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!";
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
int LowX = 0;
|
|
|
|
int LowY = 0;
|
|
|
|
int LowZ = 0;
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
int HighX = 0;
|
|
|
|
int HighY = 0;
|
|
|
|
int HighZ = 0;
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
if (pos1.getX() > pos2.getX()) {
|
|
|
|
LowX = (int) pos2.getX();
|
|
|
|
HighX = (int) pos1.getX();
|
|
|
|
} else {
|
|
|
|
LowX = (int) pos1.getX();
|
|
|
|
HighX = (int) pos2.getX();
|
|
|
|
}
|
|
|
|
if (pos1.getY() > pos2.getY()) {
|
|
|
|
LowY = (int) pos2.getY();
|
|
|
|
HighY = (int) pos1.getY();
|
|
|
|
} else {
|
|
|
|
LowY = (int) pos1.getY();
|
|
|
|
HighY = (int) pos2.getY();
|
|
|
|
}
|
|
|
|
if (pos1.getZ() > pos2.getZ()) {
|
|
|
|
LowZ = (int) pos2.getZ();
|
|
|
|
HighZ = (int) pos1.getZ();
|
|
|
|
} else {
|
|
|
|
LowZ = (int) pos1.getZ();
|
|
|
|
HighZ = (int) pos2.getZ();
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
|
|
|
|
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
/*
|
|
|
|
* if (checkPortalOverlap(checkpos1, checkpos2)) {
|
|
|
|
* plugin.getLogger().log(Level.WARNING, "portals must not overlap!"); return
|
|
|
|
* "\u00A7cPortal creation error, portals must not overlap!"; }
|
|
|
|
*/
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
portalData.getConfig().set(name + ".world", pos1.getWorld().getName());
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
String store = triggerBlocks.stream().map(Enum::name).collect(Collectors.joining(","));
|
|
|
|
portalData.getConfig().set(name + ".triggerblock", store);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
portalData.getConfig().set(name + ".destination", destination);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
portalData.getConfig().set(name + ".bungee", serverName);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
portalData.getConfig().set(name + ".pos1.X", HighX);
|
|
|
|
portalData.getConfig().set(name + ".pos1.Y", HighY);
|
|
|
|
portalData.getConfig().set(name + ".pos1.Z", HighZ);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
portalData.getConfig().set(name + ".pos2.X", LowX);
|
|
|
|
portalData.getConfig().set(name + ".pos2.Y", LowY);
|
|
|
|
portalData.getConfig().set(name + ".pos2.Z", LowZ);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
for (PortalArg arg : portalArgs) {
|
|
|
|
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
|
|
|
|
}
|
2015-03-25 23:51:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
portalData.saveConfig();
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
loadPortals();
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
return "\u00A7aPortal creation successful!";
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
private static boolean checkPortalOverlap(Location pos1, Location pos2) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
if (portalsActive) {
|
|
|
|
int portalId = 0;
|
2020-04-06 22:36:46 +02:00
|
|
|
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())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
|
|
|
|
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
|
|
|
|
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
|
|
|
|
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
|
|
|
|
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
|
|
|
|
portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(),
|
|
|
|
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(),
|
|
|
|
portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
2016-03-29 13:38:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
portalId++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) {
|
|
|
|
if (pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ) {
|
|
|
|
if ((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
public static String create(Location pos1, Location pos2, String name, String destination, String serverName,
|
|
|
|
PortalArg... extraData) { // add stuff for destination names or coordinates
|
2016-03-29 13:38:03 +02:00
|
|
|
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
Material triggerBlockType;
|
|
|
|
String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock");
|
2018-07-23 04:02:42 +02:00
|
|
|
triggerBlockType = Material.getMaterial(BlockID);
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
if (triggerBlockType == null) {
|
2018-07-23 04:02:42 +02:00
|
|
|
triggerBlockType = Material.NETHER_PORTAL;
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
return create(pos1, pos2, name, destination, new HashSet<>(Collections.singletonList(triggerBlockType)),
|
|
|
|
serverName, extraData);
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static void redefine(Location pos1, Location pos2, String name) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
portalData.getConfig().set(name + ".pos1.X", pos1.getX());
|
|
|
|
portalData.getConfig().set(name + ".pos1.Y", pos1.getY());
|
|
|
|
portalData.getConfig().set(name + ".pos1.Z", pos1.getZ());
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
portalData.getConfig().set(name + ".pos2.X", pos2.getX());
|
|
|
|
portalData.getConfig().set(name + ".pos2.Y", pos2.getY());
|
|
|
|
portalData.getConfig().set(name + ".pos2.Z", pos2.getZ());
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
portalData.saveConfig();
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
loadPortals();
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static String getDestination(String portalName) {
|
|
|
|
return portalData.getConfig().getString(portalName + ".destination");
|
|
|
|
}
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static void remove(String name) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
Object[] keys = portalData.getConfig().getKeys(true).toArray();
|
|
|
|
for (int i = keys.length - 1; i >= 0; i--) {
|
|
|
|
String key = keys[i].toString();
|
|
|
|
if (key.startsWith(name + ".")) {
|
|
|
|
portalData.getConfig().set(key, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
portalData.getConfig().set(name, null);
|
2015-02-08 14:08:50 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
// 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); } }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
*/
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
portalData.saveConfig();
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
loadPortals();
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-08 15:44:53 +02:00
|
|
|
public static AdvancedPortal getPortal(String portalName) {
|
|
|
|
for (AdvancedPortal portalElement : Portal.portals) {
|
|
|
|
if (portalElement.getName().equals(portalName)) {
|
|
|
|
return portalElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static boolean portalExists(String portalName) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-07-12 14:27:22 +02:00
|
|
|
String posX = portalData.getConfig().getString(portalName + ".pos1.X");
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
return posX != null;
|
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static boolean activate(Player player, String portalName) {
|
2017-05-19 07:09:57 +02:00
|
|
|
for (AdvancedPortal portal : Portal.portals) {
|
2020-04-06 22:36:46 +02:00
|
|
|
if (portal.getName().equals(portalName))
|
|
|
|
return activate(player, portal);
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
|
|
|
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 23:31:16 +01:00
|
|
|
|
2020-06-21 04:18:26 +02:00
|
|
|
public static boolean activate(Player player, AdvancedPortal portal, boolean doKnockback) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (blockSpectatorMode && player.getGameMode() == GameMode.SPECTATOR) {
|
|
|
|
player.sendMessage(
|
|
|
|
PluginMessages.customPrefixFail + "\u00A7c You cannot enter a portal in spectator mode!");
|
2017-11-30 20:13:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
String permission = portal.getArg("permission");
|
2019-05-31 05:04:48 +02:00
|
|
|
|
|
|
|
if (!(permission == null || player.hasPermission(permission) || player.isOp())) {
|
2020-04-06 22:36:46 +02:00
|
|
|
player.sendMessage(
|
|
|
|
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
|
2017-06-11 20:14:35 +02:00
|
|
|
failSound(player, portal);
|
2020-06-21 04:18:26 +02:00
|
|
|
if(doKnockback)
|
|
|
|
throwPlayerBack(player);
|
2016-03-29 13:38:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
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);
|
2020-06-21 04:18:26 +02:00
|
|
|
if(doKnockback)
|
|
|
|
throwPlayerBack(player);
|
2020-04-06 22:36:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
joinCooldown.remove(player.getName());
|
|
|
|
}
|
|
|
|
|
2020-04-04 17:12:09 +02:00
|
|
|
HashMap<String, Long> cds = cooldown.get(player.getName());
|
|
|
|
if (cds != null) {
|
|
|
|
if (cds.get(portal.getName()) != null) {
|
2020-04-06 22:36:46 +02:00
|
|
|
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"));
|
2020-04-08 18:28:26 +02:00
|
|
|
} catch (Exception ignored) {
|
2020-04-06 22:36:46 +02:00
|
|
|
}
|
|
|
|
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.");
|
2020-04-04 17:12:09 +02:00
|
|
|
failSound(player, portal);
|
2020-06-21 04:18:26 +02:00
|
|
|
if(doKnockback)
|
|
|
|
throwPlayerBack(player);
|
2020-04-04 17:12:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-28 20:13:52 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-06 22:36:46 +02:00
|
|
|
if (cds == null) {
|
2020-04-04 17:12:09 +02:00
|
|
|
cds = new HashMap<String, Long>();
|
|
|
|
}
|
|
|
|
cds.put(portal.getName(), System.currentTimeMillis());
|
|
|
|
cooldown.put(player.getName(), cds);
|
2020-04-06 22:36:46 +02:00
|
|
|
|
2017-04-13 15:41:16 +02:00
|
|
|
boolean showFailMessage = !portal.hasArg("command.1");
|
2016-04-24 18:54:14 +02:00
|
|
|
|
2019-06-03 03:55:44 +02:00
|
|
|
boolean hasMessage = portal.getArg("message") != null;
|
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
// plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation());
|
2017-03-07 01:12:13 +01:00
|
|
|
boolean warped = false;
|
2017-06-13 19:06:48 +02:00
|
|
|
if (portal.getBungee() != null) {
|
2019-06-02 05:39:08 +02:00
|
|
|
String[] bungeeServers = portal.getBungee().split(",");
|
|
|
|
String bungeeServer = bungeeServers[random.nextInt(bungeeServers.length)];
|
2017-05-19 07:09:57 +02:00
|
|
|
if (showBungeeMessage) {
|
2020-04-06 22:36:46 +02:00
|
|
|
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + bungeeServer
|
|
|
|
+ "\u00A7a.");
|
2017-03-07 01:12:13 +01:00
|
|
|
}
|
2020-01-20 11:55:18 +01:00
|
|
|
|
2020-04-08 18:28:26 +02:00
|
|
|
if(portal.hasArg("leavedesti")) {
|
|
|
|
player.setMetadata("leaveDesti", new FixedMetadataValue(plugin, portal.getArg("leavedesti")));
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
|
|
|
player.removeMetadata("leaveDesti", plugin);
|
|
|
|
}, 20 * 10);
|
|
|
|
}
|
|
|
|
|
2020-01-21 12:22:12 +01:00
|
|
|
if (portal.getDestiation() != null) {
|
|
|
|
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
|
2020-06-18 04:37:06 +02:00
|
|
|
outForList.writeUTF(BungeeMessages.ENTER_PORTAL);
|
2020-01-21 12:22:12 +01:00
|
|
|
outForList.writeUTF(bungeeServer);
|
|
|
|
outForList.writeUTF(portal.getDestiation());
|
2020-06-18 04:37:06 +02:00
|
|
|
outForList.writeUTF(player.getUniqueId().toString());
|
|
|
|
outForList.writeUTF(player.getName());
|
2020-01-21 12:22:12 +01:00
|
|
|
|
|
|
|
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
|
|
|
|
}
|
2020-01-20 11:55:18 +01:00
|
|
|
|
|
|
|
ByteArrayDataOutput outForSend = ByteStreams.newDataOutput();
|
|
|
|
outForSend.writeUTF("Connect");
|
|
|
|
outForSend.writeUTF(bungeeServer);
|
|
|
|
|
2020-04-08 18:28:26 +02:00
|
|
|
|
|
|
|
|
2019-06-02 05:39:08 +02:00
|
|
|
portal.inPortal.add(player.getUniqueId());
|
2020-01-20 11:55:18 +01:00
|
|
|
player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray());
|
2020-04-06 22:36:46 +02:00
|
|
|
// Down to bungee to sort out the teleporting but yea theoretically they should
|
|
|
|
// warp.
|
|
|
|
} else if (portal.getDestiation() != null) {
|
2017-03-07 01:12:13 +01:00
|
|
|
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
|
2017-06-13 19:06:48 +02:00
|
|
|
if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) {
|
2019-06-03 03:55:44 +02:00
|
|
|
warped = Destination.warp(player, portal.getDestiation(), hasMessage);
|
2020-04-06 22:36:46 +02:00
|
|
|
if (!warped) {
|
2020-06-21 04:18:26 +02:00
|
|
|
if(doKnockback)
|
|
|
|
throwPlayerBack(player);
|
2017-03-07 13:06:17 +01:00
|
|
|
}
|
2017-03-07 01:12:13 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (showFailMessage) {
|
2020-04-06 22:36:46 +02:00
|
|
|
player.sendMessage(PluginMessages.customPrefixFail
|
|
|
|
+ "\u00A7c The portal you are trying to use doesn't have a destination!");
|
2017-06-13 19:06:48 +02:00
|
|
|
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.getName() + "' has just had a warp "
|
2017-03-07 01:12:13 +01:00
|
|
|
+ "attempt and either the data is corrupt or portal doesn't exist!");
|
2020-06-21 04:18:26 +02:00
|
|
|
if(doKnockback)
|
|
|
|
throwPlayerBack(player);
|
2017-06-11 20:14:35 +02:00
|
|
|
failSound(player, portal);
|
2017-03-07 01:12:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:55:14 +02:00
|
|
|
if (portal.hasArg("command.1")) {
|
2019-05-31 05:04:48 +02:00
|
|
|
warped = true;
|
2016-04-24 18:54:14 +02:00
|
|
|
int commandLine = 1;
|
2020-04-06 22:36:46 +02:00
|
|
|
String command = portal.getArg("command." + commandLine);// portalData.getConfig().getString(portal.getName()+
|
|
|
|
// ".portalArgs.command." + commandLine);
|
2016-04-24 18:54:14 +02:00
|
|
|
do {
|
|
|
|
// (?i) makes the search case insensitive
|
|
|
|
command = command.replaceAll("@player", player.getName());
|
|
|
|
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
|
2020-04-20 14:20:27 +02:00
|
|
|
if (command.startsWith("#") && plugin.getSettings().enabledCommandLevel("c")) {
|
2016-04-24 18:54:14 +02:00
|
|
|
command = command.substring(1);
|
|
|
|
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
|
2020-04-06 22:36:46 +02:00
|
|
|
try {
|
2016-09-01 21:11:07 +02:00
|
|
|
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
2020-04-06 22:36:46 +02:00
|
|
|
} catch (Exception e) {
|
2016-05-15 11:29:52 +02:00
|
|
|
plugin.getLogger().warning("Error while executing: " + command);
|
|
|
|
}
|
2020-04-20 14:20:27 +02:00
|
|
|
} else if (command.startsWith("!") && plugin.getSettings().enabledCommandLevel("o")) {
|
2016-04-24 18:54:14 +02:00
|
|
|
command = command.substring(1);
|
|
|
|
boolean wasOp = player.isOp();
|
|
|
|
try {
|
|
|
|
player.setOp(true);
|
2017-12-02 02:48:59 +01:00
|
|
|
player.chat("/" + command);
|
2020-04-06 22:36:46 +02:00
|
|
|
// player.performCommand(command);
|
2016-04-24 18:54:14 +02:00
|
|
|
} finally {
|
|
|
|
player.setOp(wasOp);
|
|
|
|
}
|
2020-04-20 14:20:27 +02:00
|
|
|
} else if (command.startsWith("^") && plugin.getSettings().enabledCommandLevel("p")) {
|
2016-04-24 18:54:14 +02:00
|
|
|
command = command.substring(1);
|
|
|
|
PermissionAttachment permissionAttachment = null;
|
|
|
|
try {
|
|
|
|
permissionAttachment = player.addAttachment(plugin, "*", true);
|
2017-12-02 02:48:59 +01:00
|
|
|
player.chat("/" + command);
|
2020-04-06 22:36:46 +02:00
|
|
|
// player.performCommand(command);
|
2016-04-24 18:54:14 +02:00
|
|
|
} finally {
|
|
|
|
player.removeAttachment(permissionAttachment);
|
|
|
|
}
|
2020-04-20 14:20:27 +02:00
|
|
|
} else if (command.startsWith("%") && plugin.getSettings().enabledCommandLevel("b")) {
|
|
|
|
command = command.substring(1);
|
|
|
|
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
|
2020-06-18 04:37:06 +02:00
|
|
|
outForList.writeUTF(BungeeMessages.BUNGEE_COMMAND);
|
2020-04-20 14:20:27 +02:00
|
|
|
outForList.writeUTF(command);
|
|
|
|
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
|
2016-04-24 18:54:14 +02:00
|
|
|
} else {
|
2020-04-20 14:20:27 +02:00
|
|
|
player.chat("/" + command);
|
|
|
|
// player.performCommand(command);
|
2016-04-24 18:54:14 +02:00
|
|
|
}
|
|
|
|
command = portal.getArg("command." + ++commandLine);
|
|
|
|
} while (command != null);
|
|
|
|
}
|
2017-03-07 01:12:13 +01:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
if (warped) {
|
|
|
|
if (hasMessage) {
|
2020-06-26 01:42:39 +02:00
|
|
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR,
|
|
|
|
TextComponent.fromLegacyText(portal.getArg("message").replaceAll("&(?=[0-9a-fk-or])", "\u00A7")));
|
2019-06-03 03:55:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 01:12:13 +01:00
|
|
|
return warped;
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2017-06-11 20:14:35 +02:00
|
|
|
private static void failSound(Player player, AdvancedPortal portal) {
|
2020-04-06 22:36:46 +02:00
|
|
|
if (!(portal.getTriggers().contains(Material.NETHER_PORTAL) && player.getGameMode() == GameMode.CREATIVE)) {
|
2018-08-27 22:43:02 +02:00
|
|
|
player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F);
|
2017-06-11 20:14:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
public static void rename(String oldName, String newName) {
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
// set it so it gets all data from one and puts it into another place
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
Set<String> keys = config.getConfig().getKeys(true);
|
|
|
|
for (String key : keys) {
|
|
|
|
if (key.startsWith(oldName + ".")) {
|
|
|
|
if (config.getConfig().getString(key) != null) {
|
|
|
|
try {
|
|
|
|
int intData = Integer.parseInt(config.getConfig().getString(key));
|
|
|
|
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
|
|
|
|
} catch (Exception e) {
|
2020-04-06 22:36:46 +02:00
|
|
|
config.getConfig().set(key.replace(oldName + ".", newName + "."),
|
|
|
|
config.getConfig().getString(key));
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
2015-11-15 23:52:29 +01:00
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config.saveConfig();
|
|
|
|
|
|
|
|
remove(oldName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean addCommand(String portalName, String portalCommand) {
|
|
|
|
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
|
|
|
|
if (portalExists(portalName)) {
|
|
|
|
int commandLine = 0;
|
2020-04-06 22:36:46 +02:00
|
|
|
while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null)
|
|
|
|
; // Loops increasing commandLine till 1 is null
|
2016-03-29 13:38:03 +02:00
|
|
|
config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand);
|
|
|
|
config.saveConfig();
|
|
|
|
loadPortals();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 18:26:04 +02:00
|
|
|
|
2016-08-01 08:45:24 +02:00
|
|
|
public static boolean inPortalTriggerRegion(Location loc) {
|
2017-05-19 07:09:57 +02:00
|
|
|
for (AdvancedPortal portal : Portal.portals)
|
2016-08-01 08:45:24 +02:00
|
|
|
if (Portal.locationInPortalTrigger(portal, loc))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-31 05:04:48 +02:00
|
|
|
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea) {
|
2019-06-02 05:39:08 +02:00
|
|
|
return portal.getTriggers().contains(loc.getBlock().getType()) && locationInPortal(portal, loc, additionalArea);
|
2019-05-31 05:04:48 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 08:45:24 +02:00
|
|
|
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {
|
2019-05-31 05:04:48 +02:00
|
|
|
return locationInPortalTrigger(portal, loc, 0);
|
2016-08-01 08:45:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean inPortalRegion(Location loc, int additionalArea) {
|
2017-05-19 07:09:57 +02:00
|
|
|
for (AdvancedPortal portal : Portal.portals)
|
2016-08-01 08:45:24 +02:00
|
|
|
if (Portal.locationInPortal(portal, loc, additionalArea))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-11 19:32:53 +02:00
|
|
|
public static boolean locationInPortal(Location loc, int additionalArea) {
|
|
|
|
for (AdvancedPortal portal : Portal.portals)
|
|
|
|
if (Portal.locationInPortal(portal, loc, additionalArea))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-31 05:04:48 +02:00
|
|
|
public static boolean locationInPortal(AdvancedPortal portal, Location loc) {
|
|
|
|
return locationInPortal(portal, loc);
|
|
|
|
}
|
|
|
|
|
2016-08-01 08:45:24 +02:00
|
|
|
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
|
|
|
|
if (!portalsActive)
|
|
|
|
return false;
|
2017-06-13 19:06:48 +02:00
|
|
|
if (loc.getWorld() != null && portal.getWorldName().equals(loc.getWorld().getName()))
|
2020-04-06 22:36:46 +02:00
|
|
|
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())
|
2016-08-01 08:45:24 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-04 03:43:58 +02:00
|
|
|
|
2020-04-06 22:36:46 +02:00
|
|
|
public static void throwPlayerBack(Player player) {
|
|
|
|
// Not ensured to remove them out of the portal but it makes it feel nicer for
|
|
|
|
// the player.
|
2016-09-01 21:11:07 +02:00
|
|
|
if (throwback > 0) {
|
|
|
|
Vector velocity = player.getLocation().getDirection();
|
|
|
|
player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(throwback));
|
2016-07-31 18:26:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 19:56:42 +01:00
|
|
|
|
|
|
|
public static int getPortalProtectionRadius() {
|
|
|
|
return portalProtectionRadius;
|
|
|
|
}
|
2020-06-21 04:18:26 +02:00
|
|
|
|
|
|
|
public static boolean activate(Player player, AdvancedPortal portal) {
|
|
|
|
return activate(player, portal, true);
|
|
|
|
}
|
2015-01-15 20:56:13 +01:00
|
|
|
}
|