Archived
Added some new commands and made the rewards system fully functional, release stage;
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Controllers;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.Reward;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigController {
|
||||
@@ -56,13 +61,26 @@ public class ConfigController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Reward> getRewards(){
|
||||
List<Reward> returnList = new ArrayList<Reward>();
|
||||
if (!customConfig.getConfigurationSection("rewards").getKeys(false).isEmpty()) {
|
||||
customConfig.getConfigurationSection("rewards").getKeys(false).forEach((str) -> {
|
||||
returnList.add(new Reward(Integer.parseInt(str), customConfig.getBoolean("rewards." + str + ".doesRepeat"), customConfig.getString("rewards." + str + ".message"), customConfig.getStringList("rewards." + str + ".commands")));
|
||||
});
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public String getSavedX(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.X");
|
||||
return this.customConfig.getString("data."+uuid.toString()+".lastLocation.X");
|
||||
}
|
||||
public String getSavedY(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.Y");
|
||||
return this.customConfig.getString("data."+uuid.toString()+".lastLocation.Y");
|
||||
}
|
||||
public String getSavedZ(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.Z");
|
||||
return this.customConfig.getString("data."+uuid.toString()+".lastLocation.Z");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class PlayerDatabase {
|
||||
@@ -35,6 +33,26 @@ public class PlayerDatabase {
|
||||
return returnedPlayer;
|
||||
}
|
||||
|
||||
class Sortbyroll implements Comparator<PlayerData>
|
||||
{
|
||||
// Used for sorting in ascending order of
|
||||
// roll number
|
||||
public int compare(PlayerData a, PlayerData b)
|
||||
{
|
||||
return b.getPlaytime() - a.getPlaytime();
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerData> getSortedPlayerlist(){
|
||||
List<PlayerData> sorted = new ArrayList<PlayerData>();
|
||||
|
||||
sorted.addAll(playerList);
|
||||
Collections.sort(sorted, new Sortbyroll());
|
||||
|
||||
return sorted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void updatePlayerDisplayName(UUID uuid, String displayName){
|
||||
PlayerData player = getPlayer(uuid);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Controllers;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.Reward;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RewardManager {
|
||||
private List<Reward> rewards = new ArrayList<Reward>();
|
||||
private Plugin plugin;
|
||||
|
||||
public RewardManager(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void unlockRewards(Player player, String chatPrefix){
|
||||
for (int i = 0; i < rewards.size(); i++) {
|
||||
Reward reward = rewards.get(i);
|
||||
PlayerData pd = plugin.db.getPlayer(player.getUniqueId());
|
||||
if(reward.DoesRepeat == true){
|
||||
if((pd.getPlaytime()/reward.TimeRequred)>1){
|
||||
//Put Unlock Code Here
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', chatPrefix+reward.UnlockMessage));
|
||||
|
||||
for (int b = 0; b < reward.Commands.size(); b++) {
|
||||
String rewardCommand = reward.Commands.get(b);
|
||||
|
||||
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
Bukkit.dispatchCommand(console, rewardCommand.replace("%PLAYER%", player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}else if(reward.DoesRepeat == false){
|
||||
if(pd.getPlaytime() == reward.TimeRequred){
|
||||
//Put Unlock Code Here
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', chatPrefix+reward.UnlockMessage));
|
||||
|
||||
for (int b = 0; b < reward.Commands.size(); b++) {
|
||||
String rewardCommand = reward.Commands.get(b);
|
||||
|
||||
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
Bukkit.dispatchCommand(console, rewardCommand.replace("%PLAYER%", player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadRewards(){
|
||||
this.rewards = plugin.config.getRewards();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user