Skip to content

Commit

Permalink
1.7.8 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Apr 11, 2020
1 parent f292c98 commit eb4d92c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.scheduler.BukkitRunnable;

import com.loohp.interactivechat.Updater.Updater;
import com.loohp.interactivechat.Utils.MaterialUtils;
import com.loohp.interactivechat.Utils.Updater;

import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.ChatColor;
Expand Down
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import com.loohp.interactivechat.Utils.Updater;
import com.loohp.interactivechat.Updater.Updater;

import net.md_5.bungee.api.ChatColor;

Expand Down
7 changes: 4 additions & 3 deletions src/com/loohp/interactivechat/Listeners/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void onPacketSending(PacketEvent event) {
if (component != null) {
if (component.getJson().contains("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4")) {
event.setReadOnly(false);
component.setJson(component.getJson().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", ""));
component.setJson(component.getJson().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", "").replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, ""));
packet.getChatComponents().write(0, component);
event.setReadOnly(true);
return;
Expand All @@ -210,9 +210,10 @@ public void onPacketSending(PacketEvent event) {
base = CustomStringUtils.loadExtras(Arrays.asList(basecomp));
boolean is = false;
event.setReadOnly(false);
for (BaseComponent each : base) {
for (BaseComponent each : base) {
if (each.toLegacyText().contains("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4")) {
TextComponent text = (TextComponent) each;
text.setText(text.getText().replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, ""));
text.setText(text.getText().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", ""));
is = true;
}
Expand Down Expand Up @@ -415,7 +416,7 @@ public void run () {
TextComponent removeKeyText = new TextComponent("");
for (BaseComponent each : base) {
String json = ComponentSerializer.toString(each);
json = json.replaceAll(InteractiveChat.space0, "").replaceAll(InteractiveChat.space1, "");
json = json.replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, "");
BaseComponent[] newBase = ComponentSerializer.parse(json);
for (BaseComponent eachNew : newBase) {
removeKeyText.addExtra(eachNew);
Expand Down
9 changes: 5 additions & 4 deletions src/com/loohp/interactivechat/Listeners/LegacyEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void onPacketSending(PacketEvent event) {
if (component != null) {
if (component.getJson().contains("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4")) {
event.setReadOnly(false);
component.setJson(component.getJson().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", ""));
component.setJson(component.getJson().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", "").replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, ""));
send.getChatComponents().write(0, component);
event.setReadOnly(true);
return;
Expand All @@ -213,9 +213,10 @@ public void onPacketSending(PacketEvent event) {
base = CustomStringUtils.loadExtras(Arrays.asList(basecomp));
boolean is = false;
event.setReadOnly(false);
for (BaseComponent each : base) {
for (BaseComponent each : base) {
if (each.toLegacyText().contains("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4")) {
TextComponent text = (TextComponent) each;
text.setText(text.getText().replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, ""));
text.setText(text.getText().replace("§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4§4", ""));
is = true;
}
Expand Down Expand Up @@ -419,12 +420,12 @@ public void run () {
TextComponent removeKeyText = new TextComponent("");
for (BaseComponent each : base) {
String json = ComponentSerializer.toString(each);
json = json.replaceAll(InteractiveChat.space0, "").replaceAll(InteractiveChat.space1, "");
json = json.replace(InteractiveChat.space0, "").replace(InteractiveChat.space1, "");
BaseComponent[] newBase = ComponentSerializer.parse(json);
for (BaseComponent eachNew : newBase) {
removeKeyText.addExtra(eachNew);
}
}
}
bcs = ComponentSerializer.parse(ComponentSerializer.toString(removeKeyText));
base = new ArrayList<BaseComponent>();
base = CustomStringUtils.loadExtras(Arrays.asList(bcs));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.loohp.interactivechat.Utils;
package com.loohp.interactivechat.Updater;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -52,7 +52,9 @@ public static String checkUpdate() {
try {
String localPluginVersion = InteractiveChat.plugin.getDescription().getVersion();
String spigotPluginVersion = readStringFromURL("https://api.spigotmc.org/legacy/update.php?resource=75870");
if (!spigotPluginVersion.isEmpty() && !spigotPluginVersion.equals(localPluginVersion)) {
Version current = new Version(localPluginVersion);
Version spigotmc = new Version(spigotPluginVersion);
if (!spigotPluginVersion.isEmpty() && current.compareTo(spigotmc) < 0) {
return spigotPluginVersion;
} else {
return "latest";
Expand Down
50 changes: 50 additions & 0 deletions src/com/loohp/interactivechat/Updater/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.loohp.interactivechat.Updater;

public class Version implements Comparable<Version> {

private String version;

public final String get() {
return this.version;
}

public Version(String version) {
if(version == null)
throw new IllegalArgumentException("Version can not be null");
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
throw new IllegalArgumentException("Invalid version format");
this.version = version;
}

@Override
public int compareTo(Version that) {
if(that == null)
return 1;
String[] thisParts = this.get().split("\\.");
String[] thatParts = that.get().split("\\.");
int length = Math.max(thisParts.length, thatParts.length);
for(int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ?
Integer.parseInt(thisParts[i]) : 0;
int thatPart = i < thatParts.length ?
Integer.parseInt(thatParts[i]) : 0;
if(thisPart < thatPart)
return -1;
if(thisPart > thatPart)
return 1;
}
return 0;
}

@Override
public boolean equals(Object that) {
if(this == that)
return true;
if(that == null)
return false;
if(this.getClass() != that.getClass())
return false;
return this.compareTo((Version) that) == 0;
}

}
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: InteractiveChat
author: loohp
version: 1.7.7
version: 1.7.8
main: com.loohp.interactivechat.InteractiveChat
api-version: 1.13
description: Make the chat interactive
Expand Down

0 comments on commit eb4d92c

Please sign in to comment.