MinecraftManagerPlugin/src/main/java/xyz/etztech/minecraftmanager/command/CommandTicket.java

85 lines
3.0 KiB
Java
Raw Normal View History

2018-09-12 15:55:10 +00:00
package xyz.etztech.minecraftmanager.command;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.core.web.ICallback;
2018-09-12 15:55:10 +00:00
import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.objects.MCMResponse;
2018-09-12 15:55:10 +00:00
import xyz.etztech.minecraftmanager.MinecraftManager;
import java.util.Map;
2018-09-12 15:55:10 +00:00
public class CommandTicket implements CommandExecutor {
MinecraftManager plugin;
public CommandTicket(MinecraftManager plugin) {
this.plugin = plugin;
}
private class TicketCallback implements ICallback {
private Player player;
TicketCallback(Player player) {
this.player = player;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
player.sendMessage(response.getMCMessage());
}
}
2018-09-12 15:55:10 +00:00
@Override
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "The console cannot submit tickets.");
return true;
}
Player player = (Player) sender;
if (sender.hasPermission("minecraftmanager.ticket")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "You cannot send a ticket with no message.");
return true;
}
Location location = player.getLocation();
String x = String.valueOf(location.getBlockX());
String y = String.valueOf(location.getBlockY());
String z = String.valueOf(location.getBlockZ());
World.Environment env = location.getWorld().getEnvironment();
String world = "";
if (World.Environment.NORMAL == env) {
world = "O";
} else if (World.Environment.NETHER == env) {
world = "N";
} else if (World.Environment.THE_END == env) {
world = "E";
}
String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/ticket/";
Map<String, String> data = MCMAPI.setup();
data.put("uuid", player.getUniqueId().toString());
data.put("message", StringUtils.join(args, " "));
data.put("x", x);
data.put("y", y);
data.put("z", z);
data.put("world", world);
CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new TicketCallback(player));
2018-09-12 15:55:10 +00:00
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission to submit a ticket.");
sender.sendMessage(ChatColor.RED + "If you were submitting a ticket about not being able to submit a ticket, that's called irony.");
2018-09-12 15:55:10 +00:00
}
return true;
}
}