Skip to content

Commit

Permalink
v3.1.2 - projectile hit message, 1.8.3 compat, api changes, and bug f…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
Realizedd committed Aug 6, 2018
1 parent 7ef60d1 commit 7731d33
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

allprojects {
group 'me.realized'
version '3.1.1'
version '3.1.2'
}

subprojects {
Expand Down
33 changes: 22 additions & 11 deletions duels-api/src/main/java/me/realized/duels/api/Duels.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.realized.duels.api;

import javax.annotation.Nonnull;
import lombok.NonNull;
import me.realized.duels.api.arena.ArenaManager;
import me.realized.duels.api.command.SubCommand;
import me.realized.duels.api.kit.KitManager;
import me.realized.duels.api.user.UserManager;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;

Expand All @@ -31,6 +31,13 @@ public interface Duels extends Plugin {
boolean registerSubCommand(@Nonnull final String command, @Nonnull final SubCommand subCommand);


/**
* @param listener Listener to register
* @since 3.1.2
*/
void registerListener(@Nonnull final Listener listener);


/**
* Reloads the plugin.
*
Expand All @@ -46,7 +53,7 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSync(@NonNull final Runnable task);
BukkitTask doSync(@Nonnull final Runnable task);


/**
Expand All @@ -57,7 +64,7 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSyncAfter(@NonNull final Runnable task, long delay);
BukkitTask doSyncAfter(@Nonnull final Runnable task, long delay);


/**
Expand All @@ -69,7 +76,7 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSyncRepeat(@NonNull final Runnable task, long delay, long interval);
BukkitTask doSyncRepeat(@Nonnull final Runnable task, long delay, long interval);


/**
Expand All @@ -79,7 +86,7 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsync(@NonNull final Runnable task);
BukkitTask doAsync(@Nonnull final Runnable task);


/**
Expand All @@ -90,7 +97,7 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsyncAfter(@NonNull final Runnable task, long delay);
BukkitTask doAsyncAfter(@Nonnull final Runnable task, long delay);


/**
Expand All @@ -102,31 +109,35 @@ public interface Duels extends Plugin {
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsyncRepeat(@NonNull final Runnable task, long delay, long interval);
BukkitTask doAsyncRepeat(@Nonnull final Runnable task, long delay, long interval);


/**
* @param message message to log
* @since 3.1.0
*/
void info(@NonNull final String message);
void info(@Nonnull final String message);


/**
* @param message message to log
* @since 3.1.0
*/
void warn(@NonNull final String message);
void warn(@Nonnull final String message);


/**
* @param message message to log
* @since 3.1.0
*/
void error(@NonNull final String message);
void error(@Nonnull final String message);


/**
* @param message message to log
* @since 3.1.0
*/
void error(@NonNull final String message, @NonNull Throwable thrown);
void error(@Nonnull final String message, @Nonnull Throwable thrown);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.Objects;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.NonNull;
import me.realized.duels.api.Duels;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -43,7 +42,7 @@ final void init(final Duels api, final String name, final File folder, final Fil
this.configFile = new File(dataFolder, "config.yml");
}

@NonNull
@Nonnull
public final String getName() {
return name;
}
Expand All @@ -62,7 +61,7 @@ public final void setEnabled(final boolean enabled) {
this.enabled = enabled;
}

public void saveResource(@NonNull String resourcePath) {
public void saveResource(@Nonnull String resourcePath) {
Objects.requireNonNull(resourcePath, "resourcePath");
resourcePath = resourcePath.replace('\\', '/');

Expand Down Expand Up @@ -97,7 +96,7 @@ public void saveResource(@NonNull String resourcePath) {
}

@Nullable
public InputStream getResource(@NonNull final String filename) {
public InputStream getResource(@Nonnull final String filename) {
Objects.requireNonNull(filename, "filename");

try {
Expand Down
55 changes: 38 additions & 17 deletions duels-plugin/src/main/java/me/realized/duels/DuelsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import lombok.Getter;
import lombok.NonNull;
import me.realized.duels.api.Duels;
import me.realized.duels.api.command.SubCommand;
import me.realized.duels.arena.ArenaManager;
Expand All @@ -25,10 +24,12 @@
import me.realized.duels.config.Lang;
import me.realized.duels.data.UserManager;
import me.realized.duels.duel.DuelManager;
import me.realized.duels.extension.ExtensionClassLoader;
import me.realized.duels.extension.ExtensionManager;
import me.realized.duels.extra.DamageListener;
import me.realized.duels.extra.KitItemListener;
import me.realized.duels.extra.PotionListener;
import me.realized.duels.extra.ProjectileHitListener;
import me.realized.duels.extra.SoupListener;
import me.realized.duels.extra.Teleport;
import me.realized.duels.extra.TeleportListener;
Expand All @@ -50,6 +51,8 @@
import me.realized.duels.util.command.AbstractCommand;
import me.realized.duels.util.gui.GuiListener;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.inventivetalent.update.spiget.SpigetUpdate;
Expand Down Expand Up @@ -106,6 +109,7 @@ public class DuelsPlugin extends JavaPlugin implements Duels, LogSource {
@Getter
private ExtensionManager extensionManager;
private final Map<String, AbstractCommand<DuelsPlugin>> commands = new HashMap<>();
private final List<Listener> registeredListeners = new ArrayList<>();

@Getter
private volatile boolean updateAvailable;
Expand Down Expand Up @@ -147,12 +151,6 @@ public void onEnable() {
loadables.add(teleport = new Teleport(this));
loadables.add(extensionManager = new ExtensionManager(this));

registerCommands(
new DuelCommand(this),
new SpectateCommand(this),
new DuelsCommand(this)
);

if (!load()) {
getPluginLoader().disablePlugin(this);
return;
Expand All @@ -163,6 +161,7 @@ public void onEnable() {
new PotionListener(this);
new TeleportListener(this);
new SoupListener(this);
new ProjectileHitListener(this);

new Metrics(this);

Expand Down Expand Up @@ -202,6 +201,12 @@ public void onDisable() {
* @return true if load was successful, otherwise false
*/
private boolean load() {
registerCommands(
new DuelCommand(this),
new SpectateCommand(this),
new DuelsCommand(this)
);

for (final Loadable loadable : loadables) {
try {
loadable.handleLoad();
Expand All @@ -220,6 +225,15 @@ private boolean load() {
* @return true if unload was successful, otherwise false
*/
private boolean unload() {
registeredListeners.forEach(HandlerList::unregisterAll);
registeredListeners.clear();
// Unregister all extension listeners that isn't using the method Duels#registerListener
HandlerList.getRegisteredListeners(this)
.stream()
.filter(listener -> listener.getListener().getClass().getClassLoader().getClass().isAssignableFrom(ExtensionClassLoader.class))
.forEach(listener -> HandlerList.unregisterAll(listener.getListener()));
commands.clear();

for (final Loadable loadable : Lists.reverse(loadables)) {
try {
if (loadables.indexOf(loadable) > lastLoad) {
Expand Down Expand Up @@ -265,6 +279,13 @@ protected void execute(final CommandSender sender, final String label, final Str
return true;
}

@Override
public void registerListener(@Nonnull final Listener listener) {
Objects.requireNonNull(listener, "listener");
registeredListeners.add(listener);
getServer().getPluginManager().registerEvents(listener, this);
}

@Override
public boolean reload() {
if (!(unload() && load())) {
Expand Down Expand Up @@ -296,61 +317,61 @@ public boolean reload(final Loadable loadable) {
}

@Override
public BukkitTask doSync(@NonNull final Runnable task) {
public BukkitTask doSync(@Nonnull final Runnable task) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTask(this, task);
}

@Override
public BukkitTask doSyncAfter(@NonNull final Runnable task, final long delay) {
public BukkitTask doSyncAfter(@Nonnull final Runnable task, final long delay) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTaskLater(this, task, delay);
}

@Override
public BukkitTask doSyncRepeat(@NonNull final Runnable task, final long delay, final long period) {
public BukkitTask doSyncRepeat(@Nonnull final Runnable task, final long delay, final long period) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTaskTimer(this, task, delay, period);
}

@Override
public BukkitTask doAsync(@NonNull final Runnable task) {
public BukkitTask doAsync(@Nonnull final Runnable task) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTaskAsynchronously(this, task);
}

@Override
public BukkitTask doAsyncAfter(@NonNull final Runnable task, final long delay) {
public BukkitTask doAsyncAfter(@Nonnull final Runnable task, final long delay) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTaskLaterAsynchronously(this, task, delay);
}

@Override
public BukkitTask doAsyncRepeat(@NonNull final Runnable task, final long delay, final long period) {
public BukkitTask doAsyncRepeat(@Nonnull final Runnable task, final long delay, final long period) {
Objects.requireNonNull(task, "task");
return getServer().getScheduler().runTaskTimerAsynchronously(this, task, delay, period);
}

@Override
public void info(@NonNull final String message) {
public void info(@Nonnull final String message) {
Objects.requireNonNull(message, "message");
Log.info(message);
}

@Override
public void warn(@NonNull final String message) {
public void warn(@Nonnull final String message) {
Objects.requireNonNull(message, "message");
Log.warn(message);
}

@Override
public void error(@NonNull final String message) {
public void error(@Nonnull final String message) {
Objects.requireNonNull(message, "message");
Log.error(message);
}

@Override
public void error(@NonNull final String message, @NonNull final Throwable thrown) {
public void error(@Nonnull final String message, @Nonnull final Throwable thrown) {
Objects.requireNonNull(message, "message");
Objects.requireNonNull(thrown, "thrown");
Log.error(message, thrown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
@Getter
private List<String> endCommands;
@Getter
private boolean projectileHitMessageEnabled;
@Getter
private List<String> projectileHitMessageTypes;
@Getter
private boolean preventInventoryOpen;
@Getter
private boolean removeEmptyBottle;
Expand Down Expand Up @@ -224,6 +228,8 @@ protected void loadValues(FileConfiguration configuration) throws Exception {
startCommands = configuration.getStringList("duel.match.start-commands.commands");
endCommandsEnabled = configuration.getBoolean("duel.match.end-commands.enabled", false);
endCommands = configuration.getStringList("duel.match.end-commands.commands");
projectileHitMessageEnabled = configuration.getBoolean("duel.projectile-hit-message.enabled", true);
projectileHitMessageTypes = configuration.getStringList("duel.projectile-hit-message.types");
preventInventoryOpen = configuration.getBoolean("duel.prevent-inventory-open", true);
removeEmptyBottle = configuration.getBoolean("duel.remove-empty-bottle", true);
preventTpToMatchPlayers = configuration.getBoolean("duel.prevent-teleport-to-match-players", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ItemData(final ItemStack item) {
lore = StringUtil.reverseColor(meta.getLore());
}

if (!CompatUtil.isPre1_8() && !meta.getItemFlags().isEmpty()) {
if (CompatUtil.hasItemFlag() && !meta.getItemFlags().isEmpty()) {
this.flags = new ArrayList<>();

for (final ItemFlag flag : meta.getItemFlags()) {
Expand Down Expand Up @@ -216,7 +216,7 @@ public ItemStack toItemStack() {
meta.setLore(StringUtil.color(lore));
}

if (!CompatUtil.isPre1_8() && flags != null && !flags.isEmpty()) {
if (CompatUtil.hasItemFlag() && flags != null && !flags.isEmpty()) {
for (final String flag : flags) {
meta.addItemFlags(ItemFlag.valueOf(flag));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import me.realized.duels.api.extension.DuelsExtension;
import sun.misc.CompoundEnumeration;

class ExtensionClassLoader extends URLClassLoader {
public class ExtensionClassLoader extends URLClassLoader {

private final JarFile jar;
private final Manifest manifest;
Expand Down
Loading

0 comments on commit 7731d33

Please sign in to comment.