Added multiple material portals and random bungee tags

This commit is contained in:
Sekwah 2019-06-02 04:39:08 +01:00
parent 232a5334f1
commit 677491a33f
6 changed files with 93 additions and 49 deletions

View File

@ -24,7 +24,7 @@ String getPluginData(String tag) {
version = line.substring(tag.length() + 2, line.length()) version = line.substring(tag.length() + 2, line.length())
} }
} }
System.out.println("Advanced Portals v" + version) println "Advanced Portals v" + version
return version return version
} }
@ -44,11 +44,35 @@ dependencies {
compile "io.netty:netty-all:4.0.4.Final" compile "io.netty:netty-all:4.0.4.Final"
} }
task copyPlugin {
doLast {
copy {
if(System.env.MC_SERVER_LOC == null) {
throw new GradleException('You must set the server location and jar to use')
}
println "$buildDir/libs/Advanced-Portals-${version}.jar"
println "${System.env.MC_SERVER_LOC}/plugins/Advanced-Portals-${version}.jar"
try {
delete fileTree("${System.env.MC_SERVER_LOC}/plugins/") {
include "*.jar"
}
}
catch(UnableToDeleteFileException e) {
println e.getLocalizedMessage()
}
from file("$buildDir/libs/Advanced-Portals-${version}.jar")
into file("${System.env.MC_SERVER_LOC}/plugins/")
}
}
}
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run // Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start // DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
task runJar() { task runJar() {
doLast { doLast {
if(System.env.MC_SERVER_LOC == null || System.env.MC_SERVER_JAR == null) {
throw new GradleException('You must set the server location and jar to use')
}
javaexec { javaexec {
main "-jar" main "-jar"
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar" args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"

View File

@ -18,10 +18,11 @@ import org.bukkit.material.Wool;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private final ArrayList<String> blockMaterialList = new ArrayList<>(); private final List<String> blockMaterialList;
private AdvancedPortalsPlugin plugin; private AdvancedPortalsPlugin plugin;
private int portalArgsStringLength = 0; private int portalArgsStringLength = 0;
@ -33,10 +34,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) { public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.blockMaterialList = Arrays.stream(Material.values()).filter(Material::isBlock).map(Enum::name)
.collect(Collectors.toList());
for(Material material : Material.values()) {
this.blockMaterialList.add("triggerblock:" + material.name());
}
plugin.getCommand("advancedportals").setExecutor(this); plugin.getCommand("advancedportals").setExecutor(this);
} }
@ -86,7 +86,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ItemMeta selectorname = regionselector.getItemMeta(); ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName("\u00A7ePortal Region Selector"); selectorname.setDisplayName("\u00A7ePortal Region Selector");
selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help" selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help"
, "\u00A7r create portals bistowed upon it!")); , "\u00A7r create portals bestowed upon it!"));
regionselector.setItemMeta(selectorname); regionselector.setItemMeta(selectorname);
inventory.addItem(regionselector); inventory.addItem(regionselector);
@ -254,20 +254,18 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand);
} }
Material triggerBlockMat;
if (hasTriggerBlock) { if (hasTriggerBlock) {
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase()); Set<Material> materialSet = Portal.getMaterialSet(triggerBlock.toUpperCase().split(","));
if (triggerBlockMat != null) { if (materialSet.size() != 0) {
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs); portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, portalArgs)); player.sendMessage(Portal.create(pos1, pos2, portalName, destination, materialSet, serverName, portalArgs));
} else { } else {
hasTriggerBlock = false;
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
player.sendMessage("\u00A7cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!"); player.sendMessage("\u00A7c" + triggerBlock.toUpperCase() + " no valid blocks were listed so the default has been set.");
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs); portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs));
@ -741,8 +739,18 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
} }
} }
if(args[args.length-1].startsWith("triggerblock:")) { String triggerBlock = "triggerblock:";
autoComplete.addAll(this.blockMaterialList); if(args[args.length-1].toLowerCase().startsWith(triggerBlock)) {
String currentArg = args[args.length-1];
int length = currentArg.lastIndexOf(',');
String startString;
if(triggerBlock.length() > length) {
startString = triggerBlock;
}
else {
startString = currentArg.substring(0, length+1);
}
autoComplete.addAll(blockMaterialList.stream().map(value -> startString + value).collect(Collectors.toList()));
} }
if(args[args.length-1].startsWith("delayed:")) { if(args[args.length-1].startsWith("delayed:")) {
autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false")); autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false"));

