Merge branch 'project-cosmetics' of https://github.com/Mineplex-LLC/Minecraft-PC into project-cosmetics

This commit is contained in:
LCastr0 2016-04-26 23:23:45 -03:00
commit d0e7590b2a
14 changed files with 248 additions and 55 deletions

View File

@ -0,0 +1,110 @@
package mineplex.core.common.block;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockVector;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import net.minecraft.server.v1_8_R3.Chunk;
import net.minecraft.server.v1_8_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange.MultiBlockChangeInfo;
public class MultiBlockUpdaterAgent
{
private Map<Chunk, List<BlockVector>> _chunks = new HashMap<Chunk, List<BlockVector>>();
public MultiBlockUpdaterAgent()
{
}
public void addBlock(Block block)
{
Chunk c = ((CraftChunk)block.getChunk()).getHandle();
List<BlockVector> list = _chunks.get(c);
if(list == null)
{
list = new ArrayList<BlockVector>();
_chunks.put(c, list);
}
if(list.size() >= 64) return;
list.add(block.getLocation().toVector().toBlockVector());
}
public void send()
{
send(UtilServer.getPlayersCollection());
}
public void reset()
{
_chunks.clear();
}
public void send(Collection<? extends Player> players)
{
for(Player p : players)
{
for(Chunk c : _chunks.keySet())
{
if(!p.getWorld().equals(c.bukkitChunk.getWorld())) continue;
int x = p.getLocation().getChunk().getX();
int z = p.getLocation().getChunk().getZ();
int chunkDist = Math.max(Math.abs(c.locX-x), Math.abs(c.locZ-z));
if(chunkDist > Bukkit.getViewDistance()) continue;
sendPacket(c, players);
}
}
}
private void sendPacket(Chunk c, Collection<? extends Player> players)
{
List<BlockVector> list = _chunks.get(c);
if(list == null) return;
if(list.size() >= 64)
{
for(Player p : players)
{
MapUtil.SendChunkForPlayer(c, p);
}
}
else
{
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
packet.a = new ChunkCoordIntPair(c.locX, c.locZ);
packet.b = new MultiBlockChangeInfo[list.size()];
for(int i = 0; i < list.size(); i++)
{
BlockVector bv = list.get(i);
short xyz = (short)((bv.getBlockX() & 0xF) << 12 | (bv.getBlockZ() & 0xF) << 8 | bv.getBlockY());
packet.b[i] = packet.new MultiBlockChangeInfo(xyz, c);
}
for(Player p : players)
{
UtilPlayer.sendPacket(p, packet);
}
}
}
}

View File

@ -5,6 +5,8 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import com.mysql.jdbc.Util;
import mineplex.core.common.block.DataLocationMap;
import mineplex.core.common.util.UtilBlock;
@ -54,6 +56,8 @@ public class Schematic
int startY = originLocation.getBlockY();
int startZ = originLocation.getBlockZ();
UtilBlock.startQuickRecording();
for (int x = 0; x < _width; x++)
{
for (int y = 0; y < _height; y++)
@ -109,6 +113,8 @@ public class Schematic
}
}
UtilBlock.stopQuickRecording();
return locationMap;
}

View File

@ -3,7 +3,6 @@ package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Queue;
import org.bukkit.Location;
import org.bukkit.Material;
@ -28,6 +27,7 @@ import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.Bed;
import mineplex.core.common.block.MultiBlockUpdaterAgent;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
@ -91,6 +91,8 @@ public class UtilBlock
*/
public static HashSet<BlockFace> horizontals = new HashSet<>();
private static MultiBlockUpdaterAgent _quickChangeRecorder;
static
{
@ -1512,6 +1514,39 @@ public class UtilBlock
return state.update(false, false);
}
/**
* See {@link #setQuick(World, int, int, int, int, byte)}
*/
public static void startQuickRecording()
{
if(_quickChangeRecorder != null)
{
_quickChangeRecorder.send();
_quickChangeRecorder.reset();
}
else
{
_quickChangeRecorder = new MultiBlockUpdaterAgent();
}
}
/**
* See {@link #setQuick(World, int, int, int, int, byte)}
*/
public static void stopQuickRecording()
{
if(_quickChangeRecorder == null) return;
_quickChangeRecorder.send();
_quickChangeRecorder.reset();
_quickChangeRecorder = null;
}
/**
* This doesn't send the block changes to the client. If you want to change lots of blocks and then send it to the player
* then do <code>startQuickRecording()</code> first. Change all the blocks you want. Then to send it do
* <code>stopQuickRecording()</code>. This will automatically send all the block changes to all relevant players.
*/
public static void setQuick(World world, int x, int y, int z, int type, byte data)
{
int cx = x >> 4;
@ -1525,6 +1560,11 @@ public class UtilBlock
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getById(type).fromLegacyData(data);
chunk.a(pos, ibd);
if(_quickChangeRecorder != null)
{
_quickChangeRecorder.addBlock(world.getBlockAt(x, y, z));
}
}
/**

View File

@ -53,7 +53,7 @@ public class WinEffectBabyChicken extends WinEffectGadget
@Override
public void play()
{
_chicken = spawnChicken(player, _baseLocation);
_chicken = spawnChicken(_player, _baseLocation);
UtilEnt.addGoalSelector(_chicken, 0, new PathfinderRandomRun(((CraftChicken)_chicken).getHandle(), getBaseLocation(), 4, 2.8));
@ -103,7 +103,7 @@ public class WinEffectBabyChicken extends WinEffectGadget
{
// Flap Chicken Wings
PacketPlayOutRelEntityMove packet = new PacketPlayOutRelEntityMove(_chicken.getEntityId(), (byte) 0, (byte) 0, (byte) 0, false);
UtilPlayer.getNearby(_chicken.getLocation(), 64).stream().forEach(p -> UtilPlayer.sendPacket(player, packet));
UtilPlayer.getNearby(_chicken.getLocation(), 64).stream().forEach(p -> UtilPlayer.sendPacket(_player, packet));
((CraftChicken) _chicken).getHandle().lastDamager = ((CraftChicken) _chicken).getHandle();
@ -138,7 +138,7 @@ public class WinEffectBabyChicken extends WinEffectGadget
@Override
public void finish()
{
UtilPlayer.showForAll(player);
UtilPlayer.showForAll(_player);
_text.keySet().forEach(h -> h.stop());
_text.clear();
_chicken.remove();

View File

@ -42,7 +42,7 @@ public class WinEffectFireworks extends WinEffectGadget
start.add(0, 0, r);
start.setDirection(new Vector(1, 0, 0));
_npc = getNPC(player, start);
_npc = getNPC(_player, start);
AnimatorEntity animator = new AnimatorEntity(Manager.getPlugin(), _npc.GetEntity().getBukkitEntity());

View File

@ -28,6 +28,8 @@ public class WinEffectFlames extends WinEffectGadget
{
super(manager, "Flames", UtilText.splitLineToArray(C.cGray + "Oh shit, my feets are on fire!", LineFormat.LORE),
1, Material.BLAZE_POWDER, (byte) 0);
_schematicName = "FlamesPodium";
}
@Override
@ -36,13 +38,13 @@ public class WinEffectFlames extends WinEffectGadget
int i = 0;
int points = 12;
double r = 3;
double r = 4;
Location start = getBaseLocation();
start.add(0, 0, r);
start.setDirection(new Vector(1, 0, 0));
_npc = getNPC(player, start);
_npc = getNPC(_player, start);
AnimatorEntity animator = new AnimatorEntity(Manager.getPlugin(), _npc.GetEntity().getBukkitEntity());

View File

@ -47,6 +47,8 @@ public class WinEffectLavaTrap extends WinEffectGadget
{
super(manager, "Lava Trap", UtilText.splitLineToArray(C.cGray + "FINALLY! A movie where the villain's master plan succeeds!", LineFormat.LORE),
1, Material.LAVA_BUCKET, (byte) 0);
_schematicName = "LavaTrapPodium";
}
@Override
@ -57,11 +59,11 @@ public class WinEffectLavaTrap extends WinEffectGadget
_lever = getBaseLocation().add(_baseLocation.getDirection().normalize()).getBlock();
_lever.setTypeIdAndData(Material.LEVER.getId(), (byte) 5, false);
playerNPC = getNPC(player, getBaseLocation());
playerNPC = getNPC(_player, getBaseLocation());
{
Vector forward = getBaseLocation().getDirection().normalize().multiply(1.3);
Vector right = UtilAlg.getRight(forward.clone()).multiply(2);
Vector right = UtilAlg.getRight(forward.clone()).multiply(1);
int maxPerRow = 6;
@ -71,7 +73,7 @@ public class WinEffectLavaTrap extends WinEffectGadget
int inRow = index%maxPerRow;
int rowSize = Math.min(nonTeam.size()-(row*maxPerRow), maxPerRow);
Vector f = forward.clone().multiply(3 + row);
Vector f = forward.clone().multiply(2.5 + row);
Vector r = right.clone().multiply((-rowSize/2.0) + 0.5);
r.add(right.clone().multiply(inRow));
@ -94,7 +96,7 @@ public class WinEffectLavaTrap extends WinEffectGadget
Location loc = getBaseLocation().add(f).add(r);
loc.setDirection(getBaseLocation().subtract(loc).toVector());
getNPC(team.get(index), loc);
((ArmorStand)getNPC(nonTeam.get(index), loc).GetEntity().getBukkitEntity()).setGravity(true);
}
}
@ -128,23 +130,40 @@ public class WinEffectLavaTrap extends WinEffectGadget
_lever.getWorld().playSound(_lever.getLocation(), Sound.CLICK, 0.3f, 0.6f);
}
if(_tick == 20*3 + 1)
{
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.IRONGOLEM_HIT, 0.2f, 1.6f);
}
if(_tick == 20*3 + 10)
{
UtilBlock.getInBoundingBox(a, b.clone().add(0, -1, 0), false).forEach(block ->
{
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
// UtilBlock.getInBoundingBox(a, b.clone().add(0, -1, 0), false).forEach(block ->
// {
// block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
//
// block.setType(Material.AIR);
// });
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.IRONGOLEM_DEATH, 0.2f, 0.5f);
block.setType(Material.AIR);
});
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.DIG_STONE, 1, 1f);
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.DIG_STONE, 1, 1.2f);
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.DIG_STONE, 1, 1.8f);
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.DIG_STONE, 1, 1.5f);
getBaseLocation().getWorld().playSound(getBaseLocation(), Sound.DIG_STONE, 1, 0.5f);
pasteScematic("LavaTrapPodium-part-2");
}
}
@EventHandler
public void onPhysics(BlockFromToEvent event)
{
/*
if(!isRunning()) return;
if(_webs.contains(event.getToBlock())) event.setCancelled(true);
*/
}
@Override
@ -160,6 +179,8 @@ public class WinEffectLavaTrap extends WinEffectGadget
public void buildWinnerRoom(Location loc)
{
super.buildWinnerRoom(loc);
/*
loc = loc.getBlock().getLocation();
Location floorCenter = loc.clone().add(0, -1, 0);
Location floorA = floorCenter.clone().subtract(8, 0, 8);
@ -216,12 +237,14 @@ public class WinEffectLavaTrap extends WinEffectGadget
((CraftChunk)loc.getWorld().getChunkAt(x, z)).getHandle().initLighting();
}
}
*/
}
@Override
public void teleport(Player player, List<Player> team, List<Player> other, Location loc)
{
loc = getBaseLocation().add(loc.getDirection().normalize().multiply(4)).add(-0.5, 3, -0.5);
Vector dir = loc.getDirection().normalize();
loc = getBaseLocation().add(UtilAlg.getRight(dir).multiply(5)).add(0, 2, 0).subtract(dir);
super.teleport(player, team, other, loc);
}

