Skip to content

Commit

Permalink
Merge pull request #37 from ProjectKorra/simplicitee
Browse files Browse the repository at this point in the history
Fixed Arithmetic Involved with Updating Worldtime for Manual Event Starting
  • Loading branch information
Simplicitee authored Oct 21, 2019
2 parents 9679420 + f6b147e commit 12c6452
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
8 changes: 4 additions & 4 deletions src/com/projectkorra/rpg/RPGListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public void onSunRise(SunRiseEvent event) {

ProjectKorraRPG.getEventManager().endEvent(event.getWorld(), wEvent);
} else if (wEvent.getTime() == Time.DAY || wEvent.getTime() == Time.BOTH) {
if ((Math.ceil((event.getWorld().getFullTime() / 24000)) + 1) % wEvent.getFrequency() == 0) {
if (Math.ceil((event.getWorld().getFullTime() / 24000)) % wEvent.getFrequency() == 0) {
WorldEventStartEvent startEvent = new WorldEventStartEvent(event.getWorld(), wEvent);
Bukkit.getServer().getPluginManager().callEvent(startEvent);

if (startEvent.isCancelled()) {
continue;
}

ProjectKorraRPG.getEventManager().startEvent(event.getWorld(), wEvent);
ProjectKorraRPG.getEventManager().startEvent(event.getWorld(), wEvent, true);
}
} else {
if (ProjectKorraRPG.getEventManager().isHappening(event.getWorld(), wEvent)) {
Expand All @@ -167,15 +167,15 @@ public void onSunRise(SunRiseEvent event) {
public void onSunSet(SunSetEvent event) {
for (WorldEvent wEvent : WorldEvent.getEvents()) {
if (wEvent.getTime() == Time.NIGHT) {
if ((Math.ceil((event.getWorld().getFullTime() / 24000)) + 1) % wEvent.getFrequency() == 0) {
if (Math.ceil((event.getWorld().getFullTime() / 24000)) % wEvent.getFrequency() == 0) {
WorldEventStartEvent startEvent = new WorldEventStartEvent(event.getWorld(), wEvent);
Bukkit.getServer().getPluginManager().callEvent(startEvent);

if (startEvent.isCancelled()) {
continue;
}

ProjectKorraRPG.getEventManager().startEvent(event.getWorld(), wEvent);
ProjectKorraRPG.getEventManager().startEvent(event.getWorld(), wEvent, true);
}
} else if (wEvent.getTime() == Time.DAY) {
if (ProjectKorraRPG.getEventManager().isHappening(event.getWorld(), wEvent)) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/projectkorra/rpg/commands/EventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void execute(CommandSender sender, List<String> args) {
} else if (ProjectKorraRPG.getEventManager().isHappening(world, event)) {
sender.sendMessage(ChatColor.RED + "That WorldEvent is already happening!");
} else {
ProjectKorraRPG.getEventManager().startEvent(world, event);
ProjectKorraRPG.getEventManager().startEvent(world, event, false);
sender.sendMessage(ChatColor.GOLD + "Successfully started the " + event.getName() + " event!");
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/com/projectkorra/rpg/worldevent/util/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,28 @@ public void run() {
}
}

public void startEvent(World world, WorldEvent event) {
public void startEvent(World world, WorldEvent event, boolean natural) {
if (marker.get(world).contains(event)) {
return;
}

double daysLeft = ((Math.ceil((world.getFullTime() / 24000)) + 1) % event.getFrequency());
if (daysLeft > 0) {
world.setFullTime(world.getFullTime() + (long) daysLeft * 24000);
}

if (event.getTime() != Time.BOTH && event.getTime() != time) {
long difference = 0;
if (event.getTime() == Time.DAY) {
difference = 24000 - world.getTime();
} else {
difference = 12000 - world.getTime();
if (!natural) {
double daysLeft = event.getFrequency() - (Math.ceil((world.getFullTime() / 24000)) % event.getFrequency());

if (daysLeft > 0) {
world.setFullTime(world.getFullTime() + (long) daysLeft * 24000);
}

if (event.getTime() != Time.BOTH && event.getTime() != time) {
long difference = 0;
if (event.getTime() == Time.DAY) {
difference = 24000 - world.getTime();
} else {
difference = 12000 - world.getTime();
}
world.setFullTime(world.getFullTime() + difference);
time = event.getTime();
}
world.setFullTime(world.getFullTime() + difference);
time = event.getTime();
}

marker.get(world).add(event);
Expand Down

0 comments on commit 12c6452

Please sign in to comment.