mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Actually working %jobsr_jtop_[jobName/number]_[1-15]% placeholder
This commit is contained in:
parent
e431a6cb55
commit
2fd03a4384
@ -7,8 +7,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -27,7 +25,6 @@ import com.gamingmesh.jobs.container.Title;
|
||||
import com.gamingmesh.jobs.container.TopList;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||
|
||||
import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||
import net.Zrips.CMILib.Container.CMIList;
|
||||
@ -38,7 +35,6 @@ public class Placeholder {
|
||||
|
||||
private Jobs plugin;
|
||||
|
||||
private final AtomicInteger jobLevel = new AtomicInteger();
|
||||
private final Pattern placeholderPatern = Pattern.compile("(%)([^\"^%]*)(%)");
|
||||
|
||||
public Placeholder(Jobs plugin) {
|
||||
@ -75,7 +71,6 @@ public class Placeholder {
|
||||
user_jobs,
|
||||
|
||||
user_boost_$1_$2("jname/number", "money/exp/points"),
|
||||
user_jtoplvl_$1_$2("jname/number", "number"),
|
||||
user_isin_$1("jname/number"),
|
||||
user_canjoin_$1("jname/number"),
|
||||
user_jlevel_$1("jname/number"),
|
||||
@ -92,6 +87,8 @@ public class Placeholder {
|
||||
user_archived_jobs_level_$1("jname/number"),
|
||||
user_archived_jobs_exp_$1("jname/number"),
|
||||
|
||||
jtop_$1_$2("jname/number", "[1-15]"),
|
||||
|
||||
maxjobs,
|
||||
total_workers,
|
||||
|
||||
@ -533,26 +530,6 @@ public class Placeholder {
|
||||
case user_boost_$1_$2:
|
||||
Boost boost = Jobs.getPlayerManager().getFinalBonus(user, job, true, true);
|
||||
return (vals.size() < 2 || j == null) ? "" : simplifyDouble(boost.getFinal(CurrencyType.getByName(vals.get(1)), false, true));
|
||||
case user_jtoplvl_$1_$2:
|
||||
if (vals.size() < 2 || job == null)
|
||||
return "";
|
||||
|
||||
try {
|
||||
jobLevel.set(Integer.parseInt(vals.get(1)));
|
||||
} catch (NumberFormatException e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
for (TopList l : Jobs.getJobsDAO().getGlobalTopList(jobLevel.get())) {
|
||||
if (l.getPlayerInfo().getName().equals(user.getName())) {
|
||||
JobProgression prog = l.getPlayerInfo().getJobsPlayer().getJobProgression(job);
|
||||
return prog == null ? "" : prog.getLevelFormatted();
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}).join();
|
||||
case user_isin_$1:
|
||||
return job == null ? "no" : convert(user.isInJob(job));
|
||||
case user_job_$1:
|
||||
@ -622,6 +599,26 @@ public class Placeholder {
|
||||
return "";
|
||||
// Global placeholders by jobname
|
||||
switch (placeHolder) {
|
||||
case jtop_$1_$2:
|
||||
if (values.size() < 2)
|
||||
return "";
|
||||
|
||||
int place = 0;
|
||||
try {
|
||||
place = Integer.parseInt(values.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (place < 1)
|
||||
return "";
|
||||
|
||||
List<TopList> list = Jobs.getJobsDAO().getTopListByJob(jo, 15);
|
||||
|
||||
if (list.size() < place)
|
||||
return "";
|
||||
|
||||
return list.get(place - 1).getPlayerInfo().getDisplayName();
|
||||
case name_$1:
|
||||
return jo.getName();
|
||||
case shortname_$1:
|
||||
|
@ -41,6 +41,9 @@ public class BlockProtectionManager {
|
||||
|
||||
public void add(Block block, Integer cd) {
|
||||
|
||||
if (cd == 0)
|
||||
return;
|
||||
|
||||
// Assuming that block is bottom part of flower we will add top part to the record too
|
||||
CMIMaterial cmat = CMIMaterial.get(block);
|
||||
switch (cmat) {
|
||||
@ -77,6 +80,9 @@ public class BlockProtectionManager {
|
||||
|
||||
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
|
||||
|
||||
if (time == 0)
|
||||
return null;
|
||||
|
||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
|
||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.getOrDefault(loc.getWorld(), new HashMap<>());
|
||||
|
@ -35,6 +35,7 @@ public class RestrictedBlockManager {
|
||||
"Category name can be any you like to be easily recognized",
|
||||
"id can be actual block id (use /jobs blockinfo to get correct id) or use block name",
|
||||
"By setting time to -1 will keep block protected until global cleanup, mainly used for structure blocks like diamond",
|
||||
"Set to 0 if you want to disable protection on specific blocks",
|
||||
"If you want to have default value for all blocks, enable GlobalBlockTimer in generalConfig file");
|
||||
|
||||
org.bukkit.configuration.ConfigurationSection section = cfg.getC().getConfigurationSection("blocksTimer");
|
||||
|
@ -1733,6 +1733,55 @@ public abstract class JobsDAO {
|
||||
return getGlobalTopList(0);
|
||||
}
|
||||
|
||||
HashMap<String, List<TopList>> TopListByJobCache = new HashMap<String, List<TopList>>();
|
||||
HashMap<String, Long> TopListByJobUpdateCache = new HashMap<String, Long>();
|
||||
|
||||
/**
|
||||
* Get player list by total job level
|
||||
* @param start - starting entry
|
||||
* @return info - information about jobs
|
||||
*/
|
||||
public List<TopList> getTopListByJob(Job job, int amount) {
|
||||
|
||||
if (System.currentTimeMillis() - TopListByJobUpdateCache.getOrDefault(job.getName(), 0L) < 30 * 1000L) {
|
||||
return TopListByJobCache.get(job.getName());
|
||||
}
|
||||
|
||||
TopListByJobUpdateCache.put(job.getName(), System.currentTimeMillis());
|
||||
|
||||
List<TopList> jobs = new ArrayList<>();
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return jobs;
|
||||
|
||||
PreparedStatement prest = null;
|
||||
ResultSet res = null;
|
||||
|
||||
try {
|
||||
prest = conn.prepareStatement("SELECT `" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "` FROM `"
|
||||
+ getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? OR `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? ORDER BY `" + JobsTableFields.level.getCollumn()
|
||||
+ "` DESC, `" + JobsTableFields.experience.getCollumn() + "` DESC LIMIT " + 0 + ", " + amount + ";");
|
||||
prest.setInt(1, job.getId());
|
||||
prest.setInt(2, job.getLegacyId());
|
||||
res = prest.executeQuery();
|
||||
|
||||
while (res.next()) {
|
||||
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(res.getInt(JobsTableFields.userid.getCollumn()));
|
||||
if (info != null)
|
||||
jobs.add(new TopList(info, res.getInt(JobsTableFields.level.getCollumn()), res.getInt(JobsTableFields.experience.getCollumn())));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(res);
|
||||
close(prest);
|
||||
}
|
||||
|
||||
TopListByJobCache.put(job.getName(), jobs);
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player list by total job level
|
||||
* @param start - starting entry
|
||||
@ -2452,9 +2501,11 @@ public abstract class JobsDAO {
|
||||
Location loc = new Location(world, x, y, z);
|
||||
|
||||
BlockProtection bp = Jobs.getBpManager().addP(loc, resets, true, false);
|
||||
if (bp != null) {
|
||||
bp.setId(id);
|
||||
bp.setRecorded(res.getLong(BlockTableFields.recorded.getCollumn()));
|
||||
bp.setAction(DBAction.NONE);
|
||||
}
|
||||
i++;
|
||||
|
||||
if (ii++ >= 100000) {
|
||||
|
Loading…
Reference in New Issue
Block a user