Send 1.8 titles using packets, fixes #1903

This commit is contained in:
PikaMug 2022-03-22 23:44:07 -04:00
parent 945e06c33f
commit b25449f89f
18 changed files with 377 additions and 185 deletions

View File

@ -31,6 +31,7 @@ import me.blackvein.quests.events.quester.QuesterPostFailQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent; import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent;
import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent; import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent; import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent;
import me.blackvein.quests.nms.TitleProvider;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.quests.BukkitOptions; import me.blackvein.quests.quests.BukkitOptions;
import me.blackvein.quests.quests.BukkitPlanner; import me.blackvein.quests.quests.BukkitPlanner;
@ -913,8 +914,9 @@ public class Quest implements IQuest {
Lang.send(p, ChatColor.GOLD + Lang.get(p, "questCompleteTitle").replace("<quest>", Lang.send(p, ChatColor.GOLD + Lang.get(p, "questCompleteTitle").replace("<quest>",
ChatColor.YELLOW + name + ChatColor.GOLD)); ChatColor.YELLOW + name + ChatColor.GOLD));
if (plugin.getSettings().canShowQuestTitles()) { if (plugin.getSettings().canShowQuestTitles()) {
p.sendTitle(ChatColor.GOLD + Lang.get(p, "quest") + " " + Lang.get(p, "complete"), final String title = ChatColor.GOLD + Lang.get(p, "quest") + " " + Lang.get(p, "complete");
ChatColor.YELLOW + name); final String subtitle = ChatColor.YELLOW + name;
TitleProvider.sendTitle(p, title, subtitle);
} }
Lang.send(p, ChatColor.GREEN + Lang.get(p, "questRewardsTitle")); Lang.send(p, ChatColor.GREEN + Lang.get(p, "questRewardsTitle"));
if (!issuedReward) { if (!issuedReward) {

View File

@ -30,6 +30,7 @@ import me.blackvein.quests.events.quester.QuesterPreOpenGUIEvent;
import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent; import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent; import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent;
import me.blackvein.quests.item.QuestJournal; import me.blackvein.quests.item.QuestJournal;
import me.blackvein.quests.nms.TitleProvider;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.quests.BukkitObjective; import me.blackvein.quests.quests.BukkitObjective;
import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.quests.IQuest;
@ -769,8 +770,9 @@ public class Quester implements IQuester {
sendMessage(ChatColor.GREEN + accepted); sendMessage(ChatColor.GREEN + accepted);
p.sendMessage(""); p.sendMessage("");
if (plugin.getSettings().canShowQuestTitles()) { if (plugin.getSettings().canShowQuestTitles()) {
p.sendTitle(ChatColor.GOLD + Lang.get(p, "quest") + " " + Lang.get(p, "accepted"), final String title = ChatColor.GOLD + Lang.get(p, "quest") + " " + Lang.get(p, "accepted");
ChatColor.YELLOW + quest.getName()); final String subtitle = ChatColor.YELLOW + quest.getName();
TitleProvider.sendTitle(p, title, subtitle);
} }
} }
} }

View File

