Started adding the axe interaction code
This commit is contained in:
parent
7f4715d94a
commit
a32fe6c8c5
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +1,39 @@
|
||||||
package com.sekwah.advancedportals;
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue