Skip to content

Commit 788220a

Browse files
committed
🚧 Working on v0.4.4
- Some people are having issue with the ignoreFilter packet metadata looking into that. 🐛 - Updated the UpdateChecker to now support a new PluginVersion enum class, this way its more in depth and advanced. 🎨 - Added logging points, so now the plugin is more in depth when loading. ✨
1 parent 6c67586 commit 788220a

File tree

13 files changed

+170
-58
lines changed

13 files changed

+170
-58
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.azortis</groupId>
88
<artifactId>protocolvanish</artifactId>
99
<packaging>jar</packaging>
10-
<version>0.4.3-SNAPSHOT</version>
10+
<version>0.4.4-SNAPSHOT</version>
1111

1212
<properties>
1313
<maven.compiler.source>1.8</maven.compiler.source>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Hides you completely from players on your servers by using packets!
3+
* Copyright (C) 2019 Azortis
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.azortis.protocolvanish;
20+
21+
public enum PluginVersion {
22+
v0_4_3("0.4.3", 43, "1.0.0", "1.0.0"),
23+
v0_4_4("0.4.4", 44, "1.0.0", "1.0.0");
24+
25+
private String versionString;
26+
private int versionNumber;
27+
private String settingsFileVersion;
28+
private String messageFileVersion;
29+
30+
PluginVersion(String versionString, int versionNumber, String settingsFileVersion, String messageFileVersion){
31+
this.versionString = versionString;
32+
this.versionNumber = versionNumber;
33+
this.settingsFileVersion = settingsFileVersion;
34+
this.messageFileVersion = messageFileVersion;
35+
}
36+
37+
public boolean isNewerThen(PluginVersion pluginVersion){
38+
return this.versionNumber > pluginVersion.versionNumber;
39+
}
40+
41+
public boolean isSame(PluginVersion pluginVersion){
42+
return this.versionNumber == pluginVersion.versionNumber;
43+
}
44+
45+
public String getVersionString(){
46+
return versionString;
47+
}
48+
49+
public String getSettingsFileVersion() {
50+
return settingsFileVersion;
51+
}
52+
53+
public String getMessageFileVersion() {
54+
return messageFileVersion;
55+
}
56+
57+
public static PluginVersion getVersionFromString(String versionString){
58+
return PluginVersion.valueOf("v" + versionString.replace(".", "_"));
59+
}
60+
61+
}

src/main/java/com/azortis/protocolvanish/ProtocolVanish.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public final class ProtocolVanish extends JavaPlugin {
4040
private PermissionManager permissionManager;
4141
private VisibilityManager visibilityManager;
4242
private StorageManager storageManager;
43+
private UpdateChecker updateChecker;
4344

4445
private VanishCommand vanishCommand;
4546

@@ -57,29 +58,39 @@ public void onEnable() {
5758
Bukkit.getServer().getPluginManager().disablePlugin(this);
5859
return;
5960
}
60-
this.metrics = new Metrics(this);
61+
this.updateChecker = new UpdateChecker(this);
6162
this.settingsManager = new SettingsManager(this);
63+
if(!settingsManager.areFilesUpToDate())return;
64+
65+
this.metrics = new Metrics(this);
6266
this.storageManager = new StorageManager(this);
6367
this.permissionManager = new PermissionManager(this);
6468
this.visibilityManager = new VisibilityManager(this);
65-
6669
this.vanishCommand = new VanishCommand(this);
6770

71+
this.getLogger().info("Registering events...");
6872
new PlayerLoginListener(this);
6973
new PlayerJoinListener(this);
7074
new PlayerQuitListener(this);
7175
new EntityDamageListener(this);
7276
new FoodLevelChangeListener(this);
7377
new EntityTargetLivingEntityListener(this);
7478
new EntityPickupItemListener(this);
75-
new UpdateChecker(this).fetch();
7679

7780
VanishAPI.setPlugin(this);
7881
}
7982