@ -272,7 +272,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
getServer().getPluginManager().registerEvents(getPartiesListener(), this); getServer().getPluginManager().registerEvents(getPartiesListener(), this);
} }
if (hasBungeeEnabled()) { if (hasBungeeEnabled()) {
getServer().getMessenger().registerIncomingPluginChannel(this, "quests:update", bungeeListener); getServer().getMessenger().registerIncomingPluginChannel(this, "quests:update", getBungeeListener());
} }
// 11 - Attempt to check for updates // 11 - Attempt to check for updates
@ -585,6 +585,10 @@ public class Quests extends JavaPlugin implements QuestsAPI {
return blockListener; return blockListener;
} }
public BungeeListener getBungeeListener() {
return bungeeListener;
}
public ItemListener getItemListener() { public ItemListener getItemListener() {
return itemListener; return itemListener;
} }

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -24,9 +24,9 @@ public abstract class ParticleProvider {
private static ParticleProvider loaded; private static ParticleProvider loaded;
static { static {
final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
try { try {
final String packageName = ParticleProvider.class.getPackage().getName(); final String packageName = ParticleProvider.class.getPackage().getName();
final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
if (internalsName.startsWith("v1_8_R")) { if (internalsName.startsWith("v1_8_R")) {
loaded = (ParticleProvider) Class.forName(packageName + ".ParticleProvider_" + internalsName) loaded = (ParticleProvider) Class.forName(packageName + ".ParticleProvider_" + internalsName)
.newInstance(); .newInstance();
@ -35,7 +35,7 @@ public abstract class ParticleProvider {
} }
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
| ClassCastException exception) { | ClassCastException exception) {
Bukkit.getLogger().severe("[Quests] Could not find a valid implementation for this server version."); Bukkit.getLogger().severe("[Quests] No valid particle implementation for version " + internalsName);
} }
} }

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.nms;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public abstract class TitleProvider {
private static TitleProvider loaded;
static {
final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
try {
final String packageName = TitleProvider.class.getPackage().getName();
if (internalsName.startsWith("v1_8_R")) {
loaded = (TitleProvider) Class.forName(packageName + ".TitleProvider_" + internalsName)
.newInstance();
} else {
loaded = new TitleProvider_Bukkit();
}
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
| ClassCastException exception) {
Bukkit.getLogger().severe("[Quests] No valid title implementation for version " + internalsName);
}
}
abstract void sendTitlePacket(Player player, String title, String subtitle);
/**
* Sends the title to the player.
*
* @param player
* The player to send the title to.
* @param title
* The title.
* @param subtitle
* The subtitle.
*/
public static void sendTitle(final Player player, final String title, final String subtitle) {
loaded.sendTitlePacket(player, title, subtitle);
}
}

View File

@ -0,0 +1,12 @@
package me.blackvein.quests.nms;
import org.bukkit.entity.Player;
class TitleProvider_Bukkit extends TitleProvider {
@SuppressWarnings("deprecation")
@Override
void sendTitlePacket(final Player player, final String title, final String subtitle) {
player.sendTitle(title, subtitle);
}
}

View File

@ -14,7 +14,7 @@ package me.blackvein.quests.tasks;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.particle.ParticleProvider; import me.blackvein.quests.nms.ParticleProvider;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;

View File

@ -15,8 +15,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.spigotmc</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>spigot</artifactId>
<version>1.8-R0.1-SNAPSHOT</version> <version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import net.minecraft.server.v1_8_R1.EnumParticle; import net.minecraft.server.v1_8_R1.EnumParticle;
import net.minecraft.server.v1_8_R1.PacketPlayOutWorldParticles; import net.minecraft.server.v1_8_R1.PacketPlayOutWorldParticles;

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.nms;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.EnumTitleAction;
import net.minecraft.server.v1_8_R1.IChatBaseComponent;
import net.minecraft.server.v1_8_R1.PacketPlayOutTitle;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class TitleProvider_v1_8_R1 extends TitleProvider {
@Override
void sendTitlePacket(final Player player, final String title, final String subtitle) {
final CraftPlayer craft = (CraftPlayer) player;
final String titleString = ComponentSerializer.toString(TextComponent.fromLegacyText(title));
final String titleSubtitle = ComponentSerializer.toString(TextComponent.fromLegacyText(subtitle));
final IChatBaseComponent titleJson = ChatSerializer.a(titleString);
final IChatBaseComponent subtitleJSON = ChatSerializer.a(titleSubtitle);
final PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleJson);
final PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, subtitleJSON);
craft.getHandle().playerConnection.sendPacket(titlePacket);
craft.getHandle().playerConnection.sendPacket(subtitlePacket);
}
}

View File

@ -15,8 +15,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.spigotmc</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>spigot</artifactId>
<version>1.8.3-R0.1-SNAPSHOT</version> <version>1.8.3-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import net.minecraft.server.v1_8_R2.EnumParticle; import net.minecraft.server.v1_8_R2.EnumParticle;
import net.minecraft.server.v1_8_R2.PacketPlayOutWorldParticles; import net.minecraft.server.v1_8_R2.PacketPlayOutWorldParticles;

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.nms;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.server.v1_8_R2.IChatBaseComponent;
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class TitleProvider_v1_8_R2 extends TitleProvider {
@Override
void sendTitlePacket(final Player player, final String title, final String subtitle) {
final CraftPlayer craft = (CraftPlayer) player;
final String titleString = ComponentSerializer.toString(TextComponent.fromLegacyText(title));
final String subtitleString = ComponentSerializer.toString(TextComponent.fromLegacyText(subtitle));
final IChatBaseComponent titleJson = IChatBaseComponent.ChatSerializer.a(titleString);
final IChatBaseComponent subtitleJSON = IChatBaseComponent.ChatSerializer.a(subtitleString);
final PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleJson);
final PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, subtitleJSON);
craft.getHandle().playerConnection.sendPacket(titlePacket);
craft.getHandle().playerConnection.sendPacket(subtitlePacket);
}
}

View File

@ -15,8 +15,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.spigotmc</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version> <version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -10,7 +10,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package me.blackvein.quests.particle; package me.blackvein.quests.nms;
import net.minecraft.server.v1_8_R3.EnumParticle; import net.minecraft.server.v1_8_R3.EnumParticle;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles; import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.nms;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class TitleProvider_v1_8_R3 extends TitleProvider {
@Override
void sendTitlePacket(final Player player, final String title, final String subtitle) {
final CraftPlayer craft = (CraftPlayer) player;
final String titleString = ComponentSerializer.toString(TextComponent.fromLegacyText(title));
final String subtitleString = ComponentSerializer.toString(TextComponent.fromLegacyText(subtitle));
final IChatBaseComponent titleJson = IChatBaseComponent.ChatSerializer.a(titleString);
final IChatBaseComponent subtitleJSON = IChatBaseComponent.ChatSerializer.a(subtitleString);
final PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleJson);
final PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, subtitleJSON);
craft.getHandle().playerConnection.sendPacket(titlePacket);
craft.getHandle().playerConnection.sendPacket(subtitlePacket);
}
}