clan claim visualizer

This commit is contained in:
NewGarbo 2015-12-03 22:29:36 +00:00
parent 584a02ae3e
commit 39daf969fd
12 changed files with 495 additions and 13 deletions

View File

@ -17,13 +17,15 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.event.ClanDeleteEvent;
import mineplex.game.clans.clans.event.ClanJoinEvent;
import mineplex.game.clans.clans.event.ClanLeaveEvent;
import mineplex.game.clans.clans.event.ClanSetHomeEvent;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
import mineplex.game.clans.clans.tntGenerator.TntGenerator;
import mineplex.game.clans.core.war.ClanWarData;
import mineplex.game.clans.core.repository.ClanRepository;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.core.repository.tokens.ClanToken;
import mineplex.game.clans.core.war.ClanWarData;
public class ClansDataAccessLayer
{
@ -201,6 +203,15 @@ public class ClansDataAccessLayer
public void join(final ClanInfo clan, final Player player, final ClanRole role, final Callback<Boolean> callback)
{
ClanJoinEvent event = new ClanJoinEvent(clan, player);
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
runAsync(new Runnable()
{
@Override
@ -259,6 +270,15 @@ public class ClansDataAccessLayer
{
if (clan == null) return;
ClanLeaveEvent event = new ClanLeaveEvent(clan, clansPlayer);
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
runAsync(new Runnable()
{
@Override

View File

@ -66,6 +66,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.claimview.ClaimVisualizer;
import mineplex.game.clans.clans.commands.ClanManagementCommand;
import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
@ -304,6 +305,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
loadClan(token);
}
new ClaimVisualizer(plugin, this);
// RedisDataRepository(ConnectionData writeConn, ConnectionData
// readConn, Region region, Class<T> elementType, String elementLabel)
// Initialize default region factions and territory
@ -672,7 +675,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
if (clan == null)
{
event.setFormat(rank + C.cYellow + "%1$s " + C.cWhite + "%2$s");
System.out.println(_clientManager.Get(event.getPlayer()).GetRank().name() + " " + event.getPlayer().getName() + " " + (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) ? C.cRed + "Creative " : " ") + event.getMessage());
System.out.println(_clientManager.Get(event.getPlayer()).GetRank().name() + " " + event.getPlayer().getName() + " " + event.getMessage());
return;
}
@ -692,7 +695,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
String message = event.getMessage();
message = _chat.getFilteredMessage(event.getPlayer(), message);
ClanRelation rel = _clanUtility.rel(clan, otherClan);
String formatted = rank + rel.getColor(true) + clan.getName() + " " + rel.getColor(false) + event.getPlayer().getName() + " " + (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) ? C.cRed + "Creative " : " ") + C.cWhite + message;
String formatted = rank + rel.getColor(true) + clan.getName() + " " + rel.getColor(false) + event.getPlayer().getName() + " " + C.cWhite + message;
other.sendMessage(formatted);
}
}

View File

@ -1084,7 +1084,7 @@ public class ClansUtility
}
// Event
PlayerUnClaimTerritoryEvent event = new PlayerUnClaimTerritoryEvent(caller, caller.getLocation().getChunk());
PlayerUnClaimTerritoryEvent event = new PlayerUnClaimTerritoryEvent(caller, caller.getLocation().getChunk(), ownerClan);
UtilServer.getServer().getPluginManager().callEvent(event);

View File

@ -0,0 +1,328 @@
package mineplex.game.clans.clans.claimview;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.claimview.commands.ClaimVisualizeCommand;
import mineplex.game.clans.clans.event.ClanDisbandedEvent;
import mineplex.game.clans.clans.event.ClanLeaveEvent;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.event.PlayerUnClaimTerritoryEvent;
import net.minecraft.server.v1_8_R3.EnumDirection;
public class ClaimVisualizer extends MiniPlugin
{
private ClansManager _clansManager;
private List<String> _visualizing;
private NautHashMap<ClanInfo, NautHashMap<String, VisualizedChunkData>> _calculated;
public ClaimVisualizer(JavaPlugin plugin, ClansManager clansManager)
{
super("Claim Visualizer", plugin);
_clansManager = clansManager;
_visualizing = new ArrayList<>();
_calculated = new NautHashMap<>();
for (ClanInfo clan : _clansManager.getClanMap().values())
{
_calculated.put(clan, new NautHashMap<String, VisualizedChunkData>());
}
}
@Override
public void addCommands()
{
addCommand(new ClaimVisualizeCommand(this));
}
@EventHandler
public void cleanup(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
{
return;
}
}
@EventHandler
public void runVisualization(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
for (String name : _visualizing)
{
Player player = Bukkit.getPlayer(name);
if (player != null && _clansManager.isInClan(player))
{
visualize(player);
}
}
}
private void visualize(Player player)
{
for (String serialized : _clansManager.getClan(player).getClaimSet())
{
if (!_calculated.get(_clansManager.getClan(player)).containsKey(serialized))
{
calculate(_clansManager.getClan(player), serialized);
}
}
draw(player, _calculated.get(_clansManager.getClan(player)).values());
}
private void draw(Player player, Collection<VisualizedChunkData> chunks)
{
for (VisualizedChunkData chunk : chunks)
{
if (!chunk.getChunk().getWorld().equals(player.getWorld()))
{
// return not break because a clan can't have claims in different worlds.
return;
}
if (UtilMath.offset2d(chunk.getChunk().getBlock(0, 0, 0).getLocation(), player.getLocation()) > 36)
{
break;
}
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
if (z == 0 || z == 15 || x == 0 || x == 15)
{
if (!chunk.shouldDisplay(x, z))
{
continue;
}
Block block = chunk.getChunk().getBlock(x, 0, z);
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER,
new Location(
chunk.getChunk().getWorld(),
block.getX() + .5,
Math.max(UtilBlock.getHighest(player.getWorld(), block.getX(), block.getZ()).getY(), player.getLocation().getY()) + .5,
block.getZ() + .5),
new Vector(0f, 0f, 0f), 0f, 1, ViewDist.NORMAL, player);
}
}
}
}
}
private void calculate(ClanInfo clan, String serialized)
{
Chunk chunk = UtilWorld.strToChunk(serialized);
List<EnumDirection> dirs = new ArrayList<>();
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(chunk.getWorld().getChunkAt(chunk.getX(), chunk.getZ() - 1))))
{
dirs.add(EnumDirection.NORTH);
}
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(chunk.getWorld().getChunkAt(chunk.getX() + 1, chunk.getZ()))))
{
dirs.add(EnumDirection.EAST);
}
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(chunk.getWorld().getChunkAt(chunk.getX(), chunk.getZ() + 1))))
{
dirs.add(EnumDirection.SOUTH);
}
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(chunk.getWorld().getChunkAt(chunk.getX() - 1, chunk.getZ()))))
{
dirs.add(EnumDirection.WEST);
}
VisualizedChunkData cached = new VisualizedChunkData(chunk, dirs);
_calculated.get(clan).put(serialized, cached);
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
if (isVisualizing(event.getPlayer()))
{
disableVisualizer(event.getPlayer());
}
}
@EventHandler
public void onKick(PlayerKickEvent event)
{
if (isVisualizing(event.getPlayer()))
{
disableVisualizer(event.getPlayer());
}
}
@EventHandler
public void onLeave(ClanLeaveEvent event)
{
if (isVisualizing(event.getPlayer().getPlayerName()))
{
disableVisualizer(event.getPlayer().getPlayerName());
}
}
@EventHandler
public void onClanDisband(ClanDisbandedEvent event)
{
for (Player player : event.getClan().getOnlinePlayers())
{
if (isVisualizing(player))
{
disableVisualizer(player);
}
}
}
@EventHandler
public void onUnclaim(PlayerUnClaimTerritoryEvent event)
{
_calculated.clear();
for (String serialized : event.getClan().getClaimSet())
{
calculate(event.getClan(), serialized);
}
if (event.getClan().getClaimCount() == 1)
{
for (Player player : event.getClan().getOnlinePlayers())
{
if (isVisualizing(player))
{
disableVisualizer(player);
}
}
}
}
@EventHandler
public void onClaim(PlayerClaimTerritoryEvent event)
{
_calculated.clear();
for (String serialized : event.getClan().getClaimSet())
{
calculate(event.getClan(), serialized);
}
}
public boolean isVisualizing(Player player)
{
return _visualizing.contains(player.getName());
}
public boolean isVisualizing(String name)
{
return _visualizing.contains(name);
}
public void enableVisualizer(String name)
{
enableVisualizer(UtilServer.getServer().getPlayer(name));
}
public void disableVisualizer(String name)
{
disableVisualizer(UtilServer.getServer().getPlayer(name));
}
public void toggleVisualizer(Player player)
{
if (_visualizing.contains(player.getName()))
{
disableVisualizer(player);
}
else
{
enableVisualizer(player);
}
}
public void enableVisualizer(Player player)
{
if (player == null)
{
return;
}
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a clan to visualize claims."));
return;
}
ClanInfo clan = _clansManager.getClan(player);
if (clan.getClaimCount() == 0)
{
UtilPlayer.message(player, F.main("Clans", "Your Clan does not have any claims!"));
return;
}
_visualizing.add(player.getName());
UtilPlayer.message(player, F.main("Clans", "You are now visualizing your claims."));
}
public void disableVisualizer(Player player)
{
if (player == null)
{
return;
}
if (!_visualizing.contains(player.getName()))
{
UtilPlayer.message(player, F.main("Clans", "You are anot visualizing your claims."));
return;
}
_visualizing.remove(player.getName());
UtilPlayer.message(player, F.main("Clans", "You are no longer visualizing your claims."));
}
}

