1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Fixed signs updating

- Level, exp adding and taking amounts now correctly calculating.
This commit is contained in:
montlikadani 2019-09-03 17:01:49 +02:00
parent d62349badc
commit f19138db4d
12 changed files with 88 additions and 110 deletions

View File

@ -83,7 +83,7 @@ public class VersionChecker {
Version() {
try {
this.value = Integer.valueOf(this.name().replaceAll("[^\\d.]", ""));
} catch (Throwable e) {
} catch (Exception e) {
}
shortVersion = this.name().substring(0, this.name().length() - 3);
}

View File

@ -66,7 +66,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Logger;
@ -843,29 +842,25 @@ public class Jobs extends JavaPlugin {
// itemManager = new ItemManager(this);
try {
Class<?> nmsClass;
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
Class<?> nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
if (NMS.class.isAssignableFrom(nmsClass)) {
setNms((NMS) nmsClass.getConstructor().newInstance());
} else {
System.out.println("Something went wrong, please note down version and contact author, version: " + version);
setEnabled(false);
return;
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
} catch (Exception e) {
System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + version);
setEnabled(false);
e.printStackTrace();
return;
}
try {
if (setupPlaceHolderAPI()) {
consoleMsg("&ePlaceholderAPI was found - Enabling capabilities.");
PlaceholderAPIEnabled = true;
}
} catch (Throwable e) {
e.printStackTrace();
}
try {

View File

@ -90,7 +90,7 @@ public class Placeholder {
try {
int id = Integer.parseInt(matcher.group(1).substring(1));
groups.add(id);
} catch (Throwable e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@ -220,7 +220,7 @@ public class Placeholder {
for (Integer oneG : groups) {
lsInLs.add(matcher.group(oneG + 1));
}
} catch (Throwable e) {
} catch (Exception e) {
}
break;
}
@ -264,12 +264,9 @@ public class Placeholder {
return JobsPlaceholderType.Jobs;
}
if (plugin.isPlaceholderAPIEnabled()) {
try {
if (placeholder.contains("%"))
if (placeholder.contains("%")) {
if (!placeholder.equals(me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, placeholder)))
return JobsPlaceholderType.PAPI;
} catch (Throwable e) {
}
}
// For MVdWPlaceholderAPI
@ -282,18 +279,13 @@ public class Placeholder {
}
public String updatePlaceHolders(Player player, String message) {
if (message == null)
return null;
if (message.contains("%"))
message = translateOwnPlaceHolder(player, message);
if (plugin.isPlaceholderAPIEnabled()) {
try {
if (message.contains("%"))
message = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message);
} catch (Throwable e) {
}
}
// For MVdWPlaceholderAPI
// if (plugin.isMVdWPlaceholderAPIEnabled()) {
@ -325,8 +317,7 @@ public class Placeholder {
if (with.startsWith("$"))
with = "\\" + with;
message = message.replaceFirst(group, with);
} catch (Throwable e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@ -348,7 +339,7 @@ public class Placeholder {
int id = Integer.parseInt(value);
if (id > 0)
j = user.getJobProgression().get(id - 1);
} catch (Throwable e) {
} catch (Exception e) {
Job job = Jobs.getJob(value);
if (job != null)
j = user.getJobProgression(job);
@ -362,7 +353,7 @@ public class Placeholder {
int id = Integer.parseInt(value);
if (id > 0)
j = Jobs.getJobs().get(id - 1);
} catch (Throwable e) {
} catch (Exception e) {
j = Jobs.getJob(value);
}
return j;
@ -376,7 +367,7 @@ public class Placeholder {
if (placeHolder == null)
return null;
JobsPlayer user = Jobs.getPlayerManager().getJobsPlayer(uuid);
JobsPlayer user = uuid == null ? null : Jobs.getPlayerManager().getJobsPlayer(uuid);
// Placeholders by JobsPlayer object
if (user != null) {
switch (placeHolder) {

View File

@ -29,22 +29,22 @@ public class Reflections {
private void initialize() {
try {
CraftServerClass = getBukkitClass("CraftServer");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
CraftServer = CraftServerClass.cast(Bukkit.getServer());
} catch (SecurityException | IllegalArgumentException e) {
} catch (ClassCastException e) {
e.printStackTrace();
}
try {
NBTTagCompound = getMinecraftClass("NBTTagCompound");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
NBTBase = getMinecraftClass("NBTBase");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
/*try {
@ -55,7 +55,7 @@ public class Reflections {
try {
CraftItemStack = getBukkitClass("inventory.CraftItemStack");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
/*try {
@ -65,7 +65,7 @@ public class Reflections {
}*/
try {
IStack = getMinecraftClass("ItemStack");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

View File

@ -126,8 +126,12 @@ public class SignUtil {
old.put(loc, newTemp);
SignsByLocation.put(loc, newTemp);
}
if (!SignsByLocation.isEmpty()) {
Jobs.consoleMsg("&e[Jobs] Loaded " + SignsByLocation.size() + " top list signs");
return;
}
signUpdate();
}
// Signs save file
@ -163,6 +167,21 @@ public class SignUtil {
return;
}
private int update = -1;
public void signUpdate() {
if (update == -1) {
update = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
for (Entry<String, HashMap<String, jobsSign>> one : SignsByType.entrySet()) {
SignUpdate(Jobs.getJob(one.getKey()));
}
}
}, 60 * 20L, Jobs.getGCManager().InfoUpdateInterval * 20L);
}
}
public boolean SignUpdate(Job job) {
return SignUpdate(job, SignTopType.toplist);
}
@ -171,34 +190,28 @@ public class SignUtil {
return SignUpdate(null, type);
}
public static Integer questSignUpdateShed = null;
public boolean SignUpdate(Job job, SignTopType type) {
if (!Jobs.getGCManager().SignsEnabled)
return true;
int timelapse = 1;
if (update == -1) {
signUpdate();
}
List<TopList> PlayerList = new ArrayList<>();
if (type == null && job == null)
if (job == null)
return false;
if (type == null && job != null)
type = SignTopType.toplist;
if (type == null)
type = SignTopType.toplist;
HashMap<String, List<TopList>> temp = new HashMap<>();
String JobNameOrType = jobsSign.getIdentifier(job, type);
HashMap<String, jobsSign> signs = this.SignsByType.get(JobNameOrType.toLowerCase());
if (signs == null)
return false;
List<TopList> PlayerList = new ArrayList<>();
switch (type) {
case toplist:
break;
@ -212,6 +225,8 @@ public class SignUtil {
break;
}
HashMap<String, List<TopList>> temp = new HashMap<>();
boolean save = false;
for (Entry<String, jobsSign> one : (new HashMap<String, jobsSign>(signs)).entrySet()) {
jobsSign jSign = one.getValue();
@ -280,8 +295,7 @@ public class SignUtil {
sign.setLine(i, line);
}
sign.update();
if (!UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse))
timelapse--;
UpdateHead(sign, PlayerList.get(0).getPlayerName());
} else {
if (jSign.getNumber() > PlayerList.size())
return true;
@ -315,12 +329,9 @@ public class SignUtil {
sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, PlayerName, pl.getLevel(), SignJobName));
sign.update();
if (!UpdateHead(sign, pl.getPlayerName(), timelapse))
timelapse--;
UpdateHead(sign, pl.getPlayerName());
}
timelapse++;
}
if (save)
saveSigns();
@ -337,9 +348,8 @@ public class SignUtil {
"[job]", jobname);
}
public boolean UpdateHead(final org.bukkit.block.Sign sign, final String Playername, int timelapse) {
public boolean UpdateHead(final org.bukkit.block.Sign sign, final String Playername) {
try {
timelapse = timelapse < 1 ? 1 : timelapse;
BlockFace directionFacing = null;
if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) {
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();
@ -378,22 +388,8 @@ public class SignUtil {
if (skull.getOwner() != null && skull.getOwner().equalsIgnoreCase(Playername))
return false;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
Block b = loc.getBlock();
if (!(b.getState() instanceof Skull))
return;
Skull skull = (Skull) b.getState();
if (skull == null)
return;
skull.setOwner(Playername);
skull.update();
return;
}
}, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L);
} catch (Throwable e) {
e.printStackTrace();
}

View File

@ -1,24 +0,0 @@
package com.gamingmesh.jobs.actions;
import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BaseActionInfo;
public class PotionDrinkInfo extends BaseActionInfo implements ActionInfo {
private String potion;
public PotionDrinkInfo(String potion, ActionType type) {
super(type);
this.potion = potion;
}
@Override
public String getName() {
return potion;
}
@Override
public String getNameWithSub() {
return getName();
}
}

View File

@ -47,11 +47,12 @@ public class area implements Cmd {
if (args[0].equalsIgnoreCase("add")) {
if (!Jobs.hasPermission(player, "jobs.area.add", true))
return true;
String name = args[1];
double bonus = 0D;
try {
bonus = Double.parseDouble(args[2]);
} catch (Throwable e) {
} catch (NumberFormatException e) {
return false;
}
boolean wg = false;

View File

@ -64,14 +64,18 @@ public class exp implements Cmd {
// check if player already has the job
if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job);
double total = 0d;
switch (action) {
case Add:
total = (prog.getExperience() + amount);
prog.addExperience(amount);
break;
case Set:
prog.setExperience(amount);
break;
case Take:
total = (prog.getExperience() - amount);
prog.takeExperience(amount);
break;
default:

View File

@ -75,14 +75,18 @@ public class level implements Cmd {
// check if player already has the job
if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job);
int total = 0;
switch (action) {
case Set:
prog.setLevel(amount);
break;
case Add:
prog.setLevel(amount);
total = (prog.getLevel() + amount);
prog.setLevel(total);
break;
case Take:
total = (prog.getLevel() - amount);
prog.setLevel(amount);
break;
default:

View File

@ -30,7 +30,6 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.Signs.SignTopType;
import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.resources.jfep.Parser;
@ -1061,16 +1060,18 @@ public class JobsPlayer {
this.doneQuests = doneQuests;
}
private Integer questSignUpdateShed = null;
public void addDoneQuest() {
this.doneQuests++;
this.setSaved(false);
if (SignUtil.questSignUpdateShed == null) {
SignUtil.questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() {
if (questSignUpdateShed == null) {
questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() {
@Override
public void run() {
Jobs.getSignUtil().SignUpdate(SignTopType.questtoplist);
SignUtil.questSignUpdateShed = null;
questSignUpdateShed = null;
}
}, Jobs.getGCManager().getSavePeriod() * 60 * 20L);
}

View File

@ -195,13 +195,18 @@ public class FurnaceBrewingHandling {
}
}
if (uuid == null) {
return false;
}
List<blockLoc> ls = furnaceMap.get(uuid);
if (ls == null)
return true;
return false;
for (blockLoc one : ls) {
if (!one.getLocation().equals(block.getLocation()))
continue;
block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance());
ls.remove(one);
return true;
@ -221,13 +226,18 @@ public class FurnaceBrewingHandling {
}
}
if (uuid == null) {
return false;
}
List<blockLoc> ls = brewingMap.get(uuid);
if (ls == null)
return true;
return false;
for (blockLoc one : ls) {
if (!one.getLocation().equals(block.getLocation()))
continue;
block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance());
ls.remove(one);
return true;

View File

@ -34,7 +34,7 @@ public class GiveItem {
if (itemStack.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) ItemMeta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), false);
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> OneEnchant : enchants.entrySet()) {