Java Code Examples for net.minecraft.server.command.ServerCommandSource#getPlayer()
The following examples show how to use
net.minecraft.server.command.ServerCommandSource#getPlayer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CarpetScriptHost.java From fabric-carpet with MIT License | 6 votes |
public CarpetScriptHost retrieveForExecution(ServerCommandSource source) { CarpetScriptHost host = this; if (perUser) { try { ServerPlayerEntity player = source.getPlayer(); host = (CarpetScriptHost) retrieveForExecution(player.getName().getString()); } catch (CommandSyntaxException e) { host = (CarpetScriptHost) retrieveForExecution((String) null); } } if (host.errorSnooper == null) host.setChatErrorSnooper(source); return host; }
Example 2
Source File: TickCommand.java From fabric-carpet with MIT License | 6 votes |
private static int setWarp(ServerCommandSource source, int advance, String tail_command) { ServerPlayerEntity player = null; try { player = source.getPlayer(); } catch (CommandSyntaxException ignored) { } BaseText message = TickSpeed.tickrate_advance(player, advance, tail_command, source); if (message != null) { source.sendFeedback(message, false); } return 1; }
Example 3
Source File: SpawnCommand.java From fabric-carpet with MIT License | 5 votes |
private static int runTest(ServerCommandSource source, int ticks, String counter) { //stop tracking SpawnReporter.reset_spawn_stats(false); //start tracking SpawnReporter.track_spawns = (long) source.getMinecraftServer().getTicks(); //counter reset if (counter == null) { HopperCounter.resetAll(source.getMinecraftServer()); } else { HopperCounter hCounter = HopperCounter.getCounter(counter); if (hCounter != null) hCounter.reset(source.getMinecraftServer()); } // tick warp 0 TickSpeed.tickrate_advance(null, 0, null, null); // tick warp given player ServerCommandSource csource = null; ServerPlayerEntity player = null; try { player = source.getPlayer(); csource = source; } catch (CommandSyntaxException ignored) { } TickSpeed.tickrate_advance(player, ticks, null, csource); Messenger.m(source, String.format("gi Started spawn test for %d ticks", ticks)); return 1; }
Example 4
Source File: CameraModeCommand.java From fabric-carpet with MIT License | 5 votes |
private static boolean iCanHasPermissions(ServerCommandSource source, ServerPlayerEntity player) { try { return source.hasPermissionLevel(2) || source.getPlayer() == player; } catch (CommandSyntaxException e) { return true; // shoudn't happen because server has all permissions anyways } }
Example 5
Source File: SettingsManager.java From fabric-carpet with MIT License | 5 votes |
private int listAllSettings(ServerCommandSource source) { //listSettings(source, "Current "+fancyName+" Settings", getNonDefault()); listSettings(source, String.format(tr("ui.current_%(mod)s_settings","Current %s Settings"), fancyName), getNonDefault()); if (version != null) //Messenger.m(source, "g "+fancyName+" version: "+ version); Messenger.m(source, "g "+fancyName+" "+ tr("ui.version", "version") + ": "+ version); try { PlayerEntity player = source.getPlayer(); List<Object> tags = new ArrayList<>(); //tags.add("w Browse Categories:\n"); tags.add("w " + tr("ui.browse_categories", "Browse Categories") + ":\n"); for (String t : getCategories()) { String catKey = "category." + t; String translated = tr(catKey, t); String translatedPlus = Translations.hasTranslation(catKey) ? String.format("%s (%s)",tr(catKey, t), t) : t; tags.add("c [" + translated +"]"); //tags.add("^g list all " + translated + " settings"); tags.add("^g " + String.format(tr("ui.list_all_%(cat)s_settings","list all %s settings"), translatedPlus)); tags.add("!/"+identifier+" list " + t); tags.add("w "); } tags.remove(tags.size() - 1); Messenger.m(player, tags.toArray(new Object[0])); } catch (CommandSyntaxException ignored) { } return 1; }
Example 6
Source File: CarpetScriptHost.java From fabric-carpet with MIT License | 4 votes |
public void setChatErrorSnooper(ServerCommandSource source) { responsibleSource = source; errorSnooper = (expr, /*Nullable*/ token, message) -> { try { source.getPlayer(); } catch (CommandSyntaxException e) { return null; } String shebang = message; if (expr.module != null) { shebang += " in " + expr.module.getName() + ""; } else { shebang += " in system chat"; } if (token != null) { String[] lines = expr.getCodeString().split("\n"); if (lines.length > 1) { shebang += " at line " + (token.lineno + 1) + ", pos " + (token.linepos + 1); } else { shebang += " at pos " + (token.pos + 1); } Messenger.m(source, "r " + shebang); if (lines.length > 1 && token.lineno > 0) { Messenger.m(source, "l " + lines[token.lineno - 1]); } Messenger.m(source, "l " + lines[token.lineno].substring(0, token.linepos), "r HERE>> ", "l " + lines[token.lineno].substring(token.linepos)); if (lines.length > 1 && token.lineno < lines.length - 1) { Messenger.m(source, "l " + lines[token.lineno + 1]); } } else { Messenger.m(source, "r " + shebang); } return new ArrayList<>(); }; }
Example 7
Source File: LogCommand.java From fabric-carpet with MIT License | 4 votes |
private static int listLogs(ServerCommandSource source) { PlayerEntity player; try { player = source.getPlayer(); } catch (CommandSyntaxException e) { Messenger.m(source, "For players only"); return 0; } Map<String,String> subs = LoggerRegistry.getPlayerSubscriptions(source.getName()); if (subs == null) { subs = new HashMap<>(); } List<String> all_logs = new ArrayList<>(LoggerRegistry.getLoggerNames()); Collections.sort(all_logs); Messenger.m(player, "w _____________________"); Messenger.m(player, "w Available logging options:"); for (String lname: all_logs) { List<Object> comp = new ArrayList<>(); String color = subs.containsKey(lname)?"w":"g"; comp.add("w - "+lname+": "); Logger logger = LoggerRegistry.getLogger(lname); String [] options = logger.getOptions(); if (options.length == 0) { if (subs.containsKey(lname)) { comp.add("l Subscribed "); } else { comp.add(color + " [Subscribe] "); comp.add("^w subscribe to " + lname); comp.add("!/log " + lname); } } else { for (String option : logger.getOptions()) { if (subs.containsKey(lname) && subs.get(lname).equalsIgnoreCase(option)) { comp.add("l [" + option + "] "); } else { comp.add(color + " [" + option + "] "); comp.add("^w subscribe to " + lname + " " + option); comp.add("!/log " + lname + " " + option); } } } if (subs.containsKey(lname)) { comp.add("nb [X]"); comp.add("^w Click to unsubscribe"); comp.add("!/log "+lname); } Messenger.m(player,comp.toArray(new Object[0])); } return 1; }
Example 8
Source File: SettingsManager.java From fabric-carpet with MIT License | 4 votes |
private int displayRuleMenu(ServerCommandSource source, ParsedRule<?> rule) { PlayerEntity player; String displayName = rule.translatedName(); try { player = source.getPlayer(); } catch (CommandSyntaxException e) { Messenger.m(source, "w "+ displayName +" "+ tr( "ui.is_set_to","is set to")+": ","wb "+rule.getAsString()); return 1; } Messenger.m(player, ""); Messenger.m(player, "wb "+ displayName ,"!/"+identifier+" "+rule.name,"^g refresh"); Messenger.m(player, "w "+ rule.translatedDescription()); rule.translatedExtras().forEach(s -> Messenger.m(player, "g "+s)); List<BaseText> tags = new ArrayList<>(); tags.add(Messenger.c("w "+ tr("ui.tags", "Tags")+": ")); for (String t: rule.categories) { String translated = tr("category." + t, t); tags.add(Messenger.c("c ["+ translated +"]", "^g "+ String.format(tr("list_all_%s_settings","list all %s settings"), translated),"!/"+identifier+" list "+t)); tags.add(Messenger.c("w , ")); } tags.remove(tags.size()-1); Messenger.m(player, tags.toArray(new Object[0])); Messenger.m(player, "w "+ tr("ui.current_value", "Current value")+": ",String.format("%s %s (%s value)",rule.getBoolValue()?"lb":"nb", rule.getAsString(),rule.isDefault()?"default":"modified")); List<BaseText> options = new ArrayList<>(); options.add(Messenger.c("w Options: ", "y [ ")); for (String o: rule.options) { options.add(makeSetRuleButton(rule, o, false)); options.add(Messenger.c("w ")); } options.remove(options.size()-1); options.add(Messenger.c("y ]")); Messenger.m(player, options.toArray(new Object[0])); return 1; }