Skip to content

Commit

Permalink
version 2.2 release, many fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueTree242 committed Feb 16, 2022
2 parents ad164ba + 594d92f commit c82afb9
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 70 deletions.
5 changes: 1 addition & 4 deletions Bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ dependencies {

test {
useJUnitPlatform()
}

java.sourceCompatibility = JavaVersion.VERSION_1_9
java.targetCompatibility = JavaVersion.VERSION_1_9
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void onEnable() {
getProxy().getPluginManager().registerListener(this, new EventListener(this));
ProxyServer.getInstance().getPluginManager().registerCommand(this, new AdvancedPlHideCommand(this));
new Metrics(this, 13709);
ProxyServer.getInstance().getConsole().sendMessage(ChatColor.translateAlternateColorCodes('&', Constants.startupMessage()));
performStartUpdateCheck();
}

Expand Down Expand Up @@ -177,6 +178,11 @@ public String getVersionConfig() {
throw new UncheckedIOException(e);
}
}

@Override
public Type getType() {
return Type.BUNGEE;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import tk.bluetree242.advancedplhide.impl.completer.SuggestionCommandCompleterList;
import tk.bluetree242.advancedplhide.impl.subcompleter.SuggestionSubCommandCompleterList;
import tk.bluetree242.advancedplhide.utils.Constants;
import tk.bluetree242.advancedplhide.utils.MultiMap;
import tk.bluetree242.advancedplhide.utils.UsedMap;

import java.util.UUID;

public class PacketListener extends AbstractPacketListener<TabCompleteResponse> {
private final MultiMap<UUID, String> commandsWaiting = new MultiMap<>();
private final UsedMap<UUID, String> commandsWaiting = new UsedMap<>();
private final AdvancedPlHideBungee core;

public PacketListener(AdvancedPlHideBungee core) {
Expand Down Expand Up @@ -79,6 +79,7 @@ public void packetSend(PacketSendEvent<TabCompleteResponse> e) {
}else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
StringSubCommandCompleterList list = new StringSubCommandCompleterList(packet.getCommands(), notCompleted);
CompleterModifier.handleSubCompleter(list, AdvancedPlHideBungee.getGroupForPlayer(player), player.hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (list.isCancelled()) e.cancelled(true);
}
} else {
if (!notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
Expand All @@ -87,6 +88,7 @@ public void packetSend(PacketSendEvent<TabCompleteResponse> e) {
}else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")){
SuggestionSubCommandCompleterList suggestions = new SuggestionSubCommandCompleterList(e.packet().getSuggestions(), notCompleted);
CompleterModifier.handleSubCompleter(suggestions, AdvancedPlHideBungee.getGroupForPlayer(player), player.hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (suggestions.isCancelled()) e.cancelled(true);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@

### Requirements

* Java 11 or higher (For Velocity)
* Java 9 or higher (Bungee and spigot)
* Java 11 or higher
* ProtocolLib (Spigot)
* Protocolize (Proxy)
* Luckperms or some other perm plugin
Expand Down
4 changes: 0 additions & 4 deletions Spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@ test {
useJUnitPlatform()
}


java.sourceCompatibility = JavaVersion.VERSION_1_9
java.targetCompatibility = JavaVersion.VERSION_1_9

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void onEnable() {
getServer().getPluginCommand("advancedplhide").setExecutor(new AdvancedPlHideCommand(this));
getServer().getPluginCommand("advancedplhide").setTabCompleter(new AdvancedPlHideCommand.TabCompleter());
new Metrics(this, 13707);
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', Constants.startupMessage()));
performStartUpdateCheck();
}

Expand All @@ -107,7 +108,8 @@ public void performStartUpdateCheck() {
if (result == null) {
getLogger().severe("Could not check for updates");
return;
} String msg = result.getVersionsBehind() == 0 ?
}
String msg = result.getVersionsBehind() == 0 ?
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_UP_TO_DATE) :
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "")
.replace("{download}", result.getUpdateUrl()));
Expand Down Expand Up @@ -218,6 +220,11 @@ public String getVersionConfig() {
throw new UncheckedIOException(e);
}
}

@Override
public Type getType() {
return Type.SPIGOT;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
Bukkit.getScheduler().runTask(core, () -> {
UpdateCheckResult result = Platform.get().get().updateCheck();
if (result == null) return;
String msg = result.getVersionsBehind() == 0 ? null : ChatColor.translateAlternateColorCodes('&', "&e[APH-&2Velocity&e] " + Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "").replace("{download}", result.getUpdateUrl()));
String msg = result.getVersionsBehind() == 0 ? null : ChatColor.translateAlternateColorCodes('&', "&e[APH-&2Spigot&e] " + Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "").replace("{download}", result.getUpdateUrl()));
if (result.getMessage() != null) {
msg = ChatColor.translateAlternateColorCodes('&', "&e[APH-&2Spigot&e] &c" + result.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
import tk.bluetree242.advancedplhide.spigot.impl.completer.StringCommandCompleterList;
import tk.bluetree242.advancedplhide.spigot.impl.subcompleter.StringSubCommandCompleterList;
import tk.bluetree242.advancedplhide.utils.Constants;
import tk.bluetree242.advancedplhide.utils.MultiMap;
import tk.bluetree242.advancedplhide.utils.UsedMap;

import java.util.UUID;

public class PacketListener extends PacketAdapter {

private final MultiMap<UUID, String> commandsWaiting = new MultiMap<>();
private final UsedMap<UUID, String> commandsWaiting = new UsedMap<>();
private AdvancedPlHideSpigot core;

public PacketListener(AdvancedPlHideSpigot core) {
Expand All @@ -65,6 +65,7 @@ private void onTabcomplete(PacketEvent e) {
StructureModifier<Suggestions> matchModifier = e.getPacket().getSpecificModifier(Suggestions.class);
Suggestions suggestionsOrigin = matchModifier.read(0);
String notCompleted = this.commandsWaiting.get(e.getPlayer().getUniqueId());
commandsWaiting.remove(e.getPlayer().getUniqueId());
if (notCompleted == null) notCompleted = "/";
if (!notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
SuggestionCommandCompleterList suggestions = new SuggestionCommandCompleterList(suggestionsOrigin);
Expand All @@ -73,6 +74,7 @@ private void onTabcomplete(PacketEvent e) {
} else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")){
SuggestionSubCommandCompleterList suggestions = new SuggestionSubCommandCompleterList(suggestionsOrigin, notCompleted);
CompleterModifier.handleSubCompleter(suggestions, AdvancedPlHideSpigot.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (suggestions.isCancelled()) e.setCancelled(true);
matchModifier.write(0, suggestions.export());
}

Expand All @@ -91,6 +93,7 @@ private void onTabcomplete(PacketEvent e) {
} else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
StringSubCommandCompleterList suggestions = new StringSubCommandCompleterList(suggestionsOrigin, notCompleted);
CompleterModifier.handleSubCompleter(suggestions, AdvancedPlHideSpigot.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (suggestions.isCancelled()) e.setCancelled(true);
matchModifier.write(0, suggestions.export());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public String getVersionConfig() {
}
}

@Override
public Type getType() {
return Type.VELOCITY;
}

public List<Group> getGroups() {
return groups;
}
Expand All @@ -151,6 +156,7 @@ public void onProxyInitialization(ProxyInitializeEvent e) {
server.getEventManager().register(this, new EventListener());
Protocolize.listenerProvider().registerListener(new PacketListener(this));
metricsFactory.make(this, 13708);
server.getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacy('&').deserialize(Constants.startupMessage()));
performStartUpdateCheck();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
import dev.simplix.protocolize.api.listener.PacketSendEvent;
import tk.bluetree242.advancedplhide.CompleterModifier;
import tk.bluetree242.advancedplhide.utils.Constants;
import tk.bluetree242.advancedplhide.utils.MultiMap;
import tk.bluetree242.advancedplhide.utils.UsedMap;
import tk.bluetree242.advancedplhide.velocity.AdvancedPlHideVelocity;
import tk.bluetree242.advancedplhide.velocity.impl.completer.OfferCompleterList;
import tk.bluetree242.advancedplhide.velocity.impl.subcompleter.OfferSubCommandCompleterList;

import java.util.UUID;

public class PacketListener extends AbstractPacketListener<TabCompleteResponse> {
private final MultiMap<UUID, String> commandsWaiting = new MultiMap<>();
private final UsedMap<UUID, String> commandsWaiting = new UsedMap<>();
private final AdvancedPlHideVelocity core;

public PacketListener(AdvancedPlHideVelocity core) {
Expand Down Expand Up @@ -73,6 +73,7 @@ public void packetSend(PacketSendEvent<TabCompleteResponse> e) {
}else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
OfferSubCommandCompleterList list = new OfferSubCommandCompleterList(e.packet().getOffers(), notCompleted);
CompleterModifier.handleSubCompleter(list, AdvancedPlHideVelocity.getGroupForPlayer(player), player.hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (list.isCancelled()) e.cancelled(true);
}
} else {
if ((!notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) ) {
Expand All @@ -81,6 +82,7 @@ public void packetSend(PacketSendEvent<TabCompleteResponse> e) {
}else if (notCompleted.contains(" ") && notCompleted.trim().startsWith("/")) {
OfferSubCommandCompleterList list = new OfferSubCommandCompleterList(e.packet().getOffers(), notCompleted);
CompleterModifier.handleSubCompleter(list, AdvancedPlHideVelocity.getGroupForPlayer(player), player.hasPermission(Constants.SUB_WHITELIST_MODE_PERMISSION));
if (list.isCancelled()) e.cancelled(true);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ subprojects {
project.jar {
archivesBaseName = 'AdvancedPlHide-' + project.name
}
dependencies {
compile 'org.jetbrains:annotations:16.0.2'
}
project.processResources {
from(sourceSets.main.resources.srcDirs) {
filter ReplaceTokens, tokens: [version : version,
Expand All @@ -57,6 +60,7 @@ subprojects {
shadowJar {
classifier ''
}

dependencies {
implementation project(":Spigot")
implementation project(":Velocity")
Expand Down
5 changes: 0 additions & 5 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ dependencies {
implementation 'space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.0-M2'
compileOnly 'com.mojang:brigadier:1.0.18'
implementation group: 'org.json', name: 'json', version: '20210307'
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
implementation("com.squareup.okhttp3:okhttp")
}


test {
useJUnitPlatform()
}

java.sourceCompatibility = JavaVersion.VERSION_1_9
java.targetCompatibility = JavaVersion.VERSION_1_9
36 changes: 23 additions & 13 deletions core/src/main/java/tk/bluetree242/advancedplhide/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@

package tk.bluetree242.advancedplhide;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONObject;
import tk.bluetree242.advancedplhide.config.Config;
import tk.bluetree242.advancedplhide.exceptions.ConfigurationLoadException;
import tk.bluetree242.advancedplhide.impl.version.UpdateCheckResult;
import tk.bluetree242.advancedplhide.utils.HttpPostMultipart;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -95,20 +92,33 @@ public String getBuildDate() {

public UpdateCheckResult updateCheck() {
try {
OkHttpClient client = new OkHttpClient();
Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", "APH/Java");
MultipartBody form = new MultipartBody.Builder().setType(MediaType.get("multipart/form-data"))
.addFormDataPart("version", getCurrentVersion())
.addFormDataPart("buildNumber", getCurrentBuild())
.addFormDataPart("buildDate", getCurrentBuild())
.addFormDataPart("devUpdatechecker", getConfig().dev_updatechecker() + "").build();
Request req = new Request.Builder().url("https://advancedplhide.ml/updatecheck").post(form).build();
String response = client.newCall(req).execute().body().string();
HttpPostMultipart req = new HttpPostMultipart("https://advancedplhide.ml/updatecheck", "utf-8", headers);
req.addFormField("version", getCurrentVersion());
req.addFormField("buildNumber", getCurrentBuild());
req.addFormField("buildDate", getBuildDate());
req.addFormField("devUpdatechecker", getConfig().dev_updatechecker() + "");
String response = req.finish();
JSONObject json = new JSONObject(response);
return new UpdateCheckResult(json.getInt("versions_behind"), json.isNull("versions_behind") ? null : json.isNull("message") ? null : json.getString("message"), json.isNull("type") ? "INFO" : json.getString("type"), json.getString("downloadUrl"));
return new UpdateCheckResult(json.getInt("versions_behind"), json.isNull("versions_behind") ? null : json.getString("message"), json.isNull("type") ? "INFO" : json.getString("type"), json.getString("downloadUrl"));
} catch (Exception e) {
return null;
}
}

public abstract Type getType();

public enum Type {
SPIGOT("Spigot"), VELOCITY("Velocity"), BUNGEE("Bungee");
private final String name;

Type(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public void removeAll() {
}
}

/**
* Checks if the packet (or event) should be cancelled
* @return if this should be cancelled, currently true only when list is empty
* @throws IllegalStateException if this isn't supposed to be for a cancellable event/packet
*/
public boolean isCancelled() {
return isEmpty();
}

/**
* Never use this method, most likely won't affect the list final result
* @deprecated 90% won't affect the list final result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@

package tk.bluetree242.advancedplhide.utils;

import tk.bluetree242.advancedplhide.Platform;

public class Constants {
public static final String DEFAULT_UP_TO_DATE = "&aYou are up to date";
public static final String DEFAULT_BEHIND = "&cYou are {versions} Behind. Please Update ASAP. Download from {download}";
public static final String WHITELIST_MODE_PERMISSION = "plhide.whitelist-mode";
public static final String SUB_WHITELIST_MODE_PERMISSION = "plhide.sub-whitelist-mode";

public static String startupMessage() {
return "" +
"\n[]=====[&2Enabling AdvancedPlHide&r]=====[]\n" +
"| &cInformation:\n&r" +
"| &cName: &rAdvancedPlHide\n&r" +
"| &cDevelopers: &rBlueTree242\n&r" +
"| &cVersion: &r" + Platform.get().getCurrentVersion() + "\n&r" +
"| &cRunning on: &r" + Platform.get().getType().getName() + "\n&r" +
"| &cSupport:\n&r" +
"| &cGithub: &rhttps://github.com/BlueTree242/AdvancedPlHide/issues\n" +
"| &cDiscord: &rhttps://advancedplhide.ml/support\n" +
"[]================================[]";
}
}
Loading

0 comments on commit c82afb9

Please sign in to comment.