Skip to content

Commit

Permalink
Adjust some format
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhenwei committed Aug 6, 2021
1 parent bfdd6cb commit 6c41cf5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 110 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: "java"

version '0.0.3'
version '0.0.4'

sourceCompatibility = 1.8

Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"author": "Myke.H",
"main": "MykesTool.MTDChatBotPlugin",
"description": "Mindustry Chat Bot.",
"version": "0.0.3"
"version": "0.0.4"
}
133 changes: 25 additions & 108 deletions src/MykesTool/MTDChatBotPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package MykesTool;

import arc.graphics.Color;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
Expand All @@ -8,6 +9,8 @@
import mindustry.gen.*;
import mindustry.mod.*;
import mindustry.net.Administration.*;
import mindustry.net.Net;
import mindustry.net.NetConnection;
import mindustry.world.blocks.storage.*;
import java.io.*;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -89,61 +92,39 @@ private static String doGet(String httpurl) {
}

private String m_strLogPrefix = "[MykesTool:ChatBot]";
private String m_strBotName = "myke";
private NetClient m_nc;
private Player m_pNew;
private Player m_playerNew;
//called when game initializes
@Override
public void init() {
/*
//listen for a block selection event
Events.on(BuildSelectEvent.class, event -> {
if(!event.breaking && event.builder != null && event.builder.buildPlan() != null && event.builder.buildPlan().block == Blocks.thoriumReactor && event.builder.isPlayer()){
//player is the unit controller
Player player = event.builder.getPlayer();
//send a message to everyone saying that this player has begun building a reactor
Call.sendMessage("[scarlet]ALERT![] " + player.name + " has begun building a reactor at " + event.tile.x + ", " + event.tile.y);
}
});
*/

//Events.on(Event.class, event -> {
/*
m_pNew = Player.create();
m_pNew.name = "asdf";
m_pNew.admin = true;
m_pNew.id = 123;
Groups.player.add(m_pNew);
m_nc = new NetClient();
m_nc.init();
m_nc.beginConnecting();
*/


//add a chat filter that changes the contents of all messages
//in this case, all instances of "heck" are censored
Vars.netServer.admins.addChatFilter((player, text) -> {
/*
if(m_pNew == null || m_nc == null) {
m_nc = new NetClient();
//m_nc.
m_nc.init();
m_nc.beginConnecting();
m_pNew = Player.create();
m_pNew.name = "asdf";
m_pNew.admin = true;
m_pNew.id = 123;
Vars.netServer.admins.addChatFilter((player, text) -> {

/*
if(m_playerNew == null || m_nc == null) {
m_playerNew = Player.create();
m_playerNew.name = m_strBotName;
m_playerNew.admin = true;
m_playerNew.id = 123;
m_playerNew.id(123);
Groups.player.add(m_playerNew);
//m_pNew.locale = packet.locale;
//m_pNew.color.set(packet.color).a(1f);
m_playerNew.color.set(Color.yellow);
Vars.netServer.sendWorldData(player);
}
*/
player.sendMessage("test", m_playerNew);
*/


int nBotNamePos = -1;
String strCallName = "@myke";
String strCallName = "@" + m_strBotName;
String strMsgPrefix = "[red][[[yellow]"+m_strBotName+"的小仆ff[red]][white]";
nBotNamePos = text.indexOf(strCallName);
//Log.info(text);
//Log.info(nBotNamePos);
Expand All @@ -166,81 +147,17 @@ public void init() {
//Groups.player.find();
String strContent = jsonResult.getString("content");
String strFormattedContent = strContent.replace("{br}", "\n");
player.sendMessage(strFormattedContent);
//player.sendMessage(strMsgPrefix + strFormattedContent);
text = text + "\n" + strMsgPrefix + strFormattedContent;
} else {
Log.info(m_strLogPrefix + " error getting message.");
}
}
//player.sendMessage("try to do something for v008");
return text;
});
//Vars.netServer.admins.addChatFilter((player, text) -> text.replace("111", "****"));

/*
//add an action filter for preventing players from doing certain things
Vars.netServer.admins.addActionFilter(action -> {
//random example: prevent blast compound depositing
if(action.type == ActionType.depositItem && action.item == Items.blastCompound && action.tile.block() instanceof CoreBlock){
action.player.sendMessage("Example action filter: Prevents players from depositing blast compound into the core.");
return false;
}
return true;
});
*/


//register commands that run on the server
/* // sample
@Override
public void registerServerCommands(CommandHandler handler){
handler.register("reloadwordmask", "Reload word mask in config/DirtyWords.txt.", args -> {
for(int x = 0; x < Vars.world.width(); x++){
for(int y = 0; y < Vars.world.height(); y++){
//loop through and log all found reactors
//make sure to only log reactor centers
if(Vars.world.tile(x, y).block() == Blocks.thoriumReactor && Vars.world.tile(x, y).isCenter()){
Log.info("Reactor at @, @", x, y);
}
}
}
});
}
*/
}

@Override
public void registerServerCommands(CommandHandler handler){
handler.register("reloadwordmask", "Reload word mask in config/DirtyWords.txt.", args -> {
//this.reloadWords();
});
}

/*
//register commands that player can invoke in-game
@Override
public void registerClientCommands(CommandHandler handler){

//register a simple reply command
handler.<Player>register("reply", "<text...>", "A simple ping command that echoes a player's text.", (args, player) -> {
player.sendMessage("You said: [accent] " + args[0]);
});
//register a whisper command which can be used to send other players messages
handler.<Player>register("whisper", "<player> <text...>", "Whisper text to another player.", (args, player) -> {
//find player by name
Player other = Groups.player.find(p -> p.name.equalsIgnoreCase(args[0]));
//give error message with scarlet-colored text if player isn't found
if(other == null){
player.sendMessage("[scarlet]No player by that name found!");
return;
}
//send the other player a message, using [lightgray] for gray text color and [] to reset color
other.sendMessage("[lightgray](whisper) " + player.name + ":[] " + args[1]);
});
}

*/
}

0 comments on commit 6c41cf5

Please sign in to comment.