Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Small singleton class I use for most of the game modes I make---
- public class Arena {
- private static Arena arena = new Arena();
- public Arena(){}
- public static Arena getArena(){
- return arena;
- }
- public boolean inGame;
- public List<Player> players;
- public List<Player> spectators;
- public HashMap<Player,Integer> kills;
- public int border;
- public boolean isInGame() {
- return inGame;
- }
- public void setInGame(boolean inGame) {
- this.inGame = inGame;
- }
- public List<Player> getPlayers() {
- return players;
- }
- public void setPlayers(List<Player> players) {
- this.players = players;
- }
- public void addPlayer(Player p){
- players.add(p);
- kills.put(p,0);
- }
- public void removePlayer(Player p){
- players.remove(p);
- kills.remove(p);
- }
- public void addSpectator(Player p){
- spectators.add(p);
- }
- public void removeSpectator(Player p){
- spectators.remove(p);
- }
- public List<Player> getSpectators() {
- return spectators;
- }
- public void setSpectators(List<Player> spectators) {
- this.spectators = spectators;
- }
- public HashMap<Player, Integer> getKills() {
- return kills;
- }
- public void setKills(HashMap<Player, Integer> kills) {
- this.kills = kills;
- }
- public Integer getPlayerKills(Player p){
- return kills.get(p);
- }
- public void setPlayerKills(Player p, Integer playerKills){
- kills.put(p,playerKills);
- }
- public int getBorder() {
- return border;
- }
- public void setBorder(int border) {
- this.border = border;
- }
- }
- --- This is a small plugin that will perform a command thats on a sign when you right click an armorstand---
- public class main extends JavaPlugin implements Listener {
- @Override
- public void onEnable() {this.getServer().getPluginManager().registerEvents(this, this);}
- @EventHandler
- public void clickEvent(PlayerInteractAtEntityEvent e) {
- Player p = e.getPlayer();
- Entity b = e.getRightClicked();
- if (b.getType() == EntityType.ARMOR_STAND) {
- Location bLoc = b.getLocation();
- int x = bLoc.getBlockX();
- int z = bLoc.getBlockZ();
- int y1 = bLoc.getBlockY();
- int y2 = y1 - 2;
- World w = bLoc.getWorld();
- Location sLoc = new Location(w, x, y2, z);
- Block sign = sLoc.getBlock();
- if (sign.getType() == Material.SIGN || sign.getType() == Material.SIGN_POST || sign.getType() == Material.WALL_SIGN) {
- Sign signS = (Sign) sign.getState();
- String command = signS.getLine(0);
- p.performCommand(command);
- }
- }
- }
- }
- --- This is a modified zombie of course it needs to be added to the game ---
- import net.minecraft.server.v1_8_R3.*;
- import org.bukkit.ChatColor;
- import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
- import java.lang.reflect.Field;
- import java.util.List;
- /**
- * Created by robin on 31/12/15.
- */
- public class CustomZombie2 extends EntityZombie {
- public CustomZombie2(org.bukkit.World world) {
- super(((CraftWorld)world).getHandle());
- List goalB = (List)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
- List goalC = (List)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
- List targetB = (List)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
- List targetC = (List)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();
- this.goalSelector.a(0, new PathfinderGoalFloat(this));
- this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
- this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntityVillager.class, 1.0D, true));
- this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
- this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
- this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 5.0D));
- this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 16.0F));
- this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
- this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
- this.targetSelector.a(2,new PathfinderGoalNearestAttackableTarget(this,EntityHuman.class,true));
- this.targetSelector.a(2,new PathfinderGoalNearestAttackableTarget(this,EntityVillager.class,false));
- this.setCustomName(ChatColor.GREEN+"Test Subject B");
- this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(9);
- this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.5);
- this.getAttributeInstance(GenericAttributes.maxHealth).setValue(100);
- }
- public static Object getPrivateField(String fieldName, Class clazz, Object object)
- {
- Field field;
- Object o = null;
- try
- {
- field = clazz.getDeclaredField(fieldName);
- field.setAccessible(true);
- o = field.get(object);
- }
- catch(NoSuchFieldException e)
- {
- e.printStackTrace();
- }
- catch(IllegalAccessException e)
- {
- }
- return o;
- }
- }
- --- MySQL class---
- public class MySQL {
- private String host;
- private String user;
- private String pass;
- private String db;
- private String p;
- private Connection c;
- public MySQL (String hostName,String userName,String password, String database, String port){
- if(hostName!=null && userName!=null && password!=null && database != null){
- host=hostName;
- user=userName;
- pass=password;
- db=database;
- if(port==null){
- p = "3306";
- }else{
- p= port;
- }
- }
- }
- public void connect(){
- try {
- c = DriverManager.getConnection("jdbc:mysql://" + host + ":" + p + "/"
- + db + "?autoReconnect=true", user, pass);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void close(){
- try {
- c.close();
- }catch (SQLException e){
- e.printStackTrace();
- }
- }
- public void update(String qry) {
- try {
- Statement st = c.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = c.createStatement();
- rs = st.executeQuery(qry);
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- public Connection getC() {
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement