Skip to content

Commit 68a4cbe

Browse files
committed
nametag listener attempt #2
1 parent 8aea682 commit 68a4cbe

File tree

8 files changed

+282
-32
lines changed

8 files changed

+282
-32
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GradCraft/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ plugins {
1010
group 'university.quaranteen'
1111
version '1.0-SNAPSHOT'
1212

13+
java {
14+
sourceCompatibility = JavaVersion.VERSION_1_8
15+
targetCompatibility = JavaVersion.VERSION_1_8
16+
}
17+
1318
repositories {
1419
mavenCentral()
1520
enginehub()
21+
protocolLib()
1622
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
1723
maven { url 'https://oss.sonatype.org/content/repositories/central' }
1824
maven { url 'https://ci.mg-dev.eu/plugin/repository/everything' }
@@ -23,7 +29,7 @@ spigot {
2329
authors = ['Quaranteen University Team']
2430
apiVersion = '1.15'
2531
load = Load.POST_WORLD
26-
depends = ['BKCommonLib', 'WorldGuard']
32+
depends = ['BKCommonLib', 'WorldGuard', 'ProtocolLib', 'Citizens']
2733
name = 'GradCraft'
2834
description = 'A plugin for QU'
2935
website = 'https://quaranteen.university/'
@@ -104,6 +110,7 @@ dependencies {
104110
compileOnly 'com.bergerkiller.bukkit:BKCommonLib:1.15.2-v4-SNAPSHOT'
105111
compileOnly worldedit()
106112
compileOnly worldguard()
113+
compileOnly protocolLib()
107114
implementation 'mysql:mysql-connector-java:8.0.20'
108115
implementation 'com.zaxxer:HikariCP:3.4.5'
109116
compileOnly 'net.citizensnpcs:citizens:2.0.26-SNAPSHOT'
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
3+
* Copyright (C) dmulloy2 <http://dmulloy2.net>
4+
* Copyright (C) Kristian S. Strangeland
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.comphenix.packetwrapper;
20+
21+
import java.lang.reflect.InvocationTargetException;
22+
23+
import org.bukkit.entity.Player;
24+
25+
import com.comphenix.protocol.PacketType;
26+
import com.comphenix.protocol.ProtocolLibrary;
27+
import com.comphenix.protocol.events.PacketContainer;
28+
import com.google.common.base.Objects;
29+
30+
public abstract class AbstractPacket {
31+
// The packet we will be modifying
32+
protected PacketContainer handle;
33+
34+
/**
35+
* Constructs a new strongly typed wrapper for the given packet.
36+
*
37+
* @param handle - handle to the raw packet data.
38+
* @param type - the packet type.
39+
*/
40+
protected AbstractPacket(PacketContainer handle, PacketType type) {
41+
// Make sure we're given a valid packet
42+
if (handle == null)
43+
throw new IllegalArgumentException("Packet handle cannot be NULL.");
44+
if (!Objects.equal(handle.getType(), type))
45+
throw new IllegalArgumentException(handle.getHandle()
46+
+ " is not a packet of type " + type);
47+
48+
this.handle = handle;
49+
}
50+
51+
/**
52+
* Retrieve a handle to the raw packet data.
53+
*
54+
* @return Raw packet data.
55+
*/
56+
public PacketContainer getHandle() {
57+
return handle;
58+
}
59+
60+
/**
61+
* Send the current packet to the given receiver.
62+
*
63+
* @param receiver - the receiver.
64+
* @throws RuntimeException If the packet cannot be sent.
65+
*/
66+
public void sendPacket(Player receiver) {
67+
try {
68+
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
69+
getHandle());
70+
} catch (InvocationTargetException e) {
71+
throw new RuntimeException("Cannot send packet.", e);
72+
}
73+
}
74+
75+
/**
76+
* Send the current packet to all online players.
77+
*/
78+
public void broadcastPacket() {
79+
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
80+
}
81+
82+
/**
83+
* Simulate receiving the current packet from the given sender.
84+
*
85+
* @param sender - the sender.
86+
* @throws RuntimeException If the packet cannot be received.
87+
* @deprecated Misspelled. recieve to receive
88+
* @see #receivePacket(Player)
89+
*/
90+
@Deprecated
91+
public void recievePacket(Player sender) {
92+
try {
93+
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
94+
getHandle());
95+
} catch (Exception e) {
96+
throw new RuntimeException("Cannot recieve packet.", e);
97+
}
98+
}
99+
100+
/**
101+
* Simulate receiving the current packet from the given sender.
102+
*
103+
* @param sender - the sender.
104+
* @throws RuntimeException if the packet cannot be received.
105+
*/
106+
public void receivePacket(Player sender) {
107+
try {
108+
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
109+
getHandle());
110+
} catch (Exception e) {
111+
throw new RuntimeException("Cannot receive packet.", e);
112+
}
113+
}
114+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
3+
* Copyright (C) dmulloy2 <http://dmulloy2.net>
4+
* Copyright (C) Kristian S. Strangeland
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.comphenix.packetwrapper;
20+
21+
import java.util.List;
22+
23+
import com.comphenix.protocol.PacketType;
24+
import com.comphenix.protocol.events.PacketContainer;
25+
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
26+
import com.comphenix.protocol.wrappers.PlayerInfoData;
27+
28+
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
29+
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
30+
31+
public WrapperPlayServerPlayerInfo() {
32+
super(new PacketContainer(TYPE), TYPE);
33+
handle.getModifier().writeDefaults();
34+
}
35+
36+
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
37+
super(packet, TYPE);
38+
}
39+
40+
public PlayerInfoAction getAction() {
41+
return handle.getPlayerInfoAction().read(0);
42+
}
43+
44+
public void setAction(PlayerInfoAction value) {
45+
handle.getPlayerInfoAction().write(0, value);
46+
}
47+
48+
public List<PlayerInfoData> getData() {
49+
return handle.getPlayerInfoDataLists().read(0);
50+
}
51+
52+
public void setData(List<PlayerInfoData> value) {
53+
handle.getPlayerInfoDataLists().write(0, value);
54+
}
55+
}

