Skip to content

Commit

Permalink
Merged jobUpdate into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgrandt committed Jan 25, 2017
2 parents 446f46d + 739014d commit 9bcc355
Show file tree
Hide file tree
Showing 26 changed files with 1,220 additions and 232 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
v1.5.4
v1.6.0

+ Reusable job sets that allow for easier job creation
+ CHANGE: Updated format of job info command
+ CHANGE: Commands now properly return as successful or unsuccessful.

v1.5.3

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/erigitic/commands/AdminPayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
recipient.sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by ",
TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
}

return CommandResult.success();
}
} else {
src.sendMessage(Text.of(TextColors.RED, "The amount must be numeric."));
}

return CommandResult.success();
return CommandResult.empty();
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/erigitic/commands/BalanceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
Text playerBalance = defaultCurrency.format(playerAccount.getBalance(defaultCurrency));

sender.sendMessage(Text.of(TextColors.GRAY, "Balance: ", TextColors.GOLD, playerBalance));

return CommandResult.success();
}

return CommandResult.success();
return CommandResult.empty();
}
}
41 changes: 31 additions & 10 deletions src/main/java/com/erigitic/commands/JobCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
package com.erigitic.commands;

import com.erigitic.config.AccountManager;
import com.erigitic.jobs.TEJobs;
import com.erigitic.jobs.JobBasedRequirement;
import com.erigitic.jobs.TEJob;
import com.erigitic.jobs.TEJobManager;
import com.erigitic.main.TotalEconomy;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
Expand All @@ -37,31 +39,50 @@
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.util.Optional;

public class JobCommand implements CommandExecutor {
private AccountManager accountManager;
private TEJobs teJobs;
private TEJobManager teJobManager;

public JobCommand(TotalEconomy totalEconomy) {
accountManager = totalEconomy.getAccountManager();
teJobs = totalEconomy.getTEJobs();
teJobManager = totalEconomy.getTEJobManager();
}

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player sender = ((Player) src).getPlayer().get();
Player player = ((Player) src).getPlayer().get();

// Do checks here, in case we or other plugins want to bypass them in the future
if (args.getOne("jobName").isPresent()) {
String jobName = args.getOne("jobName").get().toString().toLowerCase();

teJobs.setJob(sender, jobName);
Optional<TEJob> optJob = teJobManager.getJob(jobName, false);
if (!optJob.isPresent()) throw new CommandException(Text.of("Job " + jobName + " does not exist!"));

TEJob job = optJob.get();

if (job.getRequirement().isPresent()) {
JobBasedRequirement req = job.getRequirement().get();

if (req.permissionNeeded() != null && !player.hasPermission(req.permissionNeeded()))
throw new CommandException(Text.of("You're not allowed to join job \"" + jobName + "\""));

if (req.jobNeeded() != null && req.jobLevelNeeded() > teJobManager.getJobLevel(req.jobNeeded().toLowerCase(), player)) {
throw new CommandException(Text.of("You need to reach level " + req.jobLevelNeeded() + " as a " + req.jobNeeded() + " first!"));
}
}

teJobManager.setJob(player, jobName);
} else {
String jobName = teJobs.getPlayerJob(sender);
String jobName = teJobManager.getPlayerJob(player);

sender.sendMessage(Text.of(TextColors.GRAY, "Your current job is: ", TextColors.GOLD, jobName));
sender.sendMessage(Text.of(TextColors.GRAY, jobName, " Level: ", TextColors.GOLD, teJobs.getJobLevel(jobName, sender)));
sender.sendMessage(Text.of(TextColors.GRAY, jobName, " Exp: ", TextColors.GOLD, teJobs.getJobExp(jobName, sender), "/", teJobs.getExpToLevel(sender), "\n"));
sender.sendMessage(Text.of(TextColors.GRAY, "Available Jobs: ", TextColors.GOLD, teJobs.getJobList()));
player.sendMessage(Text.of(TextColors.GRAY, "Your current job is: ", TextColors.GOLD, jobName));
player.sendMessage(Text.of(TextColors.GRAY, teJobManager.titleize(jobName), " Level: ", TextColors.GOLD, teJobManager.getJobLevel(jobName, player)));
player.sendMessage(Text.of(TextColors.GRAY, teJobManager.titleize(jobName), " Exp: ", TextColors.GOLD, teJobManager.getJobExp(jobName, player), "/", teJobManager.getExpToLevel(player), " exp\n"));
player.sendMessage(Text.of(TextColors.GRAY, "Available Jobs: ", TextColors.GOLD, teJobManager.getJobList()));
}
}