View File

@ -28,7 +28,7 @@ public class WinEffectLightningStrike extends WinEffectGadget
@Override
public void play()
{
final DisguisePlayer player = getNPC(this.player, getBaseLocation());
final DisguisePlayer player = getNPC(this._player, getBaseLocation());
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(),
new Runnable()
{

View File

@ -40,7 +40,7 @@ public class WinEffectMrPunchMan extends WinEffectGadget
@Override
public void play()
{
_npc = getNPC(player, getBaseLocation());
_npc = getNPC(_player, getBaseLocation());
List<Player> players = new ArrayList<>();

View File

@ -35,19 +35,19 @@ public class WinEffectPodium extends WinEffectGadget
@Override
public void play()
{
_baseLocation = _baseLocation.getBlock().getLocation();
// _baseLocation = _baseLocation.getBlock().getLocation();
Location a = getBaseLocation().add(1, 0, 1);
Location b = getBaseLocation().add(-2, 0, -2);
// Location a = getBaseLocation().add(1, 0, 1);
// Location b = getBaseLocation().add(-2, 0, -2);
UtilBlock.getInBoundingBox(a, b, false).forEach(block -> block.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 4, false));
// UtilBlock.getInBoundingBox(a, b, false).forEach(block -> block.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 4, false));
a = getBaseLocation().add(0, 1, 0);
b = getBaseLocation().add(-1, 0, -1);
// a = getBaseLocation().add(0, 1, 0);
// b = getBaseLocation().add(-1, 0, -1);
//
// UtilBlock.getInBoundingBox(a, b, false).forEach(block -> block.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 5, false));
UtilBlock.getInBoundingBox(a, b, false).forEach(block -> block.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 5, false));
_npc = getNPC(this.player, getBaseLocation().add(0, 2, 0));
_npc = getNPC(this._player, getBaseLocation());
AnimatorEntity animator = new AnimatorEntity(Manager.getPlugin(), _npc.GetEntity().getBukkitEntity());

View File

@ -51,8 +51,8 @@ public class WinEffectRiseOfTheElderGuardian extends WinEffectGadget
UtilEnt.setAI(_guardian, false);
Location loc = getBaseLocation();
loc.setDirection(player.getLocation().subtract(loc).toVector());
_npc = getNPC(player, loc);
loc.setDirection(_player.getLocation().subtract(loc).toVector());
_npc = getNPC(_player, loc);
_npc.setHeldItem(new ItemStack(Material.DIAMOND_SWORD));
_npc.sendPacket(_npc.getEquipmentPackets().toArray(new Packet[5]));

View File

@ -1,5 +1,6 @@
package mineplex.core.gadget.gadgets.wineffect;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
@ -28,12 +29,13 @@ public class WinEffectSnowTrails extends WinEffectGadget
{
super(manager, "Snow Trail", UtilText.splitLinesToArray(new String[] {C.cGray + "Oh the weather outside is frightful.", C.cGray + "But the fire is so delightful.", C.cGray + "And since we've no place to go.", C.cGray + "Let It Snow! Let It Snow! Let It Snow!"}, LineFormat.LORE),
1, Material.SNOW_BALL, (byte) 0);
_schematicName = "SnowPodium";
}
@Override
public void play()
{
_loc = getBaseLocation().add(0, 6, 0);
int i = 0;
@ -44,7 +46,7 @@ public class WinEffectSnowTrails extends WinEffectGadget
start.add(0, 0, r);
start.setDirection(new Vector(1, 0, 0));
_npc = getNPC(player, start);
_npc = getNPC(_player, start);
AnimatorEntity animator = new AnimatorEntity(Manager.getPlugin(), _npc.GetEntity().getBukkitEntity());

View File

@ -17,6 +17,7 @@ import org.bukkit.potion.PotionEffectType;
import com.mojang.authlib.GameProfile;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
@ -27,11 +28,13 @@ import mineplex.core.gadget.GadgetManager;
public abstract class WinEffectGadget extends Gadget
{
protected Player player;
protected long start;
protected long finish;
protected Player _player;
protected long _start;
protected long _finish;
protected Location _baseLocation;
protected String _schematicName = "WinRoomPodium";
/** All the players on the winners team. Empty if solo game. */
protected List<Player> team;
/** All the other players on the other teams that didn't win. */
@ -65,7 +68,7 @@ public abstract class WinEffectGadget extends Gadget
public void runPlay()
{
this.finish = start + 1000*12;
this._finish = _start + 1000*12;
play();
}
@ -87,7 +90,7 @@ public abstract class WinEffectGadget extends Gadget
{
finish();
UtilServer.getPlayersCollection().forEach(p -> {unlockPlayer(p); UtilPlayer.showForAll(p); });
player = null;
_player = null;
_baseLocation = null;
team.clear();
team = null;
@ -103,15 +106,15 @@ public abstract class WinEffectGadget extends Gadget
public boolean isRunning()
{
if(player == null) return false;
if(_player == null) return false;
if(_baseLocation == null) return false;
if(System.currentTimeMillis() >= finish) return false;
if(System.currentTimeMillis() >= _finish) return false;
return true;
}
public Player getPlayer()
{
return player;
return _player;
}
public Location getBaseLocation()
@ -121,24 +124,24 @@ public abstract class WinEffectGadget extends Gadget
public long getStart()
{
return start;
return _start;
}
public long getFinish()
{
return finish;
return _finish;
}
public void activate(Player player, List<Player> team, List<Player> nonTeam, Location loc)
{
this.player = player;
this._player = player;
this.team = team;
this.nonTeam = nonTeam;
this.other = new ArrayList<>();
other.addAll(UtilServer.getPlayersCollection());
other.remove(player);
other.removeAll(team);
this.start = System.currentTimeMillis();
this._start = System.currentTimeMillis();
this._baseLocation = loc.clone();
}
@ -221,14 +224,7 @@ public abstract class WinEffectGadget extends Gadget
// ((CraftChunk)loc.getChunk()).getHandle().initLighting();
*/
try
{
UtilSchematic.loadSchematic(new File("schematic" + File.separator + "WinRoom.schematic")).paste(getBaseLocation(), true);
}
catch (IOException e)
{
e.printStackTrace();
}
pasteScematic(_schematicName);
}
@ -248,4 +244,18 @@ public abstract class WinEffectGadget extends Gadget
return disguise;
}
public Schematic pasteScematic(String schematicName) {
try
{
Schematic schematic = UtilSchematic.loadSchematic(new File("schematic" + File.separator + schematicName + ".schematic"));
schematic.paste(getBaseLocation(), false, true);
return schematic;
}
catch(IOException e)
{
e.printStackTrace();
return null;
}
}
}

View File

@ -63,7 +63,7 @@ public class WinEffectManager
protected void playEffect() {
WinEffectGadget effect = getWinEffect(winner);
effect.teleport(winner, team, other, loc.clone().add(loc.getDirection().normalize().multiply(10)).add(0, 5, 0));
effect.teleport(winner, team, other, loc.clone().add(loc.getDirection().normalize().multiply(10)).add(0, 3, 0));
new BukkitRunnable() {
public void run() {
game.CreatureAllowOverride = true;