-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
105,766 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package plugin.commands.history; | ||
|
||
import arc.Events; | ||
import arc.struct.Seq; | ||
import arc.util.Align; | ||
import arc.util.Threads; | ||
import mindustry.Vars; | ||
import mindustry.game.EventType; | ||
import mindustry.gen.Building; | ||
import mindustry.gen.Call; | ||
import mindustry.gen.Groups; | ||
import mindustry.gen.Player; | ||
import mindustry.world.Block; | ||
import mindustry.world.Tile; | ||
import mindustry.world.blocks.ConstructBlock; | ||
import useful.Bundle; | ||
|
||
import java.util.Date; | ||
|
||
import static java.lang.reflect.Array.get; | ||
import static mindustry.Vars.emptyTile; | ||
import static mindustry.Vars.world; | ||
|
||
public class History { | ||
static Seq<HistoryTile> historyTilesSeq = new Seq<>(); | ||
public static Seq<String> historyPlayers = new Seq<>(); | ||
public static void loadHistory(){ | ||
Events.on(EventType.BlockBuildEndEvent.class, event -> { | ||
int block = event.tile.build instanceof ConstructBlock.ConstructBuild build ? build.current.id : event.tile.blockID(); | ||
if (!event.unit.isPlayer()) return; | ||
if (event.breaking){ | ||
HistoryObject obj = new HistoryObject(event.tile, Vars.content.block(block), event.unit.getPlayer(), "broke", new Date()); | ||
add(obj, obj.tile); | ||
} else { | ||
HistoryObject obj = new HistoryObject(event.tile, Vars.content.block(block), event.unit.getPlayer(), "built", new Date()); | ||
add(obj, obj.tile); | ||
} | ||
}); | ||
Events.on(EventType.BuildRotateEvent.class, event -> { | ||
int block = event.build instanceof ConstructBlock.ConstructBuild build ? build.current.id : event.build.tile.blockID(); | ||
if (!event.unit.isPlayer()) return; | ||
HistoryObject obj = new HistoryObject(event.build.tile, Vars.content.block(block), event.unit.getPlayer(), "rotated", new Date()); | ||
add(obj, obj.tile); | ||
}); | ||
Events.on(EventType.ConfigEvent.class, event -> { | ||
int block = event.tile instanceof ConstructBlock.ConstructBuild build ? build.current.id : event.tile.block().id; | ||
if (event.player == null) return; | ||
HistoryObject obj = new HistoryObject(event.tile.tile, Vars.content.block(block), event.player, "configured", new Date()); | ||
add(obj, obj.tile); | ||
}); | ||
/*Events.on(EventType.TapEvent.class, event -> { | ||
if (!historyPlayers.contains(event.player.uuid())){ | ||
return; | ||
} | ||
StringBuilder list = new StringBuilder(); | ||
list.append("[orange]Tile history:[white]\n"); | ||
HistoryTile tile = getTile(event.tile); | ||
Seq<HistoryObject> reversed = new Seq<>(tile.objectSeq); | ||
reversed.reverse(); | ||
if (reversed.isEmpty()){ | ||
list.append("[red]No actions has been done on this tile!"); | ||
} else { | ||
for (HistoryObject obj : reversed) { | ||
if (obj.tile == Vars.world.tileWorld(event.player.mouseX, event.player.mouseY)) { | ||
list.append(format(obj)); | ||
} | ||
} | ||
} | ||
event.player.sendMessage(list.toString()); | ||
});*/ | ||
Events.run(EventType.Trigger.update, () -> { | ||
Threads.daemon(() -> { | ||
for (Player plr : Groups.player){ | ||
if (historyPlayers.contains(plr.uuid())) { | ||
Tile Eventtile = world.tileWorld(plr.mouseX, plr.mouseY); | ||
if (Eventtile != null) { | ||
StringBuilder list = new StringBuilder(); | ||
HistoryTile tile = getTile(Eventtile); | ||
Seq<HistoryObject> reversed = new Seq<>(tile.objectSeq); | ||
reversed.reverse(); | ||
for (HistoryObject obj : reversed) { | ||
if (obj.tile == Vars.world.tileWorld(plr.mouseX, plr.mouseY)) { | ||
list.append(format(obj)); | ||
} | ||
} | ||
list.append("[").append(Eventtile.x).append(", ").append(Eventtile.y).append("]"); | ||
/*Call.infoPopup(plr.con(), list.toString(), 0.017f, Align.center | Align.left, 0, 0, 0, 0);*/ | ||
Call.setHudText(plr.con(), list.toString()); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
Events.on(EventType.GameOverEvent.class, event -> { | ||
historyTilesSeq.clear(); | ||
}); | ||
} | ||
public static void add(HistoryObject obj, Tile tile){ | ||
if(obj.tile == emptyTile) return; | ||
obj.tile.getLinkedTiles(other -> { | ||
HistoryObject newObj = new HistoryObject(other, obj.actionBlock, obj.actionPlayer, obj.action, obj.time); | ||
HistoryTile realTile = getTile(other); | ||
HistoryTile newTile = getTile(other); | ||
Seq<HistoryObject> objectSeq = new Seq<>(realTile.objectSeq); | ||
objectSeq.add(newObj); | ||
if (objectSeq.size > 7){ | ||
objectSeq.remove(0); | ||
} | ||
newTile.objectSeq = objectSeq; | ||
if (historyTilesSeq.contains(realTile)){ | ||
historyTilesSeq.replace(realTile, newTile); | ||
} else { | ||
historyTilesSeq.add(newTile); | ||
} | ||
}); | ||
} | ||
public static String format(HistoryObject obj){ | ||
return Bundle.formatDateTime(obj.time) + " " +obj.actionPlayer.name() + "[white] " + obj.action + " " + obj.actionBlock.emoji() + "\n"; | ||
} | ||
public static HistoryTile getTile(Tile tile){ | ||
for (HistoryTile histTile : historyTilesSeq){ | ||
if (histTile.tileX == tile.worldx() && histTile.tileY == tile.worldy()){ | ||
return histTile; | ||
} | ||
} | ||
return new HistoryTile(tile.worldx(), tile.worldy()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package plugin.commands.history; | ||
|
||
import mindustry.gen.Player; | ||
import mindustry.world.Block; | ||
import mindustry.world.Tile; | ||
|
||
import java.util.Date; | ||
|
||
public class HistoryObject { | ||
public final Tile tile; | ||
public final Block actionBlock; | ||
public final Player actionPlayer; | ||
public final String action; | ||
public final Date time; | ||
|
||
public HistoryObject(Tile tile, Block actionBlock, Player actionPlayer, String action, Date time) { | ||
this.tile = tile; | ||
this.actionBlock = actionBlock; | ||
this.actionPlayer = actionPlayer; | ||
this.action = action; | ||
this.time = time; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package plugin.commands.history; | ||
|
||
import arc.struct.Seq; | ||
|
||
public class HistoryTile { | ||
public Seq<HistoryObject> objectSeq = new Seq<>(); | ||
public final float tileX; | ||
public final float tileY; | ||
|
||
public HistoryTile(float tileX, float tileY) { | ||
this.tileX = tileX; | ||
this.tileY = tileY; | ||
} | ||
} |
Oops, something went wrong.