mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-20 14:21:43 +01:00
new command to display posible placeholders
Some complexing for similar placeholders
This commit is contained in:
parent
0849d5532d
commit
98cd4dee23
@ -205,7 +205,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
|
if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
|
||||||
return false;
|
return false;
|
||||||
if ((new PlaceholderAPIHook(this)).hook())
|
if ((new PlaceholderAPIHook(this)).hook())
|
||||||
Bukkit.getConsoleSender().sendMessage("[Jobs] PlaceholderAPI hooked.");
|
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,10 +786,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (setupPlaceHolderAPI()) {
|
if (setupPlaceHolderAPI()) {
|
||||||
consoleMsg("PlaceholderAPI was found - Enabling capabilities.");
|
consoleMsg("&ePlaceholderAPI was found - Enabling capabilities.");
|
||||||
PlaceholderAPIEnabled = true;
|
PlaceholderAPIEnabled = true;
|
||||||
} else {
|
|
||||||
consoleMsg("PlaceholderAPI nope");
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -6,6 +6,7 @@ import java.util.UUID;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
@ -13,6 +14,7 @@ import com.gamingmesh.jobs.container.CurrencyType;
|
|||||||
import com.gamingmesh.jobs.container.Job;
|
import com.gamingmesh.jobs.container.Job;
|
||||||
import com.gamingmesh.jobs.container.JobProgression;
|
import com.gamingmesh.jobs.container.JobProgression;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
|
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||||
|
|
||||||
public class Placeholder {
|
public class Placeholder {
|
||||||
|
|
||||||
@ -38,38 +40,32 @@ public class Placeholder {
|
|||||||
user_issaved,
|
user_issaved,
|
||||||
user_displayhonorific,
|
user_displayhonorific,
|
||||||
user_joinedjobcount,
|
user_joinedjobcount,
|
||||||
user_boost_$1_$2("jobname/number", "money/exp/points"),
|
user_boost_$1_$2("jname/number", "money/exp/points"),
|
||||||
user_isin_$1("jobname/number"),
|
user_isin_$1("jname/number"),
|
||||||
user_canjoin_$1("jobname/number"),
|
user_canjoin_$1("jname/number"),
|
||||||
user_jlevel_$1("jobname/number"),
|
user_jlevel_$1("jname/number"),
|
||||||
user_jexp_$1("jobname/number"),
|
user_jexp_$1("jname/number"),
|
||||||
user_jmaxexp_$1("jobname/number"),
|
user_jmaxexp_$1("jname/number"),
|
||||||
user_jmaxlvl_$1("jobname/number"),
|
user_jmaxlvl_$1("jname/number"),
|
||||||
|
|
||||||
maxjobs,
|
maxjobs,
|
||||||
|
|
||||||
limit_exp,
|
limit_$1("money/exp/points"),
|
||||||
limit_points,
|
plimit_$1("money/exp/points"),
|
||||||
limit_money,
|
plimit_tleft_$1("money/exp/points"),
|
||||||
plimit_exp,
|
|
||||||
plimit_money,
|
|
||||||
plimit_points,
|
|
||||||
plimit_tleft_exp,
|
|
||||||
plimit_tleft_money,
|
|
||||||
plimit_tleft_points,
|
|
||||||
|
|
||||||
total_workers,
|
total_workers,
|
||||||
|
|
||||||
name_$1("number/name"),
|
name_$1("jname/number"),
|
||||||
shortname_$1("number/name"),
|
shortname_$1("jname/number"),
|
||||||
chatcolor_$1("number/name"),
|
chatcolor_$1("jname/number"),
|
||||||
description_$1("number/name"),
|
description_$1("jname/number"),
|
||||||
maxdailyq_$1("number/name"),
|
maxdailyq_$1("jname/number"),
|
||||||
maxlvl_$1("number/name"),
|
maxlvl_$1("jname/number"),
|
||||||
maxviplvl_$1("number/name"),
|
maxviplvl_$1("jname/number"),
|
||||||
totalplayers_$1("number/name"),
|
totalplayers_$1("jname/number"),
|
||||||
maxslots_$1("number/name"),
|
maxslots_$1("jname/number"),
|
||||||
bonus_$1("jobname/number");
|
bonus_$1("jname/number");
|
||||||
|
|
||||||
private String[] vars;
|
private String[] vars;
|
||||||
private List<Integer> groups = new ArrayList<>();
|
private List<Integer> groups = new ArrayList<>();
|
||||||
@ -108,7 +104,7 @@ public class Placeholder {
|
|||||||
if (one.isComplex())
|
if (one.isComplex())
|
||||||
continue;
|
continue;
|
||||||
// String n = one.name().replace("_", "");
|
// String n = one.name().replace("_", "");
|
||||||
if (one.name().equalsIgnoreCase(name)) {
|
if (one.getName().equalsIgnoreCase(name)) {
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +112,7 @@ public class Placeholder {
|
|||||||
for (JobsPlaceHolders one : JobsPlaceHolders.values()) {
|
for (JobsPlaceHolders one : JobsPlaceHolders.values()) {
|
||||||
if (one.isComplex())
|
if (one.isComplex())
|
||||||
continue;
|
continue;
|
||||||
String n = one.name();
|
String n = one.getName();
|
||||||
if (n.equalsIgnoreCase(name)) {
|
if (n.equalsIgnoreCase(name)) {
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
@ -151,7 +147,7 @@ public class Placeholder {
|
|||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String n = one.name();
|
String n = one.getName();
|
||||||
if (n.equals(name))
|
if (n.equals(name))
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
@ -159,11 +155,15 @@ public class Placeholder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return pref + "_" + this.name();
|
||||||
|
}
|
||||||
|
|
||||||
public String getFull() {
|
public String getFull() {
|
||||||
if (this.isComplex()) {
|
if (this.isComplex()) {
|
||||||
String name = this.name();
|
String name = this.getName();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String one : this.name().split("_")) {
|
for (String one : this.getName().split("_")) {
|
||||||
if (!one.startsWith("$"))
|
if (!one.startsWith("$"))
|
||||||
continue;
|
continue;
|
||||||
if (vars.length >= i - 1)
|
if (vars.length >= i - 1)
|
||||||
@ -173,14 +173,14 @@ public class Placeholder {
|
|||||||
|
|
||||||
return "%" + name + "%";
|
return "%" + name + "%";
|
||||||
}
|
}
|
||||||
return "%" + this.name() + "%";
|
return "%" + this.getName() + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMVdW() {
|
public String getMVdW() {
|
||||||
if (this.isComplex()) {
|
if (this.isComplex()) {
|
||||||
String name = this.name();
|
String name = this.getName();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String one : this.name().split("_")) {
|
for (String one : this.getName().split("_")) {
|
||||||
if (!one.startsWith("$"))
|
if (!one.startsWith("$"))
|
||||||
continue;
|
continue;
|
||||||
if (vars.length >= i - 1)
|
if (vars.length >= i - 1)
|
||||||
@ -190,7 +190,7 @@ public class Placeholder {
|
|||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
return this.name();
|
return this.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getComplexRegexMatchers(String text) {
|
public List<String> getComplexRegexMatchers(String text) {
|
||||||
@ -326,8 +326,9 @@ public class Placeholder {
|
|||||||
if (with.startsWith("$"))
|
if (with.startsWith("$"))
|
||||||
with = "\\" + with;
|
with = "\\" + with;
|
||||||
message = message.replaceFirst(group, with);
|
message = message.replaceFirst(group, with);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,11 +380,6 @@ public class Placeholder {
|
|||||||
if (placeHolder == null)
|
if (placeHolder == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<String> vals = placeHolder.getComplexValues(value);
|
|
||||||
if (vals.size() < 2)
|
|
||||||
return "";
|
|
||||||
JobProgression j = getProgFromValue(user, vals.get(0));
|
|
||||||
|
|
||||||
// Placeholders by JobsPLayer object
|
// Placeholders by JobsPLayer object
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
switch (placeHolder) {
|
switch (placeHolder) {
|
||||||
@ -400,7 +396,7 @@ public class Placeholder {
|
|||||||
case user_doneq:
|
case user_doneq:
|
||||||
return String.valueOf(user.getDoneQuests());
|
return String.valueOf(user.getDoneQuests());
|
||||||
case user_seen:
|
case user_seen:
|
||||||
return String.valueOf(user.getSeen());
|
return TimeManage.to24hourShort(System.currentTimeMillis() - user.getSeen());
|
||||||
case user_totallevels:
|
case user_totallevels:
|
||||||
return String.valueOf(user.getTotalLevels());
|
return String.valueOf(user.getTotalLevels());
|
||||||
case user_issaved:
|
case user_issaved:
|
||||||
@ -409,44 +405,49 @@ public class Placeholder {
|
|||||||
return String.valueOf(user.getDisplayHonorific());
|
return String.valueOf(user.getDisplayHonorific());
|
||||||
case user_joinedjobcount:
|
case user_joinedjobcount:
|
||||||
return String.valueOf(user.getJobProgression().size());
|
return String.valueOf(user.getJobProgression().size());
|
||||||
case user_jlevel_$1:
|
|
||||||
return j == null ? "" : String.valueOf(j.getLevel());
|
|
||||||
case user_jexp_$1:
|
|
||||||
return j == null ? "" : String.valueOf(j.getExperience());
|
|
||||||
case user_jmaxexp_$1:
|
|
||||||
return j == null ? "" : String.valueOf(j.getMaxExperience());
|
|
||||||
case user_jmaxlvl_$1:
|
|
||||||
return j == null ? "" : String.valueOf(j.getJob().getMaxLevel(user));
|
|
||||||
case user_boost_$1_$2:
|
|
||||||
return j == null ? "" : simplifyDouble(user.getBoost(j.getJob().getName(), CurrencyType.getByName(vals.get(1))));
|
|
||||||
case user_isin_$1:
|
|
||||||
vals = placeHolder.getComplexValues(value);
|
|
||||||
if (vals.isEmpty())
|
|
||||||
return "";
|
|
||||||
Job jobs = getJobFromValue(vals.get(0));
|
|
||||||
return jobs == null ? "" : convert(user.isInJob(jobs));
|
|
||||||
case limit_exp:
|
|
||||||
return String.valueOf(user.getLimit(CurrencyType.EXP));
|
|
||||||
case limit_money:
|
|
||||||
return String.valueOf(user.getLimit(CurrencyType.MONEY));
|
|
||||||
case limit_points:
|
|
||||||
return String.valueOf(user.getLimit(CurrencyType.POINTS));
|
|
||||||
case plimit_exp:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetAmount(CurrencyType.EXP));
|
|
||||||
case plimit_money:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetAmount(CurrencyType.MONEY));
|
|
||||||
case plimit_points:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetAmount(CurrencyType.POINTS));
|
|
||||||
case plimit_tleft_exp:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetLeftTime(CurrencyType.EXP));
|
|
||||||
case plimit_tleft_money:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetLeftTime(CurrencyType.MONEY));
|
|
||||||
case plimit_tleft_points:
|
|
||||||
return String.valueOf(user.getPaymentLimit().GetLeftTime(CurrencyType.POINTS));
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (placeHolder.isComplex()) {
|
||||||
|
List<String> vals = placeHolder.getComplexValues(value);
|
||||||
|
if (vals.isEmpty())
|
||||||
|
return "";
|
||||||
|
JobProgression j = getProgFromValue(user, vals.get(0));
|
||||||
|
switch (placeHolder) {
|
||||||
|
case limit_$1:
|
||||||
|
CurrencyType t = CurrencyType.getByName(vals.get(0));
|
||||||
|
return String.valueOf(user.getLimit(t));
|
||||||
|
case plimit_$1:
|
||||||
|
t = CurrencyType.getByName(vals.get(0));
|
||||||
|
return String.valueOf(user.getPaymentLimit().GetAmount(t));
|
||||||
|
case plimit_tleft_$1:
|
||||||
|
t = CurrencyType.getByName(vals.get(0));
|
||||||
|
return TimeManage.to24hourShort(user.getPaymentLimit().GetLeftTime(t));
|
||||||
|
case user_jlevel_$1:
|
||||||
|
return j == null ? "" : String.valueOf(j.getLevel());
|
||||||
|
case user_jexp_$1:
|
||||||
|
return j == null ? "" : String.valueOf(j.getExperience());
|
||||||
|
case user_jmaxexp_$1:
|
||||||
|
return j == null ? "" : String.valueOf(j.getMaxExperience());
|
||||||
|
case user_jmaxlvl_$1:
|
||||||
|
return j == null ? "" : String.valueOf(j.getJob().getMaxLevel(user));
|
||||||
|
case user_boost_$1_$2:
|
||||||
|
if (vals.size() < 2)
|
||||||
|
return "";
|
||||||
|
return j == null ? "" : simplifyDouble(user.getBoost(j.getJob().getName(), CurrencyType.getByName(vals.get(1))));
|
||||||
|
case user_isin_$1:
|
||||||
|
vals = placeHolder.getComplexValues(value);
|
||||||
|
if (vals.isEmpty())
|
||||||
|
return "";
|
||||||
|
Job jobs = getJobFromValue(vals.get(0));
|
||||||
|
return jobs == null ? "" : convert(user.isInJob(jobs));
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholders by player object
|
// Placeholders by player object
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
package com.gamingmesh.jobs.commands.list;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.Jobs;
|
||||||
|
import com.gamingmesh.jobs.CMILib.RawMessage;
|
||||||
|
import com.gamingmesh.jobs.Placeholders.Placeholder.JobsPlaceHolders;
|
||||||
|
import com.gamingmesh.jobs.Placeholders.Placeholder.JobsPlaceholderType;
|
||||||
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
|
import com.gamingmesh.jobs.stuff.PageInfo;
|
||||||
|
|
||||||
|
public class placeholders implements Cmd {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JobCommand(1400)
|
||||||
|
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||||
|
|
||||||
|
Player player = null;
|
||||||
|
if (sender instanceof Player)
|
||||||
|
player = (Player) sender;
|
||||||
|
|
||||||
|
int page = 1;
|
||||||
|
if (args.length > 0 && args[0].startsWith("-p:")) {
|
||||||
|
try {
|
||||||
|
page = Integer.parseInt(args[0].substring("-p:".length()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length >= 2 && args[0].equalsIgnoreCase("parse")) {
|
||||||
|
|
||||||
|
String placeholder = args[1];
|
||||||
|
JobsPlaceholderType type = plugin.getPlaceholderAPIManager().getPlaceHolderType(player, placeholder);
|
||||||
|
|
||||||
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.placeholders.output.parse",
|
||||||
|
"[placeholder]", placeholder,
|
||||||
|
"[source]", type == null ? "Unknown" : type.name(),
|
||||||
|
"[result]", plugin.getPlaceholderAPIManager().updatePlaceHolders(player, placeholder)));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PageInfo pi = new PageInfo(player != null ? 10 : JobsPlaceHolders.values().length, JobsPlaceHolders.values().length, page);
|
||||||
|
|
||||||
|
for (JobsPlaceHolders one : JobsPlaceHolders.values()) {
|
||||||
|
if (one.isHidden())
|
||||||
|
continue;
|
||||||
|
if (pi.isBreak())
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!pi.isEntryOk())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
RawMessage rm = new RawMessage();
|
||||||
|
String extra = "";
|
||||||
|
|
||||||
|
if (player != null && !one.isComplex())
|
||||||
|
extra = plugin.getPlaceholderAPIManager().updatePlaceHolders(player, Jobs.getLanguage().getMessage("command.placeholders.output.outputResult",
|
||||||
|
"[result]", Jobs.getInstance().getPlaceholderAPIManager().updatePlaceHolders(player, one.getFull())));
|
||||||
|
|
||||||
|
String place = one.getFull();
|
||||||
|
String hover = "";
|
||||||
|
if (plugin.isPlaceholderAPIEnabled()) {
|
||||||
|
place = one.getFull();
|
||||||
|
hover = one.getFull();
|
||||||
|
}
|
||||||
|
// For MVdWPlaceholderAPI
|
||||||
|
// if (plugin.isMVdWPlaceholderAPIEnabled()) {
|
||||||
|
// if (!plugin.isPlaceholderAPIEnabled()) {
|
||||||
|
// place = one.getFull().substring(1, one.getFull().length() - 2);
|
||||||
|
// place = "{" + place + "}";
|
||||||
|
// }
|
||||||
|
// if (hover.isEmpty())
|
||||||
|
// hover = one.getFull();
|
||||||
|
// else
|
||||||
|
// hover += "\n" + "{" + one.getFull().substring(1, one.getFull().length() - 2) + "}";
|
||||||
|
// }
|
||||||
|
rm.add(Jobs.getLanguage().getMessage("command.placeholders.output.list", "[place]", pi.getPositionForOutput(), "[placeholder]", place) + extra, hover, null, one.getFull());
|
||||||
|
rm.show(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null) {
|
||||||
|
plugin.ShowPagination(sender, pi, "jobs placeholders", "-p:");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -302,6 +302,14 @@ public class LanguageManager {
|
|||||||
c.get("command.iteminfo.output.id", " &eItem id: &6%itemid%");
|
c.get("command.iteminfo.output.id", " &eItem id: &6%itemid%");
|
||||||
c.get("command.iteminfo.output.data", " &eItem data: &6%itemdata%");
|
c.get("command.iteminfo.output.data", " &eItem data: &6%itemdata%");
|
||||||
c.get("command.iteminfo.output.usage", " &eUsage: &6%first% &eor &6%second%");
|
c.get("command.iteminfo.output.usage", " &eUsage: &6%first% &eor &6%second%");
|
||||||
|
|
||||||
|
|
||||||
|
c.get("command.placeholders.help.info", "List out all placeholders");
|
||||||
|
c.get("command.placeholders.help.args", "(parse) (placeholder)");
|
||||||
|
c.get("command.placeholders.output.list", "&e[place]. &7[placeholder]");
|
||||||
|
c.get("command.placeholders.output.outputResult", " &eresult: &7[result]");
|
||||||
|
c.get("command.placeholders.output.parse", "&6[placeholder] &7by [source] &6result &8|&f[result]&8|");
|
||||||
|
|
||||||
|
|
||||||
c.get("command.entitylist.help.info", "Shows all possible entities can be used with plugin.");
|
c.get("command.entitylist.help.info", "Shows all possible entities can be used with plugin.");
|
||||||
c.get("command.entitylist.help.args", "");
|
c.get("command.entitylist.help.args", "");
|
||||||
|
@ -291,6 +291,8 @@ public class JobsPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getLimit(CurrencyType type) {
|
public int getLimit(CurrencyType type) {
|
||||||
|
if (type == null)
|
||||||
|
return 0;
|
||||||
Integer value = this.limits.get(type);
|
Integer value = this.limits.get(type);
|
||||||
return value == null ? 0 : value;
|
return value == null ? 0 : value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user