Better See Chunk

This commit is contained in:
Olof Larsson 2014-10-08 09:24:03 +02:00
parent f1375ea699
commit 8630ae8ed3
9 changed files with 241 additions and 48 deletions

View File

@ -22,6 +22,7 @@ import com.massivecraft.factions.cmd.*;
import com.massivecraft.factions.engine.EngineChat; import com.massivecraft.factions.engine.EngineChat;
import com.massivecraft.factions.engine.EngineEcon; import com.massivecraft.factions.engine.EngineEcon;
import com.massivecraft.factions.engine.EngineExploit; import com.massivecraft.factions.engine.EngineExploit;
import com.massivecraft.factions.engine.EngineIdUpdate;
import com.massivecraft.factions.engine.EngineMain; import com.massivecraft.factions.engine.EngineMain;
import com.massivecraft.factions.engine.EngineSeeChunk; import com.massivecraft.factions.engine.EngineSeeChunk;
import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.Board;

View File

@ -52,7 +52,8 @@ public enum Perm
POWERBOOST("powerboost"), POWERBOOST("powerboost"),
PROMOTE("promote"), PROMOTE("promote"),
RELATION("relation"), RELATION("relation"),
SEE_CHUNK("seechunk"), SEECHUNK("seechunk"),
SEECHUNKOLD("seechunkold"),
SETHOME("sethome"), SETHOME("sethome"),
NAME("name"), NAME("name"),
TITLE("title"), TITLE("title"),

View File

@ -36,6 +36,7 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader(); public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader();
public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney();
public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk();
public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld();
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
public CmdFactionsAutoClaim cmdFactionsAutoClaim = new CmdFactionsAutoClaim(); public CmdFactionsAutoClaim cmdFactionsAutoClaim = new CmdFactionsAutoClaim();
public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
@ -82,6 +83,7 @@ public class CmdFactions extends FactionsCommand
this.addSubCommand(this.cmdFactionsLeader); this.addSubCommand(this.cmdFactionsLeader);
this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsMoney);
this.addSubCommand(this.cmdFactionsSeeChunk); this.addSubCommand(this.cmdFactionsSeeChunk);
this.addSubCommand(this.cmdFactionsSeeChunkOld);
this.addSubCommand(this.cmdFactionsClaim); this.addSubCommand(this.cmdFactionsClaim);
this.addSubCommand(this.cmdFactionsAutoClaim); this.addSubCommand(this.cmdFactionsAutoClaim);
this.addSubCommand(this.cmdFactionsUnclaim); this.addSubCommand(this.cmdFactionsUnclaim);

View File

@ -1,16 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
public class CmdFactionsSeeChunk extends FactionsCommand public class CmdFactionsSeeChunk extends FactionsCommand
{ {
@ -22,9 +16,12 @@ public class CmdFactionsSeeChunk extends FactionsCommand
{ {
// Aliases // Aliases
this.addAliases("sc", "seechunk"); this.addAliases("sc", "seechunk");
// Args
this.addOptionalArg("active", "toggle");
// Requirements // Requirements
this.addRequirements(ReqHasPerm.get(Perm.SEE_CHUNK.node)); this.addRequirements(ReqHasPerm.get(Perm.SEECHUNK.node));
this.addRequirements(ReqIsPlayer.get()); this.addRequirements(ReqIsPlayer.get());
} }
@ -36,45 +33,24 @@ public class CmdFactionsSeeChunk extends FactionsCommand
public void perform() public void perform()
{ {
// Args // Args
World world = me.getWorld(); boolean old = msender.isSeeingChunk();
PS chunk = PS.valueOf(me).getChunk(true); boolean targetDefault = !old;
int chunkX = chunk.getChunkX(); Boolean target = this.arg(0, ARBoolean.get(), targetDefault);
int chunkZ = chunk.getChunkZ(); if (target == null) return;
String targetDesc = Txt.parse(target ? "<g>ON": "<b>OFF");
// NoChange
if (target.equals(old))
{
msg("<i>See Chunk is already %s<i>.", targetDesc);
return;
}
// Apply // Apply
int blockX; msender.setSeeingChunk(target);
int blockZ;
blockX = chunkX*16;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
// Inform // Inform
msg("<i>Visualized %s", chunk.toString(PSFormatHumanSpace.get())); msg("<i>See Chunk is now %s<i>.", targetDesc);
} }
@SuppressWarnings("deprecation")
public static void showPillar(Player player, World world, int blockX, int blockZ)
{
for (int blockY = 0; blockY < world.getMaxHeight(); blockY++)
{
Location loc = new Location(world, blockX, blockY, blockZ);
if (loc.getBlock().getType() != Material.AIR) continue;
int typeId = blockY % 5 == 0 ? Material.GLOWSTONE.getId() : Material.GLASS.getId();
VisualizeUtil.addLocation(player, loc, typeId);
}
}
} }

