use of org.spongepowered.api.resourcepack.ResourcePack in project SpongeCommon by SpongePowered.
the class ResourcePackState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final net.minecraft.server.level.ServerPlayer player = phaseContext.getPacketPlayer();
final ServerGamePacketListenerImpl connection = player.connection;
final ServerGamePacketListenerImplBridge mixinHandler = (ServerGamePacketListenerImplBridge) connection;
final ServerboundResourcePackPacketAccessor resource = phaseContext.getPacket();
final ResourcePackStatusEvent.ResourcePackStatus status;
ResourcePack pack;
switch(resource.accessor$action()) {
case ACCEPTED:
pack = mixinHandler.bridge$popReceivedResourcePack(true);
status = ResourcePackStatusEvent.ResourcePackStatus.ACCEPTED;
break;
case DECLINED:
pack = mixinHandler.bridge$popReceivedResourcePack(false);
status = ResourcePackStatusEvent.ResourcePackStatus.DECLINED;
break;
case SUCCESSFULLY_LOADED:
pack = mixinHandler.bridge$popAcceptedResourcePack();
status = ResourcePackStatusEvent.ResourcePackStatus.SUCCESSFULLY_LOADED;
break;
case FAILED_DOWNLOAD:
pack = mixinHandler.bridge$popAcceptedResourcePack();
status = ResourcePackStatusEvent.ResourcePackStatus.FAILED;
break;
default:
throw new AssertionError();
}
if (pack == null) {
return;
}
SpongeCommon.post(SpongeEventFactory.createResourcePackStatusEvent(PhaseTracker.getCauseStackManager().currentCause(), pack, (ServerPlayer) player, status));
}
use of org.spongepowered.api.resourcepack.ResourcePack in project LanternServer by LanternPowered.
the class LanternResourcePackFactory method fromUri.
private ResourcePack fromUri(URI uri, boolean unchecked) throws IOException {
final CacheKey key = new CacheKey(uri, unchecked);
if (this.resourcePacksByKey.containsKey(key)) {
return this.resourcePacksByKey.get(key);
}
final String path = uri.toString();
final String plainPath = path.replaceAll("[^\\p{L}\\p{Nd}]+", "");
String hash = null;
String id = "{URI:" + path;
if (!unchecked) {
final URL url;
if (path.startsWith("level://")) {
final String path0 = path.replaceFirst("level://", "");
final Path file = this.levelPacksFolder.resolve(path0);
if (!Files.exists(file)) {
throw new FileNotFoundException("Cannot find the file: \"" + file.toAbsolutePath() + "\" which" + " is required to generate the hash for \"" + path + "\"");
}
url = PathUtils.toURL(file);
uri = file.toUri();
} else {
url = PathUtils.toURL(uri);
}
try (InputStream is = url.openStream()) {
hash = Hashing.sha1().hashBytes(ByteStreams.toByteArray(is)).toString();
}
id += ";Hash:" + hash;
}
id += "}";
final ResourcePack resourcePack = new LanternResourcePack(uri, plainPath, id, hash);
this.resourcePacks.put(id, resourcePack);
this.resourcePacksByKey.put(key, resourcePack);
return resourcePack;
}
use of org.spongepowered.api.resourcepack.ResourcePack in project LanternServer by LanternPowered.
the class ResourcePackSendQueue method poll.
public Optional<ResourcePack> poll(ResourcePackStatusEvent.ResourcePackStatus status) {
synchronized (this.queue) {
final ResourcePack resourcePack = this.waitingForResponse;
// status message for this resource pack
if (!status.wasSuccessful().isPresent()) {
this.counter = -1;
return Optional.ofNullable(resourcePack);
}
if (!this.queue.isEmpty()) {
send(this.queue.remove(0));
this.counter = 0;
} else {
this.waitingForResponse = null;
}
return Optional.ofNullable(resourcePack);
}
}
use of org.spongepowered.api.resourcepack.ResourcePack in project LanternServer by LanternPowered.
the class HandlerPlayInResourcePackStatus method handle.
@Override
public void handle(NetworkContext context, MessagePlayInResourcePackStatus message) {
final Optional<ResourcePack> resourcePack = context.getSession().getPlayer().getResourcePackSendQueue().poll(message.getStatus());
final LanternPlayer player = context.getSession().getPlayer();
if (!resourcePack.isPresent()) {
Lantern.getLogger().warn("{} received a unexpected resource pack status message ({}), no resource pack was pending", player.getName(), message.getStatus());
return;
}
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.addContext(EventContextKeys.PLAYER, player);
Sponge.getEventManager().post(SpongeEventFactory.createResourcePackStatusEvent(frame.getCurrentCause(), resourcePack.get(), player, message.getStatus()));
}
}
Aggregations