-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuckyBlock.java
More file actions
171 lines (150 loc) · 6.99 KB
/
Copy pathLuckyBlock.java
File metadata and controls
171 lines (150 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.akiisx.luckyblock.config;
import com.akiisx.luckyblock.LuckyBlock;
import com.akiisx.luckyblock.data.AnimationConfig;
import com.akiisx.luckyblock.data.ParticleConfig;
import com.akiisx.luckyblock.data.SoundConfig;
import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
public class ConfigManager {
private final LuckyBlock plugin;
private FileConfiguration config;
private String prefix;
private String displayName;
private String skullOwner;
private String mode;
private List<String> lore;
private List<String> disabledWorlds;
private boolean disableAllBuiltInSurprises;
private boolean disableAllCustomSurprises;
private boolean permissionEnabled;
private String permission;
private boolean preventBreak;
private boolean permissionMessageEnabled;
private String permissionMessage;
private ParticleConfig particleConfig;
private SoundConfig soundConfig;
private AnimationConfig animationConfig;
private Map<XMaterial, Double> miningChances;
public ConfigManager(LuckyBlock plugin) {
this.plugin = plugin;
this.miningChances = new HashMap<>();
reload();
}
public void reload() {
plugin.saveDefaultConfig();
plugin.reloadConfig();
this.config = plugin.getConfig();
loadSettings();
loadPermissions();
loadParticles();
loadSounds();
loadAnimation();
loadMiningChances();
}
private void loadSettings() {
ConfigurationSection settings = config.getConfigurationSection("Settings");
if (settings != null) {
this.prefix = settings.getString("Prefix", "&e&lLB &7» ");
this.displayName = settings.getString("DisplayName", "&e&lLucky Block");
this.skullOwner = settings.getString("SkullOwner", "");
this.mode = settings.getString("Mode", "break");
this.lore = settings.getStringList("Lore");
this.disabledWorlds = settings.getStringList("DisabledWorlds");
this.disableAllBuiltInSurprises = settings.getBoolean("DisableAllBuiltInSurprises", true);
this.disableAllCustomSurprises = settings.getBoolean("DisableAllCustomSurprises", false);
}
}
private void loadPermissions() {
ConfigurationSection perm = config.getConfigurationSection("Settings.Permission");
if (perm != null) {
this.permissionEnabled = perm.getBoolean("Enabled", false);
this.permission = perm.getString("Permission", "superluckyblock.luckyblock.default");
this.preventBreak = perm.getBoolean("PreventBreak", false);
ConfigurationSection msg = perm.getConfigurationSection("Message");
if (msg != null) {
this.permissionMessageEnabled = msg.getBoolean("Enabled", true);
this.permissionMessage = msg.getString("Message", "You cannot open this lucky block.");
}
}
}
private void loadParticles() {
ConfigurationSection particles = config.getConfigurationSection("Settings.Particles");
if (particles != null) {
this.particleConfig = new ParticleConfig();
this.particleConfig.setEnabled(particles.getBoolean("Enabled", true));
this.particleConfig.setEffect(particles.getString("Effect", "FLAME"));
this.particleConfig.setAmount(particles.getInt("Amount", 150));
ConfigurationSection offset = particles.getConfigurationSection("Offset");
if (offset != null) {
this.particleConfig.setOffsetX(offset.getDouble("X", 0.5));
this.particleConfig.setOffsetY(offset.getDouble("Y", 0.25));
this.particleConfig.setOffsetZ(offset.getDouble("Z", 0.5));
}
}
}
private void loadSounds() {
ConfigurationSection sounds = config.getConfigurationSection("Settings.Sounds");
if (sounds != null) {
this.soundConfig = new SoundConfig();
this.soundConfig.setEnabled(sounds.getBoolean("Enabled", true));
this.soundConfig.setSound(sounds.getString("Sound", "BLOCK_NOTE_BLOCK_PLING"));
this.soundConfig.setVolume((float) sounds.getDouble("Volume", 1.0));
this.soundConfig.setPitch((float) sounds.getDouble("Pitch", 1.0));
}
}
private void loadAnimation() {
ConfigurationSection anim = config.getConfigurationSection("Animation");
if (anim != null) {
this.animationConfig = new AnimationConfig();
this.animationConfig.setEnabled(anim.getBoolean("Enabled", true));
this.animationConfig.setDurationTicks(anim.getInt("DurationTicks", 40));
this.animationConfig.setFreezePlayer(anim.getBoolean("FreezePlayer", false));
ConfigurationSection animParticles = anim.getConfigurationSection("Particles");
if (animParticles != null) {
ParticleConfig pc = new ParticleConfig();
pc.setEnabled(animParticles.getBoolean("Enabled", true));
pc.setEffect(animParticles.getString("Effect", "FLAME"));
pc.setAmount(animParticles.getInt("Amount", 100));
pc.setOffsetX(0.5);
pc.setOffsetY(0.5);
pc.setOffsetZ(0.5);
this.animationConfig.setParticles(pc);
}
ConfigurationSection animSounds = anim.getConfigurationSection("Sounds");
if (animSounds != null) {
SoundConfig sc = new SoundConfig();
sc.setEnabled(animSounds.getBoolean("Enabled", true));
sc.setSound(animSounds.getString("Sound", "ENTITY_PLAYER_LEVELUP"));
sc.setVolume((float) animSounds.getDouble("Volume", 1.0));
sc.setPitch((float) animSounds.getDouble("Pitch", 1.0));
this.animationConfig.setSounds(sc);
}
}
}
private void loadMiningChances() {
this.miningChances.clear();
List<String> chances = config.getStringList("Chances");
for (String entry : chances) {
String[] parts = entry.split(":");
if (parts.length == 2) {
XMaterial.matchXMaterial(parts[0]).ifPresent(material -> {
try {
double chance = Double.parseDouble(parts[1]);
this.miningChances.put(material, chance);
} catch (NumberFormatException e) {
plugin.getLogger().warning("Invalid chance value for " + parts[0] + ": " + parts[1]);
}
});
}
}
}
public double getMiningChance(XMaterial material) {
return this.miningChances.getOrDefault(material, 0.0);
}
}