Skip to content

Commit 7b480b4

Browse files
authored
Merge pull request #43 from celesteoficial/fixes
multiple fixes and refactoring
2 parents 049bf3f + bc06535 commit 7b480b4

61 files changed

Lines changed: 379 additions & 472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bungeecord/build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ dependencies {
77
/**
88
* BUNGEECORD FRAMEWORK
99
*/
10-
implementation 'com.github.SaiintBrisson.command-framework:bungee:1.2.0'
11-
12-
/**
13-
* REFLECTION FRAMEWORK
14-
*/
15-
implementation 'org.reflections:reflections:0.9.12'
10+
implementation 'com.github.SaiintBrisson.command-framework:bungee:1.3.0'
1611

1712
/**
1813
* SHARED FRAMEWORK

bungeecord/src/main/java/com/celeste/library/bungee/AbstractBungeePlugin.java

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
package com.celeste.library.bungee;
22

3-
import com.celeste.library.bungee.annotation.CommandHolder;
4-
import com.celeste.library.bungee.exception.InvalidCommandException;
5-
import com.celeste.library.bungee.exception.InvalidListenerException;
63
import com.celeste.library.core.factory.ThreadingFactory;
7-
import com.celeste.library.core.util.Reflection;
8-
import java.lang.reflect.Constructor;
9-
import java.util.AbstractMap.SimpleImmutableEntry;
104
import java.util.Arrays;
11-
import java.util.Map.Entry;
125
import java.util.concurrent.ExecutorService;
136
import java.util.concurrent.ScheduledExecutorService;
147
import lombok.Getter;
@@ -18,7 +11,6 @@
1811
import net.md_5.bungee.api.plugin.Listener;
1912
import net.md_5.bungee.api.plugin.Plugin;
2013
import net.md_5.bungee.api.plugin.PluginManager;
21-
import org.reflections.Reflections;
2214

2315
@Getter
2416
public abstract class AbstractBungeePlugin extends Plugin {
@@ -46,9 +38,9 @@ public void registerCommands(final Object... instances) {
4638
final MessageHolder holder = frame.getMessageHolder();
4739

4840
holder.setMessage(MessageType.ERROR, "§cA error occurred.");
49-
holder.setMessage(MessageType.INCORRECT_TARGET, "Only {target} can execute this command..");
50-
holder.setMessage(MessageType.INCORRECT_USAGE, "Wrong use! The correct is: /{usage}");
51-
holder.setMessage(MessageType.NO_PERMISSION, "You don't have enough permissions.");
41+
holder.setMessage(MessageType.INCORRECT_TARGET, "§cOnly {target} can execute this command..");
42+
holder.setMessage(MessageType.INCORRECT_USAGE, "§cWrong use! The correct is: /{usage}");
43+
holder.setMessage(MessageType.NO_PERMISSION, "§cYou don't have enough permissions.");
5244

5345
frame.registerCommands(instances);
5446
}
@@ -65,103 +57,6 @@ public void registerCommands(final String[] messages, final Object... instances)
6557
frame.registerCommands(instances);
6658
}
6759

68-
@Deprecated
69-
public void register(final String path, final Class<?> clazz, final Object instance) {
70-
registerListeners(path, clazz, instance);
71-
registerCommands(path, clazz, instance);
72-
}
73-
74-
@Deprecated
75-
@SafeVarargs
76-
public final void register(final String path, final Entry<Class<?>, Object>... entries) {
77-
registerListeners(path, entries);
78-
registerCommands(path, entries);
79-
}
80-
81-
@Deprecated
82-
public void registerListeners(final String path, final Class<?> clazz, final Object instance) {
83-
registerListeners(path, new SimpleImmutableEntry<>(clazz, instance));
84-
}
85-
86-
@Deprecated
87-
@SafeVarargs
88-
public final void registerListeners(final String path, final Entry<Class<?>, Object>... entries) {
89-
try {
90-
final Class<?>[] parameters = Arrays.stream(entries)
91-
.map(Entry::getKey)
92-
.toArray(Class[]::new);
93-
94-
final Object[] instances = Arrays.stream(entries)
95-
.map(Entry::getValue)
96-
.toArray();
97-
98-
final Reflections reflections = new Reflections(path);
99-
100-
for (final Class<? extends Listener> clazz : reflections.getSubTypesOf(Listener.class)) {
101-
final Constructor<? extends Listener>[] constructors = Reflection.getConstructors(clazz);
102-
103-
final Constructor<? extends Listener> constructor = Arrays.stream(constructors)
104-
.filter(newConstructor -> Arrays.equals(newConstructor.getParameterTypes(), parameters))
105-
.findFirst()
106-
.orElse(null);
107-
108-
if (constructor == null) {
109-
continue;
110-
}
111-
112-
manager.registerListener(this, constructor.newInstance(instances));
113-
}
114-
} catch (Exception exception) {
115-
throw new InvalidListenerException("Unable to register listener: ", exception);
116-
}
117-
}
118-
119-
@Deprecated
120-
public void registerCommands(final String path, final Class<?> clazz, final Object instance) {
121-
registerCommands(path, new SimpleImmutableEntry<>(clazz, instance));
122-
}
123-
124-
@Deprecated
125-
@SafeVarargs
126-
public final void registerCommands(final String path, final Entry<Class<?>, Object>... entries) {
127-
try {
128-
final Class<?>[] parameters = Arrays.stream(entries)
129-
.map(Entry::getKey)
130-
.toArray(Class[]::new);
131-
132-
final Object[] instances = Arrays.stream(entries)
133-
.map(Entry::getValue)
134-
.toArray();
135-
136-
final Reflections reflections = new Reflections(path);
137-
138-
final BungeeFrame frame = new BungeeFrame(this);
139-
final MessageHolder holder = frame.getMessageHolder();
140-
141-
holder.setMessage(MessageType.ERROR, "§cA error occurred.");
142-
holder.setMessage(MessageType.INCORRECT_TARGET, "§cOnly {target} can execute this command.");
143-
holder.setMessage(MessageType.INCORRECT_USAGE, "§cWrong use! The correct is: /{usage}");
144-
holder.setMessage(MessageType.NO_PERMISSION, "§cYou don't have enough permissions.");
145-
146-
for (final Class<?> clazz : reflections.getTypesAnnotatedWith(CommandHolder.class)) {
147-
final Constructor<?>[] constructors = Reflection.getConstructors(clazz);
148-
149-
final Constructor<?> constructor = Arrays.stream(constructors)
150-
.filter(newConstructor -> Arrays.equals(newConstructor.getParameterTypes(), parameters))
151-
.findFirst()
152-
.orElse(null);
153-
154-
if (constructor == null) {
155-
continue;
156-
}
157-
158-
frame.registerCommands(constructor.newInstance(instances));
159-
}
160-
} catch (Exception exception) {
161-
throw new InvalidCommandException("Unable to register command: ", exception);
162-
}
163-
}
164-
16560
public static ExecutorService getExecutor() {
16661
return EXECUTOR;
16762
}

bungeecord/src/main/java/com/celeste/library/bungee/annotation/CommandHolder.java

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

bungeecord/src/main/java/com/celeste/library/bungee/exception/InvalidCommandException.java

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

bungeecord/src/main/java/com/celeste/library/bungee/exception/InvalidListenerException.java

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

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ dependencies {
22
/**
33
* JSON DEPENDENCY
44
*/
5-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
5+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.4'
66
implementation 'com.google.code.gson:gson:2.8.7'
77
}

