Skip to content

Commit

Permalink
Added 1.15 support
Browse files Browse the repository at this point in the history
Removed 1.14 support
  • Loading branch information
ShakeforProtein committed Dec 12, 2019
1 parent e6da5ce commit d7a8a57
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 45 deletions.
32 changes: 26 additions & 6 deletions src/main/java/me/shakeforprotein/shakenbt/Commands/AddNBT.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.NBTTagString;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagString;
import net.minecraft.server.v1_15_R1.NBTTagType;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

import java.lang.reflect.Field;
import java.util.Set;

public class AddNBT implements CommandExecutor {
Expand All @@ -27,19 +34,32 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player p = (Player) sender;
if(p.getInventory().getItemInMainHand() != null && p.getInventory().getItemInMainHand().getType() != Material.AIR) {
ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);

net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);
Set<String> compoundKeys = compound.getKeys();
StringBuilder sb = new StringBuilder();
int i = 0;
for(i=1; i<args.length; i++){
sb.append(args[i]);
}
String newNBTItem = sb.toString();
compound.set(args[0], new NBTTagString(newNBTItem));

compound.setString(args[0], sb.toString());
// String newNBTItem = sb.toString();
// compound.set(args[0], new NBTTagType<String>(newNBTItem));
nmsItem.setTag(compound);
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
p.getInventory().setItemInMainHand(newItem);

/*
ItemMeta iMeta = bukkitItem.getItemMeta();
PersistentDataContainer pDC = iMeta.getPersistentDataContainer();
NamespacedKey namespacedKey = new NamespacedKey(pl, args[0]);
pDC.set(namespacedKey, PersistentDataType.STRING ,sb.toString());
bukkitItem.setItemMeta(iMeta);
*/
sender.sendMessage(pl.badge + "Item Updated");

}
else {p.sendMessage("You must have an item in your main hand");}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -25,9 +25,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player p = (Player) sender;
if(p.getInventory().getItemInMainHand() != null && p.getInventory().getItemInMainHand().getType() != Material.AIR) {
ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);
Set<String> compoundKeys = compound.getKeys();
net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
//NBTTagCompound compound = pl.getCompound(nmsItem);
//Set<String> compoundKeys = compound.getKeys();
NBTTagCompound blankCompound = new NBTTagCompound();
nmsItem.setTag(blankCompound);
p.getInventory().setItemInMainHand(pl.getBukkitItem(nmsItem));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.NBTTagString;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

Expand All @@ -27,7 +26,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player p = (Player) sender;
if(p.getInventory().getItemInMainHand() != null && p.getInventory().getItemInMainHand().getType() != Material.AIR) {
ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);

if(compound.hasKey(args[0])){
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/me/shakeforprotein/shakenbt/Commands/SetNBT.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -20,21 +20,23 @@ public SetNBT(ShakeNBT main) {
}

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

/*
if(sender instanceof Player){
Player p = (Player) sender;
if(p.getInventory().getItemInMainHand() != null && p.getInventory().getItemInMainHand().getType() != Material.AIR) {
ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);
Set<String> compoundKeys = compound.getKeys();
}
else {p.sendMessage("You must have an item in your main hand");}
}
else{
sender.sendMessage("This plugin can only be run as a player");
}

*/
sender.sendMessage("Shake never actually got around to implementing this command.");
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.shakeforprotein.shakenbt.Commands;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
Expand All @@ -26,7 +26,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player p = (Player) sender;
if(p.getInventory().getItemInMainHand() != null && p.getInventory().getItemInMainHand().getType() != Material.AIR) {
ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);
Set<String> compoundKeys = compound.getKeys();
p.sendMessage("Retrieving nbt");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package me.shakeforprotein.shakenbt.Listeners;

import me.shakeforprotein.shakenbt.ShakeNBT;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import org.bukkit.ChatColor;
import net.minecraft.server.v1_15_R1.MinecraftServer;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MainHand;

import java.util.*;

Expand All @@ -28,7 +30,7 @@ public void onBlockBreakEvent(BlockBreakEvent e) {
if (mHI.getType() != Material.AIR && (mHI.getType().name().toUpperCase().contains("_PICKAXE") || mHI.getType().name().toUpperCase().contains("_AXE"))) {

ItemStack bukkitItem = p.getInventory().getItemInMainHand();
net.minecraft.server.v1_14_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
net.minecraft.server.v1_15_R1.ItemStack nmsItem = pl.getNMSItem(bukkitItem);
NBTTagCompound compound = pl.getCompound(nmsItem);
Set<String> compoundKeys = compound.getKeys();
if (compoundKeys.contains("ShakeEnchant")) {
Expand Down Expand Up @@ -78,39 +80,62 @@ public void onBlockBreakEvent(BlockBreakEvent e) {
} else if (drop.getType().name().toUpperCase().contains("CLAY_BALL")) {
newDrops.add(new ItemStack(Material.BRICK, drop.getAmount()));
}
}
else {
} else {
newDrops.add(drop);
}
}
if (!newDrops.isEmpty()) {
drops.clear();
drops.addAll(newDrops);
for(ItemStack drop: drops){
e.getBlock().getWorld().dropItem(e.getBlock().getLocation() ,drop);
for (ItemStack drop : drops) {
e.getBlock().getWorld().dropItem(e.getBlock().getLocation(), drop);
}
e.getBlock().setType(Material.AIR);
}
}
else if (ench.equalsIgnoreCase("+Size")){
} else if (ench.equalsIgnoreCase("+Size")) {
Location loc = e.getBlock().getLocation();
HashMap<Integer, Location> locationHashmap = new HashMap<>();
int i,j,k,l = 0;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
for(k=0;k<3;k++){
locationHashmap.put(l, loc.add(i-1,j-1,k-1));
l++;
int i, j, k, l = 0;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 3; k++) {
locationHashmap.put(l, loc.add(i - 1, j - 1, k - 1));
l++;
}
}
}
for(i=0; i<l+1; i++){
if(locationHashmap.get(i).getBlock().getType().equals(loc.getBlock().getType())) {
for (i = 0; i < l + 1; i++) {
if (locationHashmap.get(i).getBlock().getType().equals(loc.getBlock().getType())) {
locationHashmap.get(i).getBlock().breakNaturally(mHI);
}
}
}
}
}
}

