Skip to content

Commit

Permalink
新增检测到使用木锄时提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
LDS-XiaoYe committed Jul 8, 2023
1 parent b87bd33 commit 357f959
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.mcstaralliance.informdearplayer;

import com.mcstaralliance.informdearplayer.listener.PlayerInteractListener;
import com.mcstaralliance.informdearplayer.task.CheckRunnable;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class InformDearPlayer extends JavaPlugin {
private static InformDearPlayer instance;

@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
CheckRunnable checkRunnable = new CheckRunnable();
long interval = getConfig().getLong("resource-world-alert.interval");
checkRunnable.runTaskTimer(getInstance(), 5L, interval);
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), getInstance());
}


public static InformDearPlayer getInstance(){
public static InformDearPlayer getInstance() {
return instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mcstaralliance.informdearplayer.listener;

import com.mcstaralliance.informdearplayer.InformDearPlayer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
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.PlayerInteractEvent;

public class PlayerInteractListener implements Listener {
FileConfiguration config = InformDearPlayer.getInstance().getConfig();

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (event.getMaterial() == Material.WOOD_HOE) {
String message = config.getString("resource-world-alert.message");
player.sendMessage(colorize(message));
}
}


public String colorize(String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class CheckRunnable extends BukkitRunnable {

@Override
public void run() {
informInResourceWord();
informInResourceWorld();
}

public List<Player> getOnlinePlayers() {
return new ArrayList<>(Bukkit.getOnlinePlayers());
}

public void informInResourceWord() {
public void informInResourceWorld() {
for (Player player : getOnlinePlayers()) {
String worldName = config.getString("resource-world-alert.world-name");
String message = config.getString("resource-world-alert.message");
Expand Down

0 comments on commit 357f959

Please sign in to comment.