forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -165,8 +165,7 @@ public class TinyProtocol {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onPlayerLogin(PlayerLoginEvent e) {
|
||||
if (closed)
|
||||
return;
|
||||
if (closed) return;
|
||||
|
||||
Channel channel = getChannel(e.getPlayer());
|
||||
|
||||
@@ -201,8 +200,7 @@ public class TinyProtocol {
|
||||
List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection);
|
||||
|
||||
for (Object item : list) {
|
||||
if (!(item instanceof ChannelFuture))
|
||||
break;
|
||||
if (!(item instanceof ChannelFuture)) break;
|
||||
|
||||
// Channel future that contains the server connection
|
||||
Channel serverChannel = ((ChannelFuture) item).channel();
|
||||
@@ -215,8 +213,7 @@ public class TinyProtocol {
|
||||
}
|
||||
|
||||
private void unregisterChannelHandler() {
|
||||
if (serverChannelHandler == null)
|
||||
return;
|
||||
if (serverChannelHandler == null) return;
|
||||
|
||||
for (Channel serverChannel : serverChannels) {
|
||||
final ChannelPipeline pipeline = serverChannel.pipeline();
|
||||
|
||||
@@ -226,25 +226,25 @@ public final class Reflection {
|
||||
}
|
||||
|
||||
// Search in parent classes
|
||||
if (target.getSuperclass() != null)
|
||||
if (target.getSuperclass() != null) {
|
||||
return getField(target.getSuperclass(), name, fieldType, index);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
|
||||
}
|
||||
|
||||
private static <T> boolean matching(java.lang.reflect.Field field, String name, Class<T> fieldType, Class<?>... parameters) {
|
||||
if (name != null && !field.getName().equals(name))
|
||||
return false;
|
||||
if (name != null && !field.getName().equals(name)) return false;
|
||||
|
||||
if (!fieldType.isAssignableFrom(field.getType()))
|
||||
return false;
|
||||
if (!fieldType.isAssignableFrom(field.getType())) return false;
|
||||
|
||||
if (parameters.length > 0) {
|
||||
Type[] arguments = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
|
||||
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i])
|
||||
if (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -274,8 +274,9 @@ public final class Reflection {
|
||||
}
|
||||
|
||||
// Search in every superclass
|
||||
if (clazz.getSuperclass() != null)
|
||||
if (clazz.getSuperclass() != null) {
|
||||
return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Cannot find method %s (%s).", methodName, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
@@ -131,7 +131,6 @@ public class Core extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
TinyProtocol.instance.close();
|
||||
errorHandler.unregister();
|
||||
if (crashDetector.onMainThread())
|
||||
Statement.closeAll();
|
||||
if (crashDetector.onMainThread()) Statement.closeAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,29 +51,30 @@ public class ErrorHandler extends Handler {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void publish(LogRecord logRecord) {
|
||||
if (logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
||||
return;
|
||||
if (logRecord.getLevel().intValue() < Level.WARNING.intValue()) return;
|
||||
|
||||
if (watchdogThreadId == logRecord.getThreadID())
|
||||
return;
|
||||
if (watchdogThreadId == logRecord.getThreadID()) return;
|
||||
|
||||
String message = logRecord.getMessage() != null ? logRecord.getMessage() : "";
|
||||
for (String reason : ignoreStartsWith)
|
||||
if (message.startsWith(reason))
|
||||
return;
|
||||
for (String reason : ignoreContains)
|
||||
if (message.contains(reason))
|
||||
return;
|
||||
for (String reason : ignoreStartsWith) {
|
||||
if (message.startsWith(reason)) return;
|
||||
}
|
||||
for (String reason : ignoreContains) {
|
||||
if (message.contains(reason)) return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
|
||||
if (logRecord.getThrown() != null)
|
||||
if (logRecord.getThrown() != null) {
|
||||
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
|
||||
}
|
||||
String stacktrace = stacktraceOutput.toString();
|
||||
if (stacktrace.contains("POI data mismatch") || stacktrace.contains("Newer version! Server downgrades are not supported!"))
|
||||
if (stacktrace.contains("POI data mismatch") || stacktrace.contains("Newer version! Server downgrades are not supported!")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.isEmpty() && stacktrace.isEmpty())
|
||||
if (message.isEmpty() && stacktrace.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
SWException.log(message, stacktrace);
|
||||
|
||||
@@ -153,8 +153,9 @@ public class SWPlayer {
|
||||
|
||||
private Message getMessage() {
|
||||
Message message = this.messageThreadLocal.get();
|
||||
if (message == null)
|
||||
if (message == null) {
|
||||
throw new IllegalStateException("Use #using(Message) before sending or parsing a message!");
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,9 @@ public class TPSWatcher {
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
if (currentTime > lastTime)
|
||||
if (currentTime > lastTime) {
|
||||
tps = (timeInterval / (double) (currentTime - lastTime)) * TICK_DEFAULT;
|
||||
}
|
||||
|
||||
lastTime = currentTime;
|
||||
}, timeInterval / 50, timeInterval / 50);
|
||||
|
||||
@@ -187,8 +187,7 @@ public class WorldEditWrapper {
|
||||
}
|
||||
|
||||
Clipboard clipboard = clipboardHolder.getClipboard();
|
||||
if (clipboard == null)
|
||||
throw new NoClipboardException();
|
||||
if (clipboard == null) throw new NoClipboardException();
|
||||
|
||||
PipedOutputStream outputStream = new PipedOutputStream();
|
||||
PipedInputStream inputStream;
|
||||
|
||||
@@ -78,13 +78,16 @@ public class AntiNocom implements Listener {
|
||||
}
|
||||
|
||||
private boolean isValid(Player player, String type, int x, int z) {
|
||||
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z)))
|
||||
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a + 1);
|
||||
if (amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
||||
if (amount == 8) // Schedule player kick only once
|
||||
if (amount == 8) {
|
||||
// Schedule player kick only once
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
||||
}
|
||||
|
||||
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,9 @@ public class RArmorStand extends REntity {
|
||||
void spawn(Consumer<Object> packetSink) {
|
||||
super.spawn(packetSink);
|
||||
|
||||
if (size != null && size != Size.NORMAL)
|
||||
if (size != null && size != Size.NORMAL) {
|
||||
packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
|
||||
}
|
||||
}
|
||||
|
||||
public enum Size {
|
||||
|
||||
@@ -123,8 +123,7 @@ public class REntity {
|
||||
}
|
||||
|
||||
public void hide(boolean hide) {
|
||||
if (hidden == hide)
|
||||
return;
|
||||
if (hidden == hide) return;
|
||||
|
||||
if (hide) {
|
||||
despawn(packet -> server.updateEntity(this, packet));
|
||||
@@ -160,8 +159,9 @@ public class REntity {
|
||||
if (Math.abs(diffX) < MAX_REL_MOVE && Math.abs(diffY) < MAX_REL_MOVE && Math.abs(diffZ) < MAX_REL_MOVE) {
|
||||
Object packet = getMoveLookPacket(diffX, diffY, diffZ, rotEq);
|
||||
|
||||
if (packet != null)
|
||||
if (packet != null) {
|
||||
server.updateEntity(this, packet);
|
||||
}
|
||||
} else {
|
||||
server.updateEntity(this, getTeleportPacket());
|
||||
}
|
||||
@@ -321,15 +321,10 @@ public class REntity {
|
||||
private byte getEntityStatus() {
|
||||
byte status = 0;
|
||||
|
||||
if (fireTick != 0)
|
||||
status |= 1;
|
||||
if (pose == Pose.CROUCHING)
|
||||
status |= 2;
|
||||
if (invisible)
|
||||
status |= 0x20;
|
||||
if (isGlowing)
|
||||
status |= 0x40;
|
||||
|
||||
if (fireTick != 0) status |= 1;
|
||||
if (pose == Pose.CROUCHING) status |= 2;
|
||||
if (invisible) status |= 0x20;
|
||||
if (isGlowing) status |= 0x40;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,9 @@ public class REntityServer implements Listener {
|
||||
|
||||
private final BiFunction<Player, ServerboundInteractPacket, Object> filter = (player, packet) -> {
|
||||
REntity entity = entityMap.get(packet.getEntityId());
|
||||
if (entity == null)
|
||||
return packet;
|
||||
if (entity == null) return packet;
|
||||
|
||||
if (playersThatClicked.contains(player))
|
||||
return null;
|
||||
if (playersThatClicked.contains(player)) return null;
|
||||
|
||||
playersThatClicked.add(player);
|
||||
EntityAction action = packet.isAttack() ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||
@@ -79,8 +77,9 @@ public class REntityServer implements Listener {
|
||||
boolean uninitialized = this.callback == null;
|
||||
this.callback = callback;
|
||||
|
||||
if (uninitialized)
|
||||
if (uninitialized) {
|
||||
TinyProtocol.instance.addTypedFilter(ServerboundInteractPacket.class, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
@@ -120,11 +119,11 @@ public class REntityServer implements Listener {
|
||||
void preEntityMove(REntity entity, double toX, double toZ) {
|
||||
long fromId = entityToId(entity);
|
||||
long toId = posToId(toX, toZ);
|
||||
if (fromId == toId)
|
||||
return;
|
||||
if (fromId == toId) return;
|
||||
|
||||
if (!entity.isHidden())
|
||||
if (!entity.isHidden()) {
|
||||
onMissing(players.get(fromId), players.get(toId), entity::despawn);
|
||||
}
|
||||
onMissing(players.get(fromId), players.get(toId), entity::delist);
|
||||
removeEntityFromChunk(entity);
|
||||
}
|
||||
@@ -132,18 +131,17 @@ public class REntityServer implements Listener {
|
||||
void postEntityMove(REntity entity, double fromX, double fromZ) {
|
||||
long fromId = posToId(fromX, fromZ);
|
||||
long toId = entityToId(entity);
|
||||
if (fromId == toId)
|
||||
return;
|
||||
if (fromId == toId) return;
|
||||
|
||||
addEntityToChunk(entity);
|
||||
onMissing(players.get(toId), players.get(fromId), entity::list);
|
||||
if (!entity.isHidden())
|
||||
if (!entity.isHidden()) {
|
||||
onMissing(players.get(toId), players.get(fromId), entity::spawn);
|
||||
}
|
||||
}
|
||||
|
||||
void updateEntity(REntity entity, Object packet) {
|
||||
if (entity.isHidden())
|
||||
return;
|
||||
if (entity.isHidden()) return;
|
||||
|
||||
for (Player player : players.getOrDefault(entityToId(entity), emptyPlayers)) {
|
||||
TinyProtocol.instance.sendPacket(player, packet);
|
||||
@@ -174,8 +172,7 @@ public class REntityServer implements Listener {
|
||||
HashSet<REntity> entitiesInChunk = entities.get(id);
|
||||
if (entitiesInChunk == null) return;
|
||||
entitiesInChunk.remove(entity);
|
||||
if (entitiesInChunk.isEmpty())
|
||||
entities.remove(id);
|
||||
if (entitiesInChunk.isEmpty()) entities.remove(id);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
@@ -183,15 +180,13 @@ public class REntityServer implements Listener {
|
||||
Player player = e.getPlayer();
|
||||
Location from = lastLocation.get(player);
|
||||
Location to = e.getTo();
|
||||
if (from == null || to == null)
|
||||
return;
|
||||
if (from == null || to == null) return;
|
||||
|
||||
int fromX = posToChunk(from.getX());
|
||||
int fromZ = posToChunk(from.getZ());
|
||||
int toX = posToChunk(to.getX());
|
||||
int toZ = posToChunk(to.getZ());
|
||||
if (fromX == toX && fromZ == toZ)
|
||||
return;
|
||||
if (fromX == toX && fromZ == toZ) return;
|
||||
|
||||
lastLocation.put(player, to);
|
||||
|
||||
@@ -214,22 +209,19 @@ public class REntityServer implements Listener {
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Location location = lastLocation.remove(player);
|
||||
if (location == null)
|
||||
return;
|
||||
if (location == null) return;
|
||||
|
||||
forChunkInView(player, location, (x, z) -> {
|
||||
long id = chunkToId(x, z);
|
||||
Set<Player> playersInChunk = players.get(id);
|
||||
playersInChunk.remove(player);
|
||||
if (playersInChunk.isEmpty())
|
||||
players.remove(id);
|
||||
if (playersInChunk.isEmpty()) players.remove(id);
|
||||
});
|
||||
viewDistance.remove(player);
|
||||
}
|
||||
|
||||
private void onMissing(Set<Player> of, Set<Player> in, Consumer<Consumer<Object>> packetProvider) {
|
||||
if (of == null)
|
||||
return;
|
||||
if (of == null) return;
|
||||
|
||||
for (Player player : of) {
|
||||
if (in == null || !in.contains(player)) {
|
||||
@@ -255,8 +247,9 @@ public class REntityServer implements Listener {
|
||||
players.computeIfAbsent(id, i -> new HashSet<>()).add(player);
|
||||
for (REntity entity : entities.getOrDefault(id, emptyEntities)) {
|
||||
entity.list(packet -> TinyProtocol.instance.sendPacket(player, packet));
|
||||
if (!entity.isHidden())
|
||||
if (!entity.isHidden()) {
|
||||
entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,12 +258,12 @@ public class REntityServer implements Listener {
|
||||
|
||||
Set<Player> playersInChunk = players.get(id);
|
||||
playersInChunk.remove(player);
|
||||
if (playersInChunk.isEmpty())
|
||||
players.remove(id);
|
||||
if (playersInChunk.isEmpty()) players.remove(id);
|
||||
|
||||
for (REntity entity : entities.getOrDefault(id, emptyEntities)) {
|
||||
if (!entity.isHidden())
|
||||
if (!entity.isHidden()) {
|
||||
entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
|
||||
}
|
||||
entity.delist(packet -> TinyProtocol.instance.sendPacket(player, packet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +83,13 @@ public class SWAnvilInv {
|
||||
|
||||
private List<AnvilGUI.ResponseAction> onResult(Integer slot, AnvilGUI.StateSnapshot state) {
|
||||
if (slot != AnvilGUI.Slot.OUTPUT) {
|
||||
if (slot == AnvilGUI.Slot.INPUT_LEFT && leftCallback != null)
|
||||
leftCallback.run();
|
||||
if (slot == AnvilGUI.Slot.INPUT_LEFT && leftCallback != null) leftCallback.run();
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String s = state.getText();
|
||||
if (s.startsWith("»"))
|
||||
s = s.substring(1);
|
||||
if (s.startsWith("»")) s = s.substring(1);
|
||||
callback.accept(s);
|
||||
player.setLevel(0);
|
||||
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
||||
|
||||
@@ -156,8 +156,7 @@ public class SWInventory implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (!player.equals(e.getWhoClicked()))
|
||||
return;
|
||||
if (!player.equals(e.getWhoClicked())) return;
|
||||
|
||||
if (callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) {
|
||||
e.setCancelled(true);
|
||||
@@ -169,8 +168,7 @@ public class SWInventory implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if (!player.equals(e.getPlayer()))
|
||||
return;
|
||||
if (!player.equals(e.getPlayer())) return;
|
||||
|
||||
InventoryClickEvent.getHandlerList().unregister(this);
|
||||
InventoryCloseEvent.getHandlerList().unregister(this);
|
||||
|
||||
@@ -132,8 +132,9 @@ public class SWItem {
|
||||
item.setName(itemJson.get("title").getAsString());
|
||||
}
|
||||
|
||||
if (itemJson.has("enchanted"))
|
||||
if (itemJson.has("enchanted")) {
|
||||
item.setEnchanted(true);
|
||||
}
|
||||
if (itemJson.has("lore")) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
JsonArray loreArray = itemJson.getAsJsonArray("lore");
|
||||
@@ -141,8 +142,9 @@ public class SWItem {
|
||||
item.setLore(lore);
|
||||
}
|
||||
|
||||
if (itemJson.has("customModelData"))
|
||||
if (itemJson.has("customModelData")) {
|
||||
item.setCustomModelData(itemJson.get("customModelData").getAsInt());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,8 +111,7 @@ public class SWListInv<T> extends SWInventory {
|
||||
@Override
|
||||
public void setItem(int pos, SWItem item) {
|
||||
super.setItem(pos, item);
|
||||
if (!opened)
|
||||
customItems.put(pos, item);
|
||||
if (!opened) customItems.put(pos, item);
|
||||
}
|
||||
|
||||
public void setCallback(ListCallback<T> c) {
|
||||
@@ -122,8 +121,7 @@ public class SWListInv<T> extends SWInventory {
|
||||
public static List<SWListEntry<UUID>> createPlayerList(UUID without) {
|
||||
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (without != null && player.getUniqueId().equals(without))
|
||||
continue;
|
||||
if (without != null && player.getUniqueId().equals(without)) continue;
|
||||
|
||||
onlinePlayers.add(new SWListEntry<>(SWItem.getPlayerSkull(player), player.getUniqueId()));
|
||||
}
|
||||
@@ -134,17 +132,19 @@ public class SWListInv<T> extends SWInventory {
|
||||
List<SWListEntry<SchematicNode>> schemList = new ArrayList<>();
|
||||
|
||||
List<SchematicNode> schems;
|
||||
if (type == null)
|
||||
if (type == null) {
|
||||
schems = SchematicNode.getAllSchematicsAccessibleByUser(steamwarUserId);
|
||||
else
|
||||
} else {
|
||||
schems = SchematicNode.getAllAccessibleSchematicsOfType(steamwarUserId, type.toDB());
|
||||
}
|
||||
|
||||
for (SchematicNode s : schems) {
|
||||
Material m;
|
||||
if (s.getItem().isEmpty())
|
||||
if (s.getItem().isEmpty()) {
|
||||
m = Material.CAULDRON;
|
||||
else
|
||||
} else {
|
||||
m = SWItem.getMaterial(s.getItem());
|
||||
}
|
||||
SWItem item = new SWItem(m, "§e" + s.getName());
|
||||
item.setEnchanted(s.isDir());
|
||||
schemList.add(new SWListEntry<>(item, s));
|
||||
|
||||
@@ -38,8 +38,7 @@ public class UtilGui {
|
||||
public static void openMaterialSelector(Player player, String title, Consumer<Material> callback) {
|
||||
List<SWListInv.SWListEntry<Material>> materials = new LinkedList<>();
|
||||
for (Material material : Material.values()) {
|
||||
if (material.name().startsWith(Material.LEGACY_PREFIX) || !material.isItem())
|
||||
continue;
|
||||
if (material.name().startsWith(Material.LEGACY_PREFIX) || !material.isItem()) continue;
|
||||
SWItem item = new SWItem(material, "§7" + material.name());
|
||||
if (item.getItemMeta() != null && material.isItem()) {
|
||||
materials.add(new SWListInv.SWListEntry<>(item, material));
|
||||
|
||||
@@ -58,15 +58,15 @@ public class Message {
|
||||
|
||||
private String parse(String message, boolean prefixed, CommandSender sender, Object... params) {
|
||||
Locale locale;
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof Player) {
|
||||
locale = getLocale((Player) sender);
|
||||
else
|
||||
} else {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
|
||||
ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName, locale, classLoader);
|
||||
String pattern = "";
|
||||
if (prefixed)
|
||||
pattern = fromRB(resourceBundle, "PREFIX") + " ";
|
||||
if (prefixed) pattern = fromRB(resourceBundle, "PREFIX") + " ";
|
||||
pattern += fromRB(resourceBundle, message);
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
@@ -115,15 +115,18 @@ public class Message {
|
||||
|
||||
public void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params) {
|
||||
TextComponent msg = parseToComponent(message, prefixed, sender, params);
|
||||
if (onHover != null)
|
||||
if (onHover != null) {
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
||||
if (onClick != null)
|
||||
}
|
||||
if (onClick != null) {
|
||||
msg.setClickEvent(onClick);
|
||||
}
|
||||
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof Player) {
|
||||
BountifulWrapper.impl.sendMessage((Player) sender, type, msg);
|
||||
else
|
||||
} else {
|
||||
sender.sendMessage(msg.toPlainText());
|
||||
}
|
||||
}
|
||||
|
||||
/* Send message to all players */
|
||||
|
||||
@@ -51,8 +51,9 @@ public class InventoryHandler extends PacketHandler {
|
||||
|
||||
SWInventory inventory = new SWInventory(player, packet.getSize(), packet.getTitle(), items);
|
||||
inventory.addCloseCallback(click -> {
|
||||
if (player.getOpenInventory().getType() != InventoryType.CHEST)
|
||||
if (player.getOpenInventory().getType() != InventoryType.CHEST) {
|
||||
NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build(), player);
|
||||
}
|
||||
});
|
||||
inventory.open();
|
||||
}
|
||||
|
||||
@@ -85,8 +85,7 @@ public class PersonalKit {
|
||||
|
||||
public static PersonalKit get(int userID, String gamemode, String name) {
|
||||
InternalKit kit = InternalKit.get(userID, gamemode, name);
|
||||
if (kit == null)
|
||||
return null;
|
||||
if (kit == null) return null;
|
||||
return new PersonalKit(kit);
|
||||
}
|
||||
|
||||
@@ -97,8 +96,7 @@ public class PersonalKit {
|
||||
|
||||
public static PersonalKit getKitInUse(int userID, String gamemode) {
|
||||
InternalKit kit = InternalKit.getKitInUse(userID, gamemode);
|
||||
if (kit == null)
|
||||
return null;
|
||||
if (kit == null) return null;
|
||||
return new PersonalKit(kit);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,11 @@ public class SchematicData {
|
||||
|
||||
public SchematicData(SchematicNode node) {
|
||||
this.data = NodeData.getLatest(node);
|
||||
if (node.isDir())
|
||||
throw new SecurityException("Node is Directory");
|
||||
if (node.isDir()) throw new SecurityException("Node is Directory");
|
||||
}
|
||||
|
||||
public SchematicData(SchematicNode node, int revision) {
|
||||
if (node.isDir())
|
||||
throw new SecurityException("Node is Directory");
|
||||
if (node.isDir()) throw new SecurityException("Node is Directory");
|
||||
|
||||
if (revision < 1) {
|
||||
this.data = NodeData.getLatest(node);
|
||||
|
||||
@@ -60,8 +60,9 @@ public class ChunkHider {
|
||||
return (p, packet) -> {
|
||||
int chunkX = chunkXField.get(packet);
|
||||
int chunkZ = chunkZField.get(packet);
|
||||
if (techHider.getLocationEvaluator().skipChunk(p, chunkX, chunkZ))
|
||||
if (techHider.getLocationEvaluator().skipChunk(p, chunkX, chunkZ)) {
|
||||
return packet;
|
||||
}
|
||||
|
||||
packet = chunkPacketCloner.apply(packet);
|
||||
Object dataWrapper = chunkDataCloner.apply(chunkData.get(packet));
|
||||
@@ -134,8 +135,9 @@ public class ChunkHider {
|
||||
case SKIP:
|
||||
break;
|
||||
case CHECK:
|
||||
if (!section.getObfuscate().contains(values.get(pos)))
|
||||
if (!section.getObfuscate().contains(values.get(pos))) {
|
||||
break;
|
||||
}
|
||||
case HIDE:
|
||||
values.set(pos, section.getTarget());
|
||||
break;
|
||||
@@ -243,8 +245,7 @@ public class ChunkHider {
|
||||
}
|
||||
|
||||
int paletteLength = copyVarInt();
|
||||
if (paletteLength == 0)
|
||||
return;
|
||||
if (paletteLength == 0) return;
|
||||
|
||||
paletted = true;
|
||||
air = 0;
|
||||
@@ -252,13 +253,15 @@ public class ChunkHider {
|
||||
|
||||
for (int i = 0; i < paletteLength; i++) {
|
||||
int entry = ProtocolUtils.readVarInt(in);
|
||||
if (obfuscate.contains(entry))
|
||||
if (obfuscate.contains(entry)) {
|
||||
entry = techHider.getObfuscationTargetId();
|
||||
}
|
||||
|
||||
if (entry == TechHider.AIR_ID)
|
||||
if (entry == TechHider.AIR_ID) {
|
||||
air = i;
|
||||
else if (entry == techHider.getObfuscationTargetId())
|
||||
} else if (entry == techHider.getObfuscationTargetId()) {
|
||||
target = i;
|
||||
}
|
||||
|
||||
ProtocolUtils.writeVarInt(out, entry);
|
||||
}
|
||||
|
||||
@@ -70,17 +70,17 @@ public class ProtocolUtils {
|
||||
}
|
||||
|
||||
private static BiConsumer<Object, Object> shallowFill(Class<?> clazz) {
|
||||
if (clazz == null)
|
||||
if (clazz == null) {
|
||||
return (source, clone) -> {
|
||||
};
|
||||
}
|
||||
|
||||
BiConsumer<Object, Object> superFiller = shallowFill(clazz.getSuperclass());
|
||||
|
||||
Field[] fds = clazz.getDeclaredFields();
|
||||
List<Field> fields = new ArrayList<>();
|
||||
for (Field field : fds) {
|
||||
if (Modifier.isStatic(field.getModifiers()))
|
||||
continue;
|
||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||
|
||||
field.setAccessible(true);
|
||||
fields.add(field);
|
||||
@@ -101,8 +101,7 @@ public class ProtocolUtils {
|
||||
|
||||
public static int posToChunk(int c) {
|
||||
int chunk = c / 16;
|
||||
if (c < 0)
|
||||
chunk--;
|
||||
if (c < 0) chunk--;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@@ -134,8 +133,7 @@ public class ProtocolUtils {
|
||||
int value = (read & 0b01111111);
|
||||
result |= (value << (7 * numRead));
|
||||
|
||||
if (++numRead > 5)
|
||||
throw new SecurityException("VarInt too long");
|
||||
if (++numRead > 5) throw new SecurityException("VarInt too long");
|
||||
} while ((read & 0b10000000) != 0);
|
||||
|
||||
return result;
|
||||
|
||||
@@ -43,8 +43,9 @@ public class ProtocolWrapper {
|
||||
int chunkX = TechHider.blockPositionX.get(chunkCoords);
|
||||
int chunkY = TechHider.blockPositionY.get(chunkCoords);
|
||||
int chunkZ = TechHider.blockPositionZ.get(chunkCoords);
|
||||
if (locationEvaluator.skipChunkSection(p, chunkX, chunkY, chunkZ))
|
||||
if (locationEvaluator.skipChunkSection(p, chunkX, chunkY, chunkZ)) {
|
||||
return packet;
|
||||
}
|
||||
|
||||
packet = TechHider.multiBlockChangeCloner.apply(packet);
|
||||
final short[] oldPos = multiBlockChangePos.get(packet);
|
||||
@@ -68,8 +69,7 @@ public class ProtocolWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks.isEmpty())
|
||||
return null;
|
||||
if (blocks.isEmpty()) return null;
|
||||
|
||||
short[] newPos = new short[poss.size()];
|
||||
for (int i = 0; i < newPos.length; i++)
|
||||
|
||||
@@ -107,8 +107,9 @@ public class TechHider {
|
||||
case SKIP:
|
||||
return packet;
|
||||
case CHECK:
|
||||
if (!iBlockDataHidden((BlockState) blockChangeBlockData.get(packet)))
|
||||
if (!iBlockDataHidden((BlockState) blockChangeBlockData.get(packet))) {
|
||||
return packet;
|
||||
}
|
||||
case HIDE:
|
||||
packet = blockChangeCloner.apply(packet);
|
||||
blockChangeBlockData.set(packet, obfuscationTarget);
|
||||
@@ -125,8 +126,9 @@ public class TechHider {
|
||||
private static final Reflection.Field<?> blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0);
|
||||
|
||||
private Object blockActionHider(Player p, Object packet) {
|
||||
if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP)
|
||||
if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) {
|
||||
return packet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -138,8 +140,9 @@ public class TechHider {
|
||||
case SKIP:
|
||||
return packet;
|
||||
case CHECK:
|
||||
if (ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet))
|
||||
if (ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) {
|
||||
return packet;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user