mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-12-26 02:48:15 +01:00
Add a cooldown
This commit is contained in:
parent
5bf7b71b65
commit
252187c404
@ -69,3 +69,5 @@ UseCustomPrefix: false
|
||||
CustomPrefix: '&a[&eAdvancedPortals&a]'
|
||||
|
||||
CustomPrefixFail: '&c[&7AdvancedPortals&c]'
|
||||
|
||||
Cooldown: 5 # In Seconds, -1 to disable
|
||||
|
@ -30,6 +30,7 @@ import java.util.HashMap;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
|
||||
private HashMap<Player, Boolean> inPortal = new HashMap<Player, Boolean>();
|
||||
// The needed config values will be stored so they are easier to access later
|
||||
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP...
|
||||
private static boolean UseOnlyServerAxe = false;
|
||||
@ -83,7 +84,7 @@ public class Listeners implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (inPortal.get(player) == null) inPortal.put(player, false);
|
||||
Location fromloc = event.getFrom();
|
||||
Location loc = event.getTo();
|
||||
// Potentially fixes that stupid error cauzed by a bukkit update.
|
||||
@ -99,11 +100,9 @@ public class Listeners implements Listener {
|
||||
|| portal.trigger.equals(eyeLoc.getBlock().getType())) {
|
||||
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY()) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
|
||||
if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) {
|
||||
|
||||
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
|
||||
if (inPortal.get(player)) return;
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal);
|
||||
if (PortalMessagesDisplay == 1 && warped) {
|
||||
@ -116,16 +115,6 @@ public class Listeners implements Listener {
|
||||
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
|
||||
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||
}
|
||||
|
||||
if (warped) {
|
||||
//event.setFrom(player.getLocation());
|
||||
//event.setTo(player.getLocation());
|
||||
|
||||
//event.setCancelled(true);
|
||||
} else {
|
||||
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (portal.trigger.equals(Material.PORTAL)) {
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
@ -136,12 +125,14 @@ public class Listeners implements Listener {
|
||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
|
||||
}
|
||||
|
||||
inPortal.put(player, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
inPortal.put(player, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
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;
|
||||
@ -14,20 +15,24 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
|
||||
private static AdvancedPortalsPlugin plugin;
|
||||
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
|
||||
private static boolean ShowBungeeMessage;
|
||||
private static int cooldelay = 5;
|
||||
|
||||
public Portal(AdvancedPortalsPlugin plugin) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
|
||||
cooldelay = config.getConfig().getInt("Cooldown");
|
||||
|
||||
Portal.plugin = plugin;
|
||||
Portal.loadPortals();
|
||||
@ -366,6 +371,14 @@ public class Portal {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cooldown.get(player) != null) {
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cooldown.put(player, System.currentTimeMillis());
|
||||
boolean showFailMessage = true;
|
||||
|
||||
if (portal.getArg("command.1") != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user