View File

@ -0,0 +1,48 @@
package mineplex.game.clans.clans.claimview;
import java.util.List;
import org.bukkit.Chunk;
import net.minecraft.server.v1_8_R3.EnumDirection;
public class VisualizedChunkData
{
private List<EnumDirection> _displayable;
private Chunk _chunk;
public VisualizedChunkData(Chunk chunk, List<EnumDirection> dir)
{
_chunk = chunk;
_displayable = dir;
}
public boolean shouldDisplay(int x, int z)
{
if (z == 15 && !_displayable.contains(EnumDirection.SOUTH))
{
return false;
}
if (x == 15 && !_displayable.contains(EnumDirection.EAST))
{
return false;
}
if (x == 0 && !_displayable.contains(EnumDirection.WEST))
{
return false;
}
if (z == 0 && !_displayable.contains(EnumDirection.NORTH))
{
return false;
}
return true;
}
public Chunk getChunk() {
return _chunk;
}
}

View File

@ -0,0 +1,22 @@
package mineplex.game.clans.clans.claimview.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.game.clans.clans.claimview.ClaimVisualizer;
public class ClaimVisualizeCommand extends CommandBase<ClaimVisualizer>
{
public ClaimVisualizeCommand(ClaimVisualizer plugin)
{
super(plugin, Rank.ALL, "showclaims");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.toggleVisualizer(caller);
}
}

