use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.
the class ActionFactory method createEntity.
/**
* Entity Handler.
*
* @param actionType type
* @param entity entity
* @param nonPlayer nonPlayer
* @param dyeUsed string
* @return Handler
*/
@SuppressWarnings("WeakerAccess")
public static Handler createEntity(String actionType, Entity entity, String nonPlayer, String dyeUsed) {
final Handler a = createEntity(actionType, entity, (OfflinePlayer) null, dyeUsed);
a.setSourceName(nonPlayer);
return a;
}
use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.
the class ActionFactory method createVehicle.
/**
* Create a vehicle.
*
* @param actionType type
* @param vehicle vehicle
* @param nonPlayer nonplayer
* @return Handler
*/
public static Handler createVehicle(String actionType, Vehicle vehicle, String nonPlayer) {
final Handler a = createVehicle(actionType, vehicle, (OfflinePlayer) null);
a.setSourceName(nonPlayer);
return a;
}
use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.
the class PrismInventoryEvents method onItemBreak.
/**
* Tracks item breakage. Cant be rolled back. At this point the item damage is not 0 however it will be set 0 after
* event completes - Reported item durability will be the durability before the event.
* @param event PlayerItemBreakEvent.
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onItemBreak(PlayerItemBreakEvent event) {
if (!trackingBreaks) {
return;
}
ItemStack item = event.getBrokenItem();
Handler h = ActionFactory.createItemStack(BREAK, item, null, event.getPlayer().getLocation(), event.getPlayer());
RecordingQueue.addToQueue(h);
}
use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.
the class PrismPlayerEvents method onPlayerBucketFill.
/**
* PlayerBucketFillEvent.
*
* @param event PlayerBucketFillEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketFill(final PlayerBucketFillEvent event) {
final Player player = event.getPlayer();
if (!Prism.getIgnore().event("bucket-fill", player)) {
return;
}
final Block spot = event.getBlock();
String liquidType = "milk";
if (spot.getType() == Material.WATER) {
liquidType = "water";
} else if (spot.getBlockData() instanceof Waterlogged && ((Waterlogged) spot.getBlockData()).isWaterlogged()) {
liquidType = "water";
} else if (spot.getType() == Material.LAVA) {
liquidType = "lava";
}
final Handler pa = ActionFactory.createPlayer("bucket-fill", player, liquidType);
// Override the location with the area taken
pa.setX(spot.getX());
pa.setY(spot.getY());
pa.setZ(spot.getZ());
RecordingQueue.addToQueue(pa);
}
use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.
the class LookupCommand method handle.
/**
* Handle the command.
*/
@Override
public void handle(final CallInfo call) {
// Process and validate all of the arguments
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
// Run the lookup itself in an async task so the lookup query isn't done on the main thread
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// determine if defaults were used
final List<String> defaultsUsed = parameters.getDefaultsUsed();
StringBuilder defaultsReminder = new StringBuilder();
if (!defaultsUsed.isEmpty()) {
defaultsReminder.append(Il8nHelper.getRawMessage("queryparameter.defaults.prefix"));
for (final String d : defaultsUsed) {
defaultsReminder.append(" ").append(d);
}
}
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getSender());
final StringBuilder sharingWithPlayers = new StringBuilder();
for (final CommandSender shareWith : parameters.getSharedPlayers()) {
sharingWithPlayers.append(shareWith.getName()).append(", ");
}
if (sharingWithPlayers.length() > 0) {
sharingWithPlayers.delete(sharingWithPlayers.lastIndexOf(","), sharingWithPlayers.length());
}
final String playersList = sharingWithPlayers.toString();
// Add current sender
parameters.addSharedPlayer(call.getSender());
for (final CommandSender player : parameters.getSharedPlayers()) {
final boolean isSender = player.getName().equals(call.getSender().getName());
if (!isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("lookup-share-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<sender>"), builder -> Component.text().content(call.getSender().getName()).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1)));
} else if (sharingWithPlayers.length() > 0) {
Component component = Il8nHelper.getMessage("lookup-share-to-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<players>"), builder -> Component.text().content(playersList).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1);
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(component));
}
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
if ((defaultsReminder.length() > 0) && isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
int resultCount = results.getIndexOfFirstResult();
for (final Handler a : paginated) {
final ActionMessage am = new ActionMessage(a);
if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
am.setResultIndex(resultCount);
MiscUtils.sendClickableTpRecord(am, player);
resultCount++;
}
MiscUtils.sendPageButtons(results, player);
} else {
Prism.messenger.sendMessage(player, Prism.messenger.playerError(Il8nHelper.getMessage("no-pagination-found")));
}
if (parameters.hasFlag(Flag.PASTE)) {
StringBuilder paste = new StringBuilder();
for (final Handler a : results.getActionResults()) {
paste.append(new ActionMessage(a).getRawMessage()).append("\r\n");
}
MiscUtils.paste_results(player, paste.toString());
}
} else {
if (defaultsReminder.length() > 0) {
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
}
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
// Flush timed data
plugin.eventTimer.printTimeRecord();
});
}
Aggregations