forked from SteamWar/SteamWar
Fix RegionConfig
Implement FixedRegion Add RegionHistory.Impl
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -117,7 +118,7 @@ public class RegionConfig {
|
||||
private void load(ConfigurationSection section) {
|
||||
Active = section.getBoolean("Active", false);
|
||||
ObfuscateWith = Material.getMaterial(section.getString("ObfuscateWith", "END_STONE"));
|
||||
HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(Material::getMaterial).collect(Collectors.toUnmodifiableSet());
|
||||
HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(FlatteningWrapper.impl::getMaterial).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
|
||||
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(section.getStringList("HiddenBlockEntities")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public interface RegionHistory {
|
||||
|
||||
@@ -45,4 +49,44 @@ public interface RegionHistory {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Impl implements RegionHistory {
|
||||
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
|
||||
public Impl(int size) {
|
||||
this.undoSessions = new SizedStack<>(size);
|
||||
this.redoSessions = new SizedStack<>(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remember(@NonNull EditSession editSession) {
|
||||
undoSessions.push(editSession);
|
||||
if (redoSessions.empty()) return;
|
||||
redoSessions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean undo() {
|
||||
EditSession session = undoSessions.pop();
|
||||
if (session == null) return false;
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.undo(e);
|
||||
redoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean redo() {
|
||||
EditSession session = redoSessions.pop();
|
||||
if (session == null) return false;
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.redo(e);
|
||||
undoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ public class SizedStack<T> {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.data = (T[]) new Object[this.maxSize];
|
||||
this.head = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder result = new StringBuilder("[");
|
||||
|
||||
Reference in New Issue
Block a user