Skip to content

Commit 123abdf

Browse files
committed
Code cleanup, remove some ancient compatibility
1 parent 11247f1 commit 123abdf

File tree

10 files changed

+98
-353
lines changed

10 files changed

+98
-353
lines changed

modules/API/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.concurrent.atomic.AtomicBoolean;
2525
import java.util.concurrent.atomic.AtomicInteger;
2626

27-
import org.bukkit.plugin.Plugin;
28-
2927
import com.comphenix.protocol.ProtocolLibrary;
3028
import com.comphenix.protocol.error.Report;
3129
import com.comphenix.protocol.error.ReportType;
@@ -36,10 +34,11 @@
3634
import com.comphenix.protocol.timing.TimedListenerManager;
3735
import com.comphenix.protocol.timing.TimedListenerManager.ListenerType;
3836
import com.comphenix.protocol.timing.TimedTracker;
39-
import com.comphenix.protocol.utility.WrappedScheduler;
4037
import com.google.common.base.Function;
4138
import com.google.common.base.Joiner;
4239

40+
import org.bukkit.plugin.Plugin;
41+
4342
/**
4443
* Represents a handler for an asynchronous event.
4544
* <p>
@@ -345,8 +344,7 @@ public void run() {
345344
}
346345

347346
private void scheduleAsync(Runnable runnable) {
348-
// Handle deprecation
349-
WrappedScheduler.runAsynchronouslyRepeat(listener.getPlugin(), filterManager.getScheduler(), runnable, 0L, -1L);
347+
listener.getPlugin().getServer().getScheduler().runTaskAsynchronously(listener.getPlugin(), runnable);
350348
}
351349

352350
/**

modules/API/src/main/java/com/comphenix/protocol/utility/WrappedScheduler.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

modules/API/src/main/java/com/comphenix/protocol/wrappers/BukkitConverters.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,17 @@
1414
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1515
* 02111-1307 USA
1616
*/
17-
1817
package com.comphenix.protocol.wrappers;
1918

2019
import java.lang.ref.WeakReference;
2120
import java.lang.reflect.Array;
2221
import java.lang.reflect.Constructor;
2322
import java.lang.reflect.Method;
2423
import java.lang.reflect.Modifier;
25-
import java.util.ArrayList;
26-
import java.util.Collection;
27-
import java.util.HashSet;
28-
import java.util.List;
29-
import java.util.Map;
24+
import java.util.*;
3025
import java.util.Map.Entry;
31-
import java.util.Set;
3226
import java.util.concurrent.ConcurrentHashMap;
3327

34-
import org.bukkit.Material;
35-
import org.bukkit.Sound;
36-
import org.bukkit.World;
37-
import org.bukkit.WorldType;
38-
import org.bukkit.entity.Entity;
39-
import org.bukkit.inventory.ItemStack;
40-
import org.bukkit.potion.PotionEffect;
41-
import org.bukkit.potion.PotionEffectType;
42-
import org.bukkit.util.Vector;
43-
4428
import com.comphenix.protocol.PacketType;
4529
import com.comphenix.protocol.ProtocolLibrary;
4630
import com.comphenix.protocol.ProtocolManager;
@@ -66,6 +50,16 @@
6650
import com.google.common.collect.Lists;
6751
import com.google.common.collect.Maps;
6852

