/
CommandSetLoginMessage.java
63 lines (58 loc) · 1.87 KB
/
CommandSetLoginMessage.java
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
package net.doubledoordev.d3core.util;
import com.google.gson.JsonParseException;
import net.doubledoordev.d3core.D3Core;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
/**
* @author Dries007
*/
public class CommandSetLoginMessage extends CommandBase
{
@Override
public String getCommandName()
{
return "setloginmessage";
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_)
{
return "/setloginmessage <raw json message> OR /setloginmessage <text> OR /setloginmessage";
}
@Override
public void processCommand(ICommandSender sender, String[] args)
{
if (args.length == 0)
{
File file = new File(D3Core.getFolder(), "loginmessage.txt");
if (file.exists()) file.delete();
sender.addChatMessage(new ChatComponentTranslation("d3.core.cmd.setloginmessage.removed"));
}
else
{
String txt = func_82360_a(sender, args, 0);
try
{
FileUtils.writeStringToFile(new File(D3Core.getFolder(), "loginmessage.txt"), txt);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
sender.addChatMessage(new ChatComponentTranslation("d3.core.cmd.setloginmessage.success"));
try
{
sender.addChatMessage(IChatComponent.Serializer.func_150699_a(txt));
}
catch (JsonParseException jsonparseexception)
{
sender.addChatMessage(new ChatComponentText(txt));
}
}
}
}