Added new delay command

This commit is contained in:
Sekwah 2019-05-31 04:04:48 +01:00
parent 7a0b65187b
commit 232a5334f1
5 changed files with 80 additions and 49 deletions

View File

@ -142,6 +142,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasDestination = false;
boolean isBungeePortal = false;
boolean needsPermission = false;
boolean delayed = false;
boolean executesCommand = false;
String destination = null;
String portalName = null;
@ -152,6 +153,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ArrayList<PortalArg> extraData = new ArrayList<>();
// Is completely changed in the recode but for now im leaving it as this horrible mess...
for (int i = 1; i < args.length; i++) {
if (args[i].toLowerCase().startsWith("name:") && args[i].length() > 5) {
hasName = true;
@ -178,6 +180,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
needsPermission = true;
permission = args[i].toLowerCase().replaceFirst("permission:", "");
extraData.add(new PortalArg("permission", permission));
} else if (args[i].toLowerCase().startsWith("delayed:") && args[i].length() > 8) {
delayed = Boolean.parseBoolean(args[i].toLowerCase().replaceFirst("delayed:", ""));
extraData.add(new PortalArg("delayed", Boolean.toString(delayed)));
} else if (args[i].toLowerCase().startsWith("command:") && args[i].length() > 8) {
executesCommand = true;
portalCommand = parseArgVariable(args, i, "command:");
@ -243,6 +248,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7apermission: \u00A7e(none needed)");
}
player.sendMessage("\u00A7adelayed: \u00A7e" + delayed);
if (executesCommand) {
player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand);
}
@ -661,6 +668,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasName = false;
boolean hasTriggerBlock = false;
boolean hasDestination = false;
boolean hasDelay = false;
boolean isBungeePortal = false;
boolean needsPermission = false;
boolean hasCommand = false;
@ -690,6 +698,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
case "permission":
needsPermission = true;
break;
case "delayed":
hasDelay = true;
break;
case "command":
hasCommand = true;
break;
@ -714,6 +725,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (!needsPermission) {
autoComplete.add("permission:");
}
if (!hasDelay) {
autoComplete.add("delayed:");
}
if (!hasCommand) {
autoComplete.add("command:");
}
@ -730,6 +744,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if(args[args.length-1].startsWith("triggerblock:")) {
autoComplete.addAll(this.blockMaterialList);
}
if(args[args.length-1].startsWith("delayed:")) {
autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false"));
}
if(args[args.length-1].startsWith("desti:") || args[args.length-1].startsWith("destination:")) {
String tagStart = args[args.length-1].startsWith("desti:") ? "desti:" : "destination:";
ConfigAccessor destiConfig = new ConfigAccessor(plugin, "destinations.yml");

View File

@ -8,6 +8,7 @@ import com.sekwah.advancedportals.injector.PacketInjector;
import com.sekwah.advancedportals.listeners.*;
import com.sekwah.advancedportals.metrics.Metrics;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
@ -83,6 +84,12 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
this.setEnabled(false);
}
for (Player player:
this.getServer().getOnlinePlayers()) {
player.removeMetadata("hasWarped", this);
player.removeMetadata("lavaWarped", this);
}
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
// only copy the file if it doesnt exist!
}

View File

