Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.bukkit.entity.Player;

import com.github.iaccidentally.ecm.commands.*;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -41,7 +44,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
// Parse the commands
if(args[0].equalsIgnoreCase("adduser"))
{
Commandadduser.addUser(player, args[1]);
try {
new Commandadduser().addUser(player, args[1]);
} catch (IOException ex) {
Logger.getLogger(CommandManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if(args[0].equalsIgnoreCase("copy"))
{
Expand Down
184 changes: 96 additions & 88 deletions src/main/java/com/github/iaccidentally/ecm/ECM.java
Original file line number Diff line number Diff line change
@@ -1,100 +1,108 @@
package com.github.iaccidentally.ecm;

import com.github.iaccidentally.ecm.commands.Util;
import com.github.iaccidentally.ecm.configuration.Configuration;
import com.github.iaccidentally.ecm.listeners.BlockListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

import com.github.iaccidentally.ecm.commands.Util;
import com.github.iaccidentally.ecm.configuration.Configuration;

import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class ECM extends JavaPlugin {

Logger log;
public CommandManager manager;
private FileConfiguration data = null, language = null;
private File dataFile = null, languageFile = null;

@Override
public void onEnable() {
log = this.getLogger();
manager = new CommandManager(this);

log.info("Plugin enabled");
}

@Override
public void onDisable() {
log.info("Plugin disabled");
}

public void registerListeners() {
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new BlockListener(), this);
}

public void reloadData() {
if (dataFile == null) {
dataFile = new File(getDataFolder(), "data.yml");
}
data = YamlConfiguration.loadConfiguration(dataFile);

// Look for defaults in the jar
InputStream defConfigStream = getResource("data.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
data.setDefaults(defConfig);
}
}

public FileConfiguration getData() {
if (data == null) {
reloadData();
}
return data;
}

public void saveData() {
if (data == null || dataFile == null) {
return;
}
try {
data.save(dataFile);
} catch (IOException ex) {
Util.log("Could not save config to " + dataFile);
}
}

public void reloadLanguage() {

String lang = Configuration.getString("configuration.language") + ".yml";
Util.log("Language file used: " + lang);

if (languageFile == null) {
languageFile = new File(getDataFolder(), lang);
}
language = YamlConfiguration.loadConfiguration(languageFile);

// Look for defaults in the jar
InputStream defConfigStream = getResource(lang);
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
language.setDefaults(defConfig);
}
}

public FileConfiguration getLanguage() {
if (language == null) {
reloadLanguage();
}
return language;
}

public class ECM extends JavaPlugin
{
Logger log;
public CommandManager manager;

private FileConfiguration data = null, language = null;
private File dataFile = null, languageFile = null;

public void onEnable()
{
log = this.getLogger();
manager = new CommandManager(this);

log.info("Plugin enabled");
}

public void onDisable()
{
log.info("Plugin disabled");
}

public void reloadData() {
if (dataFile == null) {
dataFile = new File(getDataFolder(), "data.yml");
}
data = YamlConfiguration.loadConfiguration(dataFile);

// Look for defaults in the jar
InputStream defConfigStream = getResource("data.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
data.setDefaults(defConfig);
}
}

public FileConfiguration getData() {
if (data == null) {
reloadData();
}
return data;
}

public void saveData() {
if (data == null || dataFile == null) return;
try {
data.save(dataFile);
} catch (IOException ex) {
Util.log("Could not save config to " + dataFile);
}
}

public void reloadLanguage() {

String lang = Configuration.getString("configuration.language") + ".yml";
Util.log("Language file used: " + lang);

if (languageFile == null) {
languageFile = new File(getDataFolder(), lang);
}
language = YamlConfiguration.loadConfiguration(languageFile);

// Look for defaults in the jar
InputStream defConfigStream = getResource(lang);
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
language.setDefaults(defConfig);
}
}

public FileConfiguration getLanguage() {
if (language == null) {
reloadLanguage();
}
return language;
}

public void saveLanguageData() {
if (language == null || languageFile == null) return;
try {
language.save(languageFile);
} catch (IOException ex) {
Util.log("Could not save config to " + languageFile);
}
}
public void saveLanguageData() {
if (language == null || languageFile == null) {
return;
}
try {
language.save(languageFile);
} catch (IOException ex) {
Util.log("Could not save config to " + languageFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.util.BlockVector;

/**
*
* @author Whisk
*/
public class BlockListener {
public class BlockListener implements Listener{

public static BlockVector block1;
public static BlockVector block2;
public static World world;

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
Expand All @@ -32,6 +38,23 @@ public void onBlockDamage(BlockDamageEvent event) {
world = block.getWorld();
player.sendMessage(ChatColor.GREEN + "First point is now set!");
}
//prevent the block from braking by player's click
event.setCancelled(true);
}

@EventHandler
public void onBlockRightClick(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
Entity b = event.getRightClicked();
//only set the point if a block was clicked
if (!(b instanceof Block)) return;
Block block = (Block) b;
if (player.getItemInHand().getTypeId() == 281) {
if (player.hasPermission("ECM.selection"));
block2 = Util.toVector(block);
world = block.getWorld();
player.sendMessage(ChatColor.GREEN + "Second point is now set!");
}
}


Expand Down