Continued Implementation of Elite Guardian.

This commit is contained in:
sigonasr2 2017-01-27 01:56:14 -06:00
parent 1c01ad595d
commit 5d6182a393
10 changed files with 618 additions and 42 deletions

Binary file not shown.

View File

@ -0,0 +1,289 @@
package sig.plugin.TwosideKeeper.Boss;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.Classes.Box;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.Classes.MaterialData;
/**
* Holds data about an arena.
*/
public class Arena {
HashMap<Block,MaterialData> oldblocklist = new HashMap<Block,MaterialData>();
List<Material> wallmats = new ArrayList<Material>();
List<Material> floormats = new ArrayList<Material>();
List<Material> roofmats = new ArrayList<Material>();
List<Material> insidemats = new ArrayList<Material>();
List<Chunk> temporarychunks = new ArrayList<Chunk>();
List<Player> arenaplayers = new ArrayList<Player>();
Box box;
World world;
public Arena(World world, int x, int y, int z, int w, int h, int d,Material arena_mat) {
this.world = world;
this.box = new Box(x,y,z,w,h,d);
this.wallmats.add(arena_mat);
this.floormats.add(arena_mat);
this.roofmats.add(arena_mat);
}
public Arena(World world, int x, int y, int z, int w, int h, int d,Material...arena_mats) {
this.world = world;
this.box = new Box(x,y,z,w,h,d);
for (Material mat : arena_mats) {
this.wallmats.add(mat);
this.floormats.add(mat);
this.roofmats.add(mat);
}
}
public Arena(World world, int x, int y, int z, int w, int h, int d,Material insidemat, Material...arena_mats) {
this.world = world;
this.box = new Box(x,y,z,w,h,d);
for (Material mat : arena_mats) {
this.wallmats.add(mat);
this.floormats.add(mat);
this.roofmats.add(mat);
}
this.insidemats.add(insidemat);
}
public Arena(World world, int x, int y, int z, int w, int h, int d,Material insidemat, Material wallmat, Material floormat, Material roofmat) {
this.world = world;
this.box = new Box(x,y,z,w,h,d);
this.wallmats.add(wallmat);
this.floormats.add(floormat);
this.roofmats.add(roofmat);
this.insidemats.add(insidemat);
}
public Arena(World world, int x, int y, int z, int w, int h, int d, Material[] insidemats, Material[] wallmats, Material[] floormats, Material[] roofmats) {
this.world = world;
this.box = new Box(x,y,z,w,h,d);
for (Material mat : wallmats) {
this.wallmats.add(mat);
}
for (Material mat : floormats) {
this.floormats.add(mat);
}
for (Material mat : roofmats) {
this.roofmats.add(mat);
}
for (Material mat : insidemats) {
this.insidemats.add(mat);
}
}
public void runTick() {
for (Player p : arenaplayers) {
if (p==null || !p.isValid()) {
TwosideKeeper.ScheduleRemoval(arenaplayers,p);
}
}
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getGameMode()==GameMode.SURVIVAL) {
if (arenaplayers.contains(p)) {
if (!insideBoundaries(p)) {
p.teleport(new Location(world,box.getX()+(box.getWidth()/2),box.getY()+(box.getHeight()/2),box.getZ()+(box.getDepth()/2)));
p.sendMessage(ChatColor.GREEN+"You cannot leave this arena!");
}
} else {
if (insideBoundaries(p)) {
p.teleport(new Location(world,box.getX()+(box.getWidth()/2),box.getY()+(box.getHeight()*2),box.getZ()+(box.getDepth()/2)));
p.sendMessage(ChatColor.GREEN+"You cannot enter this arena!");
}
}
}
}
}
private boolean insideBoundaries(Player p) {
int x = p.getLocation().getBlockX();
int y = p.getLocation().getBlockY();
int z = p.getLocation().getBlockZ();
return (x>=box.getX() && x<=box.getX()+box.getWidth() &&
y>=box.getY() && y<=box.getY()+box.getHeight() &&
z>=box.getZ() && z<=box.getZ()+box.getDepth());
}
public void AddPlayers(Player...players) {
for (Player p : players) {
arenaplayers.add(p);
}
}
public void RemovePlayers(Player...players) {
for (Player p : players) {
arenaplayers.remove(p);
}
}
public void AssembleArena() {
final int x = box.getX();
final int y = box.getY();
final int z = box.getZ();
AssembleArena(x,y,z,box.clone());
}
public void DisassembleArena() {
DisassembleArena(-1);
}
public void DisassembleArena(int amt) {
//amt is how many blocks to process in one tick.
int processed=0;
for (Block b : oldblocklist.keySet()) {
Chunk c = b.getChunk();
if (!TwosideKeeper.temporary_chunks.contains(c)) {
TwosideKeeper.temporary_chunks.add(c);
}
c.load();
if (!temporarychunks.contains(c)) {
temporarychunks.add(c);
}
MaterialData dat = oldblocklist.get(b);
if (b.getType()!=dat.getType() || b.getData()!=dat.getData()) {
b.setType(dat.getType());
b.setData(dat.getData());
}
if (amt!=-1) {TwosideKeeper.ScheduleRemoval(oldblocklist, b);}
processed++;
if (processed>amt && amt!=-1) {
break;
}
}
if (amt!=-1 && oldblocklist.size()>0) {
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{DisassembleArena(amt);}, 1);
}
}
private void AssembleArena(int curx, int cury, int curz, Box box) {
for (int i=0;i<8;i++) {
Block b = world.getBlockAt(curx, cury, curz);
Chunk c = b.getChunk();
if (!TwosideKeeper.temporary_chunks.contains(c)) {
TwosideKeeper.temporary_chunks.add(c);
}
c.load();
if (!temporarychunks.contains(c)) {
temporarychunks.add(c);
}
while (b.getState()!=null && b.getState() instanceof InventoryHolder) {
if (curx>box.getX()+box.getWidth()) {
curx=box.getX();
cury++;
}
if (cury>box.getY()+box.getHeight()) {
cury=box.getY();
curz++;
}
if (curz<box.getZ()+box.getDepth()) {
ConvertBlock(curx, cury, curz, box, b);
curx++;
}
}
if (curx>box.getX()+box.getWidth()) {
curx=box.getX();
cury++;
}
if (cury>box.getY()+box.getHeight()) {
cury=box.getY();
curz++;
}
if (curz<box.getZ()+box.getDepth()) {
ConvertBlock(curx, cury, curz, box, b);
curx++;
}
}
if (curz<=box.getZ()+box.getDepth()) {
final int x = curx;
final int y = cury;
final int z = curz;
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{
AssembleArena(x,y,z,box);
}, 1);
} else {
ClearAllTemporaryChunks();
}
}
private void ResetBlock(int curx, int cury, int curz, Box box, Block b) {
if (oldblocklist.containsKey(b)) {
MaterialData dat = oldblocklist.get(b);
if (b.getType()!=dat.getType() || b.getData()!=dat.getData()) {
b.setType(dat.getType());
b.setData(dat.getData());
}
oldblocklist.remove(b);
}
}
public void ConvertBlock(int curx, int cury, int curz, Box box, Block b) {
if (isWallBlock(curx,cury,curz,box)) {
oldblocklist.put(b,new MaterialData(b.getType(),b.getData()));
b.setType(wallmats.get((int)(Math.random()*wallmats.size())));
} else
if (isRoofBlock(curx,cury,curz,box)) {
oldblocklist.put(b,new MaterialData(b.getType(),b.getData()));
b.setType(roofmats.get((int)(Math.random()*roofmats.size())));
} else
if (isFloorBlock(curx,cury,curz,box)) {
oldblocklist.put(b,new MaterialData(b.getType(),b.getData()));
b.setType(floormats.get((int)(Math.random()*floormats.size())));
} else
{
oldblocklist.put(b,new MaterialData(b.getType(),b.getData()));
if (insidemats.size()>0) {
if (b.getType()!=Material.AIR && !b.isLiquid()) {
SoundUtils.playGlobalSound(b.getLocation(), Sound.BLOCK_METAL_BREAK, 0.3f, 0.3f);
}
b.setType(insidemats.get((int)(Math.random()*insidemats.size())));
} else {
b.setType(Material.AIR);
}
}
/*final int x = curx++;
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{
AssembleArena(x,cury,curz,box);
}, 1);*/
}
private boolean isFloorBlock(int curx, int cury, int curz, Box box2) {
return cury==box.getY();
}
private boolean isRoofBlock(int curx, int cury, int curz, Box box2) {
return cury==box.getY()+box.getHeight();
}
private boolean isWallBlock(int curx, int cury, int curz, Box box) {
return curx==box.getX() || curx==box.getWidth()+box.getX() ||
curz==box.getZ() || curz==box.getZ()+box.getDepth();
}
public void Cleanup() {
//ClearAllTemporaryChunks();
DisassembleArena();
}
private void ClearAllTemporaryChunks() {
TwosideKeeper.temporary_chunks.removeAll(temporarychunks);
temporarychunks.clear();
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,6 +12,7 @@ import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import sig.plugin.TwosideKeeper.EliteMonster; import sig.plugin.TwosideKeeper.EliteMonster;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Common.Camera; import sig.plugin.TwosideKeeper.HelperStructures.Common.Camera;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
@ -20,6 +22,7 @@ public class EliteGuardian extends EliteMonster{
STATE state = STATE.WAITINGFORCUTSCENE; STATE state = STATE.WAITINGFORCUTSCENE;
int cutscenetimer=0; int cutscenetimer=0;
Camera cam; Camera cam;
Arena arena;
public EliteGuardian(Monster m) { public EliteGuardian(Monster m) {
super(m); super(m);
@ -37,6 +40,13 @@ public class EliteGuardian extends EliteMonster{
if (m.isValid() && targetlist.size()>0) { if (m.isValid() && targetlist.size()>0) {
getGlow(); getGlow();
} }
runArenaTick();
}
private void runArenaTick() {
if (arena!=null) {
arena.runTick();
}
} }
private void runStateMachine() { private void runStateMachine() {
@ -49,32 +59,54 @@ public class EliteGuardian extends EliteMonster{
m.setInvulnerable(true); m.setInvulnerable(true);
List<Player> nearby = GenericFunctions.getNearbyPlayers(m.getLocation(), 4); List<Player> nearby = GenericFunctions.getNearbyPlayers(m.getLocation(), 4);
if (nearby.size()>0) { if (nearby.size()>0) {
List<Player> nearby2 = GenericFunctions.getNearbyPlayers(m.getLocation(), 16); boolean hasLineOfSight=false;
//Play the cutscene for all of these players. for (Player p : nearby) {
for (Player p : nearby2) { if (p.hasLineOfSight(m)) {
p.setVelocity(new Vector(0,0,0)); hasLineOfSight=true;
targetlist.add(p); break;
if (cutscenetimer==0) {
p.setGameMode(GameMode.SPECTATOR);
p.setSpectatorTarget(m);
} }
} }
if (cutscenetimer==0) { if (hasLineOfSight) {
GenericFunctions.logAndApplyPotionEffectToEntity(PotionEffectType.BLINDNESS, 40, 1, m); List<Player> nearby2 = GenericFunctions.getNearbyPlayers(m.getLocation(), 16);
}
cutscenetimer++;
if (cutscenetimer>20) {
state=STATE.PASSIVE;
//Play the cutscene for all of these players. //Play the cutscene for all of these players.
for (Player p : targetlist) { /*for (Player p : nearby2) {
if (p!=null && p.isValid() && p.isOnline()) { p.setVelocity(new Vector(0,0,0));
p.setGameMode(GameMode.SURVIVAL); targetlist.add(p);
if (cutscenetimer==0) {
p.setGameMode(GameMode.SPECTATOR);
p.setSpectatorTarget(m);
} }
} }
if (cutscenetimer==0) {
GenericFunctions.logAndApplyPotionEffectToEntity(PotionEffectType.BLINDNESS, 40, 1, m);
}*/
cam = new Camera(m.getLocation(),nearby2.toArray(new Player[nearby2.size()]));
targetlist.addAll(nearby2);
TwosideKeeper.cameras.add(cam);
cutscenetimer=0;
state = STATE.RUNNINGCUTSCENE;
TwosideKeeper.log("Monster Location: "+m.getLocation(),5);
cam.rotateAroundPointWithZoom(0.55, 350, m.getLocation(), 8, 0.04, 1, 4);
//cam.rotateAroundPoint(0.55, 200, m.getLocation(), 8, 4);
arena = new Arena(m.getWorld(),
m.getLocation().getBlockX()-10,m.getLocation().getBlockY()-2,m.getLocation().getBlockZ()-10,
20,7,20,
Material.PRISMARINE);
arena.AddPlayers(nearby2.toArray(new Player[nearby2.size()]));
arena.AssembleArena();
TwosideKeeper.arenas.add(arena);
} }
} }
m.setAI(false); m.setAI(false);
break; break;
case RUNNINGCUTSCENE:
cutscenetimer++;
if (cutscenetimer>60) {
state=STATE.PASSIVE;
cam.Cleanup();
}
m.setAI(false);
break;
default: default:
break; break;
} }
@ -94,8 +126,30 @@ public class EliteGuardian extends EliteMonster{
super.runHitEvent(damager,dmg); super.runHitEvent(damager,dmg);
} }
public void Cleanup() {
super.Cleanup();
if (arena!=null) {
arena.DisassembleArena();
TwosideKeeper.arenas.remove(arena);
}
}
public void AnnounceFailedTakedown() {
super.AnnounceFailedTakedown();
if (dpslist.size()>0 && !m.isDead()) {
if (arena!=null) {
arena.DisassembleArena();
TwosideKeeper.arenas.remove(arena);
arena=null;
}
state=STATE.WAITINGFORCUTSCENE;
cutscenetimer=0;
}
}
enum STATE { enum STATE {
PASSIVE, //Just works like vanilla Minecraft behavior. PASSIVE, //Just works like vanilla Minecraft behavior.
WAITINGFORCUTSCENE, //A mode where the game is waiting for a cutscene to occur. The Elite Guardian does not move during this time. WAITINGFORCUTSCENE, //A mode where the game is waiting for a cutscene to occur. The Elite Guardian does not move during this time.
RUNNINGCUTSCENE,
} }
} }

View File

@ -162,7 +162,7 @@ public class EliteMonster {
} }
} }
private void AnnounceFailedTakedown() { public void AnnounceFailedTakedown() {
if (dpslist.size()>0 && !m.isDead()) { if (dpslist.size()>0 && !m.isDead()) {
Bukkit.getServer().broadcastMessage(GenericFunctions.getDisplayName(m)+" Takedown Failed..."); Bukkit.getServer().broadcastMessage(GenericFunctions.getDisplayName(m)+" Takedown Failed...");
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW+"DPS Breakdown:"); Bukkit.getServer().broadcastMessage(ChatColor.YELLOW+"DPS Breakdown:");

View File

@ -5,67 +5,154 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import sig.plugin.TwosideKeeper.TwosideKeeper; import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.MovementUtils;
public class Camera { public class Camera {
ArmorStand camera_ent; //ArmorStand camera_ent;
HashMap<UUID,Location> camera_viewerlocs; double degrees=0;
HashMap<UUID,Location> camera_viewerlocs = new HashMap<UUID,Location>();
Chunk startingchunk;
Location startedat;
public Camera(Location startingloc,Player...viewers) { public Camera(Location startingloc,Player...viewers) {
camera_ent = (ArmorStand)startingloc.getWorld().spawnEntity(startingloc, EntityType.ARMOR_STAND); startingchunk = startingloc.getChunk();
camera_ent.setGravity(false); startedat=startingloc.clone();
camera_ent.setVisible(false); TwosideKeeper.temporary_chunks.add(startingchunk);
camera_ent.setInvulnerable(true); startingchunk.load();
camera_ent.setArms(false);
for (Player p : viewers) { for (Player p : viewers) {
AddCameraViewer(p); AddCameraViewer(p);
} }
} }
public boolean containsViewer(Player p) {
return (camera_viewerlocs.containsKey(p.getUniqueId()));
}
public void AddCameraViewer(Player p) { public void AddCameraViewer(Player p) {
camera_viewerlocs.put(p.getUniqueId(), p.getLocation()); camera_viewerlocs.put(p.getUniqueId(), p.getLocation().clone());
//TwosideKeeper.log("Set starting loc of "+p.getName()+" to "+camera_viewerlocs.get(p.getUniqueId()), 1);
p.setGameMode(GameMode.SPECTATOR); p.setGameMode(GameMode.SPECTATOR);
p.setSpectatorTarget(camera_ent); p.setSpectatorTarget(null);
}
public Location getStartingLoc(Player p) {
if (containsViewer(p)) {
return camera_viewerlocs.get(p.getUniqueId());
} else {
return null;
}
} }
public void removeCameraViewer(Player p) { public void removeCameraViewer(Player p) {
if (camera_viewerlocs.containsKey(p.getUniqueId())) { if (camera_viewerlocs.containsKey(p.getUniqueId())) {
p.setSpectatorTarget(null);
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
p.teleport(camera_viewerlocs.get(p.getUniqueId())); p.teleport(camera_viewerlocs.get(p.getUniqueId()));
//TwosideKeeper.log("Teleporting player "+p.getName()+" to "+camera_viewerlocs.get(p.getUniqueId()), 1);
camera_viewerlocs.remove(p.getUniqueId()); camera_viewerlocs.remove(p.getUniqueId());
} }
} }
public boolean runTick() { public boolean runTick() {
if (camera_ent==null || !camera_ent.isValid() || camera_viewerlocs.size()==0) { if (camera_viewerlocs.size()==0) {
return false; return false;
} }
for (UUID id : camera_viewerlocs.keySet()) { for (UUID id : camera_viewerlocs.keySet()) {
Player p = Bukkit.getPlayer(id); Player p = Bukkit.getPlayer(id);
if (p!=null && p.isValid()) { if (p!=null && p.isValid()) {
p.setGameMode(GameMode.SPECTATOR); p.setGameMode(GameMode.SPECTATOR);
if (p.getSpectatorTarget()==null || !(p.getSpectatorTarget() instanceof ArmorStand)) { p.setFlying(true);
//If this player is on multiple cameras for some reason, we don't want to overwrite the previous camera. p.setSpectatorTarget(p);
p.setSpectatorTarget(camera_ent);
}
} else { } else {
TwosideKeeper.ScheduleRemoval(camera_viewerlocs, p); TwosideKeeper.ScheduleRemoval(camera_viewerlocs, p);
} }
//TwosideKeeper.log("offset: "+camera_ent.getLocation().subtract(startedat)+" || Player offset: "+p.getLocation().subtract(startedat), 0);
} }
return true; return true;
} }
public ArmorStand getEnt() {
return camera_ent;
}
public void Cleanup() { public void Cleanup() {
Cleanup(false);
}
public void Cleanup(boolean isShuttingDown) {
for (UUID id : camera_viewerlocs.keySet()) { for (UUID id : camera_viewerlocs.keySet()) {
Player p = Bukkit.getPlayer(id); Player p = Bukkit.getPlayer(id);
if (p!=null && p.isValid()) { if (p!=null && p.isValid()) {
p.setSpectatorTarget(null);
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
p.teleport(camera_viewerlocs.get(id)); p.teleport(camera_viewerlocs.get(id));
if (!isShuttingDown) {
TwosideKeeper.ScheduleRemoval(camera_viewerlocs, p);
}
} else {
if (!isShuttingDown) {
TwosideKeeper.ScheduleRemoval(camera_viewerlocs, p);
}
}
}
if (!isShuttingDown) {
TwosideKeeper.temporary_chunks.remove(startingchunk);
}
removeAllCameraViewers();
}
private void removeAllCameraViewers() {
camera_viewerlocs.clear();
}
public void pointCameraToLocation(Location fromLoc, Location toLoc) {
//Points a camera to the target location.
if (fromLoc!=null && toLoc!=null && toLoc.getWorld().equals(fromLoc.getWorld())) {
Vector dir = MovementUtils.pointTowardsLocation(fromLoc, toLoc);
Location currloc = fromLoc.clone();
currloc.setDirection(dir);
teleportViewers(currloc);
}
}
private void teleportViewers(Location loc) {
for (UUID id : camera_viewerlocs.keySet()) {
Player p = Bukkit.getPlayer(id);
if (p!=null && p.isValid()) {
p.teleport(loc);
} }
} }
} }
public void setCameraAroundCircle(double radius, double degrees, Location loc, double yoffset) {
double velx = Math.cos(Math.toRadians(degrees));
//double vely = Math.sin(Math.toRadians(degrees));
double velz = Math.sin(Math.toRadians(degrees));
Vector newvector = new Vector(-velx,0,-velz);
newvector.multiply(radius*2);
Location finalloc = loc.clone().add(newvector).add(0,yoffset,0);
//TwosideKeeper.log("offset: "+camera_ent.getLocation().subtract(startedat)+" -> "+finalloc.subtract(startedat),0);
//camera_ent.teleport(finalloc);
teleportViewers(finalloc);
pointCameraToLocation(finalloc,loc);
}
public void rotateAroundPoint(double spd, int duration, Location loc, double radius, double yoffset) {
duration--;
setCameraAroundCircle(radius,degrees,loc,yoffset);
degrees+=spd;
if (duration>0) {
final int dur = duration;
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{rotateAroundPoint(spd,dur,loc,radius,yoffset);}, 1);
}
}
public void rotateAroundPointWithZoom(double spd, int duration, Location loc, double startzoom, double zoomspd, double maxzoom, double yoffset) {
duration--;
setCameraAroundCircle(startzoom,degrees,loc,yoffset);
degrees+=spd;
startzoom = Math.max(maxzoom,startzoom-zoomspd);
yoffset = Math.min(yoffset,startzoom);
if (duration>0) {
final int dur = duration;
final double zoom = startzoom;
final double y = yoffset;
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{rotateAroundPointWithZoom(spd,dur,loc,zoom,zoomspd,maxzoom,y);}, 1);
}
}
} }

View File

@ -0,0 +1,34 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils.Classes;
public class Box {
int x,y,z,w,h,d;
public Box(int x, int y, int z, int w, int h, int d) {
this.x=x;
this.y=y;
this.z=z;
this.w=w;
this.h=h;
this.d=d;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public int getWidth() {
return w;
}
public int getHeight() {
return h;
}
public int getDepth() {
return d;
}
public Box clone() {
return new Box(x,y,z,w,h,d);
}
}

View File

@ -0,0 +1,31 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils.Classes;
import org.bukkit.Material;
public class MaterialData {
Material type;
Byte data;
public MaterialData(Material type, Byte data) {
this.type=type;
this.data=data;
}
public Material getType() {
return type;
}
public void setType(Material type) {
this.type = type;
}
public Byte getData() {
return data;
}
public void setData(Byte data) {
this.data = data;
}
}

View File

@ -17,11 +17,34 @@ public class MovementUtils {
double c = currloc.getY()-targetloc.getY(); double c = currloc.getY()-targetloc.getY();
double b = currloc.getZ()-targetloc.getZ(); double b = currloc.getZ()-targetloc.getZ();
double angle = Math.atan2(b, a); double angle = Math.atan2(b, a);
double angle2 = Math.atan2(c, a); double angle2 = Math.atan2(c, Math.sqrt(Math.pow(a,2)+Math.pow(b, 2)));
double velz = spd * Math.sin(angle); double velz = spd * Math.sin(angle);
double velx = spd * Math.cos(angle); double velx = spd * Math.cos(angle);
double vely = spd * Math.sin(angle2); double vely = spd * Math.sin(angle2);
//TwosideKeeper.log("New angle is "+angle, 0); //TwosideKeeper.log("New angle is "+angle, 0);
return new Vector(-velx,-vely,-velz); return new Vector(-velx,-vely,-velz);
} }
/**
* Returns a vector pointing from the given location to the target location.
*/
public static Vector pointTowardsLocation(Location currloc, Location targetloc) {
/*double deltax = currloc.getX()-targetloc.getX();
double deltay = currloc.getY()-targetloc.getY();
double deltaz = currloc.getZ()-targetloc.getZ();
//Move at max speed in each direction until it matches the delta.
double velx = Math.min(Math.abs(deltax), spd)*Math.signum(deltax);
double vely = Math.min(Math.abs(deltax), spd)*Math.signum(deltay);
double velz = Math.min(Math.abs(deltax), spd)*Math.signum(deltaz);
return new Vector(-velx,-vely,-velz); //Flip the sign so we're moving towards the point instead of away from it.*/
double a = currloc.getX()-targetloc.getX();
double c = currloc.getY()-targetloc.getY();
double b = currloc.getZ()-targetloc.getZ();
double angle = Math.atan2(b, a);
double angle2 = Math.atan2(c, Math.sqrt(Math.pow(a,2)+Math.pow(b, 2)));
double velz = Math.sin(angle);
double velx = Math.cos(angle);
double vely = Math.sin(angle2);
//TwosideKeeper.log("New angle is "+angle, 0);
return new Vector(-velx,-vely,-velz);
}
} }

