Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Fixed issue when disabling Skript (issue #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuke-Nuke committed Sep 5, 2017
1 parent 62ac6be commit 4c8afc1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static SkriptGUIEvent getInstance() {
private final List<GUIListener> listeners = new ArrayList<>();
private boolean registered = false;
private SkriptGUIEvent() {
new TriggerUnregisterListener();
register();
}

Expand All @@ -47,6 +46,8 @@ public void register() {
if (!registered) {
//Make sure it only execute this once when necessary
registered = true;
// A listener to know when Skript will remove all listeners
new TriggerUnregisterListener().register();
// This is a safe Trigger. Even using null values, it won't cause any issue.
// It will be used to load as "SkriptListener" instead of Bukkit one,
// So, when cancelling this event, it will still calling all scripts events too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.Bukkit;
import org.bukkit.event.Event;

import java.io.File;
import java.util.ArrayList;

/**
Expand All @@ -20,7 +21,11 @@ public class TriggerUnregisterListener extends SelfRegisteringSkriptEvent {
private Trigger t;

public TriggerUnregisterListener() {
t = new Trigger(null, getClass().getName(), this, new ArrayList<>());
}

public void register() {
if (t == null) //A file object, just to not use null
t = new Trigger(new File("TuSKe"), getClass().getName(), this, new ArrayList<>());
SkriptEventHandler.addSelfRegisteringTrigger(t);
}

Expand All @@ -37,7 +42,6 @@ public void unregister(Trigger t) {
@Override
public void unregisterAll() {
SkriptGUIEvent.getInstance().unregisterAll();
Bukkit.getScheduler().runTask(TuSKe.getInstance(), () -> SkriptEventHandler.addSelfRegisteringTrigger(t));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class EffFormatGUI extends EffectSection {
private Expression<ItemStack> i;
private Expression<?> ct;
private Expression<ItemStack> i2;
private Expression<Inventory> inv = null;
private boolean runEvent;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -155,8 +154,6 @@ protected void execute(Event e) {
gui.toCallEvent(runEvent);
else
gui.toClose(toClose);
if (this.inv != null)
gui.toOpenInventory(this.inv.getSingle(e));
TuSKe.getGUIManager().newGUI(inv, slots[x].intValue(), i.getSingle(e), gui);
}
}
Expand Down

0 comments on commit 4c8afc1

Please sign in to comment.