33import io .netty .buffer .ByteBuf ;
44import io .netty .channel .ChannelHandlerContext ;
55import net .infstudio .goki .GokiStats ;
6- import net .infstudio .goki .common .utils .DataHelper ;
76import net .infstudio .goki .common .config .GokiConfig ;
87import net .infstudio .goki .common .stats .StatBase ;
98import net .infstudio .goki .common .stats .StatMaxHealth ;
9+ import net .infstudio .goki .common .utils .DataHelper ;
1010import net .minecraft .entity .SharedMonsterAttributes ;
1111import net .minecraft .entity .player .EntityPlayer ;
1212import net .minecraft .entity .player .EntityPlayerMP ;
1313
14+ import javax .annotation .Nonnegative ;
15+
1416public class PacketStatAlter implements GokiPacket {
15- private int stat ;
16- private int amount ;
17+ protected int stat ;
18+ protected int amount ;
1719
1820 public PacketStatAlter () {
1921 }
@@ -43,11 +45,23 @@ public void handleClientSide(EntityPlayer player) {
4345 public void handleServerSide (EntityPlayer player ) {
4446 if (player == null )
4547 return ;
46- StatBase stat = StatBase .stats .get (this .stat );
47- if (!stat .enabled )
48- return ;
49- int level = DataHelper .getPlayerStatLevel (player , stat );
50- if (this .amount > 0 ) {
48+ }
49+
50+ public static class Up extends PacketStatAlter {
51+ public Up () {
52+ }
53+
54+ public Up (int stat , @ Nonnegative int amount ) {
55+ super (stat , amount );
56+ }
57+
58+ @ Override
59+ public void handleServerSide (EntityPlayer player ) {
60+ super .handleServerSide (player );
61+ StatBase stat = StatBase .stats .get (this .stat );
62+ if (!stat .enabled )
63+ return ;
64+ int level = DataHelper .getPlayerStatLevel (player , stat );
5165
5266 if (level + this .amount > stat .getLimit ()) {
5367 this .amount = stat .getLimit () - level ;
@@ -72,26 +86,44 @@ public void handleServerSide(EntityPlayer player) {
7286
7387 GokiStats .packetPipeline .sendTo (new PacketStatSync (player ), (EntityPlayerMP ) player );
7488 GokiStats .packetPipeline .sendTo (new PacketSyncXP (player ), (EntityPlayerMP ) player );
75- } else if (DataHelper .getPlayerStatLevel (player , stat ) > 0 ) {
89+ }
90+ }
91+
92+ public static class Down extends PacketStatAlter {
93+ public Down () {
94+ }
7695
77- int reverted = DataHelper .getPlayerRevertStatLevel (player , stat );
78- int maxRevert = GokiConfig .globalModifiers .globalMaxRevertLevel ;
96+ public Down (int stat , @ Nonnegative int amount ) {
97+ super (stat , amount );
98+ }
7999
80- if (maxRevert > 0 && reverted + (-this .amount ) > maxRevert ) { // check if we limit the max revert, and if the revert overflow the value
81- this .amount = -(maxRevert - reverted ); // ceil the value for max revert
82- }
100+ @ Override
101+ public void handleServerSide (EntityPlayer player ) {
102+ super .handleServerSide (player );
103+ StatBase stat = StatBase .stats .get (this .stat );
104+ if (!stat .enabled )
105+ return ;
106+ int level = DataHelper .getPlayerStatLevel (player , stat );
107+ if (DataHelper .getPlayerStatLevel (player , stat ) > 0 ) {
108+ int reverted = DataHelper .getPlayerRevertStatLevel (player , stat );
109+ int maxRevert = GokiConfig .globalModifiers .globalMaxRevertLevel ;
83110
84- reverted += (-this .amount );
85- DataHelper .setPlayerRevertStatLevel (player , stat , reverted );
111+ if (maxRevert >= 0 && reverted + this .amount > maxRevert ) { // check if we limit the max revert, and if the revert overflow the value
112+ this .amount += maxRevert - reverted ; // ceil the value for max revert
113+ }
86114
87- player .addExperience ((int ) (stat .getCost (level + this .amount - 2 ) * GokiConfig .globalModifiers .globalRevertFactor ));
88- DataHelper .setPlayerStatLevel (player , stat , level + this .amount );
89- if (stat instanceof StatMaxHealth ) {
90- player .getEntityAttribute (SharedMonsterAttributes .MAX_HEALTH ).setBaseValue (20 + level + this .amount );
91- }
115+ reverted += this .amount ;
116+ DataHelper .setPlayerRevertStatLevel (player , stat , reverted );
92117
93- GokiStats .packetPipeline .sendTo (new PacketStatSync (player ), (EntityPlayerMP ) player );
94- GokiStats .packetPipeline .sendTo (new PacketSyncXP (player ), (EntityPlayerMP ) player );
118+ player .addExperience ((int ) (stat .getCost (level - this .amount - 2 ) * GokiConfig .globalModifiers .globalRevertFactor ));
119+ DataHelper .setPlayerStatLevel (player , stat , level - this .amount );
120+ if (stat instanceof StatMaxHealth ) {
121+ player .getEntityAttribute (SharedMonsterAttributes .MAX_HEALTH ).setBaseValue (20 + level - this .amount );
122+ }
123+
124+ GokiStats .packetPipeline .sendTo (new PacketStatSync (player ), (EntityPlayerMP ) player );
125+ GokiStats .packetPipeline .sendTo (new PacketSyncXP (player ), (EntityPlayerMP ) player );
126+ }
95127 }
96128 }
97129}
0 commit comments