@ -7,12 +7,8 @@ import com.sekwah.advancedportals.api.events.WarpEvent;
import com.sekwah.advancedportals.portals.AdvancedPortal;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Orientable;
import org.bukkit.block.data.Rotatable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -28,8 +24,7 @@ import org.bukkit.metadata.FixedMetadataValue;
import java.util.UUID;
public class Listeners implements Listener {
// 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;
private static Material WandMaterial;
@ -106,36 +101,46 @@ public class Listeners implements Listener {
}
Player player = event.getPlayer();
//Location fromloc = event.getFrom();
Location loc = event.getTo();
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
checkTriggerLocations(player, false, loc, eyeLoc);
}
public void checkTriggerLocations(Player player, boolean useDelayed, Location... locations) {
for (AdvancedPortal portal : Portal.portals) {
if (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc)) {
if (portal.getTrigger().equals(Material.NETHER_PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10);
}
} else if (portal.getTrigger().equals(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
boolean delayed = portal.hasArg("delayed") && portal.getArg("delayed").equalsIgnoreCase("true");
for (Location loc : locations) {
if (delayed == useDelayed) {
if (delayed ? Portal.locationInPortal(portal, loc, 1) : Portal.locationInPortalTrigger(portal, loc)) {
if (portal.getTrigger().equals(Material.NETHER_PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10);
}
} else if (portal.getTrigger().equals(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
}
if (portal.inPortal.contains(player.getUniqueId())) return;
WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!warpEvent.isCancelled()) Portal.activate(player, portal);
if (!delayed) portal.inPortal.add(player.getUniqueId());
return;
} else if (!delayed) portal.inPortal.remove(player.getUniqueId());
}
if (portal.inPortal.contains(player.getUniqueId())) return;
WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!warpEvent.isCancelled()) Portal.activate(player, portal);
portal.inPortal.add(player.getUniqueId());
} else portal.inPortal.remove(player.getUniqueId());
}
}
}
// These are here because java 7 can only take finals straight into a runnable
class RemoveLavaData implements Runnable{
private Player player;
public RemoveLavaData(Player player){
@ -164,7 +169,7 @@ public class Listeners implements Listener {
player.removeMetadata("hasWarped", plugin);
}
}
};
}
@EventHandler
public void onCombustEntityEvent(EntityCombustEvent event) {
@ -183,7 +188,18 @@ public class Listeners implements Listener {
@EventHandler
public void onPortalEvent(PlayerPortalEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (!player.hasMetadata("hasWarped")) {
Location loc = event.getFrom();
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
checkTriggerLocations(player, true, loc, eyeLoc);
}
if (player.hasMetadata("hasWarped") | Portal.inPortalRegion(event.getFrom(),1))
event.setCancelled(true);
}
@ -212,16 +228,6 @@ public class Listeners implements Listener {
if (player.hasPermission("advancedportals.createportal")) {
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
// as a weapon.
// Null pointer exeption detected here on some servers(try decompiling the jar file to double check)
/*try {
// Use this to surround the code if needed
}
catch(NullPointerException e){
}*/
if (event.getItem() != null && event.getItem().getType() == WandMaterial // was type id
&& (!UseOnlyServerAxe || (checkItemForName(event.getItem()) && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) {

View File

@ -359,22 +359,14 @@ public class Portal {
public static boolean activate(Player player, AdvancedPortal portal) {
// add other variables or filter code here, or somehow have a way to register them
// TODO on load and unload recode the permissions to try to register themselves
// https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginManager.html#addPermission(org.bukkit.permissions.Permission)
// check they havent been registered before too and store a list of ones made by this plugin to remove when portals are unloaded.
// When a portal is added or removed it reloads all portals(i think) so add code for unloading too.
if(blockSpectatorMode && player.getGameMode() == GameMode.SPECTATOR) {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c You cannot enter a portal in spectator mode!");
return false;
}
String permission = portal.getArg("permission");
/*if((permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())){*/
// 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())) {
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);
throwPlayerBack(player);
@ -424,6 +416,7 @@ public class Portal {
}
if (portal.hasArg("command.1")) {
warped = true;
int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.getName()+ ".portalArgs.command." + commandLine);
do {
@ -525,8 +518,12 @@ public class Portal {
return false;
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea) {
return portal.getTrigger().equals(loc.getBlock().getType()) && locationInPortal(portal, loc, additionalArea);
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {
return portal.getTrigger().equals(loc.getBlock().getType()) && locationInPortal(portal, loc, 0);
return locationInPortalTrigger(portal, loc, 0);
}
public static boolean inPortalRegion(Location loc, int additionalArea) {
@ -543,6 +540,10 @@ public class Portal {
return false;
}
public static boolean locationInPortal(AdvancedPortal portal, Location loc) {
return locationInPortal(portal, loc);
}
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
if (!portalsActive)
return false;

View File

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