mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Fix multiple zones not showing.
This commit is contained in:
parent
c557b4128c
commit
02a1d6aa58
@ -100,8 +100,7 @@ namespace MCGalaxy {
|
||||
|
||||
unsafe static byte NextFreeId(PlayerBot bot) {
|
||||
byte* used = stackalloc byte[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
used[i] = 0;
|
||||
for (int i = 0; i < 256; i++) used[i] = 0;
|
||||
|
||||
PlayerBot[] bots = bot.level.Bots.Items;
|
||||
for (int i = 0; i < bots.Length; i++) {
|
||||
|
@ -72,7 +72,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
zone.MaxY = (ushort)Math.Max(marks[0].Y, marks[1].Y);
|
||||
zone.MaxZ = (ushort)Math.Max(marks[0].Z, marks[1].Z);
|
||||
|
||||
p.level.Zones.Add(zone);
|
||||
zone.AddTo(p.level);
|
||||
p.level.Save(true);
|
||||
Player.Message(p, "Created zone " + zone.ColoredName);
|
||||
return false;
|
||||
@ -137,8 +137,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Level lvl = p.level;
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < lvl.Zones.Count; i++) {
|
||||
Zone z = lvl.Zones[i];
|
||||
Zone[] zones = lvl.Zones.Items;
|
||||
for (int i = 0; i < zones.Length; i++) {
|
||||
Zone z = zones[i];
|
||||
if (!z.Contains(P.X, P.Y, P.Z)) continue;
|
||||
found = true;
|
||||
|
||||
@ -163,7 +164,8 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
public override bool museumUsable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
MultiPageOutput.Output(p, p.level.Zones, FormatZone, "ZoneList", "zones", message, true);
|
||||
Zone[] zones = p.level.Zones.Items;
|
||||
MultiPageOutput.Output(p, zones, FormatZone, "ZoneList", "zones", message, true);
|
||||
}
|
||||
|
||||
static string FormatZone(Zone zone) {
|
||||
|
@ -59,7 +59,8 @@ namespace MCGalaxy.Core {
|
||||
|
||||
// TODO: unshow old zones here??
|
||||
if (p.Supports(CpeExt.SelectionCuboid)) {
|
||||
foreach (Zone zn in level.Zones) { zn.Show(p); }
|
||||
Zone[] zones = level.Zones.Items;
|
||||
foreach (Zone zn in zones) { zn.Show(p); }
|
||||
}
|
||||
|
||||
if (!level.Config.Guns && p.aiming) {
|
||||
|
@ -137,11 +137,11 @@ namespace MCGalaxy.Levels.IO {
|
||||
}
|
||||
|
||||
static void WriteZonesSection(Level lvl, Stream gs, byte[] buffer) {
|
||||
List<Zone> zones = lvl.Zones;
|
||||
if (zones.Count == 0) return;
|
||||
Zone[] zones = lvl.Zones.Items;
|
||||
if (zones.Length == 0) return;
|
||||
|
||||
gs.WriteByte(0x51);
|
||||
NetUtils.WriteI32(zones.Count, buffer, 0);
|
||||
NetUtils.WriteI32(zones.Length, buffer, 0);
|
||||
gs.Write(buffer, 0, sizeof(int));
|
||||
|
||||
foreach (Zone z in zones) {
|
||||
|
@ -164,7 +164,7 @@ namespace MCGalaxy.Levels.IO {
|
||||
ConfigElement.Parse(elems, key, value, z.Config);
|
||||
}
|
||||
|
||||
lvl.Zones.Add(z);
|
||||
z.AddTo(lvl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,19 +199,20 @@ namespace MCGalaxy {
|
||||
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z, ExtBlock old, ExtBlock block) {
|
||||
if (!p.group.Blocks[old.BlockID] && !Block.AllowBreak(old.BlockID) && !Block.BuildIn(old.BlockID)) return false;
|
||||
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref block.BlockID)) return false;
|
||||
if (Zones.Count == 0) return CheckRank(p);
|
||||
Zone[] zones = Zones.Items;
|
||||
if (zones.Length == 0) return CheckRank(p);
|
||||
|
||||
// Check zones specifically allowed in
|
||||
for (int i = 0; i < Zones.Count; i++) {
|
||||
Zone zn = Zones[i];
|
||||
for (int i = 0; i < zones.Length; i++) {
|
||||
Zone zn = zones[i];
|
||||
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
||||
AccessResult access = zn.Access.Check(p);
|
||||
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) return true;
|
||||
}
|
||||
|
||||
// Check zones denied from
|
||||
for (int i = 0; i < Zones.Count; i++) {
|
||||
Zone zn = Zones[i];
|
||||
for (int i = 0; i < zones.Length; i++) {
|
||||
Zone zn = zones[i];
|
||||
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
||||
AccessResult access = zn.Access.Check(p);
|
||||
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue;
|
||||
|
@ -75,7 +75,7 @@ namespace MCGalaxy {
|
||||
BufferedBlockSender bulkSender;
|
||||
|
||||
public List<UndoPos> UndoBuffer = new List<UndoPos>();
|
||||
public List<Zone> Zones;
|
||||
public VolatileArray<Zone> Zones = new VolatileArray<Zone>();
|
||||
public bool backedup;
|
||||
public BlockDB BlockDB;
|
||||
public LevelAccessController VisitAccess, BuildAccess;
|
||||
|
@ -73,7 +73,6 @@ namespace MCGalaxy {
|
||||
spawnz = (ushort)(Length / 2);
|
||||
rotx = 0; roty = 0;
|
||||
|
||||
Zones = new List<Zone>();
|
||||
VisitAccess = new LevelAccessController(this, true);
|
||||
BuildAccess = new LevelAccessController(this, false);
|
||||
listCheckExists = new SparseBitSet(Width, Height, Length);
|
||||
@ -105,7 +104,8 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public Zone FindZoneExact(string name) {
|
||||
foreach (Zone zone in Zones) {
|
||||
Zone[] zones = Zones.Items;
|
||||
foreach (Zone zone in zones) {
|
||||
if (zone.Config.Name.CaselessEq(name)) return zone;
|
||||
}
|
||||
return null;
|
||||
|
@ -68,7 +68,7 @@ namespace MCGalaxy {
|
||||
|
||||
z.Config.Name = "Zone" + id;
|
||||
id++;
|
||||
level.Zones.Add(z);
|
||||
z.AddTo(level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Config;
|
||||
using MCGalaxy.Network;
|
||||
using MCGalaxy.Maths;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
@ -99,6 +99,12 @@ namespace MCGalaxy {
|
||||
public ZoneAccessController Access;
|
||||
public string ColoredName { get { return Config.Color + Config.Name; } }
|
||||
|
||||
public Zone(Level lvl) {
|
||||
Config = new ZoneConfig();
|
||||
Access = new ZoneAccessController(lvl, Config);
|
||||
}
|
||||
|
||||
|
||||
public bool Contains(int x, int y, int z) {
|
||||
return x >= MinX && x <= MaxX && y >= MinY && y <= MaxY && z >= MinZ && z <= MaxZ;
|
||||
}
|
||||
@ -108,27 +114,45 @@ namespace MCGalaxy {
|
||||
MaxX == lvl.Width - 1 && MaxY == lvl.Height - 1 && MaxZ == lvl.Length - 1;
|
||||
}
|
||||
|
||||
public bool Shows { get { return Config.ShowAlpha != 0 && Config.ShowColor != ""; } }
|
||||
public bool Shows { get { return Config.ShowAlpha != 0 && Config.ShowColor != ""; } }
|
||||
public void Show(Player p) {
|
||||
if (!p.Supports(CpeExt.SelectionCuboid) || !Shows) return;
|
||||
|
||||
ColorDesc col = Colors.ParseHex(Config.ShowColor);
|
||||
p.Send(Packet.MakeSelection(
|
||||
ID, "", new Vec3U16(MinX, MinY, MinZ),
|
||||
ID, "", new Vec3U16(MinX, MinY, MinZ),
|
||||
new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1)),
|
||||
col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437));
|
||||
col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437));
|
||||
}
|
||||
|
||||
public void ShowAll(Level lvl) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level == lvl) Show(p);
|
||||
}
|
||||
if (p.level == lvl) Show(p);
|
||||
}
|
||||
}
|
||||
|
||||
public Zone(Level lvl) {
|
||||
Config = new ZoneConfig();
|
||||
Access = new ZoneAccessController(lvl, Config);
|
||||
public void AddTo(Level level) {
|
||||
lock (level.Zones.locker) {
|
||||
ID = NextFreeZoneId(level);
|
||||
level.Zones.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe byte NextFreeZoneId(Level level) {
|
||||
byte* used = stackalloc byte[256];
|
||||
for (int i = 0; i < 256; i++) used[i] = 0;
|
||||
|
||||
Zone[] zones = level.Zones.Items;
|
||||
for (int i = 0; i < zones.Length; i++) {
|
||||
byte id = zones[i].ID;
|
||||
used[id] = 1;
|
||||
}
|
||||
|
||||
for (byte i = 0; i <= 255; i++ ) {
|
||||
if (used[i] == 0) return i;
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
}
|
||||
}
|
@ -176,8 +176,7 @@ namespace MCGalaxy {
|
||||
|
||||
unsafe static byte NextFreeId() {
|
||||
byte* used = stackalloc byte[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
used[i] = 0;
|
||||
for (int i = 0; i < 256; i++) used[i] = 0;
|
||||
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
for (int i = 0; i < players.Length; i++) {
|
||||
|
@ -90,7 +90,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Find partial matches of 'name' against the list of zones in a map. </summary>
|
||||
public static Zone FindZones(Player p, Level lvl, string name) {
|
||||
int matches = 0;
|
||||
return Find<Zone>(p, name, out matches, lvl.Zones,
|
||||
return Find<Zone>(p, name, out matches, lvl.Zones.Items,
|
||||
null, z => z.Config.Name, "zones");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user