Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
- changed author info
- now checks for gamemode when looking for non sleeping players
- now correctly registers when people leave game while sleeping
  • Loading branch information
InitialPosition committed Mar 20, 2021
1 parent 2c5b4ae commit 84917b4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ hs_err_pid*

# built artifacts
out/

# intelliJ
*.iml
22 changes: 0 additions & 22 deletions SleepBlame.iml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package de.SYRAPT0R.sleepblame;
package net.initialposition.sleepblame;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.text.MessageFormat;
import java.util.ArrayList;
Expand All @@ -31,11 +33,20 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
Collection<? extends Player> playerCollection = Bukkit.getServer().getOnlinePlayers();
ArrayList<Player> playerList = new ArrayList<>(playerCollection);

// remove everyone not in the overworld from the player list
// make sure only players that meet certain criteria are considered
for (Player currentPlayer : playerList) {

// remove everyone not in the overworld from the player list
String worldName = currentPlayer.getWorld().getName();
if (worldName.endsWith("_nether") || worldName.endsWith("_end")) {
playerList.remove(currentPlayer);
continue;
}

// remove everyone not in survival or adventure mode
GameMode playerGameMode = player.getGameMode();
if (playerGameMode == GameMode.CREATIVE || playerGameMode == GameMode.SPECTATOR) {
playerList.remove(currentPlayer);
}
}

Expand All @@ -59,7 +70,7 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (!sleepingList.contains(currentPlayer)) {

// found him!
Logging.consoleLog(MessageFormat.format("{0} is the only player not sleeping in the overworld! Sending notification...", player.getDisplayName()));
Logging.consoleLog(MessageFormat.format("{0} is the only player not sleeping in the overworld! Sending notification...", currentPlayer.getDisplayName()));
currentPlayer.sendMessage(ChatColor.RED + "You are the only person not sleeping! Please consider getting to a bed or logging off for a second!");
break;
}
Expand All @@ -77,4 +88,16 @@ public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
// we just remove the person from the sleeping list
sleepingList.remove(player);
}

@EventHandler
public void onDisconnectInBed(PlayerQuitEvent event) {
// player that logged out
Player player = event.getPlayer();

// check if player was sleeping (i.e. on the sleeping list) and remove him if he was
if (sleepingList.contains(player)) {
sleepingList.remove(player);
Logging.consoleLog(MessageFormat.format("{0} just logged out while sleeping", player.getDisplayName()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.SYRAPT0R.sleepblame;
package net.initialposition.sleepblame;

import java.text.MessageFormat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.SYRAPT0R.sleepblame;
package net.initialposition.sleepblame;

import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
public class SleepBlame extends JavaPlugin {

@Override
public void onEnable() {
Expand Down
8 changes: 4 additions & 4 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: SleepBlame
version: "1.1.3"
author: SYRAPT0R
main: de.SYRAPT0R.sleepblame.Main
api-version: 1.15
version: 1.2.0
author: InitialPosition
main: net.initialposition.sleepblame.SleepBlame
api-version: 1.16

0 comments on commit 84917b4

Please sign in to comment.