View File

@ -38,7 +38,6 @@ import mineplex.game.clans.items.legendaries.WindBlade;
public class ClanManagementCommand extends CommandBase<ClansManager>
{
private ClansManager _clansManager;
public ClanManagementCommand(ClansManager plugin)

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.task.TaskManager;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.tutorials.Tutorial;
@ -43,7 +44,7 @@ public class RestartTutCommand extends CommandBase<TutorialManager>
}
else
{
TutorialManager.Instance.sendTutorialMsg(caller, "You must be in a safezone to restart the tutorial.");
TutorialManager.Instance.sendTutorialMsg(caller, F.main("Clans", "You must be in a safezone to restart the tutorial."));
}
}
}

View File

@ -0,0 +1,56 @@
package mineplex.game.clans.clans.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansPlayer;
public class ClanLeaveEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private ClansPlayer _player;
private ClanInfo _clan;
private boolean _cancelled;
public ClanLeaveEvent(ClanInfo clan, ClansPlayer clansPlayer)
{
_player = clansPlayer;
_clan = clan;
}
public ClansPlayer getPlayer()
{
return _player;
}
public ClanInfo getClan()
{
return _clan;
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public boolean isCancelled()
{
return _cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -5,19 +5,23 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.ClanInfo;
public class PlayerUnClaimTerritoryEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _unClaimer;
private Chunk _unClaimedChunk;
private ClanInfo _clan;
private boolean _cancelled;
public PlayerUnClaimTerritoryEvent(Player unClaimer, Chunk unClaimedChunk)
public PlayerUnClaimTerritoryEvent(Player unClaimer, Chunk unClaimedChunk, ClanInfo clan)
{
_unClaimer = unClaimer;
_unClaimedChunk = unClaimedChunk;
_clan = clan;
}
public Player getUnClaimer()
@ -35,6 +39,11 @@ public class PlayerUnClaimTerritoryEvent extends Event
_cancelled = cancelled;
}
public ClanInfo getClan()
{
return _clan;
}
public boolean isCancelled()
{
return _cancelled;

View File

@ -101,7 +101,8 @@ public class TutorialTask<T extends Tutorial> implements Listener
}
}
@EventHandler
//@EventHandler
//todo: fix the multiline subtitles
public void displaySubtasks(UpdateEvent event)
{
if (!event.getType().equals(UpdateType.SEC))

View File

@ -61,11 +61,6 @@ public class TaskMakingMoney extends TutorialTask<TutorialGettingStarted>
return;
}
if (!ClansManager.getInstance().isInClan(event.getPlayer()))
{
return;
}
if (!event.getItem().getType().equals(Material.CARROT_ITEM))
{
return;