mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-12-27 19:37:44 +01:00
commit
0714278fbb
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
*.class
|
||||
.*
|
||||
/target/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
|
@ -69,3 +69,5 @@ UseCustomPrefix: false
|
||||
CustomPrefix: '&a[&eAdvancedPortals&a]'
|
||||
|
||||
CustomPrefixFail: '&c[&7AdvancedPortals&c]'
|
||||
|
||||
Cooldown: 5 # In Seconds, -1 to disable
|
||||
|
40
pom.xml
Normal file
40
pom.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.sekwah.advancedportals</groupId>
|
||||
<artifactId>Advanced-Portals</artifactId>
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/Resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<version>0.0.20-snapshot</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- spigot's buildtools automatically places it in maven's repository after building it -->
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,8 +1,9 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import com.sekwah.advancedportals.api.portaldata.PortalArg;
|
||||
import com.sekwah.advancedportals.listeners.Listeners;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import com.sekwah.advancedportals.portals.PortalArg;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -38,12 +39,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
Player player = (Player) sender;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
if (sender.hasPermission("advancedportals.portal")) {
|
||||
if (args.length > 0) {
|
||||
if (args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")) {
|
||||
Player player = (Player) sender;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
if (args.length > 0) { switch (args[0].toLowerCase()) {
|
||||
case "wand":
|
||||
case "selector":
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
|
||||
@ -62,17 +64,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
inventory.addItem(regionselector);
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!");
|
||||
} else if (args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")) {
|
||||
Player player = (Player) sender;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
break;
|
||||
case "portal":
|
||||
case "portalblock":
|
||||
ItemStack portalBlock = new ItemStack(Material.PORTAL, 1);
|
||||
|
||||
inventory.addItem(portalBlock);
|
||||
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!");
|
||||
} else if (args[0].toLowerCase().equals("create")) {
|
||||
Player player = (Player) sender;
|
||||
break;
|
||||
case "create":
|
||||
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
|
||||
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
|
||||
if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something
|
||||
@ -207,14 +208,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
} else {
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have two points selected to make a portal!");
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("variables")) {
|
||||
break;
|
||||
case "variables" :
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination");
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
|
||||
} else if (args[0].toLowerCase().equals("select")) {
|
||||
|
||||
break;
|
||||
case "select":
|
||||
// TODO finish the select command and the hit block to replace!
|
||||
Player player = (Player) sender;
|
||||
if (!player.hasMetadata("selectingPortal")) {
|
||||
if (args.length > 1) {
|
||||
if (Portal.portalExists(args[1])) {
|
||||
@ -231,8 +232,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!");
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("gui")) {
|
||||
Player player = (Player) sender;
|
||||
break;
|
||||
case "gui" :
|
||||
if (args.length > 1) {
|
||||
if (args[1].toLowerCase().equals("remove") && args.length > 2) {
|
||||
sender.sendMessage("");
|
||||
@ -243,9 +244,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("");
|
||||
}
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("edit")) {
|
||||
Player player = (Player) sender;
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
break;
|
||||
case "edit":
|
||||
if (args.length > 1) {
|
||||
if (Portal.portalExists(args[1])) {
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
|
||||
@ -267,12 +267,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!");
|
||||
}
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("rename")) {
|
||||
break;
|
||||
case "rename":
|
||||
|
||||
// not finished yet /
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
if (args.length > 1) {
|
||||
Player player = (Player) sender;
|
||||
if (player.hasMetadata("selectedPortal")) {
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
if (portalName.toLowerCase() != args[1].toLowerCase()) {
|
||||
@ -298,8 +297,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
} else {
|
||||
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!");
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("command")) {
|
||||
Player player = (Player) sender;
|
||||
break;
|
||||
case "command":
|
||||
if (player.hasMetadata("selectedPortal")) {
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
if (args.length > 1) {
|
||||
@ -333,8 +332,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("remove")) {
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length > 1) {
|
||||
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
|
||||
if (posX != null) {
|
||||
@ -344,7 +343,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!");
|
||||
}
|
||||
} else {
|
||||
Player player = (Player) sender;
|
||||
if (player.hasMetadata("selectedPortal")) {
|
||||
String portalName = player.getMetadata("selectedPortal").get(0).asString();
|
||||
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
|
||||
@ -359,16 +357,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!");
|
||||
}
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("help")) {
|
||||
break;
|
||||
case "help":
|
||||
case "helppage":
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Still designing in game help page :(");
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] For now please use the wiki http://bit.ly/portals-help");
|
||||
} else if (args[0].toLowerCase().equals("bukkitpage")) {
|
||||
break;
|
||||
case "bukkitpage":
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!");
|
||||
} else if (args[0].toLowerCase().equals("helppage")) {
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: http://bit.ly/portals-help!");
|
||||
} else if (args[0].toLowerCase().equals("show")) {
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
Player player = (Player) sender;
|
||||
break;
|
||||
case "show":
|
||||
if (args.length > 1) {
|
||||
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
|
||||
if (posX != null) {
|
||||
@ -377,28 +375,37 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!");
|
||||
}
|
||||
} else {
|
||||
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
|
||||
if (player.hasMetadata("selectedPortal")) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected portal has been shown, it will dissapear shortly!");
|
||||
Selection.Show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString());
|
||||
} else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
|
||||
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!");
|
||||
Selection.Show(player, this.plugin);
|
||||
} else {
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!");
|
||||
Selection.Show(player, this.plugin, null);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!");
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No regions selected!");
|
||||
}
|
||||
}
|
||||
} else if (args[0].toLowerCase().equals("reload")) {
|
||||
break;
|
||||
case "reload":
|
||||
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
} else {
|
||||
break;
|
||||
case "list" :
|
||||
String message = "\u00A7eAdvancedPortals\u00A7a :";
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
message = message + " " + portal.portalName;
|
||||
}
|
||||
player.sendMessage(message);
|
||||
break;
|
||||
default:
|
||||
PluginMessages.UnknownCommand(sender, command);
|
||||
}
|
||||
} else {
|
||||
PluginMessages.UnknownCommand(sender, command);
|
||||
}
|
||||
|
||||
} else {
|
||||
PluginMessages.NoPermission(sender, command);
|
||||
}
|
||||
|
@ -4,10 +4,7 @@ import com.sekwah.advancedportals.DataCollector.DataCollector;
|
||||
import com.sekwah.advancedportals.compat.bukkit.NMS;
|
||||
import com.sekwah.advancedportals.destinations.Destination;
|
||||
import com.sekwah.advancedportals.effects.WarpEffects;
|
||||
import com.sekwah.advancedportals.listeners.BungeeListener;
|
||||
import com.sekwah.advancedportals.listeners.FlowStopper;
|
||||
import com.sekwah.advancedportals.listeners.PortalPlacer;
|
||||
import com.sekwah.advancedportals.listeners.PortalProtect;
|
||||
import com.sekwah.advancedportals.listeners.*;
|
||||
import com.sekwah.advancedportals.metrics.Metrics;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -1,345 +0,0 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import com.sekwah.advancedportals.events.WarpEvent;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
private int PortalMessagesDisplay = 2;
|
||||
|
||||
// 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;
|
||||
|
||||
private static boolean ShowBungeeMessage;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void reloadValues(AdvancedPortalsPlugin plugin) {
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
// will check if the player is in the portal or not.
|
||||
if(!Portal.portalsActive){
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Location fromloc = event.getFrom();
|
||||
Location loc = event.getTo();
|
||||
// Potentially fixes that stupid error cauzed by a bukkit update.
|
||||
// Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players.
|
||||
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
// This is probably the culprite of the bloody problem, setting the location its pointing to the event location
|
||||
// rather than sorta making a clone of the object.
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())){
|
||||
if(portal.trigger.equals(loc.getBlock().getType())
|
||||
|| portal.trigger.equals(eyeLoc.getBlock().getType())){
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){
|
||||
|
||||
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal);
|
||||
if(PortalMessagesDisplay == 1 && warped){
|
||||
player.sendMessage("");
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
|
||||
player.sendMessage("");
|
||||
}
|
||||
else if(PortalMessagesDisplay == 2 && warped){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
|
||||
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
|
||||
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
|
||||
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||
}
|
||||
|
||||
if(warped){
|
||||
//event.setFrom(player.getLocation());
|
||||
//event.setTo(player.getLocation());
|
||||
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
else{
|
||||
// TODO test if canceling is suitable or it needs to be teleported
|
||||
// but listen for teleport events.
|
||||
//player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if(portal.trigger.equals(Material.PORTAL)){
|
||||
final Player finalplayer = event.getPlayer();
|
||||
if(player.getGameMode().equals(GameMode.CREATIVE)){
|
||||
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
public void run(){
|
||||
if(finalplayer != null && finalplayer.isOnline()){
|
||||
finalplayer.removeMetadata("hasWarped", plugin);
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
else if(portal.trigger.equals(Material.LAVA)){
|
||||
final Player finalplayer = event.getPlayer();
|
||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
public void run(){
|
||||
finalplayer.removeMetadata("lavaWarped", plugin);
|
||||
finalplayer.setFireTicks(-1);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCombustEntityEvent(EntityCombustEvent event) {
|
||||
if(!Portal.portalsActive){
|
||||
return;
|
||||
}
|
||||
Location loc = event.getEntity().getLocation();
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(loc.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamEvent(EntityDamageEvent event) {
|
||||
if(!Portal.portalsActive){
|
||||
return;
|
||||
}
|
||||
//System.out.println(event.getCause());
|
||||
if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){
|
||||
Location loc = event.getEntity().getLocation();
|
||||
if(event.getEntity().hasMetadata("lavaWarped")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(loc.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPortalEvent(PlayerPortalEvent event) {
|
||||
if(!Portal.portalsActive){
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasMetadata("hasWarped")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
Object[] portals = Portal.Portals;
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(player.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
|
||||
|
||||
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemInteract(PlayerInteractEvent event) {
|
||||
|
||||
// will detect if the player is using an axe so the points of a portal can be set
|
||||
// also any other detections such as sign interaction or basic block protection
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
|
||||
if(!Portal.portalsActive){
|
||||
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
for(AdvancedPortal portal : Portal.Portals){
|
||||
if(portal.worldName.equals(block.getWorld().getName())){
|
||||
|
||||
if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){
|
||||
|
||||
if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){
|
||||
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
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.getPlayer().getItemInHand().getType() == WandMaterial // was type id
|
||||
&& (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) {
|
||||
|
||||
// This checks if the action was a left or right click and if it was directly effecting a block.
|
||||
if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
Location blockloc = event.getClickedBlock().getLocation();
|
||||
// stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will
|
||||
// have to be selected again if the player joins, also it does not affect any other players.
|
||||
player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
|
||||
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
|
||||
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
|
||||
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
|
||||
player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
|
||||
|
||||
// Stops the event so the block is not damaged
|
||||
event.setCancelled(true);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Location blockloc = event.getClickedBlock().getLocation();
|
||||
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
|
||||
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
|
||||
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
|
||||
player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
|
||||
player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
|
||||
|
||||
// Stops the event so the block is not interacted with
|
||||
event.setCancelled(true);
|
||||
|
||||
// Returns the event so no more code is executed(stops unnecessary code being executed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -34,85 +34,6 @@ public class Selection {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) {
|
||||
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
|
||||
int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X");
|
||||
int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y");
|
||||
int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z");
|
||||
|
||||
int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X");
|
||||
int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y");
|
||||
int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z");
|
||||
|
||||
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
|
||||
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
|
||||
|
||||
/*
|
||||
* There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements
|
||||
* then i will change it, but for now its the best way i can think of for doing this.
|
||||
*/
|
||||
|
||||
for (int x = LowX; x <= HighX; x++) {
|
||||
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int x = LowX; x <= HighX; x++) {
|
||||
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int z = LowZ; z <= HighZ; z++) {
|
||||
Location loc = new Location(player.getWorld(), LowX, LowY, z);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int z = LowZ; z <= HighZ; z++) {
|
||||
Location loc = new Location(player.getWorld(), HighX, LowY, z);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int y = LowY; y <= HighY; y++) {
|
||||
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int y = LowY; y <= HighY; y++) {
|
||||
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int y = LowY; y <= HighY; y++) {
|
||||
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int y = LowY; y <= HighY; y++) {
|
||||
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int x = LowX; x <= HighX; x++) {
|
||||
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int x = LowX; x <= HighX; x++) {
|
||||
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int z = LowZ; z <= HighZ; z++) {
|
||||
Location loc = new Location(player.getWorld(), LowX, HighY, z);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
for (int z = LowZ; z <= HighZ; z++) {
|
||||
Location loc = new Location(player.getWorld(), HighX, HighY, z);
|
||||
player.sendBlockChange(loc, blockType, metadata);
|
||||
}
|
||||
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
Selection.Hide(player, plugin, pos1, pos2);
|
||||
}
|
||||
}, timeout * 20);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void Show(final Player player, final AdvancedPortalsPlugin plugin) {
|
||||
|
||||
int LowX = 0;
|
||||
int LowY = 0;
|
||||
int LowZ = 0;
|
||||
@ -121,31 +42,43 @@ public class Selection {
|
||||
int HighY = 0;
|
||||
int HighZ = 0;
|
||||
|
||||
if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) {
|
||||
LowX = player.getMetadata("Pos2X").get(0).asInt();
|
||||
HighX = player.getMetadata("Pos1X").get(0).asInt();
|
||||
if (portalName != null) {
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
|
||||
|
||||
LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X");
|
||||
LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y");
|
||||
LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z");
|
||||
|
||||
HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X");
|
||||
HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y");
|
||||
HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z");
|
||||
} else {
|
||||
LowX = player.getMetadata("Pos1X").get(0).asInt();
|
||||
HighX = player.getMetadata("Pos2X").get(0).asInt();
|
||||
}
|
||||
if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) {
|
||||
LowY = player.getMetadata("Pos2Y").get(0).asInt();
|
||||
HighY = player.getMetadata("Pos1Y").get(0).asInt();
|
||||
} else {
|
||||
LowY = player.getMetadata("Pos1Y").get(0).asInt();
|
||||
HighY = player.getMetadata("Pos2Y").get(0).asInt();
|
||||
}
|
||||
if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) {
|
||||
LowZ = player.getMetadata("Pos2Z").get(0).asInt();
|
||||
HighZ = player.getMetadata("Pos1Z").get(0).asInt();
|
||||
} else {
|
||||
LowZ = player.getMetadata("Pos1Z").get(0).asInt();
|
||||
HighZ = player.getMetadata("Pos2Z").get(0).asInt();
|
||||
if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) {
|
||||
LowX = player.getMetadata("Pos2X").get(0).asInt();
|
||||
HighX = player.getMetadata("Pos1X").get(0).asInt();
|
||||
} else {
|
||||
LowX = player.getMetadata("Pos1X").get(0).asInt();
|
||||
HighX = player.getMetadata("Pos2X").get(0).asInt();
|
||||
}
|
||||
if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) {
|
||||
LowY = player.getMetadata("Pos2Y").get(0).asInt();
|
||||
HighY = player.getMetadata("Pos1Y").get(0).asInt();
|
||||
} else {
|
||||
LowY = player.getMetadata("Pos1Y").get(0).asInt();
|
||||
HighY = player.getMetadata("Pos2Y").get(0).asInt();
|
||||
}
|
||||
if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) {
|
||||
LowZ = player.getMetadata("Pos2Z").get(0).asInt();
|
||||
HighZ = player.getMetadata("Pos1Z").get(0).asInt();
|
||||
} else {
|
||||
LowZ = player.getMetadata("Pos1Z").get(0).asInt();
|
||||
HighZ = player.getMetadata("Pos2Z").get(0).asInt();
|
||||
}
|
||||
}
|
||||
|
||||
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
|
||||
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
|
||||
|
||||
|
||||
/*
|
||||
* There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements
|
||||
* then i will change it, but for now its the best way i can think of for doing this.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.events;
|
||||
package com.sekwah.advancedportals.api.events;
|
||||
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,8 +12,6 @@ public final class WarpEvent extends Event implements Cancellable {
|
||||
* Use listeners so you can add new triggers easier and also other plugins can listen for the event
|
||||
* and add their own triggers
|
||||
*/
|
||||
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.portals;
|
||||
package com.sekwah.advancedportals.api.portaldata;
|
||||
|
||||
public class PortalArg {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.portals;
|
||||
package com.sekwah.advancedportals.api.portaldata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
71
src/com/sekwah/advancedportals/api/registry/TagRegistry.java
Normal file
71
src/com/sekwah/advancedportals/api/registry/TagRegistry.java
Normal file
@ -0,0 +1,71 @@
|
||||
package com.sekwah.advancedportals.api.registry;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.api.warphandler.TagHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by on 25/07/2016.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class TagRegistry {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
private ArrayList<String> tags = new ArrayList<String>();
|
||||
|
||||
private Map<String, TagHandler.Activation> tagActivation = new HashMap<String, TagHandler.Activation>();
|
||||
|
||||
private Map<String, TagHandler.Creation> tagCreation = new HashMap<String, TagHandler.Creation>();
|
||||
|
||||
private Map<String, TagHandler.TagStatus> tagStatus = new HashMap<String, TagHandler.TagStatus>();
|
||||
|
||||
// TODO the event can be used for general data detection and management, but use a TagHandler to make it so they can register
|
||||
// the individual class to handle.
|
||||
|
||||
public TagRegistry(AdvancedPortalsPlugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return if the tag has been registered or if it already exists.
|
||||
*/
|
||||
public boolean registerTag(String tag, TagHandler tagHandler){
|
||||
|
||||
if(tag == null){
|
||||
plugin.getLogger().warning("A tag can not be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tags.contains(tag)){
|
||||
return false;
|
||||
}
|
||||
|
||||
tags.add(tag);
|
||||
|
||||
if(tagHandler != null && !(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) &&
|
||||
!(tagHandler instanceof TagHandler.Creation)){
|
||||
plugin.getLogger().warning("Error with tag: " + tag + ". A tag handler must implement one of the handlers. Not just extend.");
|
||||
if(tagHandler instanceof TagHandler.Activation){
|
||||
tagActivation.put(tag, (TagHandler.Activation) tagHandler);
|
||||
}
|
||||
if(tagHandler instanceof TagHandler.TagStatus){
|
||||
tagStatus.put(tag, (TagHandler.TagStatus) tagHandler);
|
||||
}
|
||||
if(tagHandler instanceof TagHandler.Creation){
|
||||
tagCreation.put(tag, (TagHandler.Creation) tagHandler);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.sekwah.advancedportals.api.warphandler;
|
||||
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
|
||||
/**
|
||||
* Created by on 30/07/2016.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class ActivationData {
|
||||
|
||||
private boolean warpAllowed = true;
|
||||
|
||||
private WarpedStatus warpStatus = WarpedStatus.INACTIVE;
|
||||
|
||||
private Portal activePortal;
|
||||
|
||||
public ActivationData(Portal portal){
|
||||
this.activePortal = portal;
|
||||
}
|
||||
|
||||
public WarpedStatus getWarped(){
|
||||
return this.warpStatus;
|
||||
}
|
||||
|
||||
public void setWarpStatus(WarpedStatus warped){
|
||||
if(this.warpStatus == WarpedStatus.WARPED){
|
||||
return;
|
||||
}
|
||||
else if(this.warpStatus == WarpedStatus.INACTIVE){
|
||||
return;
|
||||
}
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case you need to set the status back down a step for whatever reason. However it is not recommended.
|
||||
* @param warped
|
||||
*/
|
||||
public void setWarpStatusAbsolute(WarpedStatus warped){
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
public boolean getAllowed(){
|
||||
return this.warpAllowed;
|
||||
}
|
||||
|
||||
public void setAllowed(boolean allowed){
|
||||
this.warpAllowed = allowed;
|
||||
}
|
||||
|
||||
public enum WarpedStatus{
|
||||
/**
|
||||
* Player has moved or something major has happened. (only one of these should activate)
|
||||
*/
|
||||
WARPED,
|
||||
/**
|
||||
* Shows that the portal has been activated even if a major function is not performed.
|
||||
*/
|
||||
ACTIVATED,
|
||||
/**
|
||||
* Nothing has activated on the portal.
|
||||
*/
|
||||
INACTIVE;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.sekwah.advancedportals.api.warphandler;
|
||||
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by on 30/07/2016.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class TagHandler {
|
||||
|
||||
public interface Creation{
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to use a tag on the portal.
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
* @return if the portal can be created.
|
||||
*/
|
||||
boolean portalCreated(Player player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to remove the portal.
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
* @return if the portal can be destroyed.
|
||||
*/
|
||||
boolean portalDestroyed(Player player, ActivationData activeData, String argData);
|
||||
|
||||
}
|
||||
|
||||
public interface Activation{
|
||||
|
||||
/**
|
||||
* Activates before the main part of portal activation.
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*/
|
||||
void portalPreActivated(Player player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates after portal activation
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*/
|
||||
void portalPostActivated(Player player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates if the portal is allowed from pre
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*/
|
||||
void portalActivated(Player player, ActivationData activeData, String argData);
|
||||
|
||||
}
|
||||
|
||||
public interface TagStatus{
|
||||
|
||||
/**
|
||||
* If the user has access to add the tag
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
* @return if the tag will be added.
|
||||
*/
|
||||
boolean tagAdded(Player player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* If the user has access to remove the tag
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
* @return if the tag will be removed.
|
||||
*/
|
||||
boolean ragRemoved(Player player, ActivationData activeData, String argData);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,8 @@ package com.sekwah.advancedportals.listeners;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -32,42 +31,7 @@ public class FlowStopper implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
// when checking positions check the block and the to block
|
||||
Block blockTo = event.getToBlock();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (portal.worldName.equals(blockTo.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (Portal.inPortalRegion(event.getBlock().getLocation(), 3) | Portal.inPortalRegion(event.getToBlock().getLocation(), 3))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,11 @@
|
||||
package com.sekwah.advancedportals.listeners;
|
||||
|
||||
import com.avaje.ebeaninternal.server.transaction.RemoteTransactionEvent;
|
||||
import com.google.common.base.Optional;
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.events.WarpEvent;
|
||||
import com.sekwah.advancedportals.api.events.WarpEvent;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import com.sun.org.apache.regexp.internal.RE;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -19,17 +14,12 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
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;
|
||||
@ -38,8 +28,6 @@ public class Listeners implements Listener {
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
private int PortalMessagesDisplay = 2;
|
||||
|
||||
private boolean teleportDuringMove = false;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -77,108 +65,53 @@ public class Listeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoinEvent(PlayerJoinEvent event) {
|
||||
Portal.cooldown.put(event.getPlayer(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
|
||||
// will check if the player is in the portal or not.
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
teleportDuringMove = false;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Location fromloc = event.getFrom();
|
||||
//Location fromloc = event.getFrom();
|
||||
Location loc = event.getTo();
|
||||
// Potentially fixes that stupid error cauzed by a bukkit update.
|
||||
// Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players.
|
||||
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
// This is probably the culprite of the bloody problem, setting the location its pointing to the event location
|
||||
// rather than sorta making a clone of the object.
|
||||
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
|
||||
if (portal.trigger.equals(loc.getBlock().getType())
|
||||
|| portal.trigger.equals(eyeLoc.getBlock().getType())) {
|
||||
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY()) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
|
||||
if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) {
|
||||
|
||||
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal);
|
||||
if (PortalMessagesDisplay == 1 && warped) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
|
||||
player.sendMessage("");
|
||||
} else if (PortalMessagesDisplay == 2 && warped) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
|
||||
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
|
||||
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
|
||||
if (Portal.locationInPortalTrigger(portal, loc) | Portal.locationInPortalTrigger(portal, eyeLoc)) {
|
||||
WarpEvent warpEvent = new WarpEvent(player, portal);
|
||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||
if (portal.inPortal.contains(player)) return;
|
||||
if (!event.isCancelled()) {
|
||||
boolean warped = Portal.activate(player, portal);
|
||||
if (PortalMessagesDisplay == 1 && warped) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
|
||||
player.sendMessage("");
|
||||
} else if (PortalMessagesDisplay == 2 && warped) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
|
||||
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
|
||||
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
|
||||
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||
}
|
||||
if (warped) {
|
||||
//event.setFrom(player.getLocation());
|
||||
//event.setTo(player.getLocation());
|
||||
|
||||
//event.setCancelled(true);
|
||||
} else {
|
||||
//player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
//plugin.getLogger().info(String.valueOf(teleportDuringMove));
|
||||
if(!teleportDuringMove){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (portal.trigger.equals(Material.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.trigger.equals(Material.LAVA)) {
|
||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event){
|
||||
Player player = event.getPlayer();
|
||||
plugin.getLogger().info(String.valueOf(event.getCause()));
|
||||
if(event.getCause() != PlayerTeleportEvent.TeleportCause.NETHER_PORTAL && event.getCause() != PlayerTeleportEvent.TeleportCause.END_PORTAL){
|
||||
teleportDuringMove = true;
|
||||
}
|
||||
else{
|
||||
Location loc = player.getLocation();
|
||||
Object[] portals = Portal.Portals;
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(player.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
if (portal.trigger.equals(Material.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.trigger.equals(Material.LAVA)) {
|
||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
|
||||
}
|
||||
}
|
||||
portal.inPortal.add(player);
|
||||
} else portal.inPortal.remove(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// These are here because java 7 can only take finals straight into a runnable
|
||||
@ -217,90 +150,26 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCombustEntityEvent(EntityCombustEvent event) {
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
Location loc = event.getEntity().getLocation();
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(loc.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (Portal.inPortalTriggerRegion(event.getEntity().getLocation()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onDamEvent(EntityDamageEvent event) {
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
//System.out.println(event.getCause());
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) {
|
||||
Location loc = event.getEntity().getLocation();
|
||||
if (event.getEntity().hasMetadata("lavaWarped")) {
|
||||
if (event.getEntity().hasMetadata("lavaWarped") | Portal.inPortalTriggerRegion(event.getEntity().getLocation()))
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(loc.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html
|
||||
// Also listen to this possibly.
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPortalEvent(PlayerPortalEvent event) {
|
||||
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasMetadata("hasWarped")) {
|
||||
if (player.hasMetadata("hasWarped") | Portal.inPortalTriggerRegion(player.getLocation()))
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
Object[] portals = Portal.Portals;
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(player.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -311,28 +180,13 @@ public class Listeners implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
||||
if (!Portal.portalsActive) {
|
||||
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()) {
|
||||
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
|
||||
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
player.sendMessage(plugin.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
|
||||
|
@ -2,7 +2,6 @@ package com.sekwah.advancedportals.listeners;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -16,7 +15,7 @@ public class PortalPlacer implements Listener {
|
||||
@SuppressWarnings("unused")
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
private final double PortalProtectionRadius;
|
||||
private final int PortalProtectionRadius;
|
||||
|
||||
// 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("<EFBFBD>eP...
|
||||
@ -28,7 +27,7 @@ public class PortalPlacer implements Listener {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
|
||||
|
||||
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
|
||||
this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
|
||||
|
||||
if (PortalPlace) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
@ -39,26 +38,7 @@ public class PortalPlacer implements Listener {
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Material material = block.getType();
|
||||
if (material == Material.PORTAL) {
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//event.getChangedType();
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.sekwah.advancedportals.listeners;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.portals.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -23,7 +22,7 @@ public class PortalProtect implements Listener {
|
||||
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
|
||||
private boolean PortalProtect = true;
|
||||
|
||||
private double PortalProtectionRadius = 5D;
|
||||
private int PortalProtectionRadius = 5;
|
||||
|
||||
public PortalProtect(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -31,97 +30,36 @@ public class PortalProtect implements Listener {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
this.PortalProtect = config.getConfig().getBoolean("PortalProtection");
|
||||
|
||||
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
|
||||
this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
|
||||
|
||||
if (PortalProtect) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getPlayer().hasPermission("advancedportals.build")) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!event.getPlayer().hasPermission("advancedportals.build")
|
||||
&& Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getPlayer().hasPermission("advancedportals.build")) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
for (AdvancedPortal portal : Portal.Portals) {
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
|
||||
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!event.getPlayer().hasPermission("advancedportals.build")
|
||||
&& Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onExplosion(EntityExplodeEvent event) {
|
||||
|
||||
if (!Portal.portalsActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Block> blockList = event.blockList();
|
||||
for (int i = 0; i < blockList.size(); i++) {
|
||||
Block block = blockList.get(i);
|
||||
Object[] portals = Portal.Portals;
|
||||
for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){
|
||||
if (portal.worldName.equals(block.getWorld().getName())) {
|
||||
|
||||
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
|
||||
|
||||
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
|
||||
blockList.remove(i);
|
||||
i--;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius)) {
|
||||
blockList.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.sekwah.advancedportals.portals;
|
||||
|
||||
import com.sekwah.advancedportals.api.portaldata.PortalArg;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AdvancedPortal {
|
||||
|
||||
@ -24,6 +27,8 @@ public class AdvancedPortal {
|
||||
|
||||
public PortalArg[] portalArgs = null;
|
||||
|
||||
public HashSet<Player> inPortal = new HashSet<Player>();
|
||||
|
||||
// TODO think of relaying out the data input to a more logical format.
|
||||
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) {
|
||||
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
|
||||
|
@ -1,13 +0,0 @@
|
||||
package com.sekwah.advancedportals.portals;
|
||||
|
||||
/**
|
||||
* Created by on 29/02/2016.
|
||||
* <p>
|
||||
* TODO create argument registry for easier altering and control :) also allows other coders to add custom args
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class ArgRegistry {
|
||||
|
||||
|
||||
}
|
@ -6,28 +6,34 @@ import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.destinations.Destination;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import com.sekwah.advancedportals.api.portaldata.PortalArg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Portal {
|
||||
|
||||
public static HashMap<Player, Long> cooldown = new HashMap<Player, Long>();
|
||||
// Config values
|
||||
public static boolean portalsActive = false;
|
||||
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
|
||||
private static AdvancedPortalsPlugin plugin;
|
||||
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
|
||||
private static boolean ShowBungeeMessage;
|
||||
private static int cooldelay = 5;
|
||||
|
||||
public Portal(AdvancedPortalsPlugin plugin) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
|
||||
cooldelay = config.getConfig().getInt("Cooldown");
|
||||
|
||||
Portal.plugin = plugin;
|
||||
Portal.loadPortals();
|
||||
@ -366,6 +372,14 @@ public class Portal {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cooldown.get(player) != null) {
|
||||
int diff = (int) ((System.currentTimeMillis() - cooldown.get(player)) / 1000);
|
||||
if (diff < cooldelay) {
|
||||
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + (cooldelay - diff) + ChatColor.RED + " seconds until attempting to teleport again.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cooldown.put(player, System.currentTimeMillis());
|
||||
boolean showFailMessage = true;
|
||||
|
||||
if (portal.getArg("command.1") != null) {
|
||||
@ -419,7 +433,6 @@ public class Portal {
|
||||
out.writeUTF(portal.bungee);
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
// Down to bungee to sort out the teleporting but yea theoretically they should warp.
|
||||
return true;
|
||||
}
|
||||
else if (portal.destiation != null) {
|
||||
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
|
||||
@ -430,7 +443,6 @@ public class Portal {
|
||||
player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!");
|
||||
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
|
||||
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (showFailMessage) {
|
||||
@ -438,8 +450,8 @@ public class Portal {
|
||||
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
|
||||
+ "attempt and either the data is corrupt or portal doesn't exist!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void rename(String oldName, String newName) {
|
||||
@ -484,4 +496,34 @@ public class Portal {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inPortalTriggerRegion(Location loc) {
|
||||
for (AdvancedPortal portal : Portal.Portals)
|
||||
if (Portal.locationInPortalTrigger(portal, loc))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {
|
||||
if (portal.trigger.equals(loc.getBlock().getType()))
|
||||
return locationInPortal(portal, loc, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean inPortalRegion(Location loc, int additionalArea) {
|
||||
for (AdvancedPortal portal : Portal.Portals)
|
||||
if (Portal.locationInPortal(portal, loc, additionalArea))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
|
||||
if (!portalsActive)
|
||||
return false;
|
||||
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName()))
|
||||
if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + 1 + additionalArea) > loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ())
|
||||
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user