mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-26 18:37:43 +01:00
Added support for pigs -> pig zombies and villages -> witches.
Removed stack saving system and integrated an in nametag serialization. Fixed issue with updating name tags after stack remove. Cleaned up some reflection. Cleaned up breed cooldown system.
This commit is contained in:
parent
ac32623a68
commit
91875e73cd
@ -28,6 +28,7 @@ import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -136,20 +137,6 @@ public class UltimateStacker extends JavaPlugin {
|
||||
checkStorage();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
if (storage.containsGroup("entities")) {
|
||||
for (StorageRow row : storage.getRowsByGroup("entities")) {
|
||||
try {
|
||||
EntityStack stack = new EntityStack(
|
||||
UUID.fromString(row.getKey()),
|
||||
row.get("amount").asInt());
|
||||
|
||||
this.entityStackManager.addStack(stack);
|
||||
} catch (Exception e) {
|
||||
console.sendMessage("Failed to load entity.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (storage.containsGroup("spawners")) {
|
||||
for (StorageRow row : storage.getRowsByGroup("spawners")) {
|
||||
try {
|
||||
|
@ -38,7 +38,8 @@ public class EntityStack {
|
||||
Entity entity = getEntityByUniqueId(this.entity);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateStacker.getInstance(), () -> {
|
||||
Entity entit = getEntityByUniqueId(this.entity);
|
||||
if (entit == null) return;
|
||||
if (entit == null ||
|
||||
!UltimateStacker.getInstance().getEntityStackManager().isStacked(entity)) return;
|
||||
|
||||
entit.setCustomNameVisible(!Setting.HOLOGRAMS_ON_LOOK_ENTITY.getBoolean());
|
||||
entit.setCustomName(Methods.compileEntityName(entit, amount));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.ultimatestacker.entity;
|
||||
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -25,8 +27,27 @@ public class EntityStackManager {
|
||||
return stacks.put(uuid, new EntityStack(uuid, amount));
|
||||
}
|
||||
|
||||
public EntityStack addSerializedStack(Entity entity, String customName) {
|
||||
if (customName != null && customName.contains(String.valueOf(ChatColor.COLOR_CHAR))) {
|
||||
String name = customName.replace(String.valueOf(ChatColor.COLOR_CHAR), "")
|
||||
.replace(";", "");
|
||||
if (!name.contains(":")) return null;
|
||||
String split = name.split(":")[0];
|
||||
System.out.println(customName);
|
||||
int amount = Methods.isInt(split) ? Integer.parseInt(split) : 0;
|
||||
addStack(entity, amount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityStack addSerializedStack(Entity entity) {
|
||||
return addSerializedStack(entity, entity.getCustomName());
|
||||
}
|
||||
|
||||
public EntityStack getStack(Entity entity) {
|
||||
return getStack(entity.getUniqueId());
|
||||
EntityStack stack = getStack(entity.getUniqueId());
|
||||
if (stack == null) stack = addSerializedStack(entity);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public EntityStack getStack(UUID uuid) {
|
||||
@ -34,6 +55,10 @@ public class EntityStackManager {
|
||||
}
|
||||
|
||||
public boolean isStacked(Entity entity) {
|
||||
boolean isStacked = isStacked(entity.getUniqueId());
|
||||
if (!isStacked && addSerializedStack(entity) != null) {
|
||||
return true;
|
||||
}
|
||||
return isStacked(entity.getUniqueId());
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,9 @@ public class BreedListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBread(EntityBreedEvent event) {
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (event.getFather() != null)
|
||||
event.getFather().removeMetadata("breedCooldown", instance);
|
||||
if (event.getMother() != null)
|
||||
event.getMother().removeMetadata("breedCooldown", instance);
|
||||
event.getFather().removeMetadata("breedCooldown", instance);
|
||||
event.getMother().removeMetadata("breedCooldown", instance);
|
||||
}, 5 * 20 * 60);
|
||||
event.getFather().setMetadata("breedCooldown", new FixedMetadataValue(instance, true));
|
||||
event.getFather().removeMetadata("inLove", instance);
|
||||
|
@ -41,16 +41,10 @@ public class EntityListeners implements Listener {
|
||||
entity.setMetadata("US_REASON", new FixedMetadataValue(instance, event.getSpawnReason().name()));
|
||||
|
||||
if (event.getSpawnReason().name().equals("DROWNED")
|
||||
&& entity.getCustomName() != null
|
||||
&& entity.getCustomName().contains(String.valueOf(ChatColor.COLOR_CHAR))) {
|
||||
String name = event.getEntity().getCustomName().replace(String.valueOf(ChatColor.COLOR_CHAR), "");
|
||||
if (!name.contains(":")) return;
|
||||
String split = name.split(":")[0];
|
||||
int stackSize = Methods.isInt(split) ? Integer.parseInt(split) : 0;
|
||||
|
||||
if (stackSize == 0) return;
|
||||
|| event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.LIGHTNING) {
|
||||
String name = event.getEntity().getCustomName();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance,
|
||||
() -> instance.getEntityStackManager().addStack(entity, stackSize), 1L);
|
||||
() -> instance.getEntityStackManager().addSerializedStack(entity, name), 1L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,10 +31,6 @@ public abstract class Storage {
|
||||
public abstract void prepareSaveItem(String group, StorageItem... items);
|
||||
|
||||
public void updateData(UltimateStacker instance) {
|
||||
for (EntityStack stack : instance.getEntityStackManager().getStacks().values()) {
|
||||
prepareSaveItem("entities", new StorageItem("uuid", stack.getEntityUniqueId().toString()),
|
||||
new StorageItem("amount", stack.getAmount()));
|
||||
}
|
||||
|
||||
for (SpawnerStack stack : instance.getSpawnerStackManager().getStacks()) {
|
||||
prepareSaveItem("spawners", new StorageItem("location", Methods.serializeLocation(stack.getLocation())),
|
||||
|
@ -432,7 +432,7 @@ public class Methods {
|
||||
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
||||
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
||||
|
||||
String info = Methods.convertToInvisibleString(amount + ":");
|
||||
String info = Methods.convertToInvisibleString(insertSemicolon(String.valueOf(amount)) + ":");
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
|
||||
@ -443,7 +443,7 @@ public class Methods {
|
||||
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
||||
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
||||
|
||||
String info = Methods.convertToInvisibleString(amount + ":");
|
||||
String info = Methods.convertToInvisibleString(insertSemicolon(String.valueOf(amount)) + ":");
|
||||
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
@ -455,7 +455,7 @@ public class Methods {
|
||||
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
||||
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
||||
|
||||
String info = Methods.convertToInvisibleString(amount + ":");
|
||||
String info = Methods.convertToInvisibleString(insertSemicolon(String.valueOf(amount)) + ":");
|
||||
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
@ -464,7 +464,6 @@ public class Methods {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) return;
|
||||
|
||||
ItemStack item = player.getInventory().getItemInHand();
|
||||
if (item == null) return;
|
||||
|
||||
int result = item.getAmount() - amount;
|
||||
item.setAmount(result);
|
||||
@ -599,6 +598,14 @@ public class Methods {
|
||||
return hidden.toString();
|
||||
}
|
||||
|
||||
public static String insertSemicolon(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return "";
|
||||
StringBuilder hidden = new StringBuilder();
|
||||
for (char c : s.toCharArray()) hidden.append(";").append(c);
|
||||
return hidden.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
|
@ -29,10 +29,6 @@ public class MySQLDatabase {
|
||||
|
||||
private void createTables() {
|
||||
try {
|
||||
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "entities` (\n" +
|
||||
"\t`uuid` TEXT NULL,\n" +
|
||||
"\t`amount` INT NULL\n" +
|
||||
")");
|
||||
|
||||
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "spawners` (\n" +
|
||||
"\t`location` TEXT NULL,\n" +
|
||||
|
@ -38,9 +38,9 @@ public class Reflection {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return creatureSpawner;
|
||||
}else{
|
||||
try{
|
||||
if (clazzCraftCreatureSpawner==null) {
|
||||
} else {
|
||||
try {
|
||||
if (clazzCraftCreatureSpawner == null) {
|
||||
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
clazzCraftCreatureSpawner = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftCreatureSpawner");
|
||||
clazzTileEntityMobSpawner = Class.forName("net.minecraft.server." + ver + ".TileEntityMobSpawner");
|
||||
@ -56,8 +56,8 @@ public class Reflection {
|
||||
Object objcraftCreatureSpawner = clazzCraftCreatureSpawner.cast(creatureSpawner);
|
||||
Object objTileEntityMobSpawner = fieldSpawner.get(objcraftCreatureSpawner);
|
||||
Object objMobSpawnerAbstract = methodGetSpawner.invoke(objTileEntityMobSpawner);
|
||||
fieldSpawnount.set(objMobSpawnerAbstract,count);
|
||||
fieldMaxNearbyEntities.set(objMobSpawnerAbstract,max);
|
||||
fieldSpawnount.set(objMobSpawnerAbstract, count);
|
||||
fieldMaxNearbyEntities.set(objMobSpawnerAbstract, max);
|
||||
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user