88
99import carpet .CarpetServer ;
1010import carpet .script .CarpetEventServer .Event ;
11+ import carpet .script .value .EntityValue ;
1112import carpet .script .value .ListValue ;
1213import carpet .script .value .NumericValue ;
1314import carpet .script .value .StringValue ;
@@ -18,171 +19,123 @@ public class ScarpetTwitchEvents extends Event {
1819 public static ScarpetTwitchEvents TWITCH_SUBSCRIPTION = new ScarpetTwitchEvents ("twitch_subscription" , 8 , false ) {
1920 @ Override
2021 public void onTwitchEvent (String playerName , TwitchEvent event ) {
22+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
2123 handler .call (
2224 () -> Arrays .asList (
23- new StringValue (playerName ),
24- new StringValue (event .getNickname ()),
25- new StringValue (event .getMsg ()),
26- new NumericValue (event .getSubscriptionTier ()),
27- new NumericValue (event .getSubscriptionMonths ()),
28- new NumericValue (event .isResubbed ()),
29- new NumericValue (event .getSubscriptionStreakMonths ()),
30- new NumericValue (event .isGifted ())
25+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
26+ new StringValue (event .getNickname ()),
27+ new StringValue (event .getMsg ()),
28+ new NumericValue (event .getSubscriptionTier ()),
29+ new NumericValue (event .getSubscriptionMonths ()),
30+ new NumericValue (event .isResubbed ()),
31+ new NumericValue (event .getSubscriptionStreakMonths ()),
32+ new NumericValue (event .isGifted ())
3133 ),
32- () -> {
33- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
34- if (player != null ) {
35- return player .getCommandSource ();
36- } else {
37- return CarpetServer .minecraft_server .getCommandSource ();
38- }
39- }
34+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
4035 );
4136 }
4237 };
4338 public static ScarpetTwitchEvents TWITCH_DONATION = new ScarpetTwitchEvents ("twitch_donation" , 6 , false ) {
4439 @ Override
4540 public void onTwitchEvent (String playerName , TwitchEvent event ) {
41+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
4642 handler .call (
4743 () -> Arrays .asList (
48- new StringValue (playerName ),
49- new StringValue (event .getNickname ()),
50- new StringValue (event .getMsg ()),
51- new NumericValue (event .getDonationAmount ()),
52- new StringValue (event .getFormattedAmount ()),
53- new StringValue (event .getDonationCurrency ())
44+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
45+ new StringValue (event .getNickname ()),
46+ new StringValue (event .getMsg ()),
47+ new NumericValue (event .getDonationAmount ()),
48+ new StringValue (event .getFormattedAmount ()),
49+ new StringValue (event .getDonationCurrency ())
5450 ),
55- () -> {
56- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
57- if (player != null ) {
58- return player .getCommandSource ();
59- } else {
60- return CarpetServer .minecraft_server .getCommandSource ();
61- }
62- }
51+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
6352 );
6453 }
6554 };
6655 public static ScarpetTwitchEvents TWITCH_FOLLOW = new ScarpetTwitchEvents ("twitch_follow" , 2 , false ) {
6756 @ Override
6857 public void onTwitchEvent (String playerName , TwitchEvent event ) {
58+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
6959 handler .call (
7060 () -> Arrays .asList (
71- new StringValue (playerName ),
72- new StringValue (event .getNickname ())
61+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
62+ new StringValue (event .getNickname ())
7363 ),
74- () -> {
75- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
76- if (player != null ) {
77- return player .getCommandSource ();
78- } else {
79- return CarpetServer .minecraft_server .getCommandSource ();
80- }
81- }
64+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
8265 );
8366 }
8467 };
8568 public static ScarpetTwitchEvents TWITCH_BITS = new ScarpetTwitchEvents ("twitch_bits" , 4 , false ) {
8669 @ Override
8770 public void onTwitchEvent (String playerName , TwitchEvent event ) {
71+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
8872 handler .call (
8973 () -> Arrays .asList (
90- new StringValue (playerName ),
74+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
9175 new StringValue (event .getNickname ()),
9276 new StringValue (event .getMsg ()),
9377 new NumericValue (event .getDonationAmount ())
9478 ),
95- () -> {
96- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
97- if (player != null ) {
98- return player .getCommandSource ();
99- } else {
100- return CarpetServer .minecraft_server .getCommandSource ();
101- }
102- }
79+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
10380 );
10481 }
10582 };
10683 public static ScarpetTwitchEvents TWITCH_RAID = new ScarpetTwitchEvents ("twitch_raid" , 3 , false ) {
10784 @ Override
10885 public void onTwitchEvent (String playerName , TwitchEvent event ) {
86+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
10987 handler .call (
11088 () -> Arrays .asList (
111- new StringValue (playerName ),
89+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
11290 new StringValue (event .getNickname ()),
11391 new NumericValue (event .getRaiderCount ())
11492 ),
115- () -> {
116- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
117- if (player != null ) {
118- return player .getCommandSource ();
119- } else {
120- return CarpetServer .minecraft_server .getCommandSource ();
121- }
122- }
93+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
12394 );
12495 }
12596 };
12697 public static ScarpetTwitchEvents TWITCH_HOST = new ScarpetTwitchEvents ("twitch_host" , 3 , false ) {
12798 @ Override
12899 public void onTwitchEvent (String playerName , TwitchEvent event ) {
100+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
129101 handler .call (
130102 () -> Arrays .asList (
131- new StringValue (playerName ),
103+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
132104 new StringValue (event .getNickname ()),
133105 new NumericValue (event .getViewerCount ())
134106 ),
135- () -> {
136- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
137- if (player != null ) {
138- return player .getCommandSource ();
139- } else {
140- return CarpetServer .minecraft_server .getCommandSource ();
141- }
142- }
107+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
143108 );
144109 }
145110 };
146111 public static ScarpetTwitchEvents TWITCH_SUBSCRIPTION_GIFT = new ScarpetTwitchEvents ("twitch_subscription_gift" , 4 , false ) {
147112 @ Override
148113 public void onTwitchEvent (String playerName , TwitchEvent event ) {
114+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
149115 handler .call (
150116 () -> Arrays .asList (
151- new StringValue (playerName ),
117+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
152118 new StringValue (event .getNickname ()),
153119 new NumericValue (event .getSubscriptionTier ()),
154120 new NumericValue (event .getDonationAmount ())
155121 ),
156- () -> {
157- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
158- if (player != null ) {
159- return player .getCommandSource ();
160- } else {
161- return CarpetServer .minecraft_server .getCommandSource ();
162- }
163- }
122+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
164123 );
165124 }
166125 };
167126 public static ScarpetTwitchEvents TWITCH_CHAT_MESSAGE = new ScarpetTwitchEvents ("twitch_chat_message" , 5 , false ) {
168127 @ Override
169128 public void onTwitchEvent (String playerName , TwitchEvent event ) {
129+ ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
170130 handler .call (
171131 () -> Arrays .asList (
172- new StringValue (playerName ),
132+ player != null ? new EntityValue ( player ) : new StringValue (playerName ),
173133 new StringValue (event .getNickname ()),
174134 new StringValue (event .getMsg ()),
175135 new ListValue (getBadges (event )),
176136 new NumericValue (event .getSubscriptionMonths ())
177137 ),
178- () -> {
179- ServerPlayerEntity player = CarpetServer .minecraft_server .getPlayerManager ().getPlayer (playerName );
180- if (player != null ) {
181- return player .getCommandSource ();
182- } else {
183- return CarpetServer .minecraft_server .getCommandSource ();
184- }
185- }
138+ () -> player != null ? player .getCommandSource () : CarpetServer .minecraft_server .getCommandSource ()
186139 );
187140 }
188141
0 commit comments