Skip to content

Commit c4e29ff

Browse files
committed
Update for 1.20.3
- Added verbose entry to the Player configuration files. Player configuration files will need to be regenerated. Please make sure to make backups of all configurations before regenerating configuration files. - Fixed a bug with the hide feature; now, any entity within a 25 block radius will automatically lose target of the player when their luck activates while sneaking. - Removed the vein-mining feature as it is unstable and non-functional. A fix and/or replacement will be implemented in a future update. - Updated supported version to 1.20.3 - Adjusted Logging methods.
1 parent 32a9435 commit c4e29ff

30 files changed

+609
-269
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'io.github.simplex'
6-
version = '1.2.1'
6+
version = '1.3.0'
77

88
repositories {
99
mavenCentral()
@@ -12,7 +12,7 @@ repositories {
1212
}
1313

1414
dependencies {
15-
compileOnly("io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT")
15+
compileOnly("io.papermc.paper:paper-api:1.20.3-R0.1-SNAPSHOT")
1616
}
1717

1818
def targetJavaVersion = 17
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/io/github/simplex/api/LuckContainer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package io.github.simplex.api;
22

3+
import java.io.Serializable;
34
import org.bukkit.entity.Player;
45

5-
import java.io.Serializable;
6+
public interface LuckContainer extends Serializable
7+
{
8+
9+
boolean isVerbose();
610

7-
public interface LuckContainer extends Serializable {
11+
void setVerbose(boolean verbose);
812

913
boolean isMatch(double number);
1014

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package io.github.simplex.lib;
22

3-
import net.kyori.adventure.text.Component;
3+
import net.kyori.adventure.text.ComponentLike;
44

5-
public enum Messages {
5+
public enum Messages
6+
{
67

78
NOT_FROM_CONSOLE(MiniComponent.err("This command may only be used in game.")),
89
NO_PERMISSION(MiniComponent.err("You do not have permission to use this command.")),
910
NO_PLAYER(MiniComponent.warn("That player cannot be found.")),
1011
OUT_OF_BOUNDS(MiniComponent.err("Number must be between -1024.0 and 1024.0"));
1112

12-
private final Component message;
13+
private final ComponentLike message;
1314

14-
Messages(Component message) {
15+
Messages(ComponentLike message)
16+
{
1517
this.message = message;
1618
}
1719

18-
public Component get() {
20+
public ComponentLike get()
21+
{
1922
return message;
2023
}
2124
}

src/main/java/io/github/simplex/lib/MiniComponent.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.github.simplex.lib;
22

33
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.ComponentLike;
45
import net.kyori.adventure.text.format.TextColor;
56
import net.kyori.adventure.text.format.TextDecoration;
67
import org.bukkit.ChatColor;
78
import org.jetbrains.annotations.Contract;
9+
import org.jetbrains.annotations.Nullable;
810

911
public class MiniComponent {
1012
private final String content;
@@ -21,17 +23,17 @@ public static MiniComponent of(String content) {
2123
}
2224

2325
@Contract("_ -> new")
24-
public static Component info(String content) {
26+
public static ComponentLike info(String content) {
2527
return new MiniComponent(content).color(ChatColor.GREEN).send();
2628
}
2729

2830
@Contract("_ -> new")
29-
public static Component warn(String content) {
31+
public static ComponentLike warn(String content) {
3032
return new MiniComponent(content).color(ChatColor.YELLOW).decorate(TextDecoration.ITALIC).send();
3133
}
3234

3335
@Contract("_ -> new")
34-
public static Component err(String content) {
36+
public static ComponentLike err(String content) {
3537
return new MiniComponent(content).color(ChatColor.RED).decorate(TextDecoration.BOLD).send();
3638
}
3739

@@ -45,7 +47,7 @@ public MiniComponent color(ChatColor color) {
4547
return this;
4648
}
4749

48-
public Component send() {
50+
public @Nullable Component send() {
4951
if (color == null) {
5052
if (decoration == null) return Component.empty().content(content);
5153

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package io.github.simplex.luck;
22

33
import io.github.simplex.luck.listener.AbstractListener;
4+
import io.github.simplex.luck.util.Logs;
45
import io.github.simplex.luck.util.SneakyWorker;
5-
import org.bukkit.configuration.file.YamlConfiguration;
6-
import org.jetbrains.annotations.NotNull;
7-
86
import java.io.File;
97
import java.util.HashMap;
108
import java.util.Map;
9+
import org.bukkit.configuration.file.YamlConfiguration;
10+
import org.jetbrains.annotations.NotNull;
1111

1212
@SuppressWarnings("ResultOfMethodCallIgnored")
13-
public class Config extends YamlConfiguration {
14-
private final Map<String, Object> configEntries = new HashMap<>() {{
13+
public class Config extends YamlConfiguration
14+
{
15+
private final Map<String, Object> configEntries = new HashMap<>()
16+
{{
1517
put("high_rarity_chance", 512.0);
1618
put("medium_rarity_chance", 128.0);
1719
put("low_rarity_chance", 64.0);
@@ -32,67 +34,83 @@ public class Config extends YamlConfiguration {
3234
}};
3335
private File configFile;
3436

35-
public Config(FeelingLucky plugin) {
37+
public Config(FeelingLucky plugin)
38+
{
3639
File dataFolder = plugin.getDataFolder();
37-
if (dataFolder.mkdirs()) {
40+
if (dataFolder.mkdirs())
41+
{
3842
plugin.getLogger().info("Created new data folder. Writing new configuration file...");
3943
plugin.saveResource("config.yml", true);
4044
}
4145

4246
File configFile = new File(dataFolder, "config.yml");
43-
if (!configFile.exists()) {
47+
if (!configFile.exists())
48+
{
4449
plugin.getLogger().info("No configuration file exists. Creating a new one...");
4550
plugin.saveResource("config.yml", true);
4651
}
4752

4853
this.configFile = configFile;
4954

50-
if (validateIntegrity(this.configFile)) {
55+
if (validateIntegrity(this.configFile))
56+
{
5157
load();
52-
} else {
58+
}
59+
else
60+
{
5361
configEntries.forEach(super::set);
54-
plugin.getLogger().warning("Your configuration file is missing keys. " +
55-
"\nPlease use /rgc in the console to regenerate the config file. " +
56-
"\nAlternatively, delete the config.yml and restart your server. " +
57-
"\nIt is safe to ignore this, as default values will be used." +
58-
"\nHowever, it is highly recommended to regenerate the configuration.");
62+
Logs.warn("Your configuration file is missing keys. " +
63+
"\nPlease use /rgc in the console to regenerate the config file. " +
64+
"\nAlternatively, delete the config.yml and restart your server. " +
65+
"\nIt is safe to ignore this, as default values will be used." +
66+
"\nHowever, it is highly recommended to regenerate the configuration.");
5967
}
6068
}
6169

62-
public void save() {
70+
public void save()
71+
{
6372
SneakyWorker.sneakyTry(() -> save(configFile));
6473
}
6574

66-
public void load() {
75+
public void load()
76+
{
6777
SneakyWorker.sneakyTry(() -> load(configFile));
6878
}
6979

70-
public void reload() {
80+
public void reload()
81+
{
7182
save();
7283
load();
7384
}
7485

75-
public boolean validateIntegrity(@NotNull File fromDisk) {
86+
public boolean validateIntegrity(@NotNull File fromDisk)
87+
{
7688
YamlConfiguration disk = YamlConfiguration.loadConfiguration(fromDisk);
77-
if (disk.getKeys(true).size() <= 0) {
89+
if (disk.getKeys(true).isEmpty())
90+
{
7891
return false;
7992
}
8093

8194
boolean result = true;
8295

83-
for (String key : configEntries.keySet()) {
84-
if (!disk.getKeys(false).contains(key)) {
85-
if (result) result = false;
96+
for (String key : configEntries.keySet())
97+
{
98+
if (!disk.getKeys(false).contains(key))
99+
{
100+
if (result)
101+
result = false;
86102
}
87103
}
88104
return result;
89105
}
90106

91-
public AbstractListener.Rarity getRarity(String name) {
107+
public AbstractListener.Rarity getRarity(String name)
108+
{
92109
return AbstractListener.Rarity.valueOf(getString(name));
93110
}
94111

95-
public double getChance(String path) {
112+
public double getChance(String path)
113+
{
96114
return getDouble(path);
97115
}
98116
}

src/main/java/io/github/simplex/luck/FeelingLucky.java

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,34 @@
77
import io.github.simplex.luck.util.RegenerateConfigCMD;
88
import io.github.simplex.luck.util.SpecialFootItem;
99
import io.github.simplex.metrics.Metrics;
10-
import org.bukkit.command.CommandMap;
11-
import org.bukkit.plugin.java.JavaPlugin;
12-
import org.jetbrains.annotations.NotNull;
13-
1410
import java.io.File;
1511
import java.util.Arrays;
1612
import java.util.HashMap;
1713
import java.util.Map;
1814
import java.util.UUID;
15+
import net.kyori.adventure.chat.ChatType;
16+
import net.kyori.adventure.text.Component;
17+
import org.bukkit.command.CommandMap;
18+
import org.bukkit.plugin.java.JavaPlugin;
19+
import org.jetbrains.annotations.NotNull;
1920

20-
public final class FeelingLucky extends JavaPlugin {
21+
public final class FeelingLucky extends JavaPlugin
22+
{
2123
private final Map<UUID, PlayerConfig> configMap = new HashMap<>();
2224
private final File playerDirectory = new File(getDataFolder(), "players");
2325
private final SpecialFootItem specialFootItem = new SpecialFootItem();
24-
26+
private final ChatType.Bound bind = ChatType.CHAT.bind(Component.text(getName()));
2527
private PlayerHandler handler;
2628
private Config config;
2729

28-
public Map<UUID, PlayerConfig> getConfigMap() {
30+
public Map<UUID, PlayerConfig> getConfigMap()
31+
{
2932
return configMap;
3033
}
3134

3235
@Override
33-
public void onEnable() {
36+
public void onEnable()
37+
{
3438
getLogger().info("Initializing metrics...");
3539
new Metrics(this, 15054);
3640
getLogger().info("Metrics loaded. Initializing the PlayerHandler...");
@@ -50,36 +54,44 @@ public void onEnable() {
5054
}
5155

5256
@Override
53-
public void onDisable() {
57+
public void onDisable()
58+
{
5459
getLogger().info("Saving all player configurations...");
5560
configMap.values().forEach(PlayerConfig::save);
5661
getLogger().info("Complete! Saving the main config...");
5762
config.save();
5863
getLogger().info("Complete! Goodbye! :)");
5964
}
6065

61-
private void loadPlayerConfigurations() {
62-
if (!playerDirectory.exists()) {
66+
private void loadPlayerConfigurations()
67+
{
68+
if (!playerDirectory.exists())
69+
{
6370
getLogger().info("No directory exists. Creating...");
6471
playerDirectory.mkdirs();
6572
getLogger().info("Created new directory \"FeelingLucky/players\".");
6673
return;
6774
}
6875

6976
File[] files = playerDirectory.listFiles();
70-
if (files != null) {
71-
Arrays.stream(files).forEach(file -> {
72-
UUID uuid = UUID.fromString(file.getName().split("\\.")[0]);
73-
configMap.put(uuid, PlayerConfig.initFrom(this, file));
74-
});
77+
if (files != null)
78+
{
79+
Arrays.stream(files).forEach(file ->
80+
{
81+
UUID uuid = UUID.fromString(file.getName().split("\\.")[0]);
82+
configMap.put(uuid, PlayerConfig.initFrom(this, file));
83+
});
7584
configMap.forEach((u, pc) -> pc.load());
7685
getLogger().info("Successfully loaded all configurations!");
77-
} else {
86+
}
87+
else
88+
{
7889
getLogger().info("There are no player configurations to load.");
7990
}
8091
}
8192

82-
private void registerListeners() {
93+
private void registerListeners()
94+
{
8395
new BlockDrops(this);
8496
new BonemealFullCrop(this);
8597
new CheatDeath(this);
@@ -90,7 +102,7 @@ private void registerListeners() {
90102
new IllOmen(this);
91103
new ItemDrops(this);
92104
new JumpBoost(this);
93-
new OreVein(this);
105+
// new OreVein(this); (Currently unstable & unsafe).
94106
new PlayerListener(this);
95107
new RandomEffect(this);
96108
new RestoreHunger(this);
@@ -99,21 +111,30 @@ private void registerListeners() {
99111
new VillagerInventory(this);
100112
}
101113

102-
public PlayerHandler getHandler() {
114+
public PlayerHandler getHandler()
115+
{
103116
return handler;
104117
}
105118

106119
@Override
107120
@NotNull
108-
public Config getConfig() {
121+
public Config getConfig()
122+
{
109123
return config;
110124
}
111125

112-
public SpecialFootItem getFoot() {
126+
public SpecialFootItem getFoot()
127+
{
113128
return specialFootItem;
114129
}
115130

116-
public CommandMap getCommandMap() {
131+
public CommandMap getCommandMap()
132+
{
117133
return getServer().getCommandMap();
118134
}
135+
136+
public ChatType.Bound bind()
137+
{
138+
return bind;
139+
}
119140
}

0 commit comments

Comments
 (0)