Skip to content

Commit

Permalink
Нужно больше говнокода!
Browse files Browse the repository at this point in the history
  • Loading branch information
NazrinNya committed Sep 9, 2023
1 parent 398eee4 commit add2df8
Show file tree
Hide file tree
Showing 12 changed files with 105,766 additions and 36 deletions.
38 changes: 35 additions & 3 deletions src/main/java/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,38 @@
import arc.Events;
import arc.util.CommandHandler;
import arc.util.Log;
import arc.util.Strings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import mindustry.Vars;
import mindustry.game.EventType;
import mindustry.gen.Call;
import mindustry.gen.Groups;
import mindustry.gen.Player;
import mindustry.net.Packets;
import org.bson.Document;
import org.json.simple.parser.ParseException;
import plugin.discord.Bot;
import plugin.etc.AntiVpn;
import useful.Bundle;

import javax.sql.ConnectionEvent;
import java.io.IOException;

import static mindustry.Vars.*;
import static plugin.ConfigJson.discordurl;
import static plugin.commands.BanMenu.loadBanMenu;
import static plugin.commands.ConsoleCommands.loadServerCommands;
import static plugin.commands.MainCommands.*;
import static plugin.commands.history.History.historyPlayers;
import static plugin.commands.history.History.loadHistory;
import static plugin.etc.AntiVpn.loadAntiVPN;
import static plugin.functions.MongoDB.*;
import static plugin.functions.Other.kickIfBanned;
import static plugin.functions.Other.welcomeMenu;
import static plugin.utils.FindDocument.getDoc;


public class Plugin extends mindustry.mod.Plugin implements ApplicationListener{
Expand All @@ -43,19 +54,37 @@ public Plugin() throws IOException, ParseException {

// starts once plugin is started
public void init() {
loadAntiVPN();
loadBanMenu();
loadHistory();
Log.info("Plugin started!");
Bundle.load(Plugin.class);
Events.on(EventType.PlayerJoin.class, event -> {
Player plr = event.player;
welcomeMenu(plr);
MongoDbPlayerCreation(plr);
MongoDbPlayerNameCheck(plr);
MongoDbPlayerNameCheck(event.player);
MongoDbPlayerRankCheck(plr.uuid());
kickIfBanned(event.player);
Document user = getDoc(plr.uuid());
String joinMessage = user.getString("joinmessage");
if (joinMessage.endsWith(" ")){
joinMessage = joinMessage.substring(0, joinMessage.length()-1);
}
Call.sendMessage(Strings.format(joinMessage + " [grey][" + user.getInteger("id") + "]", plr.name()));
});
MongoDbPlaytimeTimer();
MongoDbCheck();
Events.on(EventType.PlayerConnect.class, event -> kickIfBanned(event.player));
Vars.net.handleServer(Packets.Connect.class, (con, connect) -> {
Events.fire(new EventType.ConnectionEvent(con));
MongoDbPlayerIpCheck(con);

if (netServer.admins.isIPBanned(connect.addressTCP) || netServer.admins.isSubnetBanned(connect.addressTCP)){
con.kick(Packets.KickReason.banned);
}
kickIfBanned(con);
if (AntiVpn.checkAddress(connect.addressTCP))
con.kick("[orange]You are suspected in using VPN or being a bot! Please, if its not true, report that incident on our discord: " + discordurl );
});
Events.on(EventType.PlayerChatEvent.class, event ->{
if (isVoting){
if (votedPlayer.contains(event.player)){
Expand All @@ -77,6 +106,9 @@ public void init() {
}
}
});
Events.on(EventType.PlayerLeave.class, event -> {
historyPlayers.remove(event.player.uuid());
});
}


Expand Down
6 changes: 4 additions & 2 deletions src/main/java/plugin/commands/ConsoleCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import static arc.util.Strings.canParseInt;
import static arc.util.Strings.parseInt;
import static plugin.Plugin.plrCollection;
import static plugin.functions.MongoDB.MongoDbPlayerRankCheck;
import static plugin.functions.MongoDB.MongoDbUpdate;
import static plugin.functions.MongoDB.*;
import static plugin.utils.FindDocument.getDoc;
import static plugin.utils.FindDocument.getDocAnyway;

Expand Down Expand Up @@ -53,5 +52,8 @@ public static void loadServerCommands(CommandHandler handler){
}
MongoDbPlayerRankCheck(user.getString("uuid"));
});
handler.register("check", "Checks mongodb", (args, params) -> {
MongoDbCheck();
});
}
}
66 changes: 60 additions & 6 deletions src/main/java/plugin/commands/MainCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
import arc.Events;
import arc.struct.Seq;
import arc.util.CommandHandler;
import arc.util.Strings;
import com.mongodb.BasicDBObject;
import com.mongodb.client.FindIterable;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
import mindustry.Vars;
import mindustry.game.EventType;
import mindustry.game.Team;
import mindustry.gen.Call;
import mindustry.gen.Groups;
import mindustry.gen.Player;
import mindustry.maps.Map;
import org.bson.BsonDocument;
import org.bson.Document;
import useful.Bundle;

