mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-01-12 19:30:54 +01:00
Started to add code to make sure portals are not overlapping
This commit is contained in:
parent
ccf89a79a9
commit
a2b412f605
@ -113,30 +113,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString());
|
||||
Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt());
|
||||
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt());
|
||||
|
||||
Material triggerBlockMat = Material.getMaterial(0);
|
||||
if(hasTriggerBlock){
|
||||
|
||||
try
|
||||
{
|
||||
triggerBlockMat = Material.getMaterial(Integer.parseInt(triggerBlock));
|
||||
System.out.println(triggerBlockMat.toString());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
|
||||
System.out.println(triggerBlockMat.toString());
|
||||
}
|
||||
catch(Exception exeption)
|
||||
{
|
||||
hasTriggerBlock = false;
|
||||
player.sendMessage("§cThe trigger block entered is not a valid block name in minecraft!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ConfigAccessor portalconfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
String posX = portalconfig.getConfig().getString(portalName + ".pos1.X");
|
||||
@ -158,18 +134,39 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
else{
|
||||
player.sendMessage("§cdestination: §eN/A (will not work)");
|
||||
}
|
||||
|
||||
Material triggerBlockMat = Material.getMaterial(0);
|
||||
if(hasTriggerBlock){
|
||||
player.sendMessage("§atriggerBlock: §e" + triggerBlock);
|
||||
|
||||
try
|
||||
{
|
||||
triggerBlockMat = Material.getMaterial(Integer.parseInt(triggerBlock));
|
||||
player.sendMessage("§atriggerBlock: §e" + triggerBlock.toUpperCase());
|
||||
Portal.create(pos1, pos2, portalName, destination, triggerBlockMat);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
|
||||
player.sendMessage("§atriggerBlock: §e" + triggerBlock.toUpperCase());
|
||||
Portal.create(pos1, pos2, portalName, destination, triggerBlockMat);
|
||||
}
|
||||
catch(Exception exeption)
|
||||
{
|
||||
hasTriggerBlock = false;
|
||||
ConfigAccessor Config = new ConfigAccessor(plugin, "Config.yml");
|
||||
player.sendMessage("§ctriggerBlock: §edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
|
||||
|
||||
player.sendMessage("§cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!");
|
||||
Portal.create(pos1, pos2, portalName, destination);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
ConfigAccessor Config = new ConfigAccessor(plugin, "Config.yml");
|
||||
player.sendMessage("§ctriggerBlock: §edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
|
||||
}
|
||||
|
||||
if(hasTriggerBlock){
|
||||
Portal.create(pos1, pos2, portalName, destination, triggerBlockMat);
|
||||
}
|
||||
else{
|
||||
Portal.create(pos1, pos2, portalName, destination);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
@ -89,6 +91,16 @@ public class Portal {
|
||||
|
||||
public static void create(Location pos1, Location pos2 , String name, String destination , Material triggerBlock) {
|
||||
|
||||
if(!pos1.getWorld().equals(pos2.getWorld())){
|
||||
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(checkPortalOverlap(pos1, pos2)){
|
||||
System.out.println("Portals must not overlap!");
|
||||
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
|
||||
return;
|
||||
}
|
||||
|
||||
int LowX = 0;
|
||||
int LowY = 0;
|
||||
@ -146,6 +158,44 @@ public class Portal {
|
||||
loadPortals();
|
||||
}
|
||||
|
||||
private static boolean checkPortalOverlap(Location pos1, Location pos2) {
|
||||
int portalId = 0;
|
||||
for(Object portal : Portal.Portals){
|
||||
if(Portal.worldName[portalId].equals(Portal.pos2[portalId].getWorld().getName())){
|
||||
|
||||
if(pos1.getX() >= Portal.pos1[portalId].getX() && pos1.getY() >= Portal.pos1[portalId].getY() && pos1.getZ() >= Portal.pos1[portalId].getZ()){
|
||||
|
||||
if((pos2.getX()) <= Portal.pos1[portalId].getX() && pos2.getY() <= Portal.pos1[portalId].getY() && pos2.getZ() <= Portal.pos1[portalId].getZ()){
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
portalId++;
|
||||
}
|
||||
portalId = 0;
|
||||
for(Object portal : Portal.Portals){
|
||||
if(Portal.worldName[portalId].equals(Portal.pos2[portalId].getWorld().getName())){
|
||||
|
||||
if(pos1.getX() >= Portal.pos2[portalId].getX() && pos1.getY() >= Portal.pos2[portalId].getY() && pos1.getZ() >= Portal.pos2[portalId].getZ()){
|
||||
|
||||
if((pos2.getX()) <= Portal.pos2[portalId].getX() && pos2.getY() <= Portal.pos2[portalId].getY() && pos2.getZ() <= Portal.pos2[portalId].getZ()){
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
portalId++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String checkMaterial(Material triggerBlock) {
|
||||
if(triggerBlock.equals(Material.WATER)){
|
||||
return "STATIONARY_WATER";
|
||||
|
Loading…
Reference in New Issue
Block a user