@EventHandler
public void witherBreakBlocks(EntityExplodeEvent e) {
double[] tps = MinecraftServer.getServer().recentTps;
if (tps[0] < 18) {
if (e.getEntity().getType().name().toUpperCase().contains("WITHER")) {
e.setCancelled(true);
for (Block b : e.blockList()) {
b.setType(Material.AIR);
}
}
}
}

@EventHandler
public void witherBreakBlocks2(EntityChangeBlockEvent e) {
double[] tps = MinecraftServer.getServer().recentTps;
if (tps[0] < 18) {
if (e.getEntity().getType().name().toUpperCase().contains("WITHER")) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.shakeforprotein.shakenbt.Listeners;

import me.shakeforprotein.shakenbt.ShakeNBT;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.VillagerCareerChangeEvent;

public class onEntityDamage implements Listener {

private ShakeNBT pl;

public onEntityDamage(ShakeNBT main){
this.pl = main;
}

private void onHitVillager(VillagerCareerChangeEvent e){
if(!((Villager) e.getEntity()).getProfession().equals(Villager.Profession.NITWIT) && ((Villager) e.getEntity()).getProfession().equals(Villager.Profession.NONE) && ((Villager)e.getEntity()).getRecipeCount() == 0){
e.getEntity().getLocation().getWorld().spawnEntity(e.getEntity().getLocation(), e.getEntityType());
e.getEntity().remove();
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/me/shakeforprotein/shakenbt/ShakeNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import me.shakeforprotein.shakenbt.Commands.*;
import me.shakeforprotein.shakenbt.Listeners.onBlockBreak;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -35,17 +35,17 @@ public void onDisable() {
}


public net.minecraft.server.v1_14_R1.ItemStack getNMSItem(ItemStack item){
net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
public net.minecraft.server.v1_15_R1.ItemStack getNMSItem(ItemStack item){
net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
return nmsItem;
}

public NBTTagCompound getCompound(net.minecraft.server.v1_14_R1.ItemStack nmsItem){
public NBTTagCompound getCompound(net.minecraft.server.v1_15_R1.ItemStack nmsItem){
NBTTagCompound nmsCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound();
return nmsCompound;
}

public ItemStack getBukkitItem(net.minecraft.server.v1_14_R1.ItemStack nmsItem){
public ItemStack getBukkitItem(net.minecraft.server.v1_15_R1.ItemStack nmsItem){
ItemStack bukkitItem = CraftItemStack.asBukkitCopy(nmsItem);
return bukkitItem;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ releasePage: 'https://github.com/TreeboMC/ShakeNBT/releases/latest'
messages:
badge: '&6[ShakeNBT]&r'
error: '&4ERROR:&r'

disableBlockExplosionsLowTPS: true

0 comments on commit d7a8a57

Please sign in to comment.