Add ChristmasNew

This commit is contained in:
Sam 2017-11-07 13:11:09 +00:00 committed by Alexander Meech
parent 77c7362c35
commit 570033e3c9
8 changed files with 330 additions and 96 deletions

View File

@ -24,6 +24,8 @@ import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.EntityTracker;
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutCustomSoundEffect;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedSoundEffect;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import net.minecraft.server.v1_8_R3.WorldBorder;
@ -47,6 +49,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
import com.mineplex.ProtocolVersion;
import mineplex.core.common.MinecraftVersion;
public class UtilPlayer
@ -1143,4 +1147,34 @@ public class UtilPlayer
return versionToCompare.getVersion() >= getVersion();
}
}
public static void playCustomSound(CustomSound sound)
{
UtilServer.getPlayersCollection().forEach(player -> playCustomSound(player, sound));
}
public static void playCustomSound(Player player, CustomSound sound)
{
Packet packet;
int protocol = ((CraftPlayer) player).getHandle().getProtocol();
Location location = player.getLocation();
if (protocol >= ProtocolVersion.v1_12)
{
packet = new PacketPlayOutCustomSoundEffect(sound.getAudioPath(), location.getX(), location.getY(), location.getZ(), 20, 1);
}
else
{
packet = new PacketPlayOutNamedSoundEffect(sound.getAudioPath(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), 20, 1);
}
sendPacket(player, packet);
}
public interface CustomSound
{
String getAudioPath();
}
}

View File

