use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method handleLocationSetting.
private void handleLocationSetting(BlockSnapshot clicked, Player p) {
IPlayer player = new SpongePlayer(p);
Location<World> loc = clicked.getLocation().orElse(null);
if (loc == null)
return;
T trigger = getTriggerForLocation(loc);
if (trigger != null) {
p.sendMessage(Text.builder("Another trigger is set at there!").color(TextColors.RED).build());
showTriggerInfo(player, clicked);
return;
}
String script = getSettingLocationScript(player);
if (script == null) {
p.sendMessage(Text.builder("Could not find script... but how?").color(TextColors.RED).build());
return;
}
File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
try {
String name = TriggerInfo.extractName(file);
IConfigSource config = configSourceFactory.create(folder, name);
TriggerInfo info = TriggerInfo.defaultInfo(file, config);
trigger = newTrigger(info, script);
} catch (Exception e1) {
p.sendMessage(Text.builder("Encounterd an error!").color(TextColors.RED).build());
p.sendMessage(Text.builder(e1.getMessage()).color(TextColors.RED).build());
p.sendMessage(Text.builder("If you are an administrator, check console to see details.").color(TextColors.RED).build());
e1.printStackTrace();
stopLocationSet(player);
return;
}
setTriggerForLocation(loc, trigger);
showTriggerInfo(player, clicked);
stopLocationSet(player);
plugin.saveAsynchronously(this);
}
use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer in project TriggerReactor by wysohn.
the class InventoryEditManager method saveEdit.
@Override
public void saveEdit(IPlayer player) {
UUID u = player.getUniqueId();
if (!suspended.containsKey(u)) {
return;
}
Inventory inv = suspended.get(u).get();
InventoryTrigger trigger = sessions.get(u);
int size = inv.capacity();
IItemStack[] iitems = new IItemStack[size];
for (Inventory slot : inv.slots()) {
slot.getInventoryProperty(SlotIndex.class).ifPresent(slotIndex -> slot.peek().ifPresent(itemStack -> iitems[slotIndex.getValue()] = new SpongeItemStack(itemStack)));
}
// TODO this causes an error waaay down the call chain. replaceItems also saves the inventory trigger manager
// but while trying to write the new data, NPE is thrown. Starting a new edit shows that the new data at least
// gets written to the trigger, but reloading will throw away the edits.
// None of the items I want to save are null, so that isn't the source of the NPE.
// I know this because item.createSnapshot() in the sponge InventoryTriggerManager.writeItemsList() succeeds.
// please investigate this wysohn, because I have no idea at all why it can't save.
replaceItems(trigger, iitems);
stopEdit(player);
player.sendMessage("Saved edits");
}
use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method handleLocationSetting.
private void handleLocationSetting(Block clicked, Player p) {
IPlayer bukkitPlayer = BukkitTriggerReactorCore.getWrapper().wrap(p);
Location loc = clicked.getLocation();
T trigger = getTriggerForLocation(loc);
if (trigger != null) {
bukkitPlayer.sendMessage(ChatColor.RED + "Another trigger is set at there!");
showTriggerInfo(bukkitPlayer, clicked);
return;
}
String script = getSettingLocationScript(bukkitPlayer);
if (script == null) {
bukkitPlayer.sendMessage(ChatColor.RED + "Could not find script... but how?");
return;
}
File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
try {
String name = TriggerInfo.extractName(file);
IConfigSource config = configSourceFactory.create(folder, name);
TriggerInfo info = TriggerInfo.defaultInfo(file, config);
trigger = newTrigger(info, script);
} catch (TriggerInitFailedException e1) {
bukkitPlayer.sendMessage(ChatColor.RED + "Encounterd an error!");
bukkitPlayer.sendMessage(ChatColor.RED + e1.getMessage());
bukkitPlayer.sendMessage(ChatColor.RED + "If you are an administrator, check console to see details.");
e1.printStackTrace();
stopLocationSet(bukkitPlayer);
return;
}
setTriggerForLocation(loc, trigger);
showTriggerInfo(bukkitPlayer, clicked);
stopLocationSet(bukkitPlayer);
plugin.saveAsynchronously(this);
}
Aggregations