Random nooby questions

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Jan 17, 2014.

Thread Status:
Not open for further replies.
  1. Hey , how would I make it so when a TNT explodes it makes all blocks around it fly out as falling sand like a real explosion and how would I make it so it only explodes certain blocks for example dirt flys everywhere but the stone stays

    Particle question. How do I get note particles, colored particles and waterdrop particles etc
     
  2. Offline

    jusjus112

    KevyPorter
    For your first question use this from my plugins:
    Code:java
    1. Plugin plugin;
    2.  
    3. @SuppressWarnings("deprecation")
    4. @EventHandler
    5. public void explode(EntityExplodeEvent e) {
    6. if (!e.blockList().isEmpty()) {
    7. final List<BlockState> blocks = new ArrayList<BlockState>();
    8. for (Block b : e.blockList()) {
    9. if (b.getType() != Material.AIR) {
    10. if (!blocks.contains(b.getState())) {
    11. blocks.add(b.getState());
    12. FallingBlock fb = b.getWorld().spawnFallingBlock(b.getLocation(), b.getType(), b.getData());
    13. fb.setDropItem(false);
    14. fb.setVelocity(new Vector(0, 0.6, 0));
    15. b.setType(Material.AIR);
    16. }
    17. }
    18. }
    19. new BukkitRunnable() {
    20. int i = 17;
    21. public void run() {
    22. if (i>0){
    23. i--;
    24. }else{
    25. regen(blocks, true, 6);
    26. this.cancel();
    27. }
    28. }
    29. }.runTaskTimer(plugin, 15,15);
    30.  
    31.  
    32. e.blockList().clear();
    33. }
    34. }
    35.  
    36. public void regen(final List<BlockState> blocks, final boolean effect, final int speed) {
    37.  
    38. new BukkitRunnable() {
    39. int i = -1;
    40. @SuppressWarnings("deprecation")
    41. public void run() {
    42. if (i != blocks.size()-1) {
    43. i++;
    44. BlockState bs = blocks.get(i);
    45. bs.getBlock().setType(bs.getType());
    46. bs.getBlock().setData(bs.getBlock().getData());
    47. if (effect)
    48. }else{
    49. for (BlockState bs : blocks) {
    50. bs.getBlock().setType(bs.getType());
    51. bs.getBlock().setData(bs.getBlock().getData());
    52. }
    53. blocks.clear();
    54. this.cancel();
    55. }
    56. }
    57. }.runTaskTimer(plugin, speed, speed);
    58. }
    59. }

    for your seond question, use THIS lib for the particle effects!
     
  3. jusjus112 yay thanks. Now how would I make the particles play every 45 degrees around the player like a circle motion playing every 45degrees
     
  4. Offline

    jusjus112

  5. Offline

    HeavyMine13

    Hey Kevin! Its Heavy, a VIP+ from Hypixel! I have been working on java for 5 years, and I'm gonna help u here! So for particles, use these:


    Main Class:
    Code:java
    1.  
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public final class Test extends JavaPlugin {
    6.  
    7.  
    8. @Override
    9. public void onEnable(){
    10. getLogger().info("RUN has been enabled,what a noob!");
    11. getServer().getPluginManager().registerEvents(new listeners(this), this);
    12. }
    13.  
    14. @Override
    15. public void onDisable() {
    16. getLogger().info("RUN has been disabled,u noob!");
    17. }
    18.  
    19.  
    20.  
    21.  
    22. }
    23.  
    24.  





    Listener Class:
    Code:java
    1.  
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.scheduler.BukkitScheduler;
    9.  
    10.  
    11.  
    12. public class listeners implements Listener {
    13. Test plugin;
    14.  
    15.  
    16. public listeners(Test instance){
    17. plugin = instance;
    18. }
    19.  
    20.  
    21.  
    22. @EventHandler (priority = EventPriority.HIGH)
    23. public void onPlayerJoin(final PlayerJoinEvent event){
    24. if(event.getPlayer().isOnline())
    25. if (event.getPlayer().getName().equalsIgnoreCase("Kevy_Porter")){
    26. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    27. scheduler.scheduleSyncRepeatingTask (plugin, new Runnable() {
    28. public void run() {
    29. ParticleEffect.NOTE.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    30. ParticleEffect.HEART.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    31. ParticleEffect.SLIME.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    32. ParticleEffect.CLOUD.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    33. ParticleEffect.PORTAL.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    34. ParticleEffect.FIREWORKS_SPARK.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    35. ParticleEffect.HAPPY_VILLAGER.display(event.getPlayer().getLocation().add(0.0, 2.1, 0.0), 0.25F, 0.0F, 0.25F, 1F, 5);
    36. }
    37. }, 50L, 10L);
    38.  
    39. }
    40. }
    41. }
    42.  
    43.  
    44.  
    45.  
    46.  



    And Just COPY those 2 classes exactly!

    ParticleEffect:
    Code:java
    1.  
    2.  
    3. import java.lang.reflect.Constructor;
    4. import java.util.ArrayList;
    5. import java.util.Arrays;
    6. import java.util.Collection;
    7. import java.util.HashMap;
    8. import java.util.List;
    9. import java.util.Map;
    10. import java.util.Map.Entry;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.Location;
    14. import org.bukkit.entity.Player;
    15.  
    16. import me.Kevy_Porter.test.ReflectionUtil;
    17. import me.Kevy_Porter.test.ReflectionUtil.DynamicPackage;
    18. import me.Kevy_Porter.test.ReflectionUtil.FieldEntry;
    19.  
    20. /**
    21.   * ParticleEffect Library v1.2
    22.   *
    23.   * This library was created by [USER=90640105]DarkBlade12[/USER] based on content related to particles of [USER=90705652]microgeek[/USER] (names and packet values) and allows you to display all Minecraft particle effects on a Bukkit server
    24.   *
    25.   * You are welcome to use it, modify it and redistribute it under the following conditions:
    26.   * 1. Credit us if you publish a plugin that uses this library
    27.   * 2. Don't remove this text
    28.   *
    29.   * @author DarkBlade12
    30.   */
    31. public enum ParticleEffect {
    32.  
    33. HUGE_EXPLOSION("hugeexplosion", 0),
    34. LARGE_EXPLODE("largeexplode", 1),
    35. FIREWORKS_SPARK("fireworksSpark", 2),
    36. BUBBLE("bubble", 3),
    37. SUSPEND("suspend", 4),
    38. DEPTH_SUSPEND("depthSuspend", 5),
    39. TOWN_AURA("townaura", 6),
    40. CRIT("crit", 7),
    41. MAGIC_CRIT("magicCrit", 8),
    42. MOB_SPELL("mobSpell", 9),
    43. MOB_SPELL_AMBIENT("mobSpellAmbient", 10),
    44. SPELL("spell", 11),
    45. INSTANT_SPELL("instantSpell", 12),
    46. WITCH_MAGIC("witchMagic", 13),
    47. NOTE("note", 14),
    48. PORTAL("portal", 15),
    49. ENCHANTMENT_TABLE("enchantmenttable", 16),
    50. EXPLODE("explode", 17),
    51. FLAME("flame", 18),
    52. LAVA("lava", 19),
    53. FOOTSTEP("footstep", 20),
    54. SPLASH("splash", 21),
    55. LARGE_SMOKE("largesmoke", 22),
    56. CLOUD("cloud", 23),
    57. RED_DUST("reddust", 24),
    58. SNOWBALL_POOF("snowballpoof", 25),
    59. DRIP_WATER("dripWater", 26),
    60. DRIP_LAVA("dripLava", 27),
    61. SNOW_SHOVEL("snowshovel", 28),
    62. SLIME("slime", 29),
    63. HEART("heart", 30),
    64. ANGRY_VILLAGER("angryVillager", 31),
    65. HAPPY_VILLAGER("happyVillager", 32);
    66.  
    67. private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<String, ParticleEffect>();
    68. private static final Map<Integer, ParticleEffect> ID_MAP = new HashMap<Integer, ParticleEffect>();
    69. private static final double MAX_RANGE = 20.0D;
    70. private static Constructor<?> PARTICLE_PACKET_CONSTRUCTOR;
    71.  
    72. static {
    73. for (ParticleEffect effect : values()) {
    74. NAME_MAP.put(effect.name, effect);
    75. ID_MAP.put(effect.id, effect);
    76. }
    77. try {
    78. PARTICLE_PACKET_CONSTRUCTOR = ReflectionUtil.getConstructor(ReflectionUtil.getClass("PacketPlayOutWorldParticles", DynamicPackage.MINECRAFT_SERVER));
    79. } catch (Exception e) {
    80. e.printStackTrace();
    81. }
    82. }
    83.  
    84. private String name;
    85. private int id;
    86.  
    87. ParticleEffect(String name, int id) {
    88. this.name = name;
    89. this.id = id;
    90. }
    91.  
    92. public String getName() {
    93. return name;
    94. }
    95.  
    96. public int getId() {
    97. return id;
    98. }
    99.  
    100. public static ParticleEffect fromName(String name) {
    101. if (name != null)
    102. for (Entry<String, ParticleEffect> e : NAME_MAP.entrySet())
    103. if (e.getKey().equalsIgnoreCase(name))
    104. return e.getValue();
    105. return null;
    106. }
    107.  
    108. public static ParticleEffect fromId(int id) {
    109. return ID_MAP.get(id);
    110. }
    111.  
    112. private static List<Player> getPlayersInRange(Location loc, double range) {
    113. List<Player> players = new ArrayList<Player>();
    114. double sqr = range * range;
    115. for (Player p : loc.getWorld().getPlayers())
    116. if (p.getLocation().distanceSquared(loc) <= sqr)
    117. players.add(p);
    118. return players;
    119. }
    120.  
    121. private static Object createPacket(String name, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    122. if (amount <= 0)
    123. throw new IllegalArgumentException("Amount of particles has to be greater than 0");
    124. try {
    125. Object p = PARTICLE_PACKET_CONSTRUCTOR.newInstance();
    126. ReflectionUtil.setValues(p, new FieldEntry("a", name), new FieldEntry("b", (float) loc.getX()), new FieldEntry("c", (float) loc.getY()), new FieldEntry("d", (float) loc.getZ()), new FieldEntry("e",
    127. offsetX), new FieldEntry("f", offsetY), new FieldEntry("g", offsetZ), new FieldEntry("h", speed), new FieldEntry("i", amount));
    128. return p;
    129. } catch (Exception e) {
    130. Bukkit.getLogger().warning("[ParticleEffect] Failed to create a particle packet!");
    131. return null;
    132. }
    133. }
    134.  
    135. private Object createPacket(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    136. return createPacket(this.getName(), loc, offsetX, offsetY, offsetZ, speed, amount);
    137. }
    138.  
    139. private static Object createIconCrackPacket(int id, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    140. return createPacket("iconcrack_" + id, loc, offsetX, offsetY, offsetZ, speed, amount);
    141. }
    142.  
    143. private static Object createBlockCrackPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    144. return createPacket("blockcrack_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, speed, amount);
    145. }
    146.  
    147. private static Object createBlockDustPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    148. return createPacket("blockdust_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, speed, amount);
    149. }
    150.  
    151. private static void sendPacket(Player p, Object packet) {
    152. if (packet != null)
    153. try {
    154. Object entityPlayer = ReflectionUtil.invokeMethod("getHandle", p.getClass(), p);
    155. Object playerConnection = ReflectionUtil.getValue("playerConnection", entityPlayer);
    156. ReflectionUtil.invokeMethod("sendPacket", playerConnection.getClass(), playerConnection, packet);
    157. } catch (Exception e) {
    158. Bukkit.getLogger().warning("[ParticleEffect] Failed to send a particle packet to " + p.getName() + "!");
    159. }
    160. }
    161.  
    162. private static void sendPacket(Collection<Player> players, Object packet) {
    163. for (Player p : players)
    164. sendPacket(p, packet);
    165. }
    166.  
    167. /**
    168.   * Displays a particle effect which is only visible for specific players
    169.   */
    170. public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    171. sendPacket(Arrays.asList(players), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
    172. }
    173.  
    174. /**
    175.   * Displays a particle effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    176.   */
    177. public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    178. display(loc, MAX_RANGE, offsetX, offsetY, offsetZ, speed, amount);
    179. }
    180.  
    181. /**
    182.   * Displays a particle effect which is visible for all players whitin a certain range in the the world of @param loc
    183.   */
    184. public void display(Location loc, double range, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    185. if (range > MAX_RANGE)
    186. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    187. sendPacket(getPlayersInRange(loc, range), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
    188. }
    189.  
    190. /**
    191.   * Displays an icon crack (item break) effect which is only visible for specific players
    192.   */
    193. public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    194. sendPacket(Arrays.asList(players), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
    195. }
    196.  
    197. /**
    198.   * Displays an icon crack (item break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    199.   */
    200. public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    201. displayIconCrack(loc, MAX_RANGE, id, offsetX, offsetY, offsetZ, speed, amount);
    202. }
    203.  
    204. /**
    205.   * Displays an icon crack (item break) effect which is visible for all players whitin a certain range in the the world of @param loc
    206.   */
    207. public static void displayIconCrack(Location loc, double range, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    208. if (range > MAX_RANGE)
    209. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    210. sendPacket(getPlayersInRange(loc, range), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
    211. }
    212.  
    213. /**
    214.   * Displays a block crack (block break) effect which is only visible for specific players
    215.   */
    216. public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    217. sendPacket(Arrays.asList(players), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    218. }
    219.  
    220. /**
    221.   * Displays a block crack (block break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    222.   */
    223. public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    224. displayBlockCrack(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
    225. }
    226.  
    227. /**
    228.   * Displays a block crack (block break) effect which is visible for all players whitin a certain range in the the world of @param loc
    229.   */
    230. public static void displayBlockCrack(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    231. if (range > MAX_RANGE)
    232. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    233. sendPacket(getPlayersInRange(loc, range), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    234. }
    235.  
    236. /**
    237.   * Displays a block dust effect which is only visible for specific players
    238.   */
    239. public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    240. sendPacket(Arrays.asList(players), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    241. }
    242.  
    243. /**
    244.   * Displays a block dust effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    245.   */
    246. public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    247. displayBlockDust(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
    248. }
    249.  
    250. /**
    251.   * Displays a block dust effect which is visible for all players whitin a certain range in the the world of @param loc
    252.   */
    253. public static void displayBlockDust(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    254. if (range > MAX_RANGE)
    255. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    256. sendPacket(getPlayersInRange(loc, range), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    257. }
    258. }
    259.  
    260.  
    261.  


    RefelctionUtil:
    Code:java
    1.  
    2. import java.lang.reflect.Constructor;
    3. import java.lang.reflect.Field;
    4. import java.lang.reflect.Method;
    5. import java.util.HashMap;
    6. import java.util.Map;
    7.  
    8. import org.bukkit.Bukkit;
    9.  
    10. /**
    11.   * ReflectionUtil v1.1
    12.   *
    13.   * You are welcome to use it, modify it and redistribute it under the condition to not claim this class as your own
    14.   *
    15.   * @author DarkBlade12
    16.   */
    17. public abstract class ReflectionUtil {
    18. private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>();
    19.  
    20. static {
    21. CORRESPONDING_TYPES.put(Byte.class, byte.class);
    22. CORRESPONDING_TYPES.put(Short.class, short.class);
    23. CORRESPONDING_TYPES.put(Integer.class, int.class);
    24. CORRESPONDING_TYPES.put(Long.class, long.class);
    25. CORRESPONDING_TYPES.put(Character.class, char.class);
    26. CORRESPONDING_TYPES.put(Float.class, float.class);
    27. CORRESPONDING_TYPES.put(Double.class, double.class);
    28. CORRESPONDING_TYPES.put(Boolean.class, boolean.class);
    29. }
    30.  
    31. public enum DynamicPackage {
    32. MINECRAFT_SERVER {
    33. @Override
    34. public String toString() {
    35. return "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().substring(23, 30);
    36. }
    37. },
    38. CRAFTBUKKIT {
    39. @Override
    40. public String toString() {
    41. return Bukkit.getServer().getClass().getPackage().getName();
    42. }
    43. };
    44. }
    45.  
    46. public static class FieldEntry {
    47. String key;
    48. Object value;
    49.  
    50. public FieldEntry(String key, Object value) {
    51. this.key = key;
    52. this.value = value;
    53. }
    54.  
    55. public String getKey() {
    56. return this.key;
    57. }
    58.  
    59. public Object getValue() {
    60. return this.value;
    61. }
    62. }
    63.  
    64. private static Class<?> getPrimitiveType(Class<?> clazz) {
    65. return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
    66. }
    67.  
    68. private static Class<?>[] toPrimitiveTypeArray(Object[] objects) {
    69. int a = objects != null ? objects.length : 0;
    70. Class<?>[] types = new Class<?>[a];
    71. for (int i = 0; i < a; i++)
    72. types[i] = getPrimitiveType(objects[i].getClass());
    73. return types;
    74. }
    75.  
    76. private static Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
    77. int a = classes != null ? classes.length : 0;
    78. Class<?>[] types = new Class<?>[a];
    79. for (int i = 0; i < a; i++)
    80. types[i] = getPrimitiveType(classes[i]);
    81. return types;
    82. }
    83.  
    84. private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
    85. if (a.length != o.length)
    86. return false;
    87. for (int i = 0; i < a.length; i++)
    88. if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
    89. return false;
    90. return true;
    91. }
    92.  
    93. public static Class<?> getClass(String name, DynamicPackage pack, String subPackage) throws Exception {
    94. return Class.forName(pack + (subPackage != null && subPackage.length() > 0 ? "." + subPackage : "") + "." + name);
    95. }
    96.  
    97. public static Class<?> getClass(String name, DynamicPackage pack) throws Exception {
    98. return getClass(name, pack, null);
    99. }
    100.  
    101. public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... paramTypes) {
    102. Class<?>[] t = toPrimitiveTypeArray(paramTypes);
    103. for (Constructor<?> c : clazz.getConstructors()) {
    104. Class<?>[] types = toPrimitiveTypeArray(c.getParameterTypes());
    105. if (equalsTypeArray(types, t))
    106. return c;
    107. }
    108. return null;
    109. }
    110.  
    111. public static Object newInstance(Class<?> clazz, Object... args) throws Exception {
    112. return getConstructor(clazz, toPrimitiveTypeArray(args)).newInstance(args);
    113. }
    114.  
    115. public static Object newInstance(String name, DynamicPackage pack, String subPackage, Object... args) throws Exception {
    116. return newInstance(getClass(name, pack, subPackage), args);
    117. }
    118.  
    119. public static Object newInstance(String name, DynamicPackage pack, Object... args) throws Exception {
    120. return newInstance(getClass(name, pack, null), args);
    121. }
    122.  
    123. public static Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
    124. Class<?>[] t = toPrimitiveTypeArray(paramTypes);
    125. for (Method m : clazz.getMethods()) {
    126. Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
    127. if (m.getName().equals(name) && equalsTypeArray(types, t))
    128. return m;
    129. }
    130. return null;
    131. }
    132.  
    133. public static Object invokeMethod(String name, Class<?> clazz, Object obj, Object... args) throws Exception {
    134. return getMethod(name, clazz, toPrimitiveTypeArray(args)).invoke(obj, args);
    135. }
    136.  
    137. public static Field getField(String name, Class<?> clazz) throws Exception {
    138. return clazz.getDeclaredField(name);
    139. }
    140.  
    141. public static Object getValue(String name, Object obj) throws Exception {
    142. Field f = getField(name, obj.getClass());
    143. f.setAccessible(true);
    144. return f.get(obj);
    145. }
    146.  
    147. public static void setValue(Object obj, FieldEntry entry) throws Exception {
    148. Field f = getField(entry.getKey(), obj.getClass());
    149. f.setAccessible(true);
    150. f.set(obj, entry.getValue());
    151. }
    152.  
    153. public static void setValues(Object obj, FieldEntry... entrys) throws Exception {
    154. for (FieldEntry f : entrys)
    155. setValue(obj, f);
    156. }
    157. }
    158.  
    159.  
    160. [/i][/i][/i][/i][/i][/i][/i][/i]
     
Thread Status:
Not open for further replies.

Share This Page