mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 00:55:45 +00:00
particle update + logger update
This commit is contained in:
parent
2b882d93c7
commit
c96691325b
@ -92,15 +92,15 @@ public class AddonLogger implements Addon, Listener {
|
|||||||
database.log(e.getPlayer(), e.getOldLocation(), e.getLocation());
|
database.log(e.getPlayer(), e.getOldLocation(), e.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log(String str, Level lvl) {
|
||||||
|
logger.log(lvl, str);
|
||||||
|
}
|
||||||
|
|
||||||
private String getDate() {
|
private String getDate() {
|
||||||
SimpleDateFormat format = new SimpleDateFormat(this.format);
|
SimpleDateFormat format = new SimpleDateFormat(this.format);
|
||||||
return format.format(new Date());
|
return format.format(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(String str, Level lvl) {
|
|
||||||
logger.log(lvl, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Make the logs come out readable
|
//Make the logs come out readable
|
||||||
static class MyFormatter extends Formatter {
|
static class MyFormatter extends Formatter {
|
||||||
AddonLogger addon;
|
AddonLogger addon;
|
||||||
|
2
pom.xml
2
pom.xml
@ -312,7 +312,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.xenondevs</groupId>
|
<groupId>xyz.xenondevs</groupId>
|
||||||
<artifactId>particle</artifactId>
|
<artifactId>particle</artifactId>
|
||||||
<version>1.8.3</version>
|
<version>1.8.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Lombok Support (@Getter & @Setter)-->
|
<!-- Lombok Support (@Getter & @Setter)-->
|
||||||
|
@ -42,6 +42,7 @@ public class Commands {
|
|||||||
//Command Event
|
//Command Event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
|
BetterRTP.debug(sendi.getName() + " executed: /" + label + " " + String.join(" ", args));
|
||||||
cmd.execute(sendi, label, args);
|
cmd.execute(sendi, label, args);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent_After(sendi, cmd));
|
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent_After(sendi, cmd));
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,8 @@ public interface RTPCommand {
|
|||||||
default boolean isDebugOnly() {
|
default boolean isDebugOnly() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean enabled() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -103,4 +103,8 @@ public class CmdLocation implements RTPCommand, RTPCommandHelpable {
|
|||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return MessagesHelp.LOCATION.get();
|
return MessagesHelp.LOCATION.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean enabled() {
|
||||||
|
return BetterRTP.getInstance().getSettings().isLocationEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,25 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
|
|||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandType;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
|
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP_Info;
|
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
|
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesHelp;
|
import me.SuperRonanCraft.BetterRTP.references.web.LogUploader;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesUsage;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import org.bukkit.Bukkit;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import org.bukkit.World;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class CmdLogger implements RTPCommand {
|
public class CmdLogger implements RTPCommand {
|
||||||
|
|
||||||
@ -22,7 +28,35 @@ public class CmdLogger implements RTPCommand {
|
|||||||
return "logger";
|
return "logger";
|
||||||
}
|
}
|
||||||
public void execute(CommandSender sendi, String label, String[] args) {
|
public void execute(CommandSender sendi, String label, String[] args) {
|
||||||
|
get(sendi, label, args, args.length >= 2 && args[args.length - 1].equalsIgnoreCase("_UPLOAD_"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void get(CommandSender sendi, String label, String[] args, boolean upload) {
|
||||||
|
String cmd = "/" + label + " " + String.join(" ", args);
|
||||||
|
if (!upload) {
|
||||||
|
if (sendi instanceof Player) {
|
||||||
|
TextComponent component = new TextComponent(Message.color("&7- &7Click to upload log to &flogs.ronanplugins.com"));
|
||||||
|
component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cmd + " _UPLOAD_"));
|
||||||
|
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.color("&6Suggested command&f: &7" + "/betterrtp " + String.join(" ", args) + " _UPLOAD_")).create()));
|
||||||
|
((Player) sendi).spigot().sendMessage(component);
|
||||||
|
} else {
|
||||||
|
sendi.sendMessage("Execute `" + cmd + " _UPLOAD_`" + " to upload log to https://logs.ronanplugins.com");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
String key = LogUploader.post(BetterRTP.getInstance().getRtpLogger().getFile());
|
||||||
|
if (key == null) {
|
||||||
|
Message.sms(sendi, new ArrayList<>(Collections.singletonList("&cAn error occured attempting to upload log!")), null);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
JSONObject json = (JSONObject) new JSONParser().parse(key);
|
||||||
|
Message.sms(sendi, Arrays.asList(" ", Message.getPrefix(Message_RTP.msg) + "&aLog uploaded! &fView&7: &6https://logs.ronanplugins.com/" + json.get("key")), null);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> tabComplete(CommandSender sendi, String[] args) {
|
public List<String> tabComplete(CommandSender sendi, String[] args) {
|
||||||
|
@ -100,7 +100,7 @@ public class RTPLoader {
|
|||||||
static void loadLocations(@NotNull HashMap<String, RTPWorld> worlds) {
|
static void loadLocations(@NotNull HashMap<String, RTPWorld> worlds) {
|
||||||
worlds.clear();
|
worlds.clear();
|
||||||
FileOther.FILETYPE config = FileOther.FILETYPE.LOCATIONS;
|
FileOther.FILETYPE config = FileOther.FILETYPE.LOCATIONS;
|
||||||
if (!config.getBoolean("Enabled"))
|
if (!BetterRTP.getInstance().getSettings().isLocationEnabled())
|
||||||
return;
|
return;
|
||||||
BetterRTP.debug("Loading Locations...");
|
BetterRTP.debug("Loading Locations...");
|
||||||
List<Map<?, ?>> map = config.getMapList("Locations");
|
List<Map<?, ?>> map = config.getMapList("Locations");
|
||||||
|
@ -1,30 +1,56 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references;
|
package me.SuperRonanCraft.BetterRTP.references;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
public class RTPLogger {
|
public class RTPLogger {
|
||||||
|
|
||||||
static Handler fileHandler = null;
|
@Getter private String format;
|
||||||
private Logger LOGGER;
|
@Getter private File file;
|
||||||
|
private FileHandler handler;
|
||||||
|
//private ConsoleHandler consoleHandler_rtp, consoleHandler_logger;
|
||||||
|
|
||||||
public void setup(BetterRTP plugin) {
|
public void setup(BetterRTP plugin) {
|
||||||
this.LOGGER = plugin.getLogger();
|
this.format = plugin.getFiles().getType(FileOther.FILETYPE.CONFIG).getString("Settings.Logger.Format");
|
||||||
if (plugin.getSettings().isDebug())
|
boolean toConsole = plugin.getFiles().getType(FileOther.FILETYPE.CONFIG).getBoolean("Settings.Logger.LogToConsole");
|
||||||
LOGGER.setLevel(Level.ALL);
|
|
||||||
else
|
|
||||||
LOGGER.setLevel(Level.WARNING);
|
|
||||||
try {
|
try {
|
||||||
fileHandler = new FileHandler(plugin.getDataFolder().getAbsoluteFile() + File.separator + "data.log");
|
if (handler != null) {
|
||||||
SimpleFormatter simple = new SimpleFormatter();
|
handler.close();
|
||||||
fileHandler.setFormatter(simple);
|
}
|
||||||
LOGGER.addHandler(fileHandler);//adding Handler for file
|
this.file = new File(plugin.getDataFolder() + File.separator + "log.txt");
|
||||||
|
Files.deleteIfExists(file.toPath());
|
||||||
|
this.handler = new FileHandler(file.getPath(), true);
|
||||||
|
handler.setFormatter(new MyFormatter());
|
||||||
|
Logger logger = plugin.getLogger();
|
||||||
|
logger.setUseParentHandlers(toConsole); //Disable logging to console
|
||||||
|
logger.addHandler(handler);
|
||||||
|
//Log copying
|
||||||
|
//consoleHandler_logger = new MyConsole(this.logger, plugin.getName());
|
||||||
|
//plugin.getLogger().addHandler(consoleHandler_logger);
|
||||||
|
//consoleHandler_rtp = new MyConsole(this.logger, plugin.getName());
|
||||||
|
//plugin.getLogger().addHandler(consoleHandler_rtp);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getDate() {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat(BetterRTP.getInstance().getRtpLogger().getFormat());
|
||||||
|
return format.format(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyFormatter extends Formatter {
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record) {
|
||||||
|
return getDate() + " [" + record.getLevel().getName() + "]: " + record.getMessage() + '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,9 @@ public class HelperRTP {
|
|||||||
WorldPlayer pWorld = new WorldPlayer(setup_info);
|
WorldPlayer pWorld = new WorldPlayer(setup_info);
|
||||||
|
|
||||||
//Random Location
|
//Random Location
|
||||||
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
if (setup_info.getLocation() == null
|
||||||
|
&& BetterRTP.getInstance().getSettings().isLocationEnabled()
|
||||||
|
&& BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
||||||
WorldLocation worldLocation = HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld());
|
WorldLocation worldLocation = HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld());
|
||||||
if (worldLocation != null) {
|
if (worldLocation != null) {
|
||||||
setup_info.setLocation(worldLocation);
|
setup_info.setLocation(worldLocation);
|
||||||
|
@ -16,6 +16,7 @@ public class Settings {
|
|||||||
//Dependencies
|
//Dependencies
|
||||||
private final SoftDepends depends = new SoftDepends();
|
private final SoftDepends depends = new SoftDepends();
|
||||||
@Getter private boolean protocolLibSounds;
|
@Getter private boolean protocolLibSounds;
|
||||||
|
@Getter private boolean locationEnabled;
|
||||||
@Getter private boolean useLocationIfAvailable;
|
@Getter private boolean useLocationIfAvailable;
|
||||||
@Getter private boolean locationNeedPermission;
|
@Getter private boolean locationNeedPermission;
|
||||||
@Getter private boolean useLocationsInSameWorld;
|
@Getter private boolean useLocationsInSameWorld;
|
||||||
@ -50,6 +51,7 @@ public class Settings {
|
|||||||
permissionGroupEnabled = config.getBoolean("PermissionGroup.Enabled");
|
permissionGroupEnabled = config.getBoolean("PermissionGroup.Enabled");
|
||||||
queueEnabled = config.getBoolean("Settings.Queue.Enabled");
|
queueEnabled = config.getBoolean("Settings.Queue.Enabled");
|
||||||
protocolLibSounds = FileOther.FILETYPE.EFFECTS.getBoolean("Sounds.ProtocolLibSound");
|
protocolLibSounds = FileOther.FILETYPE.EFFECTS.getBoolean("Sounds.ProtocolLibSound");
|
||||||
|
locationEnabled = FileOther.FILETYPE.LOCATIONS.getBoolean("Enabled");
|
||||||
useLocationIfAvailable = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationIfAvailable");
|
useLocationIfAvailable = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationIfAvailable");
|
||||||
locationNeedPermission = FileOther.FILETYPE.LOCATIONS.getBoolean("RequirePermission");
|
locationNeedPermission = FileOther.FILETYPE.LOCATIONS.getBoolean("RequirePermission");
|
||||||
useLocationsInSameWorld = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationsInSameWorld");
|
useLocationsInSameWorld = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationsInSameWorld");
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references.web;
|
package me.SuperRonanCraft.BetterRTP.references.web;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LogUploader {
|
public class LogUploader {
|
||||||
@ -18,6 +16,7 @@ public class LogUploader {
|
|||||||
private static final String UPLOAD_URL = "https://logs.ronanplugins.com/documents";
|
private static final String UPLOAD_URL = "https://logs.ronanplugins.com/documents";
|
||||||
public static final String KEY_URL = "https://logs.ronanplugins.com/";
|
public static final String KEY_URL = "https://logs.ronanplugins.com/";
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static String post(List<String> requestBody) {
|
public static String post(List<String> requestBody) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(UPLOAD_URL);
|
URL url = new URL(UPLOAD_URL);
|
||||||
@ -49,33 +48,45 @@ public class LogUploader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sendConfigAsPostRequest(FileOther.FILETYPE file) throws IOException {
|
@Nullable
|
||||||
FileConfiguration config = file.getConfig();
|
public static String post(File file) {
|
||||||
|
FileConfiguration config = new YamlConfiguration();
|
||||||
|
try {
|
||||||
|
config.load(file);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the config file to a YAML string
|
// Convert the config file to a YAML string
|
||||||
String requestBody = config.saveToString();
|
String requestBody = config.saveToString();
|
||||||
|
|
||||||
// Create the connection to the server
|
// Create the connection to the server
|
||||||
URL url = new URL(UPLOAD_URL);
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
URL url = new URL(UPLOAD_URL);
|
||||||
connection.setRequestMethod("POST");
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestProperty("Content-Type", "text/yaml");
|
connection.setRequestMethod("POST");
|
||||||
connection.setDoOutput(true);
|
connection.setRequestProperty("Content-Type", "text/yaml");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
try (OutputStream outputStream = connection.getOutputStream()) {
|
try (OutputStream outputStream = connection.getOutputStream()) {
|
||||||
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
|
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
|
||||||
outputStream.write(input, 0, input.length);
|
outputStream.write(input, 0, input.length);
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder response = new StringBuilder();
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
response.append(line);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response.toString();
|
StringBuilder response = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
//getLogger().log(Level.INFO, "Response: " + response.toString());
|
//getLogger().log(Level.INFO, "Response: " + response.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ Settings:
|
|||||||
Queue:
|
Queue:
|
||||||
Enabled: true #Allows betterrtp to automatically queue up safe rtp locations prior to players executing `/rtp`
|
Enabled: true #Allows betterrtp to automatically queue up safe rtp locations prior to players executing `/rtp`
|
||||||
DisableUpdater: false
|
DisableUpdater: false
|
||||||
|
Logger:
|
||||||
|
LogToConsole: false
|
||||||
|
Format: 'yyyy-MM-dd HH:mm:ss'
|
||||||
|
|
||||||
Default:
|
Default:
|
||||||
UseWorldBorder: false
|
UseWorldBorder: false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user