@ -20,6 +20,7 @@ public enum GameDisplay
ChampionsDominate("Champions Domination", "Champions", Material.BEACON, (byte)0, GameCategory.CHAMPIONS, 6, true),
ChampionsTDM("Champions TDM", "Champions", Material.GOLD_SWORD, (byte)0, GameCategory.CHAMPIONS, 5, true),
Christmas("Christmas Chaos", Material.SNOW_BALL, (byte)0, GameCategory.CLASSICS, 8, false),
ChristmasNew("Christmas Chaos II", Material.SNOW_BALL, (byte)0, GameCategory.EVENT, 74, false),
DeathTag("Death Tag", Material.SKULL_ITEM, (byte)0, GameCategory.ARCADE, 9, true),
DragonEscape("Dragon Escape", Material.DRAGON_EGG, (byte)0, GameCategory.ARCADE, 10, true),
DragonEscapeTeams("Dragon Escape Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 11, false),

View File

@ -0,0 +1,148 @@
package nautilus.game.arcade.game.games.christmas;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import mineplex.core.common.util.C;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketInfo;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
public class ChristmasCommon extends TeamGame
{
private GameTeam _badGuys;
private List<Location> _barrier = new ArrayList<>();
private long _santaSayTime;
private Sleigh _sleigh;
private Location _sleighSpawn;
private final IPacketHandler _reindeerPackets = new IPacketHandler()
{
@Override
public void handle(PacketInfo packetInfo)
{
if (_sleigh == null)
{
return;
}
if (packetInfo.getPacket() instanceof PacketPlayOutSpawnEntityLiving)
{
PacketPlayOutSpawnEntityLiving spawnPacket = (PacketPlayOutSpawnEntityLiving) packetInfo.getPacket();
for (SleighHorse horse : _sleigh.getHorses())
{
if (horse.horseId == spawnPacket.a)
{
horse.spawnHorns(packetInfo.getPlayer());
break;
}
}
}
else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy)
{
try
{
PacketPlayOutEntityDestroy destroyPacket = (PacketPlayOutEntityDestroy) packetInfo.getPacket();
int[] entityIds = destroyPacket.a;
int origLength = entityIds.length;
for (int a = 0; a < entityIds.length; a++)
{
for (SleighHorse horse : _sleigh.getHorses())
{
if (horse.horseId == a)
{
int p = entityIds.length;
entityIds = Arrays.copyOf(entityIds, entityIds.length + 3);
System.arraycopy(horse.hornsAndNose, 0, entityIds, p, 3);
break;
}
}
}
if (entityIds.length != origLength)
{
destroyPacket.a = entityIds;
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
};
public ChristmasCommon(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc)
{
super(manager, gameType, kits, gameDesc);
HungerSet = 20;
PrepareFreeze = false;
registerChatStats(
DamageDealt,
DamageTaken
);
new CompassModule()
.register(this);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void generateTeams(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
{
return;
}
_badGuys = new GameTeam(this, "Christmas Thieves", ChatColor.RED, new ArrayList<>());
AddTeam(_badGuys);
}
public void sendSantaMessage(String message)
{
GetPlayers(true).forEach(player -> sendSantaMessage(player, message));
}
public void sendSantaMessage(Player player, String message)
{
player.sendMessage(getSantaMessage(message));
}
public String getSantaMessage(String message)
{
return C.cRedB + "Santa" + C.cWhiteB + ": " + C.cYellow + message;
}
public Sleigh getSleigh()
{
if (_sleigh == null)
{
_sleigh = new Sleigh();
_sleigh.setupSleigh(this, _sleighSpawn);
}
return _sleigh;
}
}

View File

@ -1,6 +1,7 @@
package nautilus.game.arcade.game.games.christmas;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Color;
@ -27,22 +28,23 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class Sleigh
{
public Christmas Host;
public ChristmasCommon Host;
//This is the central entity, all other sleigh entities have location relative to this.
private Entity CentralEntity;
private ArrayList<SleighPart> SleighEnts;
private ArrayList<SleighHorse> SleighHorses = new ArrayList<SleighHorse>();
private List<SleighPart> SleighEnts;
private List<SleighHorse> SleighHorses = new ArrayList<>();
private ArrayList<SleighPart> PresentSlots;
private List<SleighPart> PresentSlots;
private ArrayList<Location> PresentsCollected = new ArrayList<Location>();;
private List<Location> PresentsCollected = new ArrayList<>();
private Location Target;
private Entity Santa;
public void setupSleigh(Christmas host, Location loc)
public void setupSleigh(ChristmasCommon host, Location loc)
{
Host = host;
@ -56,7 +58,7 @@ public class Sleigh
Host.Manager.GetCondition().Factory().Invisible("Sleigh", (LivingEntity) CentralEntity, null, Double.MAX_VALUE, 3, false, false, true);
//Presents
PresentSlots = new ArrayList<SleighPart>();
PresentSlots = new ArrayList<>();
PresentSlots.add(new SleighPart(this, 2, 0, 0, loc.clone(), -1, -2));
PresentSlots.add(new SleighPart(this, 2, 0, 0, loc.clone(), 0, -2));
@ -75,8 +77,7 @@ public class Sleigh
//Sleigh
SleighEnts = new ArrayList<SleighPart>();
for (SleighPart part : PresentSlots)
SleighEnts.add(part);
SleighEnts.addAll(PresentSlots);
SleighEnts.add(new SleighPart(this, 0, 159, 14, loc.clone(), 0, -3));
SleighEnts.add(new SleighPart(this, 0, 159, 14, loc.clone(), -1, -3));
@ -139,10 +140,9 @@ public class Sleigh
SleighHorses.add(new SleighHorse(loc.clone(), "Blitzen", 1.5, 17));
for (SleighHorse horse : SleighHorses)
{
horse.spawnHorse();
// for (SleighHorse horse : SleighHorses)
// UtilEnt.Leash(horse.Ent, santa.GetTop(), true, false);
}
}
public Location GetLocation()
@ -160,7 +160,9 @@ public class Sleigh
Bump();
if (Target == null)
{
return;
}
Move(CentralEntity, Target, 1);
@ -256,21 +258,24 @@ public class Sleigh
UtilFirework.launchFirework(loc.clone().add(0.5, 0.5, 0.5), FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(Type.BALL).trail(true).build(), new Vector(0, 1, 0), 0);
SleighPart part = PresentSlots.remove(0);
if (part == null) return;
if (part == null)
{
return;
}
part.SetPresent();
}
public ArrayList<Location> GetPresents()
public List<Location> getPresents()
{
return PresentsCollected;
}
public void Damage(CustomDamageEvent event)
public void onDamage(CustomDamageEvent event)
{
if (event.GetDamageeEntity().equals(CentralEntity))
{
event.SetCancelled("Sleigh Damage");
event.SetCancelled("Sleigh onDamage");
return;
}
@ -278,7 +283,7 @@ public class Sleigh
{
if (part.HasEntity(event.GetDamageeEntity()))
{
event.SetCancelled("Sleigh Damage");
event.SetCancelled("Sleigh onDamage");
return;
}
}
@ -287,13 +292,13 @@ public class Sleigh
{
if (part.HasEntity(event.GetDamageeEntity()))
{
event.SetCancelled("Sleigh Damage");
event.SetCancelled("Sleigh onDamage");
return;
}
}
}
public ArrayList<SleighHorse> getHorses()
public List<SleighHorse> getHorses()
{
return SleighHorses;
}
@ -303,28 +308,42 @@ public class Sleigh
return Santa;
}
public boolean isPart(Entity ent)
private boolean isPart(Entity ent)
{
if (ent == null)
{
return false;
}
if (ent == CentralEntity)
if (ent.equals(CentralEntity) || ent.equals(Santa))
{
return true;
}
if (ent == Santa)
return true;
for (SleighPart part : SleighEnts)
{
if (part.Block == ent || part.Ent == ent || (ent instanceof LivingEntity && part.HasEntity((LivingEntity) ent)))
{
return true;
}
}
for (SleighHorse horse : SleighHorses)
{
if (horse.Ent == ent || (ent instanceof LivingEntity && horse.HasEntity((LivingEntity) ent)))
{
return true;
}
}
for (SleighPart part : PresentSlots)
{
if (part.Block == ent || part.Ent == ent || (ent instanceof LivingEntity && part.HasEntity((LivingEntity) ent)))
{
return true;
}
}
return false;
}

View File

@ -45,7 +45,7 @@ public class SleighHorse
public double OffsetZ;
public String Name;
public SleighHorse(Location loc, String name, double x, double z)
SleighHorse(Location loc, String name, double x, double z)
{
Name = name;
OffsetX = x;
@ -70,15 +70,12 @@ public class SleighHorse
public boolean HasEntity(LivingEntity ent)
{
if (Ent.equals(ent))
return true;
return false;
return Ent.equals(ent);
}
public void onTick()
{
EntityTrackerEntry entityTrackerEntry = (EntityTrackerEntry) ((CraftWorld) Ent.getWorld()).getHandle().tracker.trackedEntities
EntityTrackerEntry entityTrackerEntry = ((CraftWorld) Ent.getWorld()).getHandle().tracker.trackedEntities
.get(Ent.getEntityId());
if (entityTrackerEntry != null)
{

View File

@ -18,6 +18,7 @@ import mineplex.core.common.util.UtilMath;
public class SleighPart
{
public Chicken Ent;
public FallingBlock Block;
public double OffsetX;
@ -28,7 +29,7 @@ public class SleighPart
public int Data;
public Location Location;
public SleighPart(Sleigh sleigh, int rise, int id, int data, Location loc, double x, double z)
SleighPart(Sleigh sleigh, int rise, int id, int data, Location loc, double x, double z)
{
//Base
Ent = loc.getWorld().spawn(loc.add(x, 0, z), Chicken.class);
@ -147,18 +148,6 @@ public class SleighPart
return false;
}
public Entity GetTop()
{
Entity ent = Ent;
while (ent.getPassenger() != null)
{
ent = ent.getPassenger();
}
return ent;
}
private void addRise(Sleigh sleigh)
{
Chicken top = Ent;

View File

@ -0,0 +1,23 @@
package nautilus.game.arcade.game.games.christmasnew;
import mineplex.core.common.util.UtilPlayer.CustomSound;
enum ChristmasAudio implements CustomSound
{
;
private final String _audioPath;
ChristmasAudio(String audioPath)
{
_audioPath = audioPath;
}
@Override
public String getAudioPath()
{
return _audioPath;
}
}

View File

@ -0,0 +1,23 @@
package nautilus.game.arcade.game.games.christmasnew;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.games.christmas.ChristmasCommon;
import nautilus.game.arcade.kit.Kit;
public class ChristmasNew extends ChristmasCommon
{
private static final String[] DESCRIPTION =
{
};
public ChristmasNew(ArcadeManager manager)
{
super(manager, GameType.ChristmasNew, new Kit[]
{
}, DESCRIPTION);
}
}