GradCraft/src/main/java/university/quaranteen/gradcraft/GradCraftPlugin.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.bergerkiller.bukkit.common.Common;
44
import com.bergerkiller.bukkit.common.PluginBase;
5+
import com.comphenix.protocol.ProtocolLibrary;
56
import com.zaxxer.hikari.HikariConfig;
67
import com.zaxxer.hikari.HikariDataSource;
78
import kr.entree.spigradle.Plugin;
@@ -31,7 +32,8 @@ public class GradCraftPlugin extends PluginBase {
3132
public ActiveCeremony ceremony;
3233

3334
public BukkitTask ceremonyTimerTask;
34-
public GraduateNPC currentGraduateNPC = null;
35+
36+
private NametagListener nametagListener;
3537

3638
@Override
3739
public int getMinimumLibVersion() {
@@ -75,7 +77,9 @@ public void enable() {
7577

7678
this.getServer().getScheduler().runTaskTimer(this, new CeremonyTimer(this), 20, 20);
7779

78-
this.register(new NametagListener(this));
80+
nametagListener = new NametagListener(this);
81+
this.register(nametagListener);
82+
ProtocolLibrary.getProtocolManager().addPacketListener(nametagListener);
7983

8084
// Register your trait with Citizens
8185
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(GraduateTrait.class).withName("graduate"));
@@ -89,6 +93,9 @@ public void disable() {
8993
this.getServer().getScheduler().cancelTask(ceremonyTimerTask.getTaskId());
9094
if (db != null)
9195
db.close();
96+
97+
CitizensAPI.getTraitFactory().deregisterTrait(TraitInfo.create(GraduateTrait.class).withName("graduate"));
98+
CitizensAPI.getTraitFactory().deregisterTrait(TraitInfo.create(ProfessorTrait.class).withName("professor"));
9299
}
93100

94101
@Override

0 commit comments

Comments
 (0)