Job update
This commit is contained in:
parent
ad38f2c99b
commit
f5cfb8a1a7
18 changed files with 193 additions and 9 deletions
|
|
@ -23,5 +23,7 @@ public class CommandRegistry {
|
|||
GrimmsServer.instance.getCommand("executePlayer").setExecutor(new ExecutePlayer());
|
||||
GrimmsServer.instance.getCommand("buyEnchantment").setExecutor(new BuyEnchantment());
|
||||
GrimmsServer.instance.getCommand("logEnchantmentCosts").setExecutor(new LogEnchantmentCosts());
|
||||
GrimmsServer.instance.getCommand("logJobs").setExecutor(new LogJobs());
|
||||
GrimmsServer.instance.getCommand("takeJob").setExecutor(new TakeJob());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.JobTitle;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
public class LogJobs implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
if(args.length > 0){
|
||||
JobTitle jobTitle = JobTitlesBaseValues.jobTitleBaseValues.getOrDefault(args[0], null);
|
||||
if(jobTitle == null){
|
||||
sender.sendMessage("Job doesn't exist.");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("__Job:");
|
||||
sender.sendMessage("|" + jobTitle.jobName + " with paycheck " + jobTitle.paycheckSize + " and intelligence requirement " + jobTitle.intelligenceRequirement);
|
||||
sender.sendMessage("|" + jobTitle.jobName + "[" + args[0] + "]: " + jobTitle.jobDescription);
|
||||
sender.sendMessage("|Available for you: " + (((int)PlayerStats.getPlayerStats(((Player) sender)).getStat("intelligence") > jobTitle.intelligenceRequirement) && jobTitle.additionalRequirement.apply((Player)sender)));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("__Jobs:");
|
||||
for (String job : JobTitlesBaseValues.jobTitleBaseValues.keySet()){
|
||||
JobTitle jobTitle = JobTitlesBaseValues.jobTitleBaseValues.get(job);
|
||||
sender.sendMessage("|" + jobTitle.jobName + " with paycheck " + jobTitle.paycheckSize + " and intelligence requirement " + jobTitle.intelligenceRequirement);
|
||||
sender.sendMessage("|" + jobTitle.jobName + "[" + job + "]: " + jobTitle.jobDescription);
|
||||
sender.sendMessage("|Available for you: " + (((int)PlayerStats.getPlayerStats(((Player) sender)).getStat("intelligence") > jobTitle.intelligenceRequirement) && jobTitle.additionalRequirement.apply((Player)sender)));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("This command can only be run by a player.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.JobTitle;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
public class TakeJob implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
if(args.length == 0){
|
||||
sender.sendMessage("Usage: /takeJob <jobId>");
|
||||
return false;
|
||||
}
|
||||
JobTitle jobTitle = JobTitlesBaseValues.jobTitleBaseValues.get(args[0]);
|
||||
if(jobTitle == null || jobTitle == JobTitlesBaseValues.jobTitleBaseValues.get("")){
|
||||
sender.sendMessage("Job doesn't exist.");
|
||||
return false;
|
||||
}
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
if((int)playerStats.getStat("intelligence") < jobTitle.intelligenceRequirement){
|
||||
sender.sendMessage("Not smart enough!");
|
||||
return false;
|
||||
}
|
||||
if(!jobTitle.additionalRequirement.apply(player)){
|
||||
sender.sendMessage("Secondary requirement not met!");
|
||||
return false;
|
||||
}
|
||||
playerStats.setStat("jobTitle", args[0]);
|
||||
sender.sendMessage("Job taken: " + jobTitle.jobName);
|
||||
sender.sendMessage("Paycheck: " + jobTitle.paycheckSize + "/Description: " + jobTitle.jobDescription);
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("This command can only be run by a player.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.gsdistance.grimmsServer.Constructable;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class JobTitle {
|
||||
public final int intelligenceRequirement;
|
||||
public final double paycheckSize;
|
||||
public final String jobDescription;
|
||||
public final String jobName;
|
||||
public final Function<Player,Boolean> additionalRequirement;
|
||||
public JobTitle(String jobName, String jobDescription, int intelligenceRequirement, double paycheckSize, Function<Player,Boolean> additionalRequirement){
|
||||
this.jobName = jobName;
|
||||
this.jobDescription = jobDescription;
|
||||
this.intelligenceRequirement = intelligenceRequirement;
|
||||
this.paycheckSize = paycheckSize;
|
||||
this.additionalRequirement = additionalRequirement;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.gsdistance.grimmsServer.Data;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.JobTitle;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerTitles;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class JobTitlesBaseValues {
|
||||
public static final Map<String, JobTitle> jobTitleBaseValues = Map.ofEntries(
|
||||
Map.entry("dictator", new JobTitle("Dictator", "Dictator of a dictatorship. Requires title 'Dictator'", 95, 50000.0, (Player player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Dictator"))),
|
||||
Map.entry("executioner", new JobTitle("Executioner", "Executioner, self explanatory. Requires title 'Executioner'", 65, 8500.0, (Player player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Executioner"))),
|
||||
Map.entry("", new JobTitle("None", "No Job", -1, 0.0, (Player player) -> true)),
|
||||
Map.entry("miner", new JobTitle("Miner", "Minin' for a quick buck, requires title 'Miner'", -1, 750.0, (Player player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Miner"))),
|
||||
Map.entry("hitman", new JobTitle("Hitman", "Killing as a job? Right away! Requires title 'Hitman'", -1, 17500.0, (Player player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Hitman")))
|
||||
);
|
||||
}
|
||||
|
|
@ -2,10 +2,13 @@ package org.gsdistance.grimmsServer.Events;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Commands.CommandRegistry;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.PlayerTitleManager;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ServerStartupEvent {
|
||||
|
|
@ -24,6 +27,17 @@ public class ServerStartupEvent {
|
|||
PlayerTitleManager.checkForTotalKills(player);
|
||||
}
|
||||
}
|
||||
if(ticks % 24000 == 0){
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
String jobTitleId = (String) playerStats.getStat("jobTitle");
|
||||
double payCheck = JobTitlesBaseValues.jobTitleBaseValues.getOrDefault(jobTitleId, null).paycheckSize;
|
||||
if(!Objects.equals(jobTitleId, "") && jobTitleId != null){
|
||||
playerStats.setStat("money", (Double)playerStats.getStat("money") + payCheck);
|
||||
}
|
||||
player.sendMessage("You have received your paycheck: " + payCheck);
|
||||
}
|
||||
}
|
||||
}, 100L, 1L);
|
||||
GrimmsServer.logger.log(Level.INFO, "GrimmsServer has started successfully.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ import org.bukkit.persistence.PersistentDataType;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerStats {
|
||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||
|
|
@ -28,6 +25,9 @@ public class PlayerStats {
|
|||
Stats.put("xp_required", PersistentDataType.DOUBLE);
|
||||
Stats.put("titles", PersistentDataType.STRING);
|
||||
Stats.put("sent_messages", PersistentDataType.LONG);
|
||||
Stats.put("intelligence", PersistentDataType.INTEGER);
|
||||
Stats.put("jobTitle", PersistentDataType.STRING);
|
||||
Stats.put("homes", PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
public static final Dictionary<String, String> StatNames = new Hashtable<>();
|
||||
|
|
@ -44,6 +44,9 @@ public class PlayerStats {
|
|||
StatNames.put("xp_required", "Experience Required");
|
||||
StatNames.put("titles", "Player Titles");
|
||||
StatNames.put("sent_messages", "Messages Sent");
|
||||
StatNames.put("intelligence", "Intelligence");
|
||||
StatNames.put("jobTitle", "Job");
|
||||
StatNames.put("homes", "Homes");
|
||||
}
|
||||
|
||||
public static final List<String> StatOrder = List.of(
|
||||
|
|
@ -56,7 +59,9 @@ public class PlayerStats {
|
|||
"sent_messages",
|
||||
"level",
|
||||
"xp",
|
||||
"xp_required"
|
||||
"xp_required",
|
||||
"intelligence",
|
||||
"jobTitle"
|
||||
);
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
|
@ -68,6 +73,14 @@ public class PlayerStats {
|
|||
if (!hasExactStat("titles")) {
|
||||
setStat("titles", new Gson().toJson(new ArrayList<String>().toArray()));
|
||||
}
|
||||
if (!hasExactStat("homes")) {
|
||||
setStat("homes", new Gson().toJson(Map.of(
|
||||
"home","0 100 0"
|
||||
)));
|
||||
}
|
||||
if(!hasExactStat("intelligence")){
|
||||
setStat("intelligence", new Random().nextInt(0,100));
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerStats getPlayerStats(Player player) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue