More optimizing.

This commit is contained in:
GJ 2012-02-23 22:26:20 -05:00
parent 10fa9e5465
commit 19ab8b89f5
6 changed files with 38 additions and 94 deletions

View File

@ -23,7 +23,6 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -180,15 +179,21 @@ public class m
return true; return true;
} }
public static void mcDropItem(Location location, int id) public static void mcDropItems(Location location, ItemStack is, int quantity)
{ {
if(location == null) return; for(int i = 0; i < quantity; i++)
mcDropItem(location, is);
Material mat = Material.getMaterial(id); }
ItemStack item = new ItemStack(mat, 1, (byte) 0, (byte) 0); public static void mcRandomDropItem(Location location, ItemStack is, int chance)
mcDropItem(location, item); {
if(Math.random() * 100 < chance)
mcDropItem(location, is);
}
public static void mcRandomDropItems(Location location, ItemStack is, int chance, int quantity)
{
for(int i = 0; i < quantity; i++)
mcRandomDropItem(location, is, chance);
} }
public static void mcDropItem(Location location, ItemStack itemStack) { public static void mcDropItem(Location location, ItemStack itemStack) {
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event. // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack); McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);

View File

@ -49,56 +49,33 @@ public class BlastMining{
return; return;
} }
switch (id) switch (id){
{
//GLOWSTONE //GLOWSTONE
case 89: case 89:
mat = Material.getMaterial(348); mat = Material.getMaterial(348);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 2);
m.mcDropItem(loc, item); m.mcRandomDropItems(loc, item, 50, 2);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//REDSTONE //REDSTONE
case 73: case 73:
mat = Material.getMaterial(331); mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItem(loc, item, 50);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
case 74: case 74:
mat = Material.getMaterial(331); mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItem(loc, item, 50);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//LAPIS //LAPIS
case 21: case 21:
mat = Material.getMaterial(351); mat = Material.getMaterial(351);
item = new ItemStack(mat, 1, (byte)0,(byte)0x4); item = new ItemStack(mat, 1, (byte)0,(byte)0x4);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItems(loc, item, 50, 4);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//DIAMOND //DIAMOND
case 56: case 56:
@ -118,7 +95,7 @@ public class BlastMining{
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItem(loc, item);
break; break;
} }
} }
/* /*

View File

@ -193,14 +193,8 @@ public class Herbalism
{ {
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel)) if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
{ {
m.mcDropItem(loc, is); m.mcDropItems(loc, is, 2);
m.mcDropItem(loc, is); m.mcRandomDropItems(loc, is, 50, 3);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
} }
} }
} }
@ -310,17 +304,8 @@ public class Herbalism
{ {
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel)) if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
{ {
m.mcDropItem(loc, is); m.mcDropItems(loc, is, 3);
m.mcDropItem(loc, is); m.mcRandomDropItems(loc, is, 50, 4);
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
} }
} }
PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player); PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player);

View File

@ -100,50 +100,28 @@ public class Mining
case 89: case 89:
mat = Material.getMaterial(348); mat = Material.getMaterial(348);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 2);
m.mcDropItem(loc, item); m.mcRandomDropItems(loc, item, 50, 2);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//REDSTONE //REDSTONE
case 73: case 73:
mat = Material.getMaterial(331); mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItem(loc, item, 50);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
case 74: case 74:
mat = Material.getMaterial(331); mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage); item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItem(loc, item, 50);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//LAPIS //LAPIS
case 21: case 21:
mat = Material.getMaterial(351); mat = Material.getMaterial(351);
item = new ItemStack(mat, 1, (byte)0,(byte)0x4); item = new ItemStack(mat, 1, (byte)0,(byte)0x4);
m.mcDropItem(loc, item); m.mcDropItems(loc, item, 4);
m.mcDropItem(loc, item); m.mcRandomDropItems(loc, item, 50, 4);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
break; break;
//DIAMOND //DIAMOND
case 56: case 56:

View File

@ -441,7 +441,7 @@ public class Skills
Integer x = 0; Integer x = 0;
while(x < plugin.misc.arrowTracker.get(entity)) while(x < plugin.misc.arrowTracker.get(entity))
{ {
m.mcDropItem(entity.getLocation(), 262); m.mcDropItem(entity.getLocation(), new ItemStack(262, 1));
x++; x++;
} }
} }

View File

@ -109,9 +109,8 @@ public class WoodCutting
Material mat = Material.SAPLING; Material mat = Material.SAPLING;
ItemStack item = new ItemStack(mat, 1, (short)0, (byte)(x.getData()-8)); ItemStack item = new ItemStack(mat, 1, (short)0, (byte)(x.getData()-8));
//1 in 10 chance to drop sapling //90% chance to drop sapling
if(Math.random() * 10 > 9) m.mcRandomDropItem(x.getLocation(), item, 90);
m.mcDropItem(x.getLocation(), item);
//Remove the block //Remove the block
x.setData((byte) 0); x.setData((byte) 0);