Updated file delete mechanism so there is no reflection.

Removed list block on deleting players from coreclient quit.
This commit is contained in:
Jonathan Williams 2014-05-02 23:12:39 -07:00
parent f4a92ec07a
commit 484ba97b23
6 changed files with 495 additions and 62 deletions

Binary file not shown.

View File

@ -23,11 +23,13 @@ public class FileUtil
if(f.isDirectory())
DeleteFolder(f);
else
f.delete();
{
f.delete();
}
}
}
folder.delete();
folder.delete();
}
public static void CopyToDirectory(File file, String outputDirectory)

View File

@ -1,10 +1,6 @@
package mineplex.core.common.util;
import java.io.File;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@ -13,11 +9,10 @@ import java.util.Map;
import net.minecraft.server.v1_7_R3.Block;
import net.minecraft.server.v1_7_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_7_R3.ChunkSection;
import net.minecraft.server.v1_7_R3.IContainer;
import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.PacketPlayOutMultiBlockChange;
import net.minecraft.server.v1_7_R3.PlayerChunkMap;
import net.minecraft.server.v1_7_R3.RegionFile;
import net.minecraft.server.v1_7_R3.RegionFileCache;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@ -212,6 +207,8 @@ public class MapUtil
entity.remove();
}
((CraftWorld)world).getHandle().entityList.clear();
CraftServer server = (CraftServer)plugin.getServer();
CraftWorld craftWorld = (CraftWorld)world;
@ -270,47 +267,23 @@ public class MapUtil
@SuppressWarnings({ "rawtypes"})
public static boolean ClearWorldReferences(String worldName)
{
HashMap regionfiles = null;
Field rafField = null;
try
{
Field a = net.minecraft.server.v1_7_R3.RegionFileCache.class.getDeclaredField("a");
a.setAccessible(true);
regionfiles = (HashMap) a.get(null);
rafField = net.minecraft.server.v1_7_R3.RegionFile.class.getDeclaredField("c");
rafField.setAccessible(true);
}
catch (Throwable t)
{
System.out.println("Error binding to region file cache.");
t.printStackTrace();
}
if (regionfiles == null) return false;
if (rafField == null) return false;
HashMap regionfiles = (HashMap) RegionFileCache.a;
ArrayList<Object> removedKeys = new ArrayList<Object>();
try
{
for (Object o : regionfiles.entrySet())
for (Iterator<Object> iterator = regionfiles.entrySet().iterator(); iterator.hasNext();)
{
Map.Entry e = (Map.Entry) o;
File f = (File) e.getKey();
if (f.toString().startsWith("." + File.separator + worldName))
Map.Entry e = (Map.Entry) iterator.next();
RegionFile file = (RegionFile) e.getValue();
try
{
RegionFile file = (RegionFile) e.getValue();
try
{
RandomAccessFile raf = (RandomAccessFile) rafField.get(file);
raf.close();
removedKeys.add(f);
}
catch (Exception ex)
{
ex.printStackTrace();
}
file.c();
iterator.remove();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
@ -319,9 +292,6 @@ public class MapUtil
System.out.println("Exception while removing world reference for '" + worldName + "'!");
ex.printStackTrace();
}
for (Object key : removedKeys)
regionfiles.remove(key);
return true;
}

View File

@ -198,24 +198,10 @@ public class CoreClientManager implements Listener
}
}
@EventHandler
public void Kick(PlayerKickEvent event)
{
if (event.getReason().equalsIgnoreCase("You logged in from another location"))
{
_dontRemoveList.add(event.getPlayer().getName());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Quit(PlayerQuitEvent event)
{
if (!_dontRemoveList.contains(event.getPlayer().getName()))
{
Del(event.getPlayer().getName());
}
_dontRemoveList.remove(event.getPlayer().getName());
Del(event.getPlayer().getName());
}
public void SaveRank(final String name, Rank rank, boolean perm)

View File

@ -0,0 +1,467 @@
package net.minecraft.server.v1_7_R3;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
public class EnchantmentManager
{
private static final Random random = new Random();
public static int getEnchantmentLevel(int paramInt, ItemStack paramItemStack)
{
if (paramItemStack == null)
{
return 0;
}
NBTTagList localNBTTagList = paramItemStack.getEnchantments();
if (localNBTTagList == null)
{
return 0;
}
for (int i = 0; i < localNBTTagList.size(); i++)
{
int j = localNBTTagList.get(i).getShort("id");
int k = localNBTTagList.get(i).getShort("lvl");
if (j == paramInt)
{
return k;
}
}
return 0;
}
public static Map a(ItemStack paramItemStack)
{
LinkedHashMap localLinkedHashMap = new LinkedHashMap();
NBTTagList localNBTTagList = paramItemStack.getItem() == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK
.g(paramItemStack) : paramItemStack.getEnchantments();
if (localNBTTagList != null)
{
for (int i = 0; i < localNBTTagList.size(); i++)
{
int j = localNBTTagList.get(i).getShort("id");
int k = localNBTTagList.get(i).getShort("lvl");
localLinkedHashMap.put(Integer.valueOf(j), Integer.valueOf(k));
}
}
return localLinkedHashMap;
}
public static void a(Map paramMap, ItemStack paramItemStack)
{
NBTTagList localNBTTagList = new NBTTagList();
for (Iterator localIterator = paramMap.keySet().iterator(); localIterator.hasNext();)
{
int i = ((Integer) localIterator.next()).intValue();
NBTTagCompound localNBTTagCompound = new NBTTagCompound();
localNBTTagCompound.setShort("id", (short) i);
localNBTTagCompound.setShort("lvl", (short) ((Integer) paramMap.get(Integer.valueOf(i))).intValue());
localNBTTagList.add(localNBTTagCompound);
if (paramItemStack.getItem() == Items.ENCHANTED_BOOK)
{
Items.ENCHANTED_BOOK.a(paramItemStack,
new EnchantmentInstance(i, ((Integer) paramMap.get(Integer.valueOf(i))).intValue()));
}
}
if (localNBTTagList.size() > 0)
{
if (paramItemStack.getItem() != Items.ENCHANTED_BOOK)
{
paramItemStack.a("ench", localNBTTagList);
}
}
else if (paramItemStack.hasTag())
{
paramItemStack.getTag().remove("ench");
}
}
public static int getEnchantmentLevel(int paramInt, ItemStack[] paramArrayOfItemStack)
{
if (paramArrayOfItemStack == null)
{
return 0;
}
int i = 0;
for (ItemStack localItemStack : paramArrayOfItemStack)
{
int m = getEnchantmentLevel(paramInt, localItemStack);
if (m > i)
{
i = m;
}
}
return i;
}
private static void a(EnchantmentModifier paramEnchantmentModifier, ItemStack paramItemStack)
{
if (paramItemStack == null)
{
return;
}
NBTTagList localNBTTagList = paramItemStack.getEnchantments();
if (localNBTTagList == null)
{
return;
}
for (int i = 0; i < localNBTTagList.size(); i++)
{
int j = localNBTTagList.get(i).getShort("id");
int k = localNBTTagList.get(i).getShort("lvl");
if (Enchantment.byId[j] != null)
{
paramEnchantmentModifier.a(Enchantment.byId[j], k);
}
}
}
private static void a(EnchantmentModifier paramEnchantmentModifier, ItemStack[] paramArrayOfItemStack)
{
for (ItemStack localItemStack : paramArrayOfItemStack)
{
a(paramEnchantmentModifier, localItemStack);
}
}
private static EnchantmentModifierProtection b = null;
public static int a(ItemStack[] paramArrayOfItemStack, DamageSource paramDamageSource)
{
if (b == null)
{
try
{
Constructor<EnchantmentModifierProtection> constructor = EnchantmentModifierProtection.class.getDeclaredConstructor();
constructor.setAccessible(true);
b = constructor.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
}
b.a = 0;
b.b = paramDamageSource;
a(b, paramArrayOfItemStack);
if (b.a > 25)
{
b.a = 25;
}
b.b = null;
return (b.a + 1 >> 1) + random.nextInt((b.a >> 1) + 1);
}
private static EnchantmentModifierDamage c = null;
public static float a(EntityLiving paramEntityLiving1, EntityLiving paramEntityLiving2)
{
return a(paramEntityLiving1.bd(), paramEntityLiving2.getMonsterType());
}
public static float a(ItemStack paramItemStack, EnumMonsterType paramEnumMonsterType)
{
if (c == null)
{
try
{
Constructor<EnchantmentModifierDamage> constructor = EnchantmentModifierDamage.class.getDeclaredConstructor();
constructor.setAccessible(true);
c = constructor.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
}
c.a = 0.0F;
c.b = paramEnumMonsterType;
a(c, paramItemStack);
c.b = null;
return c.a;
}
private static EnchantmentModifierThorns d = null;
public static void a(EntityLiving paramEntityLiving, Entity paramEntity)
{
if (d == null)
{
try
{
Constructor<EnchantmentModifierThorns> constructor = EnchantmentModifierThorns.class.getDeclaredConstructor();
constructor.setAccessible(true);
d = constructor.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
}
d.b = paramEntity;
d.a = paramEntityLiving;
a(d, paramEntityLiving.getEquipment());
if ((paramEntity instanceof EntityHuman))
{
a(d, paramEntityLiving.bd());
}
d.a = null;
d.b = null;
}
private static EnchantmentModifierArthropods e = null;
public static void b(EntityLiving paramEntityLiving, Entity paramEntity)
{
if (e == null)
{
try
{
Constructor<EnchantmentModifierArthropods> constructor = EnchantmentModifierArthropods.class.getDeclaredConstructor();
constructor.setAccessible(true);
e = constructor.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
}
e.a = paramEntityLiving;
e.b = paramEntity;
a(e, paramEntityLiving.getEquipment());
if ((paramEntityLiving instanceof EntityHuman))
{
a(e, paramEntityLiving.bd());
}
e.a = null;
e.b = null;
}
public static int getKnockbackEnchantmentLevel(EntityLiving paramEntityLiving1, EntityLiving paramEntityLiving2)
{
return getEnchantmentLevel(Enchantment.KNOCKBACK.id, paramEntityLiving1.bd());
}
public static int getFireAspectEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.FIRE_ASPECT.id, paramEntityLiving.bd());
}
public static int getOxygenEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.OXYGEN.id, paramEntityLiving.getEquipment());
}
public static int getDigSpeedEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.DIG_SPEED.id, paramEntityLiving.bd());
}
public static boolean hasSilkTouchEnchantment(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.SILK_TOUCH.id, paramEntityLiving.bd()) > 0;
}
public static int getBonusBlockLootEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS.id, paramEntityLiving.bd());
}
public static int getLuckEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.LUCK.id, paramEntityLiving.bd());
}
public static int getLureEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.LURE.id, paramEntityLiving.bd());
}
public static int getBonusMonsterLootEnchantmentLevel(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS.id, paramEntityLiving.bd());
}
public static boolean hasWaterWorkerEnchantment(EntityLiving paramEntityLiving)
{
return getEnchantmentLevel(Enchantment.WATER_WORKER.id, paramEntityLiving.getEquipment()) > 0;
}
public static ItemStack a(Enchantment paramEnchantment, EntityLiving paramEntityLiving)
{
for (ItemStack localItemStack : paramEntityLiving.getEquipment())
{
if ((localItemStack != null) && (getEnchantmentLevel(paramEnchantment.id, localItemStack) > 0))
{
return localItemStack;
}
}
return null;
}
public static int a(Random paramRandom, int paramInt1, int paramInt2, ItemStack paramItemStack)
{
Item localItem = paramItemStack.getItem();
int i = localItem.c();
if (i <= 0)
{
return 0;
}
if (paramInt2 > 15)
{
paramInt2 = 15;
}
int j = paramRandom.nextInt(8) + 1 + (paramInt2 >> 1) + paramRandom.nextInt(paramInt2 + 1);
if (paramInt1 == 0)
{
return Math.max(j / 3, 1);
}
if (paramInt1 == 1)
{
return j * 2 / 3 + 1;
}
return Math.max(j, paramInt2 * 2);
}
public static ItemStack a(Random paramRandom, ItemStack paramItemStack, int paramInt)
{
List localList = b(paramRandom, paramItemStack, paramInt);
int i = paramItemStack.getItem() == Items.BOOK ? 1 : 0;
if (i != 0)
{
paramItemStack.setItem(Items.ENCHANTED_BOOK);
}
if (localList != null)
{
for (EnchantmentInstance localEnchantmentInstance : (List<EnchantmentInstance>)localList)
{
if (i != 0)
{
Items.ENCHANTED_BOOK.a(paramItemStack, localEnchantmentInstance);
}
else
{
paramItemStack.addEnchantment(localEnchantmentInstance.enchantment, localEnchantmentInstance.level);
}
}
}
return paramItemStack;
}
public static List b(Random paramRandom, ItemStack paramItemStack, int paramInt)
{
Item localItem = paramItemStack.getItem();
int i = localItem.c();
if (i <= 0)
{
return null;
}
i /= 2;
i = 1 + paramRandom.nextInt((i >> 1) + 1) + paramRandom.nextInt((i >> 1) + 1);
int j = i + paramInt;
float f = (paramRandom.nextFloat() + paramRandom.nextFloat() - 1.0F) * 0.15F;
int k = (int) (j * (1.0F + f) + 0.5F);
if (k < 1)
{
k = 1;
}
ArrayList localArrayList = null;
Map localMap = b(k, paramItemStack);
if ((localMap != null) && (!localMap.isEmpty()))
{
EnchantmentInstance localEnchantmentInstance1 = (EnchantmentInstance) WeightedRandom.a(paramRandom,
localMap.values());
if (localEnchantmentInstance1 != null)
{
localArrayList = new ArrayList();
localArrayList.add(localEnchantmentInstance1);
int m = k;
while (paramRandom.nextInt(50) <= m)
{
Iterator localIterator1 = localMap.keySet().iterator();
Object localObject;
while (localIterator1.hasNext())
{
localObject = (Integer) localIterator1.next();
int n = 1;
for (EnchantmentInstance localEnchantmentInstance2 : (List<EnchantmentInstance>)localArrayList)
{
if (!localEnchantmentInstance2.enchantment.a(Enchantment.byId[((Integer)localObject).intValue()]))
{
n = 0;
break;
}
}
if (n == 0)
{
localIterator1.remove();
}
}
if (!localMap.isEmpty())
{
localObject = (EnchantmentInstance) WeightedRandom.a(paramRandom, localMap.values());
localArrayList.add(localObject);
}
m >>= 1;
}
}
}
return localArrayList;
}
public static Map b(int paramInt, ItemStack paramItemStack)
{
Item localItem = paramItemStack.getItem();
HashMap localHashMap = null;
int i = paramItemStack.getItem() == Items.BOOK ? 1 : 0;
for (Enchantment localEnchantment : Enchantment.byId)
{
if (localEnchantment != null)
{
if ((localEnchantment.slot.canEnchant(localItem)) || (i != 0))
{
for (int m = localEnchantment.getStartLevel(); m <= localEnchantment.getMaxLevel(); m++)
{
if ((paramInt >= localEnchantment.a(m)) && (paramInt <= localEnchantment.b(m)))
{
if (localHashMap == null)
{
localHashMap = new HashMap();
}
localHashMap.put(Integer.valueOf(localEnchantment.id), new EnchantmentInstance(
localEnchantment, m));
}
}
}
}
}
return localHashMap;
}
}

View File

@ -2,6 +2,9 @@ package nautilus.game.arcade;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import nautilus.game.arcade.addons.*;
import nautilus.game.arcade.command.*;
@ -20,6 +23,8 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBurnEvent;
@ -27,6 +32,7 @@ import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
@ -67,6 +73,8 @@ import mineplex.core.projectile.ProjectileManager;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ArcadeManager extends MiniPlugin implements IRelation
{