mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
- Add the ability to customize game rules per world in config
- Add gamerules argument to /debug
This commit is contained in:
parent
1b856db297
commit
1333f06dad
46
build.gradle
46
build.gradle
@ -1,22 +1,22 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id "java"
|
||||||
id 'maven-publish'
|
id "maven-publish"
|
||||||
id 'net.minecrell.plugin-yml.bukkit' version '0.5.1'
|
id "net.minecrell.plugin-yml.bukkit" version "0.5.1"
|
||||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven {
|
maven {
|
||||||
url = uri('https://papermc.io/repo/repository/maven-public/')
|
url = uri("https://papermc.io/repo/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = uri('https://repository.apache.org/content/repositories/snapshots/')
|
url = uri("https://repository.apache.org/content/repositories/snapshots/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = uri('https://repo.maven.apache.org/maven2/')
|
url = uri("https://repo.maven.apache.org/maven2/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
@ -27,30 +27,32 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
library 'org.projectlombok:lombok:1.18.22'
|
library "org.projectlombok:lombok:1.18.22"
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
annotationProcessor "org.projectlombok:lombok:1.18.22"
|
||||||
library 'org.json:json:20211205'
|
|
||||||
library 'commons-io:commons-io:2.11.0'
|
library "org.json:json:20211205"
|
||||||
library 'dev.morphia.morphia:morphia-core:2.2.3'
|
library "commons-io:commons-io:2.11.0"
|
||||||
library 'redis.clients:jedis:4.1.1'
|
library "dev.morphia.morphia:morphia-core:2.2.3"
|
||||||
library 'org.mariadb.jdbc:mariadb-java-client:3.0.3'
|
library "redis.clients:jedis:4.1.1"
|
||||||
library 'org.apache.httpcomponents:httpclient:4.5.13'
|
library "org.mariadb.jdbc:mariadb-java-client:3.0.3"
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
|
library "org.apache.httpcomponents:httpclient:4.5.13"
|
||||||
implementation 'org.bstats:bstats-base:3.0.0'
|
library "org.apache.commons:commons-lang3:3.12.0"
|
||||||
implementation 'org.bstats:bstats-bukkit:3.0.0'
|
compileOnly "io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT"
|
||||||
|
implementation "org.bstats:bstats-base:3.0.0"
|
||||||
|
implementation "org.bstats:bstats-bukkit:3.0.0"
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") {
|
implementation("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") {
|
||||||
exclude group: "net.kyori", module: "adventure-api"
|
exclude group: "net.kyori", module: "adventure-api"
|
||||||
exclude group: "org.jetbrains", module: "annotations"
|
exclude group: "org.jetbrains", module: "annotations"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'dev.plex'
|
group = "dev.plex"
|
||||||
version = '0.6-SNAPSHOT'
|
version = "0.6-SNAPSHOT"
|
||||||
description = 'Plex'
|
description = "Plex"
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveClassifier.set("")
|
archiveClassifier.set("")
|
||||||
relocate 'org.bstats', 'dev.plex'
|
relocate "org.bstats", "dev.plex"
|
||||||
}
|
}
|
||||||
|
|
||||||
bukkit {
|
bukkit {
|
||||||
@ -100,7 +102,7 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -508,6 +508,17 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string to a mini message kyori component
|
||||||
|
*
|
||||||
|
* @param s The string to convert
|
||||||
|
* @return A Kyori component
|
||||||
|
*/
|
||||||
|
protected Component mmString(String s)
|
||||||
|
{
|
||||||
|
return MiniMessage.miniMessage().parse(s);
|
||||||
|
}
|
||||||
|
|
||||||
public Rank getLevel()
|
public Rank getLevel()
|
||||||
{
|
{
|
||||||
return level;
|
return level;
|
||||||
|
@ -5,16 +5,20 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandParameters(name = "debug", description = "Debug command", usage = "/<command> redis-reset [player]")
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandParameters(name = "debug", description = "Debug command", usage = "/<command> <redis-reset | gamerules> [player]")
|
||||||
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
||||||
public class DebugCMD extends PlexCommand
|
public class DebugCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -35,6 +39,15 @@ public class DebugCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return componentFromString("Couldn't find player in Redis punishments.");
|
return componentFromString("Couldn't find player in Redis punishments.");
|
||||||
}
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("gamerules"))
|
||||||
|
{
|
||||||
|
for (World world : Bukkit.getWorlds())
|
||||||
|
{
|
||||||
|
PlexUtils.commitGameRules(world);
|
||||||
|
PlexLog.debug("Set gamerules for world: " + world.getName());
|
||||||
|
}
|
||||||
|
return mmString("<aqua>Re-applied game all the game rules!");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
package dev.plex.services.impl;
|
package dev.plex.services.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
import dev.plex.services.AbstractService;
|
import dev.plex.services.AbstractService;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class GameRuleService extends AbstractService
|
public class GameRuleService extends AbstractService
|
||||||
{
|
{
|
||||||
public GameRuleService()
|
public GameRuleService()
|
||||||
@ -18,28 +25,12 @@ public class GameRuleService extends AbstractService
|
|||||||
{
|
{
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
{
|
{
|
||||||
commitGameRules(world);
|
PlexUtils.commitGameRules(world);
|
||||||
PlexLog.debug("Set gamerules for world: " + world.getName());
|
PlexLog.debug("Set gamerules for world: " + world.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commitGameRules(World world)
|
|
||||||
{
|
|
||||||
world.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
|
||||||
world.setGameRule(GameRule.DO_FIRE_TICK, false);
|
|
||||||
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
|
||||||
world.setGameRule(GameRule.DO_MOB_LOOT, false);
|
|
||||||
world.setGameRule(GameRule.MOB_GRIEFING, false);
|
|
||||||
world.setGameRule(GameRule.DO_TILE_DROPS, false);
|
|
||||||
world.setGameRule(GameRule.COMMAND_BLOCK_OUTPUT, false);
|
|
||||||
world.setGameRule(GameRule.NATURAL_REGENERATION, true);
|
|
||||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
|
||||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
|
||||||
world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false);
|
|
||||||
world.setGameRule(GameRule.SHOW_DEATH_MESSAGES, false);
|
|
||||||
world.setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false);
|
|
||||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int repeatInSeconds()
|
public int repeatInSeconds()
|
||||||
|
@ -4,29 +4,11 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginCommandYamlParser;
|
import org.bukkit.command.PluginCommandYamlParser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -35,6 +17,16 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlexUtils extends PlexBase
|
public class PlexUtils extends PlexBase
|
||||||
{
|
{
|
||||||
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
|
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
|
||||||
@ -68,20 +60,17 @@ public class PlexUtils extends PlexBase
|
|||||||
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled MySQL!");
|
PlexLog.log("Successfully enabled MySQL!");
|
||||||
}
|
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||||
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled SQLite!");
|
PlexLog.log("Successfully enabled SQLite!");
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Plex.get().getSqlConnection().getCon().close();
|
Plex.get().getSqlConnection().getCon().close();
|
||||||
}
|
} catch (SQLException ignored)
|
||||||
catch (SQLException ignored)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
} else if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||||
else if (Plex.get().getMongoConnection().getDatastore() != null)
|
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled MongoDB!");
|
PlexLog.log("Successfully enabled MongoDB!");
|
||||||
}
|
}
|
||||||
@ -146,7 +135,7 @@ public class PlexUtils extends PlexBase
|
|||||||
|
|
||||||
public static String messageString(String entry, Object... objects)
|
public static String messageString(String entry, Object... objects)
|
||||||
{
|
{
|
||||||
String f = plugin.messages.getString(entry);
|
String f = plugin.messages.getString(entry);
|
||||||
if (f == null)
|
if (f == null)
|
||||||
{
|
{
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
@ -164,12 +153,10 @@ public class PlexUtils extends PlexBase
|
|||||||
if (config.getString(path) == null)
|
if (config.getString(path) == null)
|
||||||
{
|
{
|
||||||
color = def;
|
color = def;
|
||||||
}
|
} else if (ChatColor.getByChar(config.getString(path)) == null)
|
||||||
else if (ChatColor.getByChar(config.getString(path)) == null)
|
|
||||||
{
|
{
|
||||||
color = def;
|
color = def;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
color = ChatColor.getByChar(config.getString(path));
|
color = ChatColor.getByChar(config.getString(path));
|
||||||
}
|
}
|
||||||
@ -196,6 +183,39 @@ public class PlexUtils extends PlexBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void commitGameRules(World world)
|
||||||
|
{
|
||||||
|
for (String s : Plex.get().config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||||
|
{
|
||||||
|
String gameRule = s.split(";")[0];
|
||||||
|
T value = (T) s.split(";")[1];
|
||||||
|
GameRule<T> rule = (GameRule<T>) GameRule.getByName(gameRule);
|
||||||
|
if (rule != null && check(value).getClass().equals(rule.getType()))
|
||||||
|
{
|
||||||
|
world.setGameRule(rule, value);
|
||||||
|
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Object check(T value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false"))
|
||||||
|
{
|
||||||
|
return Boolean.parseBoolean(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NumberUtils.isNumber(value.toString()))
|
||||||
|
{
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> getPlayerNameList()
|
public static List<String> getPlayerNameList()
|
||||||
{
|
{
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
@ -216,7 +236,7 @@ public class PlexUtils extends PlexBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
@ -228,8 +248,7 @@ public class PlexUtils extends PlexBase
|
|||||||
in.close();
|
in.close();
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
return new JSONParser().parse(content.toString());
|
return new JSONParser().parse(content.toString());
|
||||||
}
|
} catch (IOException | ParseException ex)
|
||||||
catch (IOException | ParseException ex)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -238,13 +257,13 @@ public class PlexUtils extends PlexBase
|
|||||||
public static UUID getFromName(String name)
|
public static UUID getFromName(String name)
|
||||||
{
|
{
|
||||||
JSONObject profile;
|
JSONObject profile;
|
||||||
profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
profile = (JSONObject) simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
{
|
{
|
||||||
PlexLog.error("Profile from Ashcon API returned null!");
|
PlexLog.error("Profile from Ashcon API returned null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String uuidString = (String)profile.get("uuid");
|
String uuidString = (String) profile.get("uuid");
|
||||||
return UUID.fromString(uuidString);
|
return UUID.fromString(uuidString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@ worlds:
|
|||||||
name: "Flatlands"
|
name: "Flatlands"
|
||||||
permission: "plex.world.flatlands"
|
permission: "plex.world.flatlands"
|
||||||
noEdit: "&cYou can't edit this world!"
|
noEdit: "&cYou can't edit this world!"
|
||||||
|
gameRules:
|
||||||
|
- "doWeatherCycle;false"
|
||||||
|
- "doDaylightCycle;false"
|
||||||
parameters:
|
parameters:
|
||||||
grass_block: 1
|
grass_block: 1
|
||||||
dirt: 32
|
dirt: 32
|
||||||
|
Loading…
Reference in New Issue
Block a user