Skip to content

Commit

Permalink
update Server Start Event to a ScriptEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 14, 2019
1 parent 5f727e0 commit 6579e59
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
Expand Up @@ -438,6 +438,7 @@ public void run() {
Debug.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");

// Fire the 'on Server Start' world event
ServerStartScriptEvent.instance.fire();
worldScriptHelper.serverStartEvent();

if (Settings.allowStupidx()) {
Expand Down
Expand Up @@ -2,10 +2,7 @@

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.events.block.*;
import com.denizenscript.denizen.events.core.CommandScriptEvent;
import com.denizenscript.denizen.events.core.ListPingScriptEvent;
import com.denizenscript.denizen.events.core.ServerPrestartScriptEvent;
import com.denizenscript.denizen.events.core.TabCompleteScriptEvent;
import com.denizenscript.denizen.events.core.*;
import com.denizenscript.denizen.events.entity.*;
import com.denizenscript.denizen.events.player.*;
import com.denizenscript.denizen.events.world.*;
Expand Down Expand Up @@ -42,6 +39,7 @@ public static void registerMainEvents() {
// Core events
ScriptEvent.registerScriptEvent(new ListPingScriptEvent());
ScriptEvent.registerScriptEvent(new ServerPrestartScriptEvent());
ScriptEvent.registerScriptEvent(new ServerStartScriptEvent());
ScriptEvent.registerScriptEvent(new TabCompleteScriptEvent());

// Entity events
Expand Down
@@ -0,0 +1,43 @@
package com.denizenscript.denizen.events.core;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;

public class ServerStartScriptEvent extends BukkitScriptEvent {

// <--[event]
// @Events
// server start
//
// @Regex ^on server start$
//
// @Triggers when the server starts.
//
// -->

public ServerStartScriptEvent() {
instance = this;
}

public static ServerStartScriptEvent instance;

@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("server start");
}

@Override
public boolean matches(ScriptPath path) {
return super.matches(path);
}

@Override
public String getName() {
return "ServerStart";
}

@Override
public ObjectTag getContext(String name) {
return super.getContext(name);
}
}
Expand Up @@ -51,15 +51,6 @@ public static String doEvents(List<String> events, NPCTag npc, PlayerTag player,
// CUSTOM EVENTS
/////////////////

// <--[event]
// @Events
// server start
//
// @Regex ^on server start$
//
// @Triggers when the server starts
//
// -->
public void serverStartEvent() {
long ticks = Settings.worldScriptTimeEventFrequency().getTicks();
Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(),
Expand All @@ -69,9 +60,6 @@ public void run() {
timeEvent();
}
}, ticks, ticks);

// Fire the 'Server Start' event
doEvents(Arrays.asList("server start"), null, null, null);
}

private final Map<String, Integer> current_time = new HashMap<>();
Expand All @@ -92,7 +80,7 @@ public void run() {
// -->
public void timeEvent() {
for (World world : Bukkit.getWorlds()) {
int hour = Double.valueOf(world.getTime() / 1000).intValue(); // TODO: What is this conversion math
int hour = (int) (world.getTime() / 1000);
hour = hour + 6;
// Get the hour
if (hour >= 24) {
Expand Down Expand Up @@ -138,8 +126,7 @@ public void onPlayerJoins(PlayerJoinEvent event) {

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
final String message = ChatColor.DARK_GREEN + "CHAT: " +
event.getPlayer().getName() + ": " + event.getMessage();
final String message = ChatColor.DARK_GREEN + "CHAT: " + event.getPlayer().getName() + ": " + event.getMessage();
Bukkit.getScheduler().runTaskLater(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
Expand All @@ -153,11 +140,9 @@ public void run() {

@EventHandler(priority = EventPriority.MONITOR)
public void playerLogin(PlayerLoginEvent event) {

if (EntityTag.isNPC(event.getPlayer())) {
return;
}

PlayerTag.notePlayer(event.getPlayer());
}

Expand Down

0 comments on commit 6579e59

Please sign in to comment.