Started trying to add riding mob support

This commit is contained in:
sekwah41 2014-01-05 20:35:04 +00:00
parent a2b412f605
commit 2ba2b6c61b
3 changed files with 151 additions and 87 deletions

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
@ -78,14 +79,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
else if(args[0].toLowerCase().equals("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){
if(args.length >= 2){ // may make this next piece of code more efficient, maybe check against a list of available variables or something
boolean hasName = false;
boolean hasTriggerBlock = false;
boolean hasDestination = false;
boolean isBungeePortal = false;
String destination = null;
String portalName = null;
String triggerBlock = null;
for(int i = 0; i < args.length; i++){
String serverName = null;
List<String> addArgs = new ArrayList<String>();
for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
hasName = true;
portalName = args[i].replaceFirst("name:", "");
@ -94,15 +98,22 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("§c[§7AdvancedPortals§c] You must include a name for the portal that isnt nothing!");
return true;
}
if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
else if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
hasDestination = true;
destination = args[i].replaceFirst("destination:", "");
destination = args[i].toLowerCase().replaceFirst("destination:", "");
}
if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
else if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
hasTriggerBlock = true;
triggerBlock = args[i].replaceFirst("triggerblock:", "");
triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", "");
}
else if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
hasTriggerBlock = true;
triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", "");
}
else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){ // not completely implemented
isBungeePortal = true;
serverName = args[i].toLowerCase().replaceFirst("bungee:", "");
addArgs.add(args[i]);
}
}
if(!hasName){
@ -135,6 +146,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("§cdestination: §eN/A (will not work)");
}
if(isBungeePortal){
player.sendMessage("§abungee: §e" + serverName);
}
Material triggerBlockMat = Material.getMaterial(0);
if(hasTriggerBlock){
@ -142,7 +157,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
{
triggerBlockMat = Material.getMaterial(Integer.parseInt(triggerBlock));
player.sendMessage("§atriggerBlock: §e" + triggerBlock.toUpperCase());
Portal.create(pos1, pos2, portalName, destination, triggerBlockMat);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, addArgs));
}
catch(Exception e)
{
@ -150,7 +165,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
{
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
player.sendMessage("§atriggerBlock: §e" + triggerBlock.toUpperCase());
Portal.create(pos1, pos2, portalName, destination, triggerBlockMat);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, addArgs));
}
catch(Exception exeption)
{
@ -159,15 +174,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
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);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, addArgs));
}
}
}
else{
ConfigAccessor Config = new ConfigAccessor(plugin, "Config.yml");
player.sendMessage("§ctriggerBlock: §edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
Portal.create(pos1, pos2, portalName, destination);
player.sendMessage("§atriggerBlock: §edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, addArgs));
}
}
else{
@ -264,24 +279,28 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasName = false;
boolean hasTriggerBlock = false;
boolean hasDestination = false;
boolean isBungeePortal = false;
for(int i = 0; i < args.length; i++){
for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
hasName = true;
}
if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
else if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
hasDestination = true;
}
if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
else if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
hasTriggerBlock = true;
}
else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){
isBungeePortal = true;
}
}
if(!hasName){autoComplete.add("name:");}
if(!hasTriggerBlock){autoComplete.add("triggerblock:");}
if(!hasDestination){autoComplete.add("destination:");}
if(!isBungeePortal){autoComplete.add("bungee:");}
}
}
Collections.sort(autoComplete);

View File

