Added extra checks to in portal as well as fix spam trigger on commands

This commit is contained in:
Sekwah 2020-10-26 03:39:32 +00:00
parent d104da907f
commit 6dd23ddeee
No known key found for this signature in database
GPG Key ID: C3BE2E6C861A461A
9 changed files with 57 additions and 19 deletions

View File

@ -564,7 +564,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (args.length > 2) {
StringBuilder portalCommand = new StringBuilder(args[2]);
for (int i = 3; i < args.length; i++) {
portalCommand.append(args[i]);
portalCommand.append(" ").append(args[i]);
}
if (Portal.addCommand(portalName, portalCommand.toString())) {
sender.sendMessage(

View File

@ -4,6 +4,8 @@ import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.bukkit.PluginMessages;
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import com.sekwah.advancedportals.bukkit.portals.AdvancedPortal;
import com.sekwah.advancedportals.bukkit.portals.Portal;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@ -13,6 +15,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.UUID;
import java.util.logging.Level;
public class Destination {
@ -155,6 +158,16 @@ public class Destination {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."));
}
Location newLoc = player.getLocation();
Location newEyeLoc = player.getEyeLocation();
UUID uuid = player.getUniqueId();
for (AdvancedPortal portal : Portal.portals) {
if (!portal.inPortal.contains(uuid) && !portal.isDelayed()
&& (Portal.locationInPortalTrigger(portal, newLoc) || Portal.locationInPortalTrigger(portal, newEyeLoc))) {
portal.inPortal.add(uuid);
}
}
return true;
} else {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!");

View File

@ -23,7 +23,9 @@ 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;
public class Listeners implements Listener {
@ -93,11 +95,19 @@ public class Listeners implements Listener {
Portal.joinCooldown.put(player.getName(), System.currentTimeMillis());
String uuid = player.getUniqueId().toString();
Location loc = player.getLocation();
Location eyeLoc = player.getEyeLocation();
UUID uuid = player.getUniqueId();
for (AdvancedPortal portal : Portal.portals) {
if (!portal.inPortal.contains(uuid)
&& (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc))) {
portal.inPortal.add(uuid);
}
}
if (plugin.PlayerDestiMap.containsKey(uuid)) {
Destination.warp(player, plugin.PlayerDestiMap.get(uuid), false, true);
plugin.PlayerDestiMap.remove(uuid);
if (plugin.PlayerDestiMap.containsKey(uuid.toString())) {
Destination.warp(player, plugin.PlayerDestiMap.get(uuid.toString()), false, true);
plugin.PlayerDestiMap.remove(uuid.toString());
}
}
@ -110,20 +120,19 @@ public class Listeners implements Listener {
Player player = event.getPlayer();
Location loc = event.getTo();
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
checkTriggerLocations(player, false, loc, eyeLoc);
checkTriggerLocations(player, false, event.getTo(), player.getEyeLocation());
}
public void checkTriggerLocations(Player player, boolean useDelayed, Location... locations) {
for (AdvancedPortal portal : Portal.portals) {
boolean delayed = portal.hasArg("delayed") && portal.getArg("delayed").equalsIgnoreCase("true");
boolean removeInPortal = true;
boolean delayed = portal.isDelayed();
for (Location loc : locations) {
if (delayed == useDelayed) {
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));
@ -145,10 +154,12 @@ public class Listeners implements Listener {
if (!delayed)
portal.inPortal.add(player.getUniqueId());
return;
} else if (!delayed)
portal.inPortal.remove(player.getUniqueId());
}
}
}
if(removeInPortal) {
portal.inPortal.remove(player.getUniqueId());
}
}
}

View File

@ -83,6 +83,7 @@ public class PortalPlacer implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
Block newBlock = block.getWorld().getBlockAt(block.getLocation());
Material material = block.getType();
if (material == Material.NETHER_PORTAL && Portal.inPortalRegion(block.getLocation(), Portal.getPortalProtectionRadius()))
event.setCancelled(true);

View File

@ -112,4 +112,8 @@ public class AdvancedPortal {
public void setBungee(String bungee) {
this.bungee = bungee;
}
public boolean isDelayed() {
return this.hasArg("delayed") && this.getArg("delayed").equalsIgnoreCase("true");
}
}

View File

@ -417,12 +417,19 @@ public class Portal {
String permission = portal.getArg("permission");
boolean noMessage = permission != null && permission.startsWith("nomsg.");
if(noMessage) {
permission.substring(6);
}
if (!(permission == null || player.hasPermission(permission) || player.isOp())) {
player.sendMessage(
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
failSound(player, portal);
if(doKnockback)
throwPlayerBack(player);
if(!noMessage) {
player.sendMessage(
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
failSound(player, portal);
if(doKnockback)
throwPlayerBack(player);
}
return false;
}

View File

@ -18,6 +18,8 @@ public class AdvancedPortalsPlugin extends Plugin {
public void onEnable() {
getProxy().registerChannel(channelName);
if(channelName != null)
getProxy().getPluginManager().registerListener(this, new PluginMessageReceiver(this));
getProxy().getPluginManager().registerListener(this, new EventListener(this));

View File

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

View File

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