mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 03:00:29 +01:00
Finished Level rewards. Added Repeated rewards.
This commit is contained in:
parent
032f17d51c
commit
de2c865ca9
@ -1,13 +1,12 @@
|
||||
package com.songoda.skyblock.island;
|
||||
|
||||
import com.songoda.core.locale.Message;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.island.reward.LevelReward;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -57,10 +56,7 @@ public class IslandLevel {
|
||||
|
||||
this.materials = materials;
|
||||
|
||||
if (configLoad.contains("Levelling.Highest-Level"))
|
||||
this.highestLevel = configLoad.getLong("Levelling.Highest-Level");
|
||||
else
|
||||
this.highestLevel = getLevel();
|
||||
this.highestLevel = configLoad.contains("Levelling.Highest-Level") ? configLoad.getLong("Levelling.Highest-Level") : getLevel();
|
||||
}
|
||||
|
||||
public void setOwnerUUID(UUID ownerUUID) {
|
||||
@ -126,27 +122,37 @@ public class IslandLevel {
|
||||
|
||||
long level = getLevel();
|
||||
|
||||
// Island Level increased above highest
|
||||
if (level > highestLevel) {
|
||||
// Level didn't reach the highest
|
||||
if (level <= highestLevel)
|
||||
return;
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getPlayer(ownerUUID);
|
||||
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
// Reward the player for each level reached
|
||||
if (offlinePlayer != null && offlinePlayer.isOnline()) {
|
||||
for (int i = (int) highestLevel; i <= level; i++) {
|
||||
LevelReward levelReward = skyblock.getRewardManager().getReward(i);
|
||||
String msg = configLoad.getString("Command.Island.Level.LevelUp.Message")
|
||||
.replace("%level%", "" + level);
|
||||
|
||||
if (levelReward == null)
|
||||
continue;
|
||||
Island island = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(ownerUUID));
|
||||
|
||||
levelReward.give(offlinePlayer.getPlayer(), skyblock);
|
||||
}
|
||||
for (Player player : skyblock.getIslandManager().getPlayersAtIsland(island)) {
|
||||
|
||||
new Message("You have reached island level " + level).sendMessage(offlinePlayer.getPlayer());
|
||||
skyblock.getMessageManager().sendMessage(player, msg);
|
||||
|
||||
// Reward the player for each level reached, message only for the highest, so we don't spam the chat
|
||||
for (int i = (int) highestLevel; i <= level; i++) {
|
||||
LevelReward levelReward = skyblock.getRewardManager().getReward(i);
|
||||
|
||||
if (levelReward != null)
|
||||
levelReward.give(player, skyblock, i);
|
||||
|
||||
LevelReward repeatReward = skyblock.getRewardManager().getRepeatReward(i);
|
||||
|
||||
if (repeatReward != null)
|
||||
repeatReward.give(player, skyblock, i);
|
||||
}
|
||||
|
||||
setHighestLevel(level);
|
||||
}
|
||||
|
||||
setHighestLevel(level);
|
||||
}
|
||||
|
||||
public void setMaterialAmount(String material, long amount) {
|
||||
|
@ -17,14 +17,15 @@ public class LevelReward {
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
public void give(Player player, SkyBlock skyblock) {
|
||||
public void give(Player player, SkyBlock skyblock, long level) {
|
||||
if (money > 0)
|
||||
EconomyManager.deposit(player, money);
|
||||
|
||||
if (!commands.isEmpty()) {
|
||||
for (String cmd : commands) {
|
||||
cmd = skyblock.getMessageManager().replaceMessage(player, cmd);
|
||||
skyblock.getServer().dispatchCommand(skyblock.getConsole(), cmd.replace("%player%", player.getName()));
|
||||
cmd = cmd.replace("%level%", "" + level);
|
||||
cmd = cmd.replace("%player%", player.getName());
|
||||
skyblock.getServer().dispatchCommand(skyblock.getConsole(), cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ public class RewardManager {
|
||||
|
||||
private final Map<Long, LevelReward> registeredRewards = new HashMap<>();
|
||||
|
||||
private final Map<Long, LevelReward> repeatRewards = new HashMap<>();
|
||||
|
||||
public RewardManager(SkyBlock skyBlock) {
|
||||
this.skyBlock = skyBlock;
|
||||
}
|
||||
@ -23,8 +25,10 @@ public class RewardManager {
|
||||
final FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
this.registeredRewards.clear();
|
||||
this.repeatRewards.clear();
|
||||
|
||||
for (String key : configLoad.getKeys(false)) {
|
||||
ConfigurationSection onceSection = configLoad.getConfigurationSection("Once");
|
||||
for (String key : onceSection.getKeys(false)) {
|
||||
long level;
|
||||
try {
|
||||
level = Long.parseLong(key);
|
||||
@ -32,7 +36,7 @@ public class RewardManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigurationSection section = configLoad.getConfigurationSection(key);
|
||||
ConfigurationSection section = onceSection.getConfigurationSection(key);
|
||||
|
||||
double money = section.getDouble("money", 0);
|
||||
|
||||
@ -42,13 +46,42 @@ public class RewardManager {
|
||||
|
||||
this.registeredRewards.put(level, levelReward);
|
||||
}
|
||||
|
||||
ConfigurationSection repeatSection = configLoad.getConfigurationSection("Repeat");
|
||||
for (String key : repeatSection.getKeys(false)) {
|
||||
long level;
|
||||
try {
|
||||
level = Long.parseLong(key);
|
||||
} catch (NumberFormatException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigurationSection section = repeatSection.getConfigurationSection(key);
|
||||
|
||||
double money = section.getDouble("money", 0);
|
||||
|
||||
List<String> commands = section.contains("commands") ? section.getStringList("commands") : new ArrayList<>();
|
||||
|
||||
LevelReward levelReward = new LevelReward(commands, money);
|
||||
|
||||
this.repeatRewards.put(level, levelReward);
|
||||
}
|
||||
}
|
||||
|
||||
public LevelReward getReward(long level) {
|
||||
return this.registeredRewards.getOrDefault(level, null);
|
||||
}
|
||||
|
||||
public LevelReward getRepeatReward(long level) {
|
||||
for (long loopLevel : this.repeatRewards.keySet()) {
|
||||
if (level % loopLevel == 0) {
|
||||
return this.repeatRewards.get(loopLevel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<Long, LevelReward> getRegisteredRewards() {
|
||||
return Collections.unmodifiableMap(this.registeredRewards);
|
||||
}
|
||||
}
|
||||
}
|
@ -154,8 +154,12 @@ public final class IslandScan extends BukkitRunnable {
|
||||
final MessageManager messageManager = SkyBlock.getInstance().getMessageManager();
|
||||
|
||||
for (Player player : SkyBlock.getInstance().getIslandManager().getPlayersAtIsland(island)) {
|
||||
|
||||
messageManager.sendMessage(player, message);
|
||||
if (displayComplete) messageManager.sendMessage(player, config.getString("Command.Island.Level.Scanning.Finished.Message"));
|
||||
|
||||
// Check for level ups
|
||||
island.getLevel().checkLevelUp();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,8 @@ Command:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &7&oProcessing Island level request... Please wait!'
|
||||
Materials:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eThere are no significant materials on your Island.'
|
||||
LevelUp:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &7You reached island level &e%level%&7!'
|
||||
Unban:
|
||||
Member:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eThat player is not banned from the Island because they are a Member of it.'
|
||||
|
@ -1,11 +1,17 @@
|
||||
# FabledSkyblock Island level rewards
|
||||
1:
|
||||
# Vault balance
|
||||
money: 100
|
||||
# Commands ran by console
|
||||
commands:
|
||||
- 'say %player% reached level 1!'
|
||||
2:
|
||||
money: 100
|
||||
commands:
|
||||
- 'say %player% reached level 1!'
|
||||
Once:
|
||||
1:
|
||||
# Vault balance
|
||||
money: 100
|
||||
# Commands ran by console
|
||||
commands:
|
||||
- 'say %player% reached level 1!'
|
||||
2:
|
||||
money: 100
|
||||
commands:
|
||||
- 'say %player% reached level 1!'
|
||||
Repeat:
|
||||
5:
|
||||
money: 1000
|
||||
commands:
|
||||
- 'say %player% reached level %level%'
|
Loading…
Reference in New Issue
Block a user