@ -3,9 +3,12 @@ package com.sekwah.advancedportals.destinations;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.mysql.jdbc.Util;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
@ -87,21 +90,42 @@ public class Destination {
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
if(config.getConfig().getString(name + ".world") != null){
Location loc = player.getLocation();
loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world")));
loc.setX(config.getConfig().getDouble(name + ".pos.X"));
loc.setY(config.getConfig().getDouble(name + ".pos.Y"));
loc.setZ(config.getConfig().getDouble(name + ".pos.Z"));
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
player.teleport(loc);
return true;
if(Bukkit.getWorld(config.getConfig().getString(name + ".world")) != null){
loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world")));
loc.setX(config.getConfig().getDouble(name + ".pos.X"));
loc.setY(config.getConfig().getDouble(name + ".pos.Y"));
loc.setZ(config.getConfig().getDouble(name + ".pos.Z"));
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
Chunk c = loc.getChunk();
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
if(player.getVehicle() != null){
player.sendMessage("§c[§7AdvancedPortals§c] You cannot currently teleport while riding");
riding.setPassenger(null);
riding.teleport(loc);
player.teleport(loc);
riding.setPassenger(player);
}
else{
player.teleport(loc);
}
return true;
}
else{
player.sendMessage("§cThe destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
return false;
}
}
else{
player.sendMessage("§cThere has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
return false;

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.portalcontrolls;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
@ -11,6 +12,8 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.DataCollector.DataCollector;
@ -89,17 +92,11 @@ public class Portal {
}
public static void create(Location pos1, Location pos2 , String name, String destination , Material triggerBlock) {
public static String create(Location pos1, Location pos2 , String name, String destination , Material triggerBlock, List<String> addArgs) {
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;
return "§cPortal creation error, pos1 and pos2 must be in the same world!";
}
int LowX = 0;
@ -135,6 +132,14 @@ public class Portal {
HighZ = (int) pos2.getZ();
}
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
if(checkPortalOverlap(checkpos1, checkpos2)){
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
return "§cPortal creation error, portals must not overlap!";
}
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
config.getConfig().set(name.toLowerCase() + ".world", pos1.getWorld().getName());
@ -156,46 +161,48 @@ public class Portal {
DataCollector.portalCreated(triggerBlock.toString());
loadPortals();
return "§aPortal creation successful!";
}
// make this actually work!
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;
}
}
if(Portal.worldName[portalId].equals(pos2.getWorld().getName())){ // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another
if(checkOverLapPortal(pos1, pos2, Portal.pos1[portalId].getBlockX(), Portal.pos1[portalId].getBlockY(), Portal.pos1[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos1[portalId].getBlockX(), Portal.pos1[portalId].getBlockY(), Portal.pos2[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos1[portalId].getBlockX(), Portal.pos2[portalId].getBlockY(), Portal.pos1[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos2[portalId].getBlockX(), Portal.pos1[portalId].getBlockY(), Portal.pos1[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos2[portalId].getBlockX(), Portal.pos2[portalId].getBlockY(), Portal.pos2[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos2[portalId].getBlockX(), Portal.pos1[portalId].getBlockY(), Portal.pos2[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos1[portalId].getBlockX(), Portal.pos2[portalId].getBlockY(), Portal.pos2[portalId].getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portal.pos2[portalId].getBlockX(), Portal.pos2[portalId].getBlockY(), Portal.pos1[portalId].getBlockZ())){return true;}
}
portalId++;
}
return false;
}
private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) {
if(pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ){
if((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ){
return true;
}
}
return false;
}
private static String checkMaterial(Material triggerBlock) {
if(triggerBlock.equals(Material.WATER)){
return "STATIONARY_WATER";
@ -207,7 +214,7 @@ public class Portal {
}
@SuppressWarnings("deprecation")
public static void create(Location pos1, Location pos2, String name, String destination) { // add stuff for destination names or coordinates
public static String create(Location pos1, Location pos2, String name, String destination, List<String> addArgs) { // add stuff for destination names or coordinates
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
Material triggerBlockType;
@ -225,9 +232,11 @@ public class Portal {
triggerBlockType = Material.PORTAL;
}
create(pos1, pos2, name, destination, triggerBlockType);
String result = create(pos1, pos2, name, destination, triggerBlockType, addArgs);
loadPortals();
return result;
}
public static void redefine(Location pos1, Location pos2, String name){
@ -278,25 +287,37 @@ public class Portal {
// add other variables or filter code here, or somehow have a way to register them
if(config.getConfig().getString(portalName + ".destination") != null){
ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
String destiName = config.getConfig().getString(portalName + ".destination");
if(configDesti.getConfig().getString(destiName + ".world") != null){
boolean warped = Destination.warp(player, destiName);
return warped;
}
else{
player.sendMessage("§cThe destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
if(config.getConfig().getString(portalName + ".bungee") != null){
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(config.getConfig().getString(portalName + ".bungee"));
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return true;
}
else{
player.sendMessage("§cThe portal you are trying to use doesn't have a destination!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or portal doesn't exist!");
return false;
if(config.getConfig().getString(portalName + ".destination") != null){
ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
String destiName = config.getConfig().getString(portalName + ".destination");
if(configDesti.getConfig().getString(destiName + ".world") != null){
boolean warped = Destination.warp(player, destiName);
return warped;
}
else{
player.sendMessage("§cThe destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
}
else{
player.sendMessage("§cThe portal you are trying to use doesn't have a destination!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or portal doesn't exist!");
return false;
}
}
// add code for if the portal doesnt have a destination but a teleport location