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())
}
}
System.out.println("Advanced Portals v" + version)
println "Advanced Portals v" + version
return version
}
@ -44,11 +44,35 @@ dependencies {
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
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
task runJar() {
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 {
main "-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 java.util.*;
import java.util.stream.Collectors;
public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private final ArrayList<String> blockMaterialList = new ArrayList<>();
private final List<String> blockMaterialList;
private AdvancedPortalsPlugin plugin;
private int portalArgsStringLength = 0;
@ -33,10 +34,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
public AdvancedPortalsCommand(AdvancedPortalsPlugin 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);
}
@ -86,7 +86,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName("\u00A7ePortal Region Selector");
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);
inventory.addItem(regionselector);
@ -254,20 +254,18 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand);
}
Material triggerBlockMat;
if (hasTriggerBlock) {
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
if (triggerBlockMat != null) {
Set<Material> materialSet = Portal.getMaterialSet(triggerBlock.toUpperCase().split(","));
if (materialSet.size() != 0) {
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
PortalArg[] portalArgs = new PortalArg[extraData.size()];
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 {
hasTriggerBlock = false;
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
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()];
portalArgs = extraData.toArray(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:")) {
autoComplete.addAll(this.blockMaterialList);
String triggerBlock = "triggerblock:";
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:")) {
autoComplete.addAll(Arrays.asList("delayed:true", "delayed:false"));

View File

@ -115,12 +115,13 @@ public class Listeners implements Listener {
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 (portal.getTriggers().contains(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)) {
}
if (portal.getTriggers().contains(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
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 org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.UUID;
import java.util.*;
public class AdvancedPortal {
private Material trigger = null;
private Set<Material> triggers = 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) {
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.trigger = trigger;
this.triggers = triggers;
this.pos1 = pos1;
this.pos2 = pos2;
this.worldName = worldName;
@ -72,8 +74,8 @@ public class AdvancedPortal {
return this.getArg(arg) != null;
}
public Material getTrigger() {
return this.trigger;
public Set<Material> getTriggers() {
return this.triggers;
}
public String getWorldName() {

View File

@ -14,11 +14,9 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Portal {
@ -35,6 +33,8 @@ public class Portal {
private static int portalProtectionRadius;
private static boolean blockSpectatorMode;
private static Random random = new Random();
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage", false);
@ -74,18 +74,12 @@ public class Portal {
ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString());
Material blockType = Material.NETHER_PORTAL;
String BlockID = portalConfigSection.getString("triggerblock");
String[] blockTypesString = portalConfigSection.getString("triggerblock").split(",");
try {
Integer.parseInt(BlockID);
plugin.getLogger().info("Block names must be given not IDs");
} catch (NumberFormatException e) {
blockType = Material.getMaterial(BlockID);
}
HashSet<Material> blockTypes = getMaterialSet(blockTypesString);
if (blockType == null) {
blockType = Material.NETHER_PORTAL;
if(blockTypes.size() == 0) {
blockTypes.add(Material.NETHER_PORTAL);
}
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
@ -112,7 +106,7 @@ public class Portal {
PortalArg[] portalArgs = new PortalArg[extraData.size()];
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"));
@ -135,11 +129,23 @@ public class Portal {
}
}
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) {
return create(pos1, pos2, name, destination, triggerBlock, null, extraData);
public static HashSet<Material> getMaterialSet(String[] blockTypesString) {
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())) {
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 + ".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);
@ -264,7 +271,6 @@ public class Portal {
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
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
@ -276,7 +282,7 @@ public class 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) {
@ -388,12 +394,15 @@ public class Portal {
//plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation());
boolean warped = false;
if (portal.getBungee() != null) {
String[] bungeeServers = portal.getBungee().split(",");
String bungeeServer = bungeeServers[random.nextInt(bungeeServers.length)];
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();
out.writeUTF("Connect");
out.writeUTF(portal.getBungee());
out.writeUTF(bungeeServer);
portal.inPortal.add(player.getUniqueId());
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
// 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) {
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);
}
}
@ -519,7 +528,7 @@ public class Portal {
}
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) {

View File

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