Skip to content

Commit

Permalink
Reorganized copying
Browse files Browse the repository at this point in the history
Shifted copying methods into BookSuitePrintingPress to unclutter main
class
Fixed issue with stairs not remembering type (2.1.0)
https://www.dropbox.com/sh/prg3hzlecgjigxf/4GGnhM_LAu/BookSuite%20stair%20error
  • Loading branch information
Jikoo committed Jan 12, 2013
1 parent 6a5320b commit b5123cd
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 314 deletions.
6 changes: 5 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
- KNOWN BUG [trivial]: If a second press is used by the same player while the first is "stamping" the second stamp's stairblock will overwrite the first.

2.1.1
- removed bug from 2.1.0. now opens crafting table if double tapped to quickly, with no effect on the printing process
- changed the format for /makebook (see demobook.book)
- starting framework for server book storage and upload
2.1.2
- added config
- reimplemented deny permissions
2.1.3
- fixed bug: right click on invalid "stamp" (read: regular crafting table) or with booksuite.copy.deny.nowarn returns itemId of block above
3.0.0a1
- minor changes to regex for mailing
- removed unused class
- reorganized copying code to make main class more readable
- fixed 2.1.0 bug (no longer store block data in main class)
167 changes: 25 additions & 142 deletions src/com/github/Jikoo/BookSuite/BookSuite.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.github.Jikoo.BookSuite;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -21,10 +20,8 @@

