-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplePlugin.java
More file actions
84 lines (72 loc) · 3.59 KB
/
ExamplePlugin.java
File metadata and controls
84 lines (72 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package example;
import arc.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.mod.*;
import mindustry.net.Administration.*;
import mindustry.world.blocks.storage.*;
public class ExamplePlugin extends Plugin{
//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);
}
});
//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) -> text.replace("heck", "h*ck"));
//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
@Override
public void registerServerCommands(CommandHandler handler){
handler.register("reactors", "List all thorium reactors in the map.", 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);
}
}
}
});
}
//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]);
});
}
}