Add a scoreboard

This commit is contained in:
Sam 2018-01-08 16:56:02 +00:00 committed by Alexander Meech
parent 60cdae5c04
commit 538784f8f8
7 changed files with 80 additions and 84 deletions

View File

@ -32,6 +32,7 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.itemstack.EnchantedBookBuilder;
import mineplex.core.recharge.Recharge;
@ -69,7 +70,9 @@ public abstract class Skywars extends Game
private static final long CRUMBLE_TIME = TimeUnit.SECONDS.toMillis(100);
private OreHider _oreHider;
private MapCrumbleModule _mapCrumbleModule;
private GeneratorModule _generatorModule;
private final OreHider _oreHider;
public Skywars(ArcadeManager manager, GameType type, String[] description)
{
@ -92,7 +95,7 @@ public abstract class Skywars extends Game
HideTeamSheep = true;
GameTimeout = 1500000L;
GameTimeout = TimeUnit.MINUTES.toMillis(20);
DeathDropItems = true;
@ -119,7 +122,7 @@ public abstract class Skywars extends Game
InventoryOpenChest = true;
PlaySoundGameStart = true;
PrepareTime = 10000L;
PrepareTime = TimeUnit.SECONDS.toMillis(10);
DontAllowOverfill = true;
@ -147,7 +150,7 @@ public abstract class Skywars extends Game
@Override
public void ParseData()
{
new MapCrumbleModule()
_mapCrumbleModule = new MapCrumbleModule()
.setEnableAfter(CRUMBLE_TIME, () ->
{
Announce(C.cGreenB + "The world begins to crumble...", false);
@ -156,8 +159,8 @@ public abstract class Skywars extends Game
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1, 1);
}
})
.register(this);
});
_mapCrumbleModule.register(this);
new ZombieGuardianModule()
.addSpawns(WorldData.GetDataLocs("RED"))
@ -171,13 +174,13 @@ public abstract class Skywars extends Game
ItemStack tntItem = tntModule.getTntItem().clone();
tntItem.setAmount(2);
new GeneratorModule()
_generatorModule = new GeneratorModule()
.addGenerator(new Generator
(
new GeneratorType(tntItem, TimeUnit.SECONDS.toMillis(30), "Throwable TNT", ChatColor.RED, Color.RED, true),
WorldData.GetDataLocs("LIME").get(0)
))
.register(this);
));
_generatorModule.register(this);
for (Location oreLoc : WorldData.GetCustomLocs("56"))
{
@ -389,6 +392,33 @@ public abstract class Skywars extends Game
.build();
}
void writeScoreboard()
{
if (IsLive())
{
long timeUtilCrumble = _mapCrumbleModule.getTimeUntilCrumble();
long timeUtilTNT = _generatorModule.getGenerators().get(0).getTimeUtilSpawn();
if (timeUtilCrumble > 0)
{
Scoreboard.write(C.cGreenB + "Map Crumble");
Scoreboard.write(UtilTime.MakeStr(timeUtilCrumble));
Scoreboard.writeNewLine();
}
Scoreboard.write(C.cGreenB + "Throwable TNT");
if (timeUtilTNT > 0)
{
Scoreboard.write(UtilTime.MakeStr(timeUtilTNT));
}
else
{
Scoreboard.write("Lootable");
}
}
}
@EventHandler
public void informLeapCooldown(GameStateChangeEvent event)
{

View File

@ -1,7 +1,7 @@
package nautilus.game.arcade.game.games.skywars;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
@ -9,10 +9,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -27,8 +26,6 @@ import nautilus.game.arcade.stats.WinWithoutWearingArmorStatTracker;
public class SoloSkywars extends Skywars
{
private GameTeam _players;
@SuppressWarnings("unchecked")
public SoloSkywars(ArcadeManager manager)
{
@ -82,25 +79,24 @@ public class SoloSkywars extends Skywars
public void CustomTeamGeneration(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Recruit)
{
return;
}
_players = GetTeamList().get(0);
_players.SetColor(ChatColor.YELLOW);
_players.SetName("Players");
_players.setDisplayName(C.cYellow + C.Bold + "Players");
GameTeam players = GetTeamList().get(0);
players.SetColor(ChatColor.YELLOW);
players.SetName("Players");
players.setDisplayName(C.cYellow + C.Bold + "Players");
}
@Override
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
if (event.getType() != UpdateType.FAST || !InProgress())
{
return;
if (GetTeamList().isEmpty())
return;
Scoreboard.reset();
}
GameTeam team = GetTeamList().get(0);
@ -117,32 +113,10 @@ public class SoloSkywars extends Skywars
Scoreboard.write(C.cWhite + player.getName());
}
}
// if (IsLive())
// {
// Scoreboard.writeNewLine();
// Scoreboard.write(C.cYellow + C.Bold + "Time");
// Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT));
//
// Scoreboard.writeNewLine();
// Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn");
// Scoreboard.write(this.getTnTGen().getScoreboardInfo());
//
// Scoreboard.writeNewLine();
//
// if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime()))
// {
// Scoreboard.write(C.cRed + C.Bold + "Map Crumble");
// Scoreboard.write("Active");
// }
// else
// {
// Scoreboard.write(C.cGreen + C.Bold + "Map Crumble");
// Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT));
// }
// }
Scoreboard.writeNewLine();
writeScoreboard();
Scoreboard.draw();
}
@ -187,9 +161,9 @@ public class SoloSkywars extends Skywars
List<Player> places = GetTeamList().get(0).GetPlacements(true);
if (places.isEmpty() || !places.get(0).isOnline())
return Arrays.asList();
return Collections.emptyList();
else
return Arrays.asList(places.get(0));
return Collections.singletonList(places.get(0));
}
else
return null;

