Backport changes from 1.18.2
This commit is contained in:
Telesphoreo 2022-03-03 17:24:15 -06:00
parent cd0da8d78e
commit c82586b02a
13 changed files with 104 additions and 13 deletions

View File

@ -46,7 +46,7 @@ dependencies {
}
group = "dev.plex"
version = "0.7-SNAPSHOT"
version = "0.7"
description = "Plex"
shadowJar {

View File

@ -20,6 +20,7 @@ import dev.plex.storage.SQLConnection;
import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.UpdateChecker;
import dev.plex.world.CustomWorld;
import java.util.UUID;
import lombok.Getter;
@ -52,6 +53,8 @@ public class Plex extends JavaPlugin
private AdminList adminList;
private UpdateChecker updateChecker;
private String system;
public static Plex get()
@ -91,6 +94,9 @@ public class Plex extends JavaPlugin
e.printStackTrace();
}
updateChecker = new UpdateChecker();
PlexLog.log("Update checking enabled");
// https://bstats.org/plugin/bukkit/Plex/14143
Metrics metrics = new Metrics(this, 14143);
PlexLog.log("Enabled Metrics");
@ -126,14 +132,12 @@ public class Plex extends JavaPlugin
punishmentManager = new PunishmentManager();
punishmentManager.mergeIndefiniteBans();
// banManager = new BanManager();
PlexLog.log("Punishment System initialized");
generateWorlds();
serviceManager = new ServiceManager();
PlexLog.log("Service Manager initialized");
serviceManager.startServices();
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");

View File

@ -32,6 +32,7 @@ public class SurvivalCMD extends PlexCommand
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
}
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
return null;
}
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))

View File

@ -68,6 +68,7 @@ public class Config extends YamlConfiguration
if (!externalYamlConfig.contains(string))
{
// If it doesn't contain the key, we set the key based off what was found inside the plugin jar
externalYamlConfig.setComments(string, internalYamlConfig.getComments(string));
externalYamlConfig.set(string, internalYamlConfig.get(string));
PlexLog.log("Setting key: " + string + " in " + this.name + " to the default value(s) since it does not exist!");
added = true;
@ -77,6 +78,7 @@ public class Config extends YamlConfiguration
{
externalYamlConfig.save(file);
PlexLog.log("Saving new file...");
added = false;
}
super.load(file);
}

View File

@ -58,11 +58,11 @@ public class PunishmentManager extends PlexBase
this.bannedIPs.addAll(Plex.get().indefBans.getStringList("ips"));
this.bannedUsernames.addAll(Plex.get().indefBans.getStringList("usernames"));
PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) into the indefinite banned list", this.bannedUUIDs.size(), this.bannedIPs.size(), this.bannedUsernames.size());
PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) as indefinitely banned", this.bannedUUIDs.size(), this.bannedIPs.size(), this.bannedUsernames.size());
if (Plex.get().getRedisConnection().isEnabled())
{
PlexLog.log("Resetting redis indefinite bans lists and asynchronously uploading from configuration");
PlexLog.log("Asynchronously uploading all indefinite bans to Redis");
Plex.get().getRedisConnection().runAsync(jedis -> {
jedis.set("indefbanned-uuids", new Gson().toJson(this.bannedUUIDs));
jedis.set("indefbanned-ips", new Gson().toJson(this.bannedIPs));

View File

@ -2,5 +2,5 @@ package dev.plex.punishment;
public enum PunishmentType
{
MUTE, FREEZE, BAN, KICK;
MUTE, FREEZE, BAN, KICK
}

View File

@ -1,6 +1,8 @@
package dev.plex.services;
public abstract class AbstractService implements IService
import dev.plex.PlexBase;
public abstract class AbstractService extends PlexBase implements IService
{
private boolean asynchronous;
private boolean repeating;

View File

@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.services.impl.BanService;
import dev.plex.services.impl.GameRuleService;
import dev.plex.services.impl.UpdateCheckerService;
import java.util.List;
import org.bukkit.Bukkit;
@ -15,6 +16,7 @@ public class ServiceManager
{
registerService(new BanService());
registerService(new GameRuleService());
registerService(new UpdateCheckerService());
}
public void startServices()

View File

@ -0,0 +1,32 @@
package dev.plex.services.impl;
import dev.plex.services.AbstractService;
public class UpdateCheckerService extends AbstractService
{
public UpdateCheckerService()
{
super(true, true);
}
private boolean newVersion = false;
@Override
public void run()
{
if (!newVersion)
{
if (plugin.getUpdateChecker().check())
{
newVersion = true;
}
}
}
@Override
public int repeatInSeconds()
{
// Every 30 minutes
return 1800;
}
}

View File

@ -6,14 +6,13 @@ import dev.morphia.Datastore;
import dev.morphia.Morphia;
import dev.morphia.mapping.MapperOptions;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;
public class MongoConnection
public class MongoConnection extends PlexBase
{
// USE MORPHIA API FOR MONGO <3
private final Plex plugin = Plex.get();
public Datastore getDatastore()
{
if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("mongodb"))

View File

@ -0,0 +1,47 @@
package dev.plex.util;
import dev.plex.PlexBase;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.bukkit.ChatColor;
public class UpdateChecker extends PlexBase
{
private final String currentVersion = plugin.getDescription().getVersion();
public boolean check()
{
try
{
String versionLink = "https://plex.us.org/updater/check/";
URL url = new URL(versionLink);
URLConnection con = url.openConnection();
InputStreamReader isr = new InputStreamReader(con.getInputStream());
BufferedReader reader = new BufferedReader(isr);
if (!reader.ready())
{
return false;
}
String newVersion = reader.readLine();
reader.close();
if (!newVersion.equals(currentVersion))
{
PlexLog.log(ChatColor.RED + "There is a new version of Plex available: " + newVersion);
return true;
}
else
{
return false;
}
}
catch (IOException e)
{
PlexLog.error("There was an error checking for updates!");
return false;
}
}
}

View File

@ -3,6 +3,7 @@ package dev.plex.world;
import dev.plex.Plex;
import java.io.File;
import java.util.Objects;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
@ -45,8 +46,9 @@ public class CustomWorld extends WorldCreator
if (state instanceof Sign)
{
Sign sign = (Sign)state;
sign.setLine(1, Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name")));
sign.setLine(2, "- 0, 0 -");
sign.line(1, Component.text(
Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name"))));
sign.line(2, Component.text("- 0, 0 -"));
sign.update();
}
}

View File

@ -119,7 +119,7 @@ teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been"
enabled: "enabled."
disabled: "disabled."
adminChatFormat: '&8[&9AdminChat&8] &4<v> &7» &6<v>'
adminChatFormat: '<dark_gray>[<blue>AdminChat<dark_gray>] <dark_red><v> <gray>» <gold><v>'
maximumPrefixLength: "<red>The maximum length for a tag may only be <v>."
prefixCleared: "<aqua>Your prefix has been cleared."
otherPrefixCleared: "<aqua>You have cleared <v>'s prefix."