This commit is contained in:
Sam 2018-04-30 13:42:58 +01:00 committed by Alexander Meech
parent 41fdde2c22
commit bd1d543344
6 changed files with 168 additions and 400 deletions

View File

@ -27,6 +27,7 @@ import org.bukkit.block.Jukebox;
import org.bukkit.block.Skull;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.SkullMeta;

View File

@ -54,6 +54,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import mineplex.core.common.Pair;
public class UtilEnt
{
public static final String FLAG_NO_REMOVE = "noremove";
@ -1130,4 +1132,47 @@ public class UtilEnt
{
((CraftEntity) entity).getHandle().setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
public static Pair<Location, Location> getSideStandingBox(Entity entity)
{
Location location = entity.getLocation();
double xMod = location.getX() % 1;
double zMod = location.getZ() % 1;
if (location.getX() < 0)
{
xMod += 1;
}
if (location.getZ() < 0)
{
zMod += 1;
}
int xMin = 0;
int xMax = 0;
int zMin = 0;
int zMax = 0;
if (xMod < 0.3)
{
xMin = -1;
}
else if (xMod > 0.7)
{
xMax = 1;
}
if (zMod < 0.3)
{
zMin = -1;
}
else if (zMod > 0.7)
{
zMax = 1;
}
return Pair.create(new Location(location.getWorld(), xMin, 0, zMin), new Location(location.getWorld(), xMax, 0, zMax));
}
}

View File

@ -72,7 +72,6 @@ import nautilus.game.arcade.game.games.quiver.modes.BunnyHop;
import nautilus.game.arcade.game.games.quiver.modes.UltimateOITQ;
import nautilus.game.arcade.game.games.rings.ElytraRings;
import nautilus.game.arcade.game.games.runner.Runner;
import nautilus.game.arcade.game.games.runner.modes.FasterThanLight;
import nautilus.game.arcade.game.games.sheep.SheepGame;
import nautilus.game.arcade.game.games.sheep.modes.EweHeroes;
import nautilus.game.arcade.game.games.sheep.modes.OverpoweredSheepQuest;
@ -255,7 +254,6 @@ public enum GameType
new GameMode(SheepMania.class, GameType.Sheep, "Sheep Mania"),
new GameMode(SmashSheep.class, GameType.Sheep, "Smash Sheep"),
new GameMode(OverpoweredSheepQuest.class, GameType.Sheep, "OP Sheep Quest"),
new GameMode(FasterThanLight.class, GameType.Runner, "Faster Than Light"),
new GameMode(BunnyHop.class, GameType.Quiver, "Bunny Hop"),
new GameMode(UltimateOITQ.class, GameType.Quiver, "Ultimate OITQ"),
new GameMode(Countdown.class, GameType.HideSeek, "Countdown"),

View File

@ -80,6 +80,7 @@ public class Micro extends TeamGame
.register(this);
new MapCrumbleModule()
.setRate(3)
.register(this);
registerStatTrackers(

View File

@ -1,17 +1,13 @@
package nautilus.game.arcade.game.games.runner;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import net.minecraft.server.v1_8_R3.EntityArrow;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
@ -28,8 +24,12 @@ import com.mineplex.anticheat.checks.move.Speed;
import mineplex.core.Managers;
import mineplex.core.antihack.AntiHack;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
@ -49,53 +49,45 @@ import nautilus.game.arcade.stats.DistanceTraveledStatTracker;
public class Runner extends SoloGame implements IThrown
{
private HashMap<Block, Long> _blocks = new HashMap<Block, Long>();
private static final String[] DESCRIPTION =
{
C.cGreen + "Blocks Fall" + C.Reset + " from underneath you.",
C.cAqua + "Keep Running" + C.Reset + " to stay alive.",
"Avoid " + C.cRed + "Falling Blocks" + C.Reset + " from above.",
C.cYellow + "Last Player" + C.Reset + " alive wins!"
};
private static final long BLOCK_DECAY = 600;
private static final long BLOCK_LIFETIME = 1200;
private final Map<Block, Long> _blocks = new HashMap<>();
public Runner(ArcadeManager manager)
{
this(manager, GameType.Runner);
registerStatTrackers(new DistanceTraveledStatTracker(this, "MarathonRunner"));
registerChatStats(
new ChatStatData("MarathonRunner", "Distance ran", true),
BlankLine,
new ChatStatData("kit", "Kit", true)
);
}
public Runner(ArcadeManager manager, GameType type)
{
super(manager, type,
new Kit[]
super(manager, GameType.Runner, new Kit[]
{
new KitLeaper(manager),
new KitArcher(manager),
new KitFrosty(manager)
},
}, DESCRIPTION);
new String[]
{
"Blocks fall from underneath you",
"Keep running to stay alive",
"Avoid falling blocks from above",
"Last player alive wins!"
});
this.DamagePvP = false;
this.HungerSet = 20;
this.WorldWaterDamage = 4;
this.PrepareFreeze = false;
DamagePvP = false;
HungerSet = 20;
WorldWaterDamage = 4;
PrepareFreeze = false;
new CompassModule()
.setGiveCompass(true)
.setGiveCompassToSpecs(true)
.setGiveCompassToAlive(false)
.register(this);
this.GlideCheckEnabled = false;
registerStatTrackers(
new DistanceTraveledStatTracker(this, "MarathonRunner")
);
registerChatStats(
new ChatStatData("MarathonRunner", "Distance ran", true)
);
GlideCheckEnabled = false;
AntiHack antiHack = Managers.get(AntiHack.class);
antiHack.addIgnoredCheck(Speed.class);
antiHack.addIgnoredCheck(Glide.class);
@ -103,257 +95,113 @@ public class Runner extends SoloGame implements IThrown
}
@EventHandler
public void ArrowDamage(ProjectileHitEvent event)
public void arrowDamage(ProjectileHitEvent event)
{
Entity entity = event.getEntity();
if (!(entity instanceof Arrow) || !IsLive())
{
if (!(event.getEntity() instanceof Arrow))
return;
}
final Arrow arrow = (Arrow)event.getEntity();
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
Manager.runSyncLater(() ->
{
public void run()
{
try
{
EntityArrow entityArrow = ((CraftArrow)arrow).getHandle();
Field fieldX = EntityArrow.class.getDeclaredField("d");
Field fieldY = EntityArrow.class.getDeclaredField("e");
Field fieldZ = EntityArrow.class.getDeclaredField("f");
fieldX.setAccessible(true);
fieldY.setAccessible(true);
fieldZ.setAccessible(true);
int x = fieldX.getInt(entityArrow);
int y = fieldY.getInt(entityArrow);
int z = fieldZ.getInt(entityArrow);
Block block = arrow.getWorld().getBlockAt(x, y, z);
Block block = UtilEnt.getHitBlock(entity);
double radius = 2.5;
for (Block other : UtilBlock.getInRadius(block.getLocation().add(0.5, 0.5, 0.5), radius).keySet())
{
AddBlock(other);
addBlock(other);
}
arrow.remove();
}
catch (Exception e)
{
e.printStackTrace();
}
}
entity.remove();
}, 0);
}
public void AddBlock(Block block)
private void addBlock(Block block)
{
if (block == null || block.getType() == Material.AIR || block.getType() == Material.BEDROCK || block.isLiquid() || block.getRelative(BlockFace.UP).getTypeId() != 0 || _blocks.containsKey(block))
{
if (block == null || block.getTypeId() == 0 || block.getTypeId() == 7 || block.isLiquid())
return;
if (block.getRelative(BlockFace.UP).getTypeId() != 0)
return;
if (_blocks.containsKey(block))
return;
}
_blocks.put(block, System.currentTimeMillis());
block.setTypeIdAndData(159, (byte) 14, false);
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.STAINED_CLAY, (byte) 14);
}
@EventHandler
public void BlockBreak(UpdateEvent event)
public void blockBreak(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK || !IsLive())
{
if (event.getType() != UpdateType.TICK)
return;
}
if (!IsLive())
return;
//Add Blocks
for (Player player : GetPlayers(true))
{
//Side Standing
double xMod = player.getLocation().getX() % 1;
if (player.getLocation().getX() < 0)
xMod += 1;
Pair<Location, Location> box = UtilEnt.getSideStandingBox(player);
Location min = box.getLeft(), max = box.getRight();
double zMod = player.getLocation().getZ() % 1;
if (player.getLocation().getZ() < 0)
zMod += 1;
int xMin = 0;
int xMax = 0;
int zMin = 0;
int zMax = 0;
if (xMod < 0.3) xMin = -1;
if (xMod > 0.7) xMax = 1;
if (zMod < 0.3) zMin = -1;
if (zMod > 0.7) zMax = 1;
for (int x=xMin ; x<=xMax ; x++)
for (int x = min.getBlockX(); x <= max.getBlockX(); x++)
{
for (int z=zMin ; z<=zMax ; z++)
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++)
{
AddBlock(player.getLocation().add(x, -0.5, z).getBlock());
addBlock(player.getLocation().add(x, -0.5, z).getBlock());
}
}
}
//Decay
HashSet<Block> readd = new HashSet<Block>();
Iterator<Block> blockIterator = _blocks.keySet().iterator();
while (blockIterator.hasNext())
_blocks.entrySet().removeIf(entry ->
{
Block block = blockIterator.next();
Block block = entry.getKey();
long time = entry.getValue();
if (!UtilTime.elapsed(_blocks.get(block), 600))
continue;
if (!UtilTime.elapsed(time, BLOCK_DECAY))
{
return false;
}
//Fall
int id = block.getTypeId();
byte data = block.getData();
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data);
Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 0.3f);
blockIterator.remove();
}
//
//// if (!UtilTime.elapsed(_blocks.get(block), 120))
//// continue;
//
// blockIterator.remove();
//
// //Degrade
// if (block.getTypeId() == 98)
// {
// if (block.getData() == 0)
// {
// readd.add(block);
// block.setData((byte)2);
// continue;
// }
// }
//
// //Degrade
// if (block.getTypeId() == 35 || block.getTypeId() == 159)
// {
// if (block.getData() == 3)
// {
// readd.add(block);
// block.setData((byte)5);
// continue;
// }
//
// if (block.getData() == 5)
// {
// readd.add(block);
// block.setData((byte)4);
// continue;
// }
//
// if (block.getData() == 4)
// {
// readd.add(block);
// block.setData((byte)1);
// continue;
// }
//
// if (block.getData() == 1)
// {
// readd.add(block);
// block.setData((byte)14);
// continue;
// }
//
// else if (block.getData() != 14)
// {
// readd.add(block);
// block.setData((byte)3);
// continue;
// }
// }
//
// //Fall
// int id = block.getTypeId();
// byte data = block.getData();
// MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
// FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data);
// Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 1d);
// }
//
// //Re-add
// for (Block block : readd)
// {
// _blocks.put(block, System.currentTimeMillis());
// }
FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), Material.STAINED_CLAY, (byte) 14);
Manager.GetProjectile().AddThrow(ent, null, this, BLOCK_LIFETIME, true, false, false, false, 0.3F);
return true;
});
}
@EventHandler
public void BlockForm(EntityChangeBlockEvent event)
public void blockForm(EntityChangeBlockEvent event)
{
BlockSmash(event.getEntity());
blockSmash(event.getEntity());
event.setCancelled(true);
}
public void BlockSmash(Entity ent)
private void blockSmash(Entity entity)
{
if (!(entity instanceof FallingBlock))
{
if (!(ent instanceof FallingBlock))
return;
FallingBlock block = (FallingBlock)ent;
int id = block.getBlockId();
if (id == 35 || id == 159)
id = 152;
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, id);
ent.remove();
}
if (Math.random() < 0.3)
{
FallingBlock block = (FallingBlock) entity;
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
}
entity.remove();
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{
if (target == null)
return;
if (target instanceof Player)
{
if (!Manager.GetGame().IsAlive((Player)target))
if (target == null || UtilPlayer.isSpectator(target) || target.getLocation().getY() > data.getThrown().getLocation().getY() + 0.5)
{
return;
}
if (target.getLocation().getY() > data.getThrown().getLocation().getY() + 0.5)
{
return;
}
}
//Damage Event
Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null,
DamageCause.ENTITY_ATTACK, 6, true, true, false,
"Falling Block", "Falling Block");
BlockSmash(data.getThrown());
}
public HashMap<Block, Long> getBlocks()
{
return _blocks;
Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, DamageCause.ENTITY_ATTACK, 6, true, true, false, "Falling Block", "Falling Block");
blockSmash(data.getThrown());
}
@Override
@ -365,7 +213,7 @@ public class Runner extends SoloGame implements IThrown
@Override
public void Expire(ProjectileUser data)
{
data.getThrown().remove();
}
@Override