core/src/main/java/com/celeste/library/core/model/entity/Cooldown.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @param <T> Object
1313
*/
14-
public final class Cooldown<T> extends TreeRegistry<T, Long> {
14+
public class Cooldown<T> extends TreeRegistry<T, Long> {
1515

1616
public boolean isActive(final T key) {
1717
if (!contains(key)) {

core/src/main/java/com/celeste/library/core/registry/collection/AbstractCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class AbstractCollection<E> implements Collection<E> {
1313
MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
1414
}
1515

16-
public abstract Iterator<E> iterator();
16+
public abstract @NotNull Iterator<E> iterator();
1717

1818
public abstract int size();
1919

core/src/main/java/com/celeste/library/core/registry/impl/LinkedRegistry.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ private void transferLinks(final LinkedNode<K,V> src, final LinkedNode<K,V> dst)
186186

187187
if (after == null) {
188188
setYoungest(dst);
189-
} else {
190-
after.setBefore(dst);
189+
return;
191190
}
191+
192+
after.setBefore(dst);
192193
}
193194

194195
public Node<K,V> newNode(final int hash, final K key, final V value, final Node<K,V> node) {
@@ -233,9 +234,10 @@ public void afterNodeRemoval(final Node<K,V> node) {
233234

234235
if (after == null) {
235236
setYoungest(before);
236-
} else {
237-
after.setBefore(before);
237+
return;
238238
}
239+
240+
after.setBefore(before);
239241
}
240242

241243
public void afterNodeInsertion(final boolean evict) {

core/src/main/java/com/celeste/library/core/registry/impl/MapRegistry.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@Setter
2626
@Getter
2727
public class MapRegistry<K, V> extends AbstractRegistry<K, V>
28-
implements Registry<K, V>, Cloneable, Serializable {
28+
implements Registry<K, V>, Serializable {
2929

3030
public static final int DEFAULT_INITIAL_CAPACITY;
3131
public static final int MAXIMUM_CAPACITY;
@@ -310,15 +310,14 @@ public final V registerValue(final int hash, final K key, V value, final boolean
310310
value = getKeyType().format(value);
311311

312312
Node<K,V>[] tab = nodes;
313-
Node<K,V> node;
314313
int number, index;
315314

316315
if (tab == null || (number = tab.length) == 0) {
317316
tab = resize();
318317
number = tab.length;
319318
}
320319

321-
node = tab[index = (number - 1) & hash];
320+
Node<K,V> node = tab[index = (number - 1) & hash];
322321
if (node == null) {
323322
tab[index] = newNode(hash, key, value, null);
324323

@@ -478,26 +477,29 @@ public final Node<K, V>[] resize() {
478477

479478
public final void treeifyBin(final Node<K, V>[] tab, final int hash) {
480479
int n, index;
481-
Node<K,V> node;
482480
if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY) {
483481
resize();
484482
return;
485483
}
486484

487-
if ((node = tab[index = (n - 1) & hash]) != null) {
488-
TreeNode<K,V> hd = null, tl = null;
485+
Node<K,V> node = tab[index = (n - 1) & hash];
486+
if (node != null) {
487+
TreeNode<K,V> treeNode = null, tl = null;
488+
489489
do {
490-
TreeNode<K,V> p = replacementTreeNode(node, null);
491-
if (tl == null)
492-
hd = p;
493-
else {
494-
p.setPrevious(tl);
495-
tl.setNext(p);
490+
TreeNode<K,V> replacement = replacementTreeNode(node, null);
491+
if (tl == null) {
492+
treeNode = replacement;
493+
} else {
494+
replacement.setPrevious(tl);
495+
tl.setNext(replacement);
496496
}
497-
tl = p;
497+
498+
tl = replacement;
498499
} while ((node = node.getNext()) != null);
499-
if ((tab[index] = hd) != null) {
500-
hd.treeify(tab);
500+
501+
if ((tab[index] = treeNode) != null) {
502+
treeNode.treeify(tab);
501503
}
502504
}
503505
}
@@ -532,6 +534,10 @@ public final Node<K, V> removeNode(int hash, Object key, Object value, boolean m
532534
} while ((entry = entry.getNext()) != null);
533535
}
534536

537+
if (node == null) {
538+
return null;
539+
}
540+
535541
final V v = node.getValue();
536542
if (v == null || (matchValue || !Objects.equals(value, v))) {
537543
return null;
@@ -619,10 +625,10 @@ public static Class<?> comparableClassFor(final Object comparableClazz) {
619625
}
620626

621627
@SuppressWarnings({"rawtypes","unchecked"})
622-
public static int compareComparables(final Class<?> clazz, final Object k, final Object x) {
623-
return (x == null || x.getClass() != clazz
628+
public static int compareComparables(final Class<?> clazz, final Object one, final Object two) {
629+
return two == null || two.getClass() != clazz
624630
? 0
625-
: ((Comparable)k).compareTo(x));
631+
: ((Comparable) one).compareTo(two);
626632
}
627633

628634
}

0 commit comments

Comments
 (0)