下面列出了org.bukkit.command.ConsoleCommandSender#sendMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void logToFile(String message) {
ConsoleCommandSender console = SkyWarsReloaded.get().getServer().getConsoleSender();
console.sendMessage(message);
try {
File dataFolder = SkyWarsReloaded.get().getDataFolder();
if (dataFolder.exists() || dataFolder.mkdir()) {
File saveTo = new File(dataFolder, "DebugLog.txt");
if (saveTo.exists() || saveTo.createNewFile()) {
FileWriter fw = new FileWriter(saveTo, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(ChatColor.stripColor(message));
pw.flush();
pw.close();
}
}
} catch(IOException e){
e.printStackTrace();
}
}
protected void runUpdate() {
String configBackup = backupConfig();
ConsoleCommandSender console = Bukkit.getConsoleSender();
console.sendMessage(getCratesPlus().getPluginPrefix() + ChatColor.GREEN + "Converting config to version " + getVersion() + "...");
update();
getConfig().set("Config Version", getVersion());
save();
console.sendMessage(getCratesPlus().getPluginPrefix() + ChatColor.GREEN + "Conversion of config has completed.");
if (configBackup != null && !configBackup.equalsIgnoreCase("")) {
getCratesPlus().setConfigBackup(configBackup);
console.sendMessage(getCratesPlus().getPluginPrefix() + ChatColor.GREEN + "Your old config was backed up to " + configBackup);
}
}
private void checkConfigVersions(Configuration config, Path dataFolder) {
if (config.getInt("config-version") < DefaultConfig.CURRENT_CONFIG_VERSION) {
Path configSource = dataFolder.resolve(ConfigType.DEFAULT_CONFIG.getDestinationFileName());
Path configTarget = dataFolder.resolve("config_old.yml");
try {
Files.move(configSource, configTarget, StandardCopyOption.REPLACE_EXISTING);
URL configResource = getClass().getResource(ConfigType.DEFAULT_CONFIG.getClasspathResourceName());
copyResource(configResource, configSource.toFile());
ConsoleCommandSender sender = Bukkit.getConsoleSender();
sender.sendMessage(ChatColor.RED + "Due to a HeavySpleef update your old configuration has been renamed");
sender.sendMessage(ChatColor.RED + "to config_old.yml and a new one has been generated. Make sure to");
sender.sendMessage(ChatColor.RED + "apply your old changes to the new config");
} catch (IOException e) {
getLogger().log(Level.SEVERE, "Could not create updated configuration due to an IOException", e);
}
}
}
private void initializeGameComponents() {
try {
Class<? extends IEntityRegistry> entityRegistry = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntityRegistry").asSubclass(IEntityRegistry.class);
GameRegistry.registerPermanently(IEntityRegistry.class, new Reflection().reflect(entityRegistry).getSafeConstructor().getAccessor().invoke());
Class<? extends IEntitySpawnHandler> spawnHandler = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntitySpawnHandler").asSubclass(IEntitySpawnHandler.class);
GameRegistry.register(IEntitySpawnHandler.class, new Reflection().reflect(spawnHandler).getSafeConstructor().getAccessor().invoke());
} catch (Exception e) {
ConsoleCommandSender console = this.getServer().getConsoleSender();
console.sendMessage(ChatColor.RED + "-------------------------------");
console.sendMessage(ChatColor.RED + "Failed to initialize the game components!");
console.sendMessage(ChatColor.RED + "-------------------------------");
}
}
public void sendConsoleHelp(ConsoleCommandSender console) {
console.sendMessage(i18nonly("help_title_console").replace("%version%", "Zero " + Main.getVersion()));
console.sendMessage(i18nonly("help_bw_list"));
console.sendMessage(i18nonly("help_bw_stats_other"));
console.sendMessage(i18nonly("help_bw_alljoin"));
console.sendMessage(i18nonly("help_bw_reload"));
}
public void sendConsoleHelp(ConsoleCommandSender console) {
console.sendMessage(i18nonly("help_title_console").replace("%version%", "Zero " + Main.getVersion()));
console.sendMessage(i18nonly("help_bw_list"));
console.sendMessage(i18nonly("help_bw_stats_other"));
console.sendMessage(i18nonly("help_bw_alljoin"));
console.sendMessage(i18nonly("help_bw_reload"));
}
/**
* Guilds logLogo in console
*/
public static void logLogo(ConsoleCommandSender sender, Plugin plugin) {
sender.sendMessage(StringUtils.color("&a ________ "));
sender.sendMessage(StringUtils.color("&a / _____/ "));
sender.sendMessage(StringUtils.color("&a/ \\ ___ " + " &3Guilds &8v" + plugin.getDescription().getVersion()));
sender.sendMessage(StringUtils.color("&a\\ \\_\\ \\" + " &3Server Version: &8" + plugin.getServer().getVersion()));
sender.sendMessage(StringUtils.color("&a \\______ /"));
sender.sendMessage(StringUtils.color("&a \\/ "));
}
@Override
public void debug(final String s) {
ConsoleCommandSender console = Bukkit.getConsoleSender();
if (console != null) {
console.sendMessage(BBC.color(s));
} else {
Bukkit.getLogger().info(BBC.color(s));
}
}
private void checkUpdate(final ConsoleCommandSender console) {
String updateBranch = getConfig().getString("Update Branch");
if (getDescription().getVersion().contains("SNAPSHOT"))
updateBranch = "snapshot";//Force snapshot branch on snapshot builds
String branch = updateBranch.toLowerCase();
if (branch.equalsIgnoreCase("snapshot")) {
console.sendMessage(ChatColor.RED + "WARNING: Snapshot updates are not recommended on production servers");
}
console.sendMessage(ChatColor.GREEN + "Checking for updates via " + branch + " branch...");
final LinfootUpdater updater = new LinfootUpdater(this, branch);
final LinfootUpdater.UpdateResult snapShotResult = updater.getResult();
switch (snapShotResult) {
default:
case FAILED:
updateAvailable = false;
updateMessage = pluginPrefix + "Failed to check for updates. Will try again later.";
getServer().getScheduler().runTaskLaterAsynchronously(this, () -> checkUpdate(console), 60 * (60 * 20L)); // Checks again an hour later
break;
case NO_UPDATE:
updateAvailable = false;
updateMessage = pluginPrefix + "No update was found, you are running the latest version. Will check again later.";
getServer().getScheduler().runTaskLaterAsynchronously(this, () -> checkUpdate(console), 60 * (60 * 20L)); // Checks again an hour later
break;
case SNAPSHOT_UPDATE_AVAILABLE:
updateAvailable = true;
updateMessage = pluginPrefix + "A snapshot update for CratesPlus is available, new version is " + updater.getVersion() + ". Your installed version is " + getDescription().getVersion() + ".\nPlease update to the latest version :)";
break;
case UPDATE_AVAILABLE:
updateAvailable = true;
updateMessage = pluginPrefix + "An update for CratesPlus is available, new version is " + updater.getVersion() + ". Your installed version is " + getDescription().getVersion() + ".\nPlease update to the latest version :)";
break;
}
if (updateMessage != null)
console.sendMessage(updateMessage);
}
@Subcommand("props") @CommandPermission("%srProps")
@CommandCompletion("@players")
@Description("%helpSrProps")
public void onProps(CommandSender sender, OnlinePlayer target) {
try {
Object ep = ReflectionUtil.invokeMethod(target.getPlayer(), "getHandle");
Object profile = ReflectionUtil.invokeMethod(ep, "getProfile");
Object propmap = ReflectionUtil.invokeMethod(profile, "getProperties");
Collection<?> props = (Collection<?>) ReflectionUtil.invokeMethod(propmap.getClass(), propmap, "get",
new Class[]{Object.class}, "textures");
if (props == null || props.isEmpty()) {
sender.sendMessage(Locale.NO_SKIN_DATA);
return;
}
for (Object prop : props) {
String name = (String) ReflectionUtil.invokeMethod(prop, "getName");
String value = (String) ReflectionUtil.invokeMethod(prop, "getValue");
String signature = (String) ReflectionUtil.invokeMethod(prop, "getSignature");
ConsoleCommandSender cons = Bukkit.getConsoleSender();
cons.sendMessage("\n§aName: §8" + name);
cons.sendMessage("\n§aValue : §8" + value);
cons.sendMessage("\n§aSignature : §8" + signature);
byte[] decoded = Base64.getDecoder().decode(value);
cons.sendMessage("\n§aValue Decoded: §e" + Arrays.toString(decoded));
sender.sendMessage("\n§e" + Arrays.toString(decoded));
sender.sendMessage("§cMore info in console!");
}
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(Locale.NO_SKIN_DATA);
return;
}
sender.sendMessage("§cMore info in console!");
}