View File

@ -115,12 +115,13 @@ public class Listeners implements Listener {
for (Location loc : locations) { for (Location loc : locations) {
if (delayed == useDelayed) { if (delayed == useDelayed) {
if (delayed ? Portal.locationInPortal(portal, loc, 1) : Portal.locationInPortalTrigger(portal, loc)) { if (delayed ? Portal.locationInPortal(portal, loc, 1) : Portal.locationInPortalTrigger(portal, loc)) {
if (portal.getTrigger().equals(Material.NETHER_PORTAL)) { if (portal.getTriggers().contains(Material.NETHER_PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) { if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10);
} }
} else if (portal.getTrigger().equals(Material.LAVA)) { }
if (portal.getTriggers().contains(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
} }

View File

@ -3,14 +3,12 @@ package com.sekwah.advancedportals.portals;
import com.sekwah.advancedportals.api.portaldata.PortalArg; import com.sekwah.advancedportals.api.portaldata.PortalArg;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.HashSet; import java.util.*;
import java.util.UUID;
public class AdvancedPortal { public class AdvancedPortal {
private Material trigger = null; private Set<Material> triggers = null;
private String worldName = null; private String worldName = null;
@ -47,8 +45,12 @@ public class AdvancedPortal {
} }
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, new HashSet<>(Collections.singletonList(trigger)), pos1, pos2, worldName, portalArgs);
}
public AdvancedPortal(String portalName, Set<Material> triggers, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this.portalName = portalName; this.portalName = portalName;
this.trigger = trigger; this.triggers = triggers;
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
this.worldName = worldName; this.worldName = worldName;
@ -72,8 +74,8 @@ public class AdvancedPortal {
return this.getArg(arg) != null; return this.getArg(arg) != null;
} }
public Material getTrigger() { public Set<Material> getTriggers() {
return this.trigger; return this.triggers;
} }
public String getWorldName() { public String getWorldName() {

View File

@ -14,11 +14,9 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
public class Portal { public class Portal {
@ -35,6 +33,8 @@ public class Portal {
private static int portalProtectionRadius; private static int portalProtectionRadius;
private static boolean blockSpectatorMode; private static boolean blockSpectatorMode;
private static Random random = new Random();
public Portal(AdvancedPortalsPlugin plugin) { public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage", false); this.showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage", false);
@ -74,18 +74,12 @@ public class Portal {
ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString()); ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString());
Material blockType = Material.NETHER_PORTAL; String[] blockTypesString = portalConfigSection.getString("triggerblock").split(",");
String BlockID = portalConfigSection.getString("triggerblock");
try { HashSet<Material> blockTypes = getMaterialSet(blockTypesString);
Integer.parseInt(BlockID);
plugin.getLogger().info("Block names must be given not IDs");
} catch (NumberFormatException e) {
blockType = Material.getMaterial(BlockID);
}
if (blockType == null) { if(blockTypes.size() == 0) {
blockType = Material.NETHER_PORTAL; blockTypes.add(Material.NETHER_PORTAL);
} }
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs"); ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
@ -112,7 +106,7 @@ public class Portal {
PortalArg[] portalArgs = new PortalArg[extraData.size()]; PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs); extraData.toArray(portalArgs);
portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs); portals[portalId] = new AdvancedPortal(portal.toString(), blockTypes, pos1, pos2, worldName, portalArgs);
portals[portalId].setBungee(portalConfigSection.getString("bungee")); portals[portalId].setBungee(portalConfigSection.getString("bungee"));
@ -135,11 +129,23 @@ public class Portal {
} }
} }
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) { public static HashSet<Material> getMaterialSet(String[] blockTypesString) {
return create(pos1, pos2, name, destination, triggerBlock, null, extraData); HashSet<Material> blockTypes = new HashSet<>();
for(String blockType : blockTypesString) {
Material material = Material.getMaterial(blockType);
if(material != null) {
blockTypes.add(material);
}
}
return blockTypes;
} }
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) { public static String create(Location pos1, Location pos2, String name, String destination, Set<Material> triggerBlocks, PortalArg... extraData) {
return create(pos1, pos2, name, destination, triggerBlocks, null, extraData);
}
public static String create(Location pos1, Location pos2, String name, String destination, Set<Material> triggerBlocks, String serverName, PortalArg... portalArgs) {
if (!pos1.getWorld().equals(pos2.getWorld())) { if (!pos1.getWorld().equals(pos2.getWorld())) {
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
@ -186,7 +192,8 @@ public class Portal {
portalData.getConfig().set(name + ".world", pos1.getWorld().getName()); portalData.getConfig().set(name + ".world", pos1.getWorld().getName());
portalData.getConfig().set(name + ".triggerblock", triggerBlock.toString()); String store = triggerBlocks.stream().map(Enum::name).collect(Collectors.joining(","));
portalData.getConfig().set(name + ".triggerblock", store);
portalData.getConfig().set(name + ".destination", destination); portalData.getConfig().set(name + ".destination", destination);
@ -264,7 +271,6 @@ public class Portal {
return false; return false;
} }
@SuppressWarnings("deprecation")
public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
@ -276,7 +282,7 @@ public class Portal {
triggerBlockType = Material.NETHER_PORTAL; triggerBlockType = Material.NETHER_PORTAL;
} }
return create(pos1, pos2, name, destination, triggerBlockType, serverName, extraData); return create(pos1, pos2, name, destination, new HashSet<>(Collections.singletonList(triggerBlockType)), serverName, extraData);
} }
public static void redefine(Location pos1, Location pos2, String name) { public static void redefine(Location pos1, Location pos2, String name) {
@ -388,12 +394,15 @@ public class Portal {
//plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation()); //plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation());
boolean warped = false; boolean warped = false;
if (portal.getBungee() != null) { if (portal.getBungee() != null) {
String[] bungeeServers = portal.getBungee().split(",");
String bungeeServer = bungeeServers[random.nextInt(bungeeServers.length)];
if (showBungeeMessage) { if (showBungeeMessage) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.getBungee() + "\u00A7a."); player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + bungeeServer + "\u00A7a.");
} }
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(portal.getBungee()); out.writeUTF(bungeeServer);
portal.inPortal.add(player.getUniqueId());
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
// Down to bungee to sort out the teleporting but yea theoretically they should warp. // Down to bungee to sort out the teleporting but yea theoretically they should warp.
} }
@ -464,7 +473,7 @@ public class Portal {
} }
private static void failSound(Player player, AdvancedPortal portal) { private static void failSound(Player player, AdvancedPortal portal) {
if(!(portal.getTrigger() == Material.NETHER_PORTAL && player.getGameMode() == GameMode.CREATIVE)){ if(!(portal.getTriggers().contains(Material.NETHER_PORTAL) && player.getGameMode() == GameMode.CREATIVE)){
player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F); player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F);
} }
} }
@ -519,7 +528,7 @@ public class Portal {
} }
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea) { public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea) {
return portal.getTrigger().equals(loc.getBlock().getType()) && locationInPortal(portal, loc, additionalArea); return portal.getTriggers().contains(loc.getBlock().getType()) && locationInPortal(portal, loc, additionalArea);
} }
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) { public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {

View File

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