Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
MythicCraft
MythicCosmetics
Commits
fa1ebd04
Commit
fa1ebd04
authored
2 years ago
by
Ashijin
Browse files
Options
Download
Email Patches
Plain Diff
Fixed hat and offhand disconnect issues on 1.19.2
parent
8a89afb9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
27 deletions
+90
-27
plugin/src/main/java/io/lumine/cosmetics/config/Configuration.java
...c/main/java/io/lumine/cosmetics/config/Configuration.java
+1
-1
plugin/src/main/resources/config.yml
plugin/src/main/resources/config.yml
+1
-1
v1_19_R1_2/src/main/java/io/lumine/cosmetics/nms/v1_19_R1_2/cosmetic/VolatileHatImpl.java
...ne/cosmetics/nms/v1_19_R1_2/cosmetic/VolatileHatImpl.java
+50
-12
v1_19_R1_2/src/main/java/io/lumine/cosmetics/nms/v1_19_R1_2/cosmetic/VolatileOffhandImpl.java
...osmetics/nms/v1_19_R1_2/cosmetic/VolatileOffhandImpl.java
+38
-13
No files found.
plugin/src/main/java/io/lumine/cosmetics/config/Configuration.java
View file @
fa1ebd04
...
@@ -28,7 +28,7 @@ public class Configuration extends ReloadableModule<MCCosmeticsPlugin> implement
...
@@ -28,7 +28,7 @@ public class Configuration extends ReloadableModule<MCCosmeticsPlugin> implement
private
static
final
EnumProp
<
StorageDriver
>
STORAGE_DRIVER
=
Property
.
Enum
(
Scope
.
CONFIG
,
StorageDriver
.
class
,
"Storage.Driver"
,
StorageDriver
.
JSON
);
private
static
final
EnumProp
<
StorageDriver
>
STORAGE_DRIVER
=
Property
.
Enum
(
Scope
.
CONFIG
,
StorageDriver
.
class
,
"Storage.Driver"
,
StorageDriver
.
JSON
);
private
static
final
SqlCredentialsProp
SQL_CREDENTIALS
=
Property
.
SqlCredentials
(
Scope
.
CONFIG
,
"Storage"
);
private
static
final
SqlCredentialsProp
SQL_CREDENTIALS
=
Property
.
SqlCredentials
(
Scope
.
CONFIG
,
"Storage"
);
private
static
final
IntProp
EQUIP_DELAY
=
Property
.
Int
(
Scope
.
CONFIG
,
"General.EquipDelay"
,
0
);
private
static
final
IntProp
EQUIP_DELAY
=
Property
.
Int
(
Scope
.
CONFIG
,
"General.EquipDelay"
,
5
);
@Getter
private
boolean
allowingMetrics
=
true
;
@Getter
private
boolean
allowingMetrics
=
true
;
...
...
This diff is collapsed.
Click to expand it.
plugin/src/main/resources/config.yml
View file @
fa1ebd04
...
@@ -2,7 +2,7 @@ Configuration:
...
@@ -2,7 +2,7 @@ Configuration:
Storage
:
Storage
:
Driver
:
JSON
Driver
:
JSON
General
:
General
:
EquipDelay
:
0
EquipDelay
:
5
Sprays
:
Sprays
:
Sound
:
'
entity.cat.hiss'
Sound
:
'
entity.cat.hiss'
Volume
:
1.0
Volume
:
1.0
...
...
This diff is collapsed.
Click to expand it.
v1_19_R1_2/src/main/java/io/lumine/cosmetics/nms/v1_19_R1_2/cosmetic/VolatileHatImpl.java
View file @
fa1ebd04
...
@@ -11,6 +11,7 @@ import io.lumine.cosmetics.managers.hats.Hat;
...
@@ -11,6 +11,7 @@ import io.lumine.cosmetics.managers.hats.Hat;
import
io.lumine.cosmetics.nms.VolatileCodeEnabled_v1_19_R1_2
;
import
io.lumine.cosmetics.nms.VolatileCodeEnabled_v1_19_R1_2
;
import
io.lumine.cosmetics.nms.cosmetic.VolatileEquipmentHelper
;
import
io.lumine.cosmetics.nms.cosmetic.VolatileEquipmentHelper
;
import
io.lumine.cosmetics.players.Profile
;
import
io.lumine.cosmetics.players.Profile
;
import
io.lumine.utils.logging.Log
;
import
io.netty.buffer.Unpooled
;
import
io.netty.buffer.Unpooled
;
import
lombok.Getter
;
import
lombok.Getter
;
import
net.minecraft.network.FriendlyByteBuf
;
import
net.minecraft.network.FriendlyByteBuf
;
...
@@ -21,7 +22,9 @@ import net.minecraft.world.entity.EquipmentSlot;
...
@@ -21,7 +22,9 @@ import net.minecraft.world.entity.EquipmentSlot;
import
org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer
;
import
org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer
;
import
org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
;
import
org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
;
import
org.bukkit.entity.Player
;
import
org.bukkit.entity.Player
;
import
org.bukkit.inventory.ItemStack
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -29,7 +32,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -29,7 +32,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
@Getter
private
final
MCCosmeticsPlugin
plugin
;
@Getter
private
final
MCCosmeticsPlugin
plugin
;
private
final
VolatileCodeEnabled_v1_19_R1_2
nmsHandler
;
private
final
VolatileCodeEnabled_v1_19_R1_2
nmsHandler
;
private
final
Map
<
Integer
,
Player
>
playerTracker
=
Maps
.
newConcurrentMap
();
//
private final Map<Integer, Player> playerTracker = Maps.newConcurrentMap();
public
VolatileHatImpl
(
MCCosmeticsPlugin
plugin
,
VolatileCodeEnabled_v1_19_R1_2
nmsHandler
)
{
public
VolatileHatImpl
(
MCCosmeticsPlugin
plugin
,
VolatileCodeEnabled_v1_19_R1_2
nmsHandler
)
{
this
.
plugin
=
plugin
;
this
.
plugin
=
plugin
;
...
@@ -55,7 +58,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -55,7 +58,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
maybeEquipped
.
get
()));
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
maybeEquipped
.
get
()));
playerTracker
.
put
(
player
.
getEntityId
(),
player
);
//
playerTracker.put(player.getEntityId(), player);
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
...
@@ -81,7 +84,8 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -81,7 +84,8 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
cosmetic
));
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
cosmetic
));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
entityId
,
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
entityId
,
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
nmsHandler
.
broadcast
(
player
,
equipmentPacket
);
nmsHandler
.
broadcast
(
player
,
equipmentPacket
);
}
}
...
@@ -107,18 +111,20 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -107,18 +111,20 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
@Override
@Override
public
List
<
Object
>
write
(
Player
receiver
,
Object
packet
)
{
public
List
<
Object
>
write
(
Player
receiver
,
Object
packet
)
{
/*
if(packet instanceof ClientboundAddPlayerPacket playerPacket) {
if(packet instanceof ClientboundAddPlayerPacket playerPacket) {
int id = playerPacket.getEntityId();
int id = playerPacket.getEntityId();
Profile profile = getProfile(receiver, id);
Profile profile = getProfile(receiver, id);
if(profile != null && !profile.isHidden(Hat.class)) {
if(profile != null && !profile.isHidden(Hat.class)) {
handleSpawn(profile);
handleSpawn(profile);
}
}
}
else
if
(
packet
instanceof
ClientboundSetEquipmentPacket
equipmentPacket
)
{
} else */
if
(
packet
instanceof
ClientboundSetEquipmentPacket
equipmentPacket
)
{
int
id
=
equipmentPacket
.
getEntity
();
int
id
=
equipmentPacket
.
getEntity
();
Profile
profile
=
getProfile
(
receiver
,
id
);
Profile
profile
=
getProfile
(
receiver
,
id
);
if
(
profile
!=
null
&&
!
profile
.
isHidden
(
Hat
.
class
))
{
if
(
profile
!=
null
&&
!
profile
.
isHidden
(
Hat
.
class
))
{
handleSpawn
(
profile
);
modifyPacket
(
profile
,
equipmentPacket
);
}
}
}
}
...
@@ -133,6 +139,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -133,6 +139,7 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
}
}
public
void
handleSpawn
(
Profile
profile
)
{
public
void
handleSpawn
(
Profile
profile
)
{
final
var
maybeEquipped
=
profile
.
getEquipped
(
Hat
.
class
);
final
var
maybeEquipped
=
profile
.
getEquipped
(
Hat
.
class
);
if
(
maybeEquipped
.
isEmpty
())
{
if
(
maybeEquipped
.
isEmpty
())
{
return
;
return
;
...
@@ -140,19 +147,50 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
...
@@ -140,19 +147,50 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
var
equip
=
maybeEquipped
.
get
();
var
equip
=
maybeEquipped
.
get
();
var
opt
=
equip
.
getCosmetic
();
var
opt
=
equip
.
getCosmetic
();
if
(!(
opt
instanceof
ItemCosmetic
hat
))
if
(!(
opt
instanceof
ItemCosmetic
hat
))
{
return
;
return
;
}
final
var
player
=
profile
.
getPlayer
();
final
var
player
=
profile
.
getPlayer
();
final
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
equip
));
final
var
nmsHat
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
equip
));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsHat
)));
//FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
nmsHandler
.
broadcastAroundAndSelf
(
player
,
equipmentPacket
);
//byteBuf.writeByte(80);
}
//equipmentPacket.write(byteBuf);
private
void
modifyPacket
(
Profile
profile
,
ClientboundSetEquipmentPacket
packet
)
{
final
var
maybeEquipped
=
profile
.
getEquipped
(
Hat
.
class
);
if
(
maybeEquipped
.
isEmpty
())
{
return
;
}
var
equip
=
maybeEquipped
.
get
();
var
opt
=
equip
.
getCosmetic
();
if
(!(
opt
instanceof
ItemCosmetic
hat
))
{
return
;
}
final
var
pipeline
=
((
CraftPlayer
)
player
).
getHandle
().
connection
.
getConnection
().
channel
.
pipeline
();
final
var
nmsItem
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
equip
));
pipeline
.
writeAndFlush
(
equipmentPacket
);
var
slots
=
(
List
<
Pair
<
EquipmentSlot
,
net
.
minecraft
.
world
.
item
.
ItemStack
>>)
packet
.
getSlots
();
List
<
Pair
<
EquipmentSlot
,
net
.
minecraft
.
world
.
item
.
ItemStack
>>
newSlots
=
new
ArrayList
<>();
boolean
foundHead
=
false
;
for
(
var
pair
:
slots
)
{
final
EquipmentSlot
slot
=
pair
.
getFirst
();
if
(
slot
==
EquipmentSlot
.
HEAD
)
{
foundHead
=
true
;
newSlots
.
add
(
Pair
.
of
(
pair
.
getFirst
(),
nmsItem
));
}
else
{
newSlots
.
add
(
pair
);
}
}
if
(!
foundHead
)
{
newSlots
.
add
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsItem
));
}
packet
.
getSlots
().
clear
();
packet
.
getSlots
().
addAll
(
newSlots
);
}
}
}
}
This diff is collapsed.
Click to expand it.
v1_19_R1_2/src/main/java/io/lumine/cosmetics/nms/v1_19_R1_2/cosmetic/VolatileOffhandImpl.java
View file @
fa1ebd04
...
@@ -22,6 +22,7 @@ import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
...
@@ -22,6 +22,7 @@ import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import
org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
;
import
org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
;
import
org.bukkit.entity.Player
;
import
org.bukkit.entity.Player
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -98,16 +99,11 @@ public class VolatileOffhandImpl implements VolatileEquipmentHelper {
...
@@ -98,16 +99,11 @@ public class VolatileOffhandImpl implements VolatileEquipmentHelper {
@Override
@Override
public
List
<
Object
>
write
(
Player
receiver
,
Object
packet
)
{
public
List
<
Object
>
write
(
Player
receiver
,
Object
packet
)
{
if
(
packet
instanceof
ClientboundAddPlayerPacket
playerPacket
)
{
if
(
packet
instanceof
ClientboundSetEquipmentPacket
equipmentPacket
)
{
int
id
=
playerPacket
.
getEntityId
();
Profile
profile
=
getProfile
(
receiver
,
id
);
if
(
profile
!=
null
&&
!
profile
.
isHidden
(
Offhand
.
class
))
handleSpawn
(
profile
);
}
else
if
(
packet
instanceof
ClientboundSetEquipmentPacket
equipmentPacket
)
{
int
id
=
equipmentPacket
.
getEntity
();
int
id
=
equipmentPacket
.
getEntity
();
Profile
profile
=
getProfile
(
receiver
,
id
);
Profile
profile
=
getProfile
(
receiver
,
id
);
if
(
profile
!=
null
&&
!
profile
.
isHidden
(
Offhand
.
class
))
if
(
profile
!=
null
&&
!
profile
.
isHidden
(
Offhand
.
class
))
handleSpawn
(
profile
);
modifyPacket
(
profile
,
equipmentPacket
);
}
}
return
null
;
return
null
;
...
@@ -134,13 +130,42 @@ public class VolatileOffhandImpl implements VolatileEquipmentHelper {
...
@@ -134,13 +130,42 @@ public class VolatileOffhandImpl implements VolatileEquipmentHelper {
final
var
player
=
profile
.
getPlayer
();
final
var
player
=
profile
.
getPlayer
();
final
var
nmsOffhand
=
CraftItemStack
.
asNMSCopy
(
offhand
.
getCosmetic
(
equip
));
final
var
nmsOffhand
=
CraftItemStack
.
asNMSCopy
(
offhand
.
getCosmetic
(
equip
));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
OFFHAND
,
nmsOffhand
)));
ClientboundSetEquipmentPacket
equipmentPacket
=
new
ClientboundSetEquipmentPacket
(
player
.
getEntityId
(),
List
.
of
(
Pair
.
of
(
EquipmentSlot
.
OFFHAND
,
nmsOffhand
)));
nmsHandler
.
broadcastAroundAndSelf
(
player
,
equipmentPacket
);
}
private
void
modifyPacket
(
Profile
profile
,
ClientboundSetEquipmentPacket
packet
)
{
final
var
maybeEquipped
=
profile
.
getEquipped
(
Hat
.
class
);
if
(
maybeEquipped
.
isEmpty
())
{
return
;
}
var
equip
=
maybeEquipped
.
get
();
var
opt
=
equip
.
getCosmetic
();
if
(!(
opt
instanceof
ItemCosmetic
hat
))
{
return
;
}
FriendlyByteBuf
byteBuf
=
new
FriendlyByteBuf
(
Unpooled
.
buffer
());
final
var
nmsItem
=
CraftItemStack
.
asNMSCopy
(
hat
.
getCosmetic
(
equip
));
byteBuf
.
writeByte
(
80
);
equipmentPacket
.
write
(
byteBuf
);
var
slots
=
(
List
<
Pair
<
EquipmentSlot
,
net
.
minecraft
.
world
.
item
.
ItemStack
>>)
packet
.
getSlots
();
List
<
Pair
<
EquipmentSlot
,
net
.
minecraft
.
world
.
item
.
ItemStack
>>
newSlots
=
new
ArrayList
<>();
final
var
pipeline
=
((
CraftPlayer
)
player
).
getHandle
().
connection
.
getConnection
().
channel
.
pipeline
();
pipeline
.
writeAndFlush
(
equipmentPacket
);
boolean
foundHead
=
false
;
for
(
var
pair
:
slots
)
{
final
EquipmentSlot
slot
=
pair
.
getFirst
();
if
(
slot
==
EquipmentSlot
.
HEAD
)
{
foundHead
=
true
;
newSlots
.
add
(
Pair
.
of
(
pair
.
getFirst
(),
nmsItem
));
}
else
{
newSlots
.
add
(
pair
);
}
}
if
(!
foundHead
)
{
newSlots
.
add
(
Pair
.
of
(
EquipmentSlot
.
HEAD
,
nmsItem
));
}
packet
.
getSlots
().
clear
();
packet
.
getSlots
().
addAll
(
newSlots
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment