Started adding the axe interaction code

This commit is contained in:
sekwah41 2013-10-07 21:26:03 +01:00
parent 7f4715d94a
commit a32fe6c8c5
2 changed files with 104 additions and 3 deletions

View File

@ -0,0 +1,71 @@
package com.sekwah.advancedportals;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class ConfigAccessor {
private final String fileName;
private final JavaPlugin plugin;
private File configFile;
private FileConfiguration fileConfiguration;
public ConfigAccessor(JavaPlugin plugin, String fileName) {
if (!plugin.isInitialized())
throw new IllegalArgumentException("plugin must be initiaized");
this.plugin = plugin;
this.fileName = fileName;
}
// gets all of the
public void reloadConfig() {
if (configFile == null) {
File dataFolder = plugin.getDataFolder();
if (dataFolder == null)
throw new IllegalStateException();
configFile = new File(dataFolder, fileName);
}
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
// Look for defaults in the jar
InputStream defConfigStream = plugin.getResource(fileName);
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
fileConfiguration.setDefaults(defConfig);
}
}
public FileConfiguration getConfig() {
if (fileConfiguration == null) {
this.reloadConfig();
}
return fileConfiguration;
}
// Saves all the data to the selected yml file
public void saveConfig() {
if (fileConfiguration == null || configFile == null) {
return;
} else {
try {
getConfig().save(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}
// Saves
public void saveDefaultConfig() {
if (!configFile.exists()) {
this.plugin.saveResource(fileName, false);
}
}
}

View File

@ -1,9 +1,39 @@
package com.sekwah.advancedportals;
import org.bukkit.event.Listener;
import net.minecraft.server.v1_6_R3.Item;
public class Listeners implements Listener{
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class Listeners implements Listener {
@EventHandler
public void onMoveEvent(PlayerMoveEvent event) {
// will check if the player is in the portal or not.
}
@EventHandler
public void oniteminteract(PlayerInteractEvent event) {
// will detect if the player is using an axe so the points of a portal can be set
// also any other detections such as sign interaction or basic block protection
if(event.getPlayer().getItemInHand().getTypeId() == Material.IRON_AXE.getId()) {
if(event.getAction() == Action.LEFT_CLICK_BLOCK){
}
else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
}
}
}
}