-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
34 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package idl; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
abstract class AbstractItemNotifier { | ||
private final ItemChecker checker; | ||
private final FileConfiguration config; | ||
|
||
public AbstractItemNotifier(ItemChecker checker, FileConfiguration config) { | ||
this.checker = checker; | ||
this.config = config; | ||
} | ||
|
||
public void handle(Player player) { | ||
int newItems = this.checker.check(player); | ||
if (newItems > 0) { | ||
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Got " + ChatColor.WHITE + newItems + ChatColor.GREEN + " new items for you. Use " + ChatColor.YELLOW + "/get" + ChatColor.GREEN + " command to get it!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
package idl; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Collection; | ||
|
||
public class ItemCheckTask implements Runnable { | ||
private ItemChecker checker; | ||
private FileConfiguration config; | ||
public class ItemCheckTask extends AbstractItemNotifier implements Runnable { | ||
|
||
public ItemCheckTask(ItemChecker checker, FileConfiguration config) { | ||
this.checker = checker; | ||
this.config = config; | ||
super(checker, config); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers(); | ||
for (Player player : players) { | ||
int newItems = this.checker.check(player); | ||
if (newItems > 0) { | ||
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Got " + ChatColor.WHITE + newItems + ChatColor.GREEN + " new items for you. Use " + ChatColor.YELLOW + "/get" + ChatColor.GREEN + " command to get it!"); | ||
} | ||
this.handle(player.getPlayer()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
package idl; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
public class JoinListener implements Listener { | ||
private final ItemChecker checker; | ||
private FileConfiguration config; | ||
|
||
public JoinListener(ItemChecker itemChecker, FileConfiguration config) { | ||
this.checker = itemChecker; | ||
this.config = config; | ||
public class JoinListener extends AbstractItemNotifier implements Listener { | ||
public JoinListener(ItemChecker checker, FileConfiguration config) { | ||
super(checker, config); | ||
} | ||
|
||
@EventHandler | ||
public void onAuth(PlayerJoinEvent event) { | ||
Player player = event.getPlayer(); | ||
int newItems = this.checker.check(player); | ||
if (newItems > 0) { | ||
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Got " + ChatColor.WHITE + newItems + ChatColor.GREEN + " new items for you. Use " + ChatColor.YELLOW + "/get" + ChatColor.GREEN + " command to get it!"); | ||
} | ||
this.handle(event.getPlayer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
package idl; | ||
|
||
import fr.xephi.authme.events.LoginEvent; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class LoginListener implements Listener { | ||
private final ItemChecker checker; | ||
private FileConfiguration config; | ||
|
||
public class LoginListener extends AbstractItemNotifier implements Listener { | ||
public LoginListener(ItemChecker checker, FileConfiguration config) { | ||
this.checker = checker; | ||
this.config = config; | ||
super(checker, config); | ||
} | ||
|
||
@EventHandler | ||
public void onAuth(LoginEvent event) { | ||
Player player = event.getPlayer(); | ||
int newItems = this.checker.check(player); | ||
if (newItems > 0) { | ||
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Got " + ChatColor.WHITE + newItems + ChatColor.GREEN + " new items for you. Use " + ChatColor.YELLOW + "/get" + ChatColor.GREEN + " command to get it!"); | ||
} | ||
this.handle(event.getPlayer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters