-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3139c69
commit f2b2fc0
Showing
4 changed files
with
321 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
package com.endercrest; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.bukkit.ChatColor; | ||
|
||
public class BlockBreakListener implements Listener { | ||
|
||
DisplayChest plugin; | ||
|
||
public BlockBreakListener(DisplayChest instance) { | ||
plugin = instance; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@EventHandler | ||
public void onBlockBreak(BlockBreakEvent event){ | ||
Player p = event.getPlayer(); | ||
|
||
if(plugin.chests.contains(p.getTargetBlock(null, 5).getLocation().toString())){ | ||
event.setCancelled(true); | ||
String msg = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Break", "&cYou Can't Break This Block.")); | ||
|
||
p.sendMessage(msg); | ||
public void onBreakBreak(BlockBreakEvent event){ | ||
if(plugin.chests.contains(event.getBlock().getLocation().toString())){ | ||
if(event.getBlock().getType() == Material.CHEST || event.getBlock().getType() == Material.TRAPPED_CHEST){ | ||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package com.endercrest; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import me.xhawk87.PopupMenuAPI.MenuItem; | ||
import me.xhawk87.PopupMenuAPI.PopupMenu; | ||
import me.xhawk87.PopupMenuAPI.PopupMenuAPI; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.Material; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.material.MaterialData; | ||
|
||
public class Menu { | ||
|
||
DisplayChest plugin; | ||
|
||
ArrayList<MenuItem> items = new ArrayList<MenuItem>(); | ||
|
||
public Menu(DisplayChest instance) { | ||
plugin = instance; | ||
} | ||
|
||
/** | ||
* Menu | ||
* | ||
* @param p - The player | ||
* @param id - The id of the menu | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public void MenuGUI(Player p, String id){ | ||
File idFile = new File(plugin.getDataFolder() + File.separator + "Menus", id + ".yml"); | ||
final FileConfiguration idConfig = YamlConfiguration.loadConfiguration(idFile); | ||
final PopupMenu GUI; | ||
GUI = PopupMenuAPI.createMenu(ChatColor.translateAlternateColorCodes('&', idConfig.get("Title").toString()), idConfig.getInt("Size")); | ||
|
||
for(int i=0; i<idConfig.getInt("Size")*9; i++){ | ||
|
||
if(idConfig.isSet(i + ".Item_ID")){ | ||
MenuItem item = new MenuItem(ChatColor.translateAlternateColorCodes('&', idConfig.get(i + ".Name").toString()),new MaterialData(Material.getMaterial(idConfig.getInt(i + ".Item_ID")))){ | ||
@Override | ||
public void onClick(Player player) { | ||
|
||
} | ||
}; | ||
|
||
if(idConfig.isSet(i + ".Sub-Text")){ | ||
List<String> sub = idConfig.getStringList(i + ".Sub-Text"); | ||
for(int s = 0; s < sub.size(); s++){ | ||
String text = sub.get(s); | ||
item.addDescription(ChatColor.translateAlternateColorCodes('&', text)); | ||
} | ||
} | ||
|
||
GUI.addMenuItem(item, i); | ||
} | ||
} | ||
|
||
GUI.setExitOnClickOutside(false); | ||
GUI.openMenu(p); | ||
} | ||
|
||
/** | ||
* Create a new file | ||
* | ||
* | ||
* @param id - The ID of the menu. | ||
* @param loc - The Location of the chest | ||
*/ | ||
public void createFile(String id, String loc){ | ||
//File idFile = new File(plugin.getDataFolder() + File.separator + "Menus", id + ".yml"); | ||
//final FileConfiguration idConfig = YamlConfiguration.loadConfiguration(idFile); | ||
|
||
loadFile("menu.yml", id); | ||
|
||
plugin.chests.add(loc); | ||
plugin.chests_id.add(id); | ||
plugin.getConfig().set("Chests", plugin.chests); | ||
plugin.getConfig().set("Chests_ID", plugin.chests_id); | ||
plugin.saveConfig(); | ||
} | ||
|
||
/** | ||
* Delete file/Possibly relocate file | ||
* | ||
* @param id The ID of the menu. | ||
*/ | ||
public void deleteFile(String id, String loc){ | ||
File idFile = new File(plugin.getDataFolder() + File.separator + "Menus", id + ".yml"); | ||
File oldFile = new File(plugin.getDataFolder() + File.separator + "Old_Menus", id + "_old.yml"); | ||
|
||
oldFile.delete(); | ||
idFile.renameTo(oldFile); | ||
|
||
plugin.chests.remove(loc); | ||
plugin.chests_id.remove(id); | ||
plugin.getConfig().set("Chests", plugin.chests); | ||
plugin.getConfig().set("Chests_ID", plugin.chests_id); | ||
plugin.saveConfig(); | ||
} | ||
|
||
/** | ||
* Copy's default file then rename it. | ||
* | ||
* @param file - The file | ||
*/ | ||
public void loadFile(String file, String id){ | ||
File t = new File(plugin.getDataFolder() + File.separator + "Menus", file); | ||
File idFile = new File(plugin.getDataFolder() + File.separator + "Menus", id + ".yml"); | ||
//System.out.println("Writing new file: "+ t.getAbsolutePath()); | ||
|
||
try { | ||
t.createNewFile(); | ||
FileWriter out = new FileWriter(t); | ||
//System.out.println(file); | ||
InputStream is = getClass().getResourceAsStream("/"+file); | ||
InputStreamReader isr = new InputStreamReader(is); | ||
BufferedReader br = new BufferedReader(isr); | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
out.write(line+"\n"); | ||
//System.out.println(line); | ||
} | ||
out.flush(); | ||
is.close(); | ||
isr.close(); | ||
br.close(); | ||
out.close(); | ||
t.renameTo(idFile); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Reload Config | ||
* | ||
* @param id The ID of the menu | ||
*/ | ||
//TODO Reload file | ||
public void reloadFile(String id){ | ||
//File idFile = new File(plugin.getDataFolder() + File.separator + "Menus", id + ".yml"); | ||
//final FileConfiguration idConfig = YamlConfiguration.loadConfiguration(idFile); | ||
} | ||
|
||
/** | ||
* Reload all config. | ||
*/ | ||
//TODO Reload all configs | ||
public void reloadAllFiles(){ | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.