1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

1.12 support and new version checker

This commit is contained in:
Zrips 2017-05-20 14:46:11 +03:00
parent 77d03db7b5
commit 3f71080b02
10 changed files with 267 additions and 90 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId>
<artifactId>jobs</artifactId>
<version>3.9.0</version>
<version>3.9.2</version>
<name>Jobs</name>
<url>http://maven.apache.org</url>
<properties>
@ -118,6 +118,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>C:\Users\Arte\Desktop\Server\plugins</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -88,6 +88,7 @@ import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.JobsClassLoader;
import com.gamingmesh.jobs.stuff.Loging;
import com.gamingmesh.jobs.stuff.TabComplete;
import com.gamingmesh.jobs.stuff.VersionChecker;
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
@ -145,6 +146,8 @@ public class Jobs extends JavaPlugin {
private static ActionBar actionbar;
private boolean running = false;
protected static VersionChecker versionCheckManager;
protected static SelectionManager smanager;
public void setMcMMOlistener() {
@ -686,12 +689,21 @@ public class Jobs extends JavaPlugin {
return economy;
}
/**
* Gets the version check manager
* @return the version check manager
*/
public static VersionChecker getVersionCheckManager() {
return versionCheckManager;
}
@Override
public void onEnable() {
running = true;
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
versionCheckManager = new VersionChecker(this);
version = versionCheckManager.getVersion().getShortVersion();
try {
Class<?> nmsClass;
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
@ -710,6 +722,7 @@ public class Jobs extends JavaPlugin {
}
try {
setActionBar();
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
jobConfig.saveDefaultConfig();

View File

@ -18,6 +18,7 @@ import com.gamingmesh.jobs.container.BossBarInfo;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
public class BossBarManager {
@ -28,7 +29,7 @@ public class BossBarManager {
}
public synchronized void ShowJobProgression(final JobsPlayer player) {
if (Jobs.getActionBar().getVersion() < 1900)
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1))
return;
if (player == null)
@ -48,7 +49,7 @@ public class BossBarManager {
}
public synchronized void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg) {
if (Jobs.getActionBar().getVersion() < 1900)
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1))
return;
String playername = player.getUserName();
if (!Jobs.getBossBarToggleList().containsKey(playername) && Jobs.getGCManager().BossBarsMessageByDefault)

View File

@ -42,6 +42,7 @@ import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.dao.JobsDAOMySQL;
import com.gamingmesh.jobs.dao.JobsDAOSQLite;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
public class GeneralConfigManager {
private Jobs plugin;
@ -144,6 +145,8 @@ public class GeneralConfigManager {
public boolean DBCleaningUsersUse;
public int DBCleaningUsersDays;
private boolean ShowNewVersion;
public HashMap<String, List<String>> getCommandArgs() {
return commandArgs;
}
@ -438,6 +441,10 @@ public class GeneralConfigManager {
if (MultiServerCompatability)
saveOnDisconnect = true;
c.getW().addComment("Optimizations.NewVersion",
"When set to true staff will be informed about new Jobs plugin version", "You need to have jobs.versioncheck permission node");
ShowNewVersion = c.get("Optimizations.NewVersion", true);
c.getW().addComment("Optimizations.DBCleaning.Jobs.Use",
"Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning",
"When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs",
@ -518,7 +525,7 @@ public class GeneralConfigManager {
modifyChat = c.get("modify-chat", true);
modifyChatPrefix = c.get("modify-chat-prefix", "&c[", true);
modifyChatSuffix = c.get("modify-chat-suffix", "&c]", true);
modifyChatSuffix = c.get("modify-chat-suffix", "&c]&r", true);
modifyChatSeparator = c.get("modify-chat-separator", " ", true);
c.getW().addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names",
@ -768,7 +775,7 @@ public class GeneralConfigManager {
c.getW().addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version");
BossBarEnabled = c.get("BossBar.Enabled", true);
if (Jobs.getActionBar().getVersion() < 1900) {
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) {
BossBarEnabled = false;
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Jobs] Your server version don't support BossBar. This feature will be disabled");
}
@ -885,4 +892,8 @@ public class GeneralConfigManager {
public int getSelectionTooldID() {
return getSelectionTooldID;
}
public boolean isShowNewVersion() {
return ShowNewVersion;
}
}

View File

@ -30,6 +30,7 @@ import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.api.JobsPaymentEvent;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
public class BufferedEconomy {
@ -193,7 +194,7 @@ public class BufferedEconomy {
try {
// Action bar stuff
Jobs.getActionBar().ShowActionBar(payment);
if (payment.getOfflinePlayer().isOnline() && Jobs.getActionBar().getVersion() > 1900) {
if (payment.getOfflinePlayer().isOnline() && Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R3)) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId());
Jobs.getBBManager().ShowJobProgression(jPlayer);
}

View File

@ -93,6 +93,12 @@ public class JobsListener implements Listener {
return false;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(PlayerJoinEvent event) {
if (Jobs.getGCManager().isShowNewVersion() && event.getPlayer().hasPermission("jobs.versioncheck"))
plugin.getVersionCheckManager().VersionCheck(event.getPlayer());
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onSelection(PlayerInteractEvent event) {
if (event.getPlayer() == null)

View File

@ -0,0 +1,39 @@
package com.gamingmesh.jobs.nmsUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.NMS;
public class v1_12 implements NMS {
@Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<Block>();
blocks.addAll(event.getBlocks());
return blocks;
}
@Override
public String getRealType(Entity entity) {
return entity.getType().name();
}
@Override
public ItemStack getItemInMainHand(Player player) {
return player.getInventory().getItemInMainHand();
}
@Override
public Block getTargetBlock(Player player, int range) {
return player.getTargetBlock((Set<Material>) null, range);
}
}

View File

@ -12,14 +12,14 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.economy.BufferedPayment;
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
/**
*
* @author hamzaxx
*/
public class ActionBar {
private int cleanVersion = -1;
private String version = "";
private Version version = Version.v1_11_R1;
private Object packet;
private Method getHandle;
private Method sendPacket;
@ -28,49 +28,13 @@ public class ActionBar {
private Class<?> nmsIChatBaseComponent;
private Class<?> packetType;
public int getVersion() {
if (cleanVersion == -1)
getInfo();
return cleanVersion;
}
private void getInfo() {
private Class<?> ChatMessageclz;
private Class<?> sub;
private Object[] consts;
public ActionBar() {
try {
String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
version = v[v.length - 1];
// Translating version to integer for simpler use
try {
cleanVersion = Integer.parseInt(version.replace("v", "").replace("V", "").replace("_", "").replace("r", "").replace("R", ""));
cleanVersion *= 10;
} catch (NumberFormatException e) {
// Fail safe if it for some reason can't translate version to integer
if (version.contains("v1_4"))
cleanVersion = 1400;
if (version.contains("v1_5"))
cleanVersion = 1500;
if (version.contains("v1_6"))
cleanVersion = 1600;
if (version.contains("v1_7"))
cleanVersion = 1700;
if (version.contains("v1_8_R1"))
cleanVersion = 1810;
if (version.contains("v1_8_R2"))
cleanVersion = 1820;
if (version.contains("v1_8_R3"))
cleanVersion = 1830;
if (version.contains("v1_9_R1"))
cleanVersion = 1910;
if (version.contains("v1_9_R2"))
cleanVersion = 1920;
if (version.contains("v1_10_R1"))
cleanVersion = 11010;
if (version.contains("v1_11_R1"))
cleanVersion = 11110;
}
if (cleanVersion < 1400)
cleanVersion *= 10;
version = Jobs.getVersionCheckManager().getVersion();
packetType = Class.forName(getPacketPlayOutChat());
Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
@ -81,17 +45,21 @@ public class ActionBar {
playerConnection = typeNMSPlayer.getField("playerConnection");
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath()));
if (Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_11_R1)) {
ChatMessageclz = Class.forName(getChatMessageTypeClasspath());
consts = ChatMessageclz.getEnumConstants();
sub = consts[2].getClass();
}
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
}
public void ShowActionBar(BufferedPayment payment) {
if (cleanVersion == -1)
getInfo();
if (cleanVersion == -1)
if (!payment.getOfflinePlayer().isOnline())
return;
String playername = payment.getOfflinePlayer().getName();
@ -110,31 +78,15 @@ public class ActionBar {
if (abp != null && show) {
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
if (payment.getAmount() != 0D)
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", convertAmount(payment.getAmount()));
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format("%.2f", payment.getAmount()));
if (payment.getPoints() != 0D)
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", convertAmount(payment.getPoints()));
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format("%.2f", payment.getPoints()));
if (payment.getExp() != 0D)
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", convertAmount(payment.getExp()));
Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format("%.2f", payment.getExp()));
send(abp, ChatColor.GREEN + Message);
}
}
private static String convertAmount(double amount) {
String format = "%.2f";
if (amount % 1 == 0 || amount > 100 || amount < -100) {
amount = (int) Math.round(amount);
format = "%.0f";
} else {
if ((amount * 10) % 1 == 0) {
format = "%.1f";
}
}
return String.format(format, amount);
}
public void send(CommandSender receivingPacket, String msg) {
try {
if (msg == null || nmsChatSerializer == null || msg.isEmpty())
@ -142,14 +94,16 @@ public class ActionBar {
if (receivingPacket == null)
return;
if (cleanVersion < 1800 || !(receivingPacket instanceof Player)) {
if (version.isLower(Version.v1_8_R1) || !(receivingPacket instanceof Player)) {
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
return;
}
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}");
if (cleanVersion > 1800) {
if (Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_11_R1))
packet = packetType.getConstructor(nmsIChatBaseComponent, sub).newInstance(serialized, consts[2]);
else if (version.isHigher(Version.v1_7_R4)) {
packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2);
} else {
packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2);
@ -163,32 +117,36 @@ public class ActionBar {
}
private String getCraftPlayerClasspath() {
return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer";
return "org.bukkit.craftbukkit." + version.name() + ".entity.CraftPlayer";
}
private String getPlayerConnectionClasspath() {
return "net.minecraft.server." + version + ".PlayerConnection";
return "net.minecraft.server." + version.name() + ".PlayerConnection";
}
private String getNMSPlayerClasspath() {
return "net.minecraft.server." + version + ".EntityPlayer";
return "net.minecraft.server." + version.name() + ".EntityPlayer";
}
private String getPacketClasspath() {
return "net.minecraft.server." + version + ".Packet";
return "net.minecraft.server." + version.name() + ".Packet";
}
private String getIChatBaseComponentClasspath() {
return "net.minecraft.server." + version + ".IChatBaseComponent";
return "net.minecraft.server." + version.name() + ".IChatBaseComponent";
}
private String getChatSerializerClasspath() {
if (cleanVersion < 1820)
return "net.minecraft.server." + version + ".ChatSerializer";
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
if (!Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R2))
return "net.minecraft.server." + version.name() + ".ChatSerializer";
return "net.minecraft.server." + version.name() + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
}
private String getPacketPlayOutChat() {
return "net.minecraft.server." + version + ".PacketPlayOutChat";
return "net.minecraft.server." + version.name() + ".PacketPlayOutChat";
}
private String getChatMessageTypeClasspath() {
return "net.minecraft.server." + version.name() + ".ChatMessageType";
}
}

View File

@ -0,0 +1,144 @@
package com.gamingmesh.jobs.stuff;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
public class VersionChecker {
Jobs plugin;
private int resource = 4216;
public VersionChecker(Jobs plugin) {
this.plugin = plugin;
version = getCurrent();
}
private Version version = Version.v1_11_R1;
public Version getVersion() {
return version;
}
public enum Version {
v1_7_R1(),
v1_7_R2(),
v1_7_R3(),
v1_7_R4(),
v1_8_R1(),
v1_8_R2(),
v1_8_R3(),
v1_9_R1(),
v1_9_R2(),
v1_10_R1(),
v1_11_R1(),
v1_11_R2(),
v1_11_R3(),
v1_12_R1(),
v1_12_R2(),
v1_12_R3(),
v1_13_R1(),
v1_13_R2(),
v1_13_R3();
private Integer value = null;
private String shortVersion = null;
public Integer getValue() {
if (value == null)
try {
value = Integer.valueOf(this.name().replaceAll("[^\\d.]", ""));
} catch (Exception e) {
}
return this.value;
}
public String getShortVersion() {
if (shortVersion == null)
shortVersion = this.name().split("_R")[0];
return shortVersion;
}
public boolean isHigher(Version version) {
return getValue() > version.getValue();
}
public boolean isLower(Version version) {
return getValue() < version.getValue();
}
}
public static Version getCurrent() {
String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
String vv = v[v.length - 1];
for (Version one : Version.values()) {
if (one.name().equalsIgnoreCase(vv)) {
return one;
}
}
return null;
}
public boolean isLower(Version version) {
return this.version.getValue() < version.getValue();
}
public boolean isLowerEquals(Version version) {
return this.version.getValue() <= version.getValue();
}
public boolean isHigher(Version version) {
return this.version.getValue() > version.getValue();
}
public boolean isHigherEquals(Version version) {
return this.version.getValue() >= version.getValue();
}
public void VersionCheck(final Player player) {
if (!Jobs.getGCManager().isShowNewVersion())
return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
String currentVersion = plugin.getDescription().getVersion();
String newVersion = getNewVersion();
if (newVersion == null || newVersion.equalsIgnoreCase(currentVersion))
return;
List<String> msg = Arrays.asList(
ChatColor.GREEN + "*********************** " + plugin.getDescription().getName() + " **************************",
ChatColor.GREEN + "* " + newVersion + " is now available! Your version: " + currentVersion,
ChatColor.GREEN + "* " + ChatColor.DARK_GREEN + plugin.getDescription().getWebsite(),
ChatColor.GREEN + "************************************************************");
for (String one : msg)
if (player != null)
player.sendMessage(one);
}
});
}
public String getNewVersion() {
try {
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + resource).getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 9)
return version;
} catch (Exception ex) {
plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Failed to check for " + plugin.getDescription().getName() + " update on spigot web page.");
}
return null;
}
}

View File

@ -1,7 +1,8 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.Jobs
version: 3.9.0
version: 3.9.2
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
author: phrstbrn
softdepend: [Vault, iConomy, MythicMobs, McMMO]
commands: