php code tags

Results 1 to 4 of 4
  1. #1
    Account Upgraded | Title Enabled! Las Systos is offline
    True MemberRank
    Mar 2015 Join Date
    NetherlandsLocation
    211Posts

    php code tags


    RaGEZONE Recommends

    RaGEZONE Recommends

    So I was making a thread for a release.
    I put some code in [php] tags and suddenly this happened:
    PHP Code:
    /* * Bingo Event for MapleStory! * (ragezone-link) */package net.custom;
    import client.MapleCharacter;import client.MapleClient;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Arrays;import java.util.HashMap;import java.util.LinkedHashSet;import java.util.Map;import java.util.Random;import java.util.Set;import java.util.concurrent.ScheduledFuture;import java.util.logging.Level;import java.util.logging.Logger;import net.server.Server;import server.TimerManager;import tools.DatabaseConnection;import tools.MaplePacketCreator;
    /** * * @author Las Systos */public class BingoHandler {
        private static BingoHandler instance = null;    private final Map<Integer, Boolean> bingoCalls = new HashMap<>();    private ScheduledFuture<?bingoTimer;    private final int interval 1// interval between new bingo numbers in minutes
        /**     * The constructor for BingoHandler, can only be 'constructed' once due to     * getInstance method. loadBingoCalls method should only be used once on     * server startup, for updating bingoCalls use updateBingoCalls method.     */    
    public BingoHandler() {        loadBingoCalls();        bingoTimer();    }
        
    /**     * This method makes a new BingoHandler just once, and always returns this     * bingo handler. (leeched from Server.java)     *     * [MENTION=850422]return[/MENTION] The BingoHandler Object     */    public static BingoHandler getInstance() {        if (instance == null) {            instance = new BingoHandler();        }        return instance;    }
        
    /**     * The makeBingoCard method generates 24 random non-recurring numbers and     * updates the new bingo card into the database.     *     * [MENTION=2000183830]para[/MENTION]m c - MapleClient     */    public static void makeBingoCard(MapleClient c) {        // generating numbers        int[] arr = new int[24];        Random rand = new Random();        Set<Integer> set = new LinkedHashSet<>();        while (set.size() < arr.length) {            set.add(rand.nextInt(89) + 10);        }        int pos = 0;        for (Integer v : set) {            arr[pos++] = v;        }        String numbers = Arrays.toString(arr);        numbers = numbers.substring(1, numbers.length() - 1);
            // adding generated numbers to db (too lazy to make 2 seperate methods for this)        try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE `characters` SET `bingocard` = ? WHERE `name` = ?")) {            ps.setString(1, numbers);            ps.setString(2, c.getPlayer().getName());            ps.execute();        } catch (SQLException ex) {            Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVERE, null, ex);        }
            // setting 'havecard' to true        c.getPlayer().setCard(true);
            // adding card to MapleCharacter        loadCard(c);    }
        /**     * The readBingoCard method returns all the bingo numbers from the players     * card that are stored in the database, the check if someone has a bingo     * card occurs in the script!     *     * [MENTION=2000183830]para[/MENTION]m c - MapleClient     * [MENTION=850422]return[/MENTION] BingoCard numbers     */    
    private static String readBingoCard(MapleClient c) {        try (PreparedStatement ps DatabaseConnection.getConnection().prepareStatement("SELECT `bingocard` FROM `characters` WHERE `name` = ?")) {            ps.setString(1c.getPlayer().getName());            try (ResultSet rs ps.executeQuery()) {                if (rs.next()) {                    String card rs.getString("bingocard");                    return card;                }            }        } catch (SQLException ex) {            Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVEREnullex);        }        return null;    }
        
    /**     * Method to check if the player has a bingo card.     *     * [MENTION=2000183830]para[/MENTION]m c MapleClient     * [MENTION=850422]return[/MENTION] True or False whether the player has a card or not     */    public static boolean hasCard(MapleClient c) {        return readBingoCard(c) != null;    }
        
    /**     * Stores the bingo card in MapleCharacter     *     * [MENTION=2000183830]para[/MENTION]m c - MapleClient     */    public static void loadCard(MapleClient c) {        if (readBingoCard(c) != null) {            String[] numbers_string readBingoCard(c).split(", ");            int[] numbers_int = new int[24];            for (int i 0numbers_string.lengthi++) {                numbers_int[i] = Integer.valueOf(numbers_string[i]);            }            c.getPlayer().fillBingoNumbers(numbers_int);        }    }
        
    /**     * This method makes the bingo card readable for players.     *     * [MENTION=2000183830]para[/MENTION]m c - MapleClient     * [MENTION=850422]return[/MENTION] The String that shows players their bingo card     */    public static String convertCard(MapleClient c) {        int[] playerNumbers c.getPlayer().getBingoNumbers();        String[] redNumbers = {"#i3990009#""#i3990000#""#i3990001#""#i3990002#""#i3990003#""#i3990004#""#i3990005#""#i3990006#""#i3990007#""#i3990008#"}; // I can't find a better way to do this :(        String[] greenNumbers = {"#i3990019#", "#i3990010#", "#i3990011#", "#i3990012#", "#i3990013#", "#i3990014#", "#i3990015#", "#i3990016#", "#i3990017#", "#i3990018#"}; // ...
            
    String str = new String(); // new String(); looks fancy, don't hate :)        int i = 0;        for (int number : playerNumbers) {            i++;            int first = number / 10; // can't be 0            int second = number % 10; // I'm completely improvising at this point T_T            if (BingoHandler.getInstance().isCalled(number)) { // called = green                str += greenNumbers[first];                str += greenNumbers[second];            } else { // not called = red                str += redNumbers[first];                str += redNumbers[second];            }            str += "\t";            if (i == 12) { // the 2 ++ (empty space in the middle)                str += "#i3990022##i3990022#\t";            }        }        return str;    }
        /**     * Checks if the player has a full card or not.     *     * [MENTION=2000183830]para[/MENTION]m c - MapleClient     * [MENTION=850422]return[/MENTION] True or False whether you have a full card or not.     */    
    public static boolean checkFullCard(MapleClient c) {        int[] playerNumbers c.getPlayer().getBingoNumbers();        for (int number playerNumbers) {            if (!BingoHandler.getInstance().isCalled(number)) { // as soon as it sees a number that is not true, it can't be a full card anymore                return false; // no full card            }        }        return true; // full card    }
        /**     * A method that reads all bingo numbers from the database and puts them     * into a HashMap.     */    
    private void loadBingoCalls() {        for (int i 10100i++) {            bingoCalls.put(iisCalledDB(i));            System.out.println(": " isCalledDB(i));        }    }
        
    /**     * This method updates the bingoCalls HashMap and the database.     *     * [MENTION=2000183830]para[/MENTION]m number the number to change     * [MENTION=2000183830]para[/MENTION]m call set the number to true or false, since people are retarded I     * build a failsafe     */    public void updateBingoCalls(int numberboolean call) {        if (bingoCalls.replace(numberisCalled(number), call)) {            try (PreparedStatement ps DatabaseConnection.getConnection().prepareStatement("UPDATE `bingo` SET `called` = ? WHERE `number` = ?")) {                ps.setBoolean(1call);                ps.setInt(2number);                ps.execute();            } catch (SQLException ex) {                Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVEREnullex);            }        } else {            System.out.println("Derp derp, derpy dy derp");        }    }
        
    /**     * Reads the number directly from the database.     *     * [MENTION=2000183830]para[/MENTION]m number - The number that the database has to read     * [MENTION=850422]return[/MENTION] Boolean whether the specified number is called or not     */    private boolean isCalledDB(int number) {        try (PreparedStatement ps DatabaseConnection.getConnection().prepareStatement("SELECT `called` FROM `bingo` WHERE `number` = ?")) {            ps.setInt(1number);            try (ResultSet rs ps.executeQuery()) {                if (rs.next()) {                    return rs.getBoolean("called");                }            }        } catch (SQLException ex) {            Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVEREnullex);        }        return false// ???    }
        /**     * A method to see if a certain number is called or not.     *     * [MENTION=2000183830]para[/MENTION]m number - The number to read from the HashMap     * [MENTION=850422]return[/MENTION] Boolean whether the specified number is called or not     */    
    private boolean isCalled(int number) {        return bingoCalls.get(number);    }
        
    /**     * Method to reset the bingo event with the option to reset player bingo     * cards     *     * [MENTION=2000183830]para[/MENTION]m playerCards True if you want to reset bingo cards     */    public void resetBingo(boolean playerCards) {        for (int i 10100i++) {            bingoCalls.put(ifalse); // there has to be an easier way to do this?        }
            
    try (PreparedStatement ps DatabaseConnection.getConnection().prepareStatement("UPDATE `bingo` SET `called` = 0")) {            ps.execute();        } catch (SQLException ex) {            Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVEREnullex);        }
            if (
    playerCards) {            try (PreparedStatement ps DatabaseConnection.getConnection().prepareStatement("UPDATE `characters` SET `bingocard` = ?")) {                ps.setString(1null);                ps.execute();            } catch (SQLException ex) {                Logger.getLogger(BingoHandler.class.getName()).log(Level.SEVEREnullex);            }
                for (
    MapleCharacter chr Server.getInstance().getWorld(0).getPlayerStorage().getAllCharacters()) { // if you want multiworld support then you can probably code this yourself                chr.setCard(false);                chr.fillBingoNumbers(null); // Technically this isn't required, but I'm not 100% sure...            }        }    }
        
    public void startBingoTimer() {        bingoTimer();    }
        public 
    void destroyBingoTimer() {        if (bingoTimer != null) {            bingoTimer.cancel(false);            bingoTimer null;        } else {            System.out.println("Some shitty GM tried to stop a non-existing bingo timer. Fire him.");        }    }
        private 
    void bingoTimer() {        if (bingoTimer == null) {            bingoTimer TimerManager.getInstance().register(() -> {                if (this != null) { // huh                    Random rand = new Random();                    boolean called = false;                    int number = 0; // java is too stupid to see that number will always be initialized                    while (!called) {                        number = rand.nextInt(89) + 10;                        called = !isCalled(number);                    }                    updateBingoCalls(number, true);                    Server.getInstance().broadcastMessage(MaplePacketCreator.serverNotice(6, "[Bingo] Number " + number + " has been called!"));                } else {                    System.out.println("If you are seeing this you are either high or you did something really weird.");                }            }, interval * 1000 * 60, interval * 1000 * 60);        } else {            System.out.println("Some shitty GM tried to run 2 bingo timers at once. Fire him.");        }    }}
    [code] tags look so dull and are kinda hard to read, any solution?


  2. #2
    Moderator GigaToni is offline
    ModeratorRank
    Aug 2009 Join Date
    GER / FRLocation
    2,007Posts

    Re: php code tags

    I don't have access to the not fucked up code but..

    PHP Code:
    /* * Bingo Event for MapleStory! * (ragezone-link) */
    packagenet custom;
    importclient MapleCharacter;
    importclient MapleClient;
    importjava sql PreparedStatement;
    importjava sql ResultSet;
    importjava sql SQLException;
    importjava util Arrays;
    importjava util HashMap;
    importjava util LinkedHashSet;
    importjava util Map;
    importjava util Random;
    importjava util Set;
    importjava util concurrent ScheduledFuture;
    importjava util logging Level;
    importjava util logging Logger;
    importnet server Server;
    importserver TimerManager;
    importtools DatabaseConnection;
    importtools MaplePacketCreator;
    /** * * @author Las Systos */
    public class BingoHandler

        
    {
        private static 
    BingoHandlerinstance null;
        private final 
    Map IntegerBoolean bingoCalls = new HashMap <> ();
        private 
    ScheduledFuture ?> bingoTimer; 
    It works for me.

    Guess your editor saves without clf endings. Try pasting it into notepad++ and change the line endings to windows.

  3. #3
    Deep thoughts php code tags Joopie is online now
    Alpha MaleRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,596Posts

    Re: php code tags

    Or use the "paste as plain text" option in the reply box

  4. #4
    Would You Kindly? Bola is online now
    DeveloperRank
    Dec 2011 Join Date
    BrazilLocation
    1,503Posts

    Re: php code tags

    When user copy the code, the ; and all {} keeps correct, user can use the auto identify from IDE to make it readable

    NetBeans -> ctrl + alt + f




Advertisement