View File

@ -0,0 +1,80 @@
package com.massivecraft.factions.cmd;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
public class CmdFactionsSeeChunkOld extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsSeeChunkOld()
{
// Aliases
this.addAliases("sco", "seechunkold");
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.SEECHUNKOLD.node));
this.addRequirements(ReqIsPlayer.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Args
World world = me.getWorld();
PS chunk = PS.valueOf(me).getChunk(true);
int chunkX = chunk.getChunkX();
int chunkZ = chunk.getChunkZ();
// Apply
int blockX;
int blockZ;
blockX = chunkX*16;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
// Inform
msg("<i>Visualized %s", chunk.toString(PSFormatHumanSpace.get()));
}
@SuppressWarnings("deprecation")
public static void showPillar(Player player, World world, int blockX, int blockZ)
{
for (int blockY = 0; blockY < world.getMaxHeight(); blockY++)
{
Location loc = new Location(world, blockX, blockY, blockZ);
if (loc.getBlock().getType() != Material.AIR) continue;
int typeId = blockY % 5 == 0 ? Material.GLOWSTONE.getId() : Material.GLASS.getId();
VisualizeUtil.addLocation(player, loc, typeId);
}
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions; package com.massivecraft.factions.engine;
import java.util.Set; import java.util.Set;
@ -6,6 +6,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.Board;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;

View File

@ -1,5 +1,12 @@
package com.massivecraft.factions.engine; package com.massivecraft.factions.engine;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -7,12 +14,16 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.particleeffect.ParticleEffect;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.PeriodUtil;
public class EngineSeeChunk extends EngineAbstract public class EngineSeeChunk extends EngineAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
@ -31,6 +42,12 @@ public class EngineSeeChunk extends EngineAbstract
return Factions.get(); return Factions.get();
} }
@Override
public Long getPeriod()
{
return 1L;
}
// -------------------------------------------- // // -------------------------------------------- //
// LEAVE AND WORLD CHANGE REMOVAL // LEAVE AND WORLD CHANGE REMOVAL
// -------------------------------------------- // // -------------------------------------------- //
@ -55,4 +72,104 @@ public class EngineSeeChunk extends EngineAbstract
leaveAndWorldChangeRemoval(event.getPlayer()); leaveAndWorldChangeRemoval(event.getPlayer());
} }
// -------------------------------------------- //
// MODULO REPEAT TASK
// -------------------------------------------- //
@Override
public void run()
{
// Do we have a new period?
final long now = System.currentTimeMillis();
final long length = MConf.get().seeChunkPeriodMillis;
if ( ! PeriodUtil.isNewPeriod(this, length, now)) return;
// Get the period number
final long period = PeriodUtil.getPeriod(length, now);
// Calculate the "step" from the period number
final int steps = MConf.get().seeChunkSteps; // Example: 4
final int step = (int) (period % steps); // Example: 0, 1, 2, 3
// Load other related config options
final float offsetX = 0.2f;
final float offsetY = MConf.get().seeChunkParticleOffsetY;
final float offsetZ = 0.2f;
final float speed = 0;
final int amount = MConf.get().seeChunkParticleAmount;
// For each player
for (Player player : Bukkit.getOnlinePlayers())
{
MPlayer mplayer = MPlayer.get(player);
if ( ! mplayer.isSeeingChunk()) continue;
List<Location> locations = getLocations(player, steps, step);
for (Location location : locations)
{
ParticleEffect.EXPLODE.display(location, offsetX, offsetY, offsetZ, speed, amount, player);
}
}
}
public static List<Location> getLocations(Player player, int steps, int step)
{
// Clean Args
if (player == null) throw new NullPointerException("player");
if (steps < 1) throw new InvalidParameterException("steps must be larger than 0");
if (step < 0) throw new InvalidParameterException("step must at least be 0");
if (step >= steps) throw new InvalidParameterException("step must be less than steps");
// Create Ret
List<Location> ret = new ArrayList<Location>();
final Location location = player.getLocation();
final World world = location.getWorld();
PS chunk = PS.valueOf(location).getChunk(true);
final int xmin = chunk.getChunkX() * 16;
final int xmax = xmin + 15;
final double y = location.getBlockY() + MConf.get().seeChunkParticleDeltaY;
final int zmin = chunk.getChunkZ() * 16;
final int zmax = zmin + 15;
int x = xmin;
int z = zmin;
int i = 0;
// Add #1
while (x + 1 <= xmax)
{
x++;
i++;
if (i % steps == step) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
// Add #2
while (z + 1 <= zmax)
{
z++;
i++;
if (i % steps == step) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
// Add #3
while (x - 1 >= xmin)
{
x--;
i++;
if (i % steps == step) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
// Add #4
while (z - 1 >= zmin)
{
z--;
i++;
if (i % steps == step) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
// Return Ret
return ret;
}
} }

View File

@ -311,6 +311,17 @@ public class MConf extends Entity<MConf>
public boolean handleExploitEnderPearlClipping = true; public boolean handleExploitEnderPearlClipping = true;
public boolean handleExploitTNTWaterlog = false; public boolean handleExploitTNTWaterlog = false;
// -------------------------------------------- //
// SEE CHUNK
// -------------------------------------------- //
// Use 1 or multiple of 3, 4 or 5.
public int seeChunkSteps = 5;
public long seeChunkPeriodMillis = 1000;
public int seeChunkParticleAmount = 30;
public float seeChunkParticleOffsetY = 2;
public float seeChunkParticleDeltaY = 2;
// -------------------------------------------- // // -------------------------------------------- //
// LOGGING // LOGGING
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -53,6 +53,7 @@ permissions:
factions.promote: {description: promote lesser members in your faction, default: false} factions.promote: {description: promote lesser members in your faction, default: false}
factions.relation: {description: set relation wish to another faction, default: false} factions.relation: {description: set relation wish to another faction, default: false}
factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunk: {description: see the chunk you stand in, default: false}
factions.seechunkold: {description: see the chunk you stand in, default: false}
factions.sethome: {description: set the faction home, default: false} factions.sethome: {description: set the faction home, default: false}
factions.name: {description: set faction name, default: false} factions.name: {description: set faction name, default: false}
factions.title: {description: set player title, default: false} factions.title: {description: set player title, default: false}
@ -109,6 +110,7 @@ permissions:
factions.promote: true factions.promote: true
factions.relation: true factions.relation: true
factions.seechunk: true factions.seechunk: true
factions.seechunkold: true
factions.sethome: true factions.sethome: true
factions.name: true factions.name: true
factions.title: true factions.title: true
@ -183,6 +185,7 @@ permissions:
factions.promote: true factions.promote: true
factions.relation: true factions.relation: true
factions.seechunk: true factions.seechunk: true
factions.seechunkold: true
factions.sethome: true factions.sethome: true
factions.name: true factions.name: true
factions.title: true factions.title: true