View File

@ -1,125 +0,0 @@
package nautilus.game.arcade.game.games.runner.modes;
import java.util.HashSet;
import java.util.Iterator;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.runner.Runner;
/**
* GottaGoFast gamemode for Runner
*
* @author xXVevzZXx
*/
public class FasterThanLight extends Runner
{
public FasterThanLight(ArcadeManager manager)
{
super(manager);
}
@EventHandler
public void speed(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.SEC)
return;
for (Player player : GetPlayers(true))
{
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 40, 2, true, true),
true);
}
}
@Override
@EventHandler
public void BlockBreak(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!IsLive())
return;
//Add Blocks
for (Player player : GetPlayers(true))
{
//Side Standing
double xMod = player.getLocation().getX() % 1;
if (player.getLocation().getX() < 0)
xMod += 1;
double zMod = player.getLocation().getZ() % 1;
if (player.getLocation().getZ() < 0)
zMod += 1;
int xMin = 0;
int xMax = 0;
int zMin = 0;
int zMax = 0;
if (xMod < 0.3)
xMin = -1;
if (xMod > 0.7)
xMax = 1;
if (zMod < 0.3)
zMin = -1;
if (zMod > 0.7)
zMax = 1;
for (int x = xMin; x <= xMax; x++)
{
for (int z = zMin; z <= zMax; z++)
{
AddBlock(player.getLocation().add(x, -0.5, z).getBlock());
}
}
}
//Decay
HashSet<Block> readd = new HashSet<Block>();
Iterator<Block> blockIterator = getBlocks().keySet().iterator();
while (blockIterator.hasNext())
{
Block block = blockIterator.next();
if (!UtilTime.elapsed(getBlocks().get(block), 200))
continue;
//Fall
int id = block.getTypeId();
byte data = block.getData();
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data);
Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 0.3f);
blockIterator.remove();
}
}
@Override
public String GetMode()
{
return "Faster Than Light";
}
}