2018-09-12 15:55:10 +00:00
|
|
|
package xyz.etztech.minecraftmanager.command;
|
|
|
|
|
2018-09-14 05:05:38 +00:00
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import net.md_5.bungee.api.chat.ClickEvent;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
2018-09-12 15:55:10 +00:00
|
|
|
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;
|
2018-09-12 16:03:59 +00:00
|
|
|
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;
|
2018-09-14 05:05:38 +00:00
|
|
|
import xyz.etztech.minecraftmanager.MCMUtil;
|
2018-09-12 16:03:59 +00:00
|
|
|
import xyz.etztech.minecraftmanager.objects.MCMResponse;
|
2018-09-12 15:55:10 +00:00
|
|
|
import xyz.etztech.minecraftmanager.MinecraftManager;
|
2018-09-15 21:19:38 +00:00
|
|
|
import xyz.etztech.minecraftmanager.objects.MinecraftManagerThread;
|
2018-09-12 15:55:10 +00:00
|
|
|
|
2018-09-12 16:03:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-12 16:03:59 +00:00
|
|
|
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);
|
2018-12-07 23:07:54 +00:00
|
|
|
player.spigot().sendMessage(response.getMCJSON());
|
2018-09-14 05:05:38 +00:00
|
|
|
try {
|
|
|
|
JsonObject extra = (JsonObject) response.getExtra();
|
2018-09-15 21:19:38 +00:00
|
|
|
MinecraftManagerThread.ticket(player.getName(), extra.get("id").getAsString(), extra.get("link").getAsString());
|
2018-09-14 05:05:38 +00:00
|
|
|
} catch (Exception ex) {}
|
2018-09-12 16:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
}
|
2018-09-12 16:03:59 +00:00
|
|
|
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.");
|
2018-09-12 16:03:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|