53+
import org.bukkit.Material;
54+
import org.bukkit.Sound;
55+
import org.bukkit.World;
56+
import org.bukkit.WorldType;
57+
import org.bukkit.entity.Entity;
58+
import org.bukkit.inventory.ItemStack;
59+
import org.bukkit.potion.PotionEffect;
60+
import org.bukkit.potion.PotionEffectType;
61+
import org.bukkit.util.Vector;
62+
6963
/**
7064
* Contains several useful equivalent converters for normal Bukkit types.
7165
*
@@ -123,7 +117,7 @@ public class BukkitConverters {
123117
* Represents a typical equivalence converter.
124118
*
125119
* @author Kristian
126-
* @param <T> - type that can be converted.
120+
* @param <TType> - type that can be converted.
127121
*/
128122
public static abstract class IgnoreNullConverter<TType> implements EquivalentConverter<TType> {
129123
@Override

modules/API/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,8 @@
1616
*/
1717
package com.comphenix.protocol.wrappers;
1818

19-
import java.lang.reflect.Field;
20-
import java.lang.reflect.Method;
21-
import java.lang.reflect.Modifier;
22-
import java.lang.reflect.ParameterizedType;
23-
import java.lang.reflect.Type;
24-
import java.util.ArrayList;
25-
import java.util.Iterator;
26-
import java.util.List;
27-
import java.util.Map;
28-
import java.util.Set;
29-
import java.util.UUID;
30-
31-
import org.apache.commons.lang.Validate;
32-
import org.bukkit.entity.Entity;
33-
import org.bukkit.inventory.ItemStack;
19+
import java.lang.reflect.*;
20+
import java.util.*;
3421

3522
import com.comphenix.protocol.injector.BukkitUnwrapper;
3623
import com.comphenix.protocol.reflect.FieldAccessException;
@@ -47,6 +34,10 @@
4734
import com.google.common.base.Optional;
4835
import com.google.common.collect.ImmutableBiMap;
4936

37+
import org.apache.commons.lang.Validate;
38+
import org.bukkit.entity.Entity;
39+
import org.bukkit.inventory.ItemStack;
40+
5041
/**
5142
* Represents a DataWatcher in 1.8 thru 1.10
5243
*
@@ -419,7 +410,7 @@ public void setObject(int index, Object value) {
419410
* Sets the DataWatcher Item at a given index to a new value.
420411
*
421412
* @param index Index of the object to set
422-
* @param Serializer Serializer from {@link Serializer#get(Class)}
413+
* @param serializer Serializer from {@link Registry#get(Class)}
423414
* @param value New value
424415
* @param update Whether or not to inform the client
425416
*
@@ -463,7 +454,7 @@ public void setObject(int index, WrappedWatchableObject value) {
463454
* @param value Wrapped value
464455
* @param update Whether or not to inform the client
465456
*
466-
* @see {@link #setObject(WrappedDataWatcherObject, Object)}
457+
* @see #setObject(WrappedDataWatcherObject, Object)
467458
*/
468459
public void setObject(WrappedDataWatcherObject object, WrappedWatchableObject value, boolean update) {
469460
setObject(object, value.getRawValue(), update);
@@ -893,14 +884,15 @@ public String toString() {
893884
* <li>Float</li>
894885
* <li>String</li>
895886
* <li>IChatBaseComponent</li>
896-
* <li>Optional&lt;ItemStack&gt;</li>
887+
* <li>ItemStack</li>
897888
* <li>Optional&lt;IBlockData&gt;</li>
898889
* <li>Boolean</li>
899890
* <li>Vector3f</li>
900891
* <li>BlockPosition</li>
901892
* <li>Optional&lt;BlockPosition&gt;</li>
902893
* <li>EnumDirection</li>
903894
* <li>Optional&lt;UUID&gt;</li>
895+
* <li>NBTTagCompound</li>
904896
* </ul>
905897
*
906898
* @author dmulloy2
@@ -1078,5 +1070,13 @@ public static Serializer getDirectionSerializer() {
10781070
public static Serializer getUUIDSerializer(boolean optional) {
10791071
return get(UUID.class, optional);
10801072
}
1073+
1074+
/**
1075+
* Gets the serializer for NBT Compound tags
1076+
* @return The serializer
1077+
*/
1078+
public static Serializer getNBTCompoundSerializer() {
1079+
return get(MinecraftReflection.getNBTCompoundClass(), false);
1080+
}
10811081
}
10821082
}

modules/API/src/main/java/com/comphenix/protocol/wrappers/WrappedWatchableObject.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
2828
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
2929
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
30+
import com.comphenix.protocol.wrappers.nbt.NbtBase;
31+
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
32+
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
3033
import com.google.common.base.Optional;
3134

3235
/**
@@ -235,6 +238,8 @@ static Object getWrapped(Object value) {
235238
return BlockPosition.getConverter().getSpecific(value);
236239
} else if (is(EnumWrappers.getDirectionClass(), value)) {
237240
return EnumWrappers.getDirectionConverter().getSpecific(value);
241+
} else if (is(MinecraftReflection.getNBTCompoundClass(), value)) {
242+
return NbtFactory.fromNMSCompound(value);
238243
}
239244

240245
// Legacy classes
@@ -277,6 +282,8 @@ static Object getUnwrapped(Object wrapped) {
277282
return BlockPosition.getConverter().getGeneric(MinecraftReflection.getBlockPositionClass(), (BlockPosition) wrapped);
278283
} else if (wrapped instanceof Direction) {
279284
return EnumWrappers.getDirectionConverter().getGeneric(EnumWrappers.getDirectionClass(), (Direction) wrapped);
285+
} else if (wrapped instanceof NbtCompound) {
286+
return NbtFactory.fromBase((NbtCompound) wrapped).getHandle();
280287
}
281288

282289
// Legacy classes

modules/API/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static <T> NbtWrapper<T> fromBase(NbtBase<T> base) {
133133
* Set the NBT compound tag of a given item stack.
134134
* <p>
135135
* The item stack must be a wrapper for a CraftItemStack. Use
136-
* {@link MinecraftReflection#getCraftItemStack(ItemStack)} if not.
136+
* {@link MinecraftReflection#getBukkitItemStack(Object)} if not.
137137
* @param stack - the item stack, cannot be air.
138138
* @param compound - the new NBT compound, or NULL to remove it.
139139
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
@@ -151,7 +151,7 @@ public static void setItemTag(ItemStack stack, NbtCompound compound) {
151151
* material, damage value or count.
152152
* <p>
153153
* The item stack must be a wrapper for a CraftItemStack. Use
154-
* {@link MinecraftReflection#getCraftItemStack(ItemStack)} if not.
154+
* {@link MinecraftReflection#getBukkitItemStack(Object)} if not.
155155
* @param stack - the item stack.
156156
* @return A wrapper for its NBT tag.
157157
*/

modules/ProtocolLib/src/main/java/com/comphenix/protocol/PacketLogging.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,7 @@
2323
import java.text.SimpleDateFormat;
2424
import java.util.ArrayList;
2525
import java.util.List;
26-
import java.util.logging.FileHandler;
27-
import java.util.logging.Formatter;
28-
import java.util.logging.Handler;
29-
import java.util.logging.Level;
30-
import java.util.logging.LogRecord;
31-
import java.util.logging.Logger;
32-
33-
import org.apache.commons.io.HexDump;
34-
import org.bukkit.ChatColor;
35-
import org.bukkit.command.Command;
36-
import org.bukkit.command.CommandExecutor;
37-
import org.bukkit.command.CommandSender;
38-
import org.bukkit.plugin.Plugin;
26+
import java.util.logging.*;
3927

4028
import com.comphenix.protocol.PacketType.Protocol;
4129
import com.comphenix.protocol.PacketType.Sender;
@@ -45,6 +33,13 @@
4533
import com.comphenix.protocol.injector.netty.WirePacket;
4634
import com.google.common.base.Charsets;
4735

36+
import org.apache.commons.io.HexDump;
37+
import org.bukkit.ChatColor;
38+
import org.bukkit.command.Command;
39+
import org.bukkit.command.CommandExecutor;
40+
import org.bukkit.command.CommandSender;
41+
import org.bukkit.plugin.Plugin;
42+
4843
/**
4944
* Logs packets to a given stream
5045
* @author dmulloy2
@@ -99,16 +94,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
9994
type = PacketType.findCurrent(protocol, pSender, id);
10095
} catch (NumberFormatException ex) { // Check packet names
10196
String name = args[2];
102-
outer: for (PacketType packet : PacketType.values()) {
97+
for (PacketType packet : PacketType.values()) {
10398
if (packet.getProtocol() == protocol && packet.getSender() == pSender) {
10499
if (packet.name().equalsIgnoreCase(name)) {
105100
type = packet;
106-
break outer;
101+
break;
107102
}
108103
for (String className : packet.getClassNames()) {
109104
if (className.equalsIgnoreCase(name)) {
110105
type = packet;
111-
break outer;
106+
break;
112107
}
113108
}
114109
}
@@ -248,9 +243,8 @@ public Plugin getPlugin() {
248243
return plugin;
249244
}
250245

251-
private static enum LogLocation {
252-
CONSOLE,
253-
FILE;
246+
private enum LogLocation {
247+
CONSOLE, FILE
254248
}
255249

256250
private static class LogFormatter extends Formatter {

0 commit comments

Comments
 (0)