use of org.spongepowered.api.text.channel.MessageReceiver in project modules-extra by CubeEngine.
the class MuteListener method onChat.
@Listener
public void onChat(MessageChannelEvent.Chat event, @First Player source) {
// muted?
Date muted = muteCmd.getMuted(source);
if (muted != null && System.currentTimeMillis() < muted.getTime()) {
event.setCancelled(true);
i18n.send(source, NEGATIVE, "You try to speak but nothing happens!");
return;
}
// ignored?
for (Iterator<MessageReceiver> iterator = event.getChannel().get().getMembers().iterator(); iterator.hasNext(); ) {
final MessageReceiver player = iterator.next();
if (player instanceof Player) {
if (this.ignoreCmd.checkIgnored(((Player) player), source)) {
iterator.remove();
}
}
}
}
use of org.spongepowered.api.text.channel.MessageReceiver in project LanternServer by LanternPowered.
the class ActivePagination method specificPage.
public void specificPage(int page) throws CommandException {
MessageReceiver src = this.src.get();
if (src == null) {
throw new CommandException(t("Source for pagination %s is no longer active!", getId()));
}
this.currentPage = page;
List<Text> toSend = new ArrayList<>();
Text title = this.title;
if (title != null) {
toSend.add(title);
}
if (this.header != null) {
toSend.add(this.header);
}
for (Text line : getLines(page)) {
toSend.add(line);
}
Text footer = calculateFooter(page);
toSend.add(this.calc.center(footer, this.padding));
if (this.footer != null) {
toSend.add(this.footer);
}
src.sendMessages(toSend);
}
use of org.spongepowered.api.text.channel.MessageReceiver in project Nucleus by NucleusPowered.
the class NucleusTeleportHandler method teleportPlayer.
private TeleportResult teleportPlayer(Player player, Location<World> locationToTeleportTo, Vector3d rotation, TeleportMode teleportMode, Cause cause, boolean addOffset) {
Optional<Location<World>> targetLocation = getSafeLocation(player, locationToTeleportTo, teleportMode);
if (targetLocation.isPresent() && Util.isLocationInWorldBorder(targetLocation.get())) {
AboutToTeleportEvent event = new AboutToTeleportEvent(cause, new Transform<>(targetLocation.get().getExtent(), targetLocation.get().getPosition(), rotation), player);
if (Sponge.getEventManager().post(event)) {
event.getCancelMessage().ifPresent(x -> {
Object o = cause.root();
if (o instanceof MessageReceiver) {
((MessageReceiver) o).sendMessage(x);
}
});
return TeleportResult.FAILED_CANCELLED;
}
Optional<Entity> oe = player.getVehicle();
if (oe.isPresent()) {
player.setVehicle(null);
}
// Do it, tell the routine if it worked.
TeleportResult tr;
if (addOffset) {
tr = result(player.setLocationAndRotation(targetLocation.get().add(0.5, 0.5, 0.5), rotation));
} else {
tr = result(player.setLocationAndRotation(targetLocation.get(), rotation));
}
if (tr.isSuccess()) {
player.setSpectatorTarget(null);
} else {
oe.ifPresent(player::setVehicle);
}
return tr;
}
return TeleportResult.FAILED_NO_LOCATION;
}
use of org.spongepowered.api.text.channel.MessageReceiver in project Nucleus by NucleusPowered.
the class NucleusPlugin method onPreInit.
@Listener
public void onPreInit(GamePreInitializationEvent preInitializationEvent) {
// Setup object mapper.
MessageReceiver s;
if (Sponge.getGame().isServerAvailable()) {
s = Sponge.getServer().getConsole();
} else {
s = new ClientMessageReciever();
}
if (this.versionFail != null) {
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat", PluginInfo.NAME, Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(), Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown")));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat2", this.versionFail));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat3", this.versionFail));
disable();
return;
}
s.sendMessage(Text.of(TextColors.WHITE, "--------------------------"));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome", PluginInfo.NAME, PluginInfo.VERSION, Sponge.getPlatform().getContainer(Platform.Component.API).getVersion().orElse("unknown")));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome2"));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome3"));
s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome4"));
s.sendMessage(Text.of(TextColors.WHITE, "--------------------------"));
logger.info(messageProvider.getMessageWithFormat("startup.preinit", PluginInfo.NAME));
Game game = Sponge.getGame();
NucleusAPITokens.onPreInit(this);
// Startup tasks, for the migrations I need to do.
PreloadTasks.getPreloadTasks().forEach(x -> x.accept(this));
// Get the mandatory config files.
try {
Files.createDirectories(this.configDir);
if (this.isServer) {
Files.createDirectories(this.dataDir.get());
}
this.commandsConfig = new CommandsConfig(Paths.get(configDir.toString(), "commands.conf"));
DataProviders d = new DataProviders(this);
this.generalService = new ModularGeneralService(d.getGeneralDataProvider());
this.itemDataService = new ItemDataService(d.getItemDataProvider());
this.itemDataService.loadInternal();
this.userDataManager = new UserDataManager(d::getUserFileDataProviders, d::doesUserFileExist);
this.worldDataManager = new WorldDataManager(d::getWorldFileDataProvider, d::doesWorldFileExist);
this.kitService = new KitService(d.getKitsDataProvider());
this.nameBanService = new NameBanService(d.getNameBanDataProvider());
this.userCacheService = new UserCacheService(d.getUserCacheDataProvider());
this.warmupManager = new WarmupManager();
this.textParsingUtils = new TextParsingUtils(this);
this.nameUtil = new NameUtil(this);
if (this.isServer) {
allChange();
}
} catch (Exception e) {
this.isErrored = e;
disable();
e.printStackTrace();
return;
}
PreloadTasks.getPreloadTasks2().forEach(x -> x.accept(this));
// We register the ModuleService NOW so that others can hook into it.
game.getServiceManager().setProvider(this, NucleusModuleService.class, new ModuleRegistrationProxyService(this));
game.getServiceManager().setProvider(this, NucleusWarmupManagerService.class, warmupManager);
serviceManager.registerService(WarmupManager.class, warmupManager);
nucleusChatService = new NucleusTokenServiceImpl(this);
serviceManager.registerService(NucleusTokenServiceImpl.class, nucleusChatService);
Sponge.getServiceManager().setProvider(this, NucleusMessageTokenService.class, nucleusChatService);
try {
final String he = this.messageProvider.getMessageWithFormat("config.main-header", PluginInfo.VERSION);
HoconConfigurationLoader.Builder builder = HoconConfigurationLoader.builder();
Optional<Asset> optionalAsset = Sponge.getAssetManager().getAsset(Nucleus.getNucleus(), "classes.json");
DiscoveryModuleContainer.Builder db = DiscoveryModuleContainer.builder();
if (optionalAsset.isPresent()) {
Map<String, Map<String, List<String>>> m = new Gson().fromJson(optionalAsset.get().readString(), new TypeToken<Map<String, Map<String, List<String>>>>() {
}.getType());
Set<Class<?>> sc = Sets.newHashSet();
for (String classString : m.keySet()) {
sc.add(Class.forName(classString));
}
db.setStrategy((string, classloader) -> sc).setConstructor(new QuickStartModuleConstructor(m));
} else {
db.setConstructor(new QuickStartModuleConstructor(null)).setStrategy(Strategy.DEFAULT);
}
this.moduleContainer = db.setConfigurationLoader(builder.setDefaultOptions(ConfigurateHelper.setOptions(builder.getDefaultOptions()).setHeader(he)).setPath(Paths.get(configDir.toString(), "main.conf")).build()).setPackageToScan(getClass().getPackage().getName() + ".modules").setLoggerProxy(new NucleusLoggerProxy(logger)).setConfigurationOptionsTransformer(x -> ConfigurateHelper.setOptions(x).setHeader(he)).setOnPreEnable(() -> {
initDocGenIfApplicable();
Sponge.getEventManager().post(new BaseModuleEvent.AboutToEnable(this));
}).setOnEnable(() -> {
Sponge.getEventManager().post(new BaseModuleEvent.PreEnable(this));
}).setOnPostEnable(() -> Sponge.getEventManager().post(new BaseModuleEvent.Enabled(this))).setRequireModuleDataAnnotation(true).setNoMergeIfPresent(true).setModuleConfigurationHeader(m -> {
StringBuilder ssb = new StringBuilder().append(divider).append("\n");
String name = m.getClass().getAnnotation(ModuleData.class).name();
int nameLength = name.length() + 2;
int dashes = (length - nameLength) / 2;
ssb.append("|");
for (int i = 0; i < dashes; i++) {
ssb.append(" ");
}
ssb.append(" ").append(name).append(" ");
for (int i = 0; i < dashes; i++) {
ssb.append(" ");
}
if (length > dashes * 2 + nameLength) {
ssb.append(" ");
}
return ssb.append("|").append("\n").append(divider).toString();
}).setModuleConfigSectionName("-modules").setModuleConfigSectionDescription(this.messageProvider.getMessageWithFormat("config.module-desc")).setModuleDescriptionHandler(m -> this.messageProvider.getMessageWithFormat("config.module." + m.getAnnotation(ModuleData.class).id().toLowerCase() + ".desc")).build();
moduleContainer.startDiscover();
} catch (Exception e) {
isErrored = e;
disable();
e.printStackTrace();
}
}
Aggregations