11package dev .plex .request ;
22
3- import dev .plex .Plex ;
3+ import dev .plex .HTTPDModule ;
4+ import dev .plex .api .player .PlexPlayerView ;
5+ import dev .plex .api .punishment .PunishmentRequest ;
6+ import dev .plex .api .punishment .PunishmentType ;
47import dev .plex .authentication .AuthenticatedUser ;
5- import dev .plex .cache .DataUtils ;
68import dev .plex .logging .Log ;
7- import dev .plex .player .PlexPlayer ;
8- import dev .plex .punishment .Punishment ;
9- import dev .plex .punishment .PunishmentType ;
10- import dev .plex .util .BungeeUtil ;
11- import dev .plex .util .TimeUtils ;
129import jakarta .servlet .ServletException ;
1310import jakarta .servlet .http .HttpServlet ;
1411import jakarta .servlet .http .HttpServletRequest ;
1512import jakarta .servlet .http .HttpServletResponse ;
1613import org .bukkit .Bukkit ;
1714import org .bukkit .entity .Player ;
1815import org .bukkit .inventory .PlayerInventory ;
16+ import net .kyori .adventure .text .Component ;
1917
2018import java .io .IOException ;
2119import java .time .ZoneId ;
@@ -73,7 +71,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
7371 return ;
7472 }
7573
76- PlexPlayer target = DataUtils . getPlayer ( uuid );
74+ PlexPlayerView target = HTTPDModule . plexApi (). players (). byUuid ( uuid ). orElse ( null );
7775 if (target == null )
7876 {
7977 response .setStatus (HttpServletResponse .SC_NOT_FOUND );
@@ -91,37 +89,41 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
9189 if (safeReason .length () > 500 ) safeReason = safeReason .substring (0 , 500 );
9290
9391 PunishmentType type = mapType (action );
94- ZonedDateTime now = ZonedDateTime .now (ZoneId .of ( TimeUtils . TIMEZONE ));
92+ ZonedDateTime now = ZonedDateTime .now (ZoneId .systemDefault ( ));
9593 ZonedDateTime endDate = TEMP_ACTIONS .contains (action )
9694 ? now .plusSeconds (parseDurationSeconds (durationStr ))
9795 : now .plusDays (FAR_FUTURE_DAYS );
9896
99- Punishment punishment = new Punishment (uuid , null );
100- punishment .setType (type );
101- punishment .setReason (safeReason );
102- punishment .setPunishedUsername (target .getName ());
103- punishment .setPunisherName ("xf:" + staff .username ());
104- punishment .setEndDate (endDate );
105- punishment .setCustomTime (TEMP_ACTIONS .contains (action ));
106- punishment .setActive (true );
107- List <String > ips = target .getIps ();
108- if (ips != null && !ips .isEmpty ()) punishment .setIp (ips .getLast ());
97+ List <String > ips = target .ips ();
98+ String ip = ips == null || ips .isEmpty () ? "" : ips .getLast ();
99+ PunishmentRequest punishment = new PunishmentRequest (
100+ uuid ,
101+ null ,
102+ "xf:" + staff .username (),
103+ ip ,
104+ target .name (),
105+ type ,
106+ safeReason ,
107+ TEMP_ACTIONS .contains (action ),
108+ true ,
109+ endDate
110+ );
109111
110112 String ipAddress = request .getRemoteAddr ();
111113 if ("127.0.0.1" .equals (ipAddress ))
112114 {
113115 String forwarded = request .getHeader ("X-FORWARDED-FOR" );
114116 if (forwarded != null ) ipAddress = forwarded ;
115117 }
116- Log .log (ipAddress + " (xf:" + staff .username () + ") issued " + action + " on " + target .getName () + " (" + uuid + ")" );
118+ Log .log (ipAddress + " (xf:" + staff .username () + ") issued " + action + " on " + target .name () + " (" + uuid + ")" );
117119
118120 final boolean kick = action .equals ("ban" ) || action .equals ("tempban" );
119- final Punishment toApply = punishment ;
120- Bukkit . getScheduler ().runTask ( Plex . get (), () ->
121+ final PunishmentRequest toApply = punishment ;
122+ HTTPDModule . plexApi ().scheduler (). runSync ( () ->
121123 {
122124 try
123125 {
124- Plex . get ().getPunishmentManager ().punish (target , toApply );
126+ HTTPDModule . plexApi ().punishments ().punish (target , toApply );
125127 }
126128 catch (Throwable t )
127129 {
@@ -133,7 +135,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
133135 Player online = Bukkit .getPlayer (uuid );
134136 if (online != null )
135137 {
136- try { BungeeUtil . kickPlayer ( online , Punishment . generateBanMessage ( toApply )); }
138+ try { online . kick ( Component . text ( "You have been banned: " + toApply . reason () )); }
137139 catch (Throwable t ) { t .printStackTrace (); }
138140 }
139141 }
@@ -142,7 +144,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
142144 response .sendRedirect ("/player/" + uuid );
143145 }
144146
145- private static void handleInventoryAction (HttpServletRequest request , HttpServletResponse response , AuthenticatedUser staff , UUID uuid , PlexPlayer target , String action , String slot )
147+ private static void handleInventoryAction (HttpServletRequest request , HttpServletResponse response , AuthenticatedUser staff , UUID uuid , PlexPlayerView target , String action , String slot )
146148 throws IOException
147149 {
148150 String ipAddress = request .getRemoteAddr ();
@@ -152,9 +154,9 @@ private static void handleInventoryAction(HttpServletRequest request, HttpServle
152154 if (forwarded != null ) ipAddress = forwarded ;
153155 }
154156
155- Log .log (ipAddress + " (xf:" + staff .username () + ") issued " + action + " on " + target .getName () + " (" + uuid + ")" + (slot == null || slot .isBlank () ? "" : " slot " + slot ));
157+ Log .log (ipAddress + " (xf:" + staff .username () + ") issued " + action + " on " + target .name () + " (" + uuid + ")" + (slot == null || slot .isBlank () ? "" : " slot " + slot ));
156158
157- Bukkit . getScheduler ().runTask ( Plex . get (), () ->
159+ HTTPDModule . plexApi ().scheduler (). runSync ( () ->
158160 {
159161 Player online = Bukkit .getPlayer (uuid );
160162 if (online == null ) return ;
0 commit comments