"Various" fixes

master
Alexander B 4 years ago
parent a74b74addd
commit dbdcd10a40

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
public class OnBlockBreak implements Listener { public class OnBlockBreak implements Listener {
@ -21,46 +24,77 @@ public class OnBlockBreak implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
if(e.getBlock().getType() == Material.MOB_SPAWNER){ if(e.getBlock().getType() == Material.MOB_SPAWNER){
// Allow creative Location loc = e.getBlock().getLocation();
if(p.getGameMode() == GameMode.CREATIVE) String locSer = Main.serialiseLocation(loc);
return;
// Get spawner-source (unknown, player, admin) // Get spawner-source (unknown, player, admin)
Location loc = e.getBlock().getLocation();
BlockSource bSource; BlockSource bSource;
Boolean placedByAdmin = Main.data.getBoolean(Main.serialiseLocation(loc)); Object placedByAdmin = Main.data.get(locSer);
if(placedByAdmin == null) if(placedByAdmin == null)
bSource = BlockSource.UNKNOWN; bSource = BlockSource.UNKNOWN;
else else
if(!placedByAdmin) if(!(boolean)placedByAdmin)
bSource = BlockSource.PLAYER; bSource = BlockSource.PLAYER;
else else
bSource = BlockSource.ADMIN; bSource = BlockSource.ADMIN;
// # Break-Prerequisite // Ignore creative
ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource); if(p.getGameMode() != GameMode.CREATIVE){
// Silktouch
if(breakPreConfig.getBoolean("silktouch")){ // # Break-Prerequisite
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource);
e.setCancelled(true); boolean success = false;
// Silktouch
if(breakPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true);
}
// Send msg
String msg = breakPreConfig.getString("msg."+ (success?"success":"fail"));
if(msg != null && !msg.equals("")) p.sendMessage(msg);
// Stop if breaking wasnt successful
if(!success) return;
} }
// Send msg
String msg = breakPreConfig.getString("msg."+ (e.isCancelled()?"fail":"success"));
if(msg != null && !msg.equals("")) p.sendMessage(msg);
if(e.isCancelled()) return; // Remove block from data
if(bSource != BlockSource.UNKNOWN){
Main.data.set(locSer, null);
try {
Main.data.save("data.yml");
} catch (IOException ex) {
Main.plugin.getLogger().severe("Cannot save data to data.yml! Data will lost after restart!");
ex.printStackTrace();
}
}
// Ignore creative
if(p.getGameMode() != GameMode.CREATIVE){
// # Drop-Prerequisite
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource);
boolean success = false;
// Silktouch
if(dropPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true);
}
// Set drop
if(success){
ItemStack item = new ItemStack(Material.MOB_SPAWNER);
loc.getWorld().dropItem(loc, item);
}
// # Drop-Prerequisite // Send msg
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource); String msg = dropPreConfig.getString("msg."+ (success?"success":"fail"));
// Silktouch if(msg != null && !msg.equals("")) p.sendMessage(msg);
if(breakPreConfig.getBoolean("silktouch")){
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
e.setDropItems(false);
} }
// Send msg
msg = dropPreConfig.getString("msg."+ (e.isDropItems()?"success":"fail"));
if(msg != null && !msg.equals("")) p.sendMessage(msg);
} }
} }
} }

@ -4,6 +4,7 @@ import eu.railduction.ruakij.spawnerDrops.Main;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
@ -11,6 +12,7 @@ import java.io.IOException;
public class OnBlockPlace implements Listener { public class OnBlockPlace implements Listener {
@EventHandler
public void onBlockPlaceEvent(BlockPlaceEvent e){ public void onBlockPlaceEvent(BlockPlaceEvent e){
Player p = e.getPlayer(); Player p = e.getPlayer();
@ -20,29 +22,32 @@ public class OnBlockPlace implements Listener {
// Can break? // Can break?
boolean isAdmin = p.hasPermission("spawnerDrops.admin"); boolean isAdmin = p.hasPermission("spawnerDrops.admin");
if(!isAdmin && !Main.config.getBoolean("place.player.canPlace")){ if(!isAdmin && !Main.config.getBoolean("place.PLAYER.canPlace")){
// Cancel place-event // Cancel place-event
e.setCancelled(true); e.setCancelled(true);
// Send msg // Send msg
String msg = Main.config.getString("place.player.msg.fail"); String msg = Main.config.getString("place.PLAYER.msg.fail");
if(msg != null && !msg.equals("")) p.sendMessage(msg); if(msg != null && !msg.equals("")) p.sendMessage(msg);
return;
} }
else{
// Write place-data
Main.data.set(Main.serialiseLocation(loc), isAdmin);
try {
Main.data.save("data.yml");
} catch (IOException ex) {
Main.plugin.getLogger().severe("Cannot save data to data.yml! Data will lost after restart!");
ex.printStackTrace();
}
// Send msg // Write place-data
String msg = Main.config.getString("place.player.msg.success"); Main.plugin.getLogger().info(Main.serialiseLocation(loc) +" - "+ isAdmin);
if(msg != null && !msg.equals("")) p.sendMessage(msg); Main.data.set(Main.serialiseLocation(loc), isAdmin);
try {
Main.data.save("data.yml");
} catch (IOException ex) {
Main.plugin.getLogger().severe("Cannot save data to data.yml! Data will lost after restart!");
ex.printStackTrace();
} }
// Send msg
String msg = Main.config.getString("place."+ (isAdmin?"ADMIN":"PLAYER") +".msg.success");
if(msg != null && !msg.equals("")) p.sendMessage(msg);
} }
} }
} }

Loading…
Cancel
Save