2
0
forked from Upstream/mmocore

The block tag that prevents blocks from giving out XP now gets properly removed when a block is removed or when a block forms naturally in place of a placed block

(Exploits COULD be present, please report anything you find out in tickets)
This commit is contained in:
ASangarin 2021-07-01 12:54:05 +02:00
parent 0dcc8968c8
commit c299978e10
4 changed files with 34 additions and 35 deletions
src/main
java/net/Indyuce/mmocore
resources

View File

@ -34,8 +34,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
@Override @Override
public ExperienceManager<MineBlockExperienceSource> newManager() { public ExperienceManager<MineBlockExperienceSource> newManager() {
return new ExperienceManager<MineBlockExperienceSource>() { return new ExperienceManager<MineBlockExperienceSource>() {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void a(BlockBreakEvent event) { public void a(BlockBreakEvent event) {
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) if (event.getPlayer().getGameMode() != GameMode.SURVIVAL)
return; return;

View File

@ -146,10 +146,19 @@ public class BlockListener implements Listener {
} }
} }
/*
* This is handled in a separate event because it
* needs to happen AFTER it's already checked the tag
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void unregisterPlayerPlacedBlocksTag(BlockBreakEvent event) {
if(event.getBlock().hasMetadata("player_placed"))
event.getBlock().removeMetadata("player_placed", MMOCore.plugin);
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void registerPlayerPlacedBlocksTag(BlockPlaceEvent event) { public void registerPlayerPlacedBlocksTag(BlockPlaceEvent event) {
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true)); event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
} }
@ -186,19 +195,15 @@ public class BlockListener implements Listener {
* exp is not gained by these blocks * exp is not gained by these blocks
*/ */
private boolean protect;
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void cobblestoneGeneratorHandling(BlockFormEvent event) { public void cobblestoneGeneratorHandling(BlockFormEvent event) {
if(MMOCore.plugin.getConfig().contains("should-cobblestone-generators-give-exp")) { if(event.getBlock().hasMetadata("player_placed"))
this.protect = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); event.getBlock().removeMetadata("player_placed", MMOCore.plugin);
} else{ this.protect = false; } if(MMOCore.plugin.configManager.cobbleGeneratorXP) return;
if(!protect) { if (event.getBlock().getType() == Material.WATER || event.getBlock().getType() == Material.LAVA)
if (event.getBlock().getType() == Material.WATER || event.getBlock().getType() == Material.LAVA) if (event.getNewState().getType() == Material.COBBLESTONE || event.getNewState().getType() == Material.OBSIDIAN)
if (event.getNewState().getType() == Material.COBBLESTONE || event.getNewState().getType() == Material.OBSIDIAN) event.getNewState().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
event.getNewState().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
}
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -24,7 +24,7 @@ import java.util.logging.Level;
public class ConfigManager { public class ConfigManager {
public final CommandVerbose commandVerbose = new CommandVerbose(); public final CommandVerbose commandVerbose = new CommandVerbose();
public boolean overrideVanillaExp, canCreativeCast; public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP;
public double expPartyBuff, regenPartyBuff; public double expPartyBuff, regenPartyBuff;
public String partyChatPrefix, noSkillBoundPlaceholder; public String partyChatPrefix, noSkillBoundPlaceholder;
public ChatColor staminaFull, staminaHalf, staminaEmpty; public ChatColor staminaFull, staminaHalf, staminaEmpty;
@ -94,22 +94,19 @@ public class ConfigManager {
messages = new ConfigFile("messages").getConfig(); messages = new ConfigFile("messages").getConfig();
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input"); chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000; combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L;
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000; lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L;
lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000; lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000L;
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE); staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.normal").toUpperCase()).orElse(SwapAction.VANILLA);
MMOCore.plugin.getConfig().getString("swap-keybind.normal") sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.sneaking").toUpperCase()).orElse(SwapAction.VANILLA);
.toUpperCase()).orElse(SwapAction.VANILLA);
sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class,
MMOCore.plugin.getConfig().getString("swap-keybind.sneaking")
.toUpperCase()).orElse(SwapAction.VANILLA);
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
} }
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) { private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
@ -132,16 +129,14 @@ public class ConfigManager {
public void loadDefaultFile(String path, String name) { public void loadDefaultFile(String path, String name) {
String newPath = path.isEmpty() ? "" : "/" + path; String newPath = path.isEmpty() ? "" : "/" + path;
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath)); File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
if (!folder.exists()) if (!folder.exists()) folder.mkdir();
folder.mkdir();
File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name); File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name);
if (!file.exists()) if (!file.exists()) try {
try { Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath()); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
}
} }
public List<String> getMessage(String key) { public List<String> getMessage(String key) {
@ -174,10 +169,8 @@ public class ConfigManager {
String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message; String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message;
if (!msg.isEmpty()) { if (!msg.isEmpty()) {
if (actionbar) if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg);
PlayerData.get(player.getUniqueId()).displayActionBar(msg); else player.sendMessage(msg);
else
player.sendMessage(msg);
} }
return !msg.isEmpty(); return !msg.isEmpty();
} }

View File

@ -58,6 +58,8 @@ custom-mine-conditions:
# broken when custom mining conditions are met # broken when custom mining conditions are met
protect-custom-mine: false protect-custom-mine: false
# Whether blocks generated with a "cobblegenerator" should
# provide the player with experience points or not
should-cobblestone-generators-give-exp: false should-cobblestone-generators-give-exp: false
loot-chests: loot-chests: