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