Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. ---Small singleton class I use for most of the game modes I make---
  2.  
  3. public class Arena {
  4. private static Arena arena = new Arena();
  5. public Arena(){}
  6. public static Arena getArena(){
  7. return arena;
  8. }
  9. public boolean inGame;
  10. public List<Player> players;
  11. public List<Player> spectators;
  12. public HashMap<Player,Integer> kills;
  13. public int border;
  14.  
  15. public boolean isInGame() {
  16. return inGame;
  17. }
  18. public void setInGame(boolean inGame) {
  19. this.inGame = inGame;
  20. }
  21.  
  22. public List<Player> getPlayers() {
  23. return players;
  24. }
  25.  
  26. public void setPlayers(List<Player> players) {
  27. this.players = players;
  28. }
  29.  
  30. public void addPlayer(Player p){
  31. players.add(p);
  32. kills.put(p,0);
  33. }
  34. public void removePlayer(Player p){
  35. players.remove(p);
  36. kills.remove(p);
  37. }
  38. public void addSpectator(Player p){
  39. spectators.add(p);
  40. }
  41. public void removeSpectator(Player p){
  42. spectators.remove(p);
  43. }
  44.  
  45. public List<Player> getSpectators() {
  46. return spectators;
  47. }
  48.  
  49. public void setSpectators(List<Player> spectators) {
  50. this.spectators = spectators;
  51. }
  52.  
  53. public HashMap<Player, Integer> getKills() {
  54. return kills;
  55. }
  56.  
  57. public void setKills(HashMap<Player, Integer> kills) {
  58. this.kills = kills;
  59. }
  60.  
  61. public Integer getPlayerKills(Player p){
  62. return kills.get(p);
  63. }
  64. public void setPlayerKills(Player p, Integer playerKills){
  65. kills.put(p,playerKills);
  66. }
  67.  
  68. public int getBorder() {
  69. return border;
  70. }
  71.  
  72. public void setBorder(int border) {
  73. this.border = border;
  74. }
  75. }
  76.  
  77. --- This is a small plugin that will perform a command thats on a sign when you right click an armorstand---
  78.  
  79. public class main extends JavaPlugin implements Listener {
  80.  
  81. @Override
  82. public void onEnable() {this.getServer().getPluginManager().registerEvents(this, this);}
  83.  
  84. @EventHandler
  85. public void clickEvent(PlayerInteractAtEntityEvent e) {
  86. Player p = e.getPlayer();
  87. Entity b = e.getRightClicked();
  88.  
  89. if (b.getType() == EntityType.ARMOR_STAND) {
  90. Location bLoc = b.getLocation();
  91. int x = bLoc.getBlockX();
  92. int z = bLoc.getBlockZ();
  93. int y1 = bLoc.getBlockY();
  94. int y2 = y1 - 2;
  95. World w = bLoc.getWorld();
  96. Location sLoc = new Location(w, x, y2, z);
  97. Block sign = sLoc.getBlock();
  98.  
  99. if (sign.getType() == Material.SIGN || sign.getType() == Material.SIGN_POST || sign.getType() == Material.WALL_SIGN) {
  100.  
  101. Sign signS = (Sign) sign.getState();
  102. String command = signS.getLine(0);
  103. p.performCommand(command);
  104. }
  105. }
  106. }
  107. }
  108.  
  109. --- This is a modified zombie of course it needs to be added to the game ---
  110.  
  111. import net.minecraft.server.v1_8_R3.*;
  112. import org.bukkit.ChatColor;
  113. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  114.  
  115. import java.lang.reflect.Field;
  116. import java.util.List;
  117.  
  118. /**
  119. * Created by robin on 31/12/15.
  120. */
  121. public class CustomZombie2 extends EntityZombie {
  122.  
  123. public CustomZombie2(org.bukkit.World world) {
  124.  
  125. super(((CraftWorld)world).getHandle());
  126.  
  127. List goalB = (List)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
  128. List goalC = (List)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
  129. List targetB = (List)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
  130. List targetC = (List)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();
  131.  
  132. this.goalSelector.a(0, new PathfinderGoalFloat(this));
  133. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
  134. this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntityVillager.class, 1.0D, true));
  135. this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
  136. this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
  137. this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 5.0D));
  138. this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 16.0F));
  139. this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
  140. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
  141. this.targetSelector.a(2,new PathfinderGoalNearestAttackableTarget(this,EntityHuman.class,true));
  142. this.targetSelector.a(2,new PathfinderGoalNearestAttackableTarget(this,EntityVillager.class,false));
  143. this.setCustomName(ChatColor.GREEN+"Test Subject B");
  144. this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(9);
  145. this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.5);
  146. this.getAttributeInstance(GenericAttributes.maxHealth).setValue(100);
  147.  
  148.  
  149. }
  150.  
  151.  
  152. public static Object getPrivateField(String fieldName, Class clazz, Object object)
  153. {
  154. Field field;
  155. Object o = null;
  156. try
  157. {
  158. field = clazz.getDeclaredField(fieldName);
  159.  
  160. field.setAccessible(true);
  161.  
  162. o = field.get(object);
  163. }
  164. catch(NoSuchFieldException e)
  165. {
  166. e.printStackTrace();
  167. }
  168. catch(IllegalAccessException e)
  169. {
  170. }
  171.  
  172. return o;
  173. }
  174.  
  175. }
  176.  
  177.  
  178. --- MySQL class---
  179.  
  180. public class MySQL {
  181. private String host;
  182. private String user;
  183. private String pass;
  184. private String db;
  185. private String p;
  186.  
  187. private Connection c;
  188.  
  189. public MySQL (String hostName,String userName,String password, String database, String port){
  190. if(hostName!=null && userName!=null && password!=null && database != null){
  191. host=hostName;
  192. user=userName;
  193. pass=password;
  194. db=database;
  195. if(port==null){
  196. p = "3306";
  197. }else{
  198. p= port;
  199. }
  200. }
  201. }
  202. public void connect(){
  203. try {
  204. c = DriverManager.getConnection("jdbc:mysql://" + host + ":" + p + "/"
  205. + db + "?autoReconnect=true", user, pass);
  206. } catch (SQLException e) {
  207. e.printStackTrace();
  208. }
  209. }
  210.  
  211. public void close(){
  212. try {
  213. c.close();
  214. }catch (SQLException e){
  215. e.printStackTrace();
  216. }
  217. }
  218.  
  219. public void update(String qry) {
  220. try {
  221. Statement st = c.createStatement();
  222. st.executeUpdate(qry);
  223. st.close();
  224. } catch (SQLException e) {
  225. e.printStackTrace();
  226. }
  227. }
  228.  
  229. public ResultSet query(String qry) {
  230. ResultSet rs = null;
  231.  
  232. try {
  233. Statement st = c.createStatement();
  234. rs = st.executeQuery(qry);
  235. } catch (SQLException e) {
  236. connect();
  237. System.err.println(e);
  238. }
  239. return rs;
  240. }
  241.  
  242. public Connection getC() {
  243. return c;
  244. }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement