forked from LogBlock/LogBlock
replace deprecated api usage
This commit is contained in:
@@ -113,7 +113,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
@@ -127,7 +127,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
BlockData replaced = getBlockReplaced();
|
||||
if (type == null || replaced == null) {
|
||||
msg.addExtra("did an unknown block modification");
|
||||
return new BaseComponent[] { msg };
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Process type details once for later use.
|
||||
@@ -254,7 +254,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
msg.addExtra(" at ");
|
||||
msg.addExtra(prettyLocation(loc, entry));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
return msg;
|
||||
}
|
||||
|
||||
public BlockData getBlockReplaced() {
|
||||
|
@@ -39,7 +39,7 @@ public class ChatMessage implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
@@ -50,10 +50,8 @@ public class ChatMessage implements LookupCacheElement {
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (message != null) {
|
||||
for (BaseComponent messageComponent : TextComponent.fromLegacyText(message)) {
|
||||
msg.addExtra(messageComponent);
|
||||
}
|
||||
msg.addExtra(TextComponent.fromLegacy(message));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
@@ -443,9 +443,7 @@ public class CommandsHandler implements CommandExecutor {
|
||||
if (lookupElements[i].getLocation() != null) {
|
||||
message.addExtra(new TextComponent("(" + (i + 1) + ") "));
|
||||
}
|
||||
for (BaseComponent component : lookupElements[i].getLogMessage(i + 1)) {
|
||||
message.addExtra(component);
|
||||
}
|
||||
message.addExtra(lookupElements[i].getLogMessage(i + 1));
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
if (setSessionPage) {
|
||||
|
@@ -77,7 +77,7 @@ public class EntityChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
@@ -128,7 +128,7 @@ public class EntityChange implements LookupCacheElement {
|
||||
msg.addExtra(" at ");
|
||||
msg.addExtra(prettyLocation(loc, entry));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -49,7 +49,7 @@ public class Kill implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
@@ -65,7 +65,7 @@ public class Kill implements LookupCacheElement {
|
||||
msg.addExtra(" with ");
|
||||
msg.addExtra(prettyItemName(MaterialConverter.getMaterial(weapon)));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
return msg;
|
||||
}
|
||||
|
||||
public TextComponent prettyItemName(Material t) {
|
||||
|
@@ -6,11 +6,11 @@ import org.bukkit.Location;
|
||||
public interface LookupCacheElement {
|
||||
public Location getLocation();
|
||||
|
||||
public default BaseComponent[] getLogMessage() {
|
||||
public default BaseComponent getLogMessage() {
|
||||
return getLogMessage(-1);
|
||||
}
|
||||
|
||||
public BaseComponent[] getLogMessage(int entry);
|
||||
public BaseComponent getLogMessage(int entry);
|
||||
|
||||
public default int getNumChanges() {
|
||||
return 1;
|
||||
|
@@ -32,7 +32,7 @@ public class SummedBlockChanges implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(MaterialConverter.getMaterial(type))), 10, 10, spaceFactor);
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public class SummedEntityChanges implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(EntityTypeConverter.getEntityType(type))), 10, 10, spaceFactor);
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ public class SummedKills implements LookupCacheElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
return MessagingUtil.formatSummarizedChanges(kills, killed, new TextComponent(player.getName()), 6, 7, spaceFactor);
|
||||
}
|
||||
|
||||
|
@@ -486,8 +486,8 @@ public class WorldEditor implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
return TextComponent.fromLegacyText(getMessage());
|
||||
public BaseComponent getLogMessage(int entry) {
|
||||
return TextComponent.fromLegacy(getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -182,7 +182,7 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
||||
}
|
||||
tc.addExtra("[");
|
||||
if (line != null && !line.isEmpty()) {
|
||||
tc.addExtra(new TextComponent(TextComponent.fromLegacyText(line)));
|
||||
tc.addExtra(TextComponent.fromLegacy(line));
|
||||
}
|
||||
tc.addExtra("]");
|
||||
}
|
||||
|
@@ -18,10 +18,14 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class MessagingUtil {
|
||||
public static BaseComponent[] formatSummarizedChanges(int created, int destroyed, BaseComponent actor, int createdWidth, int destroyedWidth, float spaceFactor) {
|
||||
public static BaseComponent formatSummarizedChanges(int created, int destroyed, BaseComponent actor, int createdWidth, int destroyedWidth, float spaceFactor) {
|
||||
TextComponent textCreated = createTextComponentWithColor(created + spaces((int) ((10 - String.valueOf(created).length()) / spaceFactor)), CREATE.getColor());
|
||||
TextComponent textDestroyed = createTextComponentWithColor(destroyed + spaces((int) ((10 - String.valueOf(destroyed).length()) / spaceFactor)), DESTROY.getColor());
|
||||
return new BaseComponent[] { textCreated, textDestroyed, actor };
|
||||
TextComponent result = new TextComponent();
|
||||
result.addExtra(textCreated);
|
||||
result.addExtra(textDestroyed);
|
||||
result.addExtra(actor);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TextComponent createTextComponentWithColor(String text, ChatColor color) {
|
||||
|
@@ -8,6 +8,7 @@ import com.google.gson.JsonObject;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -45,7 +46,7 @@ public class UUIDFetcher {
|
||||
}
|
||||
|
||||
private static HttpURLConnection createConnection() throws Exception {
|
||||
URL url = new URL(PROFILE_URL);
|
||||
URL url = new URI(PROFILE_URL).toURL();
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
|
@@ -2,10 +2,10 @@ package de.diddiz.LogBlock.worldedit;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -17,15 +17,13 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.FloatTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import com.sk89q.jnbt.NamedTag;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import org.enginehub.linbus.stream.LinBinaryIO;
|
||||
import org.enginehub.linbus.stream.LinStream;
|
||||
import org.enginehub.linbus.tree.LinCompoundTag;
|
||||
import org.enginehub.linbus.tree.LinDoubleTag;
|
||||
import org.enginehub.linbus.tree.LinListTag;
|
||||
import org.enginehub.linbus.tree.LinRootEntry;
|
||||
import org.enginehub.linbus.tree.LinTagType;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@@ -33,6 +31,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.util.CuboidRegion;
|
||||
|
||||
@@ -107,21 +106,20 @@ public class WorldEditHelper {
|
||||
com.sk89q.worldedit.world.entity.EntityType weType = BukkitAdapter.adapt(type);
|
||||
com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
|
||||
try {
|
||||
NBTInputStream nbtis = new NBTInputStream(new ByteArrayInputStream(serialized));
|
||||
NamedTag namedTag = nbtis.readNamedTag();
|
||||
nbtis.close();
|
||||
LinStream stream = LinBinaryIO.read(new DataInputStream(new ByteArrayInputStream(serialized)));
|
||||
LinRootEntry namedTag = LinRootEntry.readFrom(stream);
|
||||
UUID newUUID = null;
|
||||
if (namedTag.getName().equals("entity") && namedTag.getTag() instanceof CompoundTag) {
|
||||
CompoundTag serializedState = (CompoundTag) namedTag.getTag();
|
||||
BaseEntity state = new BaseEntity(weType, serializedState);
|
||||
if (namedTag.name().equals("entity")) {
|
||||
LinCompoundTag serializedState = namedTag.value();
|
||||
BaseEntity state = new BaseEntity(weType, LazyReference.computed(serializedState));
|
||||
com.sk89q.worldedit.entity.Entity weEntity = weLocation.getExtent().createEntity(weLocation, state);
|
||||
if (weEntity != null) {
|
||||
CompoundTag newNbt = weEntity.getState().getNbtData();
|
||||
int[] uuidInts = newNbt.getIntArray("UUID");
|
||||
LinCompoundTag newNbt = weEntity.getState().getNbt();
|
||||
int[] uuidInts = newNbt.findTag("UUID", LinTagType.intArrayTag()).value();
|
||||
if (uuidInts != null && uuidInts.length >= 4) {
|
||||
newUUID = new UUID(((long) uuidInts[0] << 32) | (uuidInts[1] & 0xFFFFFFFFL), ((long) uuidInts[2] << 32) | (uuidInts[3] & 0xFFFFFFFFL));
|
||||
} else {
|
||||
newUUID = new UUID(newNbt.getLong("UUIDMost"), newNbt.getLong("UUIDLeast")); // pre 1.16
|
||||
newUUID = new UUID(newNbt.findTag("UUIDMost", LinTagType.longTag()).valueAsLong(), newNbt.findTag("UUIDLeast", LinTagType.longTag()).valueAsLong()); // pre 1.16
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,16 +134,18 @@ public class WorldEditHelper {
|
||||
BaseEntity state = weEntity.getState();
|
||||
if (state != null) {
|
||||
try {
|
||||
LinCompoundTag.Builder nbt = state.getNbt().toBuilder();
|
||||
nbt.putFloat("Health", 20.0f);
|
||||
nbt.put("Motion", LinListTag.builder(LinTagType.doubleTag()).add(LinDoubleTag.of(0)).add(LinDoubleTag.of(0)).add(LinDoubleTag.of(0)).build());
|
||||
nbt.putShort("Fire", (short) -20);
|
||||
nbt.putShort("HurtTime", (short) 0);
|
||||
|
||||
LinRootEntry root = new LinRootEntry("entity", nbt.build());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
NBTOutputStream nbtos = new NBTOutputStream(baos);
|
||||
CompoundTag nbt = state.getNbtData();
|
||||
LinkedHashMap<String, Tag<?, ?>> value = new LinkedHashMap<>(nbt.getValue());
|
||||
value.put("Health", new FloatTag(20.0f));
|
||||
value.put("Motion", new ListTag(DoubleTag.class, Arrays.asList(new DoubleTag[] { new DoubleTag(0), new DoubleTag(0), new DoubleTag(0) })));
|
||||
value.put("Fire", new ShortTag((short) -20));
|
||||
value.put("HurtTime", new ShortTag((short) 0));
|
||||
nbtos.writeNamedTag("entity", new CompoundTag(value));
|
||||
nbtos.close();
|
||||
try (DataOutputStream dos = new DataOutputStream(baos)) {
|
||||
LinBinaryIO.write(dos, root);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("This IOException should be impossible", e);
|
||||
@@ -175,7 +175,7 @@ public class WorldEditHelper {
|
||||
}
|
||||
BlockVector3 min = selection.getMinimumPoint();
|
||||
BlockVector3 max = selection.getMaximumPoint();
|
||||
return new CuboidRegion(world, new BlockVector(min.getBlockX(), min.getBlockY(), min.getBlockZ()), new BlockVector(max.getBlockX(), max.getBlockY(), max.getBlockZ()));
|
||||
return new CuboidRegion(world, new BlockVector(min.x(), min.y(), min.z()), new BlockVector(max.x(), max.y(), max.z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user