Inventory improvements

This commit is contained in:
mathias 2019-08-08 23:39:41 +03:00
parent 2e5eecf936
commit a0c403207b
2 changed files with 31 additions and 3 deletions

View file

@ -7,7 +7,9 @@ import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.ShulkerBox;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -30,6 +32,8 @@ import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
@ -49,6 +53,14 @@ class EntitySpawn implements Listener {
} catch (Exception exception) { } catch (Exception exception) {
event.setCancelled(true); event.setCancelled(true);
} }
/*try {
BlockStateMeta state = (BlockStateMeta) event.getItem().getItemMeta();
state.getBlockState();
} catch (UnsupportedOperationException exception) {
System.out.println("I caught: " + exception);
event.setCancelled(true);
}*/
} }
@EventHandler @EventHandler
@ -320,8 +332,9 @@ class EntitySpawn implements Listener {
void onTNTPrime(TNTPrimeEvent event) { void onTNTPrime(TNTPrimeEvent event) {
final double tps = Bukkit.getTPS()[0]; final double tps = Bukkit.getTPS()[0];
if (tps < 10) { /*if (tps < 10) {*/
event.setCancelled(true);
event.getBlock().setType(Material.AIR, false); event.getBlock().setType(Material.AIR, false);
} /*}*/
} }
} }

View file

@ -11,6 +11,8 @@ import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.banner.Pattern;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -22,6 +24,9 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent; import com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent;
@ -122,7 +127,17 @@ class PlayerConnection implements Listener {
if (player.hasPlayedBefore()) { if (player.hasPlayedBefore()) {
try { try {
player.getInventory().getContents(); for (ItemStack item : player.getInventory().getContents()) {
if (item.getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) item.getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
player.getInventory().clear();
}
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
player.getInventory().clear(); player.getInventory().clear();
} }