Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Update 3.0
Browse files Browse the repository at this point in the history
・ダイヤモンド以外の鉱石も全体通知可能に
 ∟ config.yml にて無効化設定可能
・鉱石の表示名を config.yml で設定可能に
  • Loading branch information
Siroshun09 authored Jul 20, 2019
1 parent 369079f commit d03f96c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,38 @@
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import java.util.HashSet;
import java.util.Set;
import java.util.*;

import static org.bukkit.Material.*;

public class BlockBreakListener implements Listener {

private final OreBroadcast plugin;
private final FileConfiguration config;
private final List<Material> oreList = new ArrayList<>();
private final Map<Material, String> oreName = new HashMap<>();

public BlockBreakListener(OreBroadcast plugin) {
this.plugin = plugin;
config = plugin.getConfig();

Collections.addAll(oreList, COAL_ORE, IRON_ORE, GOLD_ORE, REDSTONE_ORE, LAPIS_ORE, EMERALD_ORE, DIAMOND_ORE);

oreList.forEach(m -> oreName.put(m, config.getString("Ores." + m.toString(), m.toString())));

}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
Block block = event.getBlock();
if (oreList.contains(block.getType()) && !config.getStringList("disableOres").contains(block.getType().toString())) {

Player player = event.getPlayer();

Expand All @@ -35,8 +47,6 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}

Block block = event.getBlock();

if (plugin.isBlackListed(block)) {
plugin.unBlackList(block);
return;
Expand All @@ -61,7 +71,7 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}

String blockName = "Diamond";
String blockName = oreName.get(block.getType());
plugin.blackList(e.getVein());
plugin.unBlackList(e.getBlockMined());

Expand All @@ -71,6 +81,7 @@ public void onBlockBreak(BlockBreakEvent event) {
e.getVein().size(),
blockName
);

Bukkit.broadcastMessage(formattedMessage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.bukkit.Material.*;

public class BlockPlaceListener implements Listener {

private final OreBroadcast plugin;
private final FileConfiguration config;
private final List<Material> oreList = new ArrayList<>();

public BlockPlaceListener(OreBroadcast plugin) {
this.plugin = plugin;
config = plugin.getConfig();
Collections.addAll(oreList, COAL_ORE, IRON_ORE, GOLD_ORE, REDSTONE_ORE, LAPIS_ORE, EMERALD_ORE, DIAMOND_ORE);
}

@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
Block block = e.getBlock();
if(e.getBlock().getType().equals(Material.DIAMOND_ORE) && plugin.isWorldDisabled(block.getWorld().getName()) && !plugin.isBlackListed(block)
if (oreList.contains(e.getBlockPlaced().getType())
&& !plugin.isWorldDisabled(block.getWorld().getName())
&& !config.getStringList("disableOres").contains(block.getType().toString())
&& !plugin.isBlackListed(block)
&& (e.getPlayer().getGameMode() != GameMode.CREATIVE
|| !plugin.getConfig().getBoolean("broadcast-creative-placed-blocks", true))) {
|| !plugin.getConfig().getBoolean("broadcast-creative-placed-blocks", true))) {

plugin.blackList(block);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@

message: "&7* &l{player_name}&r &7が &b{count}個&r &7の &b{ore}&7 を発見した!"

# 鉱石の名前を設定
Ores:
COAL_ORE: "Coal"
IRON_ORE: "Iron Ore"
GOLD_ORE: "Gold Ore"
REDSTONE_ORE: "Redstone Ore"
LAPIS_ORE: "Lapis"
EMERALD_ORE: "Emerald"
DIAMOND_ORE: "Diamond"

# 鉱石を破壊した際、全体通知しないようにするワールドを指定

disableWorlds: []

# 全体通知を無効化する鉱石 ex) COAL_ORE

disableOres: []

# 発掘した鉱石をカウントする最大値

max-vein-size: 100
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ name: OreBroadcast
main: be.bendem.bukkit.orebroadcast.OreBroadcast
version: ${pom.version}
author: bendem
api-version: "1.14"
description: Send messages to other players when you find ores.

0 comments on commit d03f96c

Please sign in to comment.