Expand Down
65 changes: 43 additions & 22 deletions src/main/java/com/erigitic/commands/JobInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
package com.erigitic.commands;

import com.erigitic.config.AccountManager;
import com.erigitic.jobs.TEJobs;
import com.erigitic.jobs.TEJob;
import com.erigitic.jobs.TEJobManager;
import com.erigitic.jobs.TEJobSet;
import com.erigitic.main.TotalEconomy;
import ninja.leaping.configurate.ConfigurationNode;
import org.apache.commons.lang3.text.WordUtils;
Expand All @@ -45,9 +47,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class JobInfoCommand implements CommandExecutor {
private TEJobs teJobs;
private TEJobManager teJobManager;
private AccountManager accountManager;

private ConfigurationNode jobsConfig;
Expand All @@ -57,34 +61,51 @@ public class JobInfoCommand implements CommandExecutor {
private PaginationList.Builder builder = paginationService.builder();

public JobInfoCommand(TotalEconomy totalEconomy) {
teJobs = totalEconomy.getTEJobs();
teJobManager = totalEconomy.getTEJobManager();
accountManager = totalEconomy.getAccountManager();

jobsConfig = teJobs.getJobsConfig();
jobsConfig = teJobManager.getJobsConfig();
}

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player sender = ((Player) src).getPlayer().get();
String jobName = teJobs.getPlayerJob(sender);
List<Text> jobValues = new ArrayList<>();

// TODO: There is probably a much better way of doing this.
boolean hasBreakNode = (jobsConfig.getNode(jobName, "break").getValue() != null);
boolean hasPlaceNode = (jobsConfig.getNode(jobName, "place").getValue() != null);
boolean hasCatchNode = (jobsConfig.getNode(jobName, "catch").getValue() != null);
boolean hasKillNode = (jobsConfig.getNode(jobName, "kill").getValue() != null);

// TODO: Same with this, probably a much better way of doing this.
if (hasBreakNode) { jobValues.addAll(getJobValues(jobName, "break", "Breakables")); }
if (hasPlaceNode) { jobValues.addAll(getJobValues(jobName, "place", "Placeables")); }
if (hasCatchNode) { jobValues.addAll(getJobValues(jobName, "catch", "Catchables")); }
if (hasKillNode) { jobValues.addAll(getJobValues(jobName, "kill", "Killables")); }

printNodeChildren(sender, jobValues);
Optional<String> optJobName = args.getOne("jobName");
Optional<TEJob> optJob = Optional.empty();

if (!optJobName.isPresent() && (src instanceof Player)) {
optJob = teJobManager.getPlayerTEJob(((Player) src));
}

if (optJobName.isPresent()) {
optJob = teJobManager.getJob(optJobName.get(), false);
}

if (!optJob.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "Unknown job: \"" + optJobName.orElse("") + "\""));
}

List<Text> lines = new ArrayList();

lines.add(Text.of(TextColors.GREEN, "Job information for ", TextColors.GOLD, optJobName.isPresent() ? optJobName.get() : teJobManager.getPlayerJob(((Player) src)),"\n\n"));

for (String s : optJob.get().getSets()) {
Optional<TEJobSet> optSet = teJobManager.getJobSet(s);

if (optSet.isPresent()) {
Map<String, List<String>> map = optSet.get().getRewardData();
map.forEach((k, v) -> {
//Add event name
lines.add(Text.of(TextColors.GRAY, TextColors.GOLD, TextStyles.ITALIC, k, "\n"));
//Add targets
v.forEach(id -> {
lines.add(Text.of(TextColors.GRAY, " ID: ", TextColors.DARK_GREEN, id, "\n"));
});
});
}
}

src.sendMessage(Text.join(lines.toArray(new Text[lines.size()])));

return CommandResult.success();
}

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/erigitic/commands/JobReloadCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.erigitic.commands;

import com.erigitic.jobs.TEJobManager;
import com.erigitic.main.TotalEconomy;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

/**
* Created by Life4YourGames on 16.01.17.
*/
public class JobReloadCommand implements CommandExecutor {

private TEJobManager teJobManager;

public JobReloadCommand(TotalEconomy totalEconomy) {
this.teJobManager = totalEconomy.getTEJobManager();
}

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (teJobManager.reloadJobsAndSets()) {
src.sendMessage(Text.of(TextColors.GREEN, "[TE] Sets and jobs reloaded."));
} else {
throw new CommandException(Text.of(TextColors.RED, "[TE] Failed to reload sets and/or jobs!"));
}

return CommandResult.success();
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/erigitic/commands/JobToggleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
Player sender = ((Player) src).getPlayer().get();

accountManager.toggleNotifications(sender);

return CommandResult.success();
}

return CommandResult.success();
return CommandResult.empty();
}
}
12 changes: 11 additions & 1 deletion src/main/java/com/erigitic/commands/PayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,23 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm

recipient.sendMessage(Text.of(TextColors.GRAY, "You have received ", TextColors.GOLD, defaultCurrency.format(amount),
TextColors.GRAY, " from ", TextColors.GOLD, sender.getName(), TextColors.GRAY, "."));

return CommandResult.success();
} else if (transferResult.getResult() == ResultType.ACCOUNT_NO_FUNDS) {
sender.sendMessage(Text.of(TextColors.RED, "Insufficient funds."));

return CommandResult.empty();
}
}
} else {
sender.sendMessage(Text.of(TextColors.RED, "The amount must be positive."));

return CommandResult.empty();
}
} else {
sender.sendMessage(Text.of(TextColors.RED, "The amount must only contain numbers and a single decimal point if needed."));

return CommandResult.empty();
}
} else if (src instanceof ConsoleSource || src instanceof CommandBlockSource) {
Object playerArg = args.getOne("player").get();
Expand All @@ -120,10 +128,12 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
recipient.sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by the ",
TextColors.GOLD, "SERVER."));
}

return CommandResult.success();
}
}
}

return CommandResult.success();
return CommandResult.empty();
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/erigitic/config/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Optional;
Expand Down Expand Up @@ -164,7 +163,7 @@ public Optional<UniqueAccount> getOrCreateAccount(UUID uuid) {
if (!hasAccount(uuid)) {
if (!databaseActive) {
accountConfig.getNode(uuid.toString(), currencyName + "-balance").setValue(playerAccount.getDefaultBalance(getDefaultCurrency()));
accountConfig.getNode(uuid.toString(), "job").setValue("Unemployed");
accountConfig.getNode(uuid.toString(), "job").setValue("unemployed");
accountConfig.getNode(uuid.toString(), "jobnotifications").setValue(totalEconomy.hasJobNotifications());
loader.save(accountConfig);
} else {
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/erigitic/jobs/JobBasedRequirement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of Total Economy, licensed under the MIT License (MIT).
*
* Copyright (c) Eric Grandt <https://www.ericgrandt.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.erigitic.jobs;

import ninja.leaping.configurate.ConfigurationNode;

/**
* @author MarkL4YG
*
* Requirement notation that is usable in various places such as higher job tiers
*/
public class JobBasedRequirement {
private int needsJobLevel;
private String needsJob;
private String needsPermission;

private JobBasedRequirement(ConfigurationNode node) {
this(node.getNode("job").getString(null),
node.getNode("level").getInt(0),
node.getNode("permission").getString(null));
}

private JobBasedRequirement(String needsJob, int needJobLevel, String needsPermission) {
this.needsJob = needsJob;
this.needsJobLevel = needJobLevel;
this.needsPermission = needsPermission;
}

public static JobBasedRequirement of(ConfigurationNode node) {
return new JobBasedRequirement(node);
}
public static JobBasedRequirement of(String needsJob, int needsJobLevel, String needsPermission) {
return new JobBasedRequirement(needsJob, needsJobLevel, needsPermission);
}

public int jobLevelNeeded() {
return needsJobLevel;
}

//@Nullable
public String jobNeeded() {
return needsJob;
}

//@Nullable
public String permissionNeeded() {
return needsPermission;
}

public void addTo(ConfigurationNode node) {
node = node.getNode("require");
node.getNode("job").setValue(needsJob);
node.getNode("level").setValue(needsJobLevel);
node.getNode("permission").setValue(needsPermission);
}
}
Loading

0 comments on commit 9bcc355

Please sign in to comment.