Skip to content

Commit

Permalink
Update to API changes. Some fixes
Browse files Browse the repository at this point in the history
* Account for magic entity rest velocity, fixes #149
* Add shadow setSize to MixinEntity, closes #283
  • Loading branch information
simon816 committed Nov 23, 2015
1 parent 6b75eea commit 48371fa
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 59 deletions.
16 changes: 8 additions & 8 deletions src/main/java/co/aikar/timings/TimingsExport.java
Expand Up @@ -239,8 +239,8 @@ private static JsonElement serializeConfigNode(ConfigurationNode node) {
@Override
public synchronized void start() {
if (this.sender instanceof RconSource) {
this.sender.sendMessage(Texts.of(TextColors.RED, "Warning: Timings report done over RCON will cause lag spikes."));
this.sender.sendMessage(Texts.of(TextColors.RED, "You should use ", TextColors.YELLOW,
this.sender.sendMessages(Texts.of(TextColors.RED, "Warning: Timings report done over RCON will cause lag spikes."));
this.sender.sendMessages(Texts.of(TextColors.RED, "You should use ", TextColors.YELLOW,
"/sponge timings report" + TextColors.RED, " in game or console."));
run();
} else {
Expand All @@ -250,7 +250,7 @@ public synchronized void start() {

@Override
public void run() {
this.sender.sendMessage(Texts.of(TextColors.GREEN, "Preparing Timings Report..."));
this.sender.sendMessages(Texts.of(TextColors.GREEN, "Preparing Timings Report..."));

this.out.add("data", JSONUtil.mapArray(this.history, TimingHistory::export));

Expand All @@ -275,17 +275,17 @@ public void run() {
response = getResponse(con);

if (con.getResponseCode() != 302) {
this.sender.sendMessage(Texts.of(
this.sender.sendMessages(Texts.of(
TextColors.RED, "Upload Error: " + con.getResponseCode() + ": " + con.getResponseMessage()));
this.sender.sendMessage(Texts.of(TextColors.RED, "Check your logs for more information"));
this.sender.sendMessages(Texts.of(TextColors.RED, "Check your logs for more information"));
if (response != null) {
SpongeImpl.getLogger().fatal(response);
}
return;
}

String location = con.getHeaderField("Location");
this.sender.sendMessage(Texts.of(TextColors.GREEN, "View Timings Report: ", TextActions.openUrl(new URL(location)), location));
this.sender.sendMessages(Texts.of(TextColors.GREEN, "View Timings Report: ", TextActions.openUrl(new URL(location)), location));
if (!(this.sender instanceof ConsoleSource)) {
SpongeImpl.getLogger().info("View Timings Report: " + location);
}
Expand All @@ -294,7 +294,7 @@ public void run() {
SpongeImpl.getLogger().info("Timing Response: " + response);
}
} catch (IOException ex) {
this.sender.sendMessage(Texts.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
this.sender.sendMessages(Texts.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
if (response != null) {
SpongeImpl.getLogger().fatal(response);
}
Expand All @@ -316,7 +316,7 @@ private String getResponse(HttpURLConnection con) throws IOException {
return bos.toString();

} catch (IOException ex) {
this.sender.sendMessage(Texts.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
this.sender.sendMessages(Texts.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
SpongeImpl.getLogger().warn(con.getResponseMessage(), ex);
return null;
} finally {
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/org/spongepowered/common/command/CommandSponge.java
Expand Up @@ -127,13 +127,13 @@ private abstract static class ConfigUsingExecutor implements CommandExecutor {
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
int successes = 0;
if (args.hasAny("global")) {
src.sendMessage(Texts.of("Global: ", processGlobal(SpongeImpl.getGlobalConfig(), src, args)));
src.sendMessages(Texts.of("Global: ", processGlobal(SpongeImpl.getGlobalConfig(), src, args)));
++successes;
}
if (args.hasAny("dimension")) {
for (DimensionType dimension : args.<DimensionType>getAll("dimension")) {
WorldProvider provider = DimensionManager.getWorldFromDimId(((SpongeDimensionType) dimension).getDimensionTypeId()).provider;
src.sendMessage(Texts.of("Dimension ", dimension.getName(), ": ", processDimension(((IMixinWorldProvider) provider)
src.sendMessages(Texts.of("Dimension ", dimension.getName(), ": ", processDimension(((IMixinWorldProvider) provider)
.getDimensionConfig(), dimension, src, args)));
++successes;
}
Expand All @@ -144,7 +144,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
if (!world.isPresent()) {
throw new CommandException(Texts.of("World ", properties.getWorldName(), " is not loaded, cannot work with it"));
}
src.sendMessage(Texts.of("World ", properties.getWorldName(), ": ", processWorld(((IMixinWorld) world.get()).getWorldConfig(),
src.sendMessages(Texts.of("World ", properties.getWorldName(), ": ", processWorld(((IMixinWorld) world.get()).getWorldConfig(),
world.get(), src, args)));
++successes;
}
Expand Down Expand Up @@ -189,9 +189,9 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
if (args.hasAny("dump")) {
File file = new File(new File(new File("."), "chunk-dumps"),
"chunk-info-" + new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss").format(new Date()) + "-server.txt");
src.sendMessage(Texts.of("Writing chunk info to: ", file));
src.sendMessages(Texts.of("Writing chunk info to: ", file));
ChunkSaveHelper.writeChunks(file, args.hasAny("dump-all"));
src.sendMessage(Texts.of("Chunk info complete"));
src.sendMessages(Texts.of("Chunk info complete"));
}
return res;
}
Expand All @@ -200,7 +200,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
protected Text processGlobal(SpongeConfig<SpongeConfig.GlobalConfig> config, CommandSource source, CommandContext args)
throws CommandException {
for (World world : SpongeImpl.getGame().getServer().getWorlds()) {
source.sendMessage(Texts.of("World ", Texts.of(TextStyles.BOLD, world.getName()),
source.sendMessages(Texts.of("World ", Texts.of(TextStyles.BOLD, world.getName()),
getChunksInfo(((WorldServer) world))));
}
return Texts.of("Printed chunk info for all worlds ");
Expand All @@ -211,7 +211,7 @@ protected Text processDimension(SpongeConfig<SpongeConfig.DimensionConfig> confi
CommandContext args)
throws CommandException {
SpongeImpl.getGame().getServer().getWorlds().stream().filter(world -> world.getDimension().getType().equals(dim))
.forEach(world -> source.sendMessage(Texts.of("World ", Texts.of(TextStyles.BOLD, world.getName()),
.forEach(world -> source.sendMessages(Texts.of("World ", Texts.of(TextStyles.BOLD, world.getName()),
getChunksInfo(((WorldServer) world)))));
return Texts.of("Printed chunk info for all worlds in dimension ", dim.getName());
}
Expand Down Expand Up @@ -310,9 +310,9 @@ private static CommandSpec getHeapCommand() {
.executor((src, args) -> {
File file = new File(new File(new File("."), "dumps"),
"heap-dump-" + new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss").format(new Date()) + "-server.bin");
src.sendMessage(Texts.of("Writing JVM heap data to: ", file));
src.sendMessages(Texts.of("Writing JVM heap data to: ", file));
SpongeHooks.dumpHeap(file, true);
src.sendMessage(Texts.of("Heap dump complete"));
src.sendMessages(Texts.of("Heap dump complete"));
return CommandResult.success();
})
.build();
Expand All @@ -325,7 +325,7 @@ private static CommandSpec getVersionCommand() {
.description(Texts.of("Display Sponge's current version"))
.permission("sponge.command.version")
.executor((src, args) -> {
src.sendMessage(Texts.of("SpongeMod: ", title(SpongeImpl.getGame().getPlatform().getVersion()), "\n",
src.sendMessages(Texts.of("SpongeMod: ", title(SpongeImpl.getGame().getPlatform().getVersion()), "\n",
"SpongeAPI: ", title(SpongeImpl.getGame().getPlatform().getApiVersion())));
return CommandResult.success();
})
Expand Down Expand Up @@ -382,7 +382,7 @@ private static CommandSpec getPluginsCommand() {
INDENT, title("Main class: "), container.getInstance() == null ? " Virtual mod " :
container.getInstance().getClass().getCanonicalName()));
// TODO: Provide more metadata once it is exposed
src.sendMessage(build.build());
src.sendMessages(build.build());

}
} else {
Expand All @@ -399,7 +399,7 @@ INDENT, title("Main class: "), container.getInstance() == null ? " Virtual mod "
.onHover(TextActions.showText(Texts.of("Version " + next.getVersion())))
.color(TextColors.GREEN).build());
}
src.sendMessage(build.build());
src.sendMessages(build.build());
}
return CommandResult.success();
}).build();
Expand All @@ -412,18 +412,18 @@ private static CommandCallable getTimingsCommand() {
.child(CommandSpec.builder()
.executor((src, args) -> {
if (!Timings.isTimingsEnabled()) {
src.sendMessage(Texts.of("Please enable timings by typing /sponge timings on"));
src.sendMessages(Texts.of("Please enable timings by typing /sponge timings on"));
return CommandResult.empty();
}
Timings.reset();
src.sendMessage(Texts.of("Timings reset"));
src.sendMessages(Texts.of("Timings reset"));
return CommandResult.success();
})
.build(), "reset")
.child(CommandSpec.builder()
.executor((src, args) -> {
if (!Timings.isTimingsEnabled()) {
src.sendMessage(Texts.of("Please enable timings by typing /sponge timings on"));
src.sendMessages(Texts.of("Please enable timings by typing /sponge timings on"));
return CommandResult.empty();
}
Timings.generateReport(src);
Expand All @@ -433,46 +433,46 @@ private static CommandCallable getTimingsCommand() {
.child(CommandSpec.builder()
.executor((src, args) -> {
Timings.setTimingsEnabled(true);
src.sendMessage(Texts.of("Enabled Timings & Reset"));
src.sendMessages(Texts.of("Enabled Timings & Reset"));
return CommandResult.success();
})
.build(), "on")
.child(CommandSpec.builder()
.executor((src, args) -> {
Timings.setTimingsEnabled(false);
src.sendMessage(Texts.of("Disabled Timings"));
src.sendMessages(Texts.of("Disabled Timings"));
return CommandResult.success();
})
.build(), "off")
.child(CommandSpec.builder()
.executor((src, args) -> {
if (!Timings.isTimingsEnabled()) {
src.sendMessage(Texts.of("Please enable timings by typing /sponge timings on"));
src.sendMessages(Texts.of("Please enable timings by typing /sponge timings on"));
return CommandResult.empty();
}
Timings.setVerboseTimingsEnabled(true);
src.sendMessage(Texts.of("Enabled Verbose Timings"));
src.sendMessages(Texts.of("Enabled Verbose Timings"));
return CommandResult.success();
})
.build(), "verbon")
.child(CommandSpec.builder()
.executor((src, args) -> {
if (!Timings.isTimingsEnabled()) {
src.sendMessage(Texts.of("Please enable timings by typing /sponge timings on"));
src.sendMessages(Texts.of("Please enable timings by typing /sponge timings on"));
return CommandResult.empty();
}
Timings.setVerboseTimingsEnabled(false);
src.sendMessage(Texts.of("Disabled Verbose Timings"));
src.sendMessages(Texts.of("Disabled Verbose Timings"));
return CommandResult.success();
})
.build(), "verboff")
.child(CommandSpec.builder()
.executor((src, args) -> {
if (!Timings.isTimingsEnabled()) {
src.sendMessage(Texts.of("Please enable timings by typing /sponge timings on"));
src.sendMessages(Texts.of("Please enable timings by typing /sponge timings on"));
return CommandResult.empty();
}
src.sendMessage(Texts.of("Timings cost: " + SpongeTimingsFactory.getCost()));
src.sendMessages(Texts.of("Timings cost: " + SpongeTimingsFactory.getCost()));
return CommandResult.success();
})
.build(), "cost")
Expand Down
Expand Up @@ -63,14 +63,14 @@ public Optional<CommandMapping> disambiguate(CommandSource source, String aliasU
Optional<PluginContainer> container = this.game.getPluginManager().getPlugin(chosenPlugin);
if (!container.isPresent()) {
SpongeImpl
.getGame().getServer().getConsole().sendMessage(t("Unable to find plugin '" + chosenPlugin + "' for command '" + aliasUsed
.getGame().getServer().getConsole().sendMessages(t("Unable to find plugin '" + chosenPlugin + "' for command '" + aliasUsed
+ "', falling back to default"));
} else {
final Set<CommandMapping> ownedCommands = this.game.getCommandDispatcher().getOwnedBy(container.get());
final List<CommandMapping> ownedMatchingCommands = ImmutableList.copyOf(Iterables.filter(availableOptions,
Predicates.in(ownedCommands)));
if (ownedMatchingCommands.isEmpty()) {
SpongeImpl.getGame().getServer().getConsole().sendMessage(t("Plugin " + container.get().getName() + " was specified as the "
SpongeImpl.getGame().getServer().getConsole().sendMessages(t("Plugin " + container.get().getName() + " was specified as the "
+ "preferred owner for " + aliasUsed + ", but does not have any such command!"));
} else if (ownedMatchingCommands.size() > 1) {
throw new IllegalStateException("Plugin " + container.get().getName() + " seems to have multiple commands registered as "
Expand Down
Expand Up @@ -69,9 +69,9 @@ public static CommandSpec create() {
CommandCallable callable = mapping.get().getCallable();
Optional<? extends Text> desc = callable.getHelp(src);
if (desc.isPresent()) {
src.sendMessage(desc.get());
src.sendMessages(desc.get());
} else {
src.sendMessage(Texts.of("Usage: /", command.get(), callable.getUsage(src)));
src.sendMessages(Texts.of("Usage: /", command.get(), callable.getUsage(src)));
}
return CommandResult.success();
}
Expand Down
Expand Up @@ -97,14 +97,14 @@ public String getName() {
}

@Override
public void sendMessage(Text... messages) {
public void sendMessages(Text... messages) {
for (Text text : messages) {
this.sender.addChatMessage(SpongeTexts.toComponent(text));
}
}

@Override
public void sendMessage(Iterable<Text> messages) {
public void sendMessages(Iterable<Text> messages) {
for (Text text : messages) {
this.sender.addChatMessage(SpongeTexts.toComponent(text));
}
Expand Down
Expand Up @@ -62,7 +62,7 @@ public IChatComponent getDisplayName() {

@Override
public void addChatMessage(IChatComponent component) {
this.source.sendMessage(SpongeTexts.toText(component));
this.source.sendMessages(SpongeTexts.toText(component));
}

@Override
Expand Down
Expand Up @@ -48,6 +48,11 @@

public class VelocityDataProcessor extends AbstractEntityDataProcessor<Entity, VelocityData, ImmutableVelocityData> {

// EntityLivingBase.moveEntityWithHeading sets y-velocity at this value when
// entity is at rest. Value is -0.08 * 0.9800000190734863. See
// https://github.com/SpongePowered/SpongeCommon/issues/149#issuecomment-158832297
public static final float ENTITY_REST_Y_VEL = -0.0784000015258789F;

public VelocityDataProcessor() {
super(Entity.class);
}
Expand Down Expand Up @@ -75,7 +80,7 @@ protected boolean set(Entity entity, Map<Key<?>, Object> keyValues) {
@Override
protected Map<Key<?>, ?> getValues(Entity entity) {
final double xVel = entity.motionX;
final double yVel = entity.motionY;
final double yVel = entity.motionY == ENTITY_REST_Y_VEL ? 0 : entity.motionY;
final double zVel = entity.motionZ;
return ImmutableMap.<Key<?>, Object>of(Keys.VELOCITY, new Vector3d(xVel, yVel, zVel));
}
Expand Down

0 comments on commit 48371fa

Please sign in to comment.