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());
|
||||
}
|
||||
|
||||
private void log(String str, Level lvl) {
|
||||
logger.log(lvl, str);
|
||||
}
|
||||
|
||||
private String getDate() {
|
||||
SimpleDateFormat format = new SimpleDateFormat(this.format);
|
||||
return format.format(new Date());
|
||||
}
|
||||
|
||||
private void log(String str, Level lvl) {
|
||||
logger.log(lvl, str);
|
||||
}
|
||||
|
||||
//Make the logs come out readable
|
||||
static class MyFormatter extends Formatter {
|
||||
AddonLogger addon;
|
||||
|
2
pom.xml
2
pom.xml
@ -312,7 +312,7 @@
|
||||
<dependency>
|
||||
<groupId>xyz.xenondevs</groupId>
|
||||
<artifactId>particle</artifactId>
|
||||
<version>1.8.3</version>
|
||||
<version>1.8.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Lombok Support (@Getter & @Setter)-->
|
||||
|
@ -42,6 +42,7 @@ public class Commands {
|
||||
//Command Event
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
BetterRTP.debug(sendi.getName() + " executed: /" + label + " " + String.join(" ", args));
|
||||
cmd.execute(sendi, label, args);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent_After(sendi, cmd));
|
||||
}
|
||||
|
@ -17,4 +17,8 @@ public interface RTPCommand {
|
||||
default boolean isDebugOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean enabled() {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
@ -103,4 +103,8 @@ public class CmdLocation implements RTPCommand, RTPCommandHelpable {
|
||||
public String getHelp() {
|
||||
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.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.helpers.HelperRTP_Info;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesHelp;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesUsage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.web.LogUploader;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CmdLogger implements RTPCommand {
|
||||
|
||||
@ -22,7 +28,35 @@ public class CmdLogger implements RTPCommand {
|
||||
return "logger";
|
||||
}
|
||||
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) {
|
||||
|
@ -100,7 +100,7 @@ public class RTPLoader {
|
||||
static void loadLocations(@NotNull HashMap<String, RTPWorld> worlds) {
|
||||
worlds.clear();
|
||||
FileOther.FILETYPE config = FileOther.FILETYPE.LOCATIONS;
|
||||
if (!config.getBoolean("Enabled"))
|
||||
if (!BetterRTP.getInstance().getSettings().isLocationEnabled())
|
||||
return;
|
||||
BetterRTP.debug("Loading Locations...");
|
||||
List<Map<?, ?>> map = config.getMapList("Locations");
|
||||
|
@ -1,30 +1,56 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.*;
|
||||
|
||||
public class RTPLogger {
|
||||
|
||||
static Handler fileHandler = null;
|
||||
private Logger LOGGER;
|
||||
@Getter private String format;
|
||||
@Getter private File file;
|
||||
private FileHandler handler;
|
||||
//private ConsoleHandler consoleHandler_rtp, consoleHandler_logger;
|
||||
|
||||
public void setup(BetterRTP plugin) {
|
||||
this.LOGGER = plugin.getLogger();
|
||||
if (plugin.getSettings().isDebug())
|
||||
LOGGER.setLevel(Level.ALL);
|
||||
else
|
||||
LOGGER.setLevel(Level.WARNING);
|
||||
this.format = plugin.getFiles().getType(FileOther.FILETYPE.CONFIG).getString("Settings.Logger.Format");
|
||||
boolean toConsole = plugin.getFiles().getType(FileOther.FILETYPE.CONFIG).getBoolean("Settings.Logger.LogToConsole");
|
||||
try {
|
||||
fileHandler = new FileHandler(plugin.getDataFolder().getAbsoluteFile() + File.separator + "data.log");
|
||||
SimpleFormatter simple = new SimpleFormatter();
|
||||
fileHandler.setFormatter(simple);
|
||||
LOGGER.addHandler(fileHandler);//adding Handler for file
|
||||
if (handler != null) {
|
||||
handler.close();
|
||||
}
|
||||
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) {
|
||||
// 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);
|
||||
|
||||
//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());
|
||||
if (worldLocation != null) {
|
||||
setup_info.setLocation(worldLocation);
|
||||
|
@ -16,6 +16,7 @@ public class Settings {
|
||||
//Dependencies
|
||||
private final SoftDepends depends = new SoftDepends();
|
||||
@Getter private boolean protocolLibSounds;
|
||||
@Getter private boolean locationEnabled;
|
||||
@Getter private boolean useLocationIfAvailable;
|
||||
@Getter private boolean locationNeedPermission;
|
||||
@Getter private boolean useLocationsInSameWorld;
|
||||
@ -50,6 +51,7 @@ public class Settings {
|
||||
permissionGroupEnabled = config.getBoolean("PermissionGroup.Enabled");
|
||||
queueEnabled = config.getBoolean("Settings.Queue.Enabled");
|
||||
protocolLibSounds = FileOther.FILETYPE.EFFECTS.getBoolean("Sounds.ProtocolLibSound");
|
||||
locationEnabled = FileOther.FILETYPE.LOCATIONS.getBoolean("Enabled");
|
||||
useLocationIfAvailable = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationIfAvailable");
|
||||
locationNeedPermission = FileOther.FILETYPE.LOCATIONS.getBoolean("RequirePermission");
|
||||
useLocationsInSameWorld = FileOther.FILETYPE.LOCATIONS.getBoolean("UseLocationsInSameWorld");
|
||||
|
@ -1,16 +1,14 @@
|
||||
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.YamlConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class LogUploader {
|
||||
@ -18,6 +16,7 @@ public class LogUploader {
|
||||
private static final String UPLOAD_URL = "https://logs.ronanplugins.com/documents";
|
||||
public static final String KEY_URL = "https://logs.ronanplugins.com/";
|
||||
|
||||
@Nullable
|
||||
public static String post(List<String> requestBody) {
|
||||
try {
|
||||
URL url = new URL(UPLOAD_URL);
|
||||
@ -49,33 +48,45 @@ public class LogUploader {
|
||||
}
|
||||
}
|
||||
|
||||
public static String sendConfigAsPostRequest(FileOther.FILETYPE file) throws IOException {
|
||||
FileConfiguration config = file.getConfig();
|
||||
@Nullable
|
||||
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
|
||||
String requestBody = config.saveToString();
|
||||
|
||||
// Create the connection to the server
|
||||
URL url = new URL(UPLOAD_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "text/yaml");
|
||||
connection.setDoOutput(true);
|
||||
try {
|
||||
URL url = new URL(UPLOAD_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "text/yaml");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
try (OutputStream outputStream = connection.getOutputStream()) {
|
||||
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
|
||||
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);
|
||||
try (OutputStream outputStream = connection.getOutputStream()) {
|
||||
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
|
||||
outputStream.write(input, 0, input.length);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,9 @@ Settings:
|
||||
Queue:
|
||||
Enabled: true #Allows betterrtp to automatically queue up safe rtp locations prior to players executing `/rtp`
|
||||
DisableUpdater: false
|
||||
Logger:
|
||||
LogToConsole: false
|
||||
Format: 'yyyy-MM-dd HH:mm:ss'
|
||||
|
||||
Default:
|
||||
UseWorldBorder: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user