View File

@ -68,7 +68,8 @@ public class TeamSkywars extends Skywars
TeamPerSpawn = true;
ShowTeammateMessage = true;
new TeamModule().register(this);
new TeamModule()
.register(this);
}
@Override
@ -86,11 +87,13 @@ public class TeamSkywars extends Skywars
Scoreboard.writeNewLine();
Scoreboard.write(C.cYellow + C.Bold + "Teams");
ArrayList<GameTeam> alive = new ArrayList<GameTeam>();
List<GameTeam> alive = new ArrayList<>();
for (GameTeam team : GetTeamList())
{
if (team.IsTeamAlive())
{
alive.add(team);
}
}
if (GetPlayers(true).size() <= 4)
@ -115,29 +118,9 @@ public class TeamSkywars extends Skywars
Scoreboard.write(C.cWhite + alive.size() + " Alive");
}
// if (IsLive())
// {
// Scoreboard.writeNewLine();
// Scoreboard.write(C.cYellow + C.Bold + "Time");
// Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT));
//
// Scoreboard.writeNewLine();
// Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn");
// Scoreboard.write(this.getTnTGen().getScoreboardInfo());
//
// Scoreboard.writeNewLine();
//
// if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime()))
// {
// Scoreboard.write(C.cRed + C.Bold + "Map Crumble");
// Scoreboard.write("Active");
// }
// else
// {
// Scoreboard.write(C.cGreen + C.Bold + "Map Crumble");
// Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT));
// }
// }
Scoreboard.writeNewLine();
writeScoreboard();
Scoreboard.draw();
}

View File

@ -51,7 +51,7 @@ public abstract class SkywarsPerk extends Perk
@EventHandler
public void blockPlace(BlockPlaceEvent event)
{
if (_itemStack.isSimilar(event.getItemInHand()))
if (hasPerk(event.getPlayer()) && _itemStack.isSimilar(event.getItemInHand()))
{
event.getPlayer().sendMessage(F.main("Game", "You cannot place your " + F.name("Skill Item") + "."));
event.setCancelled(true);
@ -61,7 +61,7 @@ public abstract class SkywarsPerk extends Perk
@EventHandler
public void playerDropItem(PlayerDropItemEvent event)
{
if (event.getItemDrop().getItemStack().isSimilar(_itemStack))
if (hasPerk(event.getPlayer()) && event.getItemDrop().getItemStack().isSimilar(_itemStack))
{
event.getPlayer().sendMessage(F.main("Game", "You cannot drop your " + F.name("Skill Item") + "."));
event.setCancelled(true);
@ -73,5 +73,4 @@ public abstract class SkywarsPerk extends Perk
{
event.getDrops().removeIf(itemStack -> itemStack.isSimilar(_itemStack));
}
}

View File

@ -156,7 +156,7 @@ public class ZombieGuardianModule extends Module
}
event.AddMod("Negate", -event.GetDamage());
event.AddMod("Blast Protection", 8);
event.AddMod("Blast Protection", 5);
event.SetIgnoreArmor(true);
}

View File

@ -116,4 +116,9 @@ public class Generator
{
_lastCollect = System.currentTimeMillis();
}
public long getTimeUtilSpawn()
{
return _lastCollect + _type.getSpawnRate() - System.currentTimeMillis();
}
}

View File

@ -1,7 +1,7 @@
package nautilus.game.arcade.game.modules.generator;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
@ -20,11 +20,11 @@ import nautilus.game.arcade.game.modules.Module;
public class GeneratorModule extends Module
{
private final Set<Generator> _generators;
private final List<Generator> _generators;
public GeneratorModule()
{
_generators = new HashSet<>();
_generators = new ArrayList<>();
}
@Override
@ -121,4 +121,9 @@ public class GeneratorModule extends Module
}
}
}
public List<Generator> getGenerators()
{
return _generators;
}
}