package Announce;
import l2.gameserver.Announcements;
import l2.gameserver.listener.actor.player.OnItemPickupListener;
import l2.gameserver.model.Player;
import l2.gameserver.model.actor.listener.PlayerListenerList;
import l2.gameserver.model.items.ItemInstance;
import l2.gameserver.network.l2.components.ChatType;
import l2.gameserver.scripts.Functions;
import l2.gameserver.scripts.ScriptFile;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class Announce extends Functions implements ScriptFile, OnItemPickupListener {
private static final List<Integer> itemIds = new ArrayList<>();
@Override
public void onLoad() {
PlayerListenerList.addGlobal(this);
loadItemIds();
System.out.println("Drop announcing script activated");
}
@Override
public void onReload() {}
@Override
public void onShutdown() {
PlayerListenerList.removeGlobal(this);
}
@Override
public void onItemPickup(Player player, ItemInstance itemInstance) {
if (itemIds.contains(itemInstance.getItemId()) && itemInstance.getLastDropTime() == 0) {
String playerName = player.getName();
String itemName = itemInstance.getName();
String message = String.format("PT >Atencao< : %s acabou de dropar [%s]", playerName, itemName);
String message1 = String.format("EN >Attention< : %s just dropped [%s]", playerName, itemName);
System.out.println(message);
System.out.println(message1);
Announcements.getInstance().announceToAll(message, ChatType.SHOUT);
Announcements.getInstance().announceToAll(message1, ChatType.SHOUT);
}
}
private void loadItemIds() {
try (BufferedReader reader = new BufferedReader(new FileReader(new File("config/itemids.properties")))) {
String line;
while ((line = reader.readLine()) != null) {
int itemId = Integer.parseInt(line.trim());
itemIds.add(itemId);
System.out.println("Item IDs loaded successfully - Drop Announcing System");
}
} catch (IOException e) {
System.err.println("Error loading item IDs from file config/itemids.properties: " + e.getMessage());
}
}
}