Fixed an issue with spam re-triggering on portal events

This commit is contained in:
Sekwah 2020-11-28 17:07:24 +00:00
parent 9a2ff28ab9
commit 9279be58aa
No known key found for this signature in database
GPG Key ID: C3BE2E6C861A461A
7 changed files with 41 additions and 33 deletions

View File

@ -6,6 +6,8 @@ public class ConfigHelper {
public static String CONFIG_VERSION = "ConfigVersion";
public static String COMMAND_LOGS = "CommandLogs";
public static String DISABLE_GATEWAY_BEAM = "DisableGatewayBeam";
private FileConfiguration config;
@ -20,10 +22,14 @@ public class ConfigHelper {
public void update() {
String configVersion = config.getString("ConfigVersion");
// Added in 0.5.4
if(configVersion == null || configVersion.equals("0.5.3")) {
if(configVersion == null || configVersion.equals("true") || configVersion.equals("0.5.3")) {
config.set(ConfigHelper.CONFIG_VERSION, "0.5.4");
config.set(ConfigHelper.CONFIG_VERSION, true);
config.set(ConfigHelper.DISABLE_GATEWAY_BEAM, true);
update();
} else if(configVersion.equals("0.5.4")) {
config.set(ConfigHelper.CONFIG_VERSION, "0.5.11");
config.set(ConfigHelper.COMMAND_LOGS, true);
}
}
}

View File

@ -23,7 +23,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
@ -83,7 +82,7 @@ public class Listeners implements Listener {
@EventHandler
public void onLeaveEvent(PlayerQuitEvent event) {
Player player = event.getPlayer();
if(player.hasMetadata("leaveDesti")) {
if (player.hasMetadata("leaveDesti")) {
Destination.warp(player, player.getMetadata("leaveDesti").get(0).asString(),
false, true);
}
@ -91,24 +90,24 @@ public class Listeners implements Listener {
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
Player player = event.getPlayer();
Portal.joinCooldown.put(player.getName(), System.currentTimeMillis());
Portal.joinCooldown.put(player.getName(), System.currentTimeMillis());
Location loc = player.getLocation();
Location eyeLoc = player.getEyeLocation();
UUID uuid = player.getUniqueId();
for (AdvancedPortal portal : Portal.portals) {
if (!portal.inPortal.contains(uuid)
for (AdvancedPortal portal : Portal.portals) {
if (!portal.inPortal.contains(uuid)
&& (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc))) {
portal.inPortal.add(uuid);
portal.inPortal.add(uuid);
}
}
if (plugin.PlayerDestiMap.containsKey(uuid.toString())) {
if (plugin.PlayerDestiMap.containsKey(uuid.toString())) {
Destination.warp(player, plugin.PlayerDestiMap.get(uuid.toString()), false, true);
plugin.PlayerDestiMap.remove(uuid.toString());
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -126,13 +125,11 @@ public class Listeners implements Listener {
public void checkTriggerLocations(Player player, boolean useDelayed, Location... locations) {
for (AdvancedPortal portal : Portal.portals) {
boolean removeInPortal = true;
boolean delayed = portal.isDelayed();
for (Location loc : locations) {
if (delayed == useDelayed) {
if (delayed == useDelayed) {
for (Location loc : locations) {
if (delayed ? Portal.locationInPortal(portal, loc, 1)
: Portal.locationInPortalTrigger(portal, loc)) {
removeInPortal = false;
if (portal.getTriggers().contains(Material.NETHER_PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
@ -156,8 +153,6 @@ public class Listeners implements Listener {
return;
}
}
}
if(removeInPortal) {
portal.inPortal.remove(player.getUniqueId());
}
}
@ -236,7 +231,9 @@ public class Listeners implements Listener {
player.removeMetadata("lavaWarped", plugin);
player.setFireTicks(0);
}
};
}
;
class RemoveWarpData implements Runnable {
@ -304,11 +301,11 @@ public class Listeners implements Listener {
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
// name to
// the
// metadata
// of the
// character
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
@ -324,7 +321,7 @@ public class Listeners implements Listener {
if (event.getItem() != null && event.getItem().getType() == WandMaterial // was type id
&& (!UseOnlyServerAxe || (checkItemForName(event.getItem()) && event.getItem().getItemMeta()
.getDisplayName().equals("\u00A7ePortal Region Selector")))) {
.getDisplayName().equals("\u00A7ePortal Region Selector")))) {
// This checks if the action was a left or right click and if it was directly
// effecting a block.

View File

@ -43,9 +43,8 @@ public class PortalPlacer implements Listener {
if(name == null) return;
if (name.equals("\u00A75Portal Block Placer")){
event.getBlockPlaced().setType(Material.NETHER_PORTAL);
}
else if (name.equals("\u00A78End Portal Block Placer")){
event.getBlock().setType(Material.NETHER_PORTAL);
} else if (name.equals("\u00A78End Portal Block Placer")){
event.getBlockPlaced().setType(Material.END_PORTAL);
}
else if (name.equals("\u00A78Gateway Block Placer")){

View File

@ -6,6 +6,7 @@ import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.bukkit.PluginMessages;
import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg;
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.config.ConfigHelper;
import com.sekwah.advancedportals.bukkit.destinations.Destination;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import com.sekwah.advancedportals.bungee.BungeeMessages;
@ -37,6 +38,7 @@ public class Portal {
private static int portalProtectionRadius;
private static boolean blockSpectatorMode;
private static int joinCooldownDelay;
private static boolean commandLog;
private static Random random = new Random();
public Portal(AdvancedPortalsPlugin plugin) {
@ -53,6 +55,8 @@ public class Portal {
this.joinCooldownDelay = config.getConfig().getInt("PortalCooldown", 5);
this.commandLog = config.getConfig().getBoolean(ConfigHelper.COMMAND_LOGS, true);
Portal.plugin = plugin;
Portal.loadPortals();
}
@ -550,10 +554,9 @@ public class Portal {
do {
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
if(commandLog) plugin.getLogger().log(Level.INFO, "Portal command: " + command);
if (command.startsWith("#") && plugin.getSettings().enabledCommandLevel("c")) {
command = command.substring(1);
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
try {
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (Exception e) {

View File

@ -1,4 +1,4 @@
main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.5.10
version: 0.5.11
author: sekwah41

View File

@ -3,7 +3,7 @@
# To set this file back to its default state just delete it and reload the server or restart it!
# Will update whenever there is a config update from an older version so may not be the latest plugin version
ConfigVersion: 0.5.4
ConfigVersion: 0.5.10
# Set to true if you want the normal axes to work normally but the ones gived with /portals selector or wand will still work though
# It can be usefull if people with permission want to use an iron axe on a survival server
@ -25,7 +25,7 @@ PortalProtectionArea: 5
DefaultPortalTriggerBlock: PORTAL
# This stops all water flowing inside a portal area(can be disabled if something like world edit is handelling the water flow or you dont want it active)
# you want to
# you want to
StopWaterFlow: true
# This must be a placeable block or it will not work and may even crash
@ -85,3 +85,6 @@ DisableGatewayBeam: true
# b enable bungee command portals
#
CommandLevels: opcb
# Should the commands being triggered log in the console? (If you have an active server it may cause a bit of spam)
CommandLogs: true

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.5.10
version: 0.5.11
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13