use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.
the class ChannelManager method sendMobLvlToDiscordChannel.
private void sendMobLvlToDiscordChannel(DiscordChannel discordChannel, int mobmin, int mobmax) {
String list = "";
String targetChannelId = getDefaultDiscordChannel();
if (discordChannel.equals(DiscordChannel.ADMIN))
targetChannelId = getAdminDiscordChannel();
try {
int count = 0;
for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
if (npc.isPet())
continue;
if (npc.getLevel() >= mobmin && npc.getLevel() <= mobmax) {
list += npc.getName() + "(" + npc.getLevel() + ") ";
count++;
}
}
if (count > 30) {
sendToDiscordMC(null, targetChannelId, "Too many mobs found, try lowering your level range");
} else {
sendToDiscordMC(null, targetChannelId, "Matching Npcs: " + list);
}
} catch (CoreStateInitException e) {
// ignore it
}
}
use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.
the class ChannelManager method sendLootListToDiscordChannel.
private void sendLootListToDiscordChannel(DiscordChannel discordChannel, String itemMatch) {
try {
String targetChannelId = getDefaultDiscordChannel();
if (discordChannel.equals(DiscordChannel.ADMIN))
targetChannelId = getAdminDiscordChannel();
if (itemMatch.length() < 3) {
sendToDiscordMC(null, targetChannelId, "Item search must be at least 3 characters: " + itemMatch);
return;
}
List<ISoliniaItem> items = StateManager.getInstance().getConfigurationManager().getItemsByPartialName(itemMatch);
int itemIdLookup = 0;
try {
itemIdLookup = Integer.parseInt(itemMatch);
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemIdLookup);
items.add(item);
} catch (Exception e) {
}
if (items.size() < 1) {
sendToDiscordMC(null, targetChannelId, "Could not find item: " + itemMatch);
return;
}
if (items.size() > 1) {
String itemsMatched = "";
for (ISoliniaItem item : items) {
itemsMatched += item.getId() + " ";
}
if (itemsMatched.length() > 256) {
itemsMatched = itemsMatched.substring(0, 250) + "...";
}
sendToDiscordMC(null, targetChannelId, "More than one item found with this string, please be more specific than '" + itemMatch + "' (Or Try ?loot with one of these IDs: " + itemsMatched.trim() + ")");
return;
}
String itemname = "";
for (ISoliniaItem item : items) {
itemname = item.getDisplayname();
List<Integer> lootDropIds = StateManager.getInstance().getConfigurationManager().getLootDropIdsWithItemId(item.getId());
if (lootDropIds.size() < 1) {
sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot drops");
return;
}
List<Integer> lootTableIds = StateManager.getInstance().getConfigurationManager().getLootTablesWithLootDrops(lootDropIds);
if (lootTableIds.size() < 1) {
sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot tables");
return;
}
List<String> matchingNpcList = new ArrayList<String>();
String currentLine = "";
for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
if (!lootTableIds.contains(npc.getLoottableid()))
continue;
if ((currentLine + npc.getName() + " ").length() > 2000) {
matchingNpcList.add(currentLine);
currentLine = "";
}
currentLine += npc.getName() + " ";
}
if (!currentLine.equals("")) {
matchingNpcList.add(currentLine);
}
for (String line : matchingNpcList) {
sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] found on: " + line);
}
}
} catch (CoreStateInitException e) {
// ignore it
}
}
use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.
the class JsonNPCRepository method reload.
@Override
public void reload() {
List<ISoliniaNPC> file = new ArrayList<ISoliniaNPC>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCEventHandlerTypeAdapterFactory(SoliniaNPCEventHandler.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaNPC>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
NPCs.clear();
for (ISoliniaNPC i : file) {
if (i.getEventHandlers().size() > 0) {
for (ISoliniaNPCEventHandler handler : i.getEventHandlers()) {
if (handler.getNpcId() == 0) {
handler.setNpcId(i.getId());
System.out.println("Corrected invalid NPC event handler " + handler.getTriggerdata() + " on npc: " + i.getId());
}
}
}
NPCs.put(i.getId(), i);
}
System.out.println("Reloaded " + NPCs.size() + " NPCs");
}
use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.
the class CommandCommit method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
sender.sendMessage("This is a Player/Console only command");
return false;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
player.sendMessage("This is an operator only command");
return true;
}
}
sender.sendMessage("* Executing State Commit");
try {
StateManager.getInstance().Commit();
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage("Error: " + e.getMessage());
return true;
}
if (args.length > 0 && (sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
if (args[0].equals("provider")) {
try {
System.out.println("Recommiting all NPCs via provider");
for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
try {
npc.editSetting("name", npc.getName());
StateManager.getInstance().getEntityManager().getNPCEntityProvider().updateNpc(npc);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidNpcSettingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (CoreStateInitException e) {
}
}
if (args[0].equals("patch")) {
System.out.println("Patching");
Utils.Patcher();
}
}
sender.sendMessage("* Completed State Commit");
return true;
}
use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.
the class SoliniaLivingEntity method say.
@Override
public void say(String message, LivingEntity messageto) {
if (isPlayer())
return;
if (this.getNpcid() < 1)
return;
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
if (npc == null)
return;
String decoratedMessage = ChatColor.AQUA + npc.getName() + " says to " + messageto.getName() + " '" + message + "'" + ChatColor.RESET;
StateManager.getInstance().getChannelManager().sendToLocalChannelLivingEntityChat(this, decoratedMessage);
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations