Added throwback distance

This commit is contained in:
Alastair 2016-09-01 19:11:07 +00:00
parent 0070d70c8e
commit 412dd428dd
1 changed files with 17 additions and 104 deletions

View File

@ -5,16 +5,13 @@ import com.google.common.io.ByteStreams;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.PluginMessages;
import com.sekwah.advancedportals.api.portaldata.PortalArg;
import com.sekwah.advancedportals.destinations.Destination;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import com.sekwah.advancedportals.api.portaldata.PortalArg;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
@ -22,6 +19,7 @@ import java.util.Set;
import java.util.logging.Level;
public class Portal {
public static HashMap<Player, Long> cooldown = new HashMap<Player, Long>();
// Config values
public static boolean portalsActive = false;
@ -29,12 +27,14 @@ public class Portal {
private static AdvancedPortalsPlugin plugin;
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
private static boolean ShowBungeeMessage;
private static int cooldelay = 5;
private static int cooldelay;
private static double throwback;
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
cooldelay = config.getConfig().getInt("Cooldown");
cooldelay = config.getConfig().getInt("PortalCooldown", 5);
throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7);
Portal.plugin = plugin;
Portal.loadPortals();
@ -370,6 +370,7 @@ public class Portal {
// 3 checks, 1st is if it doesnt need perms. 2nd is if it does do they have it. And third is are they op.
if (!(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7c You do not have permission to use this portal!");
throwPlayerBack(player);
return false;
}
@ -377,6 +378,7 @@ public class Portal {
int diff = (int) ((System.currentTimeMillis() - cooldown.get(player)) / 1000);
if (diff < cooldelay) {
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + (cooldelay - diff) + ChatColor.RED + " seconds until attempting to teleport again.");
throwPlayerBack(player);
return false;
}
}
@ -395,7 +397,7 @@ public class Portal {
command = command.substring(1);
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
try{
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
catch(Exception e){
plugin.getLogger().warning("Error while executing: " + command);
@ -446,6 +448,7 @@ public class Portal {
player.sendMessage(PluginMessages.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or portal doesn't exist!");
throwPlayerBack(player);
}
}
return false;
@ -524,101 +527,11 @@ public class Portal {
return false;
}
public static AdvancedPortal locationInPortal(Location loc){
return locationInPortal(loc, 0);
}
/**
* Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0.
* @param loc
* @param additionalArea
* @return
*/
public static AdvancedPortal locationInPortal(Location loc, int additionalArea){
if (!Portal.portalsActive) {
return null;
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));
}
for (AdvancedPortal portal : Portal.Portals) {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) {
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) {
return portal;
}
}
}
}
return null;
}
public static AdvancedPortal blockLocationInPortal(Location loc){
return locationInPortal(loc, 0);
}
public static AdvancedPortal blockLocationInPortal(Location loc, int additionalArea){
if (!Portal.portalsActive) {
return null;
}
for (AdvancedPortal portal : Portal.Portals) {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if ((portal.pos1.getX() + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + additionalArea) >= loc.getZ()) {
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) {
return portal;
}
}
}
}
return null;
}
/**
* Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0.
* @param player
* @param loc
* @param additionalArea
* @return
*/
public static AdvancedPortal playerInPortal(Player player, Location loc, int additionalArea){
if (!Portal.portalsActive) {
return null;
}
if(loc == null){
loc = player.getLocation();
}
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
for (AdvancedPortal portal : Portal.Portals) {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if (portal.trigger.equals(loc.getBlock().getType())
|| portal.trigger.equals(eyeLoc.getBlock().getType())) {
if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) {
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) {
return portal;
}
}
}
}
}
return null;
}
public static AdvancedPortal playerInPortal(Player player){
return playerInPortal(player, null, 0);
}
public static AdvancedPortal playerInPortal(Player player, Location loc){
return playerInPortal(player, loc, 0);
}
public static AdvancedPortal playerInPortal(Player player, int additionalArea){
return playerInPortal(player, null, additionalArea);
}
}