8083
@Override
8184
public void onDisable() {
85+
this.getLogger().info("Saving vanish players...");
86+
for (VanishPlayer vanishPlayer : vanishPlayerMap.values()){
87+
storageManager.saveVanishPlayer(vanishPlayer);
88+
storageManager.savePlayerSettings(vanishPlayer.getPlayerSettings());
89+
}
90+
}
8291

92+
public UpdateChecker getUpdateChecker(){
93+
return updateChecker;
8394
}
8495

8596
public Metrics getMetrics() {

src/main/java/com/azortis/protocolvanish/UpdateChecker.java

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,63 +33,72 @@
3333
public class UpdateChecker implements Listener {
3434

3535
private final ProtocolVanish plugin;
36-
private final int RESOURCE_ID = 69445;
37-
private String spigotVersion;
38-
private final String pluginVersion;
36+
private PluginVersion spigotVersion;
37+
private final PluginVersion pluginVersion;
3938
private boolean updateAvailable;
39+
private boolean unreleased;
4040

41-
UpdateChecker(ProtocolVanish plugin){
41+
UpdateChecker(ProtocolVanish plugin) {
4242
this.plugin = plugin;
43-
this.pluginVersion = plugin.getDescription().getVersion();
44-
}
43+
this.pluginVersion = PluginVersion.valueOf(plugin.getDescription().getVersion());
4544

46-
public boolean isUpdateAvailable() {
47-
return updateAvailable;
45+
//Grab version
46+
plugin.getLogger().info("Checking for updates...");
47+
try {
48+
HttpsURLConnection connection = (HttpsURLConnection) new URL(
49+
"https://api.spigotmc.org/legacy/update.php?resource=69445").openConnection();
50+
connection.setRequestMethod("GET");
51+
spigotVersion = PluginVersion.getVersionFromString(new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine());
52+
} catch (Exception ex) {
53+
plugin.getLogger().severe("Failed to check for updates on spigot.");
54+
}
55+
if(spigotVersion == null){
56+
plugin.getLogger().severe("Failed to check for updates on spigot.");
57+
return;
58+
}
59+
if (pluginVersion.isSame(spigotVersion)) return;
60+
61+
this.updateAvailable = spigotVersion.isNewerThen(pluginVersion);
62+
if (updateAvailable) {
63+
plugin.getLogger().info("A new version(" + spigotVersion.getVersionString() + ") is available on spigot!");
64+
plugin.getLogger().info("You can download it here: https://www.spigotmc.org/resources/69445/");
65+
Bukkit.getPluginManager().registerEvents(this, plugin);
66+
return;
67+
}
68+
69+
this.unreleased = pluginVersion.isNewerThen(spigotVersion);
70+
if (unreleased) {
71+
plugin.getLogger().warning("You're using an unreleased version(" + pluginVersion.getVersionString() + "). Please proceed with caution.");
72+
Bukkit.getPluginManager().registerEvents(this, plugin);
73+
}
4874
}
4975

50-
public String getSpigotVersion() {
76+
public PluginVersion getSpigotVersion() {
5177
return spigotVersion;
5278
}
5379

54-
public void fetch(){
55-
Bukkit.getScheduler().runTaskAsynchronously(plugin, ()-> {
56-
try {
57-
HttpsURLConnection connection = (HttpsURLConnection) new URL(
58-
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
59-
connection.setRequestMethod("GET");
60-
spigotVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
61-
}catch (Exception ex){
62-
plugin.getLogger().info("Failed to check for updates on spigot.");
63-
}
64-
if (spigotVersion == null || spigotVersion.isEmpty()) {
65-
return;
66-
}
67-
updateAvailable = spigotIsNewer();
68-
if (!updateAvailable) {
69-
return;
70-
}
80+
public PluginVersion getPluginVersion(){
81+
return pluginVersion;
82+
}
7183

72-
Bukkit.getScheduler().runTask(plugin, ()-> {
73-
plugin.getLogger().info("A new version(" + spigotVersion + ") is available on spigot!");
74-
plugin.getLogger().info("You can download it here: https://www.spigotmc.org/resources/protocolvanish.69445/");
75-
Bukkit.getPluginManager().registerEvents(this, plugin);
76-
});
77-
});
84+
public boolean isUpdateAvailable() {
85+
return updateAvailable;
7886
}
7987

80-
private boolean spigotIsNewer() {
81-
if (spigotVersion == null || spigotVersion.isEmpty()) {
82-
return false;
83-
}
84-
return !pluginVersion.equals(spigotVersion);
88+
public boolean isUnreleased() {
89+
return unreleased;
8590
}
8691

8792
@EventHandler
88-
public void onPlayerJoin(PlayerJoinEvent event){
93+
public void onPlayerJoin(PlayerJoinEvent event) {
8994
Player player = event.getPlayer();
90-
if(plugin.getPermissionManager().hasPermission(player, PermissionManager.Permission.ADMIN)){
91-
player.sendMessage(ChatColor.GREEN + "[ProtocolVanish] A new update is available(" + spigotVersion +")");
92-
player.sendMessage(ChatColor.GREEN + "You can download it here: You can download it here: https://www.spigotmc.org/resources/protocolvanish.69445/");
95+
if (plugin.getPermissionManager().hasPermission(player, PermissionManager.Permission.ADMIN)) {
96+
if (updateAvailable) {
97+
player.sendMessage(ChatColor.GREEN + "[ProtocolVanish] A new update is available(" + spigotVersion.getVersionString() + ")");
98+
player.sendMessage(ChatColor.GREEN + "You can download it here: You can download it here: https://www.spigotmc.org/resources/69445/");
99+
} else if (unreleased) {
100+
player.sendMessage(ChatColor.RED + "[ProtocolVanish] You're using an unreleased version(" + pluginVersion.getVersionString() + "). Please proceed with caution.");
101+
}
93102
}
94103
}
95104

src/main/java/com/azortis/protocolvanish/api/VanishAPI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ public static boolean hasPermissionToSee(Player hider, Player viewer) {
6363

6464
public static void setPlugin(ProtocolVanish paramPlugin) {
6565
plugin = paramPlugin;
66+
paramPlugin.getLogger().info("Applying VanishAPI...");
6667
}
6768
}

src/main/java/com/azortis/protocolvanish/command/VanishCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class VanishCommand implements ICommandExecutor, ITabCompleter {
4747

4848
public VanishCommand(ProtocolVanish plugin) {
4949
this.plugin = plugin;
50+
plugin.getLogger().info("Loading command...");
5051
CommandSettingsWrapper commandSettings = plugin.getSettingsManager().getCommandSettings();
5152
Command command = new CommandBuilder()
5253
.setName(commandSettings.getName())

src/main/java/com/azortis/protocolvanish/settings/SettingsManager.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.azortis.protocolvanish.ProtocolVanish;
2222
import com.google.gson.Gson;
2323
import com.google.gson.GsonBuilder;
24+
import org.bukkit.Bukkit;
2425

2526
import java.io.File;
2627
import java.io.FileReader;
@@ -39,20 +40,48 @@ public class SettingsManager {
3940
private Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
4041
private Map<String, Object> settingsMap;
4142
private Map<String, Object> messageMap;
43+
private boolean filesUpToDate = true;
4244

4345
public SettingsManager(ProtocolVanish plugin) {
4446
this.plugin = plugin;
47+
plugin.getLogger().info("Loading settings...");
4548
if (plugin.getDataFolder().exists()) plugin.getDataFolder().mkdir();
4649
settingsFile = new File(plugin.getDataFolder(), "settings.json");
4750
messageFile = new File(plugin.getDataFolder(), "messages.json");
48-
if (!settingsFile.exists()) plugin.saveResource(settingsFile.getName(), false);
49-
if (!messageFile.exists()) plugin.saveResource(messageFile.getName(), false);
51+
if (!settingsFile.exists()){
52+
plugin.getLogger().info("Creating new settings file...");
53+
plugin.saveResource(settingsFile.getName(), false);
54+
}
55+
if (!messageFile.exists()){
56+
plugin.getLogger().info("Creating new message file...");
57+
plugin.saveResource(messageFile.getName(), false);
58+
}
5059
try {
5160
settingsMap = gson.fromJson(new FileReader(settingsFile), Map.class);
5261
messageMap = gson.fromJson(new FileReader(messageFile), Map.class);
5362
} catch (IOException e) {
5463
e.printStackTrace();
5564
}
65+
//Check if settingsFile is up to date!
66+
String settingsFileVersion = (String) settingsMap.get("fileVersion");
67+
if(plugin.getUpdateChecker().getPluginVersion().getSettingsFileVersion() != settingsFileVersion){
68+
plugin.getLogger().severe("Settings file is outdated, Please update it!");
69+
plugin.getLogger().severe("Disabling plugin...");
70+
Bukkit.getPluginManager().disablePlugin(plugin);
71+
filesUpToDate = false;
72+
}
73+
//Check if messageFile is up to date!
74+
String messageFileVersion = (String) settingsMap.get("fileVersion");
75+
if(plugin.getUpdateChecker().getPluginVersion().getMessageFileVersion() != messageFileVersion){
76+
plugin.getLogger().severe("Message file is outdated, Please update it!");
77+
plugin.getLogger().severe("Disabling plugin...");
78+
Bukkit.getPluginManager().disablePlugin(plugin);
79+
filesUpToDate = false;
80+
}
81+
}
82+
83+
public boolean areFilesUpToDate() {
84+
return filesUpToDate;
5685
}
5786

5887
public void saveSettingsFile() {

src/main/java/com/azortis/protocolvanish/storage/SQLiteAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ public class SQLiteAdapter implements IDatabase {
3838

3939
SQLiteAdapter(ProtocolVanish plugin) {
4040
this.plugin = plugin;
41+
plugin.getLogger().info("Loading database file...");
4142
File dbFile = new File(plugin.getDataFolder(), "storage.db");
4243
try {
4344
if (!dbFile.exists()) {
45+
plugin.getLogger().info("Database file doesn't exist, creating one...");
4446
dbFile.createNewFile();
4547
}
4648
} catch (IOException ex) {

src/main/java/com/azortis/protocolvanish/storage/StorageManager.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ public class StorageManager {
3333

3434
public StorageManager(ProtocolVanish plugin) {
3535
this.plugin = plugin;
36-
/*if(plugin.getSettingsManager().getStorageSettings().getUseMySQL()){
37-
this.adapter = new MySQLAdapter();
38-
}else{
39-
this.adapter = new SQLiteAdapter(plugin);
40-
}*/
36+
plugin.getLogger().info("Loading storage...");
37+
plugin.getLogger().info("Using SQLite..."); //Because we haven't yet added MySQL checks.
4138
this.adapter = new SQLiteAdapter(plugin);
4239
}
4340

@@ -46,8 +43,7 @@ public VanishPlayer getVanishPlayer(Player player) {
4643
VanishPlayer vanishPlayer = adapter.getVanishPlayer(player);
4744

4845
if (vanishPlayer == null) return null;
49-
if (!plugin.getPermissionManager().hasPermissionToVanish(player)
50-
&& /*!plugin.getSettingsManager().getStorageSettings().getUseMySQL()*/true) {
46+
if (!plugin.getPermissionManager().hasPermissionToVanish(player)) {
5147
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> adapter.deleteVanishPlayer(vanishPlayer));
5248
return null;
5349
}

src/main/java/com/azortis/protocolvanish/visibility/packetlisteners/GeneralEntityPacketListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void onPacketSending(PacketEvent event) {
6565
Player player = plugin.getVisibilityManager().getPlayerFromEntityID(entityId, viewer.getWorld());
6666
if (player == null) {
6767
entityIdList.add(entityId);
68-
} else if ((boolean) packet.getMeta("ignoreFilter").get()) {
68+
} else if (packet.getMeta("ignoreFilter").isPresent() && (boolean) packet.getMeta("ignoreFilter").get()) {
6969
entityIdList.add(entityId);
7070
} else if (plugin.getVisibilityManager().isVanished(player.getUniqueId()) &&
7171
!plugin.getVisibilityManager().isVanishedFrom(player, viewer)) {

0 commit comments

Comments
 (0)