import java.time.Duration;
import java.util.Arrays;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

import static arc.util.Strings.canParseInt;
import static arc.util.Strings.parseInt;
import static mindustry.Vars.*;
import static plugin.ConfigJson.discordurl;
import static plugin.Plugin.plrCollection;
import static plugin.commands.history.History.historyPlayers;
import static plugin.functions.MongoDB.MongoDbUpdate;
import static plugin.functions.Other.statsMenu;
import static plugin.utils.Checks.isConsole;
import static plugin.utils.FindDocument.getDoc;
import static plugin.utils.Utilities.*;

public class MainCommands {
Expand Down Expand Up @@ -68,14 +80,19 @@ public static void loadClientCommands(CommandHandler handler){
player.sendMessage("[scarlet]You must be console to use this command.");
}
});
handler.<Player>register("maps", "<page>","List all maps", (args, player) -> {
handler.<Player>register("maps", "[page]","List all maps", (args, player) -> {
StringBuilder list = new StringBuilder();
if (!canParseInt(args[0])){
player.sendMessage("[red]Page must be number!");
return;
int page;
if (Arrays.stream(args).toList().isEmpty()){
page = 0;
} else {
if (!canParseInt(args[0])){
player.sendMessage("[red]Page must be number!");
return;
}
page = Integer.parseInt(args[0]);
}
int mapsPerPage = 10;
int page = Integer.parseInt(args[0]);
Seq<Map> maps = getMaps();
maps.list().stream().skip(page*10L).limit(mapsPerPage + (page * 10L)).forEach(
map -> list.append(map.name() + "[white], by " + map.author())
Expand All @@ -100,7 +117,7 @@ public static void loadClientCommands(CommandHandler handler){
player.sendMessage("Could not find that map!");
return;
}
Call.sendMessage(player.plainName() + " Started vote for map " + choosedMap.plainName() + " -> " + votes.get() +"/"+ votesRequired[0] + ", y/n to vote");
Call.sendMessage(player.name() + "[white] Started vote for map " + choosedMap.plainName() + " -> " + votes.get() +"/"+ votesRequired[0] + ", y/n to vote");
isVoting = true;
timer.schedule((new TimerTask() {
@Override
Expand Down Expand Up @@ -135,5 +152,42 @@ public void run() {
}
statsMenu(player, plr);
});
handler.<Player>register("history", "Enables/Disables history", (args, player) -> {
if (historyPlayers.contains(player.uuid())){
historyPlayers.remove(player.uuid());
player.sendMessage("[red]History has been disabled!");
Call.hideHudText(player.con());
return;
}
historyPlayers.add(player.uuid());
player.sendMessage("[green]History has been enabled!");
});
handler.<Player>register("joinmessage", "<message...>", "Makes custom join message! @ -> your name. Make sure this message wont break any rule!", (args, player) -> {
Document user = getDoc(player.uuid());
if (args[0].length() >= 30){
player.sendMessage("Too much symbols! Limit is 30");
return;
}
if (Strings.count(args[0], "@") == 1){
MongoDbUpdate(user, Updates.set("joinmessage", args[0]));
player.sendMessage("[green]Changed your join message!");
} else {
player.sendMessage("[red]You dont have @ symbol or its count is more than one");
}
});
handler.<Player>register("leaderboard", "<playtime/wins>", "Shows leaderboard!", (args, player) -> {
StringBuilder list = new StringBuilder();
if (Objects.equals(args[0], "playtime")){
list.append("[orange]Playtime leaderboard: \n");
FindIterable<Document> sort = plrCollection.find().sort(new BasicDBObject("playtime", -1)).limit(10);
for (Document user : sort){
int playtime = user.getInteger("playtime");
list.append(user.getString("rawName") + "[white]: " + Bundle.formatDuration(Duration.ofMinutes(playtime)) + "\n");
}
player.sendMessage(list.toString());
} else {
player.sendMessage("лох ебаный");
}
});
}
}
128 changes: 128 additions & 0 deletions src/main/java/plugin/commands/history/History.java
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());
}
}
23 changes: 23 additions & 0 deletions src/main/java/plugin/commands/history/HistoryObject.java
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;
}
}
14 changes: 14 additions & 0 deletions src/main/java/plugin/commands/history/HistoryTile.java
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;
}
}
Loading

0 comments on commit add2df8

Please sign in to comment.