Better See Chunk
This commit is contained in:
parent
f1375ea699
commit
8630ae8ed3
@ -22,6 +22,7 @@ import com.massivecraft.factions.cmd.*;
|
||||
import com.massivecraft.factions.engine.EngineChat;
|
||||
import com.massivecraft.factions.engine.EngineEcon;
|
||||
import com.massivecraft.factions.engine.EngineExploit;
|
||||
import com.massivecraft.factions.engine.EngineIdUpdate;
|
||||
import com.massivecraft.factions.engine.EngineMain;
|
||||
import com.massivecraft.factions.engine.EngineSeeChunk;
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
|
@ -52,7 +52,8 @@ public enum Perm
|
||||
POWERBOOST("powerboost"),
|
||||
PROMOTE("promote"),
|
||||
RELATION("relation"),
|
||||
SEE_CHUNK("seechunk"),
|
||||
SEECHUNK("seechunk"),
|
||||
SEECHUNKOLD("seechunkold"),
|
||||
SETHOME("sethome"),
|
||||
NAME("name"),
|
||||
TITLE("title"),
|
||||
|
@ -36,6 +36,7 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader();
|
||||
public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney();
|
||||
public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk();
|
||||
public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld();
|
||||
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
|
||||
public CmdFactionsAutoClaim cmdFactionsAutoClaim = new CmdFactionsAutoClaim();
|
||||
public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
|
||||
@ -82,6 +83,7 @@ public class CmdFactions extends FactionsCommand
|
||||
this.addSubCommand(this.cmdFactionsLeader);
|
||||
this.addSubCommand(this.cmdFactionsMoney);
|
||||
this.addSubCommand(this.cmdFactionsSeeChunk);
|
||||
this.addSubCommand(this.cmdFactionsSeeChunkOld);
|
||||
this.addSubCommand(this.cmdFactionsClaim);
|
||||
this.addSubCommand(this.cmdFactionsAutoClaim);
|
||||
this.addSubCommand(this.cmdFactionsUnclaim);
|
||||
|
@ -1,16 +1,10 @@
|
||||
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.arg.ARBoolean;
|
||||
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;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsSeeChunk extends FactionsCommand
|
||||
{
|
||||
@ -22,9 +16,12 @@ public class CmdFactionsSeeChunk extends FactionsCommand
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("sc", "seechunk");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("active", "toggle");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqHasPerm.get(Perm.SEE_CHUNK.node));
|
||||
this.addRequirements(ReqHasPerm.get(Perm.SEECHUNK.node));
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
@ -36,45 +33,24 @@ public class CmdFactionsSeeChunk extends FactionsCommand
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
World world = me.getWorld();
|
||||
PS chunk = PS.valueOf(me).getChunk(true);
|
||||
int chunkX = chunk.getChunkX();
|
||||
int chunkZ = chunk.getChunkZ();
|
||||
boolean old = msender.isSeeingChunk();
|
||||
boolean targetDefault = !old;
|
||||
Boolean target = this.arg(0, ARBoolean.get(), targetDefault);
|
||||
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
|
||||
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);
|
||||
msender.setSeeingChunk(target);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.factions;
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -6,6 +6,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
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.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
@ -1,5 +1,12 @@
|
||||
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.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -7,12 +14,16 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
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
|
||||
{
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -31,6 +42,12 @@ public class EngineSeeChunk extends EngineAbstract
|
||||
return Factions.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getPeriod()
|
||||
{
|
||||
return 1L;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LEAVE AND WORLD CHANGE REMOVAL
|
||||
// -------------------------------------------- //
|
||||
@ -55,4 +72,104 @@ public class EngineSeeChunk extends EngineAbstract
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -311,6 +311,17 @@ public class MConf extends Entity<MConf>
|
||||
public boolean handleExploitEnderPearlClipping = true;
|
||||
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
|
||||
// -------------------------------------------- //
|
||||
|
@ -53,6 +53,7 @@ permissions:
|
||||
factions.promote: {description: promote lesser members in your 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.seechunkold: {description: see the chunk you stand in, default: false}
|
||||
factions.sethome: {description: set the faction home, default: false}
|
||||
factions.name: {description: set faction name, default: false}
|
||||
factions.title: {description: set player title, default: false}
|
||||
@ -109,6 +110,7 @@ permissions:
|
||||
factions.promote: true
|
||||
factions.relation: true
|
||||
factions.seechunk: true
|
||||
factions.seechunkold: true
|
||||
factions.sethome: true
|
||||
factions.name: true
|
||||
factions.title: true
|
||||
@ -183,6 +185,7 @@ permissions:
|
||||
factions.promote: true
|
||||
factions.relation: true
|
||||
factions.seechunk: true
|
||||
factions.seechunkold: true
|
||||
factions.sethome: true
|
||||
factions.name: true
|
||||
factions.title: true
|
||||
|
Loading…
Reference in New Issue
Block a user