public class BookSuite extends JavaPlugin implements Listener{
String version = "3.0.0";
String neededSupplies = "";
BlockState originalBlock;
BlockState newBlock;
Boolean usePermissions;
String neededSupplies = "";


@Override
Expand All @@ -44,7 +41,6 @@ public void onEnable() {




@Override
public void onDisable() {
getLogger().info("BookSuite v"+version+" disabled!");
Expand All @@ -54,7 +50,6 @@ public void onDisable() {




/**
* checks if the player has the supplies needed
*
Expand All @@ -73,7 +68,6 @@ public boolean hasSupplies(Inventory inv){




/**
* master method for checking if the player can obtain the books
*
Expand Down Expand Up @@ -108,119 +102,6 @@ public boolean canObtainBook(Player p){
}





/**
*
* @param p
* @param a
* @return
*/
public boolean checkPermission(Player p, String a){
if (usePermissions){
if (p.hasPermission("booksuite.copy.other"))
return true;
if (p.hasPermission("booksuite.copy.self") && a.equals(p.getName()))
return true;
else if (p.hasPermission("booksuite.copy.self"))
p.sendMessage(ChatColor.DARK_RED+"You do not have permission to copy others' books.");
else
p.sendMessage(ChatColor.DARK_RED+"You do not have permission to copy books.");
}
else if (p.isOp())
return true;
else if (a.equals(p.getName()))
return true;
else p.sendMessage(ChatColor.DARK_RED+"Only ops can copy others' books.");
return false;
}
public boolean denyUseage(Player p){
if (p.hasPermission("booksuite.copy.deny.nowarn"))
return true;
return false;
}






/**
*
* @param p
* @param is
* @param b
*/
public void operatePress(Player p, ItemStack is, Block b){
originalBlock = b.getState();
changeStairBlock(b);
revertBlockPause(b);
p.getInventory().addItem(is.clone());
p.updateInventory();
p.sendMessage(ChatColor.DARK_GREEN+"Book copied!");
}





/**
* turns the stair block into a slab for graphical effect
*
* @param b the stair block to be transformed
*/
public void changeStairBlock(Block b){
if (b.getTypeId() == 53)//WOOD_STAIRS
b.setTypeIdAndData(126, (byte) 0, false);//WOOD_STEP

else if (b.getTypeId() == 67)//COBBLESTONE_STAIRS
b.setTypeIdAndData(44, (byte) 3, false);//STEP

else if (b.getTypeId() == 108)//BRICK_STAIRS
b.setTypeIdAndData(44, (byte) 4, false);//STEP

else if (b.getTypeId() == 109)//SMOOTH_STAIRS
b.setTypeIdAndData(44, (byte) 5, false);//STEP

else if (b.getTypeId() == 114)//NETHER_BRICK_STAIRS
b.setTypeIdAndData(44, (byte) 6, false);//STEP

else if (b.getTypeId() == 128)//SANDSTONE_STAIRS
b.setTypeIdAndData(44, (byte) 1, false);//STEP

else if (b.getTypeId() == 134)//SPRUCE_WOOD_STAIRS
b.setTypeIdAndData(126, (byte) 1, false);//WOOD_STEP

else if (b.getTypeId() == 135)//BIRCH_WOOD_STAIRS
b.setTypeIdAndData(126, (byte) 2, false);//WOOD_STEP

else if (b.getTypeId() == 136)//JUNGLE_WOOD_STAIRS
b.setTypeIdAndData(126, (byte) 3, false);//WOOD_STEP

newBlock = b.getState();
}




public class revertBlock implements Runnable{
Block b;
revertBlock(Block block){
b = block;
}
public void run() {
b.setTypeIdAndData(originalBlock.getTypeId(), originalBlock.getData().getData(), false);
}
}
public void revertBlockPause(Block b){
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new revertBlock(b), 20L);
}





/**
* copy book (PrintingPress) or send mail
*
Expand All @@ -233,49 +114,51 @@ public void onPlayerInteract(PlayerInteractEvent event){
Player p = event.getPlayer();
ItemStack is = p.getItemInHand();
Block clicked = event.getClickedBlock();

Block blockUp = clicked.getRelative(BlockFace.UP);


if (is.getType().equals(Material.WRITTEN_BOOK) && clicked.getType().equals(Material.WORKBENCH)){

Block blockUp = clicked.getRelative(BlockFace.UP);
if (BookSuiteBlockCheck.isInvertedStairs(blockUp) && !denyUseage(p)){
BookSuitePrintingPress press = new BookSuitePrintingPress(this, p, is, blockUp);
if (BookSuitePrintingPress.isInvertedStairs(blockUp) && !press.denyUseage()){

BookMeta bm = (BookMeta) is.getItemMeta();
if (checkPermission(p, bm.getAuthor()) && canObtainBook(p))
operatePress(p, is, blockUp);
if (press.checkCopyPermission(bm.getAuthor()) && canObtainBook(p))
press.operatePress();
event.setCancelled(true);
}
}



//this is for checking mail
if (clicked.getType().equals(Material.CHEST)){
//test if there is a sign above it saying "mail"
//if so, read from the player's local-file inventory and put those items into the chest
//make sure to test if the player has the ability to look into the chest before adding items
//once the items have been added to the players mailbox, REMOVE THEM FROM THE FILE
}
if (clicked.getType().equals(Material.CHEST))
if (blockUp.getType().equals(Material.SIGN)) {
Sign sign = (Sign) blockUp;
if (sign.getLine(0).contains("mail"));//rudimentary example
p.sendMessage(ChatColor.DARK_GREEN+"This will eventually be a mailbox! Woo!");
}
/*
* test if there is a sign above it saying "mail"
* if so, read from the player's local-file inventory and put those items into the chest
* make sure to test if the player has the ability to look into the chest before adding items
* once the items have been added to the players mailbox, REMOVE THEM FROM THE FILE
* re-add on chest close, if possible
*/

}


// this is for taking a "package/envelope" that contains a "gift" and opening it into your inventory.
if (event.getAction().equals(Action.RIGHT_CLICK_AIR)){
/* THIS IS GOING TO BE DONE VIA COMMAND NOW
Player p = event.getPlayer();
if (p.getItemInHand().getType().equals(Material.WRITTEN_BOOK))
if (p.hasPermission("booksuite.mail.send")){
BookMeta bm = (BookMeta) p.getItemInHand().getItemMeta();
new BookSuiteMailHandler(this, p).sendMail(bm);
event.setCancelled(true);
}
*/
Player p = event.getPlayer();
if (p.getItemInHand().getType().equals(Material.WRITTEN_BOOK)){
BookMeta bm = (BookMeta) p.getItemInHand().getItemMeta();
if (bm.getPage(0).equals("To: "+p.getName())){

}
else if (p.hasPermission("booksuite.mail.send")){
new BookSuiteMailExecutor(this, p).sendMail();
event.setCancelled(true);
}
else if(bm.getPage(0).contains("To: ")){
p.sendMessage(ChatColor.DARK_RED+"This package is not addressed to you. However you got it, you shouldnt have it. put it back now. or else.");
Expand Down
26 changes: 0 additions & 26 deletions src/com/github/Jikoo/BookSuite/BookSuiteBlockCheck.java

This file was deleted.

58 changes: 36 additions & 22 deletions src/com/github/Jikoo/BookSuite/BookSuiteMailExecutor.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,57 @@
package com.github.Jikoo.BookSuite;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BookMeta;

public class BookSuiteMailExecutor {

BookSuite plugin;
Player p;
String to;
String bookMessageName;
String itemMetaName;

public BookSuiteMailExecutor(BookSuite plugin){
public BookSuiteMailExecutor(BookSuite plugin, Player p){
this.plugin = plugin;
this.p = p;
}


public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {



public void sendMail(){
p.sendMessage(ChatColor.DARK_RED+"This function does not yet exist.");
getSendingData();
parseSendingData();
//Verify inventory
//Files!
}



//The whole point is that it's commandless >.> why have a packing slip or details in the book then?
/*public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (! (sender instanceof Player) ){
sender.sendMessage(ChatColor.DARK_RED+"you must be a player to use this command");
return false;
}
Player p = (Player) sender;
*/
public void getSendingData(){
PlayerInventory i = p.getInventory();
ItemStack potentiallyABook = i.getItemInHand();
if (potentiallyABook.equals(new ItemStack(Material.WRITTEN_BOOK, 1))){
BookMeta bm = (BookMeta)(potentiallyABook.getItemMeta());
if (bm.getTitle().equalsIgnoreCase("packing slip") || bm.getTitle().equalsIgnoreCase("packingslip")){
String to = bm.getPage(0);
String bookMessageName = bm.getPage(1);
String itemMetaName = bm.getPage(2);
}
BookMeta bm = (BookMeta) p.getItemInHand();//This is already guaranteed to be a written book by event handler
String title = bm.getTitle();
title.replaceFirst("[\\W_]*", "");//(any non [a-zA-Z0-9] consumed)
if (title.equalsIgnoreCase("packingslip")){
to = bm.getPage(0);
bookMessageName = bm.getPage(1);
itemMetaName = bm.getPage(2);
}




return true;
}

public void parseSendingData(){
to.replaceFirst("\\A.*[Tt][Oo]:\\s*", "");
to.replaceAll("\\W", "");
//no clue what we want to do for the rest, but it can be handled in similar format.
}
}

0 comments on commit b5123cd

Please sign in to comment.