mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
Spout Integration!
This commit is contained in:
parent
d9701b910d
commit
cd158cc9a9
@ -29,6 +29,12 @@ import com.tommytony.war.jobs.HelmetProtectionTask;
|
||||
import com.tommytony.war.mappers.*;
|
||||
import com.tommytony.war.utils.*;
|
||||
|
||||
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
|
||||
import org.getspout.spoutapi.event.spout.SpoutListener;
|
||||
import org.getspout.spoutapi.gui.GenericLabel;
|
||||
import org.getspout.spoutapi.gui.WidgetAnchor;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
/**
|
||||
* Main class of War
|
||||
*
|
||||
@ -155,6 +161,8 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.CUSTOM_EVENT, new WarSpoutListener(this), Priority.Low, this);
|
||||
}
|
||||
|
||||
// Load files from disk or create them (using these defaults)
|
||||
@ -197,6 +205,12 @@ public class War extends JavaPlugin {
|
||||
* Cleans up war
|
||||
*/
|
||||
public void unloadWar() {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
SpoutPlayer sp = (SpoutPlayer) player;
|
||||
if (sp.isSpoutCraftEnabled())
|
||||
sp.getMainScreen().removeWidgets(this);
|
||||
}
|
||||
|
||||
for (Warzone warzone : this.warzones) {
|
||||
warzone.unload();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Monument;
|
||||
@ -237,6 +238,13 @@ public class WarBlockListener extends BlockListener {
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " stole team " + lostFlagTeam.getName() + "'s flag.");
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = (SpoutPlayer) p;
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
String tn = team.getName();
|
||||
sp.sendNotification(tn.substring(0,1).toUpperCase()+tn.substring(1).toLowerCase()+" stole your Flag!","Stolen by "+player.getName(),lostFlagTeam.getKind().getMaterial(),lostFlagTeam.getKind().getData(),3000);
|
||||
}
|
||||
}
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching team " + team.getName() + "'s " + spawnOrFlag + ".");
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.mysql.jdbc.StringUtils;
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.WarHub;
|
||||
@ -510,6 +512,13 @@ public class WarPlayerListener extends PlayerListener {
|
||||
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
|
||||
victim.initializeTeamFlag();
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = (SpoutPlayer) p;
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
String tn = playerTeam.getName();
|
||||
sp.sendNotification(tn.substring(0,1).toUpperCase()+tn.substring(1).toLowerCase()+" captures Flag!","Capped by "+player.getName(),victim.getKind().getMaterial(),victim.getKind().getData(),3000);
|
||||
}
|
||||
}
|
||||
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
|
||||
}
|
||||
|
139
war/src/main/java/bukkit/tommytony/war/WarSpoutListener.java
Normal file
139
war/src/main/java/bukkit/tommytony/war/WarSpoutListener.java
Normal file
@ -0,0 +1,139 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
|
||||
import org.getspout.spoutapi.event.spout.SpoutListener;
|
||||
import org.getspout.spoutapi.gui.Color;
|
||||
import org.getspout.spoutapi.gui.Container;
|
||||
import org.getspout.spoutapi.gui.ContainerType;
|
||||
import org.getspout.spoutapi.gui.GenericContainer;
|
||||
import org.getspout.spoutapi.gui.GenericLabel;
|
||||
import org.getspout.spoutapi.gui.Screen;
|
||||
import org.getspout.spoutapi.gui.Widget;
|
||||
import org.getspout.spoutapi.gui.WidgetAnchor;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarSpoutListener extends SpoutListener {
|
||||
static Plugin plugin;
|
||||
|
||||
public WarSpoutListener(Plugin plugin) {
|
||||
WarSpoutListener.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
|
||||
// Should not happen
|
||||
if(!event.getPlayer().isSpoutCraftEnabled()) {
|
||||
//event.getPlayer().sendMessage("PROTIP: Get Spout at getspout.org for real-time scores display!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateStats(Warzone zone) {
|
||||
List<GenericLabel> teamlines = new ArrayList<GenericLabel>();
|
||||
List<GenericLabel> playerlines = new ArrayList<GenericLabel>();
|
||||
List<GenericLabel> scorelines = new ArrayList<GenericLabel>();
|
||||
List<GenericLabel> lifelines = new ArrayList<GenericLabel>();
|
||||
int teammax = -15, playmax = -15, scoremax = -15;
|
||||
GenericLabel line;
|
||||
|
||||
// First, we collect all the team names
|
||||
int linecounter = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
// team name
|
||||
line = new GenericLabel(t.getName());
|
||||
if (t.getPlayers().size()==0) line.setTextColor(new Color(100,100,100));
|
||||
else line.setTextColor(t.getKind().getSpoutColor());
|
||||
line.setTooltip("Warzone: "+zone.getName()).setAnchor(WidgetAnchor.TOP_LEFT);
|
||||
line.setAlign(WidgetAnchor.TOP_LEFT).setX(3).setY(3+linecounter*(GenericLabel.getStringHeight("O")+3)).setWidth(GenericLabel.getStringWidth(line.getText())).setHeight(GenericLabel.getStringHeight(line.getText()));
|
||||
teamlines.add(line);
|
||||
linecounter++;
|
||||
}
|
||||
// We need to find the longest name
|
||||
for (GenericLabel l : teamlines) {
|
||||
if (GenericLabel.getStringWidth(l.getText()) > teammax) teammax=GenericLabel.getStringWidth(l.getText());
|
||||
}
|
||||
|
||||
// Now for the players
|
||||
linecounter = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
// player number
|
||||
line = new GenericLabel("Players: "+t.getPlayers().size());
|
||||
if (t.getPlayers().size()==0) line.setTextColor(new Color(100,100,100));
|
||||
line.setTooltip("Warzone: "+zone.getName()).setAnchor(WidgetAnchor.TOP_LEFT);
|
||||
line.setAlign(WidgetAnchor.TOP_LEFT).setX(3+teammax+15).setY(3+linecounter*(GenericLabel.getStringHeight("O")+3)).setWidth(GenericLabel.getStringWidth(line.getText())).setHeight(GenericLabel.getStringHeight(line.getText()));
|
||||
playerlines.add(line);
|
||||
linecounter++;
|
||||
}
|
||||
// Again, we need the longest entry
|
||||
for (GenericLabel l : playerlines) {
|
||||
if (GenericLabel.getStringWidth(l.getText()) > playmax) playmax=GenericLabel.getStringWidth(l.getText());
|
||||
}
|
||||
|
||||
// is there even a score cap (or is it just 1 point)?
|
||||
if (zone.getScoreCap()>1) {
|
||||
linecounter = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
// scores
|
||||
line = new GenericLabel(t.getPoints()+"/"+zone.getScoreCap()+" points");
|
||||
if (t.getPlayers().size()==0) line.setTextColor(new Color(100,100,100));
|
||||
line.setTooltip("Warzone: "+zone.getName()).setAnchor(WidgetAnchor.TOP_LEFT);
|
||||
line.setAlign(WidgetAnchor.TOP_LEFT).setX(3+teammax+15+playmax+15).setY(3+linecounter*(GenericLabel.getStringHeight("O")+3)).setWidth(GenericLabel.getStringWidth(line.getText())).setHeight(GenericLabel.getStringHeight(line.getText()));
|
||||
scorelines.add(line);
|
||||
linecounter++;
|
||||
}
|
||||
// I bet you know what is done here!
|
||||
for (GenericLabel l : scorelines) {
|
||||
if (GenericLabel.getStringWidth(l.getText()) > scoremax) scoremax=GenericLabel.getStringWidth(l.getText());
|
||||
}
|
||||
}
|
||||
|
||||
// and finally, lives.
|
||||
if (zone.getLifePool()>1) {
|
||||
linecounter = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
line = new GenericLabel(t.getRemainingLifes()+"/"+zone.getLifePool()+" lives");
|
||||
if (t.getPlayers().size()==0) line.setTextColor(new Color(100,100,100));
|
||||
line.setTooltip("Warzone: "+zone.getName()).setAnchor(WidgetAnchor.TOP_LEFT);
|
||||
line.setAlign(WidgetAnchor.TOP_LEFT).setX(3+teammax+15+playmax+15+scoremax+15).setY(3+linecounter*(GenericLabel.getStringHeight("O")+3)).setWidth(GenericLabel.getStringWidth(line.getText())).setHeight(GenericLabel.getStringHeight(line.getText()));
|
||||
scorelines.add(line);
|
||||
linecounter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Now to print it to the Spout players!
|
||||
List<GenericLabel> lines = new ArrayList<GenericLabel>();
|
||||
for (GenericLabel l : teamlines) lines.add(l);
|
||||
for (GenericLabel l : playerlines) lines.add(l);
|
||||
for (GenericLabel l : scorelines) lines.add(l);
|
||||
for (GenericLabel l : lifelines) lines.add(l);
|
||||
for (Team team : zone.getTeams()) {
|
||||
for (Player player : team.getPlayers()) {
|
||||
SpoutPlayer sp = (SpoutPlayer) player;
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
drawStats(sp, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawStats(SpoutPlayer sp, List<GenericLabel> lines) {
|
||||
// remove old stats first
|
||||
removeStats(sp);
|
||||
for (GenericLabel l : lines) sp.getMainScreen().attachWidget(plugin,l.copy());
|
||||
}
|
||||
|
||||
public static void removeStats(SpoutPlayer sp) {
|
||||
sp.getMainScreen().removeWidgets(plugin);
|
||||
}
|
||||
}
|
@ -10,8 +10,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarSpoutListener;
|
||||
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
@ -310,6 +310,8 @@ public class Team {
|
||||
|
||||
SignHelper.setToSign(War.war, signBlock, (byte) signData, lines);
|
||||
}
|
||||
|
||||
WarSpoutListener.updateStats(warzone);
|
||||
}
|
||||
|
||||
private void setBlock(int x, int y, int z, TeamKind kind) {
|
||||
|
@ -2,33 +2,36 @@ package com.tommytony.war;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.getspout.spoutapi.gui.Color;
|
||||
|
||||
public enum TeamKind {
|
||||
WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE),
|
||||
ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD),
|
||||
MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE),
|
||||
BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE),
|
||||
GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW), // yellow = gold
|
||||
GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN),
|
||||
PINK ((byte) 6, Material.WOOL, ChatColor.WHITE),
|
||||
GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY),
|
||||
IRON ((byte) 8, Material.WOOL, ChatColor.GRAY), // lightgrey = iron
|
||||
DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA), // cyan = diamond
|
||||
PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE),
|
||||
NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE),
|
||||
BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED),
|
||||
DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN),
|
||||
RED ((byte) 14, Material.WOOL, ChatColor.RED),
|
||||
BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK);
|
||||
WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE, new Color(255,255,255)),
|
||||
ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD, new Color(255,128,0)),
|
||||
MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE, new Color(255,128,255)),
|
||||
BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE, new Color(0,0,255)),
|
||||
GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW, new Color(0,255,255)), // yellow = gold
|
||||
GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN, new Color(0,255,0)),
|
||||
PINK ((byte) 6, Material.WOOL, ChatColor.WHITE, new Color(255,255,255)),
|
||||
GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY, new Color(100,100,100)),
|
||||
IRON ((byte) 8, Material.WOOL, ChatColor.GRAY, new Color(200,200,200)), // lightgrey = iron
|
||||
DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA, new Color(128,255,255)), // cyan = diamond
|
||||
PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE, new Color(128,0,255)),
|
||||
NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE, new Color(0,0,128)),
|
||||
BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED, new Color(128,0,0)),
|
||||
DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN, new Color(0,128,0)),
|
||||
RED ((byte) 14, Material.WOOL, ChatColor.RED, new Color(255,0,0)),
|
||||
BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK, new Color(0,0,0));
|
||||
|
||||
private final byte data;
|
||||
private final ChatColor color;
|
||||
private final Material material;
|
||||
private final Color spoutcolor;
|
||||
|
||||
private TeamKind(byte data, Material material, ChatColor color) {
|
||||
private TeamKind(byte data, Material material, ChatColor color, Color spoutcolor) {
|
||||
this.data = data;
|
||||
this.material = material;
|
||||
this.color = color;
|
||||
this.spoutcolor = spoutcolor;
|
||||
}
|
||||
|
||||
public static TeamKind teamKindFromString(String str) {
|
||||
@ -47,6 +50,9 @@ public enum TeamKind {
|
||||
public ChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
public Color getSpoutColor() {
|
||||
return this.spoutcolor;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
|
@ -19,7 +19,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarSpoutListener;
|
||||
|
||||
import com.tommytony.war.jobs.HelmetProtectionTask;
|
||||
import com.tommytony.war.jobs.InitZoneJob;
|
||||
@ -353,6 +356,8 @@ public class Warzone {
|
||||
this.getNewlyRespawned().put(player.getName(), 0);
|
||||
}
|
||||
|
||||
((SpoutPlayer) player).setTitle(team.getKind().getColor()+player.getName());
|
||||
|
||||
// "Respawn" Timer - player will not be able to leave spawn for a few seconds
|
||||
final Warzone w = this;
|
||||
if (respawnTimer==0) {
|
||||
@ -939,6 +944,11 @@ public class Warzone {
|
||||
player.setFireTicks(0);
|
||||
player.setRemainingAir(300);
|
||||
|
||||
SpoutPlayer sp = (SpoutPlayer) player;
|
||||
if (sp.isSpoutCraftEnabled()) WarSpoutListener.removeStats(sp);
|
||||
sp.resetTitle();
|
||||
|
||||
|
||||
War.war.msg(player, "Left the zone. Your inventory is being restored.");
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(this);
|
||||
|
@ -2,6 +2,9 @@ package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import bukkit.tommytony.war.WarSpoutListener;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
@ -20,6 +23,8 @@ public class ScoreCapReachedJob implements Runnable {
|
||||
for (Team t : this.zone.getTeams()) {
|
||||
t.teamcast(this.winnersStr);
|
||||
for (Player tp : t.getPlayers()) {
|
||||
SpoutPlayer sp = (SpoutPlayer) tp;
|
||||
if (sp.isSpoutCraftEnabled()) WarSpoutListener.removeStats(sp);
|
||||
// Send everyone to rally point (or zone lobby if not rally point)
|
||||
if (this.zone.getRallyPoint() != null) {
|
||||
tp.teleport(this.zone.getRallyPoint());
|
||||
|
@ -4,6 +4,7 @@ description: Lets you create TDM and CTF (warzones) for a more structured PVP ex
|
||||
author: tommytony
|
||||
website: war.tommytony.com
|
||||
main: bukkit.tommytony.war.War
|
||||
softdepend: [Spout]
|
||||
permissions:
|
||||
war.*:
|
||||
description: Create and destroy warzones. Change War configuration.
|
||||
@ -259,4 +260,4 @@ commands:
|
||||
/war zone <zone-name>
|
||||
War:
|
||||
description: War> Same as /war. Used as fallback.
|
||||
usage: See /war.
|
||||
usage: See /war.
|
||||
|
@ -4,6 +4,7 @@ description: Lets you create TDM and CTF (warzones) for a more structured PVP ex
|
||||
author: tommytony
|
||||
website: war.tommytony.com
|
||||
main: bukkit.tommytony.war.War
|
||||
softdepend: [Spout]
|
||||
permissions:
|
||||
war.*:
|
||||
description: Create and destroy warzones. Change War configuration.
|
||||
@ -259,4 +260,4 @@ commands:
|
||||
/war zone <zone-name>
|
||||
War:
|
||||
description: War> Same as /war. Used as fallback.
|
||||
usage: See /war.
|
||||
usage: See /war.
|
||||
|
Loading…
Reference in New Issue
Block a user