View File

@ -192,6 +192,7 @@ public class PlayerStructure {
public boolean vacuumsuckup=true; public boolean vacuumsuckup=true;
public boolean equipweapons=true; public boolean equipweapons=true;
public boolean equiparmor=true; public boolean equiparmor=true;
public Location restartLoc = null; //Set to a value when the player has to be re-teleported after being controlled by a camera.
List<ItemStack> equipmentset = new ArrayList<ItemStack>(); List<ItemStack> equipmentset = new ArrayList<ItemStack>();
@ -289,6 +290,13 @@ public class PlayerStructure {
} }
} }
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{
if (this.restartLoc!=null) {
p.teleport(this.restartLoc);
this.restartLoc=null;
}
}, 5);
//Joined always gets set to new time. //Joined always gets set to new time.
this.joined = serverTickTime; this.joined = serverTickTime;
setDefaultCooldowns(p); setDefaultCooldowns(p);
@ -386,6 +394,14 @@ public class PlayerStructure {
workable.set("COOLDOWN_lastmock", last_mock); workable.set("COOLDOWN_lastmock", last_mock);
workable.set("COOLDOWN_lastassassinatetime", lastassassinatetime); workable.set("COOLDOWN_lastassassinatetime", lastassassinatetime);
workable.set("COOLDOWN_lastlifesavertime", lastlifesavertime); workable.set("COOLDOWN_lastlifesavertime", lastlifesavertime);
if (restartLoc!=null) {
workable.set("restartloc_x", restartLoc.getX());
workable.set("restartloc_y", restartLoc.getY());
workable.set("restartloc_z", restartLoc.getZ());
workable.set("restartloc_world", restartLoc.getWorld().getName());
} else {
workable.set("restartloc_world", "null");
}
try { try {
workable.save(config); workable.save(config);
@ -512,6 +528,10 @@ public class PlayerStructure {
this.vacuumsuckup = workable.getBoolean("vacuumsuckup"); this.vacuumsuckup = workable.getBoolean("vacuumsuckup");
this.equipweapons = workable.getBoolean("equipweapons"); this.equipweapons = workable.getBoolean("equipweapons");
this.equiparmor = workable.getBoolean("equiparmor"); this.equiparmor = workable.getBoolean("equiparmor");
String tempworld = workable.getString("restartloc_world");
if (tempworld!=null && !tempworld.equalsIgnoreCase("null")) {
this.restartLoc = new Location(Bukkit.getWorld(tempworld),workable.getDouble("restartloc_x"),workable.getDouble("restartloc_y"),workable.getDouble("restartloc_z"));
}
if (this.hasDied) { if (this.hasDied) {
List<ItemStack> deathlootlist = new ArrayList<ItemStack>(); List<ItemStack> deathlootlist = new ArrayList<ItemStack>();

View File

@ -193,6 +193,7 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_9_R1.EnumParticle; import net.minecraft.server.v1_9_R1.EnumParticle;
import net.minecraft.server.v1_9_R1.MinecraftServer; import net.minecraft.server.v1_9_R1.MinecraftServer;
import sig.plugin.AutoPluginUpdate.AnnounceUpdateEvent; import sig.plugin.AutoPluginUpdate.AnnounceUpdateEvent;
import sig.plugin.TwosideKeeper.Boss.Arena;
import sig.plugin.TwosideKeeper.Boss.SendMiningFatigueToAllNearbyElderGuardians; import sig.plugin.TwosideKeeper.Boss.SendMiningFatigueToAllNearbyElderGuardians;
import sig.plugin.TwosideKeeper.Events.EntityDamagedEvent; import sig.plugin.TwosideKeeper.Events.EntityDamagedEvent;
import sig.plugin.TwosideKeeper.Events.PlayerDodgeEvent; import sig.plugin.TwosideKeeper.Events.PlayerDodgeEvent;
@ -471,6 +472,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static List<BlockModifyQueue> blockqueue = new ArrayList<BlockModifyQueue>(); public static List<BlockModifyQueue> blockqueue = new ArrayList<BlockModifyQueue>();
public static List<JobRecipe> jobrecipes = new ArrayList<JobRecipe>(); public static List<JobRecipe> jobrecipes = new ArrayList<JobRecipe>();
public static List<Camera> cameras = new ArrayList<Camera>(); public static List<Camera> cameras = new ArrayList<Camera>();
public static List<Arena> arenas = new ArrayList<Arena>();
long LastClearStructureTime = 0; long LastClearStructureTime = 0;
public static final Set<Material> isNatural = ImmutableSet.of(Material.CLAY, Material.DIRT, Material.GRASS, public static final Set<Material> isNatural = ImmutableSet.of(Material.CLAY, Material.DIRT, Material.GRASS,
@ -514,7 +516,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public final static boolean CHRISTMASEVENT_ACTIVATED=false; public final static boolean CHRISTMASEVENT_ACTIVATED=false;
public final static boolean CHRISTMASLINGERINGEVENT_ACTIVATED=false; //Limited Christmas drops/functionality remain while the majority of it is turned off. public final static boolean CHRISTMASLINGERINGEVENT_ACTIVATED=false; //Limited Christmas drops/functionality remain while the majority of it is turned off.
public final static boolean ELITEGUARDIANS_ACTIVATED=false; public final static boolean ELITEGUARDIANS_ACTIVATED=true;
public static final Set<EntityType> LIVING_ENTITY_TYPES = ImmutableSet.of( public static final Set<EntityType> LIVING_ENTITY_TYPES = ImmutableSet.of(
EntityType.BAT,EntityType.BLAZE,EntityType.CAVE_SPIDER,EntityType.CHICKEN, EntityType.BAT,EntityType.BLAZE,EntityType.CAVE_SPIDER,EntityType.CHICKEN,
@ -1117,6 +1119,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
BlockModifyQueue.Cleanup(blockqueue); BlockModifyQueue.Cleanup(blockqueue);
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis(); betweentime = System.currentTimeMillis();
log("Cleaning up Cameras ["+cameras.size()+"]",CLEANUP_DEBUG);
for (Camera cam : cameras) {
cam.Cleanup(true);
}
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis();
log("Cleaning up Arenas ["+arenas.size()+"]",CLEANUP_DEBUG);
for (Arena arena : arenas) {
arena.Cleanup();
}
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
long endtime = System.currentTimeMillis(); long endtime = System.currentTimeMillis();
log("Cleanup Maintenance completed. Total Time: "+(endtime-starttime)+"ms.",CLEANUP_DEBUG); log("Cleanup Maintenance completed. Total Time: "+(endtime-starttime)+"ms.",CLEANUP_DEBUG);
} }
@ -1386,7 +1399,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
w.setHealth(10); w.setHealth(10);
}break; }break;
case "ELITE":{ case "ELITE":{
LivingEntity m = MonsterController.convertLivingEntity((LivingEntity)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), LivingEntityDifficulty.ELITE); Guardian m = (Guardian)MonsterController.convertLivingEntity((LivingEntity)p.getWorld().spawnEntity(p.getLocation(),EntityType.GUARDIAN), LivingEntityDifficulty.ELITE);
m.setElder(true);
}break; }break;
case "VACUUM":{ case "VACUUM":{
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, new ItemStack(Material.ENDER_PEARL,16), new ItemStack(Material.IRON_PICKAXE,1), new ItemStack(Material.GOLDEN_APPLE,64)); ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, new ItemStack(Material.ENDER_PEARL,16), new ItemStack(Material.IRON_PICKAXE,1), new ItemStack(Material.GOLDEN_APPLE,64));
@ -1691,7 +1705,26 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}break; }break;
case "SETTIER":{ case "SETTIER":{
ItemUtils.ModifyLoreLineContainingSubstring(p.getEquipment().getItemInMainHand(), ChatColor.GOLD+""+ChatColor.BOLD+"T", ChatColor.GOLD+""+ChatColor.BOLD+"T"+Integer.parseInt(args[1])+" Artifact"); ItemUtils.ModifyLoreLineContainingSubstring(p.getEquipment().getItemInMainHand(), ChatColor.GOLD+""+ChatColor.BOLD+"T", ChatColor.GOLD+""+ChatColor.BOLD+"T"+Integer.parseInt(args[1])+" Artifact");
} }break;
case "TESTCAMERA":{
if (args.length==1) {
Camera c = new Camera(new Location(Bukkit.getWorld("world"),0,100,0),p);
TwosideKeeper.cameras.add(c);
//c.rotateAroundPoint(1, 400, new Location(Bukkit.getWorld("world"),0,100,0), 20, 5);
c.rotateAroundPointWithZoom(1, 400, new Location(Bukkit.getWorld("world"),-10,100,0), 20, 0.06, 1, 5);
} else
if (args.length==4) {
//TwosideKeeper.cameras.add(new Camera(p.getLocation(),p));
Camera c = TwosideKeeper.cameras.get(0);
c.pointCameraToLocation(new Location(Bukkit.getWorld("world"),0,100,0),p.getLocation().add(Integer.parseInt(args[1]),Integer.parseInt(args[2]),Integer.parseInt(args[3])));
} else
if (args.length==3) {
//TwosideKeeper.cameras.add(new Camera(p.getLocation(),p));
Camera c = TwosideKeeper.cameras.get(0);
//c.pointCameraToLocation(p.getLocation().add(Integer.parseInt(args[1]),Integer.parseInt(args[2]),Integer.parseInt(args[3])));
c.setCameraAroundCircle(Double.parseDouble(args[1]), Double.parseDouble(args[2]), new Location(Bukkit.getWorld("world"),0,64,0), 5);
}
}break;
} }
} }
//LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE); //LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE);
@ -2463,15 +2496,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public void onPlayerLeave(PlayerQuitEvent ev) { public void onPlayerLeave(PlayerQuitEvent ev) {
Player p = ev.getPlayer(); Player p = ev.getPlayer();
if (p.getGameMode()==GameMode.SPECTATOR) {
p.setGameMode(GameMode.SURVIVAL);
}
TwosideSpleefGames.PassEvent(ev); TwosideSpleefGames.PassEvent(ev);
for (EliteMonster em : elitemonsters) { for (EliteMonster em : elitemonsters) {
em.runPlayerLeaveEvent(ev.getPlayer()); em.runPlayerLeaveEvent(ev.getPlayer());
} }
for (Camera c : cameras) {
if (c.containsViewer(p)) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.restartLoc = c.getStartingLoc(p);
c.removeCameraViewer(p);
}
}
for (UUID id : livingentitydata.keySet()) { for (UUID id : livingentitydata.keySet()) {
LivingEntityStructure les = LivingEntityStructure.getLivingEntityStructure(livingentitydata.get(id).m); LivingEntityStructure les = LivingEntityStructure.getLivingEntityStructure(livingentitydata.get(id).m);
les.setGlow(ev.getPlayer(), null); les.setGlow(ev.getPlayer(), null);