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

94 lines
3.5 KiB
Java

package xyz.etztech.minecraftmanager.command;
import com.google.gson.JsonObject;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
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;
import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.MCMUtil;
import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.MinecraftManager;
import xyz.etztech.minecraftmanager.objects.MinecraftManagerThread;
import java.util.Map;
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.spigot().sendMessage(response.getMCJSON());
try {
JsonObject extra = (JsonObject) response.getExtra();
MinecraftManagerThread.ticket(player.getName(), extra.get("id").getAsString(), extra.get("link").getAsString());
} catch (Exception ex) {}
}
}
@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));
} 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.");
}
return true;
}
}