mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
1.12 support and new version checker
This commit is contained in:
parent
77d03db7b5
commit
3f71080b02
5
pom.xml
5
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>Jobs</groupId>
|
<groupId>Jobs</groupId>
|
||||||
<artifactId>jobs</artifactId>
|
<artifactId>jobs</artifactId>
|
||||||
<version>3.9.0</version>
|
<version>3.9.2</version>
|
||||||
<name>Jobs</name>
|
<name>Jobs</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<properties>
|
<properties>
|
||||||
@ -118,6 +118,9 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.3.1</version>
|
<version>2.3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>C:\Users\Arte\Desktop\Server\plugins</outputDirectory>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
@ -88,6 +88,7 @@ import com.gamingmesh.jobs.stuff.Debug;
|
|||||||
import com.gamingmesh.jobs.stuff.JobsClassLoader;
|
import com.gamingmesh.jobs.stuff.JobsClassLoader;
|
||||||
import com.gamingmesh.jobs.stuff.Loging;
|
import com.gamingmesh.jobs.stuff.Loging;
|
||||||
import com.gamingmesh.jobs.stuff.TabComplete;
|
import com.gamingmesh.jobs.stuff.TabComplete;
|
||||||
|
import com.gamingmesh.jobs.stuff.VersionChecker;
|
||||||
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
||||||
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
||||||
|
|
||||||
@ -145,6 +146,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
private static ActionBar actionbar;
|
private static ActionBar actionbar;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
|
|
||||||
|
protected static VersionChecker versionCheckManager;
|
||||||
|
|
||||||
protected static SelectionManager smanager;
|
protected static SelectionManager smanager;
|
||||||
|
|
||||||
public void setMcMMOlistener() {
|
public void setMcMMOlistener() {
|
||||||
@ -686,12 +689,21 @@ public class Jobs extends JavaPlugin {
|
|||||||
return economy;
|
return economy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the version check manager
|
||||||
|
* @return the version check manager
|
||||||
|
*/
|
||||||
|
public static VersionChecker getVersionCheckManager() {
|
||||||
|
return versionCheckManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
running = true;
|
running = true;
|
||||||
String packageName = getServer().getClass().getPackage().getName();
|
|
||||||
String[] packageSplit = packageName.split("\\.");
|
versionCheckManager = new VersionChecker(this);
|
||||||
version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
|
version = versionCheckManager.getVersion().getShortVersion();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> nmsClass;
|
Class<?> nmsClass;
|
||||||
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
|
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
|
||||||
@ -710,6 +722,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
setActionBar();
|
setActionBar();
|
||||||
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
||||||
jobConfig.saveDefaultConfig();
|
jobConfig.saveDefaultConfig();
|
||||||
|
@ -18,6 +18,7 @@ import com.gamingmesh.jobs.container.BossBarInfo;
|
|||||||
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.VersionChecker.Version;
|
||||||
|
|
||||||
public class BossBarManager {
|
public class BossBarManager {
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ public class BossBarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void ShowJobProgression(final JobsPlayer player) {
|
public synchronized void ShowJobProgression(final JobsPlayer player) {
|
||||||
if (Jobs.getActionBar().getVersion() < 1900)
|
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
@ -48,7 +49,7 @@ public class BossBarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg) {
|
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;
|
return;
|
||||||
String playername = player.getUserName();
|
String playername = player.getUserName();
|
||||||
if (!Jobs.getBossBarToggleList().containsKey(playername) && Jobs.getGCManager().BossBarsMessageByDefault)
|
if (!Jobs.getBossBarToggleList().containsKey(playername) && Jobs.getGCManager().BossBarsMessageByDefault)
|
||||||
|
@ -42,6 +42,7 @@ import com.gamingmesh.jobs.container.Schedule;
|
|||||||
import com.gamingmesh.jobs.dao.JobsDAOMySQL;
|
import com.gamingmesh.jobs.dao.JobsDAOMySQL;
|
||||||
import com.gamingmesh.jobs.dao.JobsDAOSQLite;
|
import com.gamingmesh.jobs.dao.JobsDAOSQLite;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
|
||||||
|
|
||||||
public class GeneralConfigManager {
|
public class GeneralConfigManager {
|
||||||
private Jobs plugin;
|
private Jobs plugin;
|
||||||
@ -144,6 +145,8 @@ public class GeneralConfigManager {
|
|||||||
public boolean DBCleaningUsersUse;
|
public boolean DBCleaningUsersUse;
|
||||||
public int DBCleaningUsersDays;
|
public int DBCleaningUsersDays;
|
||||||
|
|
||||||
|
private boolean ShowNewVersion;
|
||||||
|
|
||||||
public HashMap<String, List<String>> getCommandArgs() {
|
public HashMap<String, List<String>> getCommandArgs() {
|
||||||
return commandArgs;
|
return commandArgs;
|
||||||
}
|
}
|
||||||
@ -438,6 +441,10 @@ public class GeneralConfigManager {
|
|||||||
if (MultiServerCompatability)
|
if (MultiServerCompatability)
|
||||||
saveOnDisconnect = true;
|
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",
|
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",
|
"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",
|
"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);
|
modifyChat = c.get("modify-chat", true);
|
||||||
|
|
||||||
modifyChatPrefix = c.get("modify-chat-prefix", "&c[", 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);
|
modifyChatSeparator = c.get("modify-chat-separator", " ", true);
|
||||||
|
|
||||||
c.getW().addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names",
|
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");
|
c.getW().addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version");
|
||||||
BossBarEnabled = c.get("BossBar.Enabled", true);
|
BossBarEnabled = c.get("BossBar.Enabled", true);
|
||||||
|
|
||||||
if (Jobs.getActionBar().getVersion() < 1900) {
|
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) {
|
||||||
BossBarEnabled = false;
|
BossBarEnabled = false;
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Jobs] Your server version don't support BossBar. This feature will be disabled");
|
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() {
|
public int getSelectionTooldID() {
|
||||||
return getSelectionTooldID;
|
return getSelectionTooldID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isShowNewVersion() {
|
||||||
|
return ShowNewVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.api.JobsPaymentEvent;
|
import com.gamingmesh.jobs.api.JobsPaymentEvent;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
|
||||||
import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
|
import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
|
||||||
|
|
||||||
public class BufferedEconomy {
|
public class BufferedEconomy {
|
||||||
@ -193,7 +194,7 @@ public class BufferedEconomy {
|
|||||||
try {
|
try {
|
||||||
// Action bar stuff
|
// Action bar stuff
|
||||||
Jobs.getActionBar().ShowActionBar(payment);
|
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());
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId());
|
||||||
Jobs.getBBManager().ShowJobProgression(jPlayer);
|
Jobs.getBBManager().ShowJobProgression(jPlayer);
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,12 @@ public class JobsListener implements Listener {
|
|||||||
return false;
|
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)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onSelection(PlayerInteractEvent event) {
|
public void onSelection(PlayerInteractEvent event) {
|
||||||
if (event.getPlayer() == null)
|
if (event.getPlayer() == null)
|
||||||
|
39
src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java
Normal file
39
src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,14 +12,14 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.economy.BufferedPayment;
|
import com.gamingmesh.jobs.economy.BufferedPayment;
|
||||||
|
import com.gamingmesh.jobs.stuff.VersionChecker.Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author hamzaxx
|
* @author hamzaxx
|
||||||
*/
|
*/
|
||||||
public class ActionBar {
|
public class ActionBar {
|
||||||
private int cleanVersion = -1;
|
private Version version = Version.v1_11_R1;
|
||||||
private String version = "";
|
|
||||||
private Object packet;
|
private Object packet;
|
||||||
private Method getHandle;
|
private Method getHandle;
|
||||||
private Method sendPacket;
|
private Method sendPacket;
|
||||||
@ -28,49 +28,13 @@ public class ActionBar {
|
|||||||
private Class<?> nmsIChatBaseComponent;
|
private Class<?> nmsIChatBaseComponent;
|
||||||
private Class<?> packetType;
|
private Class<?> packetType;
|
||||||
|
|
||||||
public int getVersion() {
|
private Class<?> ChatMessageclz;
|
||||||
if (cleanVersion == -1)
|
private Class<?> sub;
|
||||||
getInfo();
|
private Object[] consts;
|
||||||
return cleanVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getInfo() {
|
public ActionBar() {
|
||||||
try {
|
try {
|
||||||
String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
|
version = Jobs.getVersionCheckManager().getVersion();
|
||||||
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;
|
|
||||||
|
|
||||||
packetType = Class.forName(getPacketPlayOutChat());
|
packetType = Class.forName(getPacketPlayOutChat());
|
||||||
Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
|
Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
|
||||||
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
|
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
|
||||||
@ -81,17 +45,21 @@ public class ActionBar {
|
|||||||
playerConnection = typeNMSPlayer.getField("playerConnection");
|
playerConnection = typeNMSPlayer.getField("playerConnection");
|
||||||
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath()));
|
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) {
|
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
|
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowActionBar(BufferedPayment payment) {
|
public void ShowActionBar(BufferedPayment payment) {
|
||||||
|
|
||||||
if (cleanVersion == -1)
|
if (!payment.getOfflinePlayer().isOnline())
|
||||||
getInfo();
|
|
||||||
|
|
||||||
if (cleanVersion == -1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String playername = payment.getOfflinePlayer().getName();
|
String playername = payment.getOfflinePlayer().getName();
|
||||||
@ -110,31 +78,15 @@ public class ActionBar {
|
|||||||
if (abp != null && show) {
|
if (abp != null && show) {
|
||||||
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
|
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
|
||||||
if (payment.getAmount() != 0D)
|
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)
|
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)
|
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);
|
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) {
|
public void send(CommandSender receivingPacket, String msg) {
|
||||||
try {
|
try {
|
||||||
if (msg == null || nmsChatSerializer == null || msg.isEmpty())
|
if (msg == null || nmsChatSerializer == null || msg.isEmpty())
|
||||||
@ -143,13 +95,15 @@ public class ActionBar {
|
|||||||
if (receivingPacket == null)
|
if (receivingPacket == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cleanVersion < 1800 || !(receivingPacket instanceof Player)) {
|
if (version.isLower(Version.v1_8_R1) || !(receivingPacket instanceof Player)) {
|
||||||
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}");
|
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);
|
packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2);
|
||||||
} else {
|
} else {
|
||||||
packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2);
|
packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2);
|
||||||
@ -163,32 +117,36 @@ public class ActionBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCraftPlayerClasspath() {
|
private String getCraftPlayerClasspath() {
|
||||||
return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer";
|
return "org.bukkit.craftbukkit." + version.name() + ".entity.CraftPlayer";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlayerConnectionClasspath() {
|
private String getPlayerConnectionClasspath() {
|
||||||
return "net.minecraft.server." + version + ".PlayerConnection";
|
return "net.minecraft.server." + version.name() + ".PlayerConnection";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNMSPlayerClasspath() {
|
private String getNMSPlayerClasspath() {
|
||||||
return "net.minecraft.server." + version + ".EntityPlayer";
|
return "net.minecraft.server." + version.name() + ".EntityPlayer";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPacketClasspath() {
|
private String getPacketClasspath() {
|
||||||
return "net.minecraft.server." + version + ".Packet";
|
return "net.minecraft.server." + version.name() + ".Packet";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIChatBaseComponentClasspath() {
|
private String getIChatBaseComponentClasspath() {
|
||||||
return "net.minecraft.server." + version + ".IChatBaseComponent";
|
return "net.minecraft.server." + version.name() + ".IChatBaseComponent";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getChatSerializerClasspath() {
|
private String getChatSerializerClasspath() {
|
||||||
if (cleanVersion < 1820)
|
if (!Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R2))
|
||||||
return "net.minecraft.server." + version + ".ChatSerializer";
|
return "net.minecraft.server." + version.name() + ".ChatSerializer";
|
||||||
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
|
return "net.minecraft.server." + version.name() + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPacketPlayOutChat() {
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
144
src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java
Normal file
144
src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
name: Jobs
|
name: Jobs
|
||||||
description: Jobs Plugin for the BukkitAPI
|
description: Jobs Plugin for the BukkitAPI
|
||||||
main: com.gamingmesh.jobs.Jobs
|
main: com.gamingmesh.jobs.Jobs
|
||||||
version: 3.9.0
|
version: 3.9.2
|
||||||
|
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
|
||||||
author: phrstbrn
|
author: phrstbrn
|
||||||
softdepend: [Vault, iConomy, MythicMobs, McMMO]
|
softdepend: [Vault, iConomy, MythicMobs, McMMO]
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user