Skip to content

Commit dc11eec

Browse files
author
iso2013
committed
Remove unnecessary and complex shading system.
1 parent cb242c1 commit dc11eec

File tree

4 files changed

+12
-108
lines changed

4 files changed

+12
-108
lines changed

Plugin/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@
5555
</resources>
5656
</build>
5757

58-
<repositories>
59-
<repository>
60-
<id>spigotmc-repo</id>
61-
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
62-
</repository>
63-
<repository>
64-
<id>sonatype</id>
65-
<url>https://oss.sonatype.org/content/groups/public/</url>
66-
</repository>
67-
</repositories>
68-
6958
<dependencies>
7059
<dependency>
7160
<groupId>net.blitzcube.peapi</groupId>

Plugin/src/main/java/net/blitzcube/peapi/PacketEntityAPI.java

Lines changed: 11 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,17 @@
2323
import org.bukkit.Location;
2424
import org.bukkit.entity.EntityType;
2525
import org.bukkit.entity.Player;
26-
import org.bukkit.plugin.RegisteredServiceProvider;
27-
import org.bukkit.plugin.ServicePriority;
28-
import org.bukkit.plugin.ServicesManager;
2926
import org.bukkit.plugin.java.JavaPlugin;
3027

3128
import java.lang.reflect.InvocationTargetException;
3229
import java.util.Collection;
3330
import java.util.HashMap;
3431
import java.util.Map;
35-
import java.util.Optional;
36-
import java.util.function.Consumer;
3732

3833
/**
3934
* Created by iso2013 on 2/13/2018.
4035
*/
41-
public class PacketEntityAPI implements IPacketEntityAPI {
36+
public class PacketEntityAPI extends JavaPlugin implements IPacketEntityAPI {
4237
public static final Map<EntityType, Integer> OBJECTS = new HashMap<>();
4338

4439
static {
@@ -73,83 +68,41 @@ public class PacketEntityAPI implements IPacketEntityAPI {
7368
OBJECTS.put(EntityType.LIGHTNING, -1);
7469
}
7570

76-
private static boolean compareVersions(String fullVersion) {
77-
String[][] input = new String[][]{fullVersion.split("\\."), ProviderStub.FULL_VERSION.split("\\.")};
78-
int size = Math.max(input[0].length, input[1].length);
79-
for (int s = 0; s < size; s++) {
80-
if (input[0].length - 1 < s) return true;
81-
if (input[1].length - 1 < s) return false;
82-
if (input[0][s].equals(input[1][s])) continue;
83-
return Integer.valueOf(input[0][s]) < Integer.valueOf(input[1][s]);
84-
}
85-
return false;
86-
}
87-
88-
private static JavaPlugin parent;
8971
private static IPacketEntityAPI instance;
9072

9173
private static TaskChainFactory chainFactory;
9274
/*
9375
* Begin actual API implementation:
9476
*/
95-
private final EntityModifierRegistry modifierRegistry;
96-
private final ProtocolManager manager;
77+
private EntityModifierRegistry modifierRegistry;
78+
private ProtocolManager manager;
9779
private FakeEntityFactory fakeEntityFactory;
9880
private EntityPacketFactory packetFactory;
9981
private PacketEventDispatcher dispatcher;
10082

101-
private PacketEntityAPI() {
83+
@Override
84+
public void onEnable() {
10285
this.modifierRegistry = new EntityModifierRegistry();
10386
this.manager = ProtocolLibrary.getProtocolManager();
10487
this.fakeEntityFactory = new FakeEntityFactory(this);
10588
this.packetFactory = new EntityPacketFactory();
10689
this.dispatcher = new PacketEventDispatcher(this, manager);
10790

108-
chainFactory = BukkitTaskChainFactory.create(parent);
109-
}
91+
chainFactory = BukkitTaskChainFactory.create(this);
11092

111-
public static void initialize(JavaPlugin parent, Consumer<IPacketEntityAPI> onLoad) {
112-
ServicesManager m = Bukkit.getServicesManager();
93+
if (instance == null) instance = this;
11394

114-
Collection<RegisteredServiceProvider<IPacketEntityAPI.ProviderStub>> r = m.getRegistrations(IPacketEntityAPI
115-
.ProviderStub.class);
116-
Optional<RegisteredServiceProvider<IPacketEntityAPI.ProviderStub>> top = r.stream()
117-
.filter(p -> ProviderStub.MAJOR_VERSION.equals(p.getProvider().getMajorVersion())).findFirst();
118-
if (top.isPresent()) {
119-
if (compareVersions(top.get().getProvider().getFullVersion())) {
120-
m.unregister(IPacketEntityAPI.ProviderStub.class, top.get());
121-
} else return;
122-
}
123-
m.register(IPacketEntityAPI.ProviderStub.class, new PacketEntityAPI.ProviderStub(), parent, ServicePriority
124-
.Normal);
125-
126-
if (PacketEntityAPI.parent == null || parent.getName().equals("PacketEntityAPI")) {
127-
PacketEntityAPI.parent = parent;
128-
}
95+
}
12996

130-
PacketEntityAPI.instance = getLatestCompatibleVersion();
97+
@Override
98+
public void onDisable() {
13199

132-
if (onLoad != null)
133-
Bukkit.getScheduler().runTask(parent, () -> onLoad.accept(instance));
134100
}
135101

136102
public static TaskChainFactory getChainFactory() {
137103
return chainFactory;
138104
}
139105

140-
private static IPacketEntityAPI getLatestCompatibleVersion() {
141-
RegisteredServiceProvider<IPacketEntityAPI.ProviderStub> match = Bukkit.getServicesManager()
142-
.getRegistrations(IPacketEntityAPI.ProviderStub.class).stream()
143-
.filter(p -> ProviderStub.MAJOR_VERSION.equals("0") &&
144-
ProviderStub.FULL_VERSION.equals(p.getProvider().getFullVersion()) ||
145-
ProviderStub.MAJOR_VERSION.equals(p.getProvider().getMajorVersion())).findFirst()
146-
.orElse(null);
147-
if (match == null) {
148-
throw new IllegalStateException("No compatible API version found! List of current versions:");
149-
}
150-
return match.getProvider().getInstance();
151-
}
152-
153106
public static IFakeEntity getFakeEntity(int entityID) {
154107
return instance.getFakeByID(entityID);
155108
}
@@ -221,7 +174,7 @@ public void dispatchPacket(IEntityPacket packet, Player target, int delay) {
221174
PacketContainer c = packet.getRawPacket();
222175
if (c == null) return;
223176
if (delay > 0) {
224-
Bukkit.getScheduler().scheduleSyncDelayedTask(parent, () -> {
177+
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
225178
if (c.getType().isClient()) {
226179
safeReceive(target, c);
227180
} else {
@@ -256,25 +209,4 @@ private void safeReceive(Player target, PacketContainer packet) {
256209
public Collection<FakeEntity> getFakeEntities() {
257210
return fakeEntityFactory.getFakeEntities();
258211
}
259-
260-
private static class ProviderStub implements IPacketEntityAPI.ProviderStub {
261-
static final String FULL_VERSION = "${project.version}";
262-
static final String MAJOR_VERSION = FULL_VERSION.substring(0, FULL_VERSION.indexOf("."));
263-
private static PacketEntityAPI inst;
264-
265-
@Override
266-
public String getMajorVersion() {
267-
return MAJOR_VERSION;
268-
}
269-
270-
@Override
271-
public String getFullVersion() {
272-
return FULL_VERSION;
273-
}
274-
275-
@Override
276-
public IPacketEntityAPI getInstance() {
277-
return (inst == null ? (inst = new PacketEntityAPI()) : inst);
278-
}
279-
}
280212
}

Plugin/src/main/java/net/blitzcube/peapi/PacketEntityAPIPlugin.java

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: PacketEntityAPI
22
version: ${project.version}
3-
main: net.blitzcube.peapi.PacketEntityAPIPlugin
3+
main: net.blitzcube.peapi.PacketEntityAPI
44
authors: [iso2013